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

Side by Side Diff: gm/dashing.cpp

Issue 706013005: Cherry pick two CLs back to M39 to fix a bug (Closed) Base URL: https://skia.googlesource.com/skia.git@m39
Patch Set: Created 6 years, 1 month 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 | « expectations/gm/ignored-tests.txt ('k') | include/core/SkMatrix.h » ('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 SkPaint p(paint); 17 SkPaint p(paint);
17 18
18 const SkScalar intervals[] = { 19 const SkScalar intervals[] = {
19 SkIntToScalar(on), 20 SkIntToScalar(on),
20 SkIntToScalar(off), 21 SkIntToScalar(off),
21 }; 22 };
22 23
23 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref(); 24 p.setPathEffect(SkDashPathEffect::Create(intervals, 2, phase))->unref();
24 canvas->drawLine(0, 0, finalX, finalY, p); 25 canvas->drawLine(startX, startY, finalX, finalY, p);
25 } 26 }
26 27
27 // 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
28 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is 29 // SkPathMeasure was skipping very small delta-T values (nearlyzero). This is
29 // now fixes, so this giant dash should appear. 30 // now fixes, so this giant dash should appear.
30 static void show_giant_dash(SkCanvas* canvas) { 31 static void show_giant_dash(SkCanvas* canvas) {
31 SkPaint paint; 32 SkPaint paint;
32 33
33 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000)); 34 drawline(canvas, 1, 1, paint, SkIntToScalar(20 * 1000));
34 } 35 }
35 36
37 static void show_zero_len_dash(SkCanvas* canvas) {
38 SkPaint paint;
39
40 drawline(canvas, 2, 2, paint, SkIntToScalar(0));
41 paint.setStyle(SkPaint::kStroke_Style);
42 paint.setStrokeWidth(SkIntToScalar(2));
43 canvas->translate(0, SkIntToScalar(20));
44 drawline(canvas, 4, 4, paint, SkIntToScalar(0));
45 }
46
36 class DashingGM : public skiagm::GM { 47 class DashingGM : public skiagm::GM {
37 public: 48 public:
38 DashingGM() {} 49 DashingGM() {}
39 50
40 protected: 51 protected:
41 virtual uint32_t onGetFlags() const SK_OVERRIDE { 52 virtual uint32_t onGetFlags() const SK_OVERRIDE {
42 return kSkipTiled_Flag; 53 return kSkipTiled_Flag;
43 } 54 }
44 55
45 SkString onShortName() { 56 SkString onShortName() {
(...skipping 27 matching lines...) Expand all
73 84
74 drawline(canvas, gData[data].fOnInterval * scale, 85 drawline(canvas, gData[data].fOnInterval * scale,
75 gData[data].fOffInterval * scale, 86 gData[data].fOffInterval * scale,
76 paint); 87 paint);
77 canvas->translate(0, SkIntToScalar(20)); 88 canvas->translate(0, SkIntToScalar(20));
78 } 89 }
79 } 90 }
80 } 91 }
81 92
82 show_giant_dash(canvas); 93 show_giant_dash(canvas);
94 canvas->translate(0, SkIntToScalar(20));
95 show_zero_len_dash(canvas);
83 } 96 }
84 }; 97 };
85 98
86 /////////////////////////////////////////////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////////////
87 100
88 static void make_unit_star(SkPath* path, int n) { 101 static void make_unit_star(SkPath* path, int n) {
89 SkScalar rad = -SK_ScalarPI / 2; 102 SkScalar rad = -SK_ScalarPI / 2;
90 const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n; 103 const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n;
91 104
92 path->moveTo(0, -SK_Scalar1); 105 path->moveTo(0, -SK_Scalar1);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 402
390 // Case where only the off interval exists on the line. Thus nothing should be drawn 403 // Case where only the off interval exists on the line. Thus nothing should be drawn
391 drawline(canvas, 32, 16, paint, 8.f, 0.f, 40.f); 404 drawline(canvas, 32, 16, paint, 8.f, 0.f, 40.f);
392 canvas->translate(0, SkIntToScalar(20)); 405 canvas->translate(0, SkIntToScalar(20));
393 } 406 }
394 } 407 }
395 }; 408 };
396 409
397 ////////////////////////////////////////////////////////////////////////////// 410 //////////////////////////////////////////////////////////////////////////////
398 411
399 static skiagm::GM* F0(void*) { return new DashingGM; } 412 class Dashing5GM : public skiagm::GM {
400 static skiagm::GM* F1(void*) { return new Dashing2GM; } 413 public:
401 static skiagm::GM* F2(void*) { return new Dashing3GM; } 414 Dashing5GM(bool doAA) : fDoAA(doAA) {}
402 static skiagm::GM* F3(void*) { return new Dashing4GM; }
403 415
404 static skiagm::GMRegistry gR0(F0); 416 protected:
405 static skiagm::GMRegistry gR1(F1); 417 virtual uint32_t onGetFlags() const SK_OVERRIDE { return kAsBench_Flag | kSk ipTiled_Flag; }
406 static skiagm::GMRegistry gR2(F2); 418
407 static skiagm::GMRegistry gR3(F3); 419 virtual SkString onShortName() SK_OVERRIDE {
420 if (fDoAA) {
421 return SkString("dashing5_aa");
422 } else {
423 return SkString("dashing5_bw");
424 }
425 }
426
427 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(400, 200); }
428
429 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
430 static const int kOn = 4;
431 static const int kOff = 4;
432 static const int kIntervalLength = kOn + kOff;
433
434 static const SkColor gColors[kIntervalLength] = {
435 SK_ColorRED,
436 SK_ColorGREEN,
437 SK_ColorBLUE,
438 SK_ColorCYAN,
439 SK_ColorMAGENTA,
440 SK_ColorYELLOW,
441 SK_ColorGRAY,
442 SK_ColorDKGRAY
443 };
444
445 SkPaint paint;
446 paint.setStyle(SkPaint::kStroke_Style);
447
448 paint.setAntiAlias(fDoAA);
449
450 SkMatrix rot;
451 rot.setRotate(90);
452 SkASSERT(rot.rectStaysRect());
453
454 canvas->concat(rot);
455
456 int sign; // used to toggle the direction of the lines
457 int phase = 0;
458
459 for (int x = 0; x < 200; x += 10) {
460 paint.setStrokeWidth(SkIntToScalar(phase+1));
461 paint.setColor(gColors[phase]);
462 sign = (x % 20) ? 1 : -1;
463 drawline(canvas, kOn, kOff, paint,
464 SkIntToScalar(x), -sign * SkIntToScalar(10003),
465 SkIntToScalar(phase),
466 SkIntToScalar(x), sign * SkIntToScalar(10003));
467 phase = (phase + 1) % kIntervalLength;
468 }
469
470 for (int y = -400; y < 0; y += 10) {
471 paint.setStrokeWidth(SkIntToScalar(phase+1));
472 paint.setColor(gColors[phase]);
473 sign = (y % 20) ? 1 : -1;
474 drawline(canvas, kOn, kOff, paint,
475 -sign * SkIntToScalar(10003), SkIntToScalar(y),
476 SkIntToScalar(phase),
477 sign * SkIntToScalar(10003), SkIntToScalar(y));
478 phase = (phase + 1) % kIntervalLength;
479 }
480 }
481
482 private:
483 bool fDoAA;
484 };
485
486 //////////////////////////////////////////////////////////////////////////////
487
488 DEF_GM(return SkNEW(DashingGM);)
489 DEF_GM(return SkNEW(Dashing2GM);)
490 DEF_GM(return SkNEW(Dashing3GM);)
491 DEF_GM(return SkNEW(Dashing4GM);)
492 DEF_GM(return SkNEW_ARGS(Dashing5GM, (true));)
493 DEF_GM(return SkNEW_ARGS(Dashing5GM, (false));)
494
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | include/core/SkMatrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698