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

Side by Side Diff: samplecode/SampleSlides.cpp

Issue 1813123003: Reland of "switch patheffects over to sk_sp (patchset #5 id:80001 of https://codereview.chromium.or… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move flag into sktypes, so it is visible to both paint and other patheffect clients 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 | « samplecode/SamplePathEffects.cpp ('k') | src/animator/SkDrawPaint.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 13 matching lines...) Expand all
24 /////////////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////////////
25 25
26 #include "Sk1DPathEffect.h" 26 #include "Sk1DPathEffect.h"
27 #include "Sk2DPathEffect.h" 27 #include "Sk2DPathEffect.h"
28 #include "SkCornerPathEffect.h" 28 #include "SkCornerPathEffect.h"
29 #include "SkDashPathEffect.h" 29 #include "SkDashPathEffect.h"
30 #include "SkDiscretePathEffect.h" 30 #include "SkDiscretePathEffect.h"
31 31
32 static void compose_pe(SkPaint* paint) { 32 static void compose_pe(SkPaint* paint) {
33 SkPathEffect* pe = paint->getPathEffect(); 33 SkPathEffect* pe = paint->getPathEffect();
34 SkPathEffect* corner = SkCornerPathEffect::Create(25); 34 sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25);
35 SkPathEffect* compose; 35 sk_sp<SkPathEffect> compose;
36 if (pe) { 36 if (pe) {
37 compose = SkComposePathEffect::Create(pe, corner); 37 compose = SkComposePathEffect::Make(sk_ref_sp(pe), corner);
38 corner->unref();
39 } else { 38 } else {
40 compose = corner; 39 compose = corner;
41 } 40 }
42 paint->setPathEffect(compose)->unref(); 41 paint->setPathEffect(compose);
43 } 42 }
44 43
45 static void hair_pe(SkPaint* paint) { 44 static void hair_pe(SkPaint* paint) {
46 paint->setStrokeWidth(0); 45 paint->setStrokeWidth(0);
47 } 46 }
48 47
49 static void hair2_pe(SkPaint* paint) { 48 static void hair2_pe(SkPaint* paint) {
50 paint->setStrokeWidth(0); 49 paint->setStrokeWidth(0);
51 compose_pe(paint); 50 compose_pe(paint);
52 } 51 }
53 52
54 static void stroke_pe(SkPaint* paint) { 53 static void stroke_pe(SkPaint* paint) {
55 paint->setStrokeWidth(12); 54 paint->setStrokeWidth(12);
56 compose_pe(paint); 55 compose_pe(paint);
57 } 56 }
58 57
59 static void dash_pe(SkPaint* paint) { 58 static void dash_pe(SkPaint* paint) {
60 SkScalar inter[] = { 20, 10, 10, 10 }; 59 SkScalar inter[] = { 20, 10, 10, 10 };
61 paint->setStrokeWidth(12); 60 paint->setStrokeWidth(12);
62 paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter), 61 paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0) );
63 0))->unref();
64 compose_pe(paint); 62 compose_pe(paint);
65 } 63 }
66 64
67 static const int gXY[] = { 65 static const int gXY[] = {
68 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 66 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
69 }; 67 };
70 68
71 static void scale(SkPath* path, SkScalar scale) { 69 static void scale(SkPath* path, SkScalar scale) {
72 SkMatrix m; 70 SkMatrix m;
73 m.setScale(scale, scale); 71 m.setScale(scale, scale);
74 path->transform(m); 72 path->transform(m);
75 } 73 }
76 74
77 static void one_d_pe(SkPaint* paint) { 75 static void one_d_pe(SkPaint* paint) {
78 SkPath path; 76 SkPath path;
79 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); 77 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
80 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) 78 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
81 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); 79 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
82 path.close(); 80 path.close();
83 path.offset(SkIntToScalar(-6), 0); 81 path.offset(SkIntToScalar(-6), 0);
84 scale(&path, 1.5f); 82 scale(&path, 1.5f);
85 83
86 paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0, 84 paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0,
87 SkPath1DPathEffect::kRotate_ Style))->unref(); 85 SkPath1DPathEffect::kRotate_St yle));
88 compose_pe(paint); 86 compose_pe(paint);
89 } 87 }
90 88
91 typedef void (*PE_Proc)(SkPaint*); 89 typedef void (*PE_Proc)(SkPaint*);
92 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe } ; 90 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe } ;
93 91
94 static void fill_pe(SkPaint* paint) { 92 static void fill_pe(SkPaint* paint) {
95 paint->setStyle(SkPaint::kFill_Style); 93 paint->setStyle(SkPaint::kFill_Style);
96 paint->setPathEffect(nullptr); 94 paint->setPathEffect(nullptr);
97 } 95 }
98 96
99 static void discrete_pe(SkPaint* paint) { 97 static void discrete_pe(SkPaint* paint) {
100 paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref(); 98 paint->setPathEffect(SkDiscretePathEffect::Make(10, 4));
101 } 99 }
102 100
103 static SkPathEffect* MakeTileEffect() { 101 static sk_sp<SkPathEffect> MakeTileEffect() {
104 SkMatrix m; 102 SkMatrix m;
105 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); 103 m.setScale(SkIntToScalar(12), SkIntToScalar(12));
106 104
107 SkPath path; 105 SkPath path;
108 path.addCircle(0, 0, SkIntToScalar(5)); 106 path.addCircle(0, 0, SkIntToScalar(5));
109 107
110 return SkPath2DPathEffect::Create(m, path); 108 return SkPath2DPathEffect::Make(m, path);
111 } 109 }
112 110
113 static void tile_pe(SkPaint* paint) { 111 static void tile_pe(SkPaint* paint) {
114 paint->setPathEffect(MakeTileEffect())->unref(); 112 paint->setPathEffect(MakeTileEffect());
115 } 113 }
116 114
117 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; 115 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe };
118 116
119 static void patheffect_slide(SkCanvas* canvas) { 117 static void patheffect_slide(SkCanvas* canvas) {
120 SkPaint paint; 118 SkPaint paint;
121 paint.setAntiAlias(true); 119 paint.setAntiAlias(true);
122 paint.setStyle(SkPaint::kStroke_Style); 120 paint.setStyle(SkPaint::kStroke_Style);
123 121
124 SkPath path; 122 SkPath path;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 p.setXfermode(nullptr); 525 p.setXfermode(nullptr);
528 rastBuilder->addLayer(p); 526 rastBuilder->addLayer(p);
529 } 527 }
530 528
531 #include "SkDiscretePathEffect.h" 529 #include "SkDiscretePathEffect.h"
532 530
533 static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 531 static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
534 { 532 {
535 rastBuilder->addLayer(p); 533 rastBuilder->addLayer(p);
536 534
537 p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->u nref(); 535 p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3));
538 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); 536 p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
539 rastBuilder->addLayer(p); 537 rastBuilder->addLayer(p);
540 } 538 }
541 539
542 static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 540 static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
543 { 541 {
544 rastBuilder->addLayer(p); 542 rastBuilder->addLayer(p);
545 543
546 p.setAntiAlias(false); 544 p.setAntiAlias(false);
547 SkLayerRasterizer::Builder rastBuilder2; 545 SkLayerRasterizer::Builder rastBuilder2;
548 r5(&rastBuilder2, p); 546 r5(&rastBuilder2, p);
549 p.setRasterizer(rastBuilder2.detachRasterizer())->unref(); 547 p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
550 p.setXfermodeMode(SkXfermode::kClear_Mode); 548 p.setXfermodeMode(SkXfermode::kClear_Mode);
551 rastBuilder->addLayer(p); 549 rastBuilder->addLayer(p);
552 } 550 }
553 551
554 #include "Sk2DPathEffect.h" 552 #include "Sk2DPathEffect.h"
555 553
556 static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) { 554 static sk_sp<SkPathEffect> MakeDotEffect(SkScalar radius, const SkMatrix& matrix ) {
557 SkPath path; 555 SkPath path;
558 path.addCircle(0, 0, radius); 556 path.addCircle(0, 0, radius);
559 return SkPath2DPathEffect::Create(matrix, path); 557 return SkPath2DPathEffect::Make(matrix, path);
560 } 558 }
561 559
562 static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 560 static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
563 { 561 {
564 SkMatrix lattice; 562 SkMatrix lattice;
565 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); 563 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
566 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); 564 lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
567 p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref(); 565 p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice));
568 rastBuilder->addLayer(p); 566 rastBuilder->addLayer(p);
569 } 567 }
570 568
571 static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 569 static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
572 { 570 {
573 rastBuilder->addLayer(p); 571 rastBuilder->addLayer(p);
574 572
575 SkMatrix lattice; 573 SkMatrix lattice;
576 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); 574 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
577 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); 575 lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
578 p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref(); 576 p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice));
579 p.setXfermodeMode(SkXfermode::kClear_Mode); 577 p.setXfermodeMode(SkXfermode::kClear_Mode);
580 rastBuilder->addLayer(p); 578 rastBuilder->addLayer(p);
581 579
582 p.setPathEffect(nullptr); 580 p.setPathEffect(nullptr);
583 p.setXfermode(nullptr); 581 p.setXfermode(nullptr);
584 p.setStyle(SkPaint::kStroke_Style); 582 p.setStyle(SkPaint::kStroke_Style);
585 p.setStrokeWidth(SK_Scalar1); 583 p.setStrokeWidth(SK_Scalar1);
586 rastBuilder->addLayer(p); 584 rastBuilder->addLayer(p);
587 } 585 }
588 586
589 static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 587 static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
590 { 588 {
591 rastBuilder->addLayer(p); 589 rastBuilder->addLayer(p);
592 590
593 SkMatrix lattice; 591 SkMatrix lattice;
594 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); 592 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
595 lattice.postRotate(SkIntToScalar(30), 0, 0); 593 lattice.postRotate(SkIntToScalar(30), 0, 0);
596 p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref(); 594 p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice));
597 p.setXfermodeMode(SkXfermode::kClear_Mode); 595 p.setXfermodeMode(SkXfermode::kClear_Mode);
598 rastBuilder->addLayer(p); 596 rastBuilder->addLayer(p);
599 597
600 p.setPathEffect(nullptr); 598 p.setPathEffect(nullptr);
601 p.setXfermode(nullptr); 599 p.setXfermode(nullptr);
602 p.setStyle(SkPaint::kStroke_Style); 600 p.setStyle(SkPaint::kStroke_Style);
603 p.setStrokeWidth(SK_Scalar1); 601 p.setStrokeWidth(SK_Scalar1);
604 rastBuilder->addLayer(p); 602 rastBuilder->addLayer(p);
605 } 603 }
606 604
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } 710 }
713 711
714 private: 712 private:
715 typedef SampleView INHERITED; 713 typedef SampleView INHERITED;
716 }; 714 };
717 715
718 ////////////////////////////////////////////////////////////////////////////// 716 //////////////////////////////////////////////////////////////////////////////
719 717
720 static SkView* MyFactory() { return new SlideView; } 718 static SkView* MyFactory() { return new SlideView; }
721 static SkViewRegister reg(MyFactory); 719 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SamplePathEffects.cpp ('k') | src/animator/SkDrawPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698