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 | |
40 } // namespace | |
41 | |
42 base::NativeLibrary DynamicServiceRunner::LoadAndRunService( | |
43 const base::FilePath& app_path, | |
44 ScopedMessagePipeHandle service_handle) { | |
45 DVLOG(2) << "Loading/running Mojo app in process from library: " | |
46 << app_path.value(); | |
47 base::NativeLibraryLoadError error; | |
48 base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, &error); | |
49 do { | |
50 if (!app_library) { | |
51 LOG(ERROR) << "Failed to load app library (error: " << error.ToString() | |
52 << ")"; | |
53 break; | |
54 } | |
55 // Go shared library support requires us to initialize the runtime before we | |
56 // start running any go code. This is a temporary patch. | |
57 typedef void (*InitGoRuntimeFn)(); | |
58 InitGoRuntimeFn init_go_runtime = reinterpret_cast<InitGoRuntimeFn>( | |
59 base::GetFunctionPointerFromNativeLibrary( | |
60 app_library, "InitGoRuntime")); | |
61 if (init_go_runtime) { | |
62 DVLOG(2) << "InitGoRuntime: Initializing Go Runtime found in app"; | |
63 init_go_runtime(); | |
64 } | |
65 | |
66 if (!SetThunks(&MojoMakeSystemThunks, "MojoSetSystemThunks", app_library)) { | |
67 LOG(ERROR) << app_path.value() << " MojoSetSystemThunks not found"; | |
68 break; | |
69 } | |
70 | |
71 if (SetThunks(&MojoMakeGLES2ControlThunks, | |
72 "MojoSetGLES2ControlThunks", | |
73 app_library)) { | |
74 // If we have the control thunks, we should also have the GLES2 | |
75 // implementation thunks. | |
76 if (!SetThunks(&MojoMakeGLES2ImplThunks, | |
77 "MojoSetGLES2ImplThunks", | |
78 app_library)) { | |
79 LOG(ERROR) << app_path.value() | |
80 << " has MojoSetGLES2ControlThunks, " | |
81 "but doesn't have MojoSetGLES2ImplThunks."; | |
82 break; | |
83 } | |
84 | |
85 // 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 | |
87 // they are missing. | |
88 SetThunks(MojoMakeGLES2ImplChromiumTextureMailboxThunks, | |
89 "MojoSetGLES2ImplChromiumTextureMailboxThunks", | |
90 app_library); | |
91 SetThunks(MojoMakeGLES2ImplChromiumSyncPointThunks, | |
92 "MojoSetGLES2ImplChromiumSyncPointThunks", | |
93 app_library); | |
94 } | |
95 // Unlike system thunks, we don't warn on a lack of GLES2 thunks because | |
96 // not everything is a visual app. | |
97 | |
98 typedef MojoResult (*MojoMainFunction)(MojoHandle); | |
99 MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>( | |
100 base::GetFunctionPointerFromNativeLibrary(app_library, "MojoMain")); | |
101 if (!main_function) { | |
102 LOG(ERROR) << app_path.value() << " MojoMain not found"; | |
103 break; | |
104 } | |
105 // |MojoMain()| takes ownership of the service handle. | |
106 MojoResult result = main_function(service_handle.release().value()); | |
107 if (result < MOJO_RESULT_OK) { | |
108 LOG(ERROR) << app_path.value() | |
109 << " MojoMain returned error(" << result << ")"; | |
110 } | |
111 } while (false); | |
112 | |
113 return app_library; | |
114 } | |
115 | |
116 } // namespace shell | |
117 } // namespace mojo | |
OLD | NEW |