OLD | NEW |
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 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 <!--?prettify lang=cc?--> | 93 <!--?prettify lang=cc?--> |
94 | 94 |
95 SkPoint points[2] = { | 95 SkPoint points[2] = { |
96 SkPoint::Make(0.0f, 0.0f), | 96 SkPoint::Make(0.0f, 0.0f), |
97 SkPoint::Make(256.0f, 256.0f) | 97 SkPoint::Make(256.0f, 256.0f) |
98 }; | 98 }; |
99 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 99 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
100 SkShader* shader = | 100 SkShader* shader = |
101 SkGradientShader::CreateLinear( | 101 SkGradientShader::CreateLinear( |
102 points, colors, NULL, 2, | 102 points, colors, nullptr, 2, |
103 SkShader::kClamp_TileMode, 0, NULL); | 103 SkShader::kClamp_TileMode, 0, nullptr); |
104 SkPaint paint; | 104 SkPaint paint; |
105 paint.setShader(shader); | 105 paint.setShader(shader); |
106 shader->unref(); | 106 shader->unref(); |
107 canvas->drawPaint(paint); | 107 canvas->drawPaint(paint); |
108 | 108 |
109 <a href="https://fiddle.skia.org/c/f91b5310d57744a5a1475b7e47d4a172"> | 109 <a href="https://fiddle.skia.org/c/f91b5310d57744a5a1475b7e47d4a172"> |
110 <img src="https://fiddle.skia.org/i/f91b5310d57744a5a1475b7e47d4a172_raster.png"
></a> | 110 <img src="https://fiddle.skia.org/i/f91b5310d57744a5a1475b7e47d4a172_raster.png"
></a> |
111 | 111 |
112 Now, anything drawn with that paint will be drawn with the gradient | 112 Now, anything drawn with that paint will be drawn with the gradient |
113 specified in the call to `CreateLinear()`. The shader object that is | 113 specified in the call to `CreateLinear()`. The shader object that is |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 text.setAntiAlias(true); | 194 text.setAntiAlias(true); |
195 SkPoint srcPoints[2] = { | 195 SkPoint srcPoints[2] = { |
196 SkPoint::Make(0.0f, 0.0f), | 196 SkPoint::Make(0.0f, 0.0f), |
197 SkPoint::Make(64.0f, 0.0f) | 197 SkPoint::Make(64.0f, 0.0f) |
198 }; | 198 }; |
199 SkColor srcColors[2] = { | 199 SkColor srcColors[2] = { |
200 SK_ColorMAGENTA & 0x00FFFFFF, | 200 SK_ColorMAGENTA & 0x00FFFFFF, |
201 SK_ColorMAGENTA}; | 201 SK_ColorMAGENTA}; |
202 SkAutoTUnref<SkShader> srcShader( | 202 SkAutoTUnref<SkShader> srcShader( |
203 SkGradientShader::CreateLinear( | 203 SkGradientShader::CreateLinear( |
204 srcPoints, srcColors, NULL, 2, | 204 srcPoints, srcColors, nullptr, 2, |
205 SkShader::kClamp_TileMode, 0, NULL)); | 205 SkShader::kClamp_TileMode, 0, nullptr)); |
206 src.setShader(srcShader); | 206 src.setShader(srcShader); |
207 | 207 |
208 SkPoint dstPoints[2] = { | 208 SkPoint dstPoints[2] = { |
209 SkPoint::Make(0.0f, 0.0f), | 209 SkPoint::Make(0.0f, 0.0f), |
210 SkPoint::Make(0.0f, 64.0f) | 210 SkPoint::Make(0.0f, 64.0f) |
211 }; | 211 }; |
212 SkColor dstColors[2] = { | 212 SkColor dstColors[2] = { |
213 SK_ColorCYAN & 0x00FFFFFF, | 213 SK_ColorCYAN & 0x00FFFFFF, |
214 SK_ColorCYAN}; | 214 SK_ColorCYAN}; |
215 SkAutoTUnref<SkShader> dstShader( | 215 SkAutoTUnref<SkShader> dstShader( |
216 SkGradientShader::CreateLinear( | 216 SkGradientShader::CreateLinear( |
217 dstPoints, dstColors, NULL, 2, | 217 dstPoints, dstColors, nullptr, 2, |
218 SkShader::kClamp_TileMode, 0, NULL)); | 218 SkShader::kClamp_TileMode, 0, nullptr)); |
219 dst.setShader(dstShader); | 219 dst.setShader(dstShader); |
220 canvas->clear(SK_ColorWHITE); | 220 canvas->clear(SK_ColorWHITE); |
221 size_t N = sizeof(modes) / sizeof(modes[0]); | 221 size_t N = sizeof(modes) / sizeof(modes[0]); |
222 size_t K = (N - 1) / 3 + 1; | 222 size_t K = (N - 1) / 3 + 1; |
223 SkASSERT(K * 64 == 640); // tall enough | 223 SkASSERT(K * 64 == 640); // tall enough |
224 for (size_t i = 0; i < N; ++i) { | 224 for (size_t i = 0; i < N; ++i) { |
225 SkAutoCanvasRestore autoCanvasRestore(canvas, true); | 225 SkAutoCanvasRestore autoCanvasRestore(canvas, true); |
226 canvas->translate(192.0f * (i / K), 64.0f * (i % K)); | 226 canvas->translate(192.0f * (i / K), 64.0f * (i % K)); |
227 const char* desc = SkXfermode::ModeName(modes[i]); | 227 const char* desc = SkXfermode::ModeName(modes[i]); |
228 canvas->drawText(desc, strlen(desc), 68.0f, 30.0f, text); | 228 canvas->drawText(desc, strlen(desc), 68.0f, 30.0f, text); |
229 canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f)); | 229 canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f)); |
230 canvas->drawColor(SK_ColorLTGRAY); | 230 canvas->drawColor(SK_ColorLTGRAY); |
231 (void)canvas->saveLayer(NULL, NULL); | 231 (void)canvas->saveLayer(nullptr, nullptr); |
232 canvas->clear(SK_ColorTRANSPARENT); | 232 canvas->clear(SK_ColorTRANSPARENT); |
233 canvas->drawPaint(dst); | 233 canvas->drawPaint(dst); |
234 src.setXfermodeMode(modes[i]); | 234 src.setXfermodeMode(modes[i]); |
235 canvas->drawPaint(src); | 235 canvas->drawPaint(src); |
236 canvas->drawRect(rect, stroke); | 236 canvas->drawRect(rect, stroke); |
237 } | 237 } |
238 | 238 |
239 <a href="https://fiddle.skia.org/c/0a2392be5adf339ce6537799f2807f3c"><img src="h
ttps://fiddle.skia.org/i/0a2392be5adf339ce6537799f2807f3c_raster.png" alt=""></a
> | 239 <a href="https://fiddle.skia.org/c/0a2392be5adf339ce6537799f2807f3c"><img src="h
ttps://fiddle.skia.org/i/0a2392be5adf339ce6537799f2807f3c_raster.png" alt=""></a
> |
240 | 240 |
241 <span id="ShShader"></span> | 241 <span id="ShShader"></span> |
(...skipping 26 matching lines...) Expand all Loading... |
268 <img src="https://fiddle.skia.org/i/0e8d08e0a0b342e9e45c364d0e5cea8a_raster.
png"></a> | 268 <img src="https://fiddle.skia.org/i/0e8d08e0a0b342e9e45c364d0e5cea8a_raster.
png"></a> |
269 | 269 |
270 * Radial Gradient Shader | 270 * Radial Gradient Shader |
271 | 271 |
272 <!--?prettify lang=cc?--> | 272 <!--?prettify lang=cc?--> |
273 | 273 |
274 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 274 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
275 SkShader* shader = | 275 SkShader* shader = |
276 SkGradientShader::CreateRadial( | 276 SkGradientShader::CreateRadial( |
277 SkPoint::Make(128.0f, 128.0f), 180.0f, | 277 SkPoint::Make(128.0f, 128.0f), 180.0f, |
278 colors, NULL, 2, SkShader::kClamp_TileMode, 0, NULL); | 278 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullpt
r); |
279 SkPaint paint; | 279 SkPaint paint; |
280 paint.setShader(shader); | 280 paint.setShader(shader); |
281 shader->unref(); | 281 shader->unref(); |
282 canvas->drawPaint(paint); | 282 canvas->drawPaint(paint); |
283 | 283 |
284 <a href="https://fiddle.skia.org/c/601abd2819e38365900bf62286986024"> | 284 <a href="https://fiddle.skia.org/c/601abd2819e38365900bf62286986024"> |
285 <img src="https://fiddle.skia.org/i/601abd2819e38365900bf62286986024_raster.
png"></a> | 285 <img src="https://fiddle.skia.org/i/601abd2819e38365900bf62286986024_raster.
png"></a> |
286 | 286 |
287 * Two-Point Conical Gradient Shader | 287 * Two-Point Conical Gradient Shader |
288 | 288 |
289 <!--?prettify lang=cc?--> | 289 <!--?prettify lang=cc?--> |
290 | 290 |
291 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 291 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
292 SkShader* shader = | 292 SkShader* shader = |
293 SkGradientShader::CreateTwoPointConical( | 293 SkGradientShader::CreateTwoPointConical( |
294 SkPoint::Make(128.0f, 128.0f), 128.0f, | 294 SkPoint::Make(128.0f, 128.0f), 128.0f, |
295 SkPoint::Make(128.0f, 16.0f), 16.0f, | 295 SkPoint::Make(128.0f, 16.0f), 16.0f, |
296 colors, NULL, 2, SkShader::kClamp_TileMode, 0, NULL); | 296 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullp
tr); |
297 SkPaint paint; | 297 SkPaint paint; |
298 paint.setShader(shader); | 298 paint.setShader(shader); |
299 shader->unref(); | 299 shader->unref(); |
300 canvas->drawPaint(paint); | 300 canvas->drawPaint(paint); |
301 | 301 |
302 <a href="https://fiddle.skia.org/c/991f7d67ff1ccebd6c2c4fab18a76edc"> | 302 <a href="https://fiddle.skia.org/c/991f7d67ff1ccebd6c2c4fab18a76edc"> |
303 <img src="https://fiddle.skia.org/i/991f7d67ff1ccebd6c2c4fab18a76edc_raster.
png"></a> | 303 <img src="https://fiddle.skia.org/i/991f7d67ff1ccebd6c2c4fab18a76edc_raster.
png"></a> |
304 | 304 |
305 | 305 |
306 * Sweep Gradient Shader | 306 * Sweep Gradient Shader |
307 | 307 |
308 <!--?prettify lang=cc?--> | 308 <!--?prettify lang=cc?--> |
309 | 309 |
310 SkColor colors[4] = { | 310 SkColor colors[4] = { |
311 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; | 311 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; |
312 SkShader* shader = | 312 SkShader* shader = |
313 SkGradientShader::CreateSweep( | 313 SkGradientShader::CreateSweep( |
314 128.0f, 128.0f, colors, NULL, 4, 0, NULL); | 314 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr); |
315 SkPaint paint; | 315 SkPaint paint; |
316 paint.setShader(shader); | 316 paint.setShader(shader); |
317 shader->unref(); | 317 shader->unref(); |
318 canvas->drawPaint(paint); | 318 canvas->drawPaint(paint); |
319 | 319 |
320 <a href="https://fiddle.skia.org/c/cee9d1831f6679c3d88170f857995d12"> | 320 <a href="https://fiddle.skia.org/c/cee9d1831f6679c3d88170f857995d12"> |
321 <img src="https://fiddle.skia.org/i/cee9d1831f6679c3d88170f857995d12_raster.
png"></a> | 321 <img src="https://fiddle.skia.org/i/cee9d1831f6679c3d88170f857995d12_raster.
png"></a> |
322 | 322 |
323 * Fractal Perlin Noise Shader | 323 * Fractal Perlin Noise Shader |
324 | 324 |
325 <!--?prettify lang=cc?--> | 325 <!--?prettify lang=cc?--> |
326 | 326 |
327 canvas->clear(SK_ColorWHITE); | 327 canvas->clear(SK_ColorWHITE); |
328 SkShader* shader = SkPerlinNoiseShader::CreateFractalNoise( | 328 SkShader* shader = SkPerlinNoiseShader::CreateFractalNoise( |
329 0.05f, 0.05f, 4, 0.0f, NULL); | 329 0.05f, 0.05f, 4, 0.0f, nullptr); |
330 SkPaint paint; | 330 SkPaint paint; |
331 paint.setShader(shader); | 331 paint.setShader(shader); |
332 shader->unref(); | 332 shader->unref(); |
333 canvas->drawPaint(paint); | 333 canvas->drawPaint(paint); |
334 | 334 |
335 <a href="https://fiddle.skia.org/c/cc45c5349c3b31f97da7c1af7f84162a"> | 335 <a href="https://fiddle.skia.org/c/cc45c5349c3b31f97da7c1af7f84162a"> |
336 <img src="https://fiddle.skia.org/i/cc45c5349c3b31f97da7c1af7f84162a_raster.
png"></a> | 336 <img src="https://fiddle.skia.org/i/cc45c5349c3b31f97da7c1af7f84162a_raster.
png"></a> |
337 | 337 |
338 * Turbulence Perlin Noise Shader | 338 * Turbulence Perlin Noise Shader |
339 | 339 |
340 <!--?prettify lang=cc?--> | 340 <!--?prettify lang=cc?--> |
341 | 341 |
342 canvas->clear(SK_ColorWHITE); | 342 canvas->clear(SK_ColorWHITE); |
343 SkShader* shader = SkPerlinNoiseShader::CreateTurbulence( | 343 SkShader* shader = SkPerlinNoiseShader::CreateTurbulence( |
344 0.05f, 0.05f, 4, 0.0f, NULL); | 344 0.05f, 0.05f, 4, 0.0f, nullptr); |
345 SkPaint paint; | 345 SkPaint paint; |
346 paint.setShader(shader); | 346 paint.setShader(shader); |
347 shader->unref(); | 347 shader->unref(); |
348 canvas->drawPaint(paint); | 348 canvas->drawPaint(paint); |
349 | 349 |
350 <a href="https://fiddle.skia.org/c/52729ed3a71b89a6dba4f60e8eb67727"> | 350 <a href="https://fiddle.skia.org/c/52729ed3a71b89a6dba4f60e8eb67727"> |
351 <img src="https://fiddle.skia.org/i/52729ed3a71b89a6dba4f60e8eb67727_raster.
png"></a> | 351 <img src="https://fiddle.skia.org/i/52729ed3a71b89a6dba4f60e8eb67727_raster.
png"></a> |
352 | 352 |
353 * Compose Shader | 353 * Compose Shader |
354 | 354 |
355 <!--?prettify lang=cc?--> | 355 <!--?prettify lang=cc?--> |
356 | 356 |
357 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 357 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
358 SkShader* shader1 = | 358 SkShader* shader1 = |
359 SkGradientShader::CreateRadial( | 359 SkGradientShader::CreateRadial( |
360 SkPoint::Make(128.0f, 128.0f), 180.0f, | 360 SkPoint::Make(128.0f, 128.0f), 180.0f, |
361 colors, NULL, 2, SkShader::kClamp_TileMode, 0, NULL); | 361 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr); |
362 SkShader* shader2 = SkPerlinNoiseShader::CreateTurbulence( | 362 SkShader* shader2 = SkPerlinNoiseShader::CreateTurbulence( |
363 0.025f, 0.025f, 2, 0.0f, NULL); | 363 0.025f, 0.025f, 2, 0.0f, nullptr); |
364 SkShader* shader = | 364 SkShader* shader = |
365 new SkComposeShader(shader1, shader2); | 365 new SkComposeShader(shader1, shader2); |
366 SkPaint paint; | 366 SkPaint paint; |
367 paint.setShader(shader); | 367 paint.setShader(shader); |
368 shader->unref(); | 368 shader->unref(); |
369 shader2->unref(); | 369 shader2->unref(); |
370 shader1->unref(); | 370 shader1->unref(); |
371 canvas->drawPaint(paint); | 371 canvas->drawPaint(paint); |
372 | 372 |
373 <a href="https://fiddle.skia.org/c/1209b7a29d870302edcc43dc0916e8d5"> | 373 <a href="https://fiddle.skia.org/c/1209b7a29d870302edcc43dc0916e8d5"> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 * Color Table Color Filter | 500 * Color Table Color Filter |
501 | 501 |
502 <!--?prettify lang=cc?--> | 502 <!--?prettify lang=cc?--> |
503 | 503 |
504 canvas->scale(0.5, 0.5); | 504 canvas->scale(0.5, 0.5); |
505 uint8_t ct[256]; | 505 uint8_t ct[256]; |
506 for (int i = 0; i < 256; ++i) { | 506 for (int i = 0; i < 256; ++i) { |
507 int x = (i - 96) * 255 / 64; | 507 int x = (i - 96) * 255 / 64; |
508 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; | 508 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; |
509 } | 509 } |
510 SkColorFilter* cf = SkTableColorFilter::CreateARGB(NULL, ct, ct, ct); | 510 SkColorFilter* cf = SkTableColorFilter::CreateARGB(nullptr, ct, ct, ct); |
511 SkPaint paint; | 511 SkPaint paint; |
512 paint.setColorFilter(cf); | 512 paint.setColorFilter(cf); |
513 cf->unref(); | 513 cf->unref(); |
514 canvas->drawBitmap(source, 0, 0, &paint); | 514 canvas->drawBitmap(source, 0, 0, &paint); |
515 | 515 |
516 <a href="https://fiddle.skia.org/c/0d3d339543afa1b10c60f9826f264c3f"> | 516 <a href="https://fiddle.skia.org/c/0d3d339543afa1b10c60f9826f264c3f"> |
517 <img src="https://fiddle.skia.org/i/0d3d339543afa1b10c60f9826f264c3f_raster.
png"></a> | 517 <img src="https://fiddle.skia.org/i/0d3d339543afa1b10c60f9826f264c3f_raster.
png"></a> |
518 | 518 |
519 | 519 |
520 <span id="SkPathEffect"></span> | 520 <span id="SkPathEffect"></span> |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 SkPath path(star()); | 736 SkPath path(star()); |
737 canvas->drawPath(path, paint); | 737 canvas->drawPath(path, paint); |
738 } | 738 } |
739 | 739 |
740 <a href="https://fiddle.skia.org/c/e5f7861072893bd08c305a076bf32958"><img sr
c="https://fiddle.skia.org/i/e5f7861072893bd08c305a076bf32958_raster.png" alt=""
></a> | 740 <a href="https://fiddle.skia.org/c/e5f7861072893bd08c305a076bf32958"><img sr
c="https://fiddle.skia.org/i/e5f7861072893bd08c305a076bf32958_raster.png" alt=""
></a> |
741 | 741 |
742 <!-- | 742 <!-- |
743 <a href="https://fiddle.skia.org/c/"><img src="https://fiddle.skia.org/i/_ra
ster.png" alt=""></a> | 743 <a href="https://fiddle.skia.org/c/"><img src="https://fiddle.skia.org/i/_ra
ster.png" alt=""></a> |
744 --> | 744 --> |
745 | 745 |
OLD | NEW |