diff options
author | Romain Guy <romainguy@google.com> | 2012-09-07 10:19:36 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-09-07 10:32:55 -0700 |
commit | 6543c292b2d1cb3547f4565f89b7cb649ad955d6 (patch) | |
tree | 076efb8193c05c3bdd3ffdd90b674d67d0e99636 /graphics/java/android | |
parent | f6aa537c2dddfa9c68af161c082b5d4f316bd068 (diff) | |
parent | 5f49c3023a512efbef8bc9515d310c7a72be4af2 (diff) | |
download | frameworks_base-6543c292b2d1cb3547f4565f89b7cb649ad955d6.zip frameworks_base-6543c292b2d1cb3547f4565f89b7cb649ad955d6.tar.gz frameworks_base-6543c292b2d1cb3547f4565f89b7cb649ad955d6.tar.bz2 |
Merge "The drawables cache strikes again Bug #7117785" into jb-mr1-dev
Diffstat (limited to 'graphics/java/android')
5 files changed, 44 insertions, 9 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index e82ccd4..7a4a1ca 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -80,6 +80,7 @@ public class BitmapDrawable extends Drawable { @Deprecated public BitmapDrawable() { mBitmapState = new BitmapState((Bitmap) null); + mMutated = true; } /** @@ -90,6 +91,7 @@ public class BitmapDrawable extends Drawable { public BitmapDrawable(Resources res) { mBitmapState = new BitmapState((Bitmap) null); mBitmapState.mTargetDensity = mTargetDensity; + mMutated = true; } /** @@ -100,6 +102,7 @@ public class BitmapDrawable extends Drawable { @Deprecated public BitmapDrawable(Bitmap bitmap) { this(new BitmapState(bitmap), null); + mMutated = true; } /** @@ -109,6 +112,7 @@ public class BitmapDrawable extends Drawable { public BitmapDrawable(Resources res, Bitmap bitmap) { this(new BitmapState(bitmap), res); mBitmapState.mTargetDensity = mTargetDensity; + mMutated = true; } /** @@ -122,6 +126,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } + mMutated = true; } /** @@ -134,6 +139,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } + mMutated = true; } /** @@ -147,6 +153,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } + mMutated = true; } /** @@ -159,6 +166,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } + mMutated = true; } /** @@ -552,6 +560,7 @@ public class BitmapDrawable extends Drawable { } else { mTargetDensity = state.mTargetDensity; } + mMutated = false; setBitmap(state != null ? state.mBitmap : null); } } diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java index 88c9155..f8e3944 100644 --- a/graphics/java/android/graphics/drawable/ColorDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorDrawable.java @@ -36,12 +36,14 @@ import java.io.IOException; public class ColorDrawable extends Drawable { private ColorState mState; private final Paint mPaint = new Paint(); + private boolean mMutated; /** * Creates a new black ColorDrawable. */ public ColorDrawable() { this(null); + mMutated = true; } /** @@ -52,6 +54,7 @@ public class ColorDrawable extends Drawable { public ColorDrawable(int color) { this(null); setColor(color); + mMutated = true; } private ColorDrawable(ColorState state) { @@ -63,6 +66,21 @@ public class ColorDrawable extends Drawable { return super.getChangingConfigurations() | mState.mChangingConfigurations; } + /** + * A mutable BitmapDrawable still shares its Bitmap with any other Drawable + * that comes from the same resource. + * + * @return This drawable. + */ + @Override + public Drawable mutate() { + if (!mMutated && super.mutate() == this) { + mState = new ColorState(mState); + mMutated = true; + } + return this; + } + @Override public void draw(Canvas canvas) { if ((mState.mUseColor >>> 24) != 0) { @@ -165,6 +183,7 @@ public class ColorDrawable extends Drawable { if (state != null) { mBaseColor = state.mBaseColor; mUseColor = state.mUseColor; + mChangingConfigurations = state.mChangingConfigurations; } } diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index 15b2c0b..486390c 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -105,7 +105,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { mAlpha = alpha; if (mCurrDrawable != null) { if (mEnterAnimationEnd == 0) { - mCurrDrawable.setAlpha(alpha); + mCurrDrawable.mutate().setAlpha(alpha); } else { animate(false); } @@ -118,7 +118,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { if (mDrawableContainerState.mDither != dither) { mDrawableContainerState.mDither = dither; if (mCurrDrawable != null) { - mCurrDrawable.setDither(mDrawableContainerState.mDither); + mCurrDrawable.mutate().setDither(mDrawableContainerState.mDither); } } } @@ -128,7 +128,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { if (mColorFilter != cf) { mColorFilter = cf; if (mCurrDrawable != null) { - mCurrDrawable.setColorFilter(cf); + mCurrDrawable.mutate().setColorFilter(cf); } } } @@ -176,7 +176,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { } if (mCurrDrawable != null) { mCurrDrawable.jumpToCurrentState(); - mCurrDrawable.setAlpha(mAlpha); + mCurrDrawable.mutate().setAlpha(mAlpha); } if (mExitAnimationEnd != 0) { mExitAnimationEnd = 0; @@ -312,6 +312,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { mCurrDrawable = d; mCurIndex = idx; if (d != null) { + d.mutate(); if (mDrawableContainerState.mEnterFadeDuration > 0) { mEnterAnimationEnd = now + mDrawableContainerState.mEnterFadeDuration; } else { @@ -355,13 +356,13 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { if (mCurrDrawable != null) { if (mEnterAnimationEnd != 0) { if (mEnterAnimationEnd <= now) { - mCurrDrawable.setAlpha(mAlpha); + mCurrDrawable.mutate().setAlpha(mAlpha); mEnterAnimationEnd = 0; } else { int animAlpha = (int)((mEnterAnimationEnd-now)*255) / mDrawableContainerState.mEnterFadeDuration; if (DEBUG) android.util.Log.i(TAG, toString() + " cur alpha " + animAlpha); - mCurrDrawable.setAlpha(((255-animAlpha)*mAlpha)/255); + mCurrDrawable.mutate().setAlpha(((255-animAlpha)*mAlpha)/255); animating = true; } } @@ -378,7 +379,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { int animAlpha = (int)((mExitAnimationEnd-now)*255) / mDrawableContainerState.mExitFadeDuration; if (DEBUG) android.util.Log.i(TAG, toString() + " last alpha " + animAlpha); - mLastDrawable.setAlpha((animAlpha*mAlpha)/255); + mLastDrawable.mutate().setAlpha((animAlpha*mAlpha)/255); animating = true; } } diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 5b50beb..21344f4 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -124,7 +124,7 @@ public class GradientDrawable extends Drawable { private Paint mLayerPaint; // internal, used if we use saveLayer() private boolean mRectIsDirty; // internal state - private boolean mMutated; + private boolean mMutated = true; private Path mRingPath; private boolean mPathIsDirty = true; @@ -1202,6 +1202,7 @@ public class GradientDrawable extends Drawable { mGradientState = state; initializeWithState(state); mRectIsDirty = true; + mMutated = false; } private void initializeWithState(GradientState state) { diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index 62aea71..7a43496 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -77,6 +77,7 @@ public class NinePatchDrawable extends Drawable { @Deprecated public NinePatchDrawable(Bitmap bitmap, byte[] chunk, Rect padding, String srcName) { this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), null); + mMutated = true; } /** @@ -87,6 +88,7 @@ public class NinePatchDrawable extends Drawable { Rect padding, String srcName) { this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding), res); mNinePatchState.mTargetDensity = mTargetDensity; + mMutated = true; } /** @@ -99,6 +101,7 @@ public class NinePatchDrawable extends Drawable { Rect padding, Rect layoutInsets, String srcName) { this(new NinePatchState(new NinePatch(bitmap, chunk, srcName), padding, layoutInsets), res); mNinePatchState.mTargetDensity = mTargetDensity; + mMutated = true; } /** @@ -109,6 +112,7 @@ public class NinePatchDrawable extends Drawable { @Deprecated public NinePatchDrawable(NinePatch patch) { this(new NinePatchState(patch, new Rect()), null); + mMutated = true; } /** @@ -118,6 +122,7 @@ public class NinePatchDrawable extends Drawable { public NinePatchDrawable(Resources res, NinePatch patch) { this(new NinePatchState(patch, new Rect()), res); mNinePatchState.mTargetDensity = mTargetDensity; + mMutated = true; } private void setNinePatchState(NinePatchState state, Resources res) { @@ -181,7 +186,7 @@ public class NinePatchDrawable extends Drawable { } } - private Insets scaleFromDensity(Insets insets, int sdensity, int tdensity) { + private static Insets scaleFromDensity(Insets insets, int sdensity, int tdensity) { int left = Bitmap.scaleFromDensity(insets.left, sdensity, tdensity); int top = Bitmap.scaleFromDensity(insets.top, sdensity, tdensity); int right = Bitmap.scaleFromDensity(insets.right, sdensity, tdensity); |