diff options
author | John Reck <jreck@google.com> | 2014-12-09 12:33:26 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2014-12-09 14:18:33 -0800 |
commit | dad7d84c04c5954b63ea8bb58c52b2291f44b4df (patch) | |
tree | c46db9d14d4bef9ea6b16bf5d86eefd9048d0235 /graphics | |
parent | 6ef76c60df9e68950721f92a14c77a3ecd13607c (diff) | |
download | frameworks_base-dad7d84c04c5954b63ea8bb58c52b2291f44b4df.zip frameworks_base-dad7d84c04c5954b63ea8bb58c52b2291f44b4df.tar.gz frameworks_base-dad7d84c04c5954b63ea8bb58c52b2291f44b4df.tar.bz2 |
Teach AssetAtlas about more drawables
Bug: 18317479
Change-Id: I16868ee204d24af72af9a2efc987f7e9eb1d266b
Diffstat (limited to 'graphics')
7 files changed, 79 insertions, 7 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 79ac651..9be296a 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -48,6 +48,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; +import java.util.Collection; /** * A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a @@ -913,8 +914,11 @@ public class BitmapDrawable extends Drawable { } @Override - public Bitmap getBitmap() { - return mBitmap; + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + if (isAtlasable(mBitmap) && atlasList.add(mBitmap)) { + return mBitmap.getWidth() * mBitmap.getHeight(); + } + return 0; } @Override diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 1fac5b6..0e38cc0 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -51,6 +51,7 @@ import java.io.IOException; import java.io.InputStream; import java.lang.ref.WeakReference; import java.util.Arrays; +import java.util.Collection; /** * A Drawable is a general abstraction for "something that can be drawn." Most @@ -1244,10 +1245,16 @@ public abstract class Drawable { public abstract int getChangingConfigurations(); /** + * @return Total pixel count * @hide */ - public Bitmap getBitmap() { - return null; + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + return 0; + } + + /** @hide */ + protected final boolean isAtlasable(Bitmap bitmap) { + return bitmap != null && bitmap.getConfig() == Bitmap.Config.ARGB_8888; } /** diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index 2748030..1e360d3 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources.Theme; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Insets; @@ -31,6 +32,8 @@ import android.os.SystemClock; import android.util.LayoutDirection; import android.util.SparseArray; +import java.util.Collection; + /** * A helper class that contains several {@link Drawable}s and selects which one to use. * @@ -1062,6 +1065,20 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { return true; } + /** @hide */ + @Override + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + final int N = mNumChildren; + int pixelCount = 0; + for (int i = 0; i < N; i++) { + final ConstantState state = getChild(i).getConstantState(); + if (state != null) { + pixelCount += state.addAtlasableBitmaps(atlasList); + } + } + return pixelCount; + } + /** * Class capable of cloning a Drawable from another Drawable's * ConstantState. diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index acfd427..8b70a08 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -19,6 +19,7 @@ package android.graphics.drawable; import com.android.internal.R; import android.annotation.NonNull; + import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -26,16 +27,19 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.Resources.Theme; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Insets; import android.graphics.Outline; import android.graphics.PixelFormat; import android.graphics.PorterDuff.Mode; +import android.graphics.drawable.Drawable.ConstantState; import android.graphics.Rect; import android.util.AttributeSet; import java.io.IOException; +import java.util.Collection; /** * A Drawable that insets another Drawable by a specified distance. @@ -472,6 +476,15 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { return mCanConstantState; } + + @Override + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + final ConstantState state = mDrawable.getConstantState(); + if (state != null) { + return state.addAtlasableBitmaps(atlasList); + } + return 0; + } } private InsetDrawable(InsetState state, Resources res) { diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 689d225..4aa5f59 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -21,6 +21,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.ColorFilter; import android.graphics.Outline; @@ -36,6 +37,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; +import java.util.Collection; /** * A Drawable that manages an array of other Drawables. These are drawn in array @@ -1105,6 +1107,20 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { mHaveOpacity = false; mHaveIsStateful = false; } + + @Override + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + final ChildDrawable[] array = mChildren; + final int N = mNum; + int pixelCount = 0; + for (int i = 0; i < N; i++) { + final ConstantState state = array[i].mDrawable.getConstantState(); + if (state != null) { + pixelCount += state.addAtlasableBitmaps(atlasList); + } + } + return pixelCount; + } } } diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index d821224..b87ae92 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -48,6 +48,7 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.io.InputStream; +import java.util.Collection; /** * @@ -289,7 +290,7 @@ public class NinePatchDrawable extends Drawable { if (bounds.isEmpty()) return; if (mNinePatchState != null) { - NinePatch.InsetStruct insets = mNinePatchState.getBitmap().getNinePatchInsets(); + NinePatch.InsetStruct insets = mNinePatchState.mNinePatch.getBitmap().getNinePatchInsets(); if (insets != null) { final Rect outlineInsets = insets.outlineRect; outline.setRoundRect(bounds.left + outlineInsets.left, @@ -648,8 +649,12 @@ public class NinePatchDrawable extends Drawable { } @Override - public Bitmap getBitmap() { - return mNinePatch.getBitmap(); + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + final Bitmap bitmap = mNinePatch.getBitmap(); + if (isAtlasable(bitmap) && atlasList.add(bitmap)) { + return bitmap.getWidth() * bitmap.getHeight(); + } + return 0; } @Override diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index d6d4cb8..da722f3 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -31,6 +31,7 @@ import android.view.Gravity; import android.util.AttributeSet; import java.io.IOException; +import java.util.Collection; /** * A Drawable that changes the size of another Drawable based on its current @@ -413,6 +414,15 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { return mCanConstantState; } + + @Override + public int addAtlasableBitmaps(Collection<Bitmap> atlasList) { + final ConstantState state = mDrawable.getConstantState(); + if (state != null) { + return state.addAtlasableBitmaps(atlasList); + } + return 0; + } } private ScaleDrawable(ScaleState state, Resources res) { |