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/in_process_dynamic_service_runner.h" | 5 #include "mojo/shell/in_process_dynamic_service_runner.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "mojo/public/platform/native/gles2_impl_chromium_sync_point_thunks.h" |
| 13 #include "mojo/public/platform/native/gles2_impl_chromium_texture_mailbox_thunks
.h" |
| 14 #include "mojo/public/platform/native/gles2_impl_thunks.h" |
12 #include "mojo/public/platform/native/gles2_thunks.h" | 15 #include "mojo/public/platform/native/gles2_thunks.h" |
13 #include "mojo/public/platform/native/system_thunks.h" | 16 #include "mojo/public/platform/native/system_thunks.h" |
14 | 17 |
15 namespace mojo { | 18 namespace mojo { |
16 namespace shell { | 19 namespace shell { |
17 | 20 |
| 21 namespace { |
| 22 |
| 23 template <typename Thunks> |
| 24 bool SetThunks(Thunks (*make_thunks)(), |
| 25 const char* function_name, |
| 26 base::ScopedNativeLibrary* library) { |
| 27 typedef size_t (*SetThunksFn)(const Thunks* thunks); |
| 28 SetThunksFn set_thunks = |
| 29 reinterpret_cast<SetThunksFn>(library->GetFunctionPointer(function_name)); |
| 30 if (!set_thunks) |
| 31 return false; |
| 32 Thunks thunks = make_thunks(); |
| 33 size_t expected_size = set_thunks(&thunks); |
| 34 if (expected_size > sizeof(Thunks)) { |
| 35 LOG(ERROR) << "Invalid app library: expected " << function_name |
| 36 << " to return thunks of size: " << expected_size; |
| 37 return false; |
| 38 } |
| 39 return true; |
| 40 } |
| 41 } |
| 42 |
18 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( | 43 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner( |
19 Context* context) | 44 Context* context) |
20 : keep_alive_(context) { | 45 : keep_alive_(context) { |
21 } | 46 } |
22 | 47 |
23 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { | 48 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { |
24 if (thread_) { | 49 if (thread_) { |
25 DCHECK(thread_->HasBeenStarted()); | 50 DCHECK(thread_->HasBeenStarted()); |
26 DCHECK(!thread_->HasBeenJoined()); | 51 DCHECK(!thread_->HasBeenJoined()); |
27 thread_->Join(); | 52 thread_->Join(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 84 |
60 do { | 85 do { |
61 base::NativeLibraryLoadError error; | 86 base::NativeLibraryLoadError error; |
62 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); | 87 app_library_.Reset(base::LoadNativeLibrary(app_path_, &error)); |
63 if (!app_library_.is_valid()) { | 88 if (!app_library_.is_valid()) { |
64 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() | 89 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() |
65 << ")"; | 90 << ")"; |
66 break; | 91 break; |
67 } | 92 } |
68 | 93 |
69 MojoSetSystemThunksFn mojo_set_system_thunks_fn = | 94 if (!SetThunks( |
70 reinterpret_cast<MojoSetSystemThunksFn>(app_library_.GetFunctionPointer( | 95 &MojoMakeSystemThunks, "MojoSetSystemThunks", &app_library_)) { |
71 "MojoSetSystemThunks")); | |
72 if (mojo_set_system_thunks_fn) { | |
73 MojoSystemThunks system_thunks = MojoMakeSystemThunks(); | |
74 size_t expected_size = mojo_set_system_thunks_fn(&system_thunks); | |
75 if (expected_size > sizeof(MojoSystemThunks)) { | |
76 LOG(ERROR) | |
77 << "Invalid app library: expected MojoSystemThunks size: " | |
78 << expected_size; | |
79 break; | |
80 } | |
81 } else { | |
82 // In the component build, Mojo Apps link against mojo_system_impl. | 96 // In the component build, Mojo Apps link against mojo_system_impl. |
83 #if !defined(COMPONENT_BUILD) | 97 #if !defined(COMPONENT_BUILD) |
84 // Strictly speaking this is not required, but it's very unusual to have | 98 // Strictly speaking this is not required, but it's very unusual to have |
85 // an app that doesn't require the basic system library. | 99 // an app that doesn't require the basic system library. |
86 LOG(WARNING) << "MojoSetSystemThunks not found in app library"; | 100 LOG(WARNING) << "MojoSetSystemThunks not found in app library"; |
87 #endif | 101 #endif |
88 } | 102 } |
89 | 103 |
90 MojoSetGLES2ControlThunksFn mojo_set_gles2_control_thunks_fn = | 104 if (SetThunks(&MojoMakeGLES2ControlThunks, |
91 reinterpret_cast<MojoSetGLES2ControlThunksFn>( | 105 "MojoSetGLES2ControlThunks", |
92 app_library_.GetFunctionPointer("MojoSetGLES2ControlThunks")); | 106 &app_library_)) { |
93 if (mojo_set_gles2_control_thunks_fn) { | |
94 MojoGLES2ControlThunks gles2_control_thunks = | |
95 MojoMakeGLES2ControlThunks(); | |
96 size_t expected_size = mojo_set_gles2_control_thunks_fn( | |
97 &gles2_control_thunks); | |
98 if (expected_size > sizeof(MojoGLES2ControlThunks)) { | |
99 LOG(ERROR) | |
100 << "Invalid app library: expected MojoGLES2ControlThunks size: " | |
101 << expected_size; | |
102 break; | |
103 } | |
104 | |
105 // If we have the control thunks, we probably also have the | 107 // If we have the control thunks, we probably also have the |
106 // GLES2 implementation thunks. | 108 // GLES2 implementation thunks. |
107 MojoSetGLES2ImplThunksFn mojo_set_gles2_impl_thunks_fn = | 109 if (!SetThunks(&MojoMakeGLES2ImplThunks, |
108 reinterpret_cast<MojoSetGLES2ImplThunksFn>( | 110 "MojoSetGLES2ImplThunks", |
109 app_library_.GetFunctionPointer("MojoSetGLES2ImplThunks")); | 111 &app_library_)) { |
110 if (mojo_set_gles2_impl_thunks_fn) { | |
111 MojoGLES2ImplThunks gles2_impl_thunks = | |
112 MojoMakeGLES2ImplThunks(); | |
113 size_t expected_size = mojo_set_gles2_impl_thunks_fn( | |
114 &gles2_impl_thunks); | |
115 if (expected_size > sizeof(MojoGLES2ImplThunks)) { | |
116 LOG(ERROR) | |
117 << "Invalid app library: expected MojoGLES2ImplThunks size: " | |
118 << expected_size; | |
119 break; | |
120 } | |
121 } else { | |
122 // In the component build, Mojo Apps link against mojo_gles2_impl. | 112 // In the component build, Mojo Apps link against mojo_gles2_impl. |
123 #if !defined(COMPONENT_BUILD) | 113 #if !defined(COMPONENT_BUILD) |
124 // Warn on this really weird case: The library requires the GLES2 | 114 // Warn on this really weird case: The library requires the GLES2 |
125 // control functions, but doesn't require the GLES2 implementation. | 115 // control functions, but doesn't require the GLES2 implementation. |
126 LOG(WARNING) << "App library has MojoSetGLES2ControlThunks, but " | 116 LOG(WARNING) << "App library has MojoSetGLES2ControlThunks, but " |
127 "doesn't have MojoSetGLES2ImplThunks."; | 117 "doesn't have MojoSetGLES2ImplThunks."; |
128 #endif | 118 #endif |
129 } | 119 } |
| 120 |
| 121 // If the application is using GLES2 extension points, register those |
| 122 // thunks. Applications may use or not use any of these, so don't warn if |
| 123 // they are missing. |
| 124 SetThunks(MojoMakeGLES2ImplChromiumTextureMailboxThunks, |
| 125 "MojoSetGLES2ImplChromiumTextureMailboxThunks", |
| 126 &app_library_); |
| 127 SetThunks(MojoMakeGLES2ImplChromiumSyncPointThunks, |
| 128 "MojoSetGLES2ImplChromiumSyncPointThunks", |
| 129 &app_library_); |
130 } | 130 } |
131 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because | 131 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because |
132 // not everything is a visual app. | 132 // not everything is a visual app. |
133 | 133 |
134 typedef MojoResult (*MojoMainFunction)(MojoHandle); | 134 typedef MojoResult (*MojoMainFunction)(MojoHandle); |
135 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | 135 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( |
136 app_library_.GetFunctionPointer("MojoMain")); | 136 app_library_.GetFunctionPointer("MojoMain")); |
137 if (!main_function) { | 137 if (!main_function) { |
138 LOG(ERROR) << "Entrypoint MojoMain not found"; | 138 LOG(ERROR) << "Entrypoint MojoMain not found"; |
139 break; | 139 break; |
140 } | 140 } |
141 | 141 |
142 // |MojoMain()| takes ownership of the service handle. | 142 // |MojoMain()| takes ownership of the service handle. |
143 MojoResult result = main_function(service_handle_.release().value()); | 143 MojoResult result = main_function(service_handle_.release().value()); |
144 if (result < MOJO_RESULT_OK) | 144 if (result < MOJO_RESULT_OK) |
145 LOG(ERROR) << "MojoMain returned an error: " << result; | 145 LOG(ERROR) << "MojoMain returned an error: " << result; |
146 } while (false); | 146 } while (false); |
147 | 147 |
148 bool success = app_completed_callback_runner_.Run(); | 148 bool success = app_completed_callback_runner_.Run(); |
149 app_completed_callback_runner_.Reset(); | 149 app_completed_callback_runner_.Reset(); |
150 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; | 150 LOG_IF(ERROR, !success) << "Failed post run app_completed_callback"; |
151 } | 151 } |
152 | 152 |
153 } // namespace shell | 153 } // namespace shell |
154 } // namespace mojo | 154 } // namespace mojo |
OLD | NEW |