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

Side by Side Diff: site/user/api/skpaint.md

Issue 1910593005: skia.org: Update all fiddles for fiddle 2.0 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 | « site/user/api/skcanvas.md ('k') | site/user/tips.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 SkPaint 1 SkPaint
2 ======= 2 =======
3 3
4 *color, stroke, font, effects* 4 *color, stroke, font, effects*
5 5
6 - [SkXfermode](#SkXfermode) - transfer modes 6 - [SkXfermode](#SkXfermode) - transfer modes
7 - [ShShader](#ShShader) - gradients and patterns 7 - [ShShader](#ShShader) - gradients and patterns
8 - [SkMaskFilter](#SkMaskFilter) - modifications to the alpha mask 8 - [SkMaskFilter](#SkMaskFilter) - modifications to the alpha mask
9 - [SkColorFilter](#SkColorFilter) - modify the source color before applying th e 9 - [SkColorFilter](#SkColorFilter) - modify the source color before applying th e
10 - [SkPathEffect](#SkPathEffect) - modify to the geometry before it 10 - [SkPathEffect](#SkPathEffect) - modify to the geometry before it
11 generates an alpha mask. 11 generates an alpha mask.
12 12
13 Anytime you draw something in Skia, and want to specify what color it 13 Anytime you draw something in Skia, and want to specify what color it
14 is, or how it blends with the background, or what style or font to 14 is, or how it blends with the background, or what style or font to
15 draw it in, you specify those attributes in a paint. 15 draw it in, you specify those attributes in a paint.
16 16
17 Unlike `SkCanvas`, paints do not maintain an internal stack of state 17 Unlike `SkCanvas`, paints do not maintain an internal stack of state
18 (i.e. there is no save/restore on a paint). However, paints are 18 (i.e. there is no save/restore on a paint). However, paints are
19 relatively light-weight, so the client may create and maintain any 19 relatively light-weight, so the client may create and maintain any
20 number of paint objects, each set up for a particular use. Factoring 20 number of paint objects, each set up for a particular use. Factoring
21 all of these color and stylistic attribute out of the canvas state, 21 all of these color and stylistic attributes out of the canvas state,
22 and into (multiple) paint objects, allows canvas' save/restore to be 22 and into (multiple) paint objects, allows canvas' save/restore to be
23 that much more efficient, as all they have to do is maintain the stack 23 that much more efficient, as all they have to do is maintain the stack
24 of matrix and clip settings. 24 of matrix and clip settings.
25 25
26 <!--?prettify lang=cc?--> 26 <!--?prettify lang=cc?-->
27 27
28 void draw(SkCanvas* canvas) { 28 void draw(SkCanvas* canvas) {
29 canvas->clear(SK_ColorWHITE); 29 canvas->clear(SK_ColorWHITE);
30 30
31 SkPaint paint1, paint2, paint3; 31 SkPaint paint1, paint2, paint3;
(...skipping 13 matching lines...) Expand all
45 paint3.setAntiAlias(true); 45 paint3.setAntiAlias(true);
46 paint3.setColor(SkColorSetRGB(136, 136, 136)); 46 paint3.setColor(SkColorSetRGB(136, 136, 136));
47 paint3.setTextScaleX(SkFloatToScalar(1.5f)); 47 paint3.setTextScaleX(SkFloatToScalar(1.5f));
48 48
49 const char text[] = "Skia!"; 49 const char text[] = "Skia!";
50 canvas->drawText(text, strlen(text), 20.0f, 64.0f, paint1); 50 canvas->drawText(text, strlen(text), 20.0f, 64.0f, paint1);
51 canvas->drawText(text, strlen(text), 20.0f, 144.0f, paint2); 51 canvas->drawText(text, strlen(text), 20.0f, 144.0f, paint2);
52 canvas->drawText(text, strlen(text), 20.0f, 224.0f, paint3); 52 canvas->drawText(text, strlen(text), 20.0f, 224.0f, paint3);
53 } 53 }
54 54
55 <a href="https://fiddle.skia.org/c/c4cfc71ed9232dac9c0d6518311b386e"> 55 <a href='https://fiddle.skia.org/c/@skpaint_skia'><img
56 <img src="https://fiddle.skia.org/i/c4cfc71ed9232dac9c0d6518311b386e_raster.png" ></a> 56 src='https://fiddle.skia.org/c/@skpaint_skia_raster.png'></a>
57 57
58 This shows three different paints, each set up to draw in a different 58 This shows three different paints, each set up to draw in a different
59 style. Now the caller can intermix these paints freely, either using 59 style. Now the caller can intermix these paints freely, either using
60 them as is, or modifying them as the drawing proceeds. 60 them as is, or modifying them as the drawing proceeds.
61 61
62 <!--?prettify lang=cc?--> 62 <!--?prettify lang=cc?-->
63 63
64 SkPaint paint1, paint2, paint3; 64 SkPaint paint1, paint2, paint3;
65 paint2.setStyle(SkPaint::kStroke_Style); 65 paint2.setStyle(SkPaint::kStroke_Style);
66 paint2.setStrokeWidth(3); 66 paint2.setStrokeWidth(3);
67 paint3.setAntiAlias(true); 67 paint3.setAntiAlias(true);
68 paint3.setColor(SK_ColorRED); 68 paint3.setColor(SK_ColorRED);
69 paint3.setTextSize(80); 69 paint3.setTextSize(80);
70 70
71 canvas->drawRect(SkRect::MakeXYWH(10,10,60,20), paint1); 71 canvas->drawRect(SkRect::MakeXYWH(10,10,60,20), paint1);
72 canvas->drawRect(SkRect::MakeXYWH(80,10,60,20), paint2); 72 canvas->drawRect(SkRect::MakeXYWH(80,10,60,20), paint2);
73 73
74 paint2.setStrokeWidth(SkIntToScalar(5)); 74 paint2.setStrokeWidth(SkIntToScalar(5));
75 canvas->drawOval(SkRect::MakeXYWH(150,10,60,20), paint2); 75 canvas->drawOval(SkRect::MakeXYWH(150,10,60,20), paint2);
76 76
77 canvas->drawText("SKIA", 4, 20, 120, paint3); 77 canvas->drawText("SKIA", 4, 20, 120, paint3);
78 paint3.setColor(SK_ColorBLUE); 78 paint3.setColor(SK_ColorBLUE);
79 canvas->drawText("SKIA", 4, 20, 220, paint3); 79 canvas->drawText("SKIA", 4, 20, 220, paint3);
80 80
81 <a href="https://fiddle.skia.org/c/5203b17103f487dd33965b4211d80956"> 81 <a href='https://fiddle.skia.org/c/@skpaint_mix'><img
82 <img src="https://fiddle.skia.org/i/5203b17103f487dd33965b4211d80956_raster.png" ></a> 82 src='https://fiddle.skia.org/c/@skpaint_mix_raster.png'></a>
83 83
84 Beyond simple attributes such as color, strokes, and text values, 84 Beyond simple attributes such as color, strokes, and text values,
85 paints support effects. These are subclasses of different aspects of 85 paints support effects. These are subclasses of different aspects of
86 the drawing pipeline, that when referenced by a paint (each of them is 86 the drawing pipeline, that when referenced by a paint (each of them is
87 reference-counted), are called to override some part of the drawing 87 reference-counted), are called to override some part of the drawing
88 pipeline. 88 pipeline.
89 89
90 For example, to draw using a gradient instead of a single color, 90 For example, to draw using a gradient instead of a single color,
91 assign a SkShader to the paint. 91 assign a SkShader to the paint.
92 92
93 <!--?prettify lang=cc?--> 93 <!--?prettify lang=cc?-->
94 94
95 SkPoint points[2] = { 95 void draw(SkCanvas* canvas) {
96 SkPoint::Make(0.0f, 0.0f), 96 SkPoint points[2] = {
97 SkPoint::Make(256.0f, 256.0f) 97 SkPoint::Make(0.0f, 0.0f),
98 }; 98 SkPoint::Make(256.0f, 256.0f)
99 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; 99 };
100 SkShader* shader = 100 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
101 SkGradientShader::CreateLinear( 101 SkPaint paint;
102 points, colors, nullptr, 2, 102 paint.setShader(SkGradientShader::MakeLinear(
103 SkShader::kClamp_TileMode, 0, nullptr); 103 points, colors, nullptr, 2,
104 SkPaint paint; 104 SkShader::kClamp_TileMode, 0, nullptr));
105 paint.setShader(shader); 105 canvas->drawPaint(paint);
106 shader->unref(); 106 }
107 canvas->drawPaint(paint);
108 107
109 <a href="https://fiddle.skia.org/c/f91b5310d57744a5a1475b7e47d4a172"> 108 <a href='https://fiddle.skia.org/c/@skpaint_shader'><img
110 <img src="https://fiddle.skia.org/i/f91b5310d57744a5a1475b7e47d4a172_raster.png" ></a> 109 src='https://fiddle.skia.org/c/@skpaint_shader_raster.png'></a>
111 110
112 Now, anything drawn with that paint will be drawn with the gradient 111 Now, anything drawn with that paint will be drawn with the gradient
113 specified in the call to `CreateLinear()`. The shader object that is 112 specified in the call to `MakeLinear()`. The shader object that is
114 returned is reference-counted. Whenever any effects object, like a 113 returned is reference-counted. Whenever any effects object, like a
115 shader, is assigned to a paint, its reference-count is increased by 114 shader, is assigned to a paint, its reference-count is increased by
116 the paint. To balance this, the caller in the above example calls 115 the paint. To balance this, the caller in the above example calls
117 `unref()` on the shader once it has assigned it to the paint. Now the 116 `unref()` on the shader once it has assigned it to the paint. Now the
118 paint is the only "owner" of that shader, and it will automatically 117 paint is the only "owner" of that shader, and it will automatically
119 call `unref()` on the shader when either the paint goes out of scope, or 118 call `unref()` on the shader when either the paint goes out of scope, or
120 if another shader (or null) is assigned to it. 119 if another shader (or null) is assigned to it.
121 120
122 There are 6 types of effects that can be assigned to a paint: 121 There are 6 types of effects that can be assigned to a paint:
123 122
(...skipping 25 matching lines...) Expand all
149 SkXfermode 148 SkXfermode
150 ---------- 149 ----------
151 150
152 The following example demonstrates all of the Skia's standard transfer 151 The following example demonstrates all of the Skia's standard transfer
153 modes. In this example the source is a solid magenta color with a 152 modes. In this example the source is a solid magenta color with a
154 horizontal alpha gradient and the destination is a solid cyan color 153 horizontal alpha gradient and the destination is a solid cyan color
155 with a vertical alpha gradient. 154 with a vertical alpha gradient.
156 155
157 <!--?prettify lang=cc?--> 156 <!--?prettify lang=cc?-->
158 157
159 SkXfermode::Mode modes[] = { 158 void draw(SkCanvas* canvas) {
160 SkXfermode::kClear_Mode, 159 SkXfermode::Mode modes[] = {
161 SkXfermode::kSrc_Mode, 160 SkXfermode::kClear_Mode,
162 SkXfermode::kDst_Mode, 161 SkXfermode::kSrc_Mode,
163 SkXfermode::kSrcOver_Mode, 162 SkXfermode::kDst_Mode,
164 SkXfermode::kDstOver_Mode, 163 SkXfermode::kSrcOver_Mode,
165 SkXfermode::kSrcIn_Mode, 164 SkXfermode::kDstOver_Mode,
166 SkXfermode::kDstIn_Mode, 165 SkXfermode::kSrcIn_Mode,
167 SkXfermode::kSrcOut_Mode, 166 SkXfermode::kDstIn_Mode,
168 SkXfermode::kDstOut_Mode, 167 SkXfermode::kSrcOut_Mode,
169 SkXfermode::kSrcATop_Mode, 168 SkXfermode::kDstOut_Mode,
170 SkXfermode::kDstATop_Mode, 169 SkXfermode::kSrcATop_Mode,
171 SkXfermode::kXor_Mode, 170 SkXfermode::kDstATop_Mode,
172 SkXfermode::kPlus_Mode, 171 SkXfermode::kXor_Mode,
173 SkXfermode::kModulate_Mode, 172 SkXfermode::kPlus_Mode,
174 SkXfermode::kScreen_Mode, 173 SkXfermode::kModulate_Mode,
175 SkXfermode::kOverlay_Mode, 174 SkXfermode::kScreen_Mode,
176 SkXfermode::kDarken_Mode, 175 SkXfermode::kOverlay_Mode,
177 SkXfermode::kLighten_Mode, 176 SkXfermode::kDarken_Mode,
178 SkXfermode::kColorDodge_Mode, 177 SkXfermode::kLighten_Mode,
179 SkXfermode::kColorBurn_Mode, 178 SkXfermode::kColorDodge_Mode,
180 SkXfermode::kHardLight_Mode, 179 SkXfermode::kColorBurn_Mode,
181 SkXfermode::kSoftLight_Mode, 180 SkXfermode::kHardLight_Mode,
182 SkXfermode::kDifference_Mode, 181 SkXfermode::kSoftLight_Mode,
183 SkXfermode::kExclusion_Mode, 182 SkXfermode::kDifference_Mode,
184 SkXfermode::kMultiply_Mode, 183 SkXfermode::kExclusion_Mode,
185 SkXfermode::kHue_Mode, 184 SkXfermode::kMultiply_Mode,
186 SkXfermode::kSaturation_Mode, 185 SkXfermode::kHue_Mode,
187 SkXfermode::kColor_Mode, 186 SkXfermode::kSaturation_Mode,
188 SkXfermode::kLuminosity_Mode, 187 SkXfermode::kColor_Mode,
189 }; 188 SkXfermode::kLuminosity_Mode,
190 SkRect rect = SkRect::MakeWH(64.0f, 64.0f); 189 };
191 SkPaint text, stroke, src, dst; 190 SkRect rect = SkRect::MakeWH(64.0f, 64.0f);
192 stroke.setStyle(SkPaint::kStroke_Style); 191 SkPaint text, stroke, src, dst;
193 text.setTextSize(24.0f); 192 stroke.setStyle(SkPaint::kStroke_Style);
194 text.setAntiAlias(true); 193 text.setTextSize(24.0f);
195 SkPoint srcPoints[2] = { 194 text.setAntiAlias(true);
196 SkPoint::Make(0.0f, 0.0f), 195 SkPoint srcPoints[2] = {
197 SkPoint::Make(64.0f, 0.0f) 196 SkPoint::Make(0.0f, 0.0f),
198 }; 197 SkPoint::Make(64.0f, 0.0f)
199 SkColor srcColors[2] = { 198 };
200 SK_ColorMAGENTA & 0x00FFFFFF, 199 SkColor srcColors[2] = {
201 SK_ColorMAGENTA}; 200 SK_ColorMAGENTA & 0x00FFFFFF,
202 SkAutoTUnref<SkShader> srcShader( 201 SK_ColorMAGENTA};
203 SkGradientShader::CreateLinear( 202 src.setShader(SkGradientShader::MakeLinear(
204 srcPoints, srcColors, nullptr, 2, 203 srcPoints, srcColors, nullptr, 2,
205 SkShader::kClamp_TileMode, 0, nullptr)); 204 SkShader::kClamp_TileMode, 0, nullptr));
206 src.setShader(srcShader);
207 205
208 SkPoint dstPoints[2] = { 206 SkPoint dstPoints[2] = {
209 SkPoint::Make(0.0f, 0.0f), 207 SkPoint::Make(0.0f, 0.0f),
210 SkPoint::Make(0.0f, 64.0f) 208 SkPoint::Make(0.0f, 64.0f)
211 }; 209 };
212 SkColor dstColors[2] = { 210 SkColor dstColors[2] = {
213 SK_ColorCYAN & 0x00FFFFFF, 211 SK_ColorCYAN & 0x00FFFFFF,
214 SK_ColorCYAN}; 212 SK_ColorCYAN};
215 SkAutoTUnref<SkShader> dstShader( 213 dst.setShader(SkGradientShader::MakeLinear(
216 SkGradientShader::CreateLinear( 214 dstPoints, dstColors, nullptr, 2,
217 dstPoints, dstColors, nullptr, 2, 215 SkShader::kClamp_TileMode, 0, nullptr));
218 SkShader::kClamp_TileMode, 0, nullptr)); 216 canvas->clear(SK_ColorWHITE);
219 dst.setShader(dstShader); 217 size_t N = sizeof(modes) / sizeof(modes[0]);
220 canvas->clear(SK_ColorWHITE); 218 size_t K = (N - 1) / 3 + 1;
221 size_t N = sizeof(modes) / sizeof(modes[0]); 219 SkASSERT(K * 64 == 640); // tall enough
222 size_t K = (N - 1) / 3 + 1; 220 for (size_t i = 0; i < N; ++i) {
223 SkASSERT(K * 64 == 640); // tall enough 221 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
224 for (size_t i = 0; i < N; ++i) { 222 canvas->translate(192.0f * (i / K), 64.0f * (i % K));
225 SkAutoCanvasRestore autoCanvasRestore(canvas, true); 223 const char* desc = SkXfermode::ModeName(modes[i]);
226 canvas->translate(192.0f * (i / K), 64.0f * (i % K)); 224 canvas->drawText(desc, strlen(desc), 68.0f, 30.0f, text);
227 const char* desc = SkXfermode::ModeName(modes[i]); 225 canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f));
228 canvas->drawText(desc, strlen(desc), 68.0f, 30.0f, text); 226 canvas->drawColor(SK_ColorLTGRAY);
229 canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f)); 227 (void)canvas->saveLayer(nullptr, nullptr);
230 canvas->drawColor(SK_ColorLTGRAY); 228 canvas->clear(SK_ColorTRANSPARENT);
231 (void)canvas->saveLayer(nullptr, nullptr); 229 canvas->drawPaint(dst);
232 canvas->clear(SK_ColorTRANSPARENT); 230 src.setXfermodeMode(modes[i]);
233 canvas->drawPaint(dst); 231 canvas->drawPaint(src);
234 src.setXfermodeMode(modes[i]); 232 canvas->drawRect(rect, stroke);
235 canvas->drawPaint(src); 233 }
236 canvas->drawRect(rect, stroke);
237 } 234 }
238 235
239 <a href="https://fiddle.skia.org/c/0a2392be5adf339ce6537799f2807f3c"><img src="h ttps://fiddle.skia.org/i/0a2392be5adf339ce6537799f2807f3c_raster.png" alt=""></a > 236 <a href='https://fiddle.skia.org/c/@skpaint_xfer'><img
237 src='https://fiddle.skia.org/c/@skpaint_xfer_raster.png'></a>
240 238
241 <span id="ShShader"></span> 239 <span id="ShShader"></span>
242 240
243 ShShader 241 ShShader
244 -------- 242 --------
245 243
246 Several shaders are defined (besides the linear gradient already mentioned): 244 Several shaders are defined (besides the linear gradient already mentioned):
247 245
248 * Bitmap Shader 246 * Bitmap Shader
249 247
250 <!--?prettify lang=cc?--> 248 <!--?prettify lang=cc?-->
251 249
252 canvas->clear(SK_ColorWHITE); 250 canvas->clear(SK_ColorWHITE);
253 SkMatrix matrix; 251 SkMatrix matrix;
254 matrix.setScale(0.75f, 0.75f); 252 matrix.setScale(0.75f, 0.75f);
255 matrix.preRotate(30.0f); 253 matrix.preRotate(30.0f);
256 SkShader* shader =
257 SkShader::CreateBitmapShader(
258 source,
259 SkShader::kRepeat_TileMode ,
260 SkShader::kRepeat_TileMode ,
261 &matrix);
262 SkPaint paint; 254 SkPaint paint;
263 paint.setShader(shader); 255 paint.setShader(SkShader::MakeBitmapShader(source,
264 shader->unref(); 256 SkShader::kRepeat_TileMode,
257 SkShader::kRepeat_TileMode,
258 &matrix));
265 canvas->drawPaint(paint); 259 canvas->drawPaint(paint);
266 260
267 <a href="https://fiddle.skia.org/c/0e8d08e0a0b342e9e45c364d0e5cea8a"> 261 <a href='https://fiddle.skia.org/c/@skpaint_bitmap_shader'><img
268 <img src="https://fiddle.skia.org/i/0e8d08e0a0b342e9e45c364d0e5cea8a_raster. png"></a> 262 src='https://fiddle.skia.org/c/@skpaint_bitmap_shader_raster.png'></a>
269 263
270 * Radial Gradient Shader 264 * Radial Gradient Shader
271 265
272 <!--?prettify lang=cc?--> 266 <!--?prettify lang=cc?-->
273 267
274 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; 268 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
275 SkShader* shader =
276 SkGradientShader::CreateRadial(
277 SkPoint::Make(128.0f, 128.0f), 180.0f,
278 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullpt r);
279 SkPaint paint; 269 SkPaint paint;
280 paint.setShader(shader); 270 paint.setShader(SkGradientShader::MakeRadial(
281 shader->unref(); 271 SkPoint::Make(128.0f, 128.0f), 180.0f,
272 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr));
282 canvas->drawPaint(paint); 273 canvas->drawPaint(paint);
283 274
284 <a href="https://fiddle.skia.org/c/601abd2819e38365900bf62286986024"> 275 <a href='https://fiddle.skia.org/c/@skpaint_radial'><img
285 <img src="https://fiddle.skia.org/i/601abd2819e38365900bf62286986024_raster. png"></a> 276 src='https://fiddle.skia.org/c/@skpaint_radial_raster.png'></a>
286 277
287 * Two-Point Conical Gradient Shader 278 * Two-Point Conical Gradient Shader
288 279
289 <!--?prettify lang=cc?--> 280 <!--?prettify lang=cc?-->
290 281
291 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; 282 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
292 SkShader* shader =
293 SkGradientShader::CreateTwoPointConical(
294 SkPoint::Make(128.0f, 128.0f), 128.0f,
295 SkPoint::Make(128.0f, 16.0f), 16.0f,
296 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullp tr);
297 SkPaint paint; 283 SkPaint paint;
298 paint.setShader(shader); 284 paint.setShader(SkGradientShader::MakeTwoPointConical(
299 shader->unref(); 285 SkPoint::Make(128.0f, 128.0f), 128.0f,
286 SkPoint::Make(128.0f, 16.0f), 16.0f,
287 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr));
300 canvas->drawPaint(paint); 288 canvas->drawPaint(paint);
301 289
302 <a href="https://fiddle.skia.org/c/991f7d67ff1ccebd6c2c4fab18a76edc"> 290 <a href='https://fiddle.skia.org/c/@skpaint_2pt'><img
303 <img src="https://fiddle.skia.org/i/991f7d67ff1ccebd6c2c4fab18a76edc_raster. png"></a> 291 src='https://fiddle.skia.org/c/@skpaint_2pt_raster.png'></a>
304 292
305 293
306 * Sweep Gradient Shader 294 * Sweep Gradient Shader
307 295
308 <!--?prettify lang=cc?--> 296 <!--?prettify lang=cc?-->
309 297
310 SkColor colors[4] = { 298 SkColor colors[4] = {
311 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; 299 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN};
312 SkShader* shader =
313 SkGradientShader::CreateSweep(
314 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr);
315 SkPaint paint; 300 SkPaint paint;
316 paint.setShader(shader); 301 paint.setShader(SkGradientShader::MakeSweep(
317 shader->unref(); 302 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr));
318 canvas->drawPaint(paint); 303 canvas->drawPaint(paint);
319 304
320 <a href="https://fiddle.skia.org/c/cee9d1831f6679c3d88170f857995d12"> 305 <a href='https://fiddle.skia.org/c/@skpaint_sweep'><img
321 <img src="https://fiddle.skia.org/i/cee9d1831f6679c3d88170f857995d12_raster. png"></a> 306 src='https://fiddle.skia.org/c/@skpaint_sweep_raster.png'></a>
322 307
323 * Fractal Perlin Noise Shader 308 * Fractal Perlin Noise Shader
324 309
325 <!--?prettify lang=cc?--> 310 <!--?prettify lang=cc?-->
326 311
327 canvas->clear(SK_ColorWHITE); 312 canvas->clear(SK_ColorWHITE);
328 SkShader* shader = SkPerlinNoiseShader::CreateFractalNoise(
329 0.05f, 0.05f, 4, 0.0f, nullptr);
330 SkPaint paint; 313 SkPaint paint;
331 paint.setShader(shader); 314 paint.setShader(SkPerlinNoiseShader::MakeFractalNoise(
332 shader->unref(); 315 0.05f, 0.05f, 4, 0.0f, nullptr));
333 canvas->drawPaint(paint); 316 canvas->drawPaint(paint);
334 317
335 <a href="https://fiddle.skia.org/c/cc45c5349c3b31f97da7c1af7f84162a"> 318 <a href='https://fiddle.skia.org/c/@skpaint_perlin'><img
336 <img src="https://fiddle.skia.org/i/cc45c5349c3b31f97da7c1af7f84162a_raster. png"></a> 319 src='https://fiddle.skia.org/c/@skpaint_perlin_raster.png'></a>
337 320
338 * Turbulence Perlin Noise Shader 321 * Turbulence Perlin Noise Shader
339 322
340 <!--?prettify lang=cc?--> 323 <!--?prettify lang=cc?-->
341 324
342 canvas->clear(SK_ColorWHITE); 325 canvas->clear(SK_ColorWHITE);
343 SkShader* shader = SkPerlinNoiseShader::CreateTurbulence(
344 0.05f, 0.05f, 4, 0.0f, nullptr);
345 SkPaint paint; 326 SkPaint paint;
346 paint.setShader(shader); 327 paint.setShader(SkPerlinNoiseShader::MakeTurbulence(
347 shader->unref(); 328 0.05f, 0.05f, 4, 0.0f, nullptr));
348 canvas->drawPaint(paint); 329 canvas->drawPaint(paint);
349 330
350 <a href="https://fiddle.skia.org/c/52729ed3a71b89a6dba4f60e8eb67727"> 331 <a href='https://fiddle.skia.org/c/@skpaint_turb'><img
351 <img src="https://fiddle.skia.org/i/52729ed3a71b89a6dba4f60e8eb67727_raster. png"></a> 332 src='https://fiddle.skia.org/c/@skpaint_turb_raster.png'></a>
352 333
353 * Compose Shader 334 * Compose Shader
354 335
355 <!--?prettify lang=cc?--> 336 <!--?prettify lang=cc?-->
356 337
357 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; 338 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
358 SkShader* shader1 = 339 SkPaint paint;
359 SkGradientShader::CreateRadial( 340 paint.setShader(
341 SkShader::MakeComposeShader(
342 SkGradientShader::MakeRadial(
360 SkPoint::Make(128.0f, 128.0f), 180.0f, 343 SkPoint::Make(128.0f, 128.0f), 180.0f,
361 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr); 344 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr),
362 SkShader* shader2 = SkPerlinNoiseShader::CreateTurbulence( 345 SkPerlinNoiseShader::MakeTurbulence(0.025f, 0.025f, 2, 0.0f, nul lptr),
363 0.025f, 0.025f, 2, 0.0f, nullptr); 346 SkXfermode::kDifference_Mode)
364 SkShader* shader = 347 );
365 new SkComposeShader(shader1, shader2);
366 SkPaint paint;
367 paint.setShader(shader);
368 shader->unref();
369 shader2->unref();
370 shader1->unref();
371 canvas->drawPaint(paint); 348 canvas->drawPaint(paint);
372 349
373 <a href="https://fiddle.skia.org/c/1209b7a29d870302edcc43dc0916e8d5"> 350 <a href='https://fiddle.skia.org/c/@skpaint_compose_shader'><img
374 <img src="https://fiddle.skia.org/i/1209b7a29d870302edcc43dc0916e8d5_raster. png"></a> 351 src='https://fiddle.skia.org/c/@skpaint_compose_shader_raster.png'></a>
375 352
376 353
377 <span id="SkMaskFilter"></span> 354 <span id="SkMaskFilter"></span>
378 355
379 SkMaskFilter 356 SkMaskFilter
380 ------------ 357 ------------
381 358
382 * Blur Mask Filter 359 * Blur Mask Filter
383 360
384 <!--?prettify lang=cc?--> 361 <!--?prettify lang=cc?-->
385 362
363 canvas->drawText(text, strlen(text), 0, 160, paint);
386 canvas->drawColor(SK_ColorWHITE); 364 canvas->drawColor(SK_ColorWHITE);
387 SkPaint paint; 365 SkPaint paint;
388 paint.setAntiAlias(true); 366 paint.setAntiAlias(true);
389 paint.setTextSize(120); 367 paint.setTextSize(120);
390 SkMaskFilter* filter = 368 paint.setMaskFilter(SkBlurMaskFilter::Make(
391 SkBlurMaskFilter::Create( 369 kNormal_SkBlurStyle, 5.0f, 0));
392 kNormal_SkBlurStyle, 5.0f, 0);
393 paint.setMaskFilter(filter);
394 filter->unref();
395 const char text[] = "Skia"; 370 const char text[] = "Skia";
396 canvas->drawText(text, strlen(text), 0, 160, paint); 371 canvas->drawText(text, strlen(text), 0, 160, paint);
397 372
398 <a href="https://fiddle.skia.org/c/0e004664122851691d67a291007b64d7"> 373 <a href='https://fiddle.skia.org/c/@skpaint_blur_mask_filter'><img
399 <img src="https://fiddle.skia.org/i/0e004664122851691d67a291007b64d7_raster. png"></a> 374 src='https://fiddle.skia.org/c/@skpaint_blur_mask_filter_raster.png'></a>
400 375
401 * Emboss Mask Filter 376 * Emboss Mask Filter
402 377
403 <!--?prettify lang=cc?--> 378 <!--?prettify lang=cc?-->
404 379
405 canvas->drawColor(SK_ColorWHITE); 380 canvas->drawColor(SK_ColorWHITE);
406 SkPaint paint; 381 SkPaint paint;
407 paint.setAntiAlias(true); 382 paint.setAntiAlias(true);
408 paint.setTextSize(120); 383 paint.setTextSize(120);
409 SkScalar direction[3] = {1.0f, 1.0f, 1.0f}; 384 SkScalar direction[3] = {1.0f, 1.0f, 1.0f};
410 SkMaskFilter* filter = 385 paint.setMaskFilter(SkBlurMaskFilter::MakeEmboss(
411 SkBlurMaskFilter::CreateEmboss( 386 2.0f, direction, 0.3f, 0.1f));
412 2.0f, direction, 0.3f, 0.1f);
413 paint.setMaskFilter(filter);
414 filter->unref();
415 const char text[] = "Skia"; 387 const char text[] = "Skia";
416 canvas->drawText(text, strlen(text), 0, 160, paint); 388 canvas->drawText(text, strlen(text), 0, 160, paint);
417 389
418 <a href="https://fiddle.skia.org/c/1ef71be7fb749a2d81a55721b2d2c77d"> 390 <a href='https://fiddle.skia.org/c/@skpaint_emboss'><img
419 <img src="https://fiddle.skia.org/i/1ef71be7fb749a2d81a55721b2d2c77d_raster. png"></a> 391 src='https://fiddle.skia.org/c/@skpaint_emboss_raster.png'></a>
420 392
421 393
422 <span id="SkColorFilter"></span> 394 <span id="SkColorFilter"></span>
423 395
424 SkColorFilter 396 SkColorFilter
425 ------------- 397 -------------
426 398
427 * Color Matrix Color Filter 399 * Color Matrix Color Filter
428 400
429 <!--?prettify lang=cc?--> 401 <!--?prettify lang=cc?-->
430 402
431 void f(SkCanvas* c, SkScalar x, SkScalar y, SkScalar colorMatrix[20]) { 403 void f(SkCanvas* c, SkScalar x, SkScalar y, SkScalar colorMatrix[20]) {
432 SkColorFilter* cf = SkColorMatrixFilter::Create(colorMatrix);
433 SkPaint paint; 404 SkPaint paint;
434 paint.setColorFilter(cf); 405 paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(colo rMatrix));
435 cf->unref();
436 c->drawBitmap(source, x, y, &paint); 406 c->drawBitmap(source, x, y, &paint);
437 } 407 }
408
438 void draw(SkCanvas* c) { 409 void draw(SkCanvas* c) {
439 c->scale(0.25, 0.25); 410 c->scale(0.25, 0.25);
440 SkScalar colorMatrix1[20] = { 411 SkScalar colorMatrix1[20] = {
441 0, 1, 0, 0, 0, 412 0, 1, 0, 0, 0,
442 0, 0, 1, 0, 0, 413 0, 0, 1, 0, 0,
443 1, 0, 0, 0, 0, 414 1, 0, 0, 0, 0,
444 0, 0, 0, 1, 0}; 415 0, 0, 0, 1, 0};
445 f(c, 0, 0, colorMatrix1); 416 f(c, 0, 0, colorMatrix1);
446 417
447 SkScalar grayscale[20] = { 418 SkScalar grayscale[20] = {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 f(c, 1536, 0, sepia); 458 f(c, 1536, 0, sepia);
488 459
489 SkScalar inverter[20] = { 460 SkScalar inverter[20] = {
490 -1, 0, 0, 0, 255, 461 -1, 0, 0, 0, 255,
491 0, -1, 0, 0, 255, 462 0, -1, 0, 0, 255,
492 0, 0, -1, 0, 255, 463 0, 0, -1, 0, 255,
493 0, 0, 0, 1, 0}; 464 0, 0, 0, 1, 0};
494 f(c, 1536, 512, inverter); 465 f(c, 1536, 512, inverter);
495 } 466 }
496 467
497 <a href="https://fiddle.skia.org/c/91fb5341ee7903c9682df20bb3d73dbb"> 468 <a href='https://fiddle.skia.org/c/@skpaint_matrix_color_filter'><img
498 <img src="https://fiddle.skia.org/i/91fb5341ee7903c9682df20bb3d73dbb_raster. png"></a> 469 src='https://fiddle.skia.org/c/@skpaint_matrix_color_filter_raster.png'></a>
499 470
500 * Color Table Color Filter 471 * Color Table Color Filter
501 472
502 <!--?prettify lang=cc?--> 473 <!--?prettify lang=cc?-->
503 474
504 canvas->scale(0.5, 0.5); 475 void draw(SkCanvas* canvas) {
505 uint8_t ct[256]; 476 canvas->scale(0.5, 0.5);
506 for (int i = 0; i < 256; ++i) { 477 uint8_t ct[256];
507 int x = (i - 96) * 255 / 64; 478 for (int i = 0; i < 256; ++i) {
508 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; 479 int x = (i - 96) * 255 / 64;
480 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x;
481 }
482 SkPaint paint;
483 paint.setColorFilter(SkTableColorFilter::MakeARGB(nullptr, ct, ct, ct) );
484 canvas->drawBitmap(source, 0, 0, &paint);
509 } 485 }
510 SkColorFilter* cf = SkTableColorFilter::CreateARGB(nullptr, ct, ct, ct);
511 SkPaint paint;
512 paint.setColorFilter(cf);
513 cf->unref();
514 canvas->drawBitmap(source, 0, 0, &paint);
515 486
516 <a href="https://fiddle.skia.org/c/0d3d339543afa1b10c60f9826f264c3f"> 487 <a href='https://fiddle.skia.org/c/@skpaint_color_table_filter'><img
517 <img src="https://fiddle.skia.org/i/0d3d339543afa1b10c60f9826f264c3f_raster. png"></a> 488 src='https://fiddle.skia.org/c/@skpaint_color_table_filter_raster.png'></a >
518 489
519 490
520 <span id="SkPathEffect"></span> 491 <span id="SkPathEffect"></span>
521 492
522 SkPathEffect 493 SkPathEffect
523 ------------ 494 ------------
524 495
525 * SkPath2DPathEffect: Stamp the specified path to fill the shape, 496 * SkPath2DPathEffect: Stamp the specified path to fill the shape,
526 using the matrix to define the latice. 497 using the matrix to define the latice.
527 498
528 <!--?prettify lang=cc?--> 499 <!--?prettify lang=cc?-->
529 500
530 void draw(SkCanvas* canvas) { 501 void draw(SkCanvas* canvas) {
531 SkScalar scale = 10.0f; 502 SkScalar scale = 10.0f;
532 SkPath path; 503 SkPath path;
533 static const int8_t pts[] = { 2, 2, 1, 3, 0, 3, 2, 1, 3, 1, 504 static const int8_t pts[] = { 2, 2, 1, 3, 0, 3, 2, 1, 3, 1,
534 4, 0, 4, 1, 5, 1, 4, 2, 4, 3, 2, 5, 2, 4, 3, 3, 2, 3 }; 505 4, 0, 4, 1, 5, 1, 4, 2, 4, 3, 2, 5, 2, 4, 3, 3, 2, 3 };
535 path.moveTo(2 * scale, 3 * scale); 506 path.moveTo(2 * scale, 3 * scale);
536 for (size_t i = 0 ; i < sizeof(pts)/sizeof(pts[0]); i += 2) { 507 for (size_t i = 0 ; i < sizeof(pts)/sizeof(pts[0]); i += 2) {
537 path.lineTo(pts[i] * scale, pts[i + 1] * scale); 508 path.lineTo(pts[i] * scale, pts[i + 1] * scale);
538 } 509 }
539 path.close(); 510 path.close();
540 SkMatrix matrix = SkMatrix::MakeScale(4 * scale); 511 SkMatrix matrix = SkMatrix::MakeScale(4 * scale);
541 SkAutoTUnref<SkPathEffect> pathEffect(
542 SkPath2DPathEffect::Create(matrix, path));
543 SkPaint paint; 512 SkPaint paint;
544 paint.setPathEffect(pathEffect); 513 paint.setPathEffect(SkPath2DPathEffect::Make(matrix, path));
545 paint.setAntiAlias(true); 514 paint.setAntiAlias(true);
546 canvas->clear(SK_ColorWHITE); 515 canvas->clear(SK_ColorWHITE);
547 SkRect bounds; 516 SkRect bounds;
548 (void)canvas->getClipBounds(&bounds); 517 (void)canvas->getClipBounds(&bounds);
549 bounds.outset(2 * scale, 2 * scale); 518 bounds.outset(2 * scale, 2 * scale);
550 canvas->drawRect(bounds, paint); 519 canvas->drawRect(bounds, paint);
551 } 520 }
552 521
553 <a href="https://fiddle.skia.org/c/aae271e4f0178455f0e128981d714d73"><img sr c="https://fiddle.skia.org/i/aae271e4f0178455f0e128981d714d73_raster.png" alt="" ></a> 522 <a href='https://fiddle.skia.org/c/@skpaint_path_2d_path_effect'><img
523 src='https://fiddle.skia.org/c/@skpaint_path_2d_path_effect_raster.png'></ a>
554 524
555 * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the 525 * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the
556 path is a straight line to be stroked, not a path to be filled. 526 path is a straight line to be stroked, not a path to be filled.
557 527
558 <!--?prettify lang=cc?--> 528 <!--?prettify lang=cc?-->
559 529
560 void draw(SkCanvas* canvas) { 530 void draw(SkCanvas* canvas) {
561 SkPaint paint; 531 SkPaint paint;
562 SkMatrix lattice; 532 SkMatrix lattice;
563 lattice.setScale(8.0f, 8.0f); 533 lattice.setScale(8.0f, 8.0f);
564 lattice.preRotate(30.0f); 534 lattice.preRotate(30.0f);
565 SkAutoTUnref<SkPathEffect> pe( 535 paint.setPathEffect(SkLine2DPathEffect::Make(0.0f, lattice));
566 SkLine2DPathEffect::Create(0.0f, lattice));
567 paint.setPathEffect(pe);
568 paint.setAntiAlias(true); 536 paint.setAntiAlias(true);
569 SkRect bounds; 537 SkRect bounds;
570 (void)canvas->getClipBounds(&bounds); 538 (void)canvas->getClipBounds(&bounds);
571 bounds.outset(8.0f, 8.0f); 539 bounds.outset(8.0f, 8.0f);
572 canvas->clear(SK_ColorWHITE); 540 canvas->clear(SK_ColorWHITE);
573 canvas->drawRect(bounds, paint); 541 canvas->drawRect(bounds, paint);
574 } 542 }
575 543
576 <a href="https://fiddle.skia.org/c/3f49502145886920f95d43912e0f550d"><img sr c="https://fiddle.skia.org/i/3f49502145886920f95d43912e0f550d_raster.png" alt="" ></a> 544 <a href='https://fiddle.skia.org/c/@skpaint_line_2d_path_effect'><img
545 src='https://fiddle.skia.org/c/@skpaint_line_2d_path_effect_raster.png'></ a>
577 546
578 * SkPath1DPathEffect: create dash-like effects by replicating the specified pa th along the drawn path. 547 * SkPath1DPathEffect: create dash-like effects by replicating the specified pa th along the drawn path.
579 548
580 <!--?prettify lang=cc?--> 549 <!--?prettify lang=cc?-->
581 550
582 void draw(SkCanvas* canvas) { 551 void draw(SkCanvas* canvas) {
583 SkPaint paint; 552 SkPaint paint;
584 SkPath path; 553 SkPath path;
585 path.addOval(SkRect::MakeWH(16.0f, 6.0f)); 554 path.addOval(SkRect::MakeWH(16.0f, 6.0f));
586 SkAutoTUnref<SkPathEffect> pe( 555 paint.setPathEffect(SkPath1DPathEffect::Make(
587 SkPath1DPathEffect::Create(
588 path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style)); 556 path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style));
589 paint.setPathEffect(pe);
590 paint.setAntiAlias(true); 557 paint.setAntiAlias(true);
591 canvas->clear(SK_ColorWHITE); 558 canvas->clear(SK_ColorWHITE);
592 canvas->drawCircle(128.0f, 128.0f, 122.0f, paint); 559 canvas->drawCircle(128.0f, 128.0f, 122.0f, paint);
593 } 560 }
594 561
595 <a href="https://fiddle.skia.org/c/756a8cdb9458c05f6c1c7c398d979dac"><img sr c="https://fiddle.skia.org/i/756a8cdb9458c05f6c1c7c398d979dac_raster.png" alt="" ></a> 562 <a href='https://fiddle.skia.org/c/@skpaint_path_1d_path_effect'><img
563 src='https://fiddle.skia.org/c/@skpaint_path_1d_path_effect_raster.png'></ a>
596 564
597 * SkArcToPathEffect 565 * SkArcToPathEffect
598 566
599 The following few examples use this function: 567 The following few examples use this function:
600 568
601 <!--?prettify lang=cc?--> 569 <!--?prettify lang=cc?-->
602 570
603 SkPath star() { 571 SkPath star() {
604 const SkScalar R = 115.2f, C = 128.0f; 572 const SkScalar R = 115.2f, C = 128.0f;
605 SkPath path; 573 SkPath path;
606 path.moveTo(C + R, C); 574 path.moveTo(C + R, C);
607 for (int i = 1; i < 7; ++i) { 575 for (int i = 1; i < 8; ++i) {
608 SkScalar a = 2.6927937f * i; 576 SkScalar a = 2.6927937f * i;
609 path.lineTo(C + R * cos(a), C + R * sin(a)); 577 path.lineTo(C + R * cos(a), C + R * sin(a));
610 } 578 }
611 path.close();
612 return path; 579 return path;
613 } 580 }
614
615 <!--?prettify lang=cc?-->
616
617 void draw(SkCanvas* canvas) { 581 void draw(SkCanvas* canvas) {
618 SkPaint paint; 582 SkPaint paint;
619 SkAutoTUnref<SkPathEffect> pe( 583 paint.setPathEffect(SkArcToPathEffect::Make(8.0f));
620 SkArcToPathEffect::Create(8.0f));
621 paint.setPathEffect(pe);
622 paint.setStyle(SkPaint::kStroke_Style); 584 paint.setStyle(SkPaint::kStroke_Style);
623 paint.setAntiAlias(true); 585 paint.setAntiAlias(true);
624 canvas->clear(SK_ColorWHITE); 586 canvas->clear(SK_ColorWHITE);
625 SkPath path(star()); 587 SkPath path(star());
626 canvas->drawPath(path, paint); 588 canvas->drawPath(path, paint);
627 } 589 }
628 590
629 <a href="https://fiddle.skia.org/c/1cc2a1363dd0e96954e084f7ca29aa5f"><img sr c="https://fiddle.skia.org/i/1cc2a1363dd0e96954e084f7ca29aa5f_raster.png" alt="" ></a> 591 <a href='https://fiddle.skia.org/c/@skpaint_arc_to_path_effect'><img
592 src='https://fiddle.skia.org/c/@skpaint_arc_to_path_effect_raster.png'></a >
593
630 594
631 * SkCornerPathEffect: a path effect that can turn sharp corners into 595 * SkCornerPathEffect: a path effect that can turn sharp corners into
632 various treatments (e.g. rounded corners). 596 various treatments (e.g. rounded corners).
633 597
634 <!--?prettify lang=cc?--> 598 <!--?prettify lang=cc?-->
635 599
636 void draw(SkCanvas* canvas) { 600 void draw(SkCanvas* canvas) {
637 SkPaint paint; 601 SkPaint paint;
638 SkAutoTUnref<SkPathEffect> pe( 602 paint.setPathEffect(SkCornerPathEffect::Make(32.0f));
639 SkCornerPathEffect::Create(32.0f));
640 paint.setPathEffect(pe);
641 paint.setStyle(SkPaint::kStroke_Style); 603 paint.setStyle(SkPaint::kStroke_Style);
642 paint.setAntiAlias(true); 604 paint.setAntiAlias(true);
643 canvas->clear(SK_ColorWHITE); 605 canvas->clear(SK_ColorWHITE);
644 const SkScalar R = 115.2f; 606 const SkScalar R = 115.2f;
645 SkPath path(star()); 607 SkPath path(star());
646 canvas->drawPath(path, paint); 608 canvas->drawPath(path, paint);
647 } 609 }
648 610
649 <a href="https://fiddle.skia.org/c/f5361bbb33ad43c656dd40bb03ee2114"><img sr c="https://fiddle.skia.org/i/f5361bbb33ad43c656dd40bb03ee2114_raster.png" alt="" ></a> 611 <a href='https://fiddle.skia.org/c/@skpaint_corner_path_effects'><img src='h ttps://fiddle.skia.org/c/@skpaint_corner_path_effects_raster.png'></a>
650 612
651 * SkDashPathEffect: a path effect that implements dashing. 613 * SkDashPathEffect: a path effect that implements dashing.
652 614
653 <!--?prettify lang=cc?--> 615 <!--?prettify lang=cc?-->
654 616
655 void draw(SkCanvas* canvas) { 617 void draw(SkCanvas* canvas) {
656 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; 618 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f };
657 size_t count = sizeof(intervals) / sizeof(intervals[0]); 619 size_t count = sizeof(intervals) / sizeof(intervals[0]);
658 SkAutoTUnref<SkPathEffect> pe(
659 SkDashPathEffect::Create(intervals, count, 0.0f));
660 SkPaint paint; 620 SkPaint paint;
661 paint.setPathEffect(pe); 621 paint.setPathEffect(SkDashPathEffect::Make(intervals, count, 0.0f));
662 paint.setStyle(SkPaint::kStroke_Style); 622 paint.setStyle(SkPaint::kStroke_Style);
663 paint.setStrokeWidth(2.0f); 623 paint.setStrokeWidth(2.0f);
664 paint.setAntiAlias(true); 624 paint.setAntiAlias(true);
665 canvas->clear(SK_ColorWHITE); 625 canvas->clear(SK_ColorWHITE);
666 SkPath path(star()); 626 SkPath path(star());
667 canvas->drawPath(path, paint); 627 canvas->drawPath(path, paint);
668 } 628 }
669 629
670 <a href="https://fiddle.skia.org/c/d221ced999a80ac23870d0301ffeedad"><img sr c="https://fiddle.skia.org/i/d221ced999a80ac23870d0301ffeedad_raster.png" alt="" ></a> 630 <a href='https://fiddle.skia.org/c/@skpaint_dash_path_effect'><img src='http s://fiddle.skia.org/c/@skpaint_dash_path_effect_raster.png'></a>
671 631
672 * SkDiscretePathEffect: This path effect chops a path into discrete 632 * SkDiscretePathEffect: This path effect chops a path into discrete
673 segments, and randomly displaces them. 633 segments, and randomly displaces them.
674 634
675 <!--?prettify lang=cc?--> 635 <!--?prettify lang=cc?-->
676 636
677 void draw(SkCanvas* canvas) { 637 void draw(SkCanvas* canvas) {
678 SkAutoTUnref<SkPathEffect> pe(
679 SkDiscretePathEffect::Create(10.0f, 4.0f));
680 SkPaint paint; 638 SkPaint paint;
681 paint.setPathEffect(pe); 639 paint.setPathEffect(SkDiscretePathEffect::Make(10.0f, 4.0f));
682 paint.setStyle(SkPaint::kStroke_Style); 640 paint.setStyle(SkPaint::kStroke_Style);
683 paint.setStrokeWidth(2.0f); 641 paint.setStrokeWidth(2.0f);
684 paint.setAntiAlias(true); 642 paint.setAntiAlias(true);
685 canvas->clear(SK_ColorWHITE); 643 canvas->clear(SK_ColorWHITE);
686 SkPath path(star()); 644 SkPath path(star());
687 canvas->drawPath(path, paint); 645 canvas->drawPath(path, paint);
688 } 646 }
689 647
690 <a href="https://fiddle.skia.org/c/af2f177438b376ca45cfffc29cc0177a"><img sr c="https://fiddle.skia.org/i/af2f177438b376ca45cfffc29cc0177a_raster.png" alt="" ></a> 648 <a href='https://fiddle.skia.org/c/@skpaint_discrete_path_effect'><img
649 src='https://fiddle.skia.org/c/@skpaint_discrete_path_effect_raster.png'>< /a>
691 650
692 * SkComposePathEffect: a pathEffect whose effect is to apply 651 * SkComposePathEffect: a pathEffect whose effect is to apply
693 first the inner pathEffect and the the outer pathEffect (i.e. 652 first the inner pathEffect and the the outer pathEffect (i.e.
694 outer(inner(path))). 653 outer(inner(path))).
695 654
696 <!--?prettify lang=cc?--> 655 <!--?prettify lang=cc?-->
697 656
698 void draw(SkCanvas* canvas) { 657 void draw(SkCanvas* canvas) {
699 SkAutoTUnref<SkPathEffect> pe0(
700 SkDiscretePathEffect::Create(10.0f, 4.0f));
701 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; 658 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f };
702 size_t count = sizeof(intervals) / sizeof(intervals[0]); 659 size_t count = sizeof(intervals) / sizeof(intervals[0]);
703 SkAutoTUnref<SkPathEffect> pe1(
704 SkDashPathEffect::Create(intervals, count, 0.0f));
705 SkAutoTUnref<SkPathEffect> pe(
706 SkComposePathEffect::Create(pe1, pe0));
707 SkPaint paint; 660 SkPaint paint;
708 paint.setPathEffect(pe); 661 paint.setPathEffect(SkComposePathEffect::Make(
662 SkDashPathEffect::Make(intervals, count, 0.0f),
663 SkDiscretePathEffect::Make(10.0f, 4.0f)
664 ));
709 paint.setStyle(SkPaint::kStroke_Style); 665 paint.setStyle(SkPaint::kStroke_Style);
710 paint.setStrokeWidth(2.0f); 666 paint.setStrokeWidth(2.0f);
711 paint.setAntiAlias(true); 667 paint.setAntiAlias(true);
712 canvas->clear(SK_ColorWHITE); 668 canvas->clear(SK_ColorWHITE);
713 SkPath path(star()); 669 SkPath path(star());
714 canvas->drawPath(path, paint); 670 canvas->drawPath(path, paint);
715 } 671 }
716 672
717 <a href="https://fiddle.skia.org/c/39a644161da79e8b5e49c193adac7173"><img sr c="https://fiddle.skia.org/i/39a644161da79e8b5e49c193adac7173_raster.png" alt="" ></a> 673 <a href='https://fiddle.skia.org/c/@skpaint_compose_path_effect'><img
674 src='https://fiddle.skia.org/c/@skpaint_compose_path_effect_raster.png'></ a>
718 675
719 * SkSumPathEffect: a pathEffect whose effect is to apply two effects, 676 * SkSumPathEffect: a pathEffect whose effect is to apply two effects,
720 in sequence (i.e. first(path) + second(path)). 677 in sequence (i.e. first(path) + second(path)).
721 678
722 <!--?prettify lang=cc?--> 679 <!--?prettify lang=cc?-->
723 680
724 void draw(SkCanvas* canvas) { 681 void draw(SkCanvas* canvas) {
725 SkAutoTUnref<SkPathEffect> pe0(
726 SkDiscretePathEffect::Create(10.0f, 4.0f));
727 SkAutoTUnref<SkPathEffect> pe1(
728 SkDiscretePathEffect::Create(10.0f, 4.0f, 1245u));
729 SkAutoTUnref<SkPathEffect> pe(
730 SkSumPathEffect::Create(pe1, pe0));
731 SkPaint paint; 682 SkPaint paint;
732 paint.setPathEffect(pe); 683 paint.setPathEffect(SkSumPathEffect::Make(
684 SkDiscretePathEffect::Make(10.0f, 4.0f),
685 SkDiscretePathEffect::Make(10.0f, 4.0f, 1245u)
686 ));
733 paint.setStyle(SkPaint::kStroke_Style); 687 paint.setStyle(SkPaint::kStroke_Style);
734 paint.setStrokeWidth(2.0f); 688 paint.setStrokeWidth(2.0f);
735 paint.setAntiAlias(true); 689 paint.setAntiAlias(true);
736 canvas->clear(SK_ColorWHITE); 690 canvas->clear(SK_ColorWHITE);
737 SkPath path(star()); 691 SkPath path(star());
738 canvas->drawPath(path, paint); 692 canvas->drawPath(path, paint);
739 } 693 }
740 694
741 <a href="https://fiddle.skia.org/c/e5f7861072893bd08c305a076bf32958"><img sr c="https://fiddle.skia.org/i/e5f7861072893bd08c305a076bf32958_raster.png" alt="" ></a> 695 <a href='https://fiddle.skia.org/c/@skpaint_sum_path_effect'><img
696 src='https://fiddle.skia.org/c/@skpaint_sum_path_effect_raster.png'></a>
742 697
743 <!--
744 <a href="https://fiddle.skia.org/c/"><img src="https://fiddle.skia.org/i/_ra ster.png" alt=""></a>
745 -->
746
OLDNEW
« no previous file with comments | « site/user/api/skcanvas.md ('k') | site/user/tips.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698