aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/dashing.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-04 20:34:11 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-12-04 20:34:11 +0000
commit8c685c5d7594c5e8a5e6edf363cd07e325f603b7 (patch)
tree7b94ccd61c125d4d200f32254bb6b68809a1bc4c /gm/dashing.cpp
parenta444430281ea35cb76fb42516978b4a93221c2c7 (diff)
Expand dashing3 GM to include additional dashing cases
Diffstat (limited to 'gm/dashing.cpp')
-rw-r--r--gm/dashing.cpp84
1 files changed, 66 insertions, 18 deletions
diff --git a/gm/dashing.cpp b/gm/dashing.cpp
index e09df5f21e..935ae4a0d3 100644
--- a/gm/dashing.cpp
+++ b/gm/dashing.cpp
@@ -185,62 +185,110 @@ protected:
// 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();
+ canvas->translate(2, 0);
+ this->drawDashedLines(canvas, 100, 0, SK_Scalar1, 1, false);
+ canvas->restore();
+
+ // 1on/1off 1x1 squares with phase of .5 - rects fastpath (due to partial squares)
+ canvas->save();
+ canvas->translate(112, 0);
+ this->drawDashedLines(canvas, 100, SK_ScalarHalf, SK_Scalar1, 1, false);
+ canvas->restore();
+
+ // 1on/1off 1x1 squares with phase of 1 - points fastpath
+ canvas->save();
+ canvas->translate(222, 0);
+ this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, false);
+ canvas->restore();
+
+ // 1on/1off 1x1 squares with phase of 1 and non-integer length - rects fastpath
+ canvas->save();
+ 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();
- this->drawDashedLines(canvas, 100, SK_Scalar1);
+ canvas->translate(2, 110);
+ this->drawDashedLines(canvas, 100, 0, SkIntToScalar(3), 3, false);
canvas->restore();
- // non-1 phase should break the fast path
+ // 1on/1off 3x3 squares with phase of 1.5 - rects fast path
canvas->save();
- canvas->translate(110, 0);
- this->drawDashedLines(canvas, 100, SK_ScalarHalf);
+ canvas->translate(112, 110);
+ this->drawDashedLines(canvas, 100, SkFloatToScalar(1.5f), SkIntToScalar(3), 3, false);
canvas->restore();
- // non-integer length should break the fast path
+ // 1on/1off 1x1 circles with phase of 1 - no fast path yet
canvas->save();
- canvas->translate(220, 0);
- this->drawDashedLines(canvas, 99.5, SK_ScalarHalf);
+ canvas->translate(2, 220);
+ this->drawDashedLines(canvas, 100, SK_Scalar1, SK_Scalar1, 1, true);
canvas->restore();
- // rotation should break the fast path
+ // 1on/1off 3x3 circles with phase of 1 - no fast path yet
canvas->save();
- canvas->translate(110+SK_ScalarRoot2Over2*100, 110+SK_ScalarRoot2Over2*100);
+ 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();
+ }
}
};