OLD | NEW |
---|---|
(Empty) | |
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 "mojo/shell/dynamic_service_runner.h" | |
6 | |
7 #include "base/files/file_path.h" | |
8 #include "base/logging.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" | |
11 #include "mojo/public/platform/native/gles2_impl_thunks.h" | |
12 #include "mojo/public/platform/native/gles2_thunks.h" | |
13 #include "mojo/public/platform/native/system_thunks.h" | |
14 | |
15 namespace mojo { | |
16 namespace shell { | |
17 | |
18 namespace { | |
19 | |
20 template <typename Thunks> | |
21 bool SetThunks(Thunks (*make_thunks)(), | |
22 const char* function_name, | |
23 base::NativeLibrary library) { | |
24 typedef size_t (*SetThunksFn)(const Thunks* thunks); | |
25 SetThunksFn set_thunks = | |
26 reinterpret_cast<SetThunksFn>(base::GetFunctionPointerFromNativeLibrary( | |
27 library, function_name)); | |
28 if (!set_thunks) | |
29 return false; | |
30 Thunks thunks = make_thunks(); | |
31 size_t expected_size = set_thunks(&thunks); | |
32 if (expected_size > sizeof(Thunks)) { | |
33 LOG(ERROR) << "Invalid app library: expected " << function_name | |
34 << " to return thunks of size: " << expected_size; | |
35 return false; | |
36 } | |
37 return true; | |
38 } | |
39 } | |
viettrungluu
2014/10/29 23:11:43
Needs a newline above and a "// namespace" comment
DaveMoore
2014/10/30 15:32:56
Done.
| |
40 | |
41 base::NativeLibrary DynamicServiceRunner::LoadAndRunService( | |
42 const base::FilePath& app_path, | |
43 ScopedMessagePipeHandle service_handle) { | |
44 #if defined(COMPONENT_BUILD) | |
45 NOTREACHED() << "Only static builds are supported"; | |
46 return nullptr; | |
47 #endif | |
48 | |
49 DVLOG(2) << "Loading/running Mojo app in process from library: " | |
50 << app_path.value(); | |
51 base::NativeLibraryLoadError error; | |
52 base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, &error); | |
53 do { | |
54 if (!app_library) { | |
55 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() | |
56 << ")"; | |
57 break; | |
58 } | |
59 // Go shared library support requires us to initialize the runtime before we | |
60 // start running any go code. This is a temporary patch. | |
61 typedef void (*InitGoRuntimeFn)(); | |
62 InitGoRuntimeFn init_go_runtime = reinterpret_cast<InitGoRuntimeFn>( | |
63 base::GetFunctionPointerFromNativeLibrary( | |
64 app_library, "InitGoRuntime")); | |
65 if (init_go_runtime) { | |
66 DVLOG(2) << "InitGoRuntime: Initializing Go Runtime found in app"; | |
67 init_go_runtime(); | |
68 } | |
69 | |
70 if (!SetThunks(&MojoMakeSystemThunks, "MojoSetSystemThunks", app_library)) { | |
71 LOG(ERROR) << app_path.value() << " MojoSetSystemThunks not found"; | |
72 break; | |
73 } | |
74 | |
75 if (SetThunks(&MojoMakeGLES2ControlThunks, | |
76 "MojoSetGLES2ControlThunks", | |
77 app_library)) { | |
78 // If we have the control thunks, we should also have the GLES2 | |
79 // implementation thunks. | |
80 if (!SetThunks(&MojoMakeGLES2ImplThunks, | |
81 "MojoSetGLES2ImplThunks", | |
82 app_library)) { | |
83 LOG(ERROR) << app_path.value() | |
84 << " has MojoSetGLES2ControlThunks, " | |
85 "but doesn't have MojoSetGLES2ImplThunks."; | |
86 break; | |
87 } | |
88 | |
89 // If the application is using GLES2 extension points, register those | |
90 // thunks. Applications may use or not use any of these, so don't warn if | |
91 // they are missing. | |
92 SetThunks(MojoMakeGLES2ImplChromiumTextureMailboxThunks, | |
93 "MojoSetGLES2ImplChromiumTextureMailboxThunks", | |
94 app_library); | |
95 SetThunks(MojoMakeGLES2ImplChromiumSyncPointThunks, | |
96 "MojoSetGLES2ImplChromiumSyncPointThunks", | |
97 app_library); | |
98 } | |
99 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because | |
100 // not everything is a visual app. | |
101 | |
102 typedef MojoResult (*MojoMainFunction)(MojoHandle); | |
103 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | |
104 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); | |
105 if (!main_function) { | |
106 LOG(ERROR) << app_path.value() << " MojoMain not found"; | |
107 break; | |
108 } | |
109 // |MojoMain()| takes ownership of the service handle. | |
110 MojoResult result = main_function(service_handle.release().value()); | |
111 if (result < MOJO_RESULT_OK) { | |
112 LOG(ERROR) << app_path.value() | |
113 << " MojoMain returned error(" << result << ")"; | |
114 } | |
115 } while (false); | |
116 | |
117 return app_library; | |
118 } | |
119 | |
120 } // namespace shell | |
121 } // namespace mojo | |
OLD | NEW |