summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2016-07-26 16:22:50 -0700
committerChris Craik <ccraik@google.com>2016-07-26 16:22:51 -0700
commit814ee6a9218aa339a4757b2c0ba1ad268f8dbc8a (patch)
tree579a0b5fe4a17a1eabd22eccf2896bcf67ea7c61 /libs
parent2f8bf1f024a63041693ff2a1e04269b2cbff8b36 (diff)
downloadandroid-frameworks-base-814ee6a9218aa339a4757b2c0ba1ad268f8dbc8a.tar.gz
android-frameworks-base-814ee6a9218aa339a4757b2c0ba1ad268f8dbc8a.tar.xz
Reject fully transparent paint-fill ops at record time
bug:30342762 Avoids unnecessary work for each transparent operation. Change-Id: I80b1eeca34ae32249433fde55e9fe93d02c411db
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/RecordingCanvas.cpp20
-rw-r--r--libs/hwui/tests/unit/FrameBuilderTests.cpp3
-rw-r--r--libs/hwui/tests/unit/RecordingCanvasTests.cpp21
3 files changed, 40 insertions, 4 deletions
diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp
index cbefccb..1802fd4 100644
--- a/libs/hwui/RecordingCanvas.cpp
+++ b/libs/hwui/RecordingCanvas.cpp
@@ -268,7 +268,7 @@ static Rect calcBoundsOfPoints(const float* points, int floatCount) {
// Geometry
void RecordingCanvas::drawPoints(const float* points, int floatCount, const SkPaint& paint) {
- if (floatCount < 2) return;
+ if (CC_UNLIKELY(floatCount < 2 || PaintUtils::paintWillNotDraw(paint))) return;
floatCount &= ~0x1; // round down to nearest two
addOp(alloc().create_trivial<PointsOp>(
@@ -279,7 +279,7 @@ void RecordingCanvas::drawPoints(const float* points, int floatCount, const SkPa
}
void RecordingCanvas::drawLines(const float* points, int floatCount, const SkPaint& paint) {
- if (floatCount < 4) return;
+ if (CC_UNLIKELY(floatCount < 4 || PaintUtils::paintWillNotDraw(paint))) return;
floatCount &= ~0x3; // round down to nearest four
addOp(alloc().create_trivial<LinesOp>(
@@ -290,6 +290,8 @@ void RecordingCanvas::drawLines(const float* points, int floatCount, const SkPai
}
void RecordingCanvas::drawRect(float left, float top, float right, float bottom, const SkPaint& paint) {
+ if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
+
addOp(alloc().create_trivial<RectOp>(
Rect(left, top, right, bottom),
*(mState.currentSnapshot()->transform),
@@ -331,6 +333,8 @@ void RecordingCanvas::drawSimpleRects(const float* rects, int vertexCount, const
}
void RecordingCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
+ if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
+
if (paint.getStyle() == SkPaint::kFill_Style
&& (!paint.isAntiAlias() || mState.currentTransform()->isSimple())) {
int count = 0;
@@ -355,8 +359,11 @@ void RecordingCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
}
}
}
+
void RecordingCanvas::drawRoundRect(float left, float top, float right, float bottom,
float rx, float ry, const SkPaint& paint) {
+ if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
+
if (CC_LIKELY(MathUtils::isPositive(rx) || MathUtils::isPositive(ry))) {
addOp(alloc().create_trivial<RoundRectOp>(
Rect(left, top, right, bottom),
@@ -391,7 +398,8 @@ void RecordingCanvas::drawRoundRect(
void RecordingCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
// TODO: move to Canvas.h
- if (radius <= 0) return;
+ if (CC_UNLIKELY(radius <= 0 || PaintUtils::paintWillNotDraw(paint))) return;
+
drawOval(x - radius, y - radius, x + radius, y + radius, paint);
}
@@ -411,6 +419,8 @@ void RecordingCanvas::drawCircle(
}
void RecordingCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) {
+ if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
+
addOp(alloc().create_trivial<OvalOp>(
Rect(left, top, right, bottom),
*(mState.currentSnapshot()->transform),
@@ -420,6 +430,8 @@ void RecordingCanvas::drawOval(float left, float top, float right, float bottom,
void RecordingCanvas::drawArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
+ if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
+
if (fabs(sweepAngle) >= 360.0f) {
drawOval(left, top, right, bottom, paint);
} else {
@@ -433,6 +445,8 @@ void RecordingCanvas::drawArc(float left, float top, float right, float bottom,
}
void RecordingCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
+ if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
+
addOp(alloc().create_trivial<PathOp>(
Rect(path.getBounds()),
*(mState.currentSnapshot()->transform),
diff --git a/libs/hwui/tests/unit/FrameBuilderTests.cpp b/libs/hwui/tests/unit/FrameBuilderTests.cpp
index af54e07..53dbede 100644
--- a/libs/hwui/tests/unit/FrameBuilderTests.cpp
+++ b/libs/hwui/tests/unit/FrameBuilderTests.cpp
@@ -1459,7 +1459,8 @@ RENDERTHREAD_TEST(FrameBuilder, buildLayer) {
static void drawOrderedRect(RecordingCanvas* canvas, uint8_t expectedDrawOrder) {
SkPaint paint;
- paint.setColor(SkColorSetARGB(256, 0, 0, expectedDrawOrder)); // order put in blue channel
+ // order put in blue channel, transparent so overlapped content doesn't get rejected
+ paint.setColor(SkColorSetARGB(1, 0, 0, expectedDrawOrder));
canvas->drawRect(0, 0, 100, 100, paint);
}
static void drawOrderedNode(RecordingCanvas* canvas, uint8_t expectedDrawOrder, float z) {
diff --git a/libs/hwui/tests/unit/RecordingCanvasTests.cpp b/libs/hwui/tests/unit/RecordingCanvasTests.cpp
index 9cd504e..28b375f 100644
--- a/libs/hwui/tests/unit/RecordingCanvasTests.cpp
+++ b/libs/hwui/tests/unit/RecordingCanvasTests.cpp
@@ -81,6 +81,27 @@ TEST(RecordingCanvas, emptyClipRect) {
ASSERT_EQ(0u, dl->getOps().size()) << "Must be zero ops. Rect should be rejected.";
}
+TEST(RecordingCanvas, emptyPaintRejection) {
+ auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
+ SkPaint emptyPaint;
+ emptyPaint.setColor(Color::Transparent);
+
+ float points[] = {0, 0, 200, 200};
+ canvas.drawPoints(points, 4, emptyPaint);
+ canvas.drawLines(points, 4, emptyPaint);
+ canvas.drawRect(0, 0, 200, 200, emptyPaint);
+ canvas.drawRegion(SkRegion(SkIRect::MakeWH(200, 200)), emptyPaint);
+ canvas.drawRoundRect(0, 0, 200, 200, 10, 10, emptyPaint);
+ canvas.drawCircle(100, 100, 100, emptyPaint);
+ canvas.drawOval(0, 0, 200, 200, emptyPaint);
+ canvas.drawArc(0, 0, 200, 200, 0, 360, true, emptyPaint);
+ SkPath path;
+ path.addRect(0, 0, 200, 200);
+ canvas.drawPath(path, emptyPaint);
+ });
+ EXPECT_EQ(0u, dl->getOps().size()) << "Op should be rejected";
+}
+
TEST(RecordingCanvas, drawArc) {
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
canvas.drawArc(0, 0, 200, 200, 0, 180, true, SkPaint());