Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shell/native_application_support.h" |
| 6 | |
| 7 | #include "base/files/file_path.h" |
| 8 | #include "base/files/file_util.h" |
| 9 | #include "base/logging.h" |
James Robinson | cbf8d2e | 2015-08-21 18:13:44 -0700 | [diff] [blame] | 10 | #include "mojo/public/platform/native/gles2_impl_chromium_bind_uniform_location_thunks.h" |
James Robinson | fe8fa53 | 2015-08-24 11:10:17 -0700 | [diff] [blame] | 11 | #include "mojo/public/platform/native/gles2_impl_chromium_map_sub_thunks.h" |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 12 | #include "mojo/public/platform/native/gles2_impl_chromium_miscellaneous_thunks.h" |
Viet-Trung Luu | a65790a | 2015-07-28 09:49:50 -0700 | [diff] [blame] | 13 | #include "mojo/public/platform/native/gles2_impl_chromium_resize_thunks.h" |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 14 | #include "mojo/public/platform/native/gles2_impl_chromium_sync_point_thunks.h" |
| 15 | #include "mojo/public/platform/native/gles2_impl_chromium_texture_mailbox_thunks.h" |
Viet-Trung Luu | 9bddf93 | 2015-08-05 12:14:29 -0700 | [diff] [blame] | 16 | #include "mojo/public/platform/native/gles2_impl_ext_debug_marker_thunks.h" |
James Robinson | 45d6629 | 2015-08-27 13:56:17 -0700 | [diff] [blame] | 17 | #include "mojo/public/platform/native/gles2_impl_ext_discard_framebuffer_thunks.h" |
James Robinson | 92035fd | 2015-08-27 15:41:19 -0700 | [diff] [blame] | 18 | #include "mojo/public/platform/native/gles2_impl_ext_multisampled_render_to_texture_thunks.h" |
Viet-Trung Luu | 32649a8 | 2015-09-16 14:41:14 -0700 | [diff] [blame] | 19 | #include "mojo/public/platform/native/gles2_impl_ext_occlusion_query_thunks.h" |
James Robinson | b998d4d | 2015-08-27 09:44:29 -0700 | [diff] [blame] | 20 | #include "mojo/public/platform/native/gles2_impl_ext_texture_storage_thunks.h" |
James Robinson | 3f90f82 | 2015-08-27 12:29:40 -0700 | [diff] [blame] | 21 | #include "mojo/public/platform/native/gles2_impl_khr_blend_equation_advanced_thunks.h" |
Viet-Trung Luu | 7966797 | 2015-08-05 08:53:30 -0700 | [diff] [blame] | 22 | #include "mojo/public/platform/native/gles2_impl_oes_vertex_array_object_thunks.h" |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 23 | #include "mojo/public/platform/native/gles2_impl_thunks.h" |
Adam Barth | a37b8c2 | 2016-04-21 13:46:39 -0700 | [diff] [blame] | 24 | #include "mojo/public/platform/native/mgl_echo_thunks.h" |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 25 | #include "mojo/public/platform/native/mgl_onscreen_thunks.h" |
James Robinson | 0cc70ad | 2015-08-28 13:31:37 -0700 | [diff] [blame] | 26 | #include "mojo/public/platform/native/mgl_signal_sync_point_thunks.h" |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 27 | #include "mojo/public/platform/native/mgl_thunks.h" |
Forrest Reiling | 74b0cac | 2016-03-02 16:21:15 -0800 | [diff] [blame] | 28 | #include "mojo/public/platform/native/platform_handle_private_thunks.h" |
Nick Bray | da897d6 | 2015-04-08 16:28:55 -0700 | [diff] [blame] | 29 | #include "mojo/public/platform/native/system_impl_private_thunks.h" |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 30 | #include "mojo/public/platform/native/system_thunks.h" |
| 31 | |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 32 | namespace shell { |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | template <typename Thunks> |
| 37 | bool SetThunks(Thunks (*make_thunks)(), |
| 38 | const char* function_name, |
| 39 | base::NativeLibrary library) { |
| 40 | typedef size_t (*SetThunksFn)(const Thunks* thunks); |
| 41 | SetThunksFn set_thunks = reinterpret_cast<SetThunksFn>( |
| 42 | base::GetFunctionPointerFromNativeLibrary(library, function_name)); |
| 43 | if (!set_thunks) |
| 44 | return false; |
| 45 | Thunks thunks = make_thunks(); |
| 46 | size_t expected_size = set_thunks(&thunks); |
| 47 | if (expected_size > sizeof(Thunks)) { |
| 48 | LOG(ERROR) << "Invalid app library: expected " << function_name |
| 49 | << " to return thunks of size: " << expected_size; |
| 50 | return false; |
| 51 | } |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | } // namespace |
| 56 | |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 57 | base::NativeLibrary LoadNativeApplication(const base::FilePath& app_path) { |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 58 | DVLOG(2) << "Loading Mojo app in process from library: " << app_path.value(); |
| 59 | |
| 60 | base::NativeLibraryLoadError error; |
| 61 | base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, &error); |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 62 | LOG_IF(ERROR, !app_library) |
| 63 | << "Failed to load app library (error: " << error.ToString() << ")"; |
| 64 | return app_library; |
| 65 | } |
| 66 | |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 67 | bool RunNativeApplication( |
| 68 | base::NativeLibrary app_library, |
| 69 | mojo::InterfaceRequest<mojo::Application> application_request) { |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 70 | // Tolerate |app_library| being null, to make life easier for callers. |
| 71 | if (!app_library) |
| 72 | return false; |
| 73 | |
| 74 | if (!SetThunks(&MojoMakeSystemThunks, "MojoSetSystemThunks", app_library)) { |
| 75 | LOG(ERROR) << "MojoSetSystemThunks not found"; |
| 76 | return false; |
| 77 | } |
| 78 | |
Forrest Reiling | 74b0cac | 2016-03-02 16:21:15 -0800 | [diff] [blame] | 79 | // TODO(freiling): enforce the private nature of this API, somehow? |
| 80 | SetThunks(&MojoMakePlatformHandlePrivateThunks, |
| 81 | "MojoSetPlatformHandlePrivateThunks", app_library); |
| 82 | |
Nick Bray | da897d6 | 2015-04-08 16:28:55 -0700 | [diff] [blame] | 83 | // TODO(ncbray): enforce the private nature of this API, somehow? |
| 84 | SetThunks(&MojoMakeSystemImplControlThunksPrivate, |
| 85 | "MojoSetSystemImplControlThunksPrivate", app_library); |
| 86 | SetThunks(&MojoMakeSystemImplThunksPrivate, "MojoSetSystemImplThunksPrivate", |
| 87 | app_library); |
| 88 | |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 89 | SetThunks(&MojoMakeGLES2ImplThunks, "MojoSetGLES2ImplThunks", |
| 90 | app_library); |
James Robinson | 3ad6f4f | 2015-08-26 12:15:19 -0700 | [diff] [blame] | 91 | SetThunks(MojoMakeGLES2ImplEXTDebugMarkerThunks, |
| 92 | "MojoSetGLES2ImplEXTDebugMarkerThunks", app_library); |
James Robinson | 45d6629 | 2015-08-27 13:56:17 -0700 | [diff] [blame] | 93 | SetThunks(MojoMakeGLES2ImplEXTDiscardFramebufferThunks, |
| 94 | "MojoSetGLES2ImplEXTDiscardFramebufferThunks", app_library); |
Viet-Trung Luu | 32649a8 | 2015-09-16 14:41:14 -0700 | [diff] [blame] | 95 | SetThunks(MojoMakeGLES2ImplEXTOcclusionQueryThunks, |
| 96 | "MojoSetGLES2ImplEXTOcclusionQueryThunks", app_library); |
James Robinson | b998d4d | 2015-08-27 09:44:29 -0700 | [diff] [blame] | 97 | SetThunks(MojoMakeGLES2ImplEXTTextureStorageThunks, |
| 98 | "MojoSetGLES2ImplEXTTextureStorageThunks", app_library); |
James Robinson | 92035fd | 2015-08-27 15:41:19 -0700 | [diff] [blame] | 99 | SetThunks(MojoMakeGLES2ImplEXTMultisampledRenderToTextureThunks, |
| 100 | "MojoSetGLES2ImplEXTMultisampledRenderToTextureThunks", |
| 101 | app_library); |
James Robinson | 3f90f82 | 2015-08-27 12:29:40 -0700 | [diff] [blame] | 102 | SetThunks(MojoMakeGLES2ImplKHRBlendEquationAdvancedThunks, |
| 103 | "MojoSetGLES2ImplKHRBlendEquationAdvancedThunks", app_library); |
James Robinson | 3ad6f4f | 2015-08-26 12:15:19 -0700 | [diff] [blame] | 104 | SetThunks(MojoMakeGLES2ImplOESVertexArrayObjectThunks, |
| 105 | "MojoSetGLES2ImplOESVertexArrayObjectThunks", app_library); |
Viet-Trung Luu | 32649a8 | 2015-09-16 14:41:14 -0700 | [diff] [blame] | 106 | // Deprecated name for "MojoSetGLES2ImplEXTOcclusionQueryThunks" (TODO(vtl): |
| 107 | // when no app is using this name any longer, delete it): |
| 108 | SetThunks(MojoMakeGLES2ImplEXTOcclusionQueryThunks, |
| 109 | "MojoSetGLES2ImplOcclusionQueryEXTThunks", app_library); |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 110 | // "Chromium" extensions: |
James Robinson | 3ad6f4f | 2015-08-26 12:15:19 -0700 | [diff] [blame] | 111 | SetThunks(MojoMakeGLES2ImplCHROMIUMBindUniformLocationThunks, |
| 112 | "MojoSetGLES2ImplCHROMIUMBindUniformLocationThunks", app_library); |
| 113 | SetThunks(MojoMakeGLES2ImplCHROMIUMMapSubThunks, |
| 114 | "MojoSetGLES2ImplCHROMIUMMapSubThunks", app_library); |
| 115 | SetThunks(MojoMakeGLES2ImplCHROMIUMMiscellaneousThunks, |
| 116 | "MojoSetGLES2ImplCHROMIUMMiscellaneousThunks", app_library); |
| 117 | SetThunks(MojoMakeGLES2ImplCHROMIUMResizeThunks, |
| 118 | "MojoSetGLES2ImplCHROMIUMResizeThunks", app_library); |
| 119 | SetThunks(MojoMakeGLES2ImplCHROMIUMSyncPointThunks, |
| 120 | "MojoSetGLES2ImplCHROMIUMSyncPointThunks", app_library); |
| 121 | SetThunks(MojoMakeGLES2ImplCHROMIUMTextureMailboxThunks, |
| 122 | "MojoSetGLES2ImplCHROMIUMTextureMailboxThunks", app_library); |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 123 | |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 124 | if (SetThunks(MojoMakeMGLThunks, "MojoSetMGLThunks", app_library)) { |
Adam Barth | a37b8c2 | 2016-04-21 13:46:39 -0700 | [diff] [blame] | 125 | SetThunks(MojoMakeMGLEchoThunks, "MojoSetMGLEchoThunks", app_library); |
| 126 | |
James Robinson | 0cc70ad | 2015-08-28 13:31:37 -0700 | [diff] [blame] | 127 | // TODO(jamesr): We should only need to expose the onscreen thunks to apps |
| 128 | // that need to draw to the screen like the system compositor. |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 129 | SetThunks(MojoMakeMGLOnscreenThunks, "MojoSetMGLOnscreenThunks", |
| 130 | app_library); |
James Robinson | 1e96a13 | 2015-08-13 13:08:17 -0700 | [diff] [blame] | 131 | |
James Robinson | 0cc70ad | 2015-08-28 13:31:37 -0700 | [diff] [blame] | 132 | SetThunks(MojoMakeMGLSignalSyncPointThunks, |
| 133 | "MojoSetMGLSignalSyncPointThunks", app_library); |
| 134 | } |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 135 | |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 136 | typedef MojoResult (*MojoMainFunction)(MojoHandle); |
| 137 | MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
| 138 | base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); |
| 139 | if (!main_function) { |
| 140 | LOG(ERROR) << "MojoMain not found"; |
| 141 | return false; |
| 142 | } |
Mitch Rudominer | 1561910 | 2015-04-10 10:43:34 -0700 | [diff] [blame] | 143 | // |MojoMain()| takes ownership of the Application request handle. |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 144 | MojoHandle handle = application_request.PassMessagePipe().release().value(); |
| 145 | MojoResult result = main_function(handle); |
Viet-Trung Luu | f2a8c26 | 2015-04-02 13:54:32 -0700 | [diff] [blame] | 146 | LOG_IF(ERROR, result != MOJO_RESULT_OK) |
| 147 | << "MojoMain returned error (result: " << result << ")"; |
Viet-Trung Luu | e126c86 | 2015-03-30 19:20:45 -0700 | [diff] [blame] | 148 | return true; |
| 149 | } |
| 150 | |
| 151 | } // namespace shell |