diff options
author | Alan Viverette <alanv@google.com> | 2014-01-31 21:07:51 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-01-31 21:07:51 +0000 |
commit | c8577b384a0e0e04eed6d05660e013b5db47b7f2 (patch) | |
tree | 24700ab3899ef745ed0cbd3e1ad7025db2998f74 /graphics | |
parent | fe0ea8c21fe6f6cbaa0594295ec371efca4af824 (diff) | |
parent | 16f1d81d47beb1e04504a76de66e2919dde08c33 (diff) | |
download | frameworks_base-c8577b384a0e0e04eed6d05660e013b5db47b7f2.zip frameworks_base-c8577b384a0e0e04eed6d05660e013b5db47b7f2.tar.gz frameworks_base-c8577b384a0e0e04eed6d05660e013b5db47b7f2.tar.bz2 |
Merge "Revert "Cache display lists for Drawables""
Diffstat (limited to 'graphics')
6 files changed, 9 insertions, 95 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 52e5b5b..9360558 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -456,7 +456,7 @@ public class BitmapDrawable extends Drawable { } @Override - protected void onDraw(Canvas canvas) { + public void draw(Canvas canvas) { Bitmap bitmap = mBitmap; if (bitmap != null) { final BitmapState state = mBitmapState; diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 2ec4284..b8365aa 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -39,9 +39,6 @@ import android.util.DisplayMetrics; import android.util.StateSet; import android.util.TypedValue; import android.util.Xml; -import android.view.DisplayList; -import android.view.HardwareCanvas; -import android.view.HardwareRenderer; import android.view.View; import java.io.IOException; @@ -142,96 +139,16 @@ public abstract class Drawable { private Rect mBounds = ZERO_BOUNDS_RECT; // lazily becomes a new Rect() private WeakReference<Callback> mCallback = null; private boolean mVisible = true; - private DisplayList mDisplayList; private int mLayoutDirection; /** * Draw in its bounds (set via setBounds) respecting optional effects such * as alpha (set via setAlpha) and color filter (set via setColorFilter). - * <p> - * Overriding this method will prevent caching optimizations. To enable - * optimizations, override {@link #onDraw} instead. - * - * @param canvas The canvas to draw into - */ - public void draw(Canvas canvas) { - if (canvas != null && canvas.isHardwareAccelerated() && false) { // temporarily disabled - final HardwareCanvas hardwareCanvas = (HardwareCanvas) canvas; - final DisplayList displayList = getDisplayList(hardwareCanvas); - if (displayList != null) { - final int restoreCount = hardwareCanvas.save(Canvas.MATRIX_SAVE_FLAG); - hardwareCanvas.translate(mBounds.left, mBounds.top); - hardwareCanvas.drawDisplayList(displayList); - hardwareCanvas.restoreToCount(restoreCount); - return; - } - } - - onDraw(canvas); - } - - /** - * Draw in its bounds (set via setBounds) respecting optional effects such - * as alpha (set via setAlpha) and color filter (set via setColorFilter). - * <p> - * Overriding this method, rather than {@link #draw}, enables caching - * optimizations that avoid re-drawing when unnecessary. * * @param canvas The canvas to draw into */ - protected void onDraw(Canvas canvas) { - throw new UnsupportedOperationException( - "Drawable subclasses must implement either draw or onDraw"); - } - - /** - * Gets a display list that can be used to draw this drawable again without - * invoking its draw method. - * - * @param hardwareCanvas The hardware canvas. - * @return A DisplayList ready to replay, or null if caching is not enabled. - * @hide - */ - private DisplayList getDisplayList(HardwareCanvas hardwareCanvas) { - DisplayList displayList = mDisplayList; - if (displayList != null && displayList.isValid()) { - // Note: This code assumes that the display list previously generated - // is compatible with the given hardware canvas. That might not be true - // if we start using multiple different types of hardware canvas - // in the system someday. - return displayList; - } - - displayList = DisplayList.create(getClass().getName()); - mDisplayList = displayList; - - final Rect bounds = mBounds; - final int width = bounds.width(); - final int height = bounds.height(); - final HardwareCanvas canvas = displayList.start(width, height); - canvas.onPreDraw(null); - - // Draw the display list with origin (0,0) so that if the position - // changes then we can translate without recreating the display list. - final int restoreCount = canvas.save(); - try { - canvas.translate(-bounds.left, -bounds.top); - onDraw(canvas); - } finally { - canvas.restoreToCount(restoreCount); - canvas.onPostDraw(); - displayList.end(); - } - - displayList.setLeftTopRightBottom(0, 0, width, height); - displayList.setClipToBounds(false); - return displayList; - } - - private void invalidateDisplayList() { - mDisplayList = null; - } + public abstract void draw(Canvas canvas); /** * Specify a bounding rectangle for the Drawable. This is where the drawable @@ -246,11 +163,10 @@ public abstract class Drawable { if (oldBounds.left != left || oldBounds.top != top || oldBounds.right != right || oldBounds.bottom != bottom) { - if (oldBounds.right - oldBounds.left != right - left - || oldBounds.bottom - oldBounds.top != bottom - top) { - invalidateDisplayList(); + if (!oldBounds.isEmpty()) { + // first invalidate the previous bounds + invalidateSelf(); } - mBounds.set(left, top, right, bottom); onBoundsChange(mBounds); } @@ -438,8 +354,6 @@ public abstract class Drawable { * @see #setCallback(android.graphics.drawable.Drawable.Callback) */ public void invalidateSelf() { - invalidateDisplayList(); - final Callback callback = getCallback(); if (callback != null) { callback.invalidateDrawable(this); diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 6b0f7ba..e654db1 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -472,7 +472,7 @@ public class GradientDrawable extends Drawable { } @Override - protected void onDraw(Canvas canvas) { + public void draw(Canvas canvas) { if (!ensureValidRect()) { // nothing to draw return; diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index ee64d7a..515d3c1 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -223,7 +223,7 @@ public class NinePatchDrawable extends Drawable { } @Override - protected void onDraw(Canvas canvas) { + public void draw(Canvas canvas) { final Rect bounds = getBounds(); final boolean needsMirroring = needsMirroring(); if (needsMirroring) { diff --git a/graphics/java/android/graphics/drawable/PictureDrawable.java b/graphics/java/android/graphics/drawable/PictureDrawable.java index 2118b23..cb2d8f6 100644 --- a/graphics/java/android/graphics/drawable/PictureDrawable.java +++ b/graphics/java/android/graphics/drawable/PictureDrawable.java @@ -60,7 +60,7 @@ public class PictureDrawable extends Drawable { } @Override - protected void onDraw(Canvas canvas) { + public void draw(Canvas canvas) { if (mPicture != null) { Rect bounds = getBounds(); canvas.save(); diff --git a/graphics/java/android/graphics/drawable/ShapeDrawable.java b/graphics/java/android/graphics/drawable/ShapeDrawable.java index 9ca3bbf..93f2dc6 100644 --- a/graphics/java/android/graphics/drawable/ShapeDrawable.java +++ b/graphics/java/android/graphics/drawable/ShapeDrawable.java @@ -210,7 +210,7 @@ public class ShapeDrawable extends Drawable { } @Override - protected void onDraw(Canvas canvas) { + public void draw(Canvas canvas) { Rect r = getBounds(); Paint paint = mShapeState.mPaint; |