OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkDashPathEffect.h" | 11 #include "SkDashPathEffect.h" |
12 | 12 |
13 static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint, | 13 static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint, |
14 SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkI
ntToScalar(0), | 14 SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkI
ntToScalar(0), |
15 SkScalar phase = SkIntToScalar(0), | 15 SkScalar phase = SkIntToScalar(0), |
16 SkScalar startX = SkIntToScalar(0), SkScalar startY = SkInt
ToScalar(0)) { | 16 SkScalar startX = SkIntToScalar(0), SkScalar startY = SkInt
ToScalar(0)) { |
17 SkPaint p(paint); | 17 SkPaint p(paint); |
18 | 18 |
19 const SkScalar intervals[] = { | 19 const SkScalar intervals[] = { |
20 SkIntToScalar(on), | 20 SkIntToScalar(on), |
21 SkIntToScalar(off), | 21 SkIntToScalar(off), |
22 }; | 22 }; |
23 | 23 |
24 SkAutoTUnref<SkPathEffect> effect(SkDashPathEffect::Create(intervals, 2, pha
se)); | 24 p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase)); |
25 p.setPathEffect(effect); | |
26 canvas->drawLine(startX, startY, finalX, finalY, p); | 25 canvas->drawLine(startX, startY, finalX, finalY, p); |
27 } | 26 } |
28 | 27 |
29 // earlier bug stopped us from drawing very long single-segment dashes, because | 28 // earlier bug stopped us from drawing very long single-segment dashes, because |
30 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is | 29 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is |
31 // now fixes, so this giant dash should appear. | 30 // now fixes, so this giant dash should appear. |
32 static void show_giant_dash(SkCanvas* canvas) { | 31 static void show_giant_dash(SkCanvas* canvas) { |
33 SkPaint paint; | 32 SkPaint paint; |
34 | 33 |
35 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); | 34 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 SkScalar dy = bounds.height() * 4 / 3; | 167 SkScalar dy = bounds.height() * 4 / 3; |
169 | 168 |
170 const int* intervals = &gIntervals[1]; | 169 const int* intervals = &gIntervals[1]; |
171 for (int y = 0; y < gIntervals[0]; ++y) { | 170 for (int y = 0; y < gIntervals[0]; ++y) { |
172 SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough | 171 SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough |
173 int count = *intervals++; | 172 int count = *intervals++; |
174 for (int i = 0; i < count; ++i) { | 173 for (int i = 0; i < count; ++i) { |
175 vals[i] = SkIntToScalar(*intervals++); | 174 vals[i] = SkIntToScalar(*intervals++); |
176 } | 175 } |
177 SkScalar phase = vals[0] / 2; | 176 SkScalar phase = vals[0] / 2; |
178 paint.setPathEffect(SkDashPathEffect::Create(vals, count, phase))->u
nref(); | 177 paint.setPathEffect(SkDashPathEffect::Make(vals, count, phase)); |
179 | 178 |
180 for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) { | 179 for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) { |
181 SkPath path; | 180 SkPath path; |
182 SkRect r = bounds; | 181 SkRect r = bounds; |
183 r.offset(x * dx, y * dy); | 182 r.offset(x * dx, y * dy); |
184 gProc[x](&path, r); | 183 gProc[x](&path, r); |
185 | 184 |
186 canvas->drawPath(path, paint); | 185 canvas->drawPath(path, paint); |
187 } | 186 } |
188 } | 187 } |
(...skipping 27 matching lines...) Expand all Loading... |
216 p.setColor(SK_ColorBLACK); | 215 p.setColor(SK_ColorBLACK); |
217 p.setStyle(SkPaint::kStroke_Style); | 216 p.setStyle(SkPaint::kStroke_Style); |
218 p.setStrokeWidth(SkIntToScalar(strokeWidth)); | 217 p.setStrokeWidth(SkIntToScalar(strokeWidth)); |
219 | 218 |
220 if (circles) { | 219 if (circles) { |
221 p.setStrokeCap(SkPaint::kRound_Cap); | 220 p.setStrokeCap(SkPaint::kRound_Cap); |
222 } | 221 } |
223 | 222 |
224 SkScalar intervals[2] = { dashLength, dashLength }; | 223 SkScalar intervals[2] = { dashLength, dashLength }; |
225 | 224 |
226 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref(); | 225 p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase)); |
227 | 226 |
228 SkPoint pts[2]; | 227 SkPoint pts[2]; |
229 | 228 |
230 for (int y = 0; y < 100; y += 10*strokeWidth) { | 229 for (int y = 0; y < 100; y += 10*strokeWidth) { |
231 pts[0].set(0, SkIntToScalar(y)); | 230 pts[0].set(0, SkIntToScalar(y)); |
232 pts[1].set(lineLength, SkIntToScalar(y)); | 231 pts[1].set(lineLength, SkIntToScalar(y)); |
233 | 232 |
234 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); | 233 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); |
235 } | 234 } |
236 | 235 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i, | 491 lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i, |
493 pts[0].fY * (1 - i) + pts[1].fY * i); | 492 pts[0].fY * (1 - i) + pts[1].fY * i); |
494 } | 493 } |
495 } | 494 } |
496 } | 495 } |
497 SkPaint p; | 496 SkPaint p; |
498 p.setAntiAlias(true); | 497 p.setAntiAlias(true); |
499 p.setStyle(SkPaint::kStroke_Style); | 498 p.setStyle(SkPaint::kStroke_Style); |
500 p.setStrokeWidth(1); | 499 p.setStrokeWidth(1); |
501 const SkScalar intervals[] = { 1, 1 }; | 500 const SkScalar intervals[] = { 1, 1 }; |
502 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals
), 0))->unref(); | 501 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals),
0)); |
503 canvas->drawPath(lines, p); | 502 canvas->drawPath(lines, p); |
504 } | 503 } |
505 | 504 |
506 DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) { | 505 DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) { |
507 SkPaint p; | 506 SkPaint p; |
508 p.setAntiAlias(true); | 507 p.setAntiAlias(true); |
509 p.setStyle(SkPaint::kStroke_Style); | 508 p.setStyle(SkPaint::kStroke_Style); |
510 p.setStrokeWidth(80); | 509 p.setStrokeWidth(80); |
511 | 510 |
512 const SkScalar intervals[] = { 2, 2 }; | 511 const SkScalar intervals[] = { 2, 2 }; |
513 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals
), 0))->unref(); | 512 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals),
0)); |
514 canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p); | 513 canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p); |
515 } | 514 } |
516 | 515 |
517 DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) { | 516 DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) { |
518 SkPaint p; | 517 SkPaint p; |
519 p.setAntiAlias(true); | 518 p.setAntiAlias(true); |
520 p.setStyle(SkPaint::kStroke_Style); | 519 p.setStyle(SkPaint::kStroke_Style); |
521 p.setStrokeWidth(2); | 520 p.setStrokeWidth(2); |
522 | 521 |
523 SkPath wavy; | 522 SkPath wavy; |
524 wavy.moveTo(-10000, 100); | 523 wavy.moveTo(-10000, 100); |
525 for (SkScalar i = -10000; i < 10000; i += 20) { | 524 for (SkScalar i = -10000; i < 10000; i += 20) { |
526 wavy.quadTo(i + 5, 95, i + 10, 100); | 525 wavy.quadTo(i + 5, 95, i + 10, 100); |
527 wavy.quadTo(i + 15, 105, i + 20, 100); | 526 wavy.quadTo(i + 15, 105, i + 20, 100); |
528 } | 527 } |
529 canvas->drawPath(wavy, p); | 528 canvas->drawPath(wavy, p); |
530 } | 529 } |
531 | 530 |
532 DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) { | 531 DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) { |
533 SkPaint p; | 532 SkPaint p; |
534 p.setAntiAlias(true); | 533 p.setAntiAlias(true); |
535 p.setStyle(SkPaint::kStroke_Style); | 534 p.setStyle(SkPaint::kStroke_Style); |
536 p.setStrokeWidth(10); | 535 p.setStrokeWidth(10); |
537 p.setStrokeCap(SkPaint::kRound_Cap); | 536 p.setStrokeCap(SkPaint::kRound_Cap); |
538 p.setStrokeJoin(SkPaint::kRound_Join); | 537 p.setStrokeJoin(SkPaint::kRound_Join); |
539 p.setTextSize(100); | 538 p.setTextSize(100); |
540 p.setARGB(0xff, 0xbb, 0x00, 0x00); | 539 p.setARGB(0xff, 0xbb, 0x00, 0x00); |
541 sk_tool_utils::set_portable_typeface(&p); | 540 sk_tool_utils::set_portable_typeface(&p); |
542 const SkScalar intervals[] = { 12, 12 }; | 541 const SkScalar intervals[] = { 12, 12 }; |
543 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals
), 0))->unref(); | 542 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals),
0)); |
544 canvas->drawText("Sausages", 8, 10, 90, p); | 543 canvas->drawText("Sausages", 8, 10, 90, p); |
545 canvas->drawLine(8, 120, 456, 120, p); | 544 canvas->drawLine(8, 120, 456, 120, p); |
546 } | 545 } |
547 | 546 |
548 ////////////////////////////////////////////////////////////////////////////// | 547 ////////////////////////////////////////////////////////////////////////////// |
549 | 548 |
550 DEF_GM(return new DashingGM;) | 549 DEF_GM(return new DashingGM;) |
551 DEF_GM(return new Dashing2GM;) | 550 DEF_GM(return new Dashing2GM;) |
552 DEF_GM(return new Dashing3GM;) | 551 DEF_GM(return new Dashing3GM;) |
553 DEF_GM(return new Dashing4GM;) | 552 DEF_GM(return new Dashing4GM;) |
554 DEF_GM(return new Dashing5GM(true);) | 553 DEF_GM(return new Dashing5GM(true);) |
555 DEF_GM(return new Dashing5GM(false);) | 554 DEF_GM(return new Dashing5GM(false);) |
OLD | NEW |