// 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>(
}
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>(
}
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),
}
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;
}
}
}
+
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),
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);
}
}
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),
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 {
}
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),
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());