summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2012-12-11 07:43:51 -0800
committerGeorge Mount <mount@google.com>2012-12-17 13:23:31 -0800
commit86616448866336aa294b88cfd93b5603e4207f88 (patch)
treec9ad408d53869ce63d884a1107cfce05b31750a2
parent4bdd0372ca1bba02828e9343fa3cc775f8c6f6e9 (diff)
downloadandroid_packages_apps_Snap-86616448866336aa294b88cfd93b5603e4207f88.zip
android_packages_apps_Snap-86616448866336aa294b88cfd93b5603e4207f88.tar.gz
android_packages_apps_Snap-86616448866336aa294b88cfd93b5603e4207f88.tar.bz2
Move LightCycle to render directly to GLRootView.
Change-Id: I298ef7127d86ca37067ffa953640aad1747961f9
-rw-r--r--src/com/android/gallery3d/glrenderer/GLCanvas.java20
-rw-r--r--src/com/android/gallery3d/glrenderer/GLES11Canvas.java11
-rw-r--r--src/com/android/gallery3d/glrenderer/GLES20Canvas.java43
-rw-r--r--tests/src/com/android/gallery3d/ui/GLCanvasStub.java7
4 files changed, 74 insertions, 7 deletions
diff --git a/src/com/android/gallery3d/glrenderer/GLCanvas.java b/src/com/android/gallery3d/glrenderer/GLCanvas.java
index 848af75..5e319f8 100644
--- a/src/com/android/gallery3d/glrenderer/GLCanvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLCanvas.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.glrenderer;
import android.graphics.Bitmap;
+import android.graphics.Rect;
import android.graphics.RectF;
import com.android.gallery3d.common.ApiHelper;
@@ -261,4 +262,23 @@ public abstract class GLCanvas {
* as well.
*/
public abstract void drawOnlyOutsideStencil(boolean onlyOutside);
+
+ /**
+ * After LightCycle makes GL calls, this method is called to restore the GL
+ * configuration to the one expected by GLCanvas.
+ */
+ public abstract void recoverFromLightCycle();
+
+ /**
+ * Gets the bounds given by x, y, width, and height as well as the internal
+ * matrix state. There is no special handling for non-90-degree rotations.
+ * It only considers the lower-left and upper-right corners as the bounds.
+ *
+ * @param bounds The output bounds to write to.
+ * @param x The left side of the input rectangle.
+ * @param y The bottom of the input rectangle.
+ * @param width The width of the input rectangle.
+ * @param height The height of the input rectangle.
+ */
+ public abstract void getBounds(Rect bounds, int x, int y, int width, int height);
}
diff --git a/src/com/android/gallery3d/glrenderer/GLES11Canvas.java b/src/com/android/gallery3d/glrenderer/GLES11Canvas.java
index c543421..e4f7d1a 100644
--- a/src/com/android/gallery3d/glrenderer/GLES11Canvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLES11Canvas.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.glrenderer;
import android.graphics.Bitmap;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.opengl.GLU;
import android.opengl.GLUtils;
@@ -1036,4 +1037,14 @@ public class GLES11Canvas extends GLCanvas {
int func = onlyOutside ? GL11.GL_NOTEQUAL : GL11.GL_ALWAYS;
mGL.glStencilFunc(func, 1, 1);
}
+
+ @Override
+ public void recoverFromLightCycle() {
+ // This is only required for GLES20
+ }
+
+ @Override
+ public void getBounds(Rect bounds, int x, int y, int width, int height) {
+ // This is only required for GLES20
+ }
}
diff --git a/src/com/android/gallery3d/glrenderer/GLES20Canvas.java b/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
index 3c3eebf..c1f8164 100644
--- a/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
@@ -16,6 +16,7 @@
package com.android.gallery3d.glrenderer;
import android.graphics.Bitmap;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.opengl.GLES20;
import android.opengl.GLUtils;
@@ -64,6 +65,11 @@ public class GLES20Canvas extends GLCanvas implements GLId {
1, 0,
};
+ private static final float[] BOUNDS_COORDINATES = {
+ 0, 0, 0, 1,
+ 1, 1, 0, 1,
+ };
+
private static final String POSITION_ATTRIBUTE = "aPosition";
private static final String COLOR_UNIFORM = "uColor";
private static final String MATRIX_UNIFORM = "uMatrix";
@@ -248,8 +254,6 @@ public class GLES20Canvas extends GLCanvas implements GLId {
private int mCountFillRect = 0;
private int mCountDrawLine = 0;
- private int mNextTextureId = 1;
-
// Buffer for framebuffer IDs -- we keep track so we can switch the attached
// texture.
private int[] mFrameBuffer = new int[1];
@@ -560,6 +564,8 @@ public class GLES20Canvas extends GLCanvas implements GLId {
GLES20.glVertexAttribPointer(params[INDEX_POSITION].handle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false, VERTEX_STRIDE, offset * VERTEX_STRIDE);
checkError();
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
+ checkError();
}
private void draw(ShaderParameter[] params, int type, int count, float x, float y, float width,
@@ -735,6 +741,8 @@ public class GLES20Canvas extends GLCanvas implements GLId {
GLES20.glVertexAttribPointer(texCoordHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT,
false, VERTEX_STRIDE, 0);
checkError();
+ GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
+ checkError();
GLES20.glEnableVertexAttribArray(positionHandle);
checkError();
@@ -987,10 +995,9 @@ public class GLES20Canvas extends GLCanvas implements GLId {
@Override
public int generateTexture() {
- // Can use anything as a lock. No need to create a new object.
- synchronized (mTempIntArray) {
- return mNextTextureId++;
- }
+ GLES20.glGenTextures(1, mTempIntArray, 0);
+ checkError();
+ return mTempIntArray[0];
}
@Override
@@ -1044,7 +1051,7 @@ public class GLES20Canvas extends GLCanvas implements GLId {
GLES20.glStencilFunc(func, 1, 1);
}
- private static void checkError() {
+ public static void checkError() {
int error = GLES20.glGetError();
if (error != 0) {
Throwable t = new Throwable();
@@ -1065,4 +1072,26 @@ public class GLES20Canvas extends GLCanvas implements GLId {
Log.v(TAG, b.toString());
}
+ @Override
+ public void recoverFromLightCycle() {
+ GLES20.glViewport(0, 0, mWidth, mHeight);
+ int blendingIndex = mBlendings.size() - 1;
+ Blending currentBlending = mBlendings.get(blendingIndex);
+ mBlendings.set(blendingIndex, null);
+ setBlending(currentBlending);
+ GLES20.glDisable(GLES20.GL_DEPTH_TEST);
+ }
+
+ @Override
+ public void getBounds(Rect bounds, int x, int y, int width, int height) {
+ Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
+ Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
+ Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
+ Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
+ bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
+ bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
+ bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
+ bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
+ bounds.sort();
+ }
}
diff --git a/tests/src/com/android/gallery3d/ui/GLCanvasStub.java b/tests/src/com/android/gallery3d/ui/GLCanvasStub.java
index bf4776d..d6bbc3d 100644
--- a/tests/src/com/android/gallery3d/ui/GLCanvasStub.java
+++ b/tests/src/com/android/gallery3d/ui/GLCanvasStub.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.ui;
import android.graphics.Bitmap;
+import android.graphics.Rect;
import android.graphics.RectF;
import com.android.gallery3d.glrenderer.BasicTexture;
@@ -166,4 +167,10 @@ public class GLCanvasStub extends GLCanvas {
@Override
public void initialize(GL11 gl) {
}
+ @Override
+ public void recoverFromLightCycle() {
+ }
+ @Override
+ public void getBounds(Rect bounds, int x, int y, int width, int height) {
+ }
}