summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2013-01-09 15:56:33 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-01-09 15:56:33 -0800
commit6681d532e7f1fe9971e10ddeae52063bf4ba5e12 (patch)
treebf145694e6ce9d96efb0fb5db1ae26f21b100d8a
parenta6911dc4d39a1c31fd15e6db55ce0e270a7bc94d (diff)
parentc8cab06ea9dbf4b1d46203603bfefa0160aa8f62 (diff)
downloadandroid_packages_apps_Snap-6681d532e7f1fe9971e10ddeae52063bf4ba5e12.tar.gz
android_packages_apps_Snap-6681d532e7f1fe9971e10ddeae52063bf4ba5e12.tar.bz2
android_packages_apps_Snap-6681d532e7f1fe9971e10ddeae52063bf4ba5e12.zip
Merge "Fix slide show animation so that cross fades work." into gb-ub-photos-bryce
-rw-r--r--src/com/android/gallery3d/glrenderer/GLCanvas.java99
-rw-r--r--src/com/android/gallery3d/glrenderer/GLES11Canvas.java23
-rw-r--r--src/com/android/gallery3d/glrenderer/GLES20Canvas.java53
-rw-r--r--src/com/android/gallery3d/ui/SlideshowView.java4
-rw-r--r--tests/src/com/android/gallery3d/ui/GLCanvasStub.java3
5 files changed, 52 insertions, 130 deletions
diff --git a/src/com/android/gallery3d/glrenderer/GLCanvas.java b/src/com/android/gallery3d/glrenderer/GLCanvas.java
index 4cf16892e..941002e8d 100644
--- a/src/com/android/gallery3d/glrenderer/GLCanvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLCanvas.java
@@ -20,6 +20,8 @@ import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.RectF;
+import javax.microedition.khronos.opengles.GL11;
+
//
// GLCanvas gives a convenient interface to draw using OpenGL.
//
@@ -27,9 +29,6 @@ import android.graphics.RectF;
// [x, x+width) * [y, y+height)
//
public interface GLCanvas {
- public enum Blending {
- Additive, Mix,
- }
public GLId getGLId();
@@ -38,106 +37,106 @@ public interface GLCanvas {
// This is called by GLRoot and should not be called by the clients
// who only want to draw on the GLCanvas. Both width and height must be
// nonnegative.
- public void setSize(int width, int height);
+ public abstract void setSize(int width, int height);
// Clear the drawing buffers. This should only be used by GLRoot.
- public void clearBuffer();
+ public abstract void clearBuffer();
- public void clearBuffer(float[] argb);
+ public abstract void clearBuffer(float[] argb);
// Sets and gets the current alpha, alpha must be in [0, 1].
- public void setAlpha(float alpha);
+ public abstract void setAlpha(float alpha);
- public float getAlpha();
+ public abstract float getAlpha();
// (current alpha) = (current alpha) * alpha
- public void multiplyAlpha(float alpha);
+ public abstract void multiplyAlpha(float alpha);
// Change the current transform matrix.
- public void translate(float x, float y, float z);
+ public abstract void translate(float x, float y, float z);
- public void translate(float x, float y);
+ public abstract void translate(float x, float y);
- public void scale(float sx, float sy, float sz);
+ public abstract void scale(float sx, float sy, float sz);
- public void rotate(float angle, float x, float y, float z);
+ public abstract void rotate(float angle, float x, float y, float z);
- public void multiplyMatrix(float[] mMatrix, int offset);
+ public abstract void multiplyMatrix(float[] mMatrix, int offset);
// Pushes the configuration state (matrix, and alpha) onto
// a private stack.
- public void save();
+ public abstract void save();
// Same as save(), but only save those specified in saveFlags.
- public void save(int saveFlags);
+ public abstract void save(int saveFlags);
public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;
public static final int SAVE_FLAG_ALPHA = 0x01;
public static final int SAVE_FLAG_MATRIX = 0x02;
- public static final int SAVE_FLAG_BLEND = 0x04;
// Pops from the top of the stack as current configuration state (matrix,
// alpha, and clip). This call balances a previous call to save(), and is
// used to remove all modifications to the configuration state since the
// last save call.
- public void restore();
+ public abstract void restore();
// Draws a line using the specified paint from (x1, y1) to (x2, y2).
// (Both end points are included).
- public void drawLine(float x1, float y1, float x2, float y2, GLPaint paint);
+ public abstract void drawLine(float x1, float y1, float x2, float y2, GLPaint paint);
// Draws a rectangle using the specified paint from (x1, y1) to (x2, y2).
// (Both end points are included).
- public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint);
+ public abstract void drawRect(float x1, float y1, float x2, float y2, GLPaint paint);
// Fills the specified rectangle with the specified color.
- public void fillRect(float x, float y, float width, float height, int color);
+ public abstract void fillRect(float x, float y, float width, float height, int color);
// Draws a texture to the specified rectangle.
- public void drawTexture(BasicTexture texture, int x, int y, int width, int height);
+ public abstract void drawTexture(
+ BasicTexture texture, int x, int y, int width, int height);
- public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,
+ public abstract void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,
int uvBuffer, int indexBuffer, int indexCount);
// Draws the source rectangle part of the texture to the target rectangle.
- public void drawTexture(BasicTexture texture, RectF source, RectF target);
+ public abstract void drawTexture(BasicTexture texture, RectF source, RectF target);
// Draw a texture with a specified texture transform.
- public void drawTexture(BasicTexture texture, float[] mTextureTransform,
+ public abstract void drawTexture(BasicTexture texture, float[] mTextureTransform,
int x, int y, int w, int h);
// Draw two textures to the specified rectangle. The actual texture used is
// from * (1 - ratio) + to * ratio
// The two textures must have the same size.
- public void drawMixed(BasicTexture from, int toColor,
+ public abstract void drawMixed(BasicTexture from, int toColor,
float ratio, int x, int y, int w, int h);
// Draw a region of a texture and a specified color to the specified
// rectangle. The actual color used is from * (1 - ratio) + to * ratio.
// The region of the texture is defined by parameter "src". The target
// rectangle is specified by parameter "target".
- public void drawMixed(BasicTexture from, int toColor,
+ public abstract void drawMixed(BasicTexture from, int toColor,
float ratio, RectF src, RectF target);
// Unloads the specified texture from the canvas. The resource allocated
// to draw the texture will be released. The specified texture will return
// to the unloaded state. This function should be called only from
// BasicTexture or its descendant
- public boolean unloadTexture(BasicTexture texture);
+ public abstract boolean unloadTexture(BasicTexture texture);
// Delete the specified buffer object, similar to unloadTexture.
- public void deleteBuffer(int bufferId);
+ public abstract void deleteBuffer(int bufferId);
// Delete the textures and buffers in GL side. This function should only be
// called in the GL thread.
- public void deleteRecycledResources();
+ public abstract void deleteRecycledResources();
// Dump statistics information and clear the counters. For debug only.
- public void dumpStatisticsAndClear();
+ public abstract void dumpStatisticsAndClear();
- public void beginRenderTarget(RawTexture texture);
+ public abstract void beginRenderTarget(RawTexture texture);
- public void endRenderTarget();
+ public abstract void endRenderTarget();
/**
* Sets texture parameters to use GL_CLAMP_TO_EDGE for both
@@ -147,7 +146,7 @@ public interface GLCanvas {
*
* @param texture The texture to set parameters on.
*/
- public void setTextureParameters(BasicTexture texture);
+ public abstract void setTextureParameters(BasicTexture texture);
/**
* Initializes the texture to a size by calling texImage2D on it.
@@ -156,7 +155,7 @@ public interface GLCanvas {
* @param format The texture format (e.g. GL_RGBA)
* @param type The texture type (e.g. GL_UNSIGNED_BYTE)
*/
- public void initializeTextureSize(BasicTexture texture, int format, int type);
+ public abstract void initializeTextureSize(BasicTexture texture, int format, int type);
/**
* Initializes the texture to a size by calling texImage2D on it.
@@ -164,7 +163,7 @@ public interface GLCanvas {
* @param texture The texture to initialize the size.
* @param bitmap The bitmap to initialize the bitmap with.
*/
- public void initializeTexture(BasicTexture texture, Bitmap bitmap);
+ public abstract void initializeTexture(BasicTexture texture, Bitmap bitmap);
/**
* Calls glTexSubImage2D to upload a bitmap to the texture.
@@ -177,7 +176,8 @@ public interface GLCanvas {
* @param format The texture format (e.g. GL_RGBA)
* @param type The texture type (e.g. GL_UNSIGNED_BYTE)
*/
- public void texSubImage2D(BasicTexture texture, int xOffset, int yOffset, Bitmap bitmap,
+ public abstract void texSubImage2D(BasicTexture texture, int xOffset, int yOffset,
+ Bitmap bitmap,
int format, int type);
/**
@@ -186,7 +186,7 @@ public interface GLCanvas {
* @param buffer The buffer to upload
* @return The buffer ID that was generated.
*/
- public int uploadBuffer(java.nio.FloatBuffer buffer);
+ public abstract int uploadBuffer(java.nio.FloatBuffer buffer);
/**
* Generates buffers and uploads the element array buffer data.
@@ -194,36 +194,29 @@ public interface GLCanvas {
* @param buffer The buffer to upload
* @return The buffer ID that was generated.
*/
- public int uploadBuffer(java.nio.ByteBuffer buffer);
-
- /**
- * Sets the blending algorithm if a texture is not opaque.
- *
- * @param blending Either mixing (overlay) or adding a texture.
- */
- public void setBlending(Blending blending);
+ public abstract int uploadBuffer(java.nio.ByteBuffer buffer);
/**
* Enable stencil test
*/
- public void enableStencil();
+ public abstract void enableStencil();
/**
* Disable stencil.
*/
- public void disableStencil();
+ public abstract void disableStencil();
/**
* Clears the stencil so that a new stencil can be generated.
*/
- public void clearStencilBuffer();
+ public abstract void clearStencilBuffer();
/**
* Start/stop updating the stencil buffer.
*
* @param update True if the stencil should be updated, false otherwise.
*/
- public void updateStencil(boolean update);
+ public abstract void updateStencil(boolean update);
/**
* Changes how the stencil buffer is used.
@@ -232,13 +225,13 @@ public interface GLCanvas {
* changed. If false, the area inside the stencil can be drawn to
* as well.
*/
- public void drawOnlyOutsideStencil(boolean onlyOutside);
+ 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 void recoverFromLightCycle();
+ public abstract void recoverFromLightCycle();
/**
* Gets the bounds given by x, y, width, and height as well as the internal
@@ -251,5 +244,5 @@ public interface GLCanvas {
* @param width The width of the input rectangle.
* @param height The height of the input rectangle.
*/
- public void getBounds(Rect bounds, int x, int y, int width, int height);
+ 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 a4ffa2a2c..efb9d80b9 100644
--- a/src/com/android/gallery3d/glrenderer/GLES11Canvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLES11Canvas.java
@@ -86,7 +86,6 @@ public class GLES11Canvas implements GLCanvas {
private static float[] sCropRect = new float[4];
private RawTexture mTargetTexture;
- private Blending mBlending = Blending.Mix;
// Drawing statistics
int mCountDrawLine;
@@ -775,12 +774,6 @@ public class GLES11Canvas implements GLCanvas {
config.mAlpha = -1;
}
- if ((saveFlags & SAVE_FLAG_BLEND) != 0) {
- config.mBlending = mBlending;
- } else {
- config.mBlending = null;
- }
-
if ((saveFlags & SAVE_FLAG_MATRIX) != 0) {
System.arraycopy(mMatrixValues, 0, config.mMatrix, 0, 16);
} else {
@@ -815,7 +808,6 @@ public class GLES11Canvas implements GLCanvas {
private static class ConfigState {
float mAlpha;
float mMatrix[] = new float[16];
- Blending mBlending;
ConfigState mNextFree;
public void restore(GLES11Canvas canvas) {
@@ -823,9 +815,6 @@ public class GLES11Canvas implements GLCanvas {
if (mMatrix[0] != Float.NEGATIVE_INFINITY) {
System.arraycopy(mMatrix, 0, canvas.mMatrixValues, 0, 16);
}
- if (mBlending != null) {
- canvas.setBlending(mBlending);
- }
}
}
@@ -993,18 +982,6 @@ public class GLES11Canvas implements GLCanvas {
}
@Override
- public void setBlending(Blending blending) {
- if (mBlending == blending) {
- return;
- }
- Assert.assertTrue(blending == Blending.Additive || blending == Blending.Mix);
- mBlending = blending;
- int srcFunc = GL11.GL_ONE;
- int dstFunc = (blending == Blending.Additive) ? GL11.GL_ONE : GL11.GL_ONE_MINUS_SRC_ALPHA;
- mGL.glBlendFunc(srcFunc, dstFunc);
- }
-
- @Override
public void enableStencil() {
mGL.glEnable(GL11.GL_STENCIL_TEST);
}
diff --git a/src/com/android/gallery3d/glrenderer/GLES20Canvas.java b/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
index 80f861b53..149b21efd 100644
--- a/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLES20Canvas.java
@@ -23,7 +23,6 @@ import android.opengl.GLUtils;
import android.opengl.Matrix;
import android.util.Log;
-import com.android.gallery3d.common.Utils;
import com.android.gallery3d.util.IntArray;
import java.nio.Buffer;
@@ -119,7 +118,7 @@ public class GLES20Canvas implements GLCanvas {
+ "uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n"
+ "void main() {\n"
+ " gl_FragColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", vTextureCoord);\n"
- + " gl_FragColor.a *= " + ALPHA_UNIFORM + ";\n"
+ + " gl_FragColor *= " + ALPHA_UNIFORM + ";\n"
+ "}\n";
private static final String OES_TEXTURE_FRAGMENT_SHADER = ""
@@ -130,7 +129,7 @@ public class GLES20Canvas implements GLCanvas {
+ "uniform samplerExternalOES " + TEXTURE_SAMPLER_UNIFORM + ";\n"
+ "void main() {\n"
+ " gl_FragColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", vTextureCoord);\n"
- + " gl_FragColor.a *= " + ALPHA_UNIFORM + ";\n"
+ + " gl_FragColor *= " + ALPHA_UNIFORM + ";\n"
+ "}\n";
private static final int INITIAL_RESTORE_STATE_SIZE = 8;
@@ -140,7 +139,6 @@ public class GLES20Canvas implements GLCanvas {
private float[] mMatrices = new float[INITIAL_RESTORE_STATE_SIZE * MATRIX_SIZE];
private float[] mAlphas = new float[INITIAL_RESTORE_STATE_SIZE];
private IntArray mSaveFlags = new IntArray();
- private ArrayList<Blending> mBlendings = new ArrayList<Blending>();
private int mCurrentAlphaIndex = 0;
private int mCurrentMatrixIndex = 0;
@@ -291,10 +289,8 @@ public class GLES20Canvas implements GLCanvas {
mOesTextureProgram = assembleProgram(textureVertexShader, oesTextureFragmentShader,
mOesTextureParameters);
mMeshProgram = assembleProgram(meshVertexShader, textureFragmentShader, mMeshParameters);
-
- mBlendings.clear();
- mBlendings.add(null);
- setBlending(Blending.Mix);
+ GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
+ checkError();
}
private static FloatBuffer createBuffer(float[] values) {
@@ -463,10 +459,6 @@ public class GLES20Canvas implements GLCanvas {
}
System.arraycopy(mMatrices, currentIndex, mMatrices, mCurrentMatrixIndex, MATRIX_SIZE);
}
- boolean saveBlending = (saveFlags & SAVE_FLAG_BLEND) == SAVE_FLAG_BLEND;
- if (saveBlending) {
- mBlendings.add(mBlendings.get(mBlendings.size() - 1));
- }
mSaveFlags.add(saveFlags);
}
@@ -481,11 +473,6 @@ public class GLES20Canvas implements GLCanvas {
if (restoreMatrix) {
mCurrentMatrixIndex -= MATRIX_SIZE;
}
- boolean restoreBlending = (restoreFlags & SAVE_FLAG_BLEND) == SAVE_FLAG_BLEND;
- if (restoreBlending) {
- setBlending(mBlendings.get(mBlendings.size() - 2));
- mBlendings.remove(mBlendings.size() - 1);
- }
}
@Override
@@ -965,32 +952,6 @@ public class GLES20Canvas implements GLCanvas {
}
@Override
- public void setBlending(Blending blending) {
- Blending currentBlending = mBlendings.get(mBlendings.size() - 1);
- if (currentBlending == blending) {
- return; // nothing to change
- }
- mBlendings.set(mBlendings.size() - 1, blending);
- int srcFunc = GLES20.GL_ONE;
- int dstFunc;
- switch (blending) {
- case Additive:
- dstFunc = GLES20.GL_ONE;
- break;
- case Mix:
- dstFunc = GLES20.GL_ONE_MINUS_SRC_ALPHA;
- break;
- default:
- Utils.fail("Unknown blend: " + blending);
- dstFunc = GLES20.GL_ONE_MINUS_SRC_ALPHA;
- break;
- }
- GLES20.glBlendFunc(srcFunc, dstFunc);
- checkError();
- }
-
-
- @Override
public void enableStencil() {
GLES20.glEnable(GLES20.GL_STENCIL_TEST);
}
@@ -1041,11 +1002,9 @@ public class GLES20Canvas implements GLCanvas {
@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);
+ GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
+ checkError();
}
@Override
diff --git a/src/com/android/gallery3d/ui/SlideshowView.java b/src/com/android/gallery3d/ui/SlideshowView.java
index b215c6661..43784232d 100644
--- a/src/com/android/gallery3d/ui/SlideshowView.java
+++ b/src/com/android/gallery3d/ui/SlideshowView.java
@@ -23,7 +23,6 @@ import com.android.gallery3d.anim.CanvasAnimation;
import com.android.gallery3d.anim.FloatAnimation;
import com.android.gallery3d.glrenderer.BitmapTexture;
import com.android.gallery3d.glrenderer.GLCanvas;
-import com.android.gallery3d.glrenderer.GLCanvas.Blending;
import java.util.Random;
@@ -94,8 +93,6 @@ public class SlideshowView extends GLView {
protected void render(GLCanvas canvas) {
long animTime = AnimationTime.get();
boolean requestRender = mTransitionAnimation.calculate(animTime);
- canvas.save(GLCanvas.SAVE_FLAG_BLEND);
- canvas.setBlending(Blending.Additive);
float alpha = mPrevTexture == null ? 1f : mTransitionAnimation.get();
if (mPrevTexture != null && alpha != 1f) {
@@ -119,7 +116,6 @@ public class SlideshowView extends GLView {
canvas.restore();
}
if (requestRender) invalidate();
- canvas.restore();
}
private class SlideshowAnimation extends CanvasAnimation {
diff --git a/tests/src/com/android/gallery3d/ui/GLCanvasStub.java b/tests/src/com/android/gallery3d/ui/GLCanvasStub.java
index da4c5c493..d258a77f7 100644
--- a/tests/src/com/android/gallery3d/ui/GLCanvasStub.java
+++ b/tests/src/com/android/gallery3d/ui/GLCanvasStub.java
@@ -148,9 +148,6 @@ public class GLCanvasStub implements GLCanvas {
return 0;
}
@Override
- public void setBlending(Blending blending) {
- }
- @Override
public void enableStencil() {
}
@Override