summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2012-05-21 16:52:25 -0700
committerOwen Lin <owenlin@google.com>2012-05-22 09:41:46 -0700
commit3bd73388114f851dcb67d1ce38966e4d22fd1d22 (patch)
tree0d210484fcac347f23abd0a349ad9a7dc7fca5ff /src
parent7f9061790e1b67b6c674314ac41a399c550f8b88 (diff)
downloadandroid_packages_apps_Snap-3bd73388114f851dcb67d1ce38966e4d22fd1d22.tar.gz
android_packages_apps_Snap-3bd73388114f851dcb67d1ce38966e4d22fd1d22.tar.bz2
android_packages_apps_Snap-3bd73388114f851dcb67d1ce38966e4d22fd1d22.zip
Limit the size of a ScreenNail.
bug:6528366 This bug was happened because we are trying to make a texture beyond the max size allowed in GL. Here is what we do in this CL: 1. Limit the size of a screen nail 2. Print warning message, if we try to allocate a texture beyond the size 3. Don't show fall-back animation if the image is not loaded yet. Change-Id: I004b1138efd0eef7ba11aa89556f67743ca46745
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/app/PhotoDataAdapter.java6
-rw-r--r--src/com/android/gallery3d/ui/BasicTexture.java6
-rw-r--r--src/com/android/gallery3d/ui/BitmapScreenNail.java21
-rw-r--r--src/com/android/gallery3d/ui/GLRootView.java2
-rw-r--r--src/com/android/gallery3d/ui/PhotoView.java5
5 files changed, 29 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java
index 6ba1ff69b..29154a082 100644
--- a/src/com/android/gallery3d/app/PhotoDataAdapter.java
+++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java
@@ -415,7 +415,7 @@ public class PhotoDataAdapter implements PhotoPage.Model {
// Create a default ScreenNail if the real one is not available yet.
if (entry.screenNail == null) {
- entry.screenNail = newDefaultScreenNail(item);
+ entry.screenNail = newPlaceholderScreenNail(item);
if (offset == 0) updateTileProvider(entry);
}
@@ -632,7 +632,7 @@ public class PhotoDataAdapter implements PhotoPage.Model {
// If this is a temporary item, don't try to get its bitmap because
// it won't be available. We will get its bitmap after a data reload.
if (isTemporaryItem(mItem)) {
- return newDefaultScreenNail(mItem);
+ return newPlaceholderScreenNail(mItem);
}
Bitmap bitmap = mItem.requestImage(MediaItem.TYPE_THUMBNAIL).run(jc);
@@ -687,7 +687,7 @@ public class PhotoDataAdapter implements PhotoPage.Model {
// Create a default ScreenNail when a ScreenNail is needed, but we don't yet
// have one available (because the image data is still being saved, or the
// Bitmap is still being loaded.
- private ScreenNail newDefaultScreenNail(MediaItem item) {
+ private ScreenNail newPlaceholderScreenNail(MediaItem item) {
int width = item.getWidth();
int height = item.getHeight();
return new BitmapScreenNail(width, height);
diff --git a/src/com/android/gallery3d/ui/BasicTexture.java b/src/com/android/gallery3d/ui/BasicTexture.java
index 6a9a17d92..68a5b7d32 100644
--- a/src/com/android/gallery3d/ui/BasicTexture.java
+++ b/src/com/android/gallery3d/ui/BasicTexture.java
@@ -33,6 +33,8 @@ abstract class BasicTexture implements Texture {
protected static final int STATE_LOADED = 1;
protected static final int STATE_ERROR = -1;
+ private static final int MAX_TEXTURE_SIZE = 2048;
+
protected int mId;
protected int mState;
@@ -75,6 +77,10 @@ abstract class BasicTexture implements Texture {
mHeight = height;
mTextureWidth = Utils.nextPowerOf2(width);
mTextureHeight = Utils.nextPowerOf2(height);
+ if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) {
+ Log.w(TAG, String.format("texture is too large: %d x %d",
+ mTextureWidth, mTextureHeight), new Exception());
+ }
}
public int getId() {
diff --git a/src/com/android/gallery3d/ui/BitmapScreenNail.java b/src/com/android/gallery3d/ui/BitmapScreenNail.java
index 14d3f1919..5c917570d 100644
--- a/src/com/android/gallery3d/ui/BitmapScreenNail.java
+++ b/src/com/android/gallery3d/ui/BitmapScreenNail.java
@@ -18,7 +18,6 @@ package com.android.gallery3d.ui;
import android.graphics.Bitmap;
import android.graphics.RectF;
-import android.util.Log;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.MediaItem;
@@ -35,6 +34,9 @@ public class BitmapScreenNail implements ScreenNail {
private static final int PLACEHOLDER_COLOR = 0xFF222222;
// The duration of the fading animation in milliseconds
private static final int DURATION = 180;
+
+ private static final int MAX_SIDE = 640;
+
// These are special values for mAnimationStartTime
private static final long ANIMATION_NOT_NEEDED = -1;
private static final long ANIMATION_NEEDED = -2;
@@ -44,7 +46,6 @@ public class BitmapScreenNail implements ScreenNail {
private int mHeight;
private Bitmap mBitmap;
private BitmapTexture mTexture;
- private FadeInTexture mFadeInTexture;
private long mAnimationStartTime = ANIMATION_NOT_NEEDED;
public BitmapScreenNail(Bitmap bitmap) {
@@ -56,12 +57,17 @@ public class BitmapScreenNail implements ScreenNail {
}
public BitmapScreenNail(int width, int height) {
+ setSize(width, height);
+ }
+
+ private void setSize(int width, int height) {
if (width == 0 || height == 0) {
width = 640;
height = 480;
}
- mWidth = width;
- mHeight = height;
+ float scale = Math.min(1, (float) MAX_SIDE / Math.max(width, height));
+ mWidth = Math.round(scale * width);
+ mHeight = Math.round(scale * height);
}
// Combines the two ScreenNails.
@@ -101,8 +107,7 @@ public class BitmapScreenNail implements ScreenNail {
public void updatePlaceholderSize(int width, int height) {
if (mBitmap != null) return;
if (width == 0 || height == 0) return;
- mWidth = width;
- mHeight = height;
+ setSize(width, height);
}
@Override
@@ -189,4 +194,8 @@ public class BitmapScreenNail implements ScreenNail {
float r = (float)(now() - mAnimationStartTime) / DURATION;
return Utils.clamp(1.0f - r, 0.0f, 1.0f);
}
+
+ public boolean isShowingPlaceholder() {
+ return (mBitmap == null) || isAnimating();
+ }
}
diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java
index 987e9a2ae..8783b66bb 100644
--- a/src/com/android/gallery3d/ui/GLRootView.java
+++ b/src/com/android/gallery3d/ui/GLRootView.java
@@ -118,7 +118,7 @@ public class GLRootView extends GLSurfaceView
getHolder().setFormat(PixelFormat.RGB_565);
// Uncomment this to enable gl error check.
- //setDebugFlags(DEBUG_CHECK_GL_ERROR);
+ // setDebugFlags(DEBUG_CHECK_GL_ERROR);
}
@Override
diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java
index fd08e0eb3..654fcd586 100644
--- a/src/com/android/gallery3d/ui/PhotoView.java
+++ b/src/com/android/gallery3d/ui/PhotoView.java
@@ -1334,7 +1334,10 @@ public class PhotoView extends GLView {
MediaItem item = mModel.getMediaItem(i);
if (item == null) continue;
ScreenNail sc = mModel.getScreenNail(i);
- if (sc == null) continue;
+ if (!(sc instanceof BitmapScreenNail)
+ || ((BitmapScreenNail) sc).isShowingPlaceholder()) continue;
+
+ // Now, sc is BitmapScreenNail and is not showing placeholder
Rect rect = new Rect(getPhotoRect(i));
if (!Rect.intersects(fullRect, rect)) continue;
rect.offset(location.left, location.top);