Reject fully transparent paint-fill ops at record time
am: 814ee6a921
Change-Id: Ie38ec468acf7ad30108f1279185f5a4b646b6f45
This commit is contained in:
@@ -268,7 +268,7 @@ static Rect calcBoundsOfPoints(const float* points, int floatCount) {
|
|||||||
|
|
||||||
// Geometry
|
// Geometry
|
||||||
void RecordingCanvas::drawPoints(const float* points, int floatCount, const SkPaint& paint) {
|
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
|
floatCount &= ~0x1; // round down to nearest two
|
||||||
|
|
||||||
addOp(alloc().create_trivial<PointsOp>(
|
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) {
|
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
|
floatCount &= ~0x3; // round down to nearest four
|
||||||
|
|
||||||
addOp(alloc().create_trivial<LinesOp>(
|
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) {
|
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>(
|
addOp(alloc().create_trivial<RectOp>(
|
||||||
Rect(left, top, right, bottom),
|
Rect(left, top, right, bottom),
|
||||||
*(mState.currentSnapshot()->transform),
|
*(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) {
|
void RecordingCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
|
||||||
|
if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
|
||||||
|
|
||||||
if (paint.getStyle() == SkPaint::kFill_Style
|
if (paint.getStyle() == SkPaint::kFill_Style
|
||||||
&& (!paint.isAntiAlias() || mState.currentTransform()->isSimple())) {
|
&& (!paint.isAntiAlias() || mState.currentTransform()->isSimple())) {
|
||||||
int count = 0;
|
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,
|
void RecordingCanvas::drawRoundRect(float left, float top, float right, float bottom,
|
||||||
float rx, float ry, const SkPaint& paint) {
|
float rx, float ry, const SkPaint& paint) {
|
||||||
|
if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
|
||||||
|
|
||||||
if (CC_LIKELY(MathUtils::isPositive(rx) || MathUtils::isPositive(ry))) {
|
if (CC_LIKELY(MathUtils::isPositive(rx) || MathUtils::isPositive(ry))) {
|
||||||
addOp(alloc().create_trivial<RoundRectOp>(
|
addOp(alloc().create_trivial<RoundRectOp>(
|
||||||
Rect(left, top, right, bottom),
|
Rect(left, top, right, bottom),
|
||||||
@@ -391,7 +398,8 @@ void RecordingCanvas::drawRoundRect(
|
|||||||
|
|
||||||
void RecordingCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
|
void RecordingCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) {
|
||||||
// TODO: move to Canvas.h
|
// 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);
|
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) {
|
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>(
|
addOp(alloc().create_trivial<OvalOp>(
|
||||||
Rect(left, top, right, bottom),
|
Rect(left, top, right, bottom),
|
||||||
*(mState.currentSnapshot()->transform),
|
*(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,
|
void RecordingCanvas::drawArc(float left, float top, float right, float bottom,
|
||||||
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
|
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) {
|
||||||
|
if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
|
||||||
|
|
||||||
if (fabs(sweepAngle) >= 360.0f) {
|
if (fabs(sweepAngle) >= 360.0f) {
|
||||||
drawOval(left, top, right, bottom, paint);
|
drawOval(left, top, right, bottom, paint);
|
||||||
} else {
|
} 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) {
|
void RecordingCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
|
||||||
|
if (CC_UNLIKELY(PaintUtils::paintWillNotDraw(paint))) return;
|
||||||
|
|
||||||
addOp(alloc().create_trivial<PathOp>(
|
addOp(alloc().create_trivial<PathOp>(
|
||||||
Rect(path.getBounds()),
|
Rect(path.getBounds()),
|
||||||
*(mState.currentSnapshot()->transform),
|
*(mState.currentSnapshot()->transform),
|
||||||
|
|||||||
@@ -1459,7 +1459,8 @@ RENDERTHREAD_TEST(FrameBuilder, buildLayer) {
|
|||||||
|
|
||||||
static void drawOrderedRect(RecordingCanvas* canvas, uint8_t expectedDrawOrder) {
|
static void drawOrderedRect(RecordingCanvas* canvas, uint8_t expectedDrawOrder) {
|
||||||
SkPaint paint;
|
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);
|
canvas->drawRect(0, 0, 100, 100, paint);
|
||||||
}
|
}
|
||||||
static void drawOrderedNode(RecordingCanvas* canvas, uint8_t expectedDrawOrder, float z) {
|
static void drawOrderedNode(RecordingCanvas* canvas, uint8_t expectedDrawOrder, float z) {
|
||||||
|
|||||||
@@ -81,6 +81,27 @@ TEST(RecordingCanvas, emptyClipRect) {
|
|||||||
ASSERT_EQ(0u, dl->getOps().size()) << "Must be zero ops. Rect should be rejected.";
|
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) {
|
TEST(RecordingCanvas, drawArc) {
|
||||||
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
|
auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
|
||||||
canvas.drawArc(0, 0, 200, 200, 0, 180, true, SkPaint());
|
canvas.drawArc(0, 0, 200, 200, 0, 180, true, SkPaint());
|
||||||
|
|||||||
Reference in New Issue
Block a user