Loading core/java/android/content/res/Resources.java +3 −1 Original line number Diff line number Diff line Loading @@ -1897,12 +1897,14 @@ public class Resources { } } final long key = (((long) value.assetCookie) << 32) | value.data; boolean isColorDrawable = false; if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { isColorDrawable = true; } final long key = isColorDrawable ? value.data : (((long) value.assetCookie) << 32) | value.data; Drawable dr = getCachedDrawable(isColorDrawable ? mColorDrawableCache : mDrawableCache, key); if (dr != null) { Loading core/java/android/view/View.java +1 −1 Original line number Diff line number Diff line Loading @@ -14118,7 +14118,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @RemotableViewMethod public void setBackgroundColor(int color) { if (mBackground instanceof ColorDrawable) { ((ColorDrawable) mBackground).setColor(color); ((ColorDrawable) mBackground.mutate()).setColor(color); computeOpaqueFlags(); } else { setBackground(new ColorDrawable(color)); graphics/java/android/graphics/drawable/BitmapDrawable.java +9 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class BitmapDrawable extends Drawable { @Deprecated public BitmapDrawable() { mBitmapState = new BitmapState((Bitmap) null); mMutated = true; } /** Loading @@ -90,6 +91,7 @@ public class BitmapDrawable extends Drawable { public BitmapDrawable(Resources res) { mBitmapState = new BitmapState((Bitmap) null); mBitmapState.mTargetDensity = mTargetDensity; mMutated = true; } /** Loading @@ -100,6 +102,7 @@ public class BitmapDrawable extends Drawable { @Deprecated public BitmapDrawable(Bitmap bitmap) { this(new BitmapState(bitmap), null); mMutated = true; } /** Loading @@ -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; } /** Loading @@ -122,6 +126,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } mMutated = true; } /** Loading @@ -134,6 +139,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } mMutated = true; } /** Loading @@ -147,6 +153,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } mMutated = true; } /** Loading @@ -159,6 +166,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } mMutated = true; } /** Loading Loading @@ -552,6 +560,7 @@ public class BitmapDrawable extends Drawable { } else { mTargetDensity = state.mTargetDensity; } mMutated = false; setBitmap(state != null ? state.mBitmap : null); } } graphics/java/android/graphics/drawable/ColorDrawable.java +19 −0 Original line number Diff line number Diff line Loading @@ -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; } /** Loading @@ -52,6 +54,7 @@ public class ColorDrawable extends Drawable { public ColorDrawable(int color) { this(null); setColor(color); mMutated = true; } private ColorDrawable(ColorState state) { Loading @@ -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) { Loading Loading @@ -165,6 +183,7 @@ public class ColorDrawable extends Drawable { if (state != null) { mBaseColor = state.mBaseColor; mUseColor = state.mUseColor; mChangingConfigurations = state.mChangingConfigurations; } } Loading graphics/java/android/graphics/drawable/DrawableContainer.java +8 −7 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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); } } } Loading @@ -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); } } } Loading Loading @@ -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; Loading Loading @@ -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 { Loading Loading @@ -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; } } Loading @@ -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; } } Loading Loading
core/java/android/content/res/Resources.java +3 −1 Original line number Diff line number Diff line Loading @@ -1897,12 +1897,14 @@ public class Resources { } } final long key = (((long) value.assetCookie) << 32) | value.data; boolean isColorDrawable = false; if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { isColorDrawable = true; } final long key = isColorDrawable ? value.data : (((long) value.assetCookie) << 32) | value.data; Drawable dr = getCachedDrawable(isColorDrawable ? mColorDrawableCache : mDrawableCache, key); if (dr != null) { Loading
core/java/android/view/View.java +1 −1 Original line number Diff line number Diff line Loading @@ -14118,7 +14118,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @RemotableViewMethod public void setBackgroundColor(int color) { if (mBackground instanceof ColorDrawable) { ((ColorDrawable) mBackground).setColor(color); ((ColorDrawable) mBackground.mutate()).setColor(color); computeOpaqueFlags(); } else { setBackground(new ColorDrawable(color));
graphics/java/android/graphics/drawable/BitmapDrawable.java +9 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public class BitmapDrawable extends Drawable { @Deprecated public BitmapDrawable() { mBitmapState = new BitmapState((Bitmap) null); mMutated = true; } /** Loading @@ -90,6 +91,7 @@ public class BitmapDrawable extends Drawable { public BitmapDrawable(Resources res) { mBitmapState = new BitmapState((Bitmap) null); mBitmapState.mTargetDensity = mTargetDensity; mMutated = true; } /** Loading @@ -100,6 +102,7 @@ public class BitmapDrawable extends Drawable { @Deprecated public BitmapDrawable(Bitmap bitmap) { this(new BitmapState(bitmap), null); mMutated = true; } /** Loading @@ -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; } /** Loading @@ -122,6 +126,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } mMutated = true; } /** Loading @@ -134,6 +139,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + filepath); } mMutated = true; } /** Loading @@ -147,6 +153,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } mMutated = true; } /** Loading @@ -159,6 +166,7 @@ public class BitmapDrawable extends Drawable { if (mBitmap == null) { android.util.Log.w("BitmapDrawable", "BitmapDrawable cannot decode " + is); } mMutated = true; } /** Loading Loading @@ -552,6 +560,7 @@ public class BitmapDrawable extends Drawable { } else { mTargetDensity = state.mTargetDensity; } mMutated = false; setBitmap(state != null ? state.mBitmap : null); } }
graphics/java/android/graphics/drawable/ColorDrawable.java +19 −0 Original line number Diff line number Diff line Loading @@ -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; } /** Loading @@ -52,6 +54,7 @@ public class ColorDrawable extends Drawable { public ColorDrawable(int color) { this(null); setColor(color); mMutated = true; } private ColorDrawable(ColorState state) { Loading @@ -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) { Loading Loading @@ -165,6 +183,7 @@ public class ColorDrawable extends Drawable { if (state != null) { mBaseColor = state.mBaseColor; mUseColor = state.mUseColor; mChangingConfigurations = state.mChangingConfigurations; } } Loading
graphics/java/android/graphics/drawable/DrawableContainer.java +8 −7 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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); } } } Loading @@ -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); } } } Loading Loading @@ -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; Loading Loading @@ -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 { Loading Loading @@ -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; } } Loading @@ -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; } } Loading