summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2010-04-29 14:20:25 +0800
committerOwen Lin <owenlin@google.com>2010-04-29 14:20:25 +0800
commitb81d7a45d5514e0777f88c012a86c267e3f641e5 (patch)
tree634c38c36cef1fc5e540791d1e37f49fd8a1025d /src
parent8cba7138e5c4a96678d735421d1ce4c00e654ab5 (diff)
downloadLegacyCamera-b81d7a45d5514e0777f88c012a86c267e3f641e5.zip
LegacyCamera-b81d7a45d5514e0777f88c012a86c267e3f641e5.tar.gz
LegacyCamera-b81d7a45d5514e0777f88c012a86c267e3f641e5.tar.bz2
Improve the Texture by using glTexSubImage to upload the image content.
So that we can prevent create another Bitmap just to satisfied the limit that the width and height must be power of 2. Change-Id: Ie0cdb1e944fb2bf928464955851fe62d00394d70
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/ui/CanvasTexture.java3
-rw-r--r--src/com/android/camera/ui/ResourceTexture.java20
-rw-r--r--src/com/android/camera/ui/Texture.java27
3 files changed, 23 insertions, 27 deletions
diff --git a/src/com/android/camera/ui/CanvasTexture.java b/src/com/android/camera/ui/CanvasTexture.java
index f1ac85a..fa0b76e 100644
--- a/src/com/android/camera/ui/CanvasTexture.java
+++ b/src/com/android/camera/ui/CanvasTexture.java
@@ -2,6 +2,7 @@ package com.android.camera.ui;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Bitmap.Config;
/** Using a canvas to draw the texture */
public abstract class CanvasTexture extends Texture {
@@ -13,7 +14,7 @@ public abstract class CanvasTexture extends Texture {
@Override
protected Bitmap getBitmap() {
- Bitmap bitmap = generateGLCompatibleBitmap(mWidth, mHeight);
+ Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
mCanvas = new Canvas(bitmap);
onDraw(mCanvas, bitmap);
return bitmap;
diff --git a/src/com/android/camera/ui/ResourceTexture.java b/src/com/android/camera/ui/ResourceTexture.java
index 0d19d2a..e63a2ef 100644
--- a/src/com/android/camera/ui/ResourceTexture.java
+++ b/src/com/android/camera/ui/ResourceTexture.java
@@ -1,12 +1,10 @@
package com.android.camera.ui;
+import com.android.camera.Util;
+
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-
-import com.android.camera.Util;
public class ResourceTexture extends Texture {
@@ -22,17 +20,11 @@ public class ResourceTexture extends Texture {
@Override
protected Bitmap getBitmap() {
if (mBitmap != null) return mBitmap;
- mBitmap = BitmapFactory.decodeResource(mContext.getResources(), mResId);
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ mBitmap = BitmapFactory.decodeResource(
+ mContext.getResources(), mResId, options);
setSize(mBitmap.getWidth(), mBitmap.getHeight());
-
- if (Util.isPowerOf2(mWidth) && Util.isPowerOf2(mHeight)) return mBitmap;
-
- Bitmap oldBitmap = mBitmap;
- mBitmap = generateGLCompatibleBitmap(mWidth, mHeight);
- Canvas canvas = new Canvas(mBitmap);
- canvas.drawBitmap(oldBitmap, new Matrix(), null);
- oldBitmap.recycle();
-
return mBitmap;
}
diff --git a/src/com/android/camera/ui/Texture.java b/src/com/android/camera/ui/Texture.java
index a384d3a..0d4b6a1 100644
--- a/src/com/android/camera/ui/Texture.java
+++ b/src/com/android/camera/ui/Texture.java
@@ -1,11 +1,10 @@
package com.android.camera.ui;
+import com.android.camera.Util;
+
import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
import android.opengl.GLUtils;
-import com.android.camera.Util;
-
import javax.microedition.khronos.opengles.GL11;
import javax.microedition.khronos.opengles.GL11Ext;
@@ -96,7 +95,19 @@ public abstract class Texture {
GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
gl.glTexParameterf(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
- GLUtils.texImage2D(GL11.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ int width = bitmap.getWidth();
+ int height = bitmap.getHeight();
+ int widthExt = Util.nextPowerOf2(width);
+ int heightExt = Util.nextPowerOf2(height);
+ int format = GLUtils.getInternalFormat(bitmap);
+ int type = GLUtils.getType(bitmap);
+ mTexCoordWidth = (float) width / widthExt;
+ mTexCoordHeight = (float) height / heightExt;
+ gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format,
+ widthExt, heightExt, 0, format, type, null);
+ GLUtils.texSubImage2D(
+ GL11.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
} finally {
freeBitmap(bitmap);
}
@@ -156,12 +167,4 @@ public abstract class Texture {
coord[offset++] = w;
coord[offset] = h;
}
-
- protected Bitmap generateGLCompatibleBitmap(int width, int height) {
- int newWidth = Util.nextPowerOf2(width);
- int newHeight = Util.nextPowerOf2(height);
- mTexCoordWidth = (float) width / newWidth;
- mTexCoordHeight = (float) height / newHeight;
- return Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888);
- }
}