OSDN Git Service

Add freeze/unfreeze for GLRootView.
authorChih-Chung Chang <chihchung@google.com>
Thu, 10 May 2012 03:03:35 +0000 (11:03 +0800)
committerChih-Chung Chang <chihchung@google.com>
Thu, 10 May 2012 08:31:03 +0000 (16:31 +0800)
Change-Id: Ieb78041fea22b064d176ea1318cf5883d5d4c94f

src/com/android/gallery3d/ui/GLRoot.java
src/com/android/gallery3d/ui/GLRootView.java
tests/src/com/android/gallery3d/ui/GLRootMock.java
tests/src/com/android/gallery3d/ui/GLRootStub.java

index 313d81a..5ed323a 100644 (file)
@@ -41,4 +41,6 @@ public interface GLRoot {
     public int getDisplayRotation();
     public int getCompensation();
     public Matrix getCompensationMatrix();
+    public void freeze();
+    public void unfreeze();
 }
index 7f8f1f4..1f25b90 100644 (file)
@@ -33,6 +33,7 @@ import com.android.gallery3d.util.Profile;
 
 import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 
 import javax.microedition.khronos.egl.EGLConfig;
@@ -97,6 +98,9 @@ public class GLRootView extends GLSurfaceView
     private final IdleRunner mIdleRunner = new IdleRunner();
 
     private final ReentrantLock mRenderLock = new ReentrantLock();
+    private final Condition mFreezeCondition =
+            mRenderLock.newCondition();
+    private boolean mFreeze;
 
     private long mLastDrawFinishTime;
     private boolean mInDownState = false;
@@ -301,6 +305,11 @@ public class GLRootView extends GLSurfaceView
             t0 = System.nanoTime();
         }
         mRenderLock.lock();
+
+        while (mFreeze) {
+            mFreezeCondition.awaitUninterruptibly();
+        }
+
         try {
             onDrawFrameLocked(gl);
         } finally {
@@ -486,4 +495,19 @@ public class GLRootView extends GLSurfaceView
     public Matrix getCompensationMatrix() {
         return mCompensationMatrix;
     }
+
+    @Override
+    public void freeze() {
+        mRenderLock.lock();
+        mFreeze = true;
+        mRenderLock.unlock();
+    }
+
+    @Override
+    public void unfreeze() {
+        mRenderLock.lock();
+        mFreeze = false;
+        mFreezeCondition.signalAll();
+        mRenderLock.unlock();
+    }
 }
index 4af7a1f..1253e50 100644 (file)
@@ -39,4 +39,6 @@ public class GLRootMock implements GLRoot {
     public int getDisplayRotation() { return 0; }
     public int getCompensation() { return 0; }
     public Matrix getCompensationMatrix() { return null; }
+    public void freeze() {}
+    public void unfreeze() {}
 }
index 878eedd..5c88c47 100644 (file)
@@ -32,4 +32,6 @@ public class GLRootStub implements GLRoot {
     public int getDisplayRotation() { return 0; }
     public int getCompensation() { return 0; }
     public Matrix getCompensationMatrix() { return null; }
+    public void freeze() {}
+    public void unfreeze() {}
 }