Expand dashing3 GM to include additional dashing cases
https://codereview.appspot.com/6870056/
git-svn-id: http://skia.googlecode.com/svn/trunk@6667 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/dashing.cpp b/gm/dashing.cpp
index e09df5f..935ae4a 100644
--- a/gm/dashing.cpp
+++ b/gm/dashing.cpp
@@ -185,62 +185,110 @@
// Draw a 100x100 block of dashed lines. The horizontal ones are BW
// while the vertical ones are AA.
- void drawDashedLines(SkCanvas* canvas, SkScalar length, SkScalar phase) {
+ void drawDashedLines(SkCanvas* canvas,
+ SkScalar lineLength,
+ SkScalar phase,
+ SkScalar dashLength,
+ int strokeWidth,
+ bool circles) {
SkPaint p;
p.setColor(SK_ColorBLACK);
p.setStyle(SkPaint::kStroke_Style);
- p.setStrokeWidth(SK_Scalar1);
+ p.setStrokeWidth(SkIntToScalar(strokeWidth));
- SkScalar intervals[2] = { SK_Scalar1, SK_Scalar1 };
+ if (circles) {
+ p.setStrokeCap(SkPaint::kRound_Cap);
+ }
+
+ SkScalar intervals[2] = { dashLength, dashLength };
p.setPathEffect(new SkDashPathEffect(intervals, 2, phase, false));
SkPoint pts[2];
- for (int y = 0; y < 100; y += 5) {
+ for (int y = 0; y < 100; y += 10*strokeWidth) {
pts[0].set(0, SkIntToScalar(y));
- pts[1].set(length, SkIntToScalar(y));
+ pts[1].set(lineLength, SkIntToScalar(y));
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
}
p.setAntiAlias(true);
- for (int x = 0; x < 100; x += 7) {
+ for (int x = 0; x < 100; x += 14*strokeWidth) {
pts[0].set(SkIntToScalar(x), 0);
- pts[1].set(SkIntToScalar(x), length);
+ pts[1].set(SkIntToScalar(x), lineLength);
canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
}
}
virtual void onDraw(SkCanvas* canvas) {
- // fast path should work on this run
+ // 1on/1off 1x1 squares with phase of 0 - points fastpath
canvas->save();
- this->drawDashedLines(canvas, 100, SK_Scalar1);
+ canvas->translate(2, 0);
+ this->drawDashedLines(canvas, 100, 0, SK_Scalar1, 1, false);
canvas->restore();
- // non-1 phase should break the fast path
+ // 1on/1off 1x1 squares with phase of .5 - rects fastpath (due to partial squares)
canvas->save();
- canvas->translate(110, 0);
- this->drawDashedLines(canvas, 100, SK_ScalarHalf);
+ canvas->translate(112, 0);
+ this->drawDashedLines(canvas, 100, SK_ScalarHalf, SK_Scalar1, 1, false);
canvas->restore();
- // non-integer length should break the fast path
+ // 1on/1off 1x1 squares with phase of 1 - points fastpath
canvas->save();
- canvas->translate(220, 0);
- this->drawDashedLines(canvas, 99.5, SK_ScalarHalf);
+ canvas->translate(222, 0);
+ this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
canvas->restore();
- // rotation should break the fast path
+ // 1on/1off 1x1 squares with phase of 1 and non-integer length - rects fastpath
canvas->save();
- canvas->translate(110+SK_ScalarRoot2Over2*100, 110+SK_ScalarRoot2Over2*100);
+ canvas->translate(332, 0);
+ this->drawDashedLines(canvas, 99.5, SK_ScalarHalf, SK_Scalar1, 1, false);
+ canvas->restore();
+
+ // 1on/1off 3x3 squares with phase of 0 - points fast path
+ canvas->save();
+ canvas->translate(2, 110);
+ this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, false);
+ canvas->restore();
+
+ // 1on/1off 3x3 squares with phase of 1.5 - rects fast path
+ canvas->save();
+ canvas->translate(112, 110);
+ this->drawDashedLines(canvas, 100, SkFloatToScalar(1.5f), SkIntToScalar(3), 3, false);
+ canvas->restore();
+
+ // 1on/1off 1x1 circles with phase of 1 - no fast path yet
+ canvas->save();
+ canvas->translate(2, 220);
+ this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, true);
+ canvas->restore();
+
+ // 1on/1off 3x3 circles with phase of 1 - no fast path yet
+ canvas->save();
+ canvas->translate(112, 220);
+ this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, true);
+ canvas->restore();
+
+ // 1on/1off 1x1 squares with rotation - should break fast path
+ canvas->save();
+ canvas->translate(332+SK_ScalarRoot2Over2*100, 110+SK_ScalarRoot2Over2*100);
canvas->rotate(45);
canvas->translate(-50, -50);
- this->drawDashedLines(canvas, 100, SK_Scalar1);
+ this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
canvas->restore();
+ // 3on/3off 3x1 rects - should use rect fast path regardless of phase
+ for (int phase = 0; phase <= 3; ++phase) {
+ canvas->save();
+ canvas->translate(SkIntToScalar(phase*110+2),
+ SkIntToScalar(330));
+ this->drawDashedLines(canvas, 100, SkIntToScalar(phase), SkIntToScalar(3), 1, false);
+ canvas->restore();
+ }
}
};