diff options
author | Mark Wei <markwei@google.com> | 2013-10-22 23:58:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-10-22 23:58:42 +0000 |
commit | 333647f2886289a23a09a84365aa42d328ec54dc (patch) | |
tree | 7f53dcd948a2deaadde79f59c2d35d6a75298b9a | |
parent | 831d986c4683f399b1b165b98f65e3aab1162aac (diff) | |
parent | e03daa1db89106c11d8885b94d7ac97c10bea3b3 (diff) | |
download | bitmap-333647f2886289a23a09a84365aa42d328ec54dc.tar.gz |
Merge "Expose sRect and mPaint to subclasses." into klp-ub-dev
-rw-r--r-- | src/com/android/bitmap/drawable/BasicBitmapDrawable.java | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java index b6a148f..9cee3c0 100644 --- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java @@ -48,17 +48,19 @@ import java.util.concurrent.TimeUnit; */ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCallback, Drawable.Callback { + protected static Rect sRect; protected RequestKey mCurrKey; protected ReusableBitmap mBitmap; + protected final Paint mPaint = new Paint(); + private final BitmapCache mCache; private final boolean mLimitDensity; + private final float mDensity; 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; @@ -67,17 +69,12 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa private static final Executor SMALL_POOL_EXECUTOR = new ThreadPoolExecutor( CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(128), new NamedThreadFactory("decode")); - private static final Executor EXECUTOR = SMALL_POOL_EXECUTOR; 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 = DecodeTask.DEBUG; public BasicBitmapDrawable(final Resources res, final BitmapCache cache, @@ -86,6 +83,12 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa mCache = cache; mLimitDensity = limitDensity; mPaint.setFilterBitmap(true); + mPaint.setAntiAlias(true); + mPaint.setDither(true); + + if (sRect == null) { + sRect = new Rect(); + } } public RequestKey getKey() { @@ -164,7 +167,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa bounds.width(), bounds.height(), bounds.height(), Integer.MAX_VALUE, VERTICAL_CENTER, false /* absoluteFraction */, - 1, mSrcRect); + 1, sRect); final int orientation = mBitmap.getOrientation(); // calculateCroppedSrcRect() gave us the source rectangle "as if" the orientation has @@ -172,7 +175,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa // coordinates. RectUtils.rotateRectForOrientation(orientation, new Rect(0, 0, mBitmap.getLogicalWidth(), mBitmap.getLogicalHeight()), - mSrcRect); + sRect); // We may need to rotate the canvas, so we also have to rotate the bounds. final Rect rotatedBounds = new Rect(bounds); @@ -181,7 +184,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeTask.DecodeCa // Rotate the canvas. canvas.save(); canvas.rotate(orientation, bounds.centerX(), bounds.centerY()); - canvas.drawBitmap(mBitmap.bmp, mSrcRect, rotatedBounds, mPaint); + canvas.drawBitmap(mBitmap.bmp, sRect, rotatedBounds, mPaint); canvas.restore(); } } |