Bug 762263 - Add EGLSync - r=bjacob
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 12 Jun 2012 14:39:43 -0700
changeset 96520 26a6e89c1efafe85d733e6cd693a6a2d2379ec90
parent 96519 27d0a3ecfe952b3513acc45d187da44c280a58ed
child 96521 496ea1df8876cfdb8213787be423d574161cfdf8
push id10578
push userjgilbert@mozilla.com
push dateTue, 12 Jun 2012 21:40:30 +0000
treeherdermozilla-inbound@26a6e89c1efa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs762263
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 762263 - Add EGLSync - r=bjacob
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLDefs.h
gfx/gl/GLLibraryEGL.cpp
gfx/gl/GLLibraryEGL.h
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -70,16 +70,17 @@ static const char *sExtensionNames[] = {
     "GL_ANGLE_framebuffer_blit",
     "GL_EXT_framebuffer_multisample",
     "GL_ANGLE_framebuffer_multisample",
     "GL_OES_rgb8_rgba8",
     "GL_ARB_robustness",
     "GL_EXT_robustness",
     "GL_ARB_sync",
     "GL_OES_EGL_image",
+    "GL_OES_EGL_sync",
     nsnull
 };
 
 /*
  * XXX - we should really know the ARB/EXT variants of these
  * instead of only handling the symbol if it's exposed directly.
  */
 
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -1500,16 +1500,17 @@ public:
         ANGLE_framebuffer_blit,
         EXT_framebuffer_multisample,
         ANGLE_framebuffer_multisample,
         OES_rgb8_rgba8,
         ARB_robustness,
         EXT_robustness,
         ARB_sync,
         OES_EGL_image,
+        OES_EGL_sync,
         Extensions_Max
     };
 
     bool IsExtensionSupported(GLExtensions aKnownExtension) {
         return mAvailableExtensions[aKnownExtension];
     }
 
     void MarkExtensionUnsupported(GLExtensions aKnownExtension) {
--- a/gfx/gl/GLDefs.h
+++ b/gfx/gl/GLDefs.h
@@ -3247,9 +3247,23 @@ typedef void* GLeglImage;
 #define LOCAL_EGL_MAP_PRESERVE_PIXELS_KHR     0x30C4
 #define LOCAL_EGL_READ_SURFACE_BIT_KHR        0x0001
 #define LOCAL_EGL_WRITE_SURFACE_BIT_KHR       0x0002
 #define LOCAL_EGL_LOCK_SURFACE_BIT_KHR        0x0080
 #define LOCAL_EGL_CORE_NATIVE_ENGINE          0x305B
 #define LOCAL_EGL_READ                        0x305A
 #define LOCAL_EGL_DRAW                        0x3059
 #define LOCAL_EGL_CONTEXT_LOST                0x300E
+
+// EGL_KHR_fence_sync
+#define LOCAL_EGL_SYNC_FENCE                  0x30F9
+#define LOCAL_EGL_SYNC_TYPE                   0x30F7
+#define LOCAL_EGL_SYNC_STATUS                 0x30F1
+#define LOCAL_EGL_SYNC_CONDITION              0x30F8
+#define LOCAL_EGL_SIGNALED                    0x30F2
+#define LOCAL_EGL_UNSIGNALED                  0x30F3
+#define LOCAL_EGL_SYNC_PRIOR_COMMANDS_COMPLETE  0x30F0
+#define LOCAL_EGL_SYNC_FLUSH_COMMANDS_BIT     0x0001
+#define LOCAL_EGL_FOREVER                     0xFFFFFFFFFFFFFFFFull
+#define LOCAL_EGL_TIMEOUT_EXPIRED             0x30F5
+#define LOCAL_EGL_CONDITION_SATISFIED         0x30F6
+
 #endif
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -15,16 +15,17 @@ namespace gl {
 static const char *sExtensionNames[] = {
     "EGL_KHR_image_base",
     "EGL_KHR_image_pixmap",
     "EGL_KHR_gl_texture_2D_image",
     "EGL_KHR_lock_surface",
     "EGL_ANGLE_surface_d3d_texture_2d_share_handle",
     "EGL_EXT_create_context_robustness",
     "EGL_KHR_image",
+    "EGL_KHR_fence_sync",
     nsnull
 };
 
 #if defined(ANDROID)
 
 static PRLibrary* LoadApitraceLibrary()
 {
     static PRLibrary* sApitraceLibrary = NULL;
@@ -238,16 +239,40 @@ GLLibraryEGL::EnsureInitialized()
             NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!");
 
             MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle);
 
             mSymbols.fQuerySurfacePointerANGLE = nsnull;
         }
     }
 
+    if (IsExtensionSupported(KHR_fence_sync)) {
+        GLLibraryLoader::SymLoadStruct syncSymbols[] = {
+            { (PRFuncPtr*) &mSymbols.fCreateSync,     { "eglCreateSyncKHR",     nsnull } },
+            { (PRFuncPtr*) &mSymbols.fDestroySync,    { "eglDestroySyncKHR",    nsnull } },
+            { (PRFuncPtr*) &mSymbols.fClientWaitSync, { "eglClientWaitSyncKHR", nsnull } },
+            { (PRFuncPtr*) &mSymbols.fGetSyncAttrib,  { "eglGetSyncAttribKHR",  nsnull } },
+            { nsnull, { nsnull } }
+        };
+
+        bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary,
+                                                    &syncSymbols[0],
+                                                    lookupFunction);
+        if (!success) {
+            NS_ERROR("EGL supports KHR_fence_sync without exposing its functions!");
+
+            MarkExtensionUnsupported(KHR_fence_sync);
+
+            mSymbols.fCreateSync = nsnull;
+            mSymbols.fDestroySync = nsnull;
+            mSymbols.fClientWaitSync = nsnull;
+            mSymbols.fGetSyncAttrib = nsnull;
+        }
+    }
+
     mInitialized = true;
     reporter.SetSuccessful();
     return true;
 }
 
 void
 GLLibraryEGL::InitExtensions()
 {
--- a/gfx/gl/GLLibraryEGL.h
+++ b/gfx/gl/GLLibraryEGL.h
@@ -19,16 +19,18 @@ typedef unsigned int EGLBoolean;
 typedef unsigned int EGLenum;
 typedef void *EGLConfig;
 typedef void *EGLContext;
 typedef void *EGLDisplay;
 typedef void *EGLSurface;
 typedef void *EGLClientBuffer;
 typedef void *EGLCastToRelevantPtr;
 typedef void *EGLImage;
+typedef void *EGLSync;
+typedef uint64_t EGLTime;
 
 #if defined(XP_WIN)
 
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN 1
 #endif
 
 #include <windows.h>
@@ -60,16 +62,17 @@ typedef void *EGLNativeWindowType;
 #if defined(MOZ_X11)
 #define EGL_DEFAULT_DISPLAY  ((EGLNativeDisplayType)mozilla::DefaultXDisplay())
 #else
 #define EGL_DEFAULT_DISPLAY  ((EGLNativeDisplayType)0)
 #endif
 #define EGL_NO_CONTEXT       ((EGLContext)0)
 #define EGL_NO_DISPLAY       ((EGLDisplay)0)
 #define EGL_NO_SURFACE       ((EGLSurface)0)
+#define EGL_NO_SYNC          ((EGLSync)0)
 
 #define EGL_DISPLAY()        sEGLLibrary.Display()
 
 namespace mozilla {
 namespace gl {
 
 #ifdef DEBUG
 #undef BEFORE_GL_CALL
@@ -123,16 +126,17 @@ public:
     enum EGLExtensions {
         KHR_image_base,
         KHR_image_pixmap,
         KHR_gl_texture_2D_image,
         KHR_lock_surface,
         ANGLE_surface_d3d_texture_2d_share_handle,
         EXT_create_context_robustness,
         KHR_image,
+        KHR_fence_sync,
         Extensions_Max
     };
 
     bool IsExtensionSupported(EGLExtensions aKnownExtension) {
         return mAvailableExtensions[aKnownExtension];
     }
 
     void MarkExtensionUnsupported(EGLExtensions aKnownExtension) {
@@ -380,16 +384,48 @@ public:
     EGLBoolean fQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value)
     {
         BEFORE_GL_CALL;
         EGLBoolean b = mSymbols.fQuerySurfacePointerANGLE(dpy, surface, attribute, value);
         AFTER_GL_CALL;
         return b;
     }
 
+    EGLSync fCreateSync(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
+    {
+        BEFORE_GL_CALL;
+        EGLSync ret = mSymbols.fCreateSync(dpy, type, attrib_list);
+        AFTER_GL_CALL;
+        return ret;
+    }
+
+    EGLBoolean fDestroySync(EGLDisplay dpy, EGLSync sync)
+    {
+        BEFORE_GL_CALL;
+        EGLBoolean b = mSymbols.fDestroySync(dpy, sync);
+        AFTER_GL_CALL;
+        return b;
+    }
+
+    EGLint fClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout)
+    {
+        BEFORE_GL_CALL;
+        EGLint ret = mSymbols.fClientWaitSync(dpy, sync, flags, timeout);
+        AFTER_GL_CALL;
+        return ret;
+    }
+
+    EGLBoolean fGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
+    {
+        BEFORE_GL_CALL;
+        EGLBoolean b = mSymbols.fGetSyncAttrib(dpy, sync, attribute, value);
+        AFTER_GL_CALL;
+        return b;
+    }
+
     EGLDisplay Display() {
         return mEGLDisplay;
     }
 
     bool IsANGLE() {
         return mIsANGLE;
     }
 
@@ -483,16 +519,25 @@ public:
         pfnLockSurface fLockSurface;
         typedef EGLBoolean (GLAPIENTRY * pfnUnlockSurface)(EGLDisplay dpy, EGLSurface surface);
         pfnUnlockSurface fUnlockSurface;
         typedef EGLBoolean (GLAPIENTRY * pfnQuerySurface)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
         pfnQuerySurface fQuerySurface;
 
         typedef EGLBoolean (GLAPIENTRY * pfnQuerySurfacePointerANGLE)(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
         pfnQuerySurfacePointerANGLE fQuerySurfacePointerANGLE;
+
+        typedef EGLSync (GLAPIENTRY * pfnCreateSync)(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+        pfnCreateSync fCreateSync;
+        typedef EGLBoolean (GLAPIENTRY * pfnDestroySync)(EGLDisplay dpy, EGLSync sync);
+        pfnDestroySync fDestroySync;
+        typedef EGLint (GLAPIENTRY * pfnClientWaitSync)(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
+        pfnClientWaitSync fClientWaitSync;
+        typedef EGLBoolean (GLAPIENTRY * pfnGetSyncAttrib)(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value);
+        pfnGetSyncAttrib fGetSyncAttrib;
     } mSymbols;
 
 private:
     bool mInitialized;
     PRLibrary* mEGLLibrary;
     EGLDisplay mEGLDisplay;
 
     bool mIsANGLE;