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

Side by Side Diff: samplecode/SampleSlides.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 | « 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 sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25); 34 SkPathEffect* corner = SkCornerPathEffect::Create(25);
35 sk_sp<SkPathEffect> compose; 35 SkPathEffect* compose;
36 if (pe) { 36 if (pe) {
37 compose = SkComposePathEffect::Make(sk_ref_sp(pe), corner); 37 compose = SkComposePathEffect::Create(pe, corner);
38 corner->unref();
38 } else { 39 } else {
39 compose = corner; 40 compose = corner;
40 } 41 }
41 paint->setPathEffect(compose); 42 paint->setPathEffect(compose)->unref();
42 } 43 }
43 44
44 static void hair_pe(SkPaint* paint) { 45 static void hair_pe(SkPaint* paint) {
45 paint->setStrokeWidth(0); 46 paint->setStrokeWidth(0);
46 } 47 }
47 48
48 static void hair2_pe(SkPaint* paint) { 49 static void hair2_pe(SkPaint* paint) {
49 paint->setStrokeWidth(0); 50 paint->setStrokeWidth(0);
50 compose_pe(paint); 51 compose_pe(paint);
51 } 52 }
52 53
53 static void stroke_pe(SkPaint* paint) { 54 static void stroke_pe(SkPaint* paint) {
54 paint->setStrokeWidth(12); 55 paint->setStrokeWidth(12);
55 compose_pe(paint); 56 compose_pe(paint);
56 } 57 }
57 58
58 static void dash_pe(SkPaint* paint) { 59 static void dash_pe(SkPaint* paint) {
59 SkScalar inter[] = { 20, 10, 10, 10 }; 60 SkScalar inter[] = { 20, 10, 10, 10 };
60 paint->setStrokeWidth(12); 61 paint->setStrokeWidth(12);
61 paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0) ); 62 paint->setPathEffect(SkDashPathEffect::Create(inter, SK_ARRAY_COUNT(inter),
63 0))->unref();
62 compose_pe(paint); 64 compose_pe(paint);
63 } 65 }
64 66
65 static const int gXY[] = { 67 static const int gXY[] = {
66 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 68 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
67 }; 69 };
68 70
69 static void scale(SkPath* path, SkScalar scale) { 71 static void scale(SkPath* path, SkScalar scale) {
70 SkMatrix m; 72 SkMatrix m;
71 m.setScale(scale, scale); 73 m.setScale(scale, scale);
72 path->transform(m); 74 path->transform(m);
73 } 75 }
74 76
75 static void one_d_pe(SkPaint* paint) { 77 static void one_d_pe(SkPaint* paint) {
76 SkPath path; 78 SkPath path;
77 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); 79 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
78 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) 80 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
79 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); 81 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
80 path.close(); 82 path.close();
81 path.offset(SkIntToScalar(-6), 0); 83 path.offset(SkIntToScalar(-6), 0);
82 scale(&path, 1.5f); 84 scale(&path, 1.5f);
83 85
84 paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0, 86 paint->setPathEffect(SkPath1DPathEffect::Create(path, SkIntToScalar(21), 0,
85 SkPath1DPathEffect::kRotate_St yle)); 87 SkPath1DPathEffect::kRotate_ Style))->unref();
86 compose_pe(paint); 88 compose_pe(paint);
87 } 89 }
88 90
89 typedef void (*PE_Proc)(SkPaint*); 91 typedef void (*PE_Proc)(SkPaint*);
90 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe } ; 92 static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe } ;
91 93
92 static void fill_pe(SkPaint* paint) { 94 static void fill_pe(SkPaint* paint) {
93 paint->setStyle(SkPaint::kFill_Style); 95 paint->setStyle(SkPaint::kFill_Style);
94 paint->setPathEffect(nullptr); 96 paint->setPathEffect(nullptr);
95 } 97 }
96 98
97 static void discrete_pe(SkPaint* paint) { 99 static void discrete_pe(SkPaint* paint) {
98 paint->setPathEffect(SkDiscretePathEffect::Make(10, 4)); 100 paint->setPathEffect(SkDiscretePathEffect::Create(10, 4))->unref();
99 } 101 }
100 102
101 static sk_sp<SkPathEffect> MakeTileEffect() { 103 static SkPathEffect* MakeTileEffect() {
102 SkMatrix m; 104 SkMatrix m;
103 m.setScale(SkIntToScalar(12), SkIntToScalar(12)); 105 m.setScale(SkIntToScalar(12), SkIntToScalar(12));
104 106
105 SkPath path; 107 SkPath path;
106 path.addCircle(0, 0, SkIntToScalar(5)); 108 path.addCircle(0, 0, SkIntToScalar(5));
107 109
108 return SkPath2DPathEffect::Make(m, path); 110 return SkPath2DPathEffect::Create(m, path);
109 } 111 }
110 112
111 static void tile_pe(SkPaint* paint) { 113 static void tile_pe(SkPaint* paint) {
112 paint->setPathEffect(MakeTileEffect()); 114 paint->setPathEffect(MakeTileEffect())->unref();
113 } 115 }
114 116
115 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; 117 static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe };
116 118
117 static void patheffect_slide(SkCanvas* canvas) { 119 static void patheffect_slide(SkCanvas* canvas) {
118 SkPaint paint; 120 SkPaint paint;
119 paint.setAntiAlias(true); 121 paint.setAntiAlias(true);
120 paint.setStyle(SkPaint::kStroke_Style); 122 paint.setStyle(SkPaint::kStroke_Style);
121 123
122 SkPath path; 124 SkPath path;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 p.setXfermode(nullptr); 527 p.setXfermode(nullptr);
526 rastBuilder->addLayer(p); 528 rastBuilder->addLayer(p);
527 } 529 }
528 530
529 #include "SkDiscretePathEffect.h" 531 #include "SkDiscretePathEffect.h"
530 532
531 static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 533 static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
532 { 534 {
533 rastBuilder->addLayer(p); 535 rastBuilder->addLayer(p);
534 536
535 p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3)); 537 p.setPathEffect(SkDiscretePathEffect::Create(SK_Scalar1*4, SK_Scalar1*3))->u nref();
536 p.setXfermodeMode(SkXfermode::kSrcOut_Mode); 538 p.setXfermodeMode(SkXfermode::kSrcOut_Mode);
537 rastBuilder->addLayer(p); 539 rastBuilder->addLayer(p);
538 } 540 }
539 541
540 static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 542 static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
541 { 543 {
542 rastBuilder->addLayer(p); 544 rastBuilder->addLayer(p);
543 545
544 p.setAntiAlias(false); 546 p.setAntiAlias(false);
545 SkLayerRasterizer::Builder rastBuilder2; 547 SkLayerRasterizer::Builder rastBuilder2;
546 r5(&rastBuilder2, p); 548 r5(&rastBuilder2, p);
547 p.setRasterizer(rastBuilder2.detachRasterizer())->unref(); 549 p.setRasterizer(rastBuilder2.detachRasterizer())->unref();
548 p.setXfermodeMode(SkXfermode::kClear_Mode); 550 p.setXfermodeMode(SkXfermode::kClear_Mode);
549 rastBuilder->addLayer(p); 551 rastBuilder->addLayer(p);
550 } 552 }
551 553
552 #include "Sk2DPathEffect.h" 554 #include "Sk2DPathEffect.h"
553 555
554 static sk_sp<SkPathEffect> MakeDotEffect(SkScalar radius, const SkMatrix& matrix ) { 556 static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
555 SkPath path; 557 SkPath path;
556 path.addCircle(0, 0, radius); 558 path.addCircle(0, 0, radius);
557 return SkPath2DPathEffect::Make(matrix, path); 559 return SkPath2DPathEffect::Create(matrix, path);
558 } 560 }
559 561
560 static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 562 static void r7(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
561 { 563 {
562 SkMatrix lattice; 564 SkMatrix lattice;
563 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); 565 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
564 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); 566 lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
565 p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice)); 567 p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
566 rastBuilder->addLayer(p); 568 rastBuilder->addLayer(p);
567 } 569 }
568 570
569 static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 571 static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
570 { 572 {
571 rastBuilder->addLayer(p); 573 rastBuilder->addLayer(p);
572 574
573 SkMatrix lattice; 575 SkMatrix lattice;
574 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); 576 lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
575 lattice.postSkew(SK_Scalar1/3, 0, 0, 0); 577 lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
576 p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice)); 578 p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
577 p.setXfermodeMode(SkXfermode::kClear_Mode); 579 p.setXfermodeMode(SkXfermode::kClear_Mode);
578 rastBuilder->addLayer(p); 580 rastBuilder->addLayer(p);
579 581
580 p.setPathEffect(nullptr); 582 p.setPathEffect(nullptr);
581 p.setXfermode(nullptr); 583 p.setXfermode(nullptr);
582 p.setStyle(SkPaint::kStroke_Style); 584 p.setStyle(SkPaint::kStroke_Style);
583 p.setStrokeWidth(SK_Scalar1); 585 p.setStrokeWidth(SK_Scalar1);
584 rastBuilder->addLayer(p); 586 rastBuilder->addLayer(p);
585 } 587 }
586 588
587 static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) 589 static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p)
588 { 590 {
589 rastBuilder->addLayer(p); 591 rastBuilder->addLayer(p);
590 592
591 SkMatrix lattice; 593 SkMatrix lattice;
592 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); 594 lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
593 lattice.postRotate(SkIntToScalar(30), 0, 0); 595 lattice.postRotate(SkIntToScalar(30), 0, 0);
594 p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice)); 596 p.setPathEffect(SkLine2DPathEffect::Create(SK_Scalar1*2, lattice))->unref();
595 p.setXfermodeMode(SkXfermode::kClear_Mode); 597 p.setXfermodeMode(SkXfermode::kClear_Mode);
596 rastBuilder->addLayer(p); 598 rastBuilder->addLayer(p);
597 599
598 p.setPathEffect(nullptr); 600 p.setPathEffect(nullptr);
599 p.setXfermode(nullptr); 601 p.setXfermode(nullptr);
600 p.setStyle(SkPaint::kStroke_Style); 602 p.setStyle(SkPaint::kStroke_Style);
601 p.setStrokeWidth(SK_Scalar1); 603 p.setStrokeWidth(SK_Scalar1);
602 rastBuilder->addLayer(p); 604 rastBuilder->addLayer(p);
603 } 605 }
604 606
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 712 }
711 713
712 private: 714 private:
713 typedef SampleView INHERITED; 715 typedef SampleView INHERITED;
714 }; 716 };
715 717
716 ////////////////////////////////////////////////////////////////////////////// 718 //////////////////////////////////////////////////////////////////////////////
717 719
718 static SkView* MyFactory() { return new SlideView; } 720 static SkView* MyFactory() { return new SlideView; }
719 static SkViewRegister reg(MyFactory); 721 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