summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2012-06-28 17:12:20 +0800
committerOwen Lin <owenlin@google.com>2012-07-03 18:05:47 +0800
commit7aac26484af3d40df81e1d08c673bd925856a7fa (patch)
tree4f444fc13ca1ee651f2e5e75787b5f1c16cef9eb /src
parentce8b4485801843c14abc3654e57aad96d1364e49 (diff)
downloadandroid_packages_apps_Snap-7aac26484af3d40df81e1d08c673bd925856a7fa.tar.gz
android_packages_apps_Snap-7aac26484af3d40df81e1d08c673bd925856a7fa.tar.bz2
android_packages_apps_Snap-7aac26484af3d40df81e1d08c673bd925856a7fa.zip
Don't reuse bitmap before HoneyComb.
Change-Id: I0df9bf0a8f43e28ed25b436d4c584dc3ceb43c1d
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/app/AbstractGalleryActivity.java10
-rw-r--r--src/com/android/gallery3d/app/CropImage.java3
-rw-r--r--src/com/android/gallery3d/app/MoviePlayer.java5
-rw-r--r--src/com/android/gallery3d/app/Wallpaper.java2
-rw-r--r--src/com/android/gallery3d/data/BitmapPool.java69
-rw-r--r--src/com/android/gallery3d/data/DecodeUtils.java79
-rw-r--r--src/com/android/gallery3d/data/ImageCacheRequest.java10
-rw-r--r--src/com/android/gallery3d/data/LocalImage.java3
-rw-r--r--src/com/android/gallery3d/data/MediaItem.java14
-rw-r--r--src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java4
-rw-r--r--src/com/android/gallery3d/ui/AlbumSlidingWindow.java4
-rw-r--r--src/com/android/gallery3d/ui/BitmapScreenNail.java16
-rw-r--r--src/com/android/gallery3d/ui/GLRootView.java3
13 files changed, 130 insertions, 92 deletions
diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java
index 0987ac39f..9b2a85ed4 100644
--- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java
+++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java
@@ -32,6 +32,7 @@ import android.view.Window;
import android.view.WindowManager;
import com.android.gallery3d.R;
+import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.DataManager;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.ui.GLRoot;
@@ -188,11 +189,16 @@ public class AbstractGalleryActivity extends Activity implements GalleryActivity
} finally {
mGLRootView.unlockRenderThread();
}
- MediaItem.getMicroThumbPool().clear();
- MediaItem.getThumbPool().clear();
+ clearBitmapPool(MediaItem.getMicroThumbPool());
+ clearBitmapPool(MediaItem.getThumbPool());
+
MediaItem.getBytesBufferPool().clear();
}
+ private static void clearBitmapPool(BitmapPool pool) {
+ if (pool != null) pool.clear();
+ }
+
@Override
protected void onDestroy() {
super.onDestroy();
diff --git a/src/com/android/gallery3d/app/CropImage.java b/src/com/android/gallery3d/app/CropImage.java
index f2646978a..294e285ea 100644
--- a/src/com/android/gallery3d/app/CropImage.java
+++ b/src/com/android/gallery3d/app/CropImage.java
@@ -33,6 +33,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.media.ExifInterface;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -369,7 +370,7 @@ public class CropImage extends AbstractGalleryActivity {
}
}
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void setImageSize(ContentValues values, int width, int height) {
// The two fields are available since ICS but got published in JB
if (ApiHelper.HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT) {
diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java
index 4f72c13ba..660c4d953 100644
--- a/src/com/android/gallery3d/app/MoviePlayer.java
+++ b/src/com/android/gallery3d/app/MoviePlayer.java
@@ -29,6 +29,7 @@ import android.graphics.Color;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
@@ -178,7 +179,7 @@ public class MoviePlayer implements
}
}
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setOnSystemUiVisibilityChangeListener() {
if (!ApiHelper.HAS_VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION) return;
@@ -212,7 +213,7 @@ public class MoviePlayer implements
});
}
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showSystemUi(boolean visible) {
if (!ApiHelper.HAS_VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE) return;
diff --git a/src/com/android/gallery3d/app/Wallpaper.java b/src/com/android/gallery3d/app/Wallpaper.java
index 1ece66c49..996d3f080 100644
--- a/src/com/android/gallery3d/app/Wallpaper.java
+++ b/src/com/android/gallery3d/app/Wallpaper.java
@@ -63,7 +63,7 @@ public class Wallpaper extends Activity {
}
@SuppressWarnings("deprecation")
- @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB_MR2)
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private Point getDefaultDisplaySize(Point size) {
Display d = getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= ApiHelper.VERSION_CODES.HONEYCOMB_MR2) {
diff --git a/src/com/android/gallery3d/data/BitmapPool.java b/src/com/android/gallery3d/data/BitmapPool.java
index 0fbd84ef5..1151dded7 100644
--- a/src/com/android/gallery3d/data/BitmapPool.java
+++ b/src/com/android/gallery3d/data/BitmapPool.java
@@ -17,14 +17,9 @@
package com.android.gallery3d.data;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.BitmapFactory.Options;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.ui.Log;
-import com.android.gallery3d.util.ThreadPool.JobContext;
-import java.io.FileDescriptor;
import java.util.ArrayList;
public class BitmapPool {
@@ -94,67 +89,7 @@ public class BitmapPool {
mPool.clear();
}
- private Bitmap findCachedBitmap(JobContext jc,
- byte[] data, int offset, int length, Options options) {
- if (mOneSize) return getBitmap();
- DecodeUtils.decodeBounds(jc, data, offset, length, options);
- return getBitmap(options.outWidth, options.outHeight);
- }
-
- private Bitmap findCachedBitmap(JobContext jc,
- FileDescriptor fileDescriptor, Options options) {
- if (mOneSize) return getBitmap();
- DecodeUtils.decodeBounds(jc, fileDescriptor, options);
- return getBitmap(options.outWidth, options.outHeight);
- }
-
- public Bitmap decode(JobContext jc,
- byte[] data, int offset, int length, BitmapFactory.Options options) {
- if (options == null) options = new BitmapFactory.Options();
- if (options.inSampleSize < 1) options.inSampleSize = 1;
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- options.inBitmap = (options.inSampleSize == 1)
- ? findCachedBitmap(jc, data, offset, length, options) : null;
- try {
- Bitmap bitmap = DecodeUtils.decode(jc, data, offset, length, options);
- if (options.inBitmap != null && options.inBitmap != bitmap) {
- recycle(options.inBitmap);
- options.inBitmap = null;
- }
- return bitmap;
- } catch (IllegalArgumentException e) {
- if (options.inBitmap == null) throw e;
-
- Log.w(TAG, "decode fail with a given bitmap, try decode to a new bitmap");
- recycle(options.inBitmap);
- options.inBitmap = null;
- return DecodeUtils.decode(jc, data, offset, length, options);
- }
- }
-
- // This is the same as the method above except the source data comes
- // from a file descriptor instead of a byte array.
- public Bitmap decode(JobContext jc,
- FileDescriptor fileDescriptor, Options options) {
- if (options == null) options = new BitmapFactory.Options();
- if (options.inSampleSize < 1) options.inSampleSize = 1;
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- options.inBitmap = (options.inSampleSize == 1)
- ? findCachedBitmap(jc, fileDescriptor, options) : null;
- try {
- Bitmap bitmap = DecodeUtils.decode(jc, fileDescriptor, options);
- if (options.inBitmap != null&& options.inBitmap != bitmap) {
- recycle(options.inBitmap);
- options.inBitmap = null;
- }
- return bitmap;
- } catch (IllegalArgumentException e) {
- if (options.inBitmap == null) throw e;
-
- Log.w(TAG, "decode fail with a given bitmap, try decode to a new bitmap");
- recycle(options.inBitmap);
- options.inBitmap = null;
- return DecodeUtils.decode(jc, fileDescriptor, options);
- }
+ public boolean isOneSize() {
+ return mOneSize;
}
}
diff --git a/src/com/android/gallery3d/data/DecodeUtils.java b/src/com/android/gallery3d/data/DecodeUtils.java
index e51dc3fa9..773af74bb 100644
--- a/src/com/android/gallery3d/data/DecodeUtils.java
+++ b/src/com/android/gallery3d/data/DecodeUtils.java
@@ -16,15 +16,18 @@
package com.android.gallery3d.data;
+import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.BitmapRegionDecoder;
+import android.os.Build;
import android.util.FloatMath;
import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.ui.Log;
import com.android.gallery3d.util.ThreadPool.CancelListener;
import com.android.gallery3d.util.ThreadPool.JobContext;
@@ -33,7 +36,7 @@ import java.io.FileInputStream;
import java.io.InputStream;
public class DecodeUtils {
- private static final String TAG = "DecodeService";
+ private static final String TAG = "DecodeUtils";
private static class DecodeCanceller implements CancelListener {
Options mOptions;
@@ -230,4 +233,78 @@ public class DecodeUtils {
return null;
}
}
+
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public static Bitmap decode(JobContext jc, byte[] data, int offset,
+ int length, BitmapFactory.Options options, BitmapPool pool) {
+ if (pool == null) {
+ return decode(jc, data, offset, length, options);
+ }
+
+ if (options == null) options = new BitmapFactory.Options();
+ if (options.inSampleSize < 1) options.inSampleSize = 1;
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ options.inBitmap = (options.inSampleSize == 1)
+ ? findCachedBitmap(pool, jc, data, offset, length, options) : null;
+ try {
+ Bitmap bitmap = decode(jc, data, offset, length, options);
+ if (options.inBitmap != null && options.inBitmap != bitmap) {
+ pool.recycle(options.inBitmap);
+ options.inBitmap = null;
+ }
+ return bitmap;
+ } catch (IllegalArgumentException e) {
+ if (options.inBitmap == null) throw e;
+
+ Log.w(TAG, "decode fail with a given bitmap, try decode to a new bitmap");
+ pool.recycle(options.inBitmap);
+ options.inBitmap = null;
+ return decode(jc, data, offset, length, options);
+ }
+ }
+
+ // This is the same as the method above except the source data comes
+ // from a file descriptor instead of a byte array.
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+ public static Bitmap decode(JobContext jc,
+ FileDescriptor fileDescriptor, Options options, BitmapPool pool) {
+ if (pool == null) {
+ return decode(jc, fileDescriptor, options);
+ }
+
+ if (options == null) options = new BitmapFactory.Options();
+ if (options.inSampleSize < 1) options.inSampleSize = 1;
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ options.inBitmap = (options.inSampleSize == 1)
+ ? findCachedBitmap(pool, jc, fileDescriptor, options) : null;
+ try {
+ Bitmap bitmap = DecodeUtils.decode(jc, fileDescriptor, options);
+ if (options.inBitmap != null && options.inBitmap != bitmap) {
+ pool.recycle(options.inBitmap);
+ options.inBitmap = null;
+ }
+ return bitmap;
+ } catch (IllegalArgumentException e) {
+ if (options.inBitmap == null) throw e;
+
+ Log.w(TAG, "decode fail with a given bitmap, try decode to a new bitmap");
+ pool.recycle(options.inBitmap);
+ options.inBitmap = null;
+ return decode(jc, fileDescriptor, options);
+ }
+ }
+
+ private static Bitmap findCachedBitmap(BitmapPool pool, JobContext jc,
+ byte[] data, int offset, int length, Options options) {
+ if (pool.isOneSize()) return pool.getBitmap();
+ decodeBounds(jc, data, offset, length, options);
+ return pool.getBitmap(options.outWidth, options.outHeight);
+ }
+
+ private static Bitmap findCachedBitmap(BitmapPool pool, JobContext jc,
+ FileDescriptor fileDescriptor, Options options) {
+ if (pool.isOneSize()) return pool.getBitmap();
+ decodeBounds(jc, fileDescriptor, options);
+ return pool.getBitmap(options.outWidth, options.outHeight);
+ }
}
diff --git a/src/com/android/gallery3d/data/ImageCacheRequest.java b/src/com/android/gallery3d/data/ImageCacheRequest.java
index 81660c915..b977b1016 100644
--- a/src/com/android/gallery3d/data/ImageCacheRequest.java
+++ b/src/com/android/gallery3d/data/ImageCacheRequest.java
@@ -57,11 +57,13 @@ abstract class ImageCacheRequest implements Job<Bitmap> {
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap;
if (mType == MediaItem.TYPE_MICROTHUMBNAIL) {
- bitmap = MediaItem.getMicroThumbPool().decode(jc,
- buffer.data, buffer.offset, buffer.length, options);
+ bitmap = DecodeUtils.decode(jc,
+ buffer.data, buffer.offset, buffer.length, options,
+ MediaItem.getMicroThumbPool());
} else {
- bitmap = MediaItem.getThumbPool().decode(jc,
- buffer.data, buffer.offset, buffer.length, options);
+ bitmap = DecodeUtils.decode(jc,
+ buffer.data, buffer.offset, buffer.length, options,
+ MediaItem.getThumbPool());
}
if (bitmap == null && !jc.isCancelled()) {
Log.w(TAG, "decode cached failed " + debugTag);
diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java
index 316e32469..c432ab44d 100644
--- a/src/com/android/gallery3d/data/LocalImage.java
+++ b/src/com/android/gallery3d/data/LocalImage.java
@@ -25,6 +25,7 @@ import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.media.ExifInterface;
import android.net.Uri;
+import android.os.Build;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.ImageColumns;
import android.provider.MediaStore.MediaColumns;
@@ -85,7 +86,7 @@ public class LocalImage extends LocalMediaItem {
updateWidthAndHeightProjection();
}
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void updateWidthAndHeightProjection() {
if (ApiHelper.HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT) {
PROJECTION[INDEX_WIDTH] = MediaColumns.WIDTH;
diff --git a/src/com/android/gallery3d/data/MediaItem.java b/src/com/android/gallery3d/data/MediaItem.java
index f0f1af434..15bb17623 100644
--- a/src/com/android/gallery3d/data/MediaItem.java
+++ b/src/com/android/gallery3d/data/MediaItem.java
@@ -19,6 +19,7 @@ package com.android.gallery3d.data;
import android.graphics.Bitmap;
import android.graphics.BitmapRegionDecoder;
+import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.ui.ScreenNail;
import com.android.gallery3d.util.ThreadPool.Job;
@@ -42,9 +43,16 @@ public abstract class MediaItem extends MediaObject {
private static final int BYTESBUFFE_POOL_SIZE = 4;
private static final int BYTESBUFFER_SIZE = 200 * 1024;
- private static final BitmapPool sMicroThumbPool = new BitmapPool(
- MICROTHUMBNAIL_TARGET_SIZE, MICROTHUMBNAIL_TARGET_SIZE, 16);
- private static final BitmapPool sThumbPool = new BitmapPool(4);
+ private static final BitmapPool sMicroThumbPool =
+ ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_FACTORY
+ ? new BitmapPool(MICROTHUMBNAIL_TARGET_SIZE, MICROTHUMBNAIL_TARGET_SIZE, 16)
+ : null;
+
+ private static final BitmapPool sThumbPool =
+ ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_FACTORY
+ ? new BitmapPool(4)
+ : null;
+
private static final BytesBufferPool sMicroThumbBufferPool =
new BytesBufferPool(BYTESBUFFE_POOL_SIZE, BYTESBUFFER_SIZE);
diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
index 6561a23f3..449c6f9d3 100644
--- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
@@ -23,6 +23,7 @@ import com.android.gallery3d.R;
import com.android.gallery3d.app.AlbumSetDataLoader;
import com.android.gallery3d.app.GalleryActivity;
import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.DataSourceType;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.MediaObject;
@@ -423,7 +424,8 @@ public class AlbumSetSlidingWindow implements AlbumSetDataLoader.DataListener {
@Override
protected void recycleBitmap(Bitmap bitmap) {
- MediaItem.getMicroThumbPool().recycle(bitmap);
+ BitmapPool pool = MediaItem.getMicroThumbPool();
+ if (pool != null) pool.recycle(bitmap);
}
@Override
diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
index deec1712d..d5d90a9ea 100644
--- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
@@ -22,6 +22,7 @@ import android.os.Message;
import com.android.gallery3d.app.AlbumDataLoader;
import com.android.gallery3d.app.GalleryActivity;
import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.Path;
import com.android.gallery3d.util.Future;
@@ -277,7 +278,8 @@ public class AlbumSlidingWindow implements AlbumDataLoader.DataListener {
@Override
protected void recycleBitmap(Bitmap bitmap) {
- MediaItem.getMicroThumbPool().recycle(bitmap);
+ BitmapPool pool = MediaItem.getMicroThumbPool();
+ if (pool != null) pool.recycle(bitmap);
}
@Override
diff --git a/src/com/android/gallery3d/ui/BitmapScreenNail.java b/src/com/android/gallery3d/ui/BitmapScreenNail.java
index 5c917570d..0043e0cbe 100644
--- a/src/com/android/gallery3d/ui/BitmapScreenNail.java
+++ b/src/com/android/gallery3d/ui/BitmapScreenNail.java
@@ -20,6 +20,7 @@ import android.graphics.Bitmap;
import android.graphics.RectF;
import com.android.gallery3d.common.Utils;
+import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.MediaItem;
// This is a ScreenNail wraps a Bitmap. There are some extra functions:
@@ -70,6 +71,11 @@ public class BitmapScreenNail implements ScreenNail {
mHeight = Math.round(scale * height);
}
+ private static void recycleBitmap(BitmapPool pool, Bitmap bitmap) {
+ if (pool == null || bitmap == null) return;
+ pool.recycle(bitmap);
+ }
+
// Combines the two ScreenNails.
// Returns the used one and recycle the unused one.
public ScreenNail combine(ScreenNail other) {
@@ -88,9 +94,7 @@ public class BitmapScreenNail implements ScreenNail {
mWidth = newer.mWidth;
mHeight = newer.mHeight;
if (newer.mBitmap != null) {
- if (mBitmap != null) {
- MediaItem.getThumbPool().recycle(mBitmap);
- }
+ recycleBitmap(MediaItem.getThumbPool(), mBitmap);
mBitmap = newer.mBitmap;
newer.mBitmap = null;
@@ -130,10 +134,8 @@ public class BitmapScreenNail implements ScreenNail {
mTexture.recycle();
mTexture = null;
}
- if (mBitmap != null) {
- MediaItem.getThumbPool().recycle(mBitmap);
- mBitmap = null;
- }
+ recycleBitmap(MediaItem.getThumbPool(), mBitmap);
+ mBitmap = null;
}
@Override
diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java
index 401ca59eb..fe4e19d7b 100644
--- a/src/com/android/gallery3d/ui/GLRootView.java
+++ b/src/com/android/gallery3d/ui/GLRootView.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
+import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
import android.util.AttributeSet;
@@ -536,7 +537,7 @@ public class GLRootView extends GLSurfaceView
}
@Override
- @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setLightsOutMode(boolean enabled) {
int flags = 0;
if (enabled) {