aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/cyanogenmod/wallpapers/photophase
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-08-20 00:33:19 +0200
committerJorge Ruesga <jorge@ruesga.com>2013-08-20 00:33:19 +0200
commit1b537a79ceedcd2369941ef6d7ca1371d395bcef (patch)
tree4b4a2719191d5f7c60e8fa10d90bfa4e00eb2c4a /src/org/cyanogenmod/wallpapers/photophase
parent8a28e0b1dd9386c70732860e71d5ee91643d61f8 (diff)
downloadandroid_packages_wallpapers_PhotoPhase-1b537a79ceedcd2369941ef6d7ca1371d395bcef.tar.gz
android_packages_wallpapers_PhotoPhase-1b537a79ceedcd2369941ef6d7ca1371d395bcef.tar.bz2
android_packages_wallpapers_PhotoPhase-1b537a79ceedcd2369941ef6d7ca1371d395bcef.zip
Force to use image dimensions instead of screen dimensions (#26)
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase')
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java11
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/TextureManager.java6
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java8
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java21
4 files changed, 28 insertions, 18 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java
index 6523b5d..4e546d4 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java
@@ -77,6 +77,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
/*package*/ int mWidth = -1;
/*package*/ int mHeight = -1;
+ private int mStatusBarHeight = 0;
/*package*/ int mMeasuredHeight = -1;
private final float[] mMVPMatrix = new float[16];
@@ -423,6 +424,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
mWidth = -1;
mHeight = -1;
mMeasuredHeight = -1;
+ mStatusBarHeight = 0;
// We have a 2d (fake) scenario, disable all unnecessary tests. Deep are
// necessary for some 3d effects
@@ -479,12 +481,12 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
// Save the width and height to avoid recreate the world
mWidth = width;
mHeight = height;
- int statusBarHeight = AndroidHelper.calculateStatusBarHeight(mContext);
- mMeasuredHeight = mHeight + statusBarHeight;
+ mStatusBarHeight = AndroidHelper.calculateStatusBarHeight(mContext);
+ mMeasuredHeight = mHeight + mStatusBarHeight;
// Calculate a better fixed size for the pictures
Rect dimensions = new Rect(0, 0, width / 2, height / 2);
- Rect screenDimensions = new Rect(0, statusBarHeight, width, height);
+ Rect screenDimensions = new Rect(0, mStatusBarHeight, width, height);
mTextureManager.setDimensions(dimensions);
mTextureManager.setScreenDimesions(screenDimensions);
mTextureManager.setPause(false);
@@ -508,7 +510,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
mOopsShape = new OopsShape(mContext, R.string.no_pictures_oops_msg);
// Set the viewport and the fustrum
- GLES20.glViewport(0, -statusBarHeight, width, height);
+ GLES20.glViewport(0, -mStatusBarHeight, mWidth, mHeight);
GLESUtil.glesCheckError("glViewport");
Matrix.frustumM(mProjMatrix, 0, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 2.0f);
@@ -527,6 +529,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
public void onDrawFrame(GL10 glUnused) {
synchronized (mDrawing) {
// Set the projection, view and model
+ GLES20.glViewport(0, -mStatusBarHeight, mWidth, mHeight);
Matrix.setLookAtM(mVMatrix, 0, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
index 700a728..8f17162 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
@@ -90,7 +90,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
// Bind to the GLES context
GLESTextureInfo oldTextureInfo = sRecycledBitmaps.remove(0);
try {
- ti = GLESUtil.loadTexture(oldTextureInfo.bitmap, effect, mScreenDimensions);
+ ti = GLESUtil.loadTexture(oldTextureInfo.bitmap, effect, mDimensions);
ti.path = oldTextureInfo.path;
} finally {
if (GLES20.glIsTexture(oldTextureInfo.handle)) {
@@ -107,7 +107,7 @@ 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, mScreenDimensions, false);
+ mImage, mDimensions, effect, mDimensions, false);
} else {
ti = GLESUtil.loadTexture(mImage, mDimensions, null, null, false);
ti.effect = effect;
@@ -450,7 +450,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
pixels.width(),
pixels.height(),
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
- GLESTextureInfo dst = GLESUtil.loadTexture(thumb, ti.effect, mScreenDimensions);
+ GLESTextureInfo dst = GLESUtil.loadTexture(thumb, ti.effect, pixels);
// Destroy references
int[] textures = new int[]{ti.handle};
diff --git a/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java b/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java
index fb49c72..3848402 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java
@@ -58,8 +58,12 @@ public class BitmapUtils {
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
- // Calculate inSampleSize
- options.inSampleSize = calculateBitmapRatio(options, reqWidth, reqHeight);
+ // Calculate inSampleSize (use 1024 as maximum size, the minimum supported
+ // by all the gles20 devices)
+ options.inSampleSize = calculateBitmapRatio(
+ options,
+ Math.min(reqWidth, 1024),
+ Math.min(reqHeight, 1024));
// Decode the bitmap with inSampleSize set
options.inJustDecodeBounds = false;
diff --git a/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java b/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java
index cc1073c..ec5834f 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java
@@ -312,12 +312,12 @@ public final class GLESUtil {
* @param file The image file
* @param dimensions The desired dimensions
* @param effect The effect to apply to the image or null if no effect is needed
- * @param screenDim The screen dimensions
+ * @param dimen The new dimensions
* @param recycle If the bitmap should be recycled
* @return GLESTextureInfo The texture info
*/
public static GLESTextureInfo loadTexture(
- File file, Rect dimensions, Effect effect, Rect screenDim, boolean recycle) {
+ File file, Rect dimensions, Effect effect, Rect dimen, boolean recycle) {
Bitmap bitmap = null;
try {
// Decode and associate the bitmap (invert the desired dimensions)
@@ -328,7 +328,7 @@ public final class GLESUtil {
}
if (DEBUG) Log.d(TAG, "image: " + file.getAbsolutePath());
- GLESTextureInfo ti = loadTexture(bitmap, effect, screenDim);
+ GLESTextureInfo ti = loadTexture(bitmap, effect, dimen);
ti.path = file;
return ti;
@@ -351,12 +351,12 @@ public final class GLESUtil {
* @param ctx The current context
* @param resourceId The resource identifier
* @param effect The effect to apply to the image or null if no effect is needed
- * @param screenDim The screen dimensions
+ * @param dimen The new dimensions
* @param recycle If the bitmap should be recycled
* @return GLESTextureInfo The texture info
*/
public static GLESTextureInfo loadTexture(
- Context ctx, int resourceId, Effect effect, Rect screenDim, boolean recycle) {
+ Context ctx, int resourceId, Effect effect, Rect dimen, boolean recycle) {
Bitmap bitmap = null;
InputStream raw = null;
try {
@@ -370,7 +370,7 @@ public final class GLESUtil {
}
if (DEBUG) Log.d(TAG, "resourceId: " + resourceId);
- GLESTextureInfo ti = loadTexture(bitmap, effect, screenDim);
+ GLESTextureInfo ti = loadTexture(bitmap, effect, dimen);
return ti;
} catch (Exception e) {
@@ -399,10 +399,10 @@ 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 screenDim The screen dimensions
+ * @param dimen The new dimensions
* @return GLESTextureInfo The texture info
*/
- public static GLESTextureInfo loadTexture(Bitmap bitmap, Effect effect, Rect screenDim) {
+ 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();
@@ -444,7 +444,10 @@ public final class GLESUtil {
if (effect != null) {
// Apply the effect (we need a thread-safe call here)
synchronized (sSync) {
- effect.apply(textureNames[0], screenDim.width(), screenDim.height(), textureNames[1]);
+ // No more than 1024 (the minimum supported by all the gles20 devices)
+ int w = Math.min(dimen.width(), 1024);
+ int h = Math.min(dimen.width(), 1024);
+ effect.apply(textureNames[0], w, h, textureNames[1]);
}
handle = textureNames[1];