Chromium Code Reviews| Index: mojo/public/platform/nacl/libmojo.cc |
| diff --git a/mojo/public/platform/nacl/libmojo.cc b/mojo/public/platform/nacl/libmojo.cc |
| index 391f6fb3665dbbaff380acf8593b8606d8d28b34..5bd51d3db1dc6e774b634748a801be3063585f83 100644 |
| --- a/mojo/public/platform/nacl/libmojo.cc |
| +++ b/mojo/public/platform/nacl/libmojo.cc |
| @@ -17,6 +17,8 @@ |
| // from there. |
| #define NACL_MOJO_DESC (NACL_CHROME_DESC_BASE + 3) |
| +namespace { |
| + |
| bool g_irt_mojo_valid = false; |
| struct nacl_irt_mojo g_irt_mojo; |
| @@ -26,12 +28,13 @@ struct nacl_irt_mojo* get_irt_mojo() { |
| sizeof(g_irt_mojo)); |
| if (rc != sizeof(g_irt_mojo)) |
| return NULL; |
| - else |
| - g_irt_mojo_valid = true; |
| + g_irt_mojo_valid = true; |
| } |
| return &g_irt_mojo; |
| } |
| +} |
| + |
| MojoResult MojoCreateSharedBuffer( |
| const struct MojoCreateSharedBufferOptions* options, |
| uint64_t num_bytes, |
| @@ -225,3 +228,123 @@ MojoResult _MojoGetInitialHandle(MojoHandle* handle) { |
| return irt_mojo->_MojoGetInitialHandle(handle); |
| } |
| +namespace { |
| + |
|
Sean Klein
2015/10/17 02:03:14
Is there a reason why you made a bunch of anonymou
Petr Hosek
2015/10/20 00:11:32
Done.
|
| +bool g_irt_mgl_valid = false; |
| +struct nacl_irt_mgl g_irt_mgl; |
| + |
| +struct nacl_irt_mgl* GetIrtMGL() { |
| + if (!g_irt_mgl_valid) { |
| + size_t rc = nacl_interface_query(NACL_IRT_MGL_v0_1, &g_irt_mgl, |
| + sizeof(g_irt_mgl)); |
| + if (rc != sizeof(g_irt_mgl)) |
| + return NULL; |
| + g_irt_mgl_valid = true; |
| + } |
| + return &g_irt_mgl; |
| +} |
| + |
| +} |
| + |
| +MGLContext MGLCreateContext(MGLOpenGLAPIVersion version, |
| + MojoHandle command_buffer_handle, |
| + MGLContext share_group, |
| + MGLContextLostCallback lost_callback, |
| + void* lost_callback_closure, |
| + const struct MojoAsyncWaiter* async_waiter) { |
| + struct nacl_irt_mgl* irt_mgl = GetIrtMGL(); |
| + if (irt_mgl == NULL) |
| + return MGL_NO_CONTEXT; |
| + return irt_mgl->MGLCreateContext(version, |
| + command_buffer_handle, |
| + share_group, |
| + lost_callback, |
| + lost_callback_closure, |
| + async_waiter); |
| +} |
| + |
| +void MGLDestroyContext(MGLContext context) { |
| + struct nacl_irt_mgl* irt_mgl = GetIrtMGL(); |
| + if (irt_mgl != NULL) |
| + irt_mgl->MGLDestroyContext(context); |
| +} |
| + |
| +void MGLMakeCurrent(MGLContext context) { |
| + struct nacl_irt_mgl* irt_mgl = GetIrtMGL(); |
| + if (irt_mgl != NULL) |
| + irt_mgl->MGLMakeCurrent(context); |
| +} |
| + |
| +MGLContext MGLGetCurrentContext(void) { |
| + struct nacl_irt_mgl* irt_mgl = GetIrtMGL(); |
| + if (irt_mgl == NULL) |
| + return MGL_NO_CONTEXT; |
| + return irt_mgl->MGLGetCurrentContext(); |
| +} |
| + |
| +MGLMustCastToProperFunctionPointerType MGLGetProcAddress(const char* name) { |
| + struct nacl_irt_mgl* irt_mgl = GetIrtMGL(); |
| + if (irt_mgl == NULL) |
| + return NULL; |
| + return irt_mgl->MGLGetProcAddress(name); |
| +} |
| + |
| +namespace { |
| + |
| +bool g_irt_mgl_onscreen_valid = false; |
| +struct nacl_irt_mgl_onscreen g_irt_mgl_onscreen; |
| + |
| +struct nacl_irt_mgl_onscreen* GetIrtMGLOnScreen() { |
| + if (!g_irt_mgl_onscreen_valid) { |
| + size_t rc = nacl_interface_query(NACL_IRT_MGL_ONSCREEN_v0_1, |
| + &g_irt_mgl_onscreen, |
| + sizeof(g_irt_mgl_onscreen)); |
| + if (rc != sizeof(g_irt_mgl_onscreen)) |
| + return NULL; |
| + g_irt_mgl_onscreen_valid = true; |
| + } |
| + return &g_irt_mgl_onscreen; |
| +} |
| + |
| +} |
| + |
| +void MGLResizeSurface(uint32_t width, uint32_t height) { |
| + struct nacl_irt_mgl_onscreen* irt_mgl_onscreen = GetIrtMGLOnScreen(); |
| + if (irt_mgl_onscreen != NULL) |
| + irt_mgl_onscreen->MGLResizeSurface(width, height); |
| +} |
| + |
| +void MGLSwapBuffers(void) { |
| + struct nacl_irt_mgl_onscreen* irt_mgl_onscreen = GetIrtMGLOnScreen(); |
| + if (irt_mgl_onscreen != NULL) |
| + irt_mgl_onscreen->MGLSwapBuffers(); |
| +} |
| + |
| +namespace { |
| + |
| +bool g_irt_mgl_signal_sync_point_valid = false; |
| +struct nacl_irt_mgl_signal_sync_point g_irt_mgl_signal_sync_point; |
| + |
| +struct nacl_irt_mgl_signal_sync_point* GetIrtMGLSignalSyncPoint() { |
| + if (!g_irt_mgl_signal_sync_point_valid) { |
| + size_t rc = nacl_interface_query(NACL_IRT_MGL_SIGNAL_SYNC_POINT_v0_1, |
| + &g_irt_mgl_signal_sync_point, |
| + sizeof(g_irt_mgl_signal_sync_point)); |
| + if (rc != sizeof(g_irt_mgl_signal_sync_point)) |
| + return NULL; |
| + g_irt_mgl_signal_sync_point_valid = true; |
| + } |
| + return &g_irt_mgl_signal_sync_point; |
| +} |
| + |
| +} |
| + |
| +void MGLSignalSyncPoint(uint32_t sync_point, |
| + MGLSignalSyncPointCallback callback, |
| + void* closure) { |
| + struct nacl_irt_mgl_signal_sync_point *irt_mgl_signal_sync_point = |
| + GetIrtMGLSignalSyncPoint(); |
| + if (irt_mgl_signal_sync_point != NULL) |
| + irt_mgl_signal_sync_point->MGLSignalSyncPoint( |
| + sync_point, callback, closure); |
| +} |