Fix a bug that the scissor box is not correct set after glViewport.

Change-Id: Ic8a7e7847b656c8557dbefe8d718f78e60861192
diff --git a/new3d/src/com/android/gallery3d/ui/GLCanvasImp.java b/new3d/src/com/android/gallery3d/ui/GLCanvasImp.java
index 1bbdc28..4df72d8 100644
--- a/new3d/src/com/android/gallery3d/ui/GLCanvasImp.java
+++ b/new3d/src/com/android/gallery3d/ui/GLCanvasImp.java
@@ -59,6 +59,8 @@
         initialize();
     }
 
+    private int mClipRetryCount = 0;
+
     public void setSize(int width, int height) {
         Util.Assert(width >= 0 && height >= 0);
 
@@ -80,7 +82,7 @@
         Matrix.scaleM(matrix, 0, 1, -1, 1);
 
         mClipRect.set(0, 0, width, height);
-        gl.glScissor(0, 0, width, height);
+        mClipRetryCount = 2;
     }
 
     public long currentAnimationTimeMillis() {
@@ -378,7 +380,6 @@
         return point;
     }
 
-
     public boolean clipRect(int left, int top, int right, int bottom) {
         float point[] = mapPoints(mMatrixValues, left, top, right, bottom);
 
@@ -671,6 +672,15 @@
     }
 
     public void clearBuffer() {
+        // OpenGL seems having a bug causing us not being able to reset the
+        // scissor box in "setSize()". We have to do it in the second
+        // onDrawFrame().
+        if (mClipRetryCount > 0) {
+            --mClipRetryCount;
+            Rect clip = mClipRect;
+            mGL.glScissor(clip.left, clip.top, clip.width(), clip.height());
+        }
+
         mGL.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_STENCIL_BUFFER_BIT);
     }