OSDN Git Service

Fix b/6590795 dejank photo effect slider
authorRuei-sung Lin <rslin@google.com>
Thu, 31 May 2012 18:59:31 +0000 (11:59 -0700)
committerRuei-sung Lin <rslin@google.com>
Sat, 2 Jun 2012 03:14:58 +0000 (20:14 -0700)
Change-Id: I14737bd01361b58c6bd4af19957d514368cc19ea

Android.mk
jni/Android.mk [new file with mode: 0644]
jni/jni_egl_fence.cpp [new file with mode: 0644]
jni/jni_egl_fence.h [new file with mode: 0644]
src/com/android/gallery3d/photoeditor/FilterStack.java

index 6584c4a..ea71b39 100644 (file)
@@ -1,4 +1,5 @@
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_TAGS := optional
@@ -19,18 +20,21 @@ LOCAL_OVERRIDES_PACKAGES := Gallery Gallery3D GalleryNew3D
 
 #LOCAL_SDK_VERSION := current
 
-LOCAL_JNI_SHARED_LIBRARIES := libjni_mosaic
+LOCAL_JNI_SHARED_LIBRARIES := libjni_mosaic libjni_eglfence
 
-LOCAL_REQUIRED_MODULES := libjni_mosaic
+LOCAL_REQUIRED_MODULES := libjni_mosaic libjni_eglfence
 
 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
 
 include $(BUILD_PACKAGE)
 
+include $(call all-makefiles-under, jni)
+
 ifeq ($(strip $(LOCAL_PACKAGE_OVERRIDES)),)
 # Use the following include to make gallery test apk.
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(call all-makefiles-under, $(LOCAL_PATH))
 
 # Use the following include to make camera test apk.
 include $(call all-makefiles-under, ../Camera)
+
 endif
diff --git a/jni/Android.mk b/jni/Android.mk
new file mode 100644 (file)
index 0000000..eedfa0b
--- /dev/null
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES
+
+LOCAL_SRC_FILES := jni_egl_fence.cpp
+
+LOCAL_SHARED_LIBRARIES := libcutils libEGL
+
+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
new file mode 100644 (file)
index 0000000..8d557df
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jni_egl_fence.h"
+
+#include <cutils/log.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+void
+Java_com_android_gallery3d_photoeditor_FilterStack_nativeEglSetFenceAndWait(JNIEnv* env,
+                                                                          jobject thiz) {
+  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);
+  if (fence == EGL_NO_SYNC_KHR) {
+    return;
+  }
+
+  EGLint result = eglClientWaitSyncKHR(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);
+}
diff --git a/jni/jni_egl_fence.h b/jni/jni_egl_fence.h
new file mode 100644 (file)
index 0000000..6b2c20a
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COM_ANDROID_GALLERY3D_PHOTOEDITOR_JNI_EGL_FENSE_H
+#define COM_ANDROID_GALLERY3D_PHOTOEDITOR_JNI_EGL_FENSE_H
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JNIEXPORT void JNICALL
+Java_com_android_gallery3d_photoeditor_FilterStack_nativeEglSetFenceAndWait(JNIEnv* env,
+                                                                            jobject thiz);
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* COM_ANDROID_GALLERY3D_PHOTOEDITOR_JNI_EGL_FENSE_H */
index fe6fb10..273c295 100644 (file)
@@ -118,6 +118,7 @@ public class FilterStack {
                 reallocateBuffer(out);
             }
             appliedStack.get(filterIndex).process(input, buffers[out]);
+            nativeEglSetFenceAndWait();
             return buffers[out];
         }
         return null;
@@ -275,4 +276,10 @@ public class FilterStack {
         photoView.onResume();
         paused = false;
     }
+
+    static {
+        System.loadLibrary("jni_eglfence");
+    }
+
+    private native void nativeEglSetFenceAndWait();
 }