| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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/@skpaint_skia'><img | 55 <a href='https://fiddle.skia.org/c/@skpaint_skia'><img |
| 56 src='https://fiddle.skia.org/c/@skpaint_skia_raster.png'></a> | 56 src='https://fiddle.skia.org/i/@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/@skpaint_mix'><img | 81 <a href='https://fiddle.skia.org/c/@skpaint_mix'><img |
| 82 src='https://fiddle.skia.org/c/@skpaint_mix_raster.png'></a> | 82 src='https://fiddle.skia.org/i/@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 void draw(SkCanvas* canvas) { | 95 void draw(SkCanvas* canvas) { |
| 96 SkPoint points[2] = { | 96 SkPoint points[2] = { |
| 97 SkPoint::Make(0.0f, 0.0f), | 97 SkPoint::Make(0.0f, 0.0f), |
| 98 SkPoint::Make(256.0f, 256.0f) | 98 SkPoint::Make(256.0f, 256.0f) |
| 99 }; | 99 }; |
| 100 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 100 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
| 101 SkPaint paint; | 101 SkPaint paint; |
| 102 paint.setShader(SkGradientShader::MakeLinear( | 102 paint.setShader(SkGradientShader::MakeLinear( |
| 103 points, colors, nullptr, 2, | 103 points, colors, nullptr, 2, |
| 104 SkShader::kClamp_TileMode, 0, nullptr)); | 104 SkShader::kClamp_TileMode, 0, nullptr)); |
| 105 canvas->drawPaint(paint); | 105 canvas->drawPaint(paint); |
| 106 } | 106 } |
| 107 | 107 |
| 108 <a href='https://fiddle.skia.org/c/@skpaint_shader'><img | 108 <a href='https://fiddle.skia.org/c/@skpaint_shader'><img |
| 109 src='https://fiddle.skia.org/c/@skpaint_shader_raster.png'></a> | 109 src='https://fiddle.skia.org/i/@skpaint_shader_raster.png'></a> |
| 110 | 110 |
| 111 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 |
| 112 specified in the call to `MakeLinear()`. The shader object that is | 112 specified in the call to `MakeLinear()`. The shader object that is |
| 113 returned is reference-counted. Whenever any effects object, like a | 113 returned is reference-counted. Whenever any effects object, like a |
| 114 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 |
| 115 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 |
| 116 `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 |
| 117 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 |
| 118 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 |
| 119 if another shader (or null) is assigned to it. | 119 if another shader (or null) is assigned to it. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 (void)canvas->saveLayer(nullptr, nullptr); | 227 (void)canvas->saveLayer(nullptr, nullptr); |
| 228 canvas->clear(SK_ColorTRANSPARENT); | 228 canvas->clear(SK_ColorTRANSPARENT); |
| 229 canvas->drawPaint(dst); | 229 canvas->drawPaint(dst); |
| 230 src.setXfermodeMode(modes[i]); | 230 src.setXfermodeMode(modes[i]); |
| 231 canvas->drawPaint(src); | 231 canvas->drawPaint(src); |
| 232 canvas->drawRect(rect, stroke); | 232 canvas->drawRect(rect, stroke); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 <a href='https://fiddle.skia.org/c/@skpaint_xfer'><img | 236 <a href='https://fiddle.skia.org/c/@skpaint_xfer'><img |
| 237 src='https://fiddle.skia.org/c/@skpaint_xfer_raster.png'></a> | 237 src='https://fiddle.skia.org/i/@skpaint_xfer_raster.png'></a> |
| 238 | 238 |
| 239 <span id="ShShader"></span> | 239 <span id="ShShader"></span> |
| 240 | 240 |
| 241 ShShader | 241 ShShader |
| 242 -------- | 242 -------- |
| 243 | 243 |
| 244 Several shaders are defined (besides the linear gradient already mentioned): | 244 Several shaders are defined (besides the linear gradient already mentioned): |
| 245 | 245 |
| 246 * Bitmap Shader | 246 * Bitmap Shader |
| 247 | 247 |
| 248 <!--?prettify lang=cc?--> | 248 <!--?prettify lang=cc?--> |
| 249 | 249 |
| 250 canvas->clear(SK_ColorWHITE); | 250 canvas->clear(SK_ColorWHITE); |
| 251 SkMatrix matrix; | 251 SkMatrix matrix; |
| 252 matrix.setScale(0.75f, 0.75f); | 252 matrix.setScale(0.75f, 0.75f); |
| 253 matrix.preRotate(30.0f); | 253 matrix.preRotate(30.0f); |
| 254 SkPaint paint; | 254 SkPaint paint; |
| 255 paint.setShader(SkShader::MakeBitmapShader(source, | 255 paint.setShader(SkShader::MakeBitmapShader(source, |
| 256 SkShader::kRepeat_TileMode, | 256 SkShader::kRepeat_TileMode, |
| 257 SkShader::kRepeat_TileMode, | 257 SkShader::kRepeat_TileMode, |
| 258 &matrix)); | 258 &matrix)); |
| 259 canvas->drawPaint(paint); | 259 canvas->drawPaint(paint); |
| 260 | 260 |
| 261 <a href='https://fiddle.skia.org/c/@skpaint_bitmap_shader'><img | 261 <a href='https://fiddle.skia.org/c/@skpaint_bitmap_shader'><img |
| 262 src='https://fiddle.skia.org/c/@skpaint_bitmap_shader_raster.png'></a> | 262 src='https://fiddle.skia.org/i/@skpaint_bitmap_shader_raster.png'></a> |
| 263 | 263 |
| 264 * Radial Gradient Shader | 264 * Radial Gradient Shader |
| 265 | 265 |
| 266 <!--?prettify lang=cc?--> | 266 <!--?prettify lang=cc?--> |
| 267 | 267 |
| 268 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 268 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
| 269 SkPaint paint; | 269 SkPaint paint; |
| 270 paint.setShader(SkGradientShader::MakeRadial( | 270 paint.setShader(SkGradientShader::MakeRadial( |
| 271 SkPoint::Make(128.0f, 128.0f), 180.0f, | 271 SkPoint::Make(128.0f, 128.0f), 180.0f, |
| 272 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); | 272 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); |
| 273 canvas->drawPaint(paint); | 273 canvas->drawPaint(paint); |
| 274 | 274 |
| 275 <a href='https://fiddle.skia.org/c/@skpaint_radial'><img | 275 <a href='https://fiddle.skia.org/c/@skpaint_radial'><img |
| 276 src='https://fiddle.skia.org/c/@skpaint_radial_raster.png'></a> | 276 src='https://fiddle.skia.org/i/@skpaint_radial_raster.png'></a> |
| 277 | 277 |
| 278 * Two-Point Conical Gradient Shader | 278 * Two-Point Conical Gradient Shader |
| 279 | 279 |
| 280 <!--?prettify lang=cc?--> | 280 <!--?prettify lang=cc?--> |
| 281 | 281 |
| 282 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 282 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
| 283 SkPaint paint; | 283 SkPaint paint; |
| 284 paint.setShader(SkGradientShader::MakeTwoPointConical( | 284 paint.setShader(SkGradientShader::MakeTwoPointConical( |
| 285 SkPoint::Make(128.0f, 128.0f), 128.0f, | 285 SkPoint::Make(128.0f, 128.0f), 128.0f, |
| 286 SkPoint::Make(128.0f, 16.0f), 16.0f, | 286 SkPoint::Make(128.0f, 16.0f), 16.0f, |
| 287 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); | 287 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); |
| 288 canvas->drawPaint(paint); | 288 canvas->drawPaint(paint); |
| 289 | 289 |
| 290 <a href='https://fiddle.skia.org/c/@skpaint_2pt'><img | 290 <a href='https://fiddle.skia.org/c/@skpaint_2pt'><img |
| 291 src='https://fiddle.skia.org/c/@skpaint_2pt_raster.png'></a> | 291 src='https://fiddle.skia.org/i/@skpaint_2pt_raster.png'></a> |
| 292 | 292 |
| 293 | 293 |
| 294 * Sweep Gradient Shader | 294 * Sweep Gradient Shader |
| 295 | 295 |
| 296 <!--?prettify lang=cc?--> | 296 <!--?prettify lang=cc?--> |
| 297 | 297 |
| 298 SkColor colors[4] = { | 298 SkColor colors[4] = { |
| 299 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; | 299 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; |
| 300 SkPaint paint; | 300 SkPaint paint; |
| 301 paint.setShader(SkGradientShader::MakeSweep( | 301 paint.setShader(SkGradientShader::MakeSweep( |
| 302 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr)); | 302 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr)); |
| 303 canvas->drawPaint(paint); | 303 canvas->drawPaint(paint); |
| 304 | 304 |
| 305 <a href='https://fiddle.skia.org/c/@skpaint_sweep'><img | 305 <a href='https://fiddle.skia.org/c/@skpaint_sweep'><img |
| 306 src='https://fiddle.skia.org/c/@skpaint_sweep_raster.png'></a> | 306 src='https://fiddle.skia.org/i/@skpaint_sweep_raster.png'></a> |
| 307 | 307 |
| 308 * Fractal Perlin Noise Shader | 308 * Fractal Perlin Noise Shader |
| 309 | 309 |
| 310 <!--?prettify lang=cc?--> | 310 <!--?prettify lang=cc?--> |
| 311 | 311 |
| 312 canvas->clear(SK_ColorWHITE); | 312 canvas->clear(SK_ColorWHITE); |
| 313 SkPaint paint; | 313 SkPaint paint; |
| 314 paint.setShader(SkPerlinNoiseShader::MakeFractalNoise( | 314 paint.setShader(SkPerlinNoiseShader::MakeFractalNoise( |
| 315 0.05f, 0.05f, 4, 0.0f, nullptr)); | 315 0.05f, 0.05f, 4, 0.0f, nullptr)); |
| 316 canvas->drawPaint(paint); | 316 canvas->drawPaint(paint); |
| 317 | 317 |
| 318 <a href='https://fiddle.skia.org/c/@skpaint_perlin'><img | 318 <a href='https://fiddle.skia.org/c/@skpaint_perlin'><img |
| 319 src='https://fiddle.skia.org/c/@skpaint_perlin_raster.png'></a> | 319 src='https://fiddle.skia.org/i/@skpaint_perlin_raster.png'></a> |
| 320 | 320 |
| 321 * Turbulence Perlin Noise Shader | 321 * Turbulence Perlin Noise Shader |
| 322 | 322 |
| 323 <!--?prettify lang=cc?--> | 323 <!--?prettify lang=cc?--> |
| 324 | 324 |
| 325 canvas->clear(SK_ColorWHITE); | 325 canvas->clear(SK_ColorWHITE); |
| 326 SkPaint paint; | 326 SkPaint paint; |
| 327 paint.setShader(SkPerlinNoiseShader::MakeTurbulence( | 327 paint.setShader(SkPerlinNoiseShader::MakeTurbulence( |
| 328 0.05f, 0.05f, 4, 0.0f, nullptr)); | 328 0.05f, 0.05f, 4, 0.0f, nullptr)); |
| 329 canvas->drawPaint(paint); | 329 canvas->drawPaint(paint); |
| 330 | 330 |
| 331 <a href='https://fiddle.skia.org/c/@skpaint_turb'><img | 331 <a href='https://fiddle.skia.org/c/@skpaint_turb'><img |
| 332 src='https://fiddle.skia.org/c/@skpaint_turb_raster.png'></a> | 332 src='https://fiddle.skia.org/i/@skpaint_turb_raster.png'></a> |
| 333 | 333 |
| 334 * Compose Shader | 334 * Compose Shader |
| 335 | 335 |
| 336 <!--?prettify lang=cc?--> | 336 <!--?prettify lang=cc?--> |
| 337 | 337 |
| 338 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 338 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
| 339 SkPaint paint; | 339 SkPaint paint; |
| 340 paint.setShader( | 340 paint.setShader( |
| 341 SkShader::MakeComposeShader( | 341 SkShader::MakeComposeShader( |
| 342 SkGradientShader::MakeRadial( | 342 SkGradientShader::MakeRadial( |
| 343 SkPoint::Make(128.0f, 128.0f), 180.0f, | 343 SkPoint::Make(128.0f, 128.0f), 180.0f, |
| 344 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr), | 344 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr), |
| 345 SkPerlinNoiseShader::MakeTurbulence(0.025f, 0.025f, 2, 0.0f, nul
lptr), | 345 SkPerlinNoiseShader::MakeTurbulence(0.025f, 0.025f, 2, 0.0f, nul
lptr), |
| 346 SkXfermode::kDifference_Mode) | 346 SkXfermode::kDifference_Mode) |
| 347 ); | 347 ); |
| 348 canvas->drawPaint(paint); | 348 canvas->drawPaint(paint); |
| 349 | 349 |
| 350 <a href='https://fiddle.skia.org/c/@skpaint_compose_shader'><img | 350 <a href='https://fiddle.skia.org/c/@skpaint_compose_shader'><img |
| 351 src='https://fiddle.skia.org/c/@skpaint_compose_shader_raster.png'></a> | 351 src='https://fiddle.skia.org/i/@skpaint_compose_shader_raster.png'></a> |
| 352 | 352 |
| 353 | 353 |
| 354 <span id="SkMaskFilter"></span> | 354 <span id="SkMaskFilter"></span> |
| 355 | 355 |
| 356 SkMaskFilter | 356 SkMaskFilter |
| 357 ------------ | 357 ------------ |
| 358 | 358 |
| 359 * Blur Mask Filter | 359 * Blur Mask Filter |
| 360 | 360 |
| 361 <!--?prettify lang=cc?--> | 361 <!--?prettify lang=cc?--> |
| 362 | 362 |
| 363 canvas->drawText(text, strlen(text), 0, 160, paint); | 363 canvas->drawText(text, strlen(text), 0, 160, paint); |
| 364 canvas->drawColor(SK_ColorWHITE); | 364 canvas->drawColor(SK_ColorWHITE); |
| 365 SkPaint paint; | 365 SkPaint paint; |
| 366 paint.setAntiAlias(true); | 366 paint.setAntiAlias(true); |
| 367 paint.setTextSize(120); | 367 paint.setTextSize(120); |
| 368 paint.setMaskFilter(SkBlurMaskFilter::Make( | 368 paint.setMaskFilter(SkBlurMaskFilter::Make( |
| 369 kNormal_SkBlurStyle, 5.0f, 0)); | 369 kNormal_SkBlurStyle, 5.0f, 0)); |
| 370 const char text[] = "Skia"; | 370 const char text[] = "Skia"; |
| 371 canvas->drawText(text, strlen(text), 0, 160, paint); | 371 canvas->drawText(text, strlen(text), 0, 160, paint); |
| 372 | 372 |
| 373 <a href='https://fiddle.skia.org/c/@skpaint_blur_mask_filter'><img | 373 <a href='https://fiddle.skia.org/c/@skpaint_blur_mask_filter'><img |
| 374 src='https://fiddle.skia.org/c/@skpaint_blur_mask_filter_raster.png'></a> | 374 src='https://fiddle.skia.org/i/@skpaint_blur_mask_filter_raster.png'></a> |
| 375 | 375 |
| 376 * Emboss Mask Filter | 376 * Emboss Mask Filter |
| 377 | 377 |
| 378 <!--?prettify lang=cc?--> | 378 <!--?prettify lang=cc?--> |
| 379 | 379 |
| 380 canvas->drawColor(SK_ColorWHITE); | 380 canvas->drawColor(SK_ColorWHITE); |
| 381 SkPaint paint; | 381 SkPaint paint; |
| 382 paint.setAntiAlias(true); | 382 paint.setAntiAlias(true); |
| 383 paint.setTextSize(120); | 383 paint.setTextSize(120); |
| 384 SkScalar direction[3] = {1.0f, 1.0f, 1.0f}; | 384 SkScalar direction[3] = {1.0f, 1.0f, 1.0f}; |
| 385 paint.setMaskFilter(SkBlurMaskFilter::MakeEmboss( | 385 paint.setMaskFilter(SkBlurMaskFilter::MakeEmboss( |
| 386 2.0f, direction, 0.3f, 0.1f)); | 386 2.0f, direction, 0.3f, 0.1f)); |
| 387 const char text[] = "Skia"; | 387 const char text[] = "Skia"; |
| 388 canvas->drawText(text, strlen(text), 0, 160, paint); | 388 canvas->drawText(text, strlen(text), 0, 160, paint); |
| 389 | 389 |
| 390 <a href='https://fiddle.skia.org/c/@skpaint_emboss'><img | 390 <a href='https://fiddle.skia.org/c/@skpaint_emboss'><img |
| 391 src='https://fiddle.skia.org/c/@skpaint_emboss_raster.png'></a> | 391 src='https://fiddle.skia.org/i/@skpaint_emboss_raster.png'></a> |
| 392 | 392 |
| 393 | 393 |
| 394 <span id="SkColorFilter"></span> | 394 <span id="SkColorFilter"></span> |
| 395 | 395 |
| 396 SkColorFilter | 396 SkColorFilter |
| 397 ------------- | 397 ------------- |
| 398 | 398 |
| 399 * Color Matrix Color Filter | 399 * Color Matrix Color Filter |
| 400 | 400 |
| 401 <!--?prettify lang=cc?--> | 401 <!--?prettify lang=cc?--> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 459 |
| 460 SkScalar inverter[20] = { | 460 SkScalar inverter[20] = { |
| 461 -1, 0, 0, 0, 255, | 461 -1, 0, 0, 0, 255, |
| 462 0, -1, 0, 0, 255, | 462 0, -1, 0, 0, 255, |
| 463 0, 0, -1, 0, 255, | 463 0, 0, -1, 0, 255, |
| 464 0, 0, 0, 1, 0}; | 464 0, 0, 0, 1, 0}; |
| 465 f(c, 1536, 512, inverter); | 465 f(c, 1536, 512, inverter); |
| 466 } | 466 } |
| 467 | 467 |
| 468 <a href='https://fiddle.skia.org/c/@skpaint_matrix_color_filter'><img | 468 <a href='https://fiddle.skia.org/c/@skpaint_matrix_color_filter'><img |
| 469 src='https://fiddle.skia.org/c/@skpaint_matrix_color_filter_raster.png'></a> | 469 src='https://fiddle.skia.org/i/@skpaint_matrix_color_filter_raster.png'></a> |
| 470 | 470 |
| 471 * Color Table Color Filter | 471 * Color Table Color Filter |
| 472 | 472 |
| 473 <!--?prettify lang=cc?--> | 473 <!--?prettify lang=cc?--> |
| 474 | 474 |
| 475 void draw(SkCanvas* canvas) { | 475 void draw(SkCanvas* canvas) { |
| 476 canvas->scale(0.5, 0.5); | 476 canvas->scale(0.5, 0.5); |
| 477 uint8_t ct[256]; | 477 uint8_t ct[256]; |
| 478 for (int i = 0; i < 256; ++i) { | 478 for (int i = 0; i < 256; ++i) { |
| 479 int x = (i - 96) * 255 / 64; | 479 int x = (i - 96) * 255 / 64; |
| 480 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; | 480 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; |
| 481 } | 481 } |
| 482 SkPaint paint; | 482 SkPaint paint; |
| 483 paint.setColorFilter(SkTableColorFilter::MakeARGB(nullptr, ct, ct, ct)
); | 483 paint.setColorFilter(SkTableColorFilter::MakeARGB(nullptr, ct, ct, ct)
); |
| 484 canvas->drawBitmap(source, 0, 0, &paint); | 484 canvas->drawBitmap(source, 0, 0, &paint); |
| 485 } | 485 } |
| 486 | 486 |
| 487 <a href='https://fiddle.skia.org/c/@skpaint_color_table_filter'><img | 487 <a href='https://fiddle.skia.org/c/@skpaint_color_table_filter'><img |
| 488 src='https://fiddle.skia.org/c/@skpaint_color_table_filter_raster.png'></a
> | 488 src='https://fiddle.skia.org/i/@skpaint_color_table_filter_raster.png'></a
> |
| 489 | 489 |
| 490 | 490 |
| 491 <span id="SkPathEffect"></span> | 491 <span id="SkPathEffect"></span> |
| 492 | 492 |
| 493 SkPathEffect | 493 SkPathEffect |
| 494 ------------ | 494 ------------ |
| 495 | 495 |
| 496 * SkPath2DPathEffect: Stamp the specified path to fill the shape, | 496 * SkPath2DPathEffect: Stamp the specified path to fill the shape, |
| 497 using the matrix to define the latice. | 497 using the matrix to define the latice. |
| 498 | 498 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 513 paint.setPathEffect(SkPath2DPathEffect::Make(matrix, path)); | 513 paint.setPathEffect(SkPath2DPathEffect::Make(matrix, path)); |
| 514 paint.setAntiAlias(true); | 514 paint.setAntiAlias(true); |
| 515 canvas->clear(SK_ColorWHITE); | 515 canvas->clear(SK_ColorWHITE); |
| 516 SkRect bounds; | 516 SkRect bounds; |
| 517 (void)canvas->getClipBounds(&bounds); | 517 (void)canvas->getClipBounds(&bounds); |
| 518 bounds.outset(2 * scale, 2 * scale); | 518 bounds.outset(2 * scale, 2 * scale); |
| 519 canvas->drawRect(bounds, paint); | 519 canvas->drawRect(bounds, paint); |
| 520 } | 520 } |
| 521 | 521 |
| 522 <a href='https://fiddle.skia.org/c/@skpaint_path_2d_path_effect'><img | 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> | 523 src='https://fiddle.skia.org/i/@skpaint_path_2d_path_effect_raster.png'></
a> |
| 524 | 524 |
| 525 * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the | 525 * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the |
| 526 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. |
| 527 | 527 |
| 528 <!--?prettify lang=cc?--> | 528 <!--?prettify lang=cc?--> |
| 529 | 529 |
| 530 void draw(SkCanvas* canvas) { | 530 void draw(SkCanvas* canvas) { |
| 531 SkPaint paint; | 531 SkPaint paint; |
| 532 SkMatrix lattice; | 532 SkMatrix lattice; |
| 533 lattice.setScale(8.0f, 8.0f); | 533 lattice.setScale(8.0f, 8.0f); |
| 534 lattice.preRotate(30.0f); | 534 lattice.preRotate(30.0f); |
| 535 paint.setPathEffect(SkLine2DPathEffect::Make(0.0f, lattice)); | 535 paint.setPathEffect(SkLine2DPathEffect::Make(0.0f, lattice)); |
| 536 paint.setAntiAlias(true); | 536 paint.setAntiAlias(true); |
| 537 SkRect bounds; | 537 SkRect bounds; |
| 538 (void)canvas->getClipBounds(&bounds); | 538 (void)canvas->getClipBounds(&bounds); |
| 539 bounds.outset(8.0f, 8.0f); | 539 bounds.outset(8.0f, 8.0f); |
| 540 canvas->clear(SK_ColorWHITE); | 540 canvas->clear(SK_ColorWHITE); |
| 541 canvas->drawRect(bounds, paint); | 541 canvas->drawRect(bounds, paint); |
| 542 } | 542 } |
| 543 | 543 |
| 544 <a href='https://fiddle.skia.org/c/@skpaint_line_2d_path_effect'><img | 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> | 545 src='https://fiddle.skia.org/i/@skpaint_line_2d_path_effect_raster.png'></
a> |
| 546 | 546 |
| 547 * 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. |
| 548 | 548 |
| 549 <!--?prettify lang=cc?--> | 549 <!--?prettify lang=cc?--> |
| 550 | 550 |
| 551 void draw(SkCanvas* canvas) { | 551 void draw(SkCanvas* canvas) { |
| 552 SkPaint paint; | 552 SkPaint paint; |
| 553 SkPath path; | 553 SkPath path; |
| 554 path.addOval(SkRect::MakeWH(16.0f, 6.0f)); | 554 path.addOval(SkRect::MakeWH(16.0f, 6.0f)); |
| 555 paint.setPathEffect(SkPath1DPathEffect::Make( | 555 paint.setPathEffect(SkPath1DPathEffect::Make( |
| 556 path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style)); | 556 path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style)); |
| 557 paint.setAntiAlias(true); | 557 paint.setAntiAlias(true); |
| 558 canvas->clear(SK_ColorWHITE); | 558 canvas->clear(SK_ColorWHITE); |
| 559 canvas->drawCircle(128.0f, 128.0f, 122.0f, paint); | 559 canvas->drawCircle(128.0f, 128.0f, 122.0f, paint); |
| 560 } | 560 } |
| 561 | 561 |
| 562 <a href='https://fiddle.skia.org/c/@skpaint_path_1d_path_effect'><img | 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> | 563 src='https://fiddle.skia.org/i/@skpaint_path_1d_path_effect_raster.png'></
a> |
| 564 | 564 |
| 565 * SkArcToPathEffect | 565 * SkArcToPathEffect |
| 566 | 566 |
| 567 The following few examples use this function: | 567 The following few examples use this function: |
| 568 | 568 |
| 569 <!--?prettify lang=cc?--> | 569 <!--?prettify lang=cc?--> |
| 570 | 570 |
| 571 SkPath star() { | 571 SkPath star() { |
| 572 const SkScalar R = 115.2f, C = 128.0f; | 572 const SkScalar R = 115.2f, C = 128.0f; |
| 573 SkPath path; | 573 SkPath path; |
| 574 path.moveTo(C + R, C); | 574 path.moveTo(C + R, C); |
| 575 for (int i = 1; i < 8; ++i) { | 575 for (int i = 1; i < 8; ++i) { |
| 576 SkScalar a = 2.6927937f * i; | 576 SkScalar a = 2.6927937f * i; |
| 577 path.lineTo(C + R * cos(a), C + R * sin(a)); | 577 path.lineTo(C + R * cos(a), C + R * sin(a)); |
| 578 } | 578 } |
| 579 return path; | 579 return path; |
| 580 } | 580 } |
| 581 void draw(SkCanvas* canvas) { | 581 void draw(SkCanvas* canvas) { |
| 582 SkPaint paint; | 582 SkPaint paint; |
| 583 paint.setPathEffect(SkArcToPathEffect::Make(8.0f)); | 583 paint.setPathEffect(SkArcToPathEffect::Make(8.0f)); |
| 584 paint.setStyle(SkPaint::kStroke_Style); | 584 paint.setStyle(SkPaint::kStroke_Style); |
| 585 paint.setAntiAlias(true); | 585 paint.setAntiAlias(true); |
| 586 canvas->clear(SK_ColorWHITE); | 586 canvas->clear(SK_ColorWHITE); |
| 587 SkPath path(star()); | 587 SkPath path(star()); |
| 588 canvas->drawPath(path, paint); | 588 canvas->drawPath(path, paint); |
| 589 } | 589 } |
| 590 | 590 |
| 591 <a href='https://fiddle.skia.org/c/@skpaint_arc_to_path_effect'><img | 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
> | 592 src='https://fiddle.skia.org/i/@skpaint_arc_to_path_effect_raster.png'></a
> |
| 593 | 593 |
| 594 | 594 |
| 595 * SkCornerPathEffect: a path effect that can turn sharp corners into | 595 * SkCornerPathEffect: a path effect that can turn sharp corners into |
| 596 various treatments (e.g. rounded corners). | 596 various treatments (e.g. rounded corners). |
| 597 | 597 |
| 598 <!--?prettify lang=cc?--> | 598 <!--?prettify lang=cc?--> |
| 599 | 599 |
| 600 void draw(SkCanvas* canvas) { | 600 void draw(SkCanvas* canvas) { |
| 601 SkPaint paint; | 601 SkPaint paint; |
| 602 paint.setPathEffect(SkCornerPathEffect::Make(32.0f)); | 602 paint.setPathEffect(SkCornerPathEffect::Make(32.0f)); |
| 603 paint.setStyle(SkPaint::kStroke_Style); | 603 paint.setStyle(SkPaint::kStroke_Style); |
| 604 paint.setAntiAlias(true); | 604 paint.setAntiAlias(true); |
| 605 canvas->clear(SK_ColorWHITE); | 605 canvas->clear(SK_ColorWHITE); |
| 606 const SkScalar R = 115.2f; | 606 const SkScalar R = 115.2f; |
| 607 SkPath path(star()); | 607 SkPath path(star()); |
| 608 canvas->drawPath(path, paint); | 608 canvas->drawPath(path, paint); |
| 609 } | 609 } |
| 610 | 610 |
| 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> | 611 <a href='https://fiddle.skia.org/c/@skpaint_corner_path_effects'><img src='h
ttps://fiddle.skia.org/i/@skpaint_corner_path_effects_raster.png'></a> |
| 612 | 612 |
| 613 * SkDashPathEffect: a path effect that implements dashing. | 613 * SkDashPathEffect: a path effect that implements dashing. |
| 614 | 614 |
| 615 <!--?prettify lang=cc?--> | 615 <!--?prettify lang=cc?--> |
| 616 | 616 |
| 617 void draw(SkCanvas* canvas) { | 617 void draw(SkCanvas* canvas) { |
| 618 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; | 618 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; |
| 619 size_t count = sizeof(intervals) / sizeof(intervals[0]); | 619 size_t count = sizeof(intervals) / sizeof(intervals[0]); |
| 620 SkPaint paint; | 620 SkPaint paint; |
| 621 paint.setPathEffect(SkDashPathEffect::Make(intervals, count, 0.0f)); | 621 paint.setPathEffect(SkDashPathEffect::Make(intervals, count, 0.0f)); |
| 622 paint.setStyle(SkPaint::kStroke_Style); | 622 paint.setStyle(SkPaint::kStroke_Style); |
| 623 paint.setStrokeWidth(2.0f); | 623 paint.setStrokeWidth(2.0f); |
| 624 paint.setAntiAlias(true); | 624 paint.setAntiAlias(true); |
| 625 canvas->clear(SK_ColorWHITE); | 625 canvas->clear(SK_ColorWHITE); |
| 626 SkPath path(star()); | 626 SkPath path(star()); |
| 627 canvas->drawPath(path, paint); | 627 canvas->drawPath(path, paint); |
| 628 } | 628 } |
| 629 | 629 |
| 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> | 630 <a href='https://fiddle.skia.org/c/@skpaint_dash_path_effect'><img src='http
s://fiddle.skia.org/i/@skpaint_dash_path_effect_raster.png'></a> |
| 631 | 631 |
| 632 * SkDiscretePathEffect: This path effect chops a path into discrete | 632 * SkDiscretePathEffect: This path effect chops a path into discrete |
| 633 segments, and randomly displaces them. | 633 segments, and randomly displaces them. |
| 634 | 634 |
| 635 <!--?prettify lang=cc?--> | 635 <!--?prettify lang=cc?--> |
| 636 | 636 |
| 637 void draw(SkCanvas* canvas) { | 637 void draw(SkCanvas* canvas) { |
| 638 SkPaint paint; | 638 SkPaint paint; |
| 639 paint.setPathEffect(SkDiscretePathEffect::Make(10.0f, 4.0f)); | 639 paint.setPathEffect(SkDiscretePathEffect::Make(10.0f, 4.0f)); |
| 640 paint.setStyle(SkPaint::kStroke_Style); | 640 paint.setStyle(SkPaint::kStroke_Style); |
| 641 paint.setStrokeWidth(2.0f); | 641 paint.setStrokeWidth(2.0f); |
| 642 paint.setAntiAlias(true); | 642 paint.setAntiAlias(true); |
| 643 canvas->clear(SK_ColorWHITE); | 643 canvas->clear(SK_ColorWHITE); |
| 644 SkPath path(star()); | 644 SkPath path(star()); |
| 645 canvas->drawPath(path, paint); | 645 canvas->drawPath(path, paint); |
| 646 } | 646 } |
| 647 | 647 |
| 648 <a href='https://fiddle.skia.org/c/@skpaint_discrete_path_effect'><img | 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> | 649 src='https://fiddle.skia.org/i/@skpaint_discrete_path_effect_raster.png'><
/a> |
| 650 | 650 |
| 651 * SkComposePathEffect: a pathEffect whose effect is to apply | 651 * SkComposePathEffect: a pathEffect whose effect is to apply |
| 652 first the inner pathEffect and the the outer pathEffect (i.e. | 652 first the inner pathEffect and the the outer pathEffect (i.e. |
| 653 outer(inner(path))). | 653 outer(inner(path))). |
| 654 | 654 |
| 655 <!--?prettify lang=cc?--> | 655 <!--?prettify lang=cc?--> |
| 656 | 656 |
| 657 void draw(SkCanvas* canvas) { | 657 void draw(SkCanvas* canvas) { |
| 658 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; | 658 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; |
| 659 size_t count = sizeof(intervals) / sizeof(intervals[0]); | 659 size_t count = sizeof(intervals) / sizeof(intervals[0]); |
| 660 SkPaint paint; | 660 SkPaint paint; |
| 661 paint.setPathEffect(SkComposePathEffect::Make( | 661 paint.setPathEffect(SkComposePathEffect::Make( |
| 662 SkDashPathEffect::Make(intervals, count, 0.0f), | 662 SkDashPathEffect::Make(intervals, count, 0.0f), |
| 663 SkDiscretePathEffect::Make(10.0f, 4.0f) | 663 SkDiscretePathEffect::Make(10.0f, 4.0f) |
| 664 )); | 664 )); |
| 665 paint.setStyle(SkPaint::kStroke_Style); | 665 paint.setStyle(SkPaint::kStroke_Style); |
| 666 paint.setStrokeWidth(2.0f); | 666 paint.setStrokeWidth(2.0f); |
| 667 paint.setAntiAlias(true); | 667 paint.setAntiAlias(true); |
| 668 canvas->clear(SK_ColorWHITE); | 668 canvas->clear(SK_ColorWHITE); |
| 669 SkPath path(star()); | 669 SkPath path(star()); |
| 670 canvas->drawPath(path, paint); | 670 canvas->drawPath(path, paint); |
| 671 } | 671 } |
| 672 | 672 |
| 673 <a href='https://fiddle.skia.org/c/@skpaint_compose_path_effect'><img | 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> | 674 src='https://fiddle.skia.org/i/@skpaint_compose_path_effect_raster.png'></
a> |
| 675 | 675 |
| 676 * SkSumPathEffect: a pathEffect whose effect is to apply two effects, | 676 * SkSumPathEffect: a pathEffect whose effect is to apply two effects, |
| 677 in sequence (i.e. first(path) + second(path)). | 677 in sequence (i.e. first(path) + second(path)). |
| 678 | 678 |
| 679 <!--?prettify lang=cc?--> | 679 <!--?prettify lang=cc?--> |
| 680 | 680 |
| 681 void draw(SkCanvas* canvas) { | 681 void draw(SkCanvas* canvas) { |
| 682 SkPaint paint; | 682 SkPaint paint; |
| 683 paint.setPathEffect(SkSumPathEffect::Make( | 683 paint.setPathEffect(SkSumPathEffect::Make( |
| 684 SkDiscretePathEffect::Make(10.0f, 4.0f), | 684 SkDiscretePathEffect::Make(10.0f, 4.0f), |
| 685 SkDiscretePathEffect::Make(10.0f, 4.0f, 1245u) | 685 SkDiscretePathEffect::Make(10.0f, 4.0f, 1245u) |
| 686 )); | 686 )); |
| 687 paint.setStyle(SkPaint::kStroke_Style); | 687 paint.setStyle(SkPaint::kStroke_Style); |
| 688 paint.setStrokeWidth(2.0f); | 688 paint.setStrokeWidth(2.0f); |
| 689 paint.setAntiAlias(true); | 689 paint.setAntiAlias(true); |
| 690 canvas->clear(SK_ColorWHITE); | 690 canvas->clear(SK_ColorWHITE); |
| 691 SkPath path(star()); | 691 SkPath path(star()); |
| 692 canvas->drawPath(path, paint); | 692 canvas->drawPath(path, paint); |
| 693 } | 693 } |
| 694 | 694 |
| 695 <a href='https://fiddle.skia.org/c/@skpaint_sum_path_effect'><img | 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> | 696 src='https://fiddle.skia.org/i/@skpaint_sum_path_effect_raster.png'></a> |
| 697 | 697 |
| OLD | NEW |