Loading graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +2 −0 Original line number Diff line number Diff line Loading @@ -209,6 +209,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { if (drawableRes != 0) { mAnimatedVectorState.mVectorDrawable = (VectorDrawable) res.getDrawable( drawableRes, theme).mutate(); mAnimatedVectorState.mVectorDrawable.setAllowCaching(false); } a.recycle(); } else if (TARGET.equals(tagName)) { Loading Loading @@ -258,6 +259,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { mChangingConfigurations = copy.mChangingConfigurations; // TODO: Make sure the constant state are handled correctly. mVectorDrawable = new VectorDrawable(); mVectorDrawable.setAllowCaching(false); mAnimators = new ArrayList<Animator>(); } } Loading graphics/java/android/graphics/drawable/VectorDrawable.java +53 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; Loading Loading @@ -142,6 +143,10 @@ public class VectorDrawable extends Drawable { private boolean mMutated; // AnimatedVectorDrawable needs to turn off the cache all the time, otherwise, // caching the bitmap by default is allowed. private boolean mAllowCaching = true; public VectorDrawable() { mVectorState = new VectorDrawableState(); } Loading Loading @@ -183,7 +188,23 @@ public class VectorDrawable extends Drawable { final int saveCount = canvas.save(); final Rect bounds = getBounds(); canvas.translate(bounds.left, bounds.top); if (!mAllowCaching) { mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height()); } else { Bitmap bitmap = mVectorState.mCachedBitmap; if (bitmap == null || !mVectorState.canReuseCache(bounds.width(), bounds.height())) { bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888); Canvas tmpCanvas = new Canvas(bitmap); mVectorState.mVPathRenderer.draw(tmpCanvas, bounds.width(), bounds.height()); mVectorState.mCachedBitmap = bitmap; mVectorState.updateCacheStates(); } canvas.drawBitmap(bitmap, null, bounds, null); } canvas.restoreToCount(saveCount); } Loading Loading @@ -444,6 +465,10 @@ public class VectorDrawable extends Drawable { return super.getChangingConfigurations() | mVectorState.mChangingConfigurations; } void setAllowCaching(boolean allowCaching) { mAllowCaching = allowCaching; } private static class VectorDrawableState extends ConstantState { int[] mThemeAttrs; int mChangingConfigurations; Loading @@ -451,6 +476,12 @@ public class VectorDrawable extends Drawable { ColorStateList mTint; Mode mTintMode; Bitmap mCachedBitmap; int[] mCachedThemeAttrs; ColorStateList mCachedTint; Mode mCachedTintMode; int mCachedRootAlpha; // Deep copy for mutate() or implicitly mutate. public VectorDrawableState(VectorDrawableState copy) { if (copy != null) { Loading @@ -462,6 +493,27 @@ public class VectorDrawable extends Drawable { } } public boolean canReuseCache(int width, int height) { if (mCachedThemeAttrs == mThemeAttrs && mCachedTint == mTint && mCachedTintMode == mTintMode && width == mCachedBitmap.getWidth() && height == mCachedBitmap.getHeight() && mCachedRootAlpha == mVPathRenderer.getRootAlpha()) { return true; } return false; } public void updateCacheStates() { // Use shallow copy here and shallow comparison in canReuseCache(), // likely hit cache miss more, but practically not much difference. mCachedThemeAttrs = mThemeAttrs; mCachedTint = mTint; mCachedTintMode = mTintMode; mCachedRootAlpha = mVPathRenderer.getRootAlpha(); } public VectorDrawableState() { mVPathRenderer = new VPathRenderer(); } Loading Loading
graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +2 −0 Original line number Diff line number Diff line Loading @@ -209,6 +209,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { if (drawableRes != 0) { mAnimatedVectorState.mVectorDrawable = (VectorDrawable) res.getDrawable( drawableRes, theme).mutate(); mAnimatedVectorState.mVectorDrawable.setAllowCaching(false); } a.recycle(); } else if (TARGET.equals(tagName)) { Loading Loading @@ -258,6 +259,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable { mChangingConfigurations = copy.mChangingConfigurations; // TODO: Make sure the constant state are handled correctly. mVectorDrawable = new VectorDrawable(); mVectorDrawable.setAllowCaching(false); mAnimators = new ArrayList<Animator>(); } } Loading
graphics/java/android/graphics/drawable/VectorDrawable.java +53 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources.Theme; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; Loading Loading @@ -142,6 +143,10 @@ public class VectorDrawable extends Drawable { private boolean mMutated; // AnimatedVectorDrawable needs to turn off the cache all the time, otherwise, // caching the bitmap by default is allowed. private boolean mAllowCaching = true; public VectorDrawable() { mVectorState = new VectorDrawableState(); } Loading Loading @@ -183,7 +188,23 @@ public class VectorDrawable extends Drawable { final int saveCount = canvas.save(); final Rect bounds = getBounds(); canvas.translate(bounds.left, bounds.top); if (!mAllowCaching) { mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height()); } else { Bitmap bitmap = mVectorState.mCachedBitmap; if (bitmap == null || !mVectorState.canReuseCache(bounds.width(), bounds.height())) { bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888); Canvas tmpCanvas = new Canvas(bitmap); mVectorState.mVPathRenderer.draw(tmpCanvas, bounds.width(), bounds.height()); mVectorState.mCachedBitmap = bitmap; mVectorState.updateCacheStates(); } canvas.drawBitmap(bitmap, null, bounds, null); } canvas.restoreToCount(saveCount); } Loading Loading @@ -444,6 +465,10 @@ public class VectorDrawable extends Drawable { return super.getChangingConfigurations() | mVectorState.mChangingConfigurations; } void setAllowCaching(boolean allowCaching) { mAllowCaching = allowCaching; } private static class VectorDrawableState extends ConstantState { int[] mThemeAttrs; int mChangingConfigurations; Loading @@ -451,6 +476,12 @@ public class VectorDrawable extends Drawable { ColorStateList mTint; Mode mTintMode; Bitmap mCachedBitmap; int[] mCachedThemeAttrs; ColorStateList mCachedTint; Mode mCachedTintMode; int mCachedRootAlpha; // Deep copy for mutate() or implicitly mutate. public VectorDrawableState(VectorDrawableState copy) { if (copy != null) { Loading @@ -462,6 +493,27 @@ public class VectorDrawable extends Drawable { } } public boolean canReuseCache(int width, int height) { if (mCachedThemeAttrs == mThemeAttrs && mCachedTint == mTint && mCachedTintMode == mTintMode && width == mCachedBitmap.getWidth() && height == mCachedBitmap.getHeight() && mCachedRootAlpha == mVPathRenderer.getRootAlpha()) { return true; } return false; } public void updateCacheStates() { // Use shallow copy here and shallow comparison in canReuseCache(), // likely hit cache miss more, but practically not much difference. mCachedThemeAttrs = mThemeAttrs; mCachedTint = mTint; mCachedTintMode = mTintMode; mCachedRootAlpha = mVPathRenderer.getRootAlpha(); } public VectorDrawableState() { mVPathRenderer = new VPathRenderer(); } Loading