From 2410b90e066b75b14798b2c60c77e00865654496 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 23 Jan 2020 12:55:53 -0500 Subject: [PATCH] Deprecate Canvas.EdgeType Bug: 129694386 Test: No change in behavior, no new tests EdgeType is only used as a parameter to quickReject, but it is always ignored. Deprecate it and the existing quickReject methods. Add new versions of quickReject without EdgeType parameters. Switch clients to the new versions. Change-Id: Id932f10915a8c4959fe0e85f507ce7fd2da8a576 --- api/current.txt | 15 +++-- core/java/android/view/View.java | 2 +- .../android/widget/ScrollBarDrawable.java | 2 +- graphics/java/android/graphics/Canvas.java | 60 +++++++++++++++++++ .../test/hwui/AlphaLayersActivity.java | 22 +++---- 5 files changed, 79 insertions(+), 22 deletions(-) diff --git a/api/current.txt b/api/current.txt index 74328c4a333ac..83ce81b40b63f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -14220,9 +14220,12 @@ package android.graphics { method public int getWidth(); method public boolean isHardwareAccelerated(); method public boolean isOpaque(); - method public boolean quickReject(@NonNull android.graphics.RectF, @NonNull android.graphics.Canvas.EdgeType); - method public boolean quickReject(@NonNull android.graphics.Path, @NonNull android.graphics.Canvas.EdgeType); - method public boolean quickReject(float, float, float, float, @NonNull android.graphics.Canvas.EdgeType); + method @Deprecated public boolean quickReject(@NonNull android.graphics.RectF, @NonNull android.graphics.Canvas.EdgeType); + method public boolean quickReject(@NonNull android.graphics.RectF); + method @Deprecated public boolean quickReject(@NonNull android.graphics.Path, @NonNull android.graphics.Canvas.EdgeType); + method public boolean quickReject(@NonNull android.graphics.Path); + method @Deprecated public boolean quickReject(float, float, float, float, @NonNull android.graphics.Canvas.EdgeType); + method public boolean quickReject(float, float, float, float); method public void restore(); method public void restoreToCount(int); method public void rotate(float); @@ -14247,9 +14250,9 @@ package android.graphics { field public static final int ALL_SAVE_FLAG = 31; // 0x1f } - public enum Canvas.EdgeType { - enum_constant public static final android.graphics.Canvas.EdgeType AA; - enum_constant public static final android.graphics.Canvas.EdgeType BW; + @Deprecated public enum Canvas.EdgeType { + enum_constant @Deprecated public static final android.graphics.Canvas.EdgeType AA; + enum_constant @Deprecated public static final android.graphics.Canvas.EdgeType BW; } public enum Canvas.VertexMode { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 377a7644f21bb..eb1d27dfcdcec 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -21773,7 +21773,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (!concatMatrix && (parentFlags & (ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS | ViewGroup.FLAG_CLIP_CHILDREN)) == ViewGroup.FLAG_CLIP_CHILDREN && - canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && + canvas.quickReject(mLeft, mTop, mRight, mBottom) && (mPrivateFlags & PFLAG_DRAW_ANIMATION) == 0) { mPrivateFlags2 |= PFLAG2_VIEW_QUICK_REJECTED; return more; diff --git a/core/java/android/widget/ScrollBarDrawable.java b/core/java/android/widget/ScrollBarDrawable.java index 80e17b5e8217d..c2d4596e17dcb 100644 --- a/core/java/android/widget/ScrollBarDrawable.java +++ b/core/java/android/widget/ScrollBarDrawable.java @@ -138,7 +138,7 @@ public class ScrollBarDrawable extends Drawable implements Drawable.Callback { } final Rect r = getBounds(); - if (canvas.quickReject(r.left, r.top, r.right, r.bottom, Canvas.EdgeType.AA)) { + if (canvas.quickReject(r.left, r.top, r.right, r.bottom)) { return; } diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 9a0ca3e4ad9b4..d949444d44d62 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1162,6 +1162,7 @@ public class Canvas extends BaseCanvas { * @see #quickReject(float, float, float, float, EdgeType) * @see #quickReject(Path, EdgeType) * @see #quickReject(RectF, EdgeType) + * @deprecated quickReject no longer uses this. */ public enum EdgeType { @@ -1197,12 +1198,29 @@ public class Canvas extends BaseCanvas { * non-antialiased ({@link Canvas.EdgeType#BW}). * @return true if the rect (transformed by the canvas' matrix) * does not intersect with the canvas' clip + * @deprecated The EdgeType is ignored. Use {@link #quickReject(RectF)} instead. */ + @Deprecated public boolean quickReject(@NonNull RectF rect, @NonNull EdgeType type) { return nQuickReject(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom); } + /** + * Return true if the specified rectangle, after being transformed by the + * current matrix, would lie completely outside of the current clip. Call + * this to check if an area you intend to draw into is clipped out (and + * therefore you can skip making the draw calls). + * + * @param rect the rect to compare with the current clip + * @return true if the rect (transformed by the canvas' matrix) + * does not intersect with the canvas' clip + */ + public boolean quickReject(@NonNull RectF rect) { + return nQuickReject(mNativeCanvasWrapper, + rect.left, rect.top, rect.right, rect.bottom); + } + /** * Return true if the specified path, after being transformed by the * current matrix, would lie completely outside of the current clip. Call @@ -1217,11 +1235,29 @@ public class Canvas extends BaseCanvas { * non-antialiased ({@link Canvas.EdgeType#BW}). * @return true if the path (transformed by the canvas' matrix) * does not intersect with the canvas' clip + * @deprecated The EdgeType is ignored. Use {@link #quickReject(Path)} instead. */ + @Deprecated public boolean quickReject(@NonNull Path path, @NonNull EdgeType type) { return nQuickReject(mNativeCanvasWrapper, path.readOnlyNI()); } + /** + * Return true if the specified path, after being transformed by the + * current matrix, would lie completely outside of the current clip. Call + * this to check if an area you intend to draw into is clipped out (and + * therefore you can skip making the draw calls). Note: for speed it may + * return false even if the path itself might not intersect the clip + * (i.e. the bounds of the path intersects, but the path does not). + * + * @param path The path to compare with the current clip + * @return true if the path (transformed by the canvas' matrix) + * does not intersect with the canvas' clip + */ + public boolean quickReject(@NonNull Path path) { + return nQuickReject(mNativeCanvasWrapper, path.readOnlyNI()); + } + /** * Return true if the specified rectangle, after being transformed by the * current matrix, would lie completely outside of the current clip. Call @@ -1241,12 +1277,36 @@ public class Canvas extends BaseCanvas { * non-antialiased ({@link Canvas.EdgeType#BW}). * @return true if the rect (transformed by the canvas' matrix) * does not intersect with the canvas' clip + * @deprecated The EdgeType is ignored. Use {@link #quickReject(float, float, float, float)} + * instead. */ + @Deprecated public boolean quickReject(float left, float top, float right, float bottom, @NonNull EdgeType type) { return nQuickReject(mNativeCanvasWrapper, left, top, right, bottom); } + /** + * Return true if the specified rectangle, after being transformed by the + * current matrix, would lie completely outside of the current clip. Call + * this to check if an area you intend to draw into is clipped out (and + * therefore you can skip making the draw calls). + * + * @param left The left side of the rectangle to compare with the + * current clip + * @param top The top of the rectangle to compare with the current + * clip + * @param right The right side of the rectangle to compare with the + * current clip + * @param bottom The bottom of the rectangle to compare with the + * current clip + * @return true if the rect (transformed by the canvas' matrix) + * does not intersect with the canvas' clip + */ + public boolean quickReject(float left, float top, float right, float bottom) { + return nQuickReject(mNativeCanvasWrapper, left, top, right, bottom); + } + /** * Return the bounds of the current clip (in local coordinates) in the * bounds parameter, and return true if it is non-empty. This can be useful diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/AlphaLayersActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/AlphaLayersActivity.java index 1a68a93eed193..37661828da229 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/AlphaLayersActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/AlphaLayersActivity.java @@ -50,7 +50,7 @@ public class AlphaLayersActivity extends Activity { setContentView(container); } - + @SuppressWarnings({"UnusedDeclaration"}) static int dipToPx(Context c, int dip) { return (int) (c.getResources().getDisplayMetrics().density * dip + 0.5f); @@ -86,30 +86,24 @@ public class AlphaLayersActivity extends Activity { canvas.save(); canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); Log.d(LOG_TAG, "clipRect = " + canvas.getClipBounds()); - Log.d(LOG_TAG, "rejected = " + canvas.quickReject(100.0f, 100.0f, 110.0f, 110.0f, - Canvas.EdgeType.BW)); - Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f, - Canvas.EdgeType.BW)); + Log.d(LOG_TAG, "rejected = " + canvas.quickReject(100.0f, 100.0f, 110.0f, 110.0f)); + Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f)); canvas.restore(); - + canvas.save(); canvas.scale(2.0f, 2.0f); canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); Log.d(LOG_TAG, "clipRect = " + canvas.getClipBounds()); - Log.d(LOG_TAG, "rejected = " + canvas.quickReject(50.0f, 50.0f, 60.0f, 60.0f, - Canvas.EdgeType.BW)); - Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f, - Canvas.EdgeType.BW)); + Log.d(LOG_TAG, "rejected = " + canvas.quickReject(50.0f, 50.0f, 60.0f, 60.0f)); + Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f)); canvas.restore(); canvas.save(); canvas.translate(20.0f, 20.0f); canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); Log.d(LOG_TAG, "clipRect = " + canvas.getClipBounds()); - Log.d(LOG_TAG, "rejected = " + canvas.quickReject(80.0f, 80.0f, 90.0f, 90.0f, - Canvas.EdgeType.BW)); - Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f, - Canvas.EdgeType.BW)); + Log.d(LOG_TAG, "rejected = " + canvas.quickReject(80.0f, 80.0f, 90.0f, 90.0f)); + Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f)); canvas.restore(); canvas.save();