summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jni/Android.mk8
-rw-r--r--jni/jni_egl_fence.cpp42
2 files changed, 44 insertions, 6 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
index eedfa0b..a4fb844 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -6,11 +6,15 @@ LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES
LOCAL_SRC_FILES := jni_egl_fence.cpp
-LOCAL_SHARED_LIBRARIES := libcutils libEGL
+ifeq ($(TARGET_ARCH), arm)
+ LOCAL_NDK_VERSION := 5
+ LOCAL_SDK_VERSION := 9
+endif
+
+LOCAL_LDFLAGS := -llog -lEGL
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libjni_eglfence
include $(BUILD_SHARED_LIBRARY)
-
diff --git a/jni/jni_egl_fence.cpp b/jni/jni_egl_fence.cpp
index 8d557df..cf15e2f 100644
--- a/jni/jni_egl_fence.cpp
+++ b/jni/jni_egl_fence.cpp
@@ -16,29 +16,63 @@
#include "jni_egl_fence.h"
-#include <cutils/log.h>
+#include <android/log.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
+#include <string.h>
+
+#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR,"egl_fence",__VA_ARGS__)
+
+typedef EGLSyncKHR EGLAPIENTRY (*TypeEglCreateSyncKHR)(EGLDisplay dpy,
+ EGLenum type, const EGLint *attrib_list);
+typedef EGLBoolean EGLAPIENTRY (*TypeEglDestroySyncKHR)(EGLDisplay dpy,
+ EGLSyncKHR sync);
+typedef EGLint EGLAPIENTRY (*TypeEglClientWaitSyncKHR)(EGLDisplay dpy,
+ EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+static TypeEglCreateSyncKHR FuncEglCreateSyncKHR = NULL;
+static TypeEglClientWaitSyncKHR FuncEglClientWaitSyncKHR = NULL;
+static TypeEglDestroySyncKHR FuncEglDestroySyncKHR = NULL;
+static bool initialized = false;
+static bool egl_khr_fence_sync_supported = false;
+
+bool IsEglKHRFenceSyncSupported() {
+ if (!initialized) {
+ EGLDisplay display = eglGetCurrentDisplay();
+ const char* eglExtensions = eglQueryString(eglGetCurrentDisplay(), EGL_EXTENSIONS);
+ if (eglExtensions && strstr(eglExtensions, "EGL_KHR_fence_sync")) {
+ FuncEglCreateSyncKHR = (TypeEglCreateSyncKHR) eglGetProcAddress("eglCreateSyncKHR");
+ FuncEglClientWaitSyncKHR = (TypeEglClientWaitSyncKHR) eglGetProcAddress("eglClientWaitSyncKHR");
+ FuncEglDestroySyncKHR = (TypeEglDestroySyncKHR) eglGetProcAddress("eglDestroySyncKHR");
+ if (FuncEglCreateSyncKHR != NULL && FuncEglClientWaitSyncKHR != NULL
+ && FuncEglDestroySyncKHR != NULL) {
+ egl_khr_fence_sync_supported = true;
+ }
+ }
+ initialized = true;
+ }
+ return egl_khr_fence_sync_supported;
+}
void
Java_com_android_gallery3d_photoeditor_FilterStack_nativeEglSetFenceAndWait(JNIEnv* env,
jobject thiz) {
+ if (!IsEglKHRFenceSyncSupported()) return;
EGLDisplay display = eglGetCurrentDisplay();
// Create a egl fence and wait for egl to return it.
// Additional reference on egl fence sync can be found in:
// http://www.khronos.org/registry/vg/extensions/KHR/EGL_KHR_fence_sync.txt
- EGLSyncKHR fence = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
+ EGLSyncKHR fence = FuncEglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
if (fence == EGL_NO_SYNC_KHR) {
return;
}
- EGLint result = eglClientWaitSyncKHR(display,
+ EGLint result = FuncEglClientWaitSyncKHR(display,
fence,
EGL_SYNC_FLUSH_COMMANDS_BIT_KHR,
EGL_FOREVER_KHR);
if (result == EGL_FALSE) {
ALOGE("EGL FENCE: error waiting for fence: %#x", eglGetError());
}
- eglDestroySyncKHR(display, fence);
+ FuncEglDestroySyncKHR(display, fence);
}