summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui/BitmapScreenNail.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/ui/BitmapScreenNail.java')
-rw-r--r--src/com/android/gallery3d/ui/BitmapScreenNail.java49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/com/android/gallery3d/ui/BitmapScreenNail.java b/src/com/android/gallery3d/ui/BitmapScreenNail.java
index 9b629160c..bf31bcbdf 100644
--- a/src/com/android/gallery3d/ui/BitmapScreenNail.java
+++ b/src/com/android/gallery3d/ui/BitmapScreenNail.java
@@ -46,16 +46,16 @@ public class BitmapScreenNail implements ScreenNail {
private int mWidth;
private int mHeight;
- private long mAnimationStartTime = ANIMATION_NOT_NEEDED;
-
private Bitmap mBitmap;
- private TiledTexture mTexture;
+ private BitmapTexture mTexture;
+ private long mAnimationStartTime = ANIMATION_NOT_NEEDED;
public BitmapScreenNail(Bitmap bitmap) {
mWidth = bitmap.getWidth();
mHeight = bitmap.getHeight();
mBitmap = bitmap;
- mTexture = new TiledTexture(bitmap);
+ // We create mTexture lazily, so we don't incur the cost if we don't
+ // actually need it.
}
public BitmapScreenNail(int width, int height) {
@@ -103,14 +103,17 @@ public class BitmapScreenNail implements ScreenNail {
BitmapScreenNail newer = (BitmapScreenNail) other;
mWidth = newer.mWidth;
mHeight = newer.mHeight;
- if (newer.mTexture != null) {
+ if (newer.mBitmap != null) {
recycleBitmap(MediaItem.getThumbPool(), mBitmap);
- if (mTexture != null) mTexture.recycle();
mBitmap = newer.mBitmap;
- mTexture = newer.mTexture;
newer.mBitmap = null;
- newer.mTexture = null;
+
+ if (mTexture != null) {
+ mTexture.recycle();
+ mTexture = null;
+ }
}
+
newer.recycle();
return this;
}
@@ -155,7 +158,7 @@ public class BitmapScreenNail implements ScreenNail {
@Override
public void draw(GLCanvas canvas, int x, int y, int width, int height) {
- if (mTexture == null || !mTexture.isReady()) {
+ if (mBitmap == null) {
if (mAnimationStartTime == ANIMATION_NOT_NEEDED) {
mAnimationStartTime = ANIMATION_NEEDED;
}
@@ -165,12 +168,16 @@ public class BitmapScreenNail implements ScreenNail {
return;
}
+ if (mTexture == null) {
+ mTexture = new BitmapTexture(mBitmap);
+ }
+
if (mAnimationStartTime == ANIMATION_NEEDED) {
- mAnimationStartTime = AnimationTime.get();
+ mAnimationStartTime = now();
}
if (isAnimating()) {
- mTexture.drawMixed(canvas, mPlaceholderColor, getRatio(), x, y,
+ canvas.drawMixed(mTexture, mPlaceholderColor, getRatio(), x, y,
width, height);
} else {
mTexture.draw(canvas, x, y, width, height);
@@ -179,26 +186,34 @@ public class BitmapScreenNail implements ScreenNail {
@Override
public void draw(GLCanvas canvas, RectF source, RectF dest) {
- if (mTexture == null || !mTexture.isReady()) {
+ if (mBitmap == null) {
canvas.fillRect(dest.left, dest.top, dest.width(), dest.height(),
mPlaceholderColor);
return;
}
- mTexture.draw(canvas, source, dest);
+ if (mTexture == null) {
+ mTexture = new BitmapTexture(mBitmap);
+ }
+
+ canvas.drawTexture(mTexture, source, dest);
}
public boolean isAnimating() {
if (mAnimationStartTime < 0) return false;
- if (AnimationTime.get() - mAnimationStartTime >= DURATION) {
+ if (now() - mAnimationStartTime >= DURATION) {
mAnimationStartTime = ANIMATION_DONE;
return false;
}
return true;
}
+ private static long now() {
+ return AnimationTime.get();
+ }
+
private float getRatio() {
- float r = (float) (AnimationTime.get() - mAnimationStartTime) / DURATION;
+ float r = (float)(now() - mAnimationStartTime) / DURATION;
return Utils.clamp(1.0f - r, 0.0f, 1.0f);
}
@@ -206,10 +221,6 @@ public class BitmapScreenNail implements ScreenNail {
return (mBitmap == null) || isAnimating();
}
- public TiledTexture getTexture() {
- return mTexture;
- }
-
public static void setMaxSide(int size) {
sMaxSide = size;
}