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

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

Issue 1413683003: Expose MGL interface through NaCl IRT (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Move MGL IRT functions to a separate file 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/mgl_irt.cc
diff --git a/mojo/public/platform/nacl/mgl_irt.cc b/mojo/public/platform/nacl/mgl_irt.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ce1c6b0c782f02bf52d2db4d261d772cc8cb324
--- /dev/null
+++ b/mojo/public/platform/nacl/mgl_irt.cc
@@ -0,0 +1,119 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/platform/nacl/mgl_irt.h"
+#include "native_client/src/untrusted/irt/irt.h"
+
+namespace {
+
+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;
Mark Seaborn 2015/10/21 04:55:49 This can become 'nullptr' in Chromium-style code
Petr Hosek 2015/10/21 16:33:21 Done.
+ 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;
+}
+
+}
+
+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)
Mark Seaborn 2015/10/21 04:55:49 In Chromium-style code you can just do "if (!irt_m
Petr Hosek 2015/10/21 16:33:21 Done.
+ 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