Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: gm/dashing.cpp

Issue 1817543002: Revert of switch patheffects over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/dashcubics.cpp ('k') | gm/pathcontourstart.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase)); 24 SkAutoTUnref<SkPathEffect> effect(SkDashPathEffect::Create(intervals, 2, pha se));
25 p.setPathEffect(effect);
25 canvas->drawLine(startX, startY, finalX, finalY, p); 26 canvas->drawLine(startX, startY, finalX, finalY, p);
26 } 27 }
27 28
28 // earlier bug stopped us from drawing very long single-segment dashes, because 29 // earlier bug stopped us from drawing very long single-segment dashes, because
29 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is 30 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is
30 // now fixes, so this giant dash should appear. 31 // now fixes, so this giant dash should appear.
31 static void show_giant_dash(SkCanvas* canvas) { 32 static void show_giant_dash(SkCanvas* canvas) {
32 SkPaint paint; 33 SkPaint paint;
33 34
34 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); 35 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 SkScalar dy = bounds.height() * 4 / 3; 168 SkScalar dy = bounds.height() * 4 / 3;
168 169
169 const int* intervals = &gIntervals[1]; 170 const int* intervals = &gIntervals[1];
170 for (int y = 0; y < gIntervals[0]; ++y) { 171 for (int y = 0; y < gIntervals[0]; ++y) {
171 SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough 172 SkScalar vals[SK_ARRAY_COUNT(gIntervals)]; // more than enough
172 int count = *intervals++; 173 int count = *intervals++;
173 for (int i = 0; i < count; ++i) { 174 for (int i = 0; i < count; ++i) {
174 vals[i] = SkIntToScalar(*intervals++); 175 vals[i] = SkIntToScalar(*intervals++);
175 } 176 }
176 SkScalar phase = vals[0] / 2; 177 SkScalar phase = vals[0] / 2;
177 paint.setPathEffect(SkDashPathEffect::Make(vals, count, phase)); 178 paint.setPathEffect(SkDashPathEffect::Create(vals, count, phase))->u nref();
178 179
179 for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) { 180 for (size_t x = 0; x < SK_ARRAY_COUNT(gProc); ++x) {
180 SkPath path; 181 SkPath path;
181 SkRect r = bounds; 182 SkRect r = bounds;
182 r.offset(x * dx, y * dy); 183 r.offset(x * dx, y * dy);
183 gProc[x](&path, r); 184 gProc[x](&path, r);
184 185
185 canvas->drawPath(path, paint); 186 canvas->drawPath(path, paint);
186 } 187 }
187 } 188 }
(...skipping 27 matching lines...) Expand all
215 p.setColor(SK_ColorBLACK); 216 p.setColor(SK_ColorBLACK);
216 p.setStyle(SkPaint::kStroke_Style); 217 p.setStyle(SkPaint::kStroke_Style);
217 p.setStrokeWidth(SkIntToScalar(strokeWidth)); 218 p.setStrokeWidth(SkIntToScalar(strokeWidth));
218 219
219 if (circles) { 220 if (circles) {
220 p.setStrokeCap(SkPaint::kRound_Cap); 221 p.setStrokeCap(SkPaint::kRound_Cap);
221 } 222 }
222 223
223 SkScalar intervals[2] = { dashLength, dashLength }; 224 SkScalar intervals[2] = { dashLength, dashLength };
224 225
225 p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase)); 226 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref();
226 227
227 SkPoint pts[2]; 228 SkPoint pts[2];
228 229
229 for (int y = 0; y < 100; y += 10*strokeWidth) { 230 for (int y = 0; y < 100; y += 10*strokeWidth) {
230 pts[0].set(0, SkIntToScalar(y)); 231 pts[0].set(0, SkIntToScalar(y));
231 pts[1].set(lineLength, SkIntToScalar(y)); 232 pts[1].set(lineLength, SkIntToScalar(y));
232 233
233 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p); 234 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, p);
234 } 235 }
235 236
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i, 492 lines.lineTo(pts[0].fX * (1 - i) + pts[1].fX * i,
492 pts[0].fY * (1 - i) + pts[1].fY * i); 493 pts[0].fY * (1 - i) + pts[1].fY * i);
493 } 494 }
494 } 495 }
495 } 496 }
496 SkPaint p; 497 SkPaint p;
497 p.setAntiAlias(true); 498 p.setAntiAlias(true);
498 p.setStyle(SkPaint::kStroke_Style); 499 p.setStyle(SkPaint::kStroke_Style);
499 p.setStrokeWidth(1); 500 p.setStrokeWidth(1);
500 const SkScalar intervals[] = { 1, 1 }; 501 const SkScalar intervals[] = { 1, 1 };
501 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); 502 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals ), 0))->unref();
502 canvas->drawPath(lines, p); 503 canvas->drawPath(lines, p);
503 } 504 }
504 505
505 DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) { 506 DEF_SIMPLE_GM(longlinedash, canvas, 512, 512) {
506 SkPaint p; 507 SkPaint p;
507 p.setAntiAlias(true); 508 p.setAntiAlias(true);
508 p.setStyle(SkPaint::kStroke_Style); 509 p.setStyle(SkPaint::kStroke_Style);
509 p.setStrokeWidth(80); 510 p.setStrokeWidth(80);
510 511
511 const SkScalar intervals[] = { 2, 2 }; 512 const SkScalar intervals[] = { 2, 2 };
512 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); 513 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals ), 0))->unref();
513 canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p); 514 canvas->drawRect(SkRect::MakeXYWH(-10000, 100, 20000, 20), p);
514 } 515 }
515 516
516 DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) { 517 DEF_SIMPLE_GM(longwavyline, canvas, 512, 512) {
517 SkPaint p; 518 SkPaint p;
518 p.setAntiAlias(true); 519 p.setAntiAlias(true);
519 p.setStyle(SkPaint::kStroke_Style); 520 p.setStyle(SkPaint::kStroke_Style);
520 p.setStrokeWidth(2); 521 p.setStrokeWidth(2);
521 522
522 SkPath wavy; 523 SkPath wavy;
523 wavy.moveTo(-10000, 100); 524 wavy.moveTo(-10000, 100);
524 for (SkScalar i = -10000; i < 10000; i += 20) { 525 for (SkScalar i = -10000; i < 10000; i += 20) {
525 wavy.quadTo(i + 5, 95, i + 10, 100); 526 wavy.quadTo(i + 5, 95, i + 10, 100);
526 wavy.quadTo(i + 15, 105, i + 20, 100); 527 wavy.quadTo(i + 15, 105, i + 20, 100);
527 } 528 }
528 canvas->drawPath(wavy, p); 529 canvas->drawPath(wavy, p);
529 } 530 }
530 531
531 DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) { 532 DEF_SIMPLE_GM(dashtextcaps, canvas, 512, 512) {
532 SkPaint p; 533 SkPaint p;
533 p.setAntiAlias(true); 534 p.setAntiAlias(true);
534 p.setStyle(SkPaint::kStroke_Style); 535 p.setStyle(SkPaint::kStroke_Style);
535 p.setStrokeWidth(10); 536 p.setStrokeWidth(10);
536 p.setStrokeCap(SkPaint::kRound_Cap); 537 p.setStrokeCap(SkPaint::kRound_Cap);
537 p.setStrokeJoin(SkPaint::kRound_Join); 538 p.setStrokeJoin(SkPaint::kRound_Join);
538 p.setTextSize(100); 539 p.setTextSize(100);
539 p.setARGB(0xff, 0xbb, 0x00, 0x00); 540 p.setARGB(0xff, 0xbb, 0x00, 0x00);
540 sk_tool_utils::set_portable_typeface(&p); 541 sk_tool_utils::set_portable_typeface(&p);
541 const SkScalar intervals[] = { 12, 12 }; 542 const SkScalar intervals[] = { 12, 12 };
542 p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); 543 p.setPathEffect(SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals ), 0))->unref();
543 canvas->drawText("Sausages", 8, 10, 90, p); 544 canvas->drawText("Sausages", 8, 10, 90, p);
544 canvas->drawLine(8, 120, 456, 120, p); 545 canvas->drawLine(8, 120, 456, 120, p);
545 } 546 }
546 547
547 ////////////////////////////////////////////////////////////////////////////// 548 //////////////////////////////////////////////////////////////////////////////
548 549
549 DEF_GM(return new DashingGM;) 550 DEF_GM(return new DashingGM;)
550 DEF_GM(return new Dashing2GM;) 551 DEF_GM(return new Dashing2GM;)
551 DEF_GM(return new Dashing3GM;) 552 DEF_GM(return new Dashing3GM;)
552 DEF_GM(return new Dashing4GM;) 553 DEF_GM(return new Dashing4GM;)
553 DEF_GM(return new Dashing5GM(true);) 554 DEF_GM(return new Dashing5GM(true);)
554 DEF_GM(return new Dashing5GM(false);) 555 DEF_GM(return new Dashing5GM(false);)
OLDNEW
« no previous file with comments | « gm/dashcubics.cpp ('k') | gm/pathcontourstart.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698