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

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: 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..2355c033fd2342dd29749203bc133d3dab7bda4d 100644
--- a/mojo/public/platform/nacl/libmojo.cc
+++ b/mojo/public/platform/nacl/libmojo.cc
@@ -225,3 +225,88 @@ MojoResult _MojoGetInitialHandle(MojoHandle* handle) {
return irt_mojo->_MojoGetInitialHandle(handle);
}
+bool g_irt_mgl_valid = false;
Mark Seaborn 2015/10/17 01:08:08 I realise you are copying the existing pattern for
Petr Hosek 2015/10/17 01:51:13 Done.
+struct nacl_irt_mgl g_irt_mgl;
+
+struct nacl_irt_mgl* get_irt_mgl() {
Mark Seaborn 2015/10/17 01:08:08 Chromium naming style would be GetIrtMgl()
Petr Hosek 2015/10/17 01:51:13 Done.
+ 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;
+ else
Mark Seaborn 2015/10/17 01:08:08 Nit: You could drop the 'else' since this is after
Petr Hosek 2015/10/17 01:51:13 Done.
+ 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 = get_irt_mgl();
+ 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 = get_irt_mgl();
+ if (irt_mgl != NULL)
+ irt_mgl->MGLDestroyContext(context);
+}
+
+void MGLMakeCurrent(MGLContext context) {
+ struct nacl_irt_mgl* irt_mgl = get_irt_mgl();
+ if (irt_mgl != NULL)
+ irt_mgl->MGLMakeCurrent(context);
+}
+
+MGLContext MGLGetCurrentContext(void) {
+ struct nacl_irt_mgl* irt_mgl = get_irt_mgl();
+ if (irt_mgl == NULL)
+ return MGL_NO_CONTEXT;
+ return irt_mgl->MGLGetCurrentContext();
+}
+
+MGLMustCastToProperFunctionPointerType MGLGetProcAddress(const char* name) {
+ struct nacl_irt_mgl* irt_mgl = get_irt_mgl();
+ if (irt_mgl == NULL)
+ return NULL;
+ return irt_mgl->MGLGetProcAddress(name);
+}
+
+bool g_irt_mgl_onscreen_valid = false;
+struct nacl_irt_mgl_onscreen g_irt_mgl_onscreen;
+
+struct nacl_irt_mgl_onscreen* get_irt_mgl_onscreen() {
+ 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;
+ else
+ 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 = get_irt_mgl_onscreen();
+ if (irt_mgl_onscreen != NULL)
+ irt_mgl_onscreen->MGLResizeSurface(width, height);
+}
+
+void MGLSwapBuffers(void) {
+ struct nacl_irt_mgl_onscreen* irt_mgl_onscreen = get_irt_mgl_onscreen();
+ if (irt_mgl_onscreen != NULL)
+ irt_mgl_onscreen->MGLSwapBuffers();
+}

Powered by Google App Engine
This is Rietveld 408576698