summaryrefslogtreecommitdiffstats
path: root/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
diff options
context:
space:
mode:
Diffstat (limited to 'WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java')
-rw-r--r--WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java138
1 files changed, 19 insertions, 119 deletions
diff --git a/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java b/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
index 8075bf868..607e2a943 100644
--- a/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
+++ b/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
@@ -19,14 +19,12 @@ package com.android.gallery3d.glrenderer;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.opengl.GLUtils;
+import android.util.Pair;
import com.android.gallery3d.common.Utils;
-import com.android.launcher3.util.Thunk;
import java.util.HashMap;
-import javax.microedition.khronos.opengles.GL11;
-
// UploadedTextures use a Bitmap for the content of the texture.
//
// Subclasses should implement onGetBitmap() to provide the Bitmap and
@@ -45,89 +43,29 @@ public abstract class UploadedTexture extends BasicTexture {
// To prevent keeping allocation the borders, we store those used borders here.
// Since the length will be power of two, it won't use too much memory.
- private static HashMap<BorderKey, Bitmap> sBorderLines =
- new HashMap<BorderKey, Bitmap>();
- private static BorderKey sBorderKey = new BorderKey();
-
- @SuppressWarnings("unused")
- private static final String TAG = "Texture";
- private boolean mContentValid = true;
+ private static HashMap<BorderKey, Bitmap> sBorderLines = new HashMap<BorderKey, Bitmap>();
- // indicate this textures is being uploaded in background
- private boolean mIsUploading = false;
- private boolean mOpaque = true;
- private boolean mThrottled = false;
- private static int sUploadedCount;
- private static final int UPLOAD_LIMIT = 100;
+ private static class BorderKey extends Pair<Config, Integer> {
+ public BorderKey(Config config, boolean vertical, int length) {
+ super(config, vertical ? length : -length);
+ }
+ }
+ private boolean mContentValid = true;
protected Bitmap mBitmap;
- private int mBorder;
protected UploadedTexture() {
- this(false);
- }
-
- protected UploadedTexture(boolean hasBorder) {
super(null, 0, STATE_UNLOADED);
- if (hasBorder) {
- setBorder(true);
- mBorder = 1;
- }
- }
-
- protected void setIsUploading(boolean uploading) {
- mIsUploading = uploading;
}
- public boolean isUploading() {
- return mIsUploading;
- }
-
- @Thunk static class BorderKey implements Cloneable {
- public boolean vertical;
- public Config config;
- public int length;
-
- @Override
- public int hashCode() {
- int x = config.hashCode() ^ length;
- return vertical ? x : -x;
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof BorderKey)) return false;
- BorderKey o = (BorderKey) object;
- return vertical == o.vertical
- && config == o.config && length == o.length;
- }
-
- @Override
- public BorderKey clone() {
- try {
- return (BorderKey) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new AssertionError(e);
- }
- }
- }
-
- protected void setThrottled(boolean throttled) {
- mThrottled = throttled;
- }
-
- private static Bitmap getBorderLine(
- boolean vertical, Config config, int length) {
- BorderKey key = sBorderKey;
- key.vertical = vertical;
- key.config = config;
- key.length = length;
+ private static Bitmap getBorderLine(boolean vertical, Config config, int length) {
+ BorderKey key = new BorderKey(config, vertical, length);
Bitmap bitmap = sBorderLines.get(key);
if (bitmap == null) {
bitmap = vertical
? Bitmap.createBitmap(1, length, config)
: Bitmap.createBitmap(length, 1, config);
- sBorderLines.put(key.clone(), bitmap);
+ sBorderLines.put(key, bitmap);
}
return bitmap;
}
@@ -135,8 +73,8 @@ public abstract class UploadedTexture extends BasicTexture {
private Bitmap getBitmap() {
if (mBitmap == null) {
mBitmap = onGetBitmap();
- int w = mBitmap.getWidth() + mBorder * 2;
- int h = mBitmap.getHeight() + mBorder * 2;
+ int w = mBitmap.getWidth();
+ int h = mBitmap.getHeight();
if (mWidth == UNSPECIFIED) {
setSize(w, h);
}
@@ -186,37 +124,23 @@ public abstract class UploadedTexture extends BasicTexture {
*/
public void updateContent(GLCanvas canvas) {
if (!isLoaded()) {
- if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
- return;
- }
uploadToCanvas(canvas);
} else if (!mContentValid) {
Bitmap bitmap = getBitmap();
int format = GLUtils.getInternalFormat(bitmap);
int type = GLUtils.getType(bitmap);
- canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
+ canvas.texSubImage2D(this, 0, 0, bitmap, format, type);
freeBitmap();
mContentValid = true;
}
}
- public static void resetUploadLimit() {
- sUploadedCount = 0;
- }
-
- public static boolean uploadLimitReached() {
- return sUploadedCount > UPLOAD_LIMIT;
- }
-
private void uploadToCanvas(GLCanvas canvas) {
-
Bitmap bitmap = getBitmap();
if (bitmap != null) {
try {
int bWidth = bitmap.getWidth();
int bHeight = bitmap.getHeight();
- int width = bWidth + mBorder * 2;
- int height = bHeight + mBorder * 2;
int texWidth = getTextureWidth();
int texHeight = getTextureHeight();
@@ -234,28 +158,18 @@ public abstract class UploadedTexture extends BasicTexture {
Config config = bitmap.getConfig();
canvas.initializeTextureSize(this, format, type);
- canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
-
- if (mBorder > 0) {
- // Left border
- Bitmap line = getBorderLine(true, config, texHeight);
- canvas.texSubImage2D(this, 0, 0, line, format, type);
-
- // Top border
- line = getBorderLine(false, config, texWidth);
- canvas.texSubImage2D(this, 0, 0, line, format, type);
- }
+ canvas.texSubImage2D(this, 0, 0, bitmap, format, type);
// Right border
- if (mBorder + bWidth < texWidth) {
+ if (bWidth < texWidth) {
Bitmap line = getBorderLine(true, config, texHeight);
- canvas.texSubImage2D(this, mBorder + bWidth, 0, line, format, type);
+ canvas.texSubImage2D(this, bWidth, 0, line, format, type);
}
// Bottom border
- if (mBorder + bHeight < texHeight) {
+ if (bHeight < texHeight) {
Bitmap line = getBorderLine(false, config, texWidth);
- canvas.texSubImage2D(this, 0, mBorder + bHeight, line, format, type);
+ canvas.texSubImage2D(this, 0, bHeight, line, format, type);
}
}
} finally {
@@ -278,20 +192,6 @@ public abstract class UploadedTexture extends BasicTexture {
}
@Override
- protected int getTarget() {
- return GL11.GL_TEXTURE_2D;
- }
-
- public void setOpaque(boolean isOpaque) {
- mOpaque = isOpaque;
- }
-
- @Override
- public boolean isOpaque() {
- return mOpaque;
- }
-
- @Override
public void recycle() {
super.recycle();
if (mBitmap != null) freeBitmap();