diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-08-06 01:47:05 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-08-06 01:47:05 +0200 |
commit | 6ab3912f76d8886ccfc88def25c18819a0594f07 (patch) | |
tree | b18b0800e82bdf4251c2bee8d892fcdfa9baf553 /src/org/cyanogenmod/wallpapers/photophase/transitions | |
parent | 660adfa9453ada61b8753dcac1adc5b9b0972b62 (diff) | |
download | android_packages_wallpapers_PhotoPhase-6ab3912f76d8886ccfc88def25c18819a0594f07.tar.gz android_packages_wallpapers_PhotoPhase-6ab3912f76d8886ccfc88def25c18819a0594f07.tar.bz2 android_packages_wallpapers_PhotoPhase-6ab3912f76d8886ccfc88def25c18819a0594f07.zip |
Support fot GPU image effects (#2)
Initial support of android.media.effects.
Note: Transitions are broken now, and must be fixed
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/transitions')
5 files changed, 61 insertions, 81 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/transitions/FadeTransition.java b/src/org/cyanogenmod/wallpapers/photophase/transitions/FadeTransition.java index d88aafc..c314a88 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/transitions/FadeTransition.java +++ b/src/org/cyanogenmod/wallpapers/photophase/transitions/FadeTransition.java @@ -88,7 +88,7 @@ public class FadeTransition extends NullTransition { @Override public void select(PhotoFrame target) { super.select(target); - mOverlay = new ColorShape(mContext, target.getPictureVertex(), Colors.getBackground()); + mOverlay = new ColorShape(mContext, target.getFrameVertex()/*target.getPictureVertex()*/, Colors.getBackground()); mOverlay.setAlpha(0); } @@ -99,15 +99,13 @@ public class FadeTransition extends NullTransition { public void apply(float[] matrix) throws GLException { // Check internal vars if (mTarget == null || - mTarget.getPictureVertexBuffer() == null || - mTarget.getTextureBuffer() == null || - mTarget.getVertexOrderBuffer() == null) { + mTarget.getPositionBuffer() == null || + mTarget.getTextureBuffer() == null) { return; } if (mTransitionTarget == null || - mTransitionTarget.getPictureVertexBuffer() == null || - mTransitionTarget.getTextureBuffer() == null || - mTransitionTarget.getVertexOrderBuffer() == null) { + mTransitionTarget.getPositionBuffer() == null || + mTransitionTarget.getTextureBuffer() == null) { return; } diff --git a/src/org/cyanogenmod/wallpapers/photophase/transitions/NullTransition.java b/src/org/cyanogenmod/wallpapers/photophase/transitions/NullTransition.java index 0332bc5..e88689d 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/transitions/NullTransition.java +++ b/src/org/cyanogenmod/wallpapers/photophase/transitions/NullTransition.java @@ -101,9 +101,8 @@ public class NullTransition extends Transition { public void apply(float[] matrix) throws GLException { // Check internal vars if (mTarget == null || - mTarget.getPictureVertexBuffer() == null || - mTarget.getTextureBuffer() == null || - mTarget.getVertexOrderBuffer() == null) { + mTarget.getPositionBuffer() == null || + mTarget.getTextureBuffer() == null) { return; } @@ -114,54 +113,50 @@ public class NullTransition extends Transition { /** * Method that draws the picture texture * - * @param target + * @param target The target to draw * @param matrix The model-view-projection matrix */ protected void draw(PhotoFrame target, float[] matrix) { - // Set the program + // Bind default FBO + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); + + // Use our shader program useProgram(0); - // Bind the texture - int textureHandle = target.getTextureHandle(); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - GLESUtil.glesCheckError("glActiveTexture"); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle); - GLESUtil.glesCheckError("glBindTexture"); + // Disable blending + GLES20.glDisable(GLES20.GL_BLEND); - // Position - FloatBuffer vertexBuffer = target.getPictureVertexBuffer(); - vertexBuffer.position(0); - GLES20.glVertexAttribPointer( - mPositionHandlers[0], - PhotoFrame.COORDS_PER_VERTER, - GLES20.GL_FLOAT, - false, - PhotoFrame.COORDS_PER_VERTER * 4, - vertexBuffer); - GLESUtil.glesCheckError("glVertexAttribPointer"); - GLES20.glEnableVertexAttribArray(mPositionHandlers[0]); - GLESUtil.glesCheckError("glEnableVertexAttribArray"); + // Apply the projection and view transformation + GLES20.glUniformMatrix4fv(mMVPMatrixHandlers[0], 1, false, matrix, 0); + GLESUtil.glesCheckError("glUniformMatrix4fv"); // Texture FloatBuffer textureBuffer = target.getTextureBuffer(); textureBuffer.position(0); - GLES20.glVertexAttribPointer( - mTextureCoordHandlers[0], - 2, - GLES20.GL_FLOAT, - false, - 2 * 4, - textureBuffer); + GLES20.glVertexAttribPointer(mTextureCoordHandlers[0], 2, GLES20.GL_FLOAT, false, 0, textureBuffer); GLESUtil.glesCheckError("glVertexAttribPointer"); GLES20.glEnableVertexAttribArray(mTextureCoordHandlers[0]); GLESUtil.glesCheckError("glEnableVertexAttribArray"); - // Apply the projection and view transformation - GLES20.glUniformMatrix4fv(mMVPMatrixHandlers[0], 1, false, matrix, 0); - GLESUtil.glesCheckError("glUniformMatrix4fv"); + // Position + FloatBuffer positionBuffer = target.getPositionBuffer(); + positionBuffer.position(0); + GLES20.glVertexAttribPointer(mPositionHandlers[0], 2, GLES20.GL_FLOAT, false, 0, positionBuffer); + GLESUtil.glesCheckError("glVertexAttribPointer"); + GLES20.glEnableVertexAttribArray(mPositionHandlers[0]); + GLESUtil.glesCheckError("glEnableVertexAttribArray"); + + // Set the input texture + int textureHandle = target.getTextureHandle(); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + GLESUtil.glesCheckError("glActiveTexture"); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle); + GLESUtil.glesCheckError("glBindTexture"); + GLES20.glUniform1i(mTextureHandlers[0], 0); + GLESUtil.glesCheckError("glBindTexture"); - // Draw the photo frame - GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4); + // Draw + GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLESUtil.glesCheckError("glDrawElements"); // Disable attributes diff --git a/src/org/cyanogenmod/wallpapers/photophase/transitions/SwapTransition.java b/src/org/cyanogenmod/wallpapers/photophase/transitions/SwapTransition.java index d100110..d5cf15f 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/transitions/SwapTransition.java +++ b/src/org/cyanogenmod/wallpapers/photophase/transitions/SwapTransition.java @@ -84,15 +84,13 @@ public class SwapTransition extends NullTransition { public void apply(float[] matrix) throws GLException { // Check internal vars if (mTarget == null || - mTarget.getPictureVertexBuffer() == null || - mTarget.getTextureBuffer() == null || - mTarget.getVertexOrderBuffer() == null) { + mTarget.getPositionBuffer() == null || + mTarget.getTextureBuffer() == null) { return; } if (mTransitionTarget == null || - mTransitionTarget.getPictureVertexBuffer() == null || - mTransitionTarget.getTextureBuffer() == null || - mTransitionTarget.getVertexOrderBuffer() == null) { + mTransitionTarget.getPositionBuffer() == null || + mTransitionTarget.getTextureBuffer() == null) { return; } diff --git a/src/org/cyanogenmod/wallpapers/photophase/transitions/Transition.java b/src/org/cyanogenmod/wallpapers/photophase/transitions/Transition.java index 315a9f8..cd24b54 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/transitions/Transition.java +++ b/src/org/cyanogenmod/wallpapers/photophase/transitions/Transition.java @@ -35,6 +35,7 @@ public abstract class Transition { private final TextureManager mTextureManager; protected int[] mProgramHandlers; + protected int[] mTextureHandlers; protected int[] mPositionHandlers; protected int[] mTextureCoordHandlers; protected int[] mMVPMatrixHandlers; @@ -64,6 +65,7 @@ public abstract class Transition { assert mVertexShader.length != mFragmentShader.length; int cc = mVertexShader.length; mProgramHandlers = new int[cc]; + mTextureHandlers = new int[cc]; mPositionHandlers = new int[cc]; mTextureCoordHandlers = new int[cc]; mMVPMatrixHandlers = new int[cc]; @@ -86,7 +88,6 @@ public abstract class Transition { mContext, mTextureManager, mTarget.getFrameVertex(), - mTarget.getPictureVertex(), mTarget.getBackgroundColor()); } } @@ -157,6 +158,8 @@ public abstract class Transition { mProgramHandlers[index] = GLESUtil.createProgram( mContext.getResources(), mVertexShader[index], mFragmentShader[index]); + mTextureHandlers[index] = + GLES20.glGetAttribLocation(mProgramHandlers[index], "sTexture"); mPositionHandlers[index] = GLES20.glGetAttribLocation(mProgramHandlers[index], "aPosition"); GLESUtil.glesCheckError("glGetAttribLocation"); @@ -192,6 +195,7 @@ public abstract class Transition { GLESUtil.glesCheckError("glDeleteProgram"); } mProgramHandlers[i] = 0; + mTextureHandlers[i] = 0; mPositionHandlers[i] = 0; mTextureCoordHandlers[i] = 0; mMVPMatrixHandlers[i] = 0; diff --git a/src/org/cyanogenmod/wallpapers/photophase/transitions/TranslateTransition.java b/src/org/cyanogenmod/wallpapers/photophase/transitions/TranslateTransition.java index 4e32a4a..33e69d7 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/transitions/TranslateTransition.java +++ b/src/org/cyanogenmod/wallpapers/photophase/transitions/TranslateTransition.java @@ -29,7 +29,6 @@ import org.cyanogenmod.wallpapers.photophase.TextureManager; import org.cyanogenmod.wallpapers.photophase.transitions.Transitions.TRANSITIONS; import java.nio.FloatBuffer; -import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -120,16 +119,16 @@ public class TranslateTransition extends Transition { new ArrayList<TranslateTransition.TRANSLATE_MODES>( Arrays.asList(TRANSLATE_MODES.values())); float[] vertex = target.getFrameVertex(); - if (vertex[0] != -1.0f) { + if (vertex[4] != -1.0f) { modes.remove(TRANSLATE_MODES.RIGHT_TO_LEFT); } - if (vertex[9] != 1.0f) { + if (vertex[6] != 1.0f) { modes.remove(TRANSLATE_MODES.LEFT_TO_RIGHT); } - if (vertex[1] != 1.0f) { + if (vertex[5] != 1.0f) { modes.remove(TRANSLATE_MODES.DOWN_TO_UP); } - if (vertex[4] != -1.0f) { + if (vertex[1] != -1.0f) { modes.remove(TRANSLATE_MODES.UP_TO_DOWN); } @@ -145,8 +144,8 @@ public class TranslateTransition extends Transition { @Override public boolean isSelectable(PhotoFrame frame) { float[] vertex = frame.getFrameVertex(); - if (vertex[0] == -1.0f || vertex[9] == 1.0f || - vertex[1] == 1.0f || vertex[4] == -1.0f) { + if (vertex[4] == -1.0f || vertex[6] == 1.0f || + vertex[5] == 1.0f || vertex[1] == -1.0f) { return true; } return false; @@ -168,15 +167,13 @@ public class TranslateTransition extends Transition { public void apply(float[] matrix) throws GLException { // Check internal vars if (mTarget == null || - mTarget.getPictureVertexBuffer() == null || - mTarget.getTextureBuffer() == null || - mTarget.getVertexOrderBuffer() == null) { + mTarget.getPositionBuffer() == null || + mTarget.getTextureBuffer() == null) { return; } if (mTransitionTarget == null || - mTransitionTarget.getPictureVertexBuffer() == null || - mTransitionTarget.getTextureBuffer() == null || - mTransitionTarget.getVertexOrderBuffer() == null) { + mTransitionTarget.getPositionBuffer() == null || + mTransitionTarget.getTextureBuffer() == null) { return; } @@ -218,7 +215,7 @@ public class TranslateTransition extends Transition { GLESUtil.glesCheckError("glBindTexture"); // Position - FloatBuffer vertexBuffer = mTarget.getPictureVertexBuffer(); + FloatBuffer vertexBuffer = mTarget.getPositionBuffer(); vertexBuffer.position(0); GLES20.glVertexAttribPointer( mPositionHandlers[0], @@ -248,8 +245,8 @@ public class TranslateTransition extends Transition { // Calculate the delta distance float distance = (mMode.compareTo(TRANSLATE_MODES.LEFT_TO_RIGHT) == 0 || mMode.compareTo(TRANSLATE_MODES.RIGHT_TO_LEFT) == 0) - ? mTarget.getPictureWidth() - : mTarget.getPictureHeight(); + ? mTarget.getFrameWidth() + : mTarget.getFrameHeight(); if (mMode.compareTo(TRANSLATE_MODES.RIGHT_TO_LEFT) == 0 || mMode.compareTo(TRANSLATE_MODES.DOWN_TO_UP) == 0) { distance *= -1; } @@ -267,13 +264,7 @@ public class TranslateTransition extends Transition { GLESUtil.glesCheckError("glUniformMatrix4fv"); // Draw the photo frame - ShortBuffer vertexOrderBuffer = mTarget.getVertexOrderBuffer(); - vertexOrderBuffer.position(0); - GLES20.glDrawElements( - GLES20.GL_TRIANGLE_FAN, - 6, - GLES20.GL_UNSIGNED_SHORT, - vertexOrderBuffer); + GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLESUtil.glesCheckError("glDrawElements"); // Disable attributes @@ -301,7 +292,7 @@ public class TranslateTransition extends Transition { GLESUtil.glesCheckError("glBindTexture"); // Position - FloatBuffer vertexBuffer = mTransitionTarget.getPictureVertexBuffer(); + FloatBuffer vertexBuffer = mTransitionTarget.getPositionBuffer(); vertexBuffer.position(0); GLES20.glVertexAttribPointer( mPositionHandlers[1], @@ -335,13 +326,7 @@ public class TranslateTransition extends Transition { GLESUtil.glesCheckError("glUniformMatrix4fv"); // Draw the photo frame - ShortBuffer vertexOrderBuffer = mTransitionTarget.getVertexOrderBuffer(); - vertexOrderBuffer.position(0); - GLES20.glDrawElements( - GLES20.GL_TRIANGLE_FAN, - 6, - GLES20.GL_UNSIGNED_SHORT, - vertexOrderBuffer); + GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GLESUtil.glesCheckError("glDrawElements"); // Disable attributes |