Expose SignalSyncPoint through MGL api

This is the last bit of functionality missing relative to c/gles2/

R=viettrungluu@chromium.org

Review URL: https://codereview.chromium.org/1320833003 .
diff --git a/mojo/gles2/control_thunks_impl.cc b/mojo/gles2/control_thunks_impl.cc
index d428607..d780705 100644
--- a/mojo/gles2/control_thunks_impl.cc
+++ b/mojo/gles2/control_thunks_impl.cc
@@ -59,7 +59,6 @@
 }
 
 void ControlThunksImpl::SignalSyncPoint(
-    MojoGLES2Context context,
     uint32_t sync_point,
     MojoGLES2SignalSyncPointCallback callback,
     void* closure) {
diff --git a/mojo/gles2/control_thunks_impl.h b/mojo/gles2/control_thunks_impl.h
index 0543adf..fd9a294 100644
--- a/mojo/gles2/control_thunks_impl.h
+++ b/mojo/gles2/control_thunks_impl.h
@@ -47,8 +47,7 @@
 
   void* GetGLES2Interface(MojoGLES2Context context);
 
-  void SignalSyncPoint(MojoGLES2Context context,
-                       uint32_t sync_point,
+  void SignalSyncPoint(uint32_t sync_point,
                        MojoGLES2SignalSyncPointCallback callback,
                        void* closure);
 
diff --git a/mojo/gles2/gles2_impl.cc b/mojo/gles2/gles2_impl.cc
index a107564..e198246 100644
--- a/mojo/gles2/gles2_impl.cc
+++ b/mojo/gles2/gles2_impl.cc
@@ -44,8 +44,8 @@
                               uint32_t sync_point,
                               MojoGLES2SignalSyncPointCallback callback,
                               void* closure) {
-  gles2::ControlThunksImpl::Get()->SignalSyncPoint(context, sync_point,
-                                                   callback, closure);
+  gles2::ControlThunksImpl::Get()->SignalSyncPoint(sync_point, callback,
+                                                   closure);
 }
 
 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS)             \
diff --git a/mojo/gles2/mgl_impl.cc b/mojo/gles2/mgl_impl.cc
index 95eb093..96861a5 100644
--- a/mojo/gles2/mgl_impl.cc
+++ b/mojo/gles2/mgl_impl.cc
@@ -35,6 +35,13 @@
   return gles2::ControlThunksImpl::Get()->GetCurrentContext();
 }
 
+void MGLSignalSyncPoint(uint32_t sync_point,
+                        MGLSignalSyncPointCallback callback,
+                        void* closure) {
+  gles2::ControlThunksImpl::Get()->SignalSyncPoint(sync_point, callback,
+                                                   closure);
+}
+
 void MGLResizeSurface(uint32_t width, uint32_t height) {
   return gles2::ControlThunksImpl::Get()->ResizeSurface(width, height);
 }
diff --git a/mojo/gpu/mojo_context_support.cc b/mojo/gpu/mojo_context_support.cc
index 1fe2973..40e2df8 100644
--- a/mojo/gpu/mojo_context_support.cc
+++ b/mojo/gpu/mojo_context_support.cc
@@ -6,6 +6,7 @@
 
 #include "base/callback.h"
 #include "base/logging.h"
+#include "mojo/public/c/gpu/MGL/mgl_signal_sync_point.h"
 
 namespace mojo {
 namespace {
@@ -26,8 +27,8 @@
 
 void MojoContextSupport::SignalSyncPoint(uint32 sync_point,
                                          const base::Closure& callback) {
-  MojoGLES2SignalSyncPoint(context_, sync_point, &RunAndDeleteCallback,
-                           new base::Closure(callback));
+  MGLSignalSyncPoint(sync_point, &RunAndDeleteCallback,
+                     new base::Closure(callback));
 }
 
 void MojoContextSupport::SignalQuery(uint32 query,
diff --git a/mojo/public/c/gpu/BUILD.gn b/mojo/public/c/gpu/BUILD.gn
index afab7a1..51fa69a 100644
--- a/mojo/public/c/gpu/BUILD.gn
+++ b/mojo/public/c/gpu/BUILD.gn
@@ -14,6 +14,7 @@
 
   deps = [
     ":MGL",
+    ":MGL_signal_sync_point",
     ":GLES2",
     "../../platform/native:mgl_thunks",
     "../../platform/native:gles2",
@@ -50,6 +51,16 @@
   ]
 }
 
+mojo_sdk_source_set("MGL_signal_sync_point") {
+  sources = [
+    "MGL/mgl_signal_sync_point.h",
+  ]
+
+  public_deps = [
+    ":MGL",
+  ]
+}
+
 mojo_sdk_source_set("GLES2") {
   sources = [
     "GLES2/gl2.h",
diff --git a/mojo/public/c/gpu/MGL/mgl_signal_sync_point.h b/mojo/public/c/gpu/MGL/mgl_signal_sync_point.h
new file mode 100644
index 0000000..c7a40dd
--- /dev/null
+++ b/mojo/public/c/gpu/MGL/mgl_signal_sync_point.h
@@ -0,0 +1,32 @@
+// 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.
+
+// Note: This header should be compilable as C.
+
+#ifndef MOJO_PUBLIC_C_GPU_MGL_MGL_SIGNAL_SYNC_POINT_H_
+#define MOJO_PUBLIC_C_GPU_MGL_MGL_SIGNAL_SYNC_POINT_H_
+
+#include <stdint.h>
+
+#include "mojo/public/c/gpu/MGL/mgl_types.h"
+#include "mojo/public/c/system/types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*MGLSyncPointCallback)(void* closure);
+
+// MGLSignalSyncPoint signals the given sync point in the current context and
+// invokes |callback| when the service side acknowleges that the sync point has
+// been passed.
+void MGLSignalSyncPoint(uint32_t sync_point,
+                        MGLSignalSyncPointCallback callback,
+                        void* closure);
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
+#endif  // MOJO_PUBLIC_C_GPU_MGL_MGL_SIGNAL_SYNC_POINT_H_
diff --git a/mojo/public/platform/native/BUILD.gn b/mojo/public/platform/native/BUILD.gn
index 3e849a0..f8447ce 100644
--- a/mojo/public/platform/native/BUILD.gn
+++ b/mojo/public/platform/native/BUILD.gn
@@ -111,11 +111,16 @@
 
 mojo_sdk_source_set("mgl_thunks") {
   sources = [
+    "mgl_signal_sync_point_thunks.c",
+    "mgl_signal_sync_point_thunks.h",
     "mgl_thunks.c",
     "mgl_thunks.h",
   ]
 
-  mojo_sdk_deps = [ "mojo/public/c/gpu:MGL" ]
+  mojo_sdk_deps = [
+    "mojo/public/c/gpu:MGL",
+    "mojo/public/c/gpu:MGL_signal_sync_point",
+  ]
 }
 
 mojo_sdk_source_set("mgl_onscreen_thunks") {
diff --git a/mojo/public/platform/native/mgl_signal_sync_point_thunks.c b/mojo/public/platform/native/mgl_signal_sync_point_thunks.c
new file mode 100644
index 0000000..0ef073e
--- /dev/null
+++ b/mojo/public/platform/native/mgl_signal_sync_point_thunks.c
@@ -0,0 +1,25 @@
+// 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/native/mgl_signal_sync_point_thunks.h"
+
+#include <assert.h>
+
+#include "mojo/public/platform/native/thunk_export.h"
+
+static struct MGLSignalSyncPointThunks g_signal_sync_point_thunks = {0};
+
+void MGLSignalSyncPoint(uint32_t sync_point,
+                        MGLSignalSyncPointCallback callback,
+                        void* closure) {
+  assert(g_signal_sync_point_thunks.MGLSignalSyncPoint);
+  g_signal_sync_point_thunks.MGLSignalSyncPoint(sync_point, callback, closure);
+}
+
+THUNK_EXPORT size_t MojoSetMGLSignalSyncPointThunks(
+    const struct MGLSignalSyncPointThunks* mgl_signal_sync_point_thunks) {
+  if (mgl_signal_sync_point_thunks->size >= sizeof(g_signal_sync_point_thunks))
+    g_signal_sync_point_thunks = *mgl_signal_sync_point_thunks;
+  return sizeof(g_signal_sync_point_thunks);
+}
diff --git a/mojo/public/platform/native/mgl_signal_sync_point_thunks.h b/mojo/public/platform/native/mgl_signal_sync_point_thunks.h
new file mode 100644
index 0000000..c6f2ebd
--- /dev/null
+++ b/mojo/public/platform/native/mgl_signal_sync_point_thunks.h
@@ -0,0 +1,50 @@
+// 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.
+
+#ifndef MOJO_PUBLIC_PLATFORM_NATIVE_MGL_SIGNAL_SYNC_POINT_THUNKS_H_
+#define MOJO_PUBLIC_PLATFORM_NATIVE_MGL_SIGNAL_SYNC_POINT_THUNKS_H_
+
+#include <stddef.h>
+
+#include "mojo/public/c/gpu/MGL/mgl_signal_sync_point.h"
+
+// Structure used to bind the MGL signal sync point interface DSO to those
+// of the embedder.
+//
+// This is the ABI between the embedder and the DSO. It can only have new
+// functions added to the end. No other changes are supported.
+#pragma pack(push, 8)
+struct MGLSignalSyncPointThunks {
+  size_t size;  // Should be set to sizeof(MGLSignalSyncPointThunks).
+
+  void (*MGLSignalSyncPoint)(uint32_t sync_point,
+                             MGLSignalSyncPointCallback callback,
+                             void* lost_callback_closure);
+};
+#pragma pack(pop)
+
+#ifdef __cplusplus
+// Intended to be called from the embedder. Returns an object initialized to
+// contain pointers to each of the embedder's MGLSignalSyncPointThunks
+// functions.
+inline struct MGLSignalSyncPointThunks MojoMakeMGLSignalSyncPointThunks() {
+  struct MGLSignalSyncPointThunks mgl_thunks = {
+      sizeof(struct MGLSignalSyncPointThunks), MGLSignalSyncPoint,
+  };
+
+  return mgl_thunks;
+}
+#endif  // __cplusplus
+
+// Use this type for the function found by dynamically discovering it in
+// a DSO linked with mojo_system. For example:
+// MojoSetMGLSignalSyncPointThunksFn mojo_set_gles2_thunks_fn =
+//     reinterpret_cast<MojoSetMGLSignalSyncPointThunksFn>(
+//         app_library.GetFunctionPointer("MojoSetMGLSignalSyncPointThunks"));
+// The expected size of |mgl_thunks| is returned.
+// The contents of |mgl_thunks| are copied.
+typedef size_t (*MojoSetMGLSignalSyncPointThunksFn)(
+    const struct MGLSignalSyncPointThunks* mgl_signal_sync_point_thunks);
+
+#endif  // MOJO_PUBLIC_PLATFORM_NATIVE_MGL_SIGNAL_SYNC_POINT_THUNKS_H_
diff --git a/shell/native_application_support.cc b/shell/native_application_support.cc
index 2e2ea17..90f4aa8 100644
--- a/shell/native_application_support.cc
+++ b/shell/native_application_support.cc
@@ -23,6 +23,7 @@
 #include "mojo/public/platform/native/gles2_impl_thunks.h"
 #include "mojo/public/platform/native/gles2_thunks.h"
 #include "mojo/public/platform/native/mgl_onscreen_thunks.h"
+#include "mojo/public/platform/native/mgl_signal_sync_point_thunks.h"
 #include "mojo/public/platform/native/mgl_thunks.h"
 #include "mojo/public/platform/native/system_impl_private_thunks.h"
 #include "mojo/public/platform/native/system_thunks.h"
@@ -114,14 +115,14 @@
             "MojoSetGLES2ImplCHROMIUMTextureMailboxThunks", app_library);
 
   if (SetThunks(MojoMakeMGLThunks, "MojoSetMGLThunks", app_library)) {
-    // TODO(jamesr): We should only need to expose these on apps that need to
-    // draw to the screen like the system compositor.
+    // TODO(jamesr): We should only need to expose the onscreen thunks to apps
+    // that need to draw to the screen like the system compositor.
     SetThunks(MojoMakeMGLOnscreenThunks, "MojoSetMGLOnscreenThunks",
               app_library);
-  }
 
-  // Unlike system thunks, we don't warn on a lack of GLES2 thunks because
-  // not everything is a visual app.
+    SetThunks(MojoMakeMGLSignalSyncPointThunks,
+              "MojoSetMGLSignalSyncPointThunks", app_library);
+  }
 
   typedef MojoResult (*MojoMainFunction)(MojoHandle);
   MojoMainFunction main_function = reinterpret_cast<MojoMainFunction>(