summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2014-12-10 11:03:40 -0800
committerNick Kralevich <nnk@google.com>2014-12-10 11:03:40 -0800
commit7668e78601a0260f8ca67ebec742fe30f3872db2 (patch)
treee9999597b668c81bdf93c773b96c227dc062b7bc
parentd64d68d9c1c56d98e06d86b7438c46b108855c3b (diff)
parent3bae94d78ed4c078552df9817a1952129a725189 (diff)
downloadframeworks_base-7668e78601a0260f8ca67ebec742fe30f3872db2.zip
frameworks_base-7668e78601a0260f8ca67ebec742fe30f3872db2.tar.gz
frameworks_base-7668e78601a0260f8ca67ebec742fe30f3872db2.tar.bz2
resolved conflicts for merge of 3bae94d7 to master
Change-Id: I381539b1494447d62290c492f2550840fe0b559c
-rw-r--r--core/java/android/view/ThreadedRenderer.java9
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java8
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java11
-rw-r--r--graphics/java/android/graphics/drawable/DrawableContainer.java17
-rw-r--r--graphics/java/android/graphics/drawable/InsetDrawable.java13
-rw-r--r--graphics/java/android/graphics/drawable/LayerDrawable.java16
-rw-r--r--graphics/java/android/graphics/drawable/NinePatchDrawable.java11
-rw-r--r--graphics/java/android/graphics/drawable/ScaleDrawable.java10
-rw-r--r--libs/hwui/DisplayListOp.h6
-rw-r--r--services/core/java/com/android/server/AssetAtlasService.java21
10 files changed, 102 insertions, 20 deletions
diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
index 14b950f..ad4a048 100644
--- a/core/java/android/view/ThreadedRenderer.java
+++ b/core/java/android/view/ThreadedRenderer.java
@@ -37,6 +37,7 @@ import android.view.View.AttachInfo;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.HashSet;
/**
@@ -465,11 +466,13 @@ public class ThreadedRenderer extends HardwareRenderer {
final LongSparseArray<Drawable.ConstantState> drawables = resources.getPreloadedDrawables();
final int count = drawables.size();
+ ArrayList<Bitmap> tmpList = new ArrayList<Bitmap>();
for (int i = 0; i < count; i++) {
- final Bitmap bitmap = drawables.valueAt(i).getBitmap();
- if (bitmap != null && bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
- preloadedPointers.add(bitmap.mNativeBitmap);
+ drawables.valueAt(i).addAtlasableBitmaps(tmpList);
+ for (int j = 0; j < tmpList.size(); j++) {
+ preloadedPointers.add(tmpList.get(j).mNativeBitmap);
}
+ tmpList.clear();
}
for (int i = 0; i < map.length; i += 4) {
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) {
diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h
index 7627163..8e341d9 100644
--- a/libs/hwui/DisplayListOp.h
+++ b/libs/hwui/DisplayListOp.h
@@ -684,7 +684,8 @@ public:
}
virtual void output(int level, uint32_t logFlags) const {
- OP_LOG("Draw bitmap %p at %f %f", mBitmap, mLocalBounds.left, mLocalBounds.top);
+ OP_LOG("Draw bitmap %p at %f %f%s", mBitmap, mLocalBounds.left, mLocalBounds.top,
+ mEntry ? " using AssetAtlas" : "");
}
virtual const char* name() { return "DrawBitmap"; }
@@ -918,7 +919,8 @@ public:
}
virtual void output(int level, uint32_t logFlags) const {
- OP_LOG("Draw patch " RECT_STRING, RECT_ARGS(mLocalBounds));
+ OP_LOG("Draw patch " RECT_STRING "%s", RECT_ARGS(mLocalBounds),
+ mEntry ? " with AssetAtlas" : "");
}
virtual const char* name() { return "DrawPatch"; }
diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java
index fc4838c..bc31450 100644
--- a/services/core/java/com/android/server/AssetAtlasService.java
+++ b/services/core/java/com/android/server/AssetAtlasService.java
@@ -46,8 +46,11 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -66,7 +69,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
*/
public static final String ASSET_ATLAS_SERVICE = "assetatlas";
- private static final String LOG_TAG = "Atlas";
+ private static final String LOG_TAG = "AssetAtlas";
// Turns debug logs on/off. Debug logs are kept to a minimum and should
// remain on to diagnose issues
@@ -131,7 +134,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
mContext = context;
mVersionName = queryVersionName(context);
- ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(300);
+ Collection<Bitmap> bitmaps = new HashSet<Bitmap>(300);
int totalPixelCount = 0;
// We only care about drawables that hold bitmaps
@@ -140,16 +143,18 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
final int count = drawables.size();
for (int i = 0; i < count; i++) {
- final Bitmap bitmap = drawables.valueAt(i).getBitmap();
- if (bitmap != null && bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
- bitmaps.add(bitmap);
- totalPixelCount += bitmap.getWidth() * bitmap.getHeight();
+ try {
+ totalPixelCount += drawables.valueAt(i).addAtlasableBitmaps(bitmaps);
+ } catch (Throwable t) {
+ Log.e("AssetAtlas", "Failed to fetch preloaded drawable state", t);
+ throw t;
}
}
+ ArrayList<Bitmap> sortedBitmaps = new ArrayList<Bitmap>(bitmaps);
// Our algorithms perform better when the bitmaps are first sorted
// The comparator will sort the bitmap by width first, then by height
- Collections.sort(bitmaps, new Comparator<Bitmap>() {
+ Collections.sort(sortedBitmaps, new Comparator<Bitmap>() {
@Override
public int compare(Bitmap b1, Bitmap b2) {
if (b1.getWidth() == b2.getWidth()) {
@@ -160,7 +165,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
});
// Kick off the packing work on a worker thread
- new Thread(new Renderer(bitmaps, totalPixelCount)).start();
+ new Thread(new Renderer(sortedBitmaps, totalPixelCount)).start();
}
/**