Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6543c292 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "The drawables cache strikes again Bug #7117785" into jb-mr1-dev

parents f6aa537c 5f49c302
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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));
+9 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -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;
            }
        }

+8 −7
Original line number Diff line number Diff line
@@ -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;
                }
            }
Loading