OSDN Git Service

Drive GLRootView with Choreographer
authorJohn Reck <jreck@google.com>
Mon, 22 Oct 2012 23:11:01 +0000 (16:11 -0700)
committerJohn Reck <jreck@google.com>
Mon, 22 Oct 2012 23:11:01 +0000 (16:11 -0700)
 Bug: 7332724
 By routing requestRender through postOnAnimation we can drive
 the GLRootView's rendering with the UI thread's coreographer, which
 ensures that touch events are processed before drawing

Change-Id: Iac2b3229e9a09ee0319c64c5fc7cb906512a379c

gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
src/com/android/gallery3d/ui/GLRootView.java

index a393025..837777e 100644 (file)
@@ -167,6 +167,9 @@ public class ApiHelper {
     public static final boolean HAS_VIEW_PROPERTY_ANIMATOR =
             Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1;
 
+    public static final boolean HAS_POST_ON_ANIMATION =
+            Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN;
+
     public static int getIntFieldIfExists(Class<?> klass, String fieldName,
             Class<?> obj, int defaultVal) {
         try {
index dbdfb67..b400b05 100644 (file)
@@ -177,6 +177,21 @@ public class GLRootView extends GLSurfaceView
         }
         if (mRenderRequested) return;
         mRenderRequested = true;
+        if (ApiHelper.HAS_POST_ON_ANIMATION) {
+            postOnAnimation(mRequestRenderOnAnimationFrame);
+        } else {
+            super.requestRender();
+        }
+    }
+
+    private Runnable mRequestRenderOnAnimationFrame = new Runnable() {
+        @Override
+        public void run() {
+            superRequestRender();
+        }
+    };
+
+    private void superRequestRender() {
         super.requestRender();
     }