Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Unified Diff: mojo/public/platform/nacl/libmojo.cc

Issue 1413683003: Expose MGL interface through NaCl IRT (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Combine anonymous namespaces into one Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8b05e27cca6c201afb9ead1cb06e6e332c09dc6e 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,57 @@ 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;
}
+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;
+}
+
+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;
+}
+
+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;
+}
+
+}
+
MojoResult MojoCreateSharedBuffer(
const struct MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
@@ -225,3 +272,67 @@ MojoResult _MojoGetInitialHandle(MojoHandle* handle) {
return irt_mojo->_MojoGetInitialHandle(handle);
}
+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);
+}
+
+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();
+}
+
+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);
+}

Powered by Google App Engine
This is Rietveld 408576698