OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/shell/dynamic_service_runner.h" | 5 #include "shell/dynamic_service_runner.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "mojo/public/platform/native/gles2_impl_chromium_sync_point_thunks.h" | 9 #include "mojo/public/platform/native/gles2_impl_chromium_sync_point_thunks.h" |
10 #include "mojo/public/platform/native/gles2_impl_chromium_texture_mailbox_thunks
.h" | 10 #include "mojo/public/platform/native/gles2_impl_chromium_texture_mailbox_thunks
.h" |
11 #include "mojo/public/platform/native/gles2_impl_thunks.h" | 11 #include "mojo/public/platform/native/gles2_impl_thunks.h" |
12 #include "mojo/public/platform/native/gles2_thunks.h" | 12 #include "mojo/public/platform/native/gles2_thunks.h" |
13 #include "mojo/public/platform/native/system_thunks.h" | 13 #include "mojo/public/platform/native/system_thunks.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace shell { | 16 namespace shell { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 template <typename Thunks> | 20 template <typename Thunks> |
21 bool SetThunks(Thunks (*make_thunks)(), | 21 bool SetThunks(Thunks (*make_thunks)(), |
22 const char* function_name, | 22 const char* function_name, |
23 base::NativeLibrary library) { | 23 base::NativeLibrary library) { |
24 typedef size_t (*SetThunksFn)(const Thunks* thunks); | 24 typedef size_t (*SetThunksFn)(const Thunks* thunks); |
25 SetThunksFn set_thunks = | 25 SetThunksFn set_thunks = reinterpret_cast<SetThunksFn>( |
26 reinterpret_cast<SetThunksFn>(base::GetFunctionPointerFromNativeLibrary( | 26 base::GetFunctionPointerFromNativeLibrary(library, function_name)); |
27 library, function_name)); | |
28 if (!set_thunks) | 27 if (!set_thunks) |
29 return false; | 28 return false; |
30 Thunks thunks = make_thunks(); | 29 Thunks thunks = make_thunks(); |
31 size_t expected_size = set_thunks(&thunks); | 30 size_t expected_size = set_thunks(&thunks); |
32 if (expected_size > sizeof(Thunks)) { | 31 if (expected_size > sizeof(Thunks)) { |
33 LOG(ERROR) << "Invalid app library: expected " << function_name | 32 LOG(ERROR) << "Invalid app library: expected " << function_name |
34 << " to return thunks of size: " << expected_size; | 33 << " to return thunks of size: " << expected_size; |
35 return false; | 34 return false; |
36 } | 35 } |
37 return true; | 36 return true; |
(...skipping 11 matching lines...) Expand all Loading... |
49 do { | 48 do { |
50 if (!app_library) { | 49 if (!app_library) { |
51 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() | 50 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() |
52 << ")"; | 51 << ")"; |
53 break; | 52 break; |
54 } | 53 } |
55 // Go shared library support requires us to initialize the runtime before we | 54 // Go shared library support requires us to initialize the runtime before we |
56 // start running any go code. This is a temporary patch. | 55 // start running any go code. This is a temporary patch. |
57 typedef void (*InitGoRuntimeFn)(); | 56 typedef void (*InitGoRuntimeFn)(); |
58 InitGoRuntimeFn init_go_runtime = reinterpret_cast<InitGoRuntimeFn>( | 57 InitGoRuntimeFn init_go_runtime = reinterpret_cast<InitGoRuntimeFn>( |
59 base::GetFunctionPointerFromNativeLibrary( | 58 base::GetFunctionPointerFromNativeLibrary(app_library, |
60 app_library, "InitGoRuntime")); | 59 "InitGoRuntime")); |
61 if (init_go_runtime) { | 60 if (init_go_runtime) { |
62 DVLOG(2) << "InitGoRuntime: Initializing Go Runtime found in app"; | 61 DVLOG(2) << "InitGoRuntime: Initializing Go Runtime found in app"; |
63 init_go_runtime(); | 62 init_go_runtime(); |
64 } | 63 } |
65 | 64 |
66 if (!SetThunks(&MojoMakeSystemThunks, "MojoSetSystemThunks", app_library)) { | 65 if (!SetThunks(&MojoMakeSystemThunks, "MojoSetSystemThunks", app_library)) { |
67 LOG(ERROR) << app_path.value() << " MojoSetSystemThunks not found"; | 66 LOG(ERROR) << app_path.value() << " MojoSetSystemThunks not found"; |
68 break; | 67 break; |
69 } | 68 } |
70 | 69 |
71 if (SetThunks(&MojoMakeGLES2ControlThunks, | 70 if (SetThunks(&MojoMakeGLES2ControlThunks, "MojoSetGLES2ControlThunks", |
72 "MojoSetGLES2ControlThunks", | |
73 app_library)) { | 71 app_library)) { |
74 // If we have the control thunks, we should also have the GLES2 | 72 // If we have the control thunks, we should also have the GLES2 |
75 // implementation thunks. | 73 // implementation thunks. |
76 if (!SetThunks(&MojoMakeGLES2ImplThunks, | 74 if (!SetThunks(&MojoMakeGLES2ImplThunks, "MojoSetGLES2ImplThunks", |
77 "MojoSetGLES2ImplThunks", | |
78 app_library)) { | 75 app_library)) { |
79 LOG(ERROR) << app_path.value() | 76 LOG(ERROR) << app_path.value() |
80 << " has MojoSetGLES2ControlThunks, " | 77 << " has MojoSetGLES2ControlThunks, " |
81 "but doesn't have MojoSetGLES2ImplThunks."; | 78 "but doesn't have MojoSetGLES2ImplThunks."; |
82 break; | 79 break; |
83 } | 80 } |
84 | 81 |
85 // If the application is using GLES2 extension points, register those | 82 // If the application is using GLES2 extension points, register those |
86 // thunks. Applications may use or not use any of these, so don't warn if | 83 // thunks. Applications may use or not use any of these, so don't warn if |
87 // they are missing. | 84 // they are missing. |
88 SetThunks(MojoMakeGLES2ImplChromiumTextureMailboxThunks, | 85 SetThunks(MojoMakeGLES2ImplChromiumTextureMailboxThunks, |
89 "MojoSetGLES2ImplChromiumTextureMailboxThunks", | 86 "MojoSetGLES2ImplChromiumTextureMailboxThunks", app_library); |
90 app_library); | |
91 SetThunks(MojoMakeGLES2ImplChromiumSyncPointThunks, | 87 SetThunks(MojoMakeGLES2ImplChromiumSyncPointThunks, |
92 "MojoSetGLES2ImplChromiumSyncPointThunks", | 88 "MojoSetGLES2ImplChromiumSyncPointThunks", app_library); |
93 app_library); | |
94 } | 89 } |
95 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because | 90 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because |
96 // not everything is a visual app. | 91 // not everything is a visual app. |
97 | 92 |
98 typedef MojoResult (*MojoMainFunction)(MojoHandle); | 93 typedef MojoResult (*MojoMainFunction)(MojoHandle); |
99 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | 94 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
100 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); | 95 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); |
101 if (!main_function) { | 96 if (!main_function) { |
102 LOG(ERROR) << app_path.value() << " MojoMain not found"; | 97 LOG(ERROR) << app_path.value() << " MojoMain not found"; |
103 break; | 98 break; |
104 } | 99 } |
105 // |MojoMain()| takes ownership of the service handle. | 100 // |MojoMain()| takes ownership of the service handle. |
106 MojoResult result = main_function(service_handle.release().value()); | 101 MojoResult result = main_function(service_handle.release().value()); |
107 if (result < MOJO_RESULT_OK) { | 102 if (result < MOJO_RESULT_OK) { |
108 LOG(ERROR) << app_path.value() | 103 LOG(ERROR) << app_path.value() << " MojoMain returned error(" << result |
109 << " MojoMain returned error(" << result << ")"; | 104 << ")"; |
110 } | 105 } |
111 } while (false); | 106 } while (false); |
112 | 107 |
113 return app_library; | 108 return app_library; |
114 } | 109 } |
115 | 110 |
116 } // namespace shell | 111 } // namespace shell |
117 } // namespace mojo | 112 } // namespace mojo |
OLD | NEW |