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

Side by Side Diff: samplecode/SamplePathEffects.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/SamplePath.cpp ('k') | samplecode/SampleSlides.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 2011 Google Inc. 2 * Copyright 2011 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkView.h" 10 #include "SkView.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkPath.h" 13 #include "SkPath.h"
14 #include "SkRegion.h" 14 #include "SkRegion.h"
15 #include "SkShader.h" 15 #include "SkShader.h"
16 #include "SkUtils.h" 16 #include "SkUtils.h"
17 #include "Sk1DPathEffect.h" 17 #include "Sk1DPathEffect.h"
18 #include "SkCornerPathEffect.h" 18 #include "SkCornerPathEffect.h"
19 #include "SkPathMeasure.h" 19 #include "SkPathMeasure.h"
20 #include "SkRandom.h" 20 #include "SkRandom.h"
21 #include "SkColorPriv.h" 21 #include "SkColorPriv.h"
22 22
23 #define CORNER_RADIUS 12 23 #define CORNER_RADIUS 12
24 24
25 static const int gXY[] = { 25 static const int gXY[] = {
26 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 26 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
27 }; 27 };
28 28
29 static sk_sp<SkPathEffect> make_pe(int flags, SkScalar phase) { 29 static SkPathEffect* make_pe(int flags, SkScalar phase) {
30 if (flags == 1) { 30 if (flags == 1)
31 return SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS)); 31 return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS));
32 }
33 32
34 SkPath path; 33 SkPath path;
35 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); 34 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
36 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) 35 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
37 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); 36 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
38 path.close(); 37 path.close();
39 path.offset(SkIntToScalar(-6), 0); 38 path.offset(SkIntToScalar(-6), 0);
40 39
41 auto outer = SkPath1DPathEffect::Make(path, 12, phase, SkPath1DPathEffect::k Rotate_Style); 40 SkPathEffect* outer = SkPath1DPathEffect::Create(path, 12, phase,
41 SkPath1DPathEffect::kRotate _Style);
42 42
43 if (flags == 2) 43 if (flags == 2)
44 return outer; 44 return outer;
45 45
46 auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS)); 46 SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS ));
47 47
48 return SkComposePathEffect::Make(outer, inner); 48 SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
49 outer->unref();
50 inner->unref();
51 return pe;
49 } 52 }
50 53
51 static sk_sp<SkPathEffect> make_warp_pe(SkScalar phase) { 54 static SkPathEffect* make_warp_pe(SkScalar phase) {
52 SkPath path; 55 SkPath path;
53 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); 56 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
54 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) { 57 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
55 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); 58 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
56 }
57 path.close(); 59 path.close();
58 path.offset(SkIntToScalar(-6), 0); 60 path.offset(SkIntToScalar(-6), 0);
59 61
60 auto outer = SkPath1DPathEffect::Make( 62 SkPathEffect* outer = SkPath1DPathEffect::Create(
61 path, 12, phase, SkPath1DPathEffect::kMorph_Style); 63 path, 12, phase, SkPath1DPathEffect::kMorph_Style);
62 auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS)); 64 SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS ));
63 65
64 return SkComposePathEffect::Make(outer, inner); 66 SkPathEffect* pe = SkComposePathEffect::Create(outer, inner);
67 outer->unref();
68 inner->unref();
69 return pe;
65 } 70 }
66 71
67 /////////////////////////////////////////////////////////// 72 ///////////////////////////////////////////////////////////
68 73
69 #include "SkColorFilter.h" 74 #include "SkColorFilter.h"
70 #include "SkLayerRasterizer.h" 75 #include "SkLayerRasterizer.h"
71 76
72 class TestRastBuilder : public SkLayerRasterizer::Builder { 77 class TestRastBuilder : public SkLayerRasterizer::Builder {
73 public: 78 public:
74 TestRastBuilder() { 79 TestRastBuilder() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 136 }
132 return this->INHERITED::onQuery(evt); 137 return this->INHERITED::onQuery(evt);
133 } 138 }
134 139
135 void onDrawContent(SkCanvas* canvas) override { 140 void onDrawContent(SkCanvas* canvas) override {
136 SkPaint paint; 141 SkPaint paint;
137 142
138 canvas->translate(0, 50); 143 canvas->translate(0, 50);
139 144
140 paint.setColor(SK_ColorBLUE); 145 paint.setColor(SK_ColorBLUE);
141 paint.setPathEffect(make_pe(2, fPhase)); 146 paint.setPathEffect(make_pe(2, fPhase))->unref();
142 canvas->drawPath(fPath, paint); 147 canvas->drawPath(fPath, paint);
143 148
144 canvas->translate(0, 50); 149 canvas->translate(0, 50);
145 150
146 paint.setARGB(0xFF, 0, 0xBB, 0); 151 paint.setARGB(0xFF, 0, 0xBB, 0);
147 paint.setPathEffect(make_pe(3, fPhase)); 152 paint.setPathEffect(make_pe(3, fPhase))->unref();
148 canvas->drawPath(fPath, paint); 153 canvas->drawPath(fPath, paint);
149 154
150 canvas->translate(0, 50); 155 canvas->translate(0, 50);
151 156
152 paint.setARGB(0xFF, 0, 0, 0); 157 paint.setARGB(0xFF, 0, 0, 0);
153 paint.setPathEffect(make_warp_pe(fPhase)); 158 paint.setPathEffect(make_warp_pe(fPhase))->unref();
154 TestRastBuilder testRastBuilder; 159 TestRastBuilder testRastBuilder;
155 paint.setRasterizer(testRastBuilder.detachRasterizer())->unref(); 160 paint.setRasterizer(testRastBuilder.detachRasterizer())->unref();
156 canvas->drawPath(fPath, paint); 161 canvas->drawPath(fPath, paint);
157 } 162 }
158 163
159 bool onAnimate(const SkAnimTimer& timer) override { 164 bool onAnimate(const SkAnimTimer& timer) override {
160 fPhase = timer.scaled(40); 165 fPhase = timer.scaled(40);
161 return true; 166 return true;
162 } 167 }
163 168
164 private: 169 private:
165 typedef SampleView INHERITED; 170 typedef SampleView INHERITED;
166 }; 171 };
167 172
168 ////////////////////////////////////////////////////////////////////////////// 173 //////////////////////////////////////////////////////////////////////////////
169 174
170 static SkView* MyFactory() { return new PathEffectView; } 175 static SkView* MyFactory() { return new PathEffectView; }
171 static SkViewRegister reg(MyFactory); 176 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SamplePath.cpp ('k') | samplecode/SampleSlides.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698