OSDN Git Service

Implement the EGL_KHR_fence_sync in libagl
authorJesse Hall <jessehall@google.com>
Tue, 22 May 2012 17:42:56 +0000 (10:42 -0700)
committerJesse Hall <jessehall@google.com>
Tue, 22 May 2012 19:11:41 +0000 (12:11 -0700)
Implementing this in libagl allows us to start using it for
SurfaceTexture in emulator builds, which is necessary to avoid
corruption in the Browser when using the host-accelerated GL path.

Bug: 6515813
Change-Id: Icafba8687cb5d010d8d42b3866b298d2be984fc9

opengl/libagl/egl.cpp
opengl/libagl/state.cpp

index e6d065a..c31aebf 100644 (file)
@@ -796,6 +796,7 @@ static char const * const gVendorString     = "Google Inc.";
 static char const * const gVersionString    = "1.2 Android Driver 1.2.0";
 static char const * const gClientApiString  = "OpenGL_ES";
 static char const * const gExtensionsString =
+        "EGL_KHR_fence_sync "
         "EGL_KHR_image_base "
         // "KHR_image_pixmap "
         "EGL_ANDROID_image_native_buffer "
@@ -850,6 +851,14 @@ static const extention_map_t gExtentionMap[] = {
             (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, 
     { "eglDestroyImageKHR", 
             (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, 
+    { "eglCreateSyncKHR",
+            (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
+    { "eglDestroySyncKHR",
+            (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
+    { "eglClientWaitSyncKHR",
+            (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
+    { "eglGetSyncAttribKHR",
+            (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
     { "eglSetSwapRectangleANDROID", 
             (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID }, 
 };
@@ -2057,6 +2066,74 @@ EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
 }
 
 // ----------------------------------------------------------------------------
+// EGL_KHR_fence_sync
+// ----------------------------------------------------------------------------
+
+#define FENCE_SYNC_HANDLE ((EGLSyncKHR)0xFE4CE)
+
+EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type,
+        const EGLint *attrib_list)
+{
+    if (egl_display_t::is_valid(dpy) == EGL_FALSE) {
+        return setError(EGL_BAD_DISPLAY, EGL_NO_SYNC_KHR);
+    }
+
+    if (type != EGL_SYNC_FENCE_KHR ||
+            (attrib_list != NULL && attrib_list[0] != EGL_NONE)) {
+        return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SYNC_KHR);
+    }
+
+    if (eglGetCurrentContext() == EGL_NO_CONTEXT) {
+        return setError(EGL_BAD_MATCH, EGL_NO_SYNC_KHR);
+    }
+
+    // AGL is synchronous; nothing to do here.
+
+    return FENCE_SYNC_HANDLE;
+}
+
+EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
+{
+    if (sync != FENCE_SYNC_HANDLE) {
+        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+    }
+
+    return EGL_TRUE;
+}
+
+EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags,
+        EGLTimeKHR timeout)
+{
+    if (sync != FENCE_SYNC_HANDLE) {
+        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+    }
+
+    return EGL_CONDITION_SATISFIED_KHR;
+}
+
+EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
+        EGLint attribute, EGLint *value)
+{
+    if (sync != FENCE_SYNC_HANDLE) {
+        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+    }
+
+    switch (attribute) {
+    case EGL_SYNC_TYPE_KHR:
+        *value = EGL_SYNC_FENCE_KHR;
+        return EGL_TRUE;
+    case EGL_SYNC_STATUS_KHR:
+        *value = EGL_SIGNALED_KHR;
+        return EGL_TRUE;
+    case EGL_SYNC_CONDITION_KHR:
+        *value = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
+        return EGL_TRUE;
+    default:
+        return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE);
+    }
+}
+
+// ----------------------------------------------------------------------------
 // ANDROID extensions
 // ----------------------------------------------------------------------------
 
index 90e9612..4bc653a 100644 (file)
@@ -47,6 +47,7 @@ static char const * const gExtensionsString =
     //        "GL_OES_point_size_array "              // TODO
     //        "GL_OES_point_sprite "                  // TODO
     "GL_OES_EGL_image "                     // OK
+    "GL_OES_EGL_sync "                      // OK
 #ifdef GL_OES_compressed_ETC1_RGB8_texture
     "GL_OES_compressed_ETC1_RGB8_texture "  // OK
 #endif