summaryrefslogtreecommitdiff
path: root/src/com/android/bitmap/drawable
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2013-10-21 16:11:15 -0700
committerMark Wei <markwei@google.com>2013-10-21 19:50:52 -0700
commitcea0c012d538f11b3ee97d4b7e78f4c1ea73d5be (patch)
tree9506342cb46c574f3913c762f6e11d08b532acfd /src/com/android/bitmap/drawable
parent7a0df68fac718a68ed44d5c667ebaee38e334f63 (diff)
downloadbitmap-cea0c012d538f11b3ee97d4b7e78f4c1ea73d5be.tar.gz
Modifications to bitmap library to make integrating into BigTop simpler.
RequestKey returns ParcelFileDescriptor instead of AssetFileDescriptor to make it easier to read files off of internal cache. Do not assume we want a top-1/3 crop. Provide vertical center in DecodeTask constructor. Move DecodeTask params into DecodeOptions to avoid param bloat. Add option to not limit bitmap density in BasicBitmapDrawable. Name AsyncTask threads in pool. Link DEBUG flags. Change-Id: I9416ac647c0c4935ee488b7db43cccd9de565c54
Diffstat (limited to 'src/com/android/bitmap/drawable')
-rw-r--r--src/com/android/bitmap/drawable/BasicBitmapDrawable.java27
-rw-r--r--src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java18
2 files changed, 30 insertions, 15 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
index 2aa6011..ae26571 100644
--- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
+++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
@@ -27,6 +27,8 @@ import android.util.Log;
import com.android.bitmap.BitmapCache;
import com.android.bitmap.DecodeTask;
+import com.android.bitmap.DecodeTask.DecodeOptions;
+import com.android.bitmap.NamedThreadFactory;
import com.android.bitmap.RequestKey;
import com.android.bitmap.ReusableBitmap;
import com.android.bitmap.util.BitmapUtils;
@@ -50,34 +52,39 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa
private RequestKey mCurrKey;
private ReusableBitmap mBitmap;
private final BitmapCache mCache;
+ private final boolean mLimitDensity;
private DecodeTask mTask;
private int mDecodeWidth;
+
private int mDecodeHeight;
+ private static final String TAG = BasicBitmapDrawable.class.getSimpleName();
// based on framework CL:I015d77
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
+
private static final Executor SMALL_POOL_EXECUTOR = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, 1, TimeUnit.SECONDS,
- new LinkedBlockingQueue<Runnable>(128));
+ new LinkedBlockingQueue<Runnable>(128), new NamedThreadFactory("decode"));
private static final Executor EXECUTOR = SMALL_POOL_EXECUTOR;
- private static final boolean LIMIT_BITMAP_DENSITY = true;
-
private static final int MAX_BITMAP_DENSITY = DisplayMetrics.DENSITY_HIGH;
+ private static final float VERTICAL_CENTER = 1f / 2;
private final float mDensity;
private final Paint mPaint = new Paint();
+
private final Rect mSrcRect = new Rect();
- private static final String TAG = BasicBitmapDrawable.class.getSimpleName();
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = DecodeTask.DEBUG;
- public BasicBitmapDrawable(final Resources res, final BitmapCache cache) {
+ public BasicBitmapDrawable(final Resources res, final BitmapCache cache,
+ final boolean limitDensity) {
mDensity = res.getDisplayMetrics().density;
mCache = cache;
+ mLimitDensity = limitDensity;
mPaint.setFilterBitmap(true);
}
@@ -156,7 +163,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa
mBitmap.getLogicalWidth(), mBitmap.getLogicalHeight(),
bounds.width(), bounds.height(),
bounds.height(), Integer.MAX_VALUE,
- 0.5f, false /* absoluteFraction */,
+ VERTICAL_CENTER, false /* absoluteFraction */,
1, mSrcRect);
final int orientation = mBitmap.getOrientation();
@@ -236,7 +243,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa
}
Trace.beginSection("decode");
- if (LIMIT_BITMAP_DENSITY) {
+ if (mLimitDensity) {
final float scale =
Math.min(1f, (float) MAX_BITMAP_DENSITY / DisplayMetrics.DENSITY_DEFAULT
/ mDensity);
@@ -254,7 +261,9 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa
if (mTask != null) {
mTask.cancel();
}
- mTask = new DecodeTask(mCurrKey, bufferW, bufferH, this, mCache);
+ final DecodeOptions opts = new DecodeOptions(bufferW, bufferH, VERTICAL_CENTER,
+ DecodeOptions.STRATEGY_ROUND_NEAREST);
+ mTask = new DecodeTask(mCurrKey, opts, this, mCache);
mTask.executeOnExecutor(EXECUTOR);
Trace.endSection();
}
diff --git a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java
index 01f5638..61efa12 100644
--- a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java
+++ b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java
@@ -32,6 +32,7 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.view.animation.LinearInterpolator;
+import com.android.bitmap.DecodeTask.DecodeOptions;
import com.android.bitmap.R;
import com.android.bitmap.BitmapCache;
import com.android.bitmap.DecodeAggregator;
@@ -59,8 +60,10 @@ public class ExtendedBitmapDrawable extends Drawable implements DecodeTask.Decod
Drawable.Callback, Runnable, Parallaxable, DecodeAggregator.Callback {
private RequestKey mCurrKey;
+
private ReusableBitmap mBitmap;
private final BitmapCache mCache;
+ private final boolean mLimitDensity;
private DecodeAggregator mDecodeAggregator;
private DecodeTask mTask;
private int mDecodeWidth;
@@ -80,10 +83,10 @@ public class ExtendedBitmapDrawable extends Drawable implements DecodeTask.Decod
private static final Executor EXECUTOR = SMALL_POOL_EXECUTOR;
- private static final boolean LIMIT_BITMAP_DENSITY = true;
-
private static final int MAX_BITMAP_DENSITY = DisplayMetrics.DENSITY_HIGH;
+ private static final float VERTICAL_CENTER = 1f / 3;
+
private static final int LOAD_STATE_UNINITIALIZED = 0;
private static final int LOAD_STATE_NOT_YET_LOADED = 1;
private static final int LOAD_STATE_LOADING = 2;
@@ -100,10 +103,11 @@ public class ExtendedBitmapDrawable extends Drawable implements DecodeTask.Decod
public static final String TAG = ExtendedBitmapDrawable.class.getSimpleName();
public ExtendedBitmapDrawable(final Resources res, final BitmapCache cache,
- final DecodeAggregator decodeAggregator, final Drawable placeholder,
- final Drawable progress) {
+ final boolean limitDensity, final DecodeAggregator decodeAggregator,
+ final Drawable placeholder, final Drawable progress) {
mDensity = res.getDisplayMetrics().density;
mCache = cache;
+ mLimitDensity = limitDensity;
this.mDecodeAggregator = decodeAggregator;
mPaint.setFilterBitmap(true);
@@ -365,7 +369,7 @@ public class ExtendedBitmapDrawable extends Drawable implements DecodeTask.Decod
}
Trace.beginSection("decode");
- if (LIMIT_BITMAP_DENSITY) {
+ if (mLimitDensity) {
final float scale =
Math.min(1f, (float) MAX_BITMAP_DENSITY / DisplayMetrics.DENSITY_DEFAULT
/ mDensity);
@@ -384,7 +388,9 @@ public class ExtendedBitmapDrawable extends Drawable implements DecodeTask.Decod
mTask.cancel();
}
setLoadState(LOAD_STATE_NOT_YET_LOADED);
- mTask = new DecodeTask(mCurrKey, bufferW, bufferH, this, mCache);
+ final DecodeOptions opts = new DecodeOptions(bufferW, bufferH, VERTICAL_CENTER,
+ DecodeOptions.STRATEGY_ROUND_NEAREST);
+ mTask = new DecodeTask(mCurrKey, opts, this, mCache);
mTask.executeOnExecutor(EXECUTOR);
Trace.endSection();
}