aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2014-09-24 00:16:03 +0200
committerJorge Ruesga <jorge@ruesga.com>2014-09-24 00:17:01 +0200
commitb742e526dadb97decbca4b84e53a3ac31ad86135 (patch)
treed817ef10e392b3417cb02c237812e08438fc6d1f
parent9cac29da38337785e97efda5fbce7e70754b3c44 (diff)
downloadandroid_packages_wallpapers_PhotoPhase-b742e526dadb97decbca4b84e53a3ac31ad86135.tar.gz
android_packages_wallpapers_PhotoPhase-b742e526dadb97decbca4b84e53a3ac31ad86135.tar.bz2
android_packages_wallpapers_PhotoPhase-b742e526dadb97decbca4b84e53a3ac31ad86135.zip
photophase: revert etc1 compression feature
Etc1 compression is causing native crashes in maguro and other collateral errors Change-Id: I84b0c1e0cec8f12c59eb126ceafb12fa8d589d09 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/TextureManager.java13
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java5
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java107
3 files changed, 18 insertions, 107 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
index 65987c3..3c3ad78 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
@@ -98,9 +98,9 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
// is associated to the destination target (only if aspect ratio will be applied)
if (!Preferences.General.isFixAspectRatio()) {
ti = GLESUtil.loadTexture(
- mImage, mDimensions, effect, mDimensions, false, enqueue);
+ mImage, mDimensions, effect, mDimensions, false);
} else {
- ti = GLESUtil.loadTexture(mImage, mDimensions, null, null, false, enqueue);
+ ti = GLESUtil.loadTexture(mImage, mDimensions, null, null, false);
ti.effect = effect;
}
@@ -109,7 +109,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
if (!enqueue) {
// Invalid textures are also reported, so requestor can handle it
TextureRequestor requestor = mPendingRequests.remove(0);
- fixAspectRatio(requestor, ti, false);
+ fixAspectRatio(requestor, ti);
requestor.setTextureHandle(ti);
// Clean up memory
@@ -252,7 +252,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
synchronized (mSync) {
try {
GLESTextureInfo ti = mQueue.remove();
- fixAspectRatio(requestor, ti, true);
+ fixAspectRatio(requestor, ti);
requestor.setTextureHandle(ti);
// Clean up memory
@@ -436,9 +436,8 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
* @param request The requestor target
* @param ti The original texture information
* @param effect The effect to apply to the destination picture
- * @param compress Compress the texture
*/
- void fixAspectRatio(TextureRequestor requestor, GLESTextureInfo ti, boolean compress) {
+ void fixAspectRatio(TextureRequestor requestor, GLESTextureInfo ti) {
// Check if we have to apply any correction to the image
if (Preferences.General.isFixAspectRatio()) {
// Transform requestor dimensions to screen dimensions
@@ -455,7 +454,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
pixels.width(),
pixels.height(),
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
- GLESTextureInfo dst = GLESUtil.loadTexture(thumb, ti.effect, pixels, compress);
+ GLESTextureInfo dst = GLESUtil.loadTexture(thumb, ti.effect, pixels);
// Destroy references
int[] textures = new int[]{ti.handle};
diff --git a/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java b/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java
index 5ef4bd9..195a1e4 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java
@@ -142,10 +142,9 @@ public class OopsShape implements DrawableShape {
mMessage = ctx.getString(resourceMessageId);
// Load the textures
- mOopsImageTexture = GLESUtil.loadTexture(ctx, R.drawable.bg_cid_oops, null,
- null, false, false);
+ mOopsImageTexture = GLESUtil.loadTexture(ctx, R.drawable.bg_cid_oops, null, null, false);
Bitmap textBitmap = text2Bitmap(ctx, mMessage);
- mOopsTextTexture = GLESUtil.loadTexture(textBitmap, null, null, false);
+ mOopsTextTexture = GLESUtil.loadTexture(textBitmap, null, null);
// Recycle
mOopsImageTexture.bitmap.recycle();
diff --git a/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java b/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java
index d8fb6e9..09e1e2c 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java
@@ -22,9 +22,6 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.media.effect.Effect;
-import android.opengl.ETC1Util;
-import android.opengl.ETC1Util.ETC1Texture;
-import android.opengl.ETC1;
import android.opengl.GLES20;
import android.opengl.GLUtils;
import android.util.Log;
@@ -34,9 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
/**
@@ -54,9 +48,6 @@ public final class GLESUtil {
private static final Object SYNC = new Object();
- private static final int MAX_ACEPTABLE_COMPRESSION_TIME = 2500;
- private static boolean sDisabledTextureCompression = false;
-
/**
* A helper class to deal with OpenGL float colors.
*/
@@ -339,11 +330,10 @@ public final class GLESUtil {
* @param effect The effect to apply to the image or null if no effect is needed
* @param dimen The new dimensions
* @param recycle If the bitmap should be recycled
- * @param compress Try to compress the bitmap into ETC1
* @return GLESTextureInfo The texture info
*/
public static GLESTextureInfo loadTexture(File file, Rect dimensions, Effect effect,
- Rect dimen, boolean recycle, boolean compress) {
+ Rect dimen, boolean recycle) {
Bitmap bitmap = null;
try {
// Decode and associate the bitmap (invert the desired dimensions)
@@ -354,7 +344,7 @@ public final class GLESUtil {
}
if (DEBUG) Log.d(TAG, "image: " + file.getAbsolutePath());
- GLESTextureInfo ti = loadTexture(bitmap, effect, dimen, compress);
+ GLESTextureInfo ti = loadTexture(bitmap, effect, dimen);
ti.path = file;
return ti;
@@ -380,11 +370,10 @@ public final class GLESUtil {
* @param effect The effect to apply to the image or null if no effect is needed
* @param dimen The new dimensions
* @param recycle If the bitmap should be recycled
- * @param compress Try to compress the bitmap into ETC1
* @return GLESTextureInfo The texture info
*/
public static GLESTextureInfo loadTexture(Context ctx, int resourceId, Effect effect,
- Rect dimen, boolean recycle, boolean compress) {
+ Rect dimen, boolean recycle) {
Bitmap bitmap = null;
InputStream raw = null;
try {
@@ -398,7 +387,7 @@ public final class GLESUtil {
}
if (DEBUG) Log.d(TAG, "resourceId: " + resourceId);
- GLESTextureInfo ti = loadTexture(bitmap, effect, dimen, compress);
+ GLESTextureInfo ti = loadTexture(bitmap, effect, dimen);
return ti;
} catch (Exception e) {
@@ -429,11 +418,9 @@ public final class GLESUtil {
* @param bitmap The bitmap reference
* @param effect The effect to apply to the image or null if no effect is needed
* @param dimen The new dimensions
- * @param compress Try to compress the bitmap into ETC1
* @return GLESTextureInfo The texture info
*/
- public static GLESTextureInfo loadTexture(Bitmap bitmap, Effect effect, Rect dimen,
- boolean compress) {
+ public static GLESTextureInfo loadTexture(Bitmap bitmap, Effect effect, Rect dimen) {
// Check that we have a valid image name reference
if (bitmap == null) {
return new GLESTextureInfo();
@@ -468,52 +455,11 @@ public final class GLESUtil {
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
GLESUtil.glesCheckError("glTexParameteri");
- // Load the texture. Check weather the device supports ETC1 compressed format
- // AOSP ETC1 implementation doesn't support alpha channel
- boolean fallback = true;
- int bytesPerPixel = bitmap.getRowBytes() / bitmap.getWidth();
- boolean hasAlpha = bitmap.hasAlpha() || (bytesPerPixel < 2 || bytesPerPixel > 3);
- if (!sDisabledTextureCompression && compress && ETC1Util.isETC1Supported() && !hasAlpha) {
- // Compress the texture
- long start = System.currentTimeMillis();
- ETC1Texture texture = createETC1CompressedTextureFromBitmap(bitmap);
- if (texture != null) {
- try {
- long time = System.currentTimeMillis() - start;
- if (DEBUG) {
- Log.d(TAG, "Compression time: " + time + " ms");
- }
- if (time > MAX_ACEPTABLE_COMPRESSION_TIME) {
- sDisabledTextureCompression = true;
- Log.e(TAG, "Excessive compression time (" + time + " ms). " +
- "Disabling compression");
- }
-
- // Load the compressed texture
- int width = texture.getWidth();
- int height = texture.getHeight();
- Buffer data = texture.getData();
- int imageSize = data.remaining();
- GLES20.glCompressedTexImage2D(GLES20.GL_TEXTURE_2D, 0, ETC1.ETC1_RGB8_OES,
- width, height, 0, imageSize, data);
- GLESUtil.glesCheckError("glCompressedTexImage2D");
- fallback = !GLES20.glIsTexture(textureHandles[0]);
- } finally {
- texture = null;
- }
- }
- }
- if (fallback) {
- if (DEBUG) {
- Log.d(TAG, "Fallback to uncompressed texture.");
- }
-
- // Fallback to uncompressed texture
- GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
- if (!GLES20.glIsTexture(textureHandles[0])) {
- Log.e(TAG, "Failed to load a valid texture");
- return new GLESTextureInfo();
- }
+ // Load the texture
+ GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
+ if (!GLES20.glIsTexture(textureHandles[0])) {
+ Log.e(TAG, "Failed to load a valid texture");
+ return new GLESTextureInfo();
}
// Has a effect?
@@ -607,37 +553,4 @@ public final class GLESUtil {
}
}
- /**
- * Method that compress a uncompressed bitmap to an compressed ETC1 texture
- *
- * @param bitmap The uncompressed bitmap
- * @return ETC1Texture The ETC1 compressed texture
- */
- private static ETC1Texture createETC1CompressedTextureFromBitmap(Bitmap bitmap) {
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- int dataSize = bitmap.getRowBytes() * height;
- int bytesPerPixel = bitmap.getRowBytes() / width;
- int stride = bitmap.getRowBytes();
-
- ByteBuffer dataBuffer = ByteBuffer.allocateDirect(dataSize).order(ByteOrder.nativeOrder());
- try {
- bitmap.copyPixelsToBuffer(dataBuffer);
- dataBuffer.position(0);
-
- int encodedImageSize = ETC1.getEncodedDataSize(width, height);
- ByteBuffer compressedImage = ByteBuffer.allocateDirect(encodedImageSize).
- order(ByteOrder.nativeOrder());
- try {
- ETC1.encodeImage(dataBuffer, width, height, bytesPerPixel, stride, compressedImage);
- return new ETC1Util.ETC1Texture(width, height, compressedImage);
- } catch (IllegalArgumentException ex) {
- compressedImage = null;
- }
- } finally {
- dataBuffer = null;
- }
- return null;
- }
-
}