summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui
diff options
context:
space:
mode:
authorBobby Georgescu <georgescu@google.com>2013-02-19 15:49:14 -0800
committerBobby Georgescu <georgescu@google.com>2013-02-22 12:56:23 -0800
commit11cfeeddedd61d3c4aa40945fef0bc2d87c7559d (patch)
treeab09906b8fe29d40768210bbeb5fc16be4a87625 /src/com/android/gallery3d/ui
parent0718d480a144ba0a44c07c48f90e85cf4ec669c6 (diff)
downloadandroid_packages_apps_Snap-11cfeeddedd61d3c4aa40945fef0bc2d87c7559d.tar.gz
android_packages_apps_Snap-11cfeeddedd61d3c4aa40945fef0bc2d87c7559d.tar.bz2
android_packages_apps_Snap-11cfeeddedd61d3c4aa40945fef0bc2d87c7559d.zip
Replace various BitmapPools with a smarter unified pool
Make all of gallery use a single shared pool, and pave the way for making the pool more adaptive based on the current workload. Change-Id: Ia32561ad50b1b9716ebe2fd32a7bf02737685dac
Diffstat (limited to 'src/com/android/gallery3d/ui')
-rw-r--r--src/com/android/gallery3d/ui/AlbumLabelMaker.java17
-rw-r--r--src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java13
-rw-r--r--src/com/android/gallery3d/ui/AlbumSlidingWindow.java9
-rw-r--r--src/com/android/gallery3d/ui/BitmapLoader.java6
-rw-r--r--src/com/android/gallery3d/ui/BitmapTileProvider.java7
-rw-r--r--src/com/android/gallery3d/ui/TileImageView.java21
-rw-r--r--src/com/android/gallery3d/ui/TileImageViewAdapter.java8
-rw-r--r--src/com/android/gallery3d/ui/TiledScreenNail.java16
8 files changed, 30 insertions, 67 deletions
diff --git a/src/com/android/gallery3d/ui/AlbumLabelMaker.java b/src/com/android/gallery3d/ui/AlbumLabelMaker.java
index 6eeeec045..da1cac0bd 100644
--- a/src/com/android/gallery3d/ui/AlbumLabelMaker.java
+++ b/src/com/android/gallery3d/ui/AlbumLabelMaker.java
@@ -27,8 +27,8 @@ import android.text.TextPaint;
import android.text.TextUtils;
import com.android.gallery3d.R;
-import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.DataSourceType;
+import com.android.photos.data.GalleryBitmapPool;
import com.android.gallery3d.util.ThreadPool;
import com.android.gallery3d.util.ThreadPool.JobContext;
@@ -41,7 +41,8 @@ public class AlbumLabelMaker {
private final Context mContext;
private int mLabelWidth;
- private BitmapPool mBitmapPool;
+ private int mBitmapWidth;
+ private int mBitmapHeight;
private final LazyLoadedBitmap mLocalSetIcon;
private final LazyLoadedBitmap mPicasaIcon;
@@ -109,8 +110,8 @@ public class AlbumLabelMaker {
if (mLabelWidth == width) return;
mLabelWidth = width;
int borders = 2 * BORDER_SIZE;
- mBitmapPool = new BitmapPool(
- width + borders, mSpec.labelBackgroundHeight + borders, 16);
+ mBitmapWidth = width + borders;
+ mBitmapHeight = mSpec.labelBackgroundHeight + borders;
}
public ThreadPool.Job<Bitmap> requestLabel(
@@ -152,7 +153,7 @@ public class AlbumLabelMaker {
synchronized (this) {
labelWidth = mLabelWidth;
- bitmap = mBitmapPool.getBitmap();
+ bitmap = GalleryBitmapPool.getInstance().get(mBitmapWidth, mBitmapHeight);
}
if (bitmap == null) {
@@ -200,10 +201,6 @@ public class AlbumLabelMaker {
}
public void recycleLabel(Bitmap label) {
- mBitmapPool.recycle(label);
- }
-
- public void clearRecycledLabels() {
- if (mBitmapPool != null) mBitmapPool.clear();
+ GalleryBitmapPool.getInstance().put(label);
}
}
diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
index d5a15b4ac..8149df4b3 100644
--- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
@@ -23,7 +23,6 @@ import com.android.gallery3d.R;
import com.android.gallery3d.app.AbstractGalleryActivity;
import com.android.gallery3d.app.AlbumSetDataLoader;
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;
@@ -403,7 +402,6 @@ public class AlbumSetSlidingWindow implements AlbumSetDataLoader.DataListener {
for (int i = mContentStart, n = mContentEnd; i < n; ++i) {
freeSlotContent(i);
}
- mLabelMaker.clearRecycledLabels();
}
public void resume() {
@@ -429,12 +427,6 @@ public class AlbumSetSlidingWindow implements AlbumSetDataLoader.DataListener {
}
@Override
- protected void recycleBitmap(Bitmap bitmap) {
- BitmapPool pool = MediaItem.getMicroThumbPool();
- if (pool != null) pool.recycle(bitmap);
- }
-
- @Override
protected Future<Bitmap> submitBitmapTask(FutureListener<Bitmap> l) {
return mThreadPool.submit(mMediaItem.requestImage(
MediaItem.TYPE_MICROTHUMBNAIL), l);
@@ -505,11 +497,6 @@ public class AlbumSetSlidingWindow implements AlbumSetDataLoader.DataListener {
}
@Override
- protected void recycleBitmap(Bitmap bitmap) {
- mLabelMaker.recycleLabel(bitmap);
- }
-
- @Override
protected void onLoadComplete(Bitmap bitmap) {
mHandler.obtainMessage(MSG_UPDATE_ALBUM_ENTRY, this).sendToTarget();
}
diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
index 8cd2cf500..fec7d1e92 100644
--- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
@@ -22,11 +22,10 @@ import android.os.Message;
import com.android.gallery3d.app.AbstractGalleryActivity;
import com.android.gallery3d.app.AlbumDataLoader;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.MediaObject;
-import com.android.gallery3d.data.Path;
import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback;
+import com.android.gallery3d.data.Path;
import com.android.gallery3d.glrenderer.Texture;
import com.android.gallery3d.glrenderer.TiledTexture;
import com.android.gallery3d.util.Future;
@@ -296,12 +295,6 @@ public class AlbumSlidingWindow implements AlbumDataLoader.DataListener {
}
@Override
- protected void recycleBitmap(Bitmap bitmap) {
- BitmapPool pool = MediaItem.getMicroThumbPool();
- if (pool != null) pool.recycle(bitmap);
- }
-
- @Override
protected Future<Bitmap> submitBitmapTask(FutureListener<Bitmap> l) {
return mThreadPool.submit(
mItem.requestImage(MediaItem.TYPE_MICROTHUMBNAIL), this);
diff --git a/src/com/android/gallery3d/ui/BitmapLoader.java b/src/com/android/gallery3d/ui/BitmapLoader.java
index 4f07cc047..a708a90f3 100644
--- a/src/com/android/gallery3d/ui/BitmapLoader.java
+++ b/src/com/android/gallery3d/ui/BitmapLoader.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.ui;
import android.graphics.Bitmap;
+import com.android.photos.data.GalleryBitmapPool;
import com.android.gallery3d.util.Future;
import com.android.gallery3d.util.FutureListener;
@@ -51,7 +52,7 @@ public abstract class BitmapLoader implements FutureListener<Bitmap> {
mBitmap = future.get();
if (mState == STATE_RECYCLED) {
if (mBitmap != null) {
- recycleBitmap(mBitmap);
+ GalleryBitmapPool.getInstance().put(mBitmap);
mBitmap = null;
}
return; // don't call callback
@@ -84,7 +85,7 @@ public abstract class BitmapLoader implements FutureListener<Bitmap> {
public synchronized void recycle() {
mState = STATE_RECYCLED;
if (mBitmap != null) {
- recycleBitmap(mBitmap);
+ GalleryBitmapPool.getInstance().put(mBitmap);
mBitmap = null;
}
if (mTask != null) mTask.cancel();
@@ -103,6 +104,5 @@ public abstract class BitmapLoader implements FutureListener<Bitmap> {
}
abstract protected Future<Bitmap> submitBitmapTask(FutureListener<Bitmap> l);
- abstract protected void recycleBitmap(Bitmap bitmap);
abstract protected void onLoadComplete(Bitmap bitmap);
}
diff --git a/src/com/android/gallery3d/ui/BitmapTileProvider.java b/src/com/android/gallery3d/ui/BitmapTileProvider.java
index c3466e7fe..e1a8b7644 100644
--- a/src/com/android/gallery3d/ui/BitmapTileProvider.java
+++ b/src/com/android/gallery3d/ui/BitmapTileProvider.java
@@ -21,7 +21,7 @@ import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import com.android.gallery3d.common.BitmapUtils;
-import com.android.gallery3d.data.BitmapPool;
+import com.android.photos.data.GalleryBitmapPool;
import java.util.ArrayList;
@@ -71,12 +71,11 @@ public class BitmapTileProvider implements TileImageView.TileSource {
}
@Override
- public Bitmap getTile(int level, int x, int y, int tileSize,
- BitmapPool pool) {
+ public Bitmap getTile(int level, int x, int y, int tileSize) {
x >>= level;
y >>= level;
- Bitmap result = pool == null ? null : pool.getBitmap();
+ Bitmap result = GalleryBitmapPool.getInstance().get(tileSize, tileSize);
if (result == null) {
result = Bitmap.createBitmap(tileSize, tileSize, mConfig);
} else {
diff --git a/src/com/android/gallery3d/ui/TileImageView.java b/src/com/android/gallery3d/ui/TileImageView.java
index f1c31e49d..3185c7598 100644
--- a/src/com/android/gallery3d/ui/TileImageView.java
+++ b/src/com/android/gallery3d/ui/TileImageView.java
@@ -27,10 +27,9 @@ import android.util.FloatMath;
import android.view.WindowManager;
import com.android.gallery3d.app.GalleryContext;
-import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.DecodeUtils;
+import com.android.photos.data.GalleryBitmapPool;
import com.android.gallery3d.glrenderer.GLCanvas;
import com.android.gallery3d.glrenderer.UploadedTexture;
import com.android.gallery3d.util.Future;
@@ -50,8 +49,6 @@ public class TileImageView extends GLView {
// TILE_SIZE must be 2^N
private static int sTileSize;
- private static BitmapPool sTilePool;
-
/*
* This is the tile state in the CPU side.
* Life of a Tile:
@@ -143,8 +140,7 @@ public class TileImageView extends GLView {
// still refers to the coordinate on the original image.
//
// The method would be called in another thread.
- public Bitmap getTile(int level, int x, int y, int tileSize,
- BitmapPool pool);
+ public Bitmap getTile(int level, int x, int y, int tileSize);
}
public static boolean isHighResolution(Context context) {
@@ -164,10 +160,6 @@ public class TileImageView extends GLView {
} else {
sTileSize = 256;
}
- sTilePool =
- ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER
- ? new BitmapPool(sTileSize, sTileSize, 128)
- : null;
}
}
@@ -399,7 +391,6 @@ public class TileImageView extends GLView {
}
}
setScreenNail(null);
- if (sTilePool != null) sTilePool.clear();
}
public void prepareTextures() {
@@ -508,7 +499,7 @@ public class TileImageView extends GLView {
if (tile.mTileState == STATE_RECYCLING) {
tile.mTileState = STATE_RECYCLED;
if (tile.mDecodedTile != null) {
- if (sTilePool != null) sTilePool.recycle(tile.mDecodedTile);
+ GalleryBitmapPool.getInstance().put(tile.mDecodedTile);
tile.mDecodedTile = null;
}
mRecycledQueue.push(tile);
@@ -536,7 +527,7 @@ public class TileImageView extends GLView {
}
tile.mTileState = STATE_RECYCLED;
if (tile.mDecodedTile != null) {
- if (sTilePool != null) sTilePool.recycle(tile.mDecodedTile);
+ GalleryBitmapPool.getInstance().put(tile.mDecodedTile);
tile.mDecodedTile = null;
}
mRecycledQueue.push(tile);
@@ -675,7 +666,7 @@ public class TileImageView extends GLView {
@Override
protected void onFreeBitmap(Bitmap bitmap) {
- if (sTilePool != null) sTilePool.recycle(bitmap);
+ GalleryBitmapPool.getInstance().put(bitmap);
}
boolean decode() {
@@ -683,7 +674,7 @@ public class TileImageView extends GLView {
// by (1 << mTilelevel) from a region in the original image.
try {
mDecodedTile = DecodeUtils.ensureGLCompatibleBitmap(mModel.getTile(
- mTileLevel, mX, mY, sTileSize, sTilePool));
+ mTileLevel, mX, mY, sTileSize));
} catch (Throwable t) {
Log.w(TAG, "fail to decode tile", t);
}
diff --git a/src/com/android/gallery3d/ui/TileImageViewAdapter.java b/src/com/android/gallery3d/ui/TileImageViewAdapter.java
index 0d20b0757..0c1f66d0c 100644
--- a/src/com/android/gallery3d/ui/TileImageViewAdapter.java
+++ b/src/com/android/gallery3d/ui/TileImageViewAdapter.java
@@ -26,7 +26,7 @@ import android.graphics.Rect;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
-import com.android.gallery3d.data.BitmapPool;
+import com.android.photos.data.GalleryBitmapPool;
public class TileImageViewAdapter implements TileImageView.TileSource {
private static final String TAG = "TileImageViewAdapter";
@@ -84,7 +84,7 @@ public class TileImageViewAdapter implements TileImageView.TileSource {
// (44, 44, 256, 256) from the original photo and down sample it to 106.
@TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB)
@Override
- public Bitmap getTile(int level, int x, int y, int tileSize, BitmapPool pool) {
+ public Bitmap getTile(int level, int x, int y, int tileSize) {
if (!ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER) {
return getTileWithoutReusingBitmap(level, x, y, tileSize);
}
@@ -106,7 +106,7 @@ public class TileImageViewAdapter implements TileImageView.TileSource {
.contains(wantRegion);
}
- Bitmap bitmap = pool == null ? null : pool.getBitmap();
+ Bitmap bitmap = GalleryBitmapPool.getInstance().get(tileSize, tileSize);
if (bitmap != null) {
if (needClear) bitmap.eraseColor(0);
} else {
@@ -126,7 +126,7 @@ public class TileImageViewAdapter implements TileImageView.TileSource {
}
} finally {
if (options.inBitmap != bitmap && options.inBitmap != null) {
- if (pool != null) pool.recycle(options.inBitmap);
+ GalleryBitmapPool.getInstance().put(options.inBitmap);
options.inBitmap = null;
}
}
diff --git a/src/com/android/gallery3d/ui/TiledScreenNail.java b/src/com/android/gallery3d/ui/TiledScreenNail.java
index ab24f5b6c..860e230bb 100644
--- a/src/com/android/gallery3d/ui/TiledScreenNail.java
+++ b/src/com/android/gallery3d/ui/TiledScreenNail.java
@@ -20,8 +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;
+import com.android.photos.data.GalleryBitmapPool;
import com.android.gallery3d.glrenderer.GLCanvas;
import com.android.gallery3d.glrenderer.TiledTexture;
@@ -83,11 +82,6 @@ public class TiledScreenNail 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) {
@@ -106,7 +100,7 @@ public class TiledScreenNail implements ScreenNail {
mWidth = newer.mWidth;
mHeight = newer.mHeight;
if (newer.mTexture != null) {
- recycleBitmap(MediaItem.getThumbPool(), mBitmap);
+ if (mBitmap != null) GalleryBitmapPool.getInstance().put(mBitmap);
if (mTexture != null) mTexture.recycle();
mBitmap = newer.mBitmap;
mTexture = newer.mTexture;
@@ -143,8 +137,10 @@ public class TiledScreenNail implements ScreenNail {
mTexture.recycle();
mTexture = null;
}
- recycleBitmap(MediaItem.getThumbPool(), mBitmap);
- mBitmap = null;
+ if (mBitmap != null) {
+ GalleryBitmapPool.getInstance().put(mBitmap);
+ mBitmap = null;
+ }
}
public static void disableDrawPlaceholder() {