Chromium Code Reviews| 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 |
| 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 Loading... | |
| 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 |
|
jcgregorio
2016/04/22 15:31:47
Does the text after this, about reference-counting
hal.canary
2016/04/22 15:36:00
yes
jcgregorio
2016/04/22 15:43:21
OK, to what? Or do you want to tackle that in a se
| |
| 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 Loading... | |
| 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 = | 254 SkPaint paint; |
| 257 SkShader::CreateBitmapShader( | 255 paint.setShader(SkShader::MakeBitmapShader( |
| 258 source, | 256 source, |
| 259 SkShader::kRepeat_TileMode , | 257 SkShader::kRepeat_TileMode , |
|
hal.canary
2016/04/22 15:36:00
indentation
jcgregorio
2016/04/22 15:43:21
Fixed.
| |
| 260 SkShader::kRepeat_TileMode , | 258 SkShader::kRepeat_TileMode , |
| 261 &matrix); | 259 &matrix)); |
| 262 SkPaint paint; | |
| 263 paint.setShader(shader); | |
| 264 shader->unref(); | |
| 265 canvas->drawPaint(paint); | 260 canvas->drawPaint(paint); |
| 266 | 261 |
| 267 <a href="https://fiddle.skia.org/c/0e8d08e0a0b342e9e45c364d0e5cea8a"> | 262 <a href='https://fiddle.skia.org/c/@skpaint_bitmap_shader'><img |
| 268 <img src="https://fiddle.skia.org/i/0e8d08e0a0b342e9e45c364d0e5cea8a_raster. png"></a> | 263 src='https://fiddle.skia.org/c/@skpaint_bitmap_shader_raster.png'></a> |
| 269 | 264 |
| 270 * Radial Gradient Shader | 265 * Radial Gradient Shader |
| 271 | 266 |
| 272 <!--?prettify lang=cc?--> | 267 <!--?prettify lang=cc?--> |
| 273 | 268 |
| 274 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 269 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; | 270 SkPaint paint; |
| 280 paint.setShader(shader); | 271 paint.setShader(SkGradientShader::MakeRadial( |
| 281 shader->unref(); | 272 SkPoint::Make(128.0f, 128.0f), 180.0f, |
| 273 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); | |
| 282 canvas->drawPaint(paint); | 274 canvas->drawPaint(paint); |
| 283 | 275 |
| 284 <a href="https://fiddle.skia.org/c/601abd2819e38365900bf62286986024"> | 276 <a href='https://fiddle.skia.org/c/@skpaint_radial'><img |
| 285 <img src="https://fiddle.skia.org/i/601abd2819e38365900bf62286986024_raster. png"></a> | 277 src='https://fiddle.skia.org/c/@skpaint_radial_raster.png'></a> |
| 286 | 278 |
| 287 * Two-Point Conical Gradient Shader | 279 * Two-Point Conical Gradient Shader |
| 288 | 280 |
| 289 <!--?prettify lang=cc?--> | 281 <!--?prettify lang=cc?--> |
| 290 | 282 |
| 291 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 283 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; | 284 SkPaint paint; |
| 298 paint.setShader(shader); | 285 paint.setShader(SkGradientShader::MakeTwoPointConical( |
| 299 shader->unref(); | 286 SkPoint::Make(128.0f, 128.0f), 128.0f, |
| 287 SkPoint::Make(128.0f, 16.0f), 16.0f, | |
| 288 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); | |
| 300 canvas->drawPaint(paint); | 289 canvas->drawPaint(paint); |
| 301 | 290 |
| 302 <a href="https://fiddle.skia.org/c/991f7d67ff1ccebd6c2c4fab18a76edc"> | 291 <a href='https://fiddle.skia.org/c/@skpaint_2pt'><img |
| 303 <img src="https://fiddle.skia.org/i/991f7d67ff1ccebd6c2c4fab18a76edc_raster. png"></a> | 292 src='https://fiddle.skia.org/c/@skpaint_2pt_raster.png'></a> |
| 304 | 293 |
| 305 | 294 |
| 306 * Sweep Gradient Shader | 295 * Sweep Gradient Shader |
| 307 | 296 |
| 308 <!--?prettify lang=cc?--> | 297 <!--?prettify lang=cc?--> |
| 309 | 298 |
| 310 SkColor colors[4] = { | 299 SkColor colors[4] = { |
| 311 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; | 300 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; | 301 SkPaint paint; |
| 316 paint.setShader(shader); | 302 paint.setShader(SkGradientShader::MakeSweep( |
| 317 shader->unref(); | 303 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr)); |
| 318 canvas->drawPaint(paint); | 304 canvas->drawPaint(paint); |
| 319 | 305 |
| 320 <a href="https://fiddle.skia.org/c/cee9d1831f6679c3d88170f857995d12"> | 306 <a href='https://fiddle.skia.org/c/@skpaint_sweep'><img |
| 321 <img src="https://fiddle.skia.org/i/cee9d1831f6679c3d88170f857995d12_raster. png"></a> | 307 src='https://fiddle.skia.org/c/@skpaint_sweep_raster.png'></a> |
| 322 | 308 |
| 323 * Fractal Perlin Noise Shader | 309 * Fractal Perlin Noise Shader |
| 324 | 310 |
| 325 <!--?prettify lang=cc?--> | 311 <!--?prettify lang=cc?--> |
| 326 | 312 |
| 327 canvas->clear(SK_ColorWHITE); | 313 canvas->clear(SK_ColorWHITE); |
| 328 SkShader* shader = SkPerlinNoiseShader::CreateFractalNoise( | |
| 329 0.05f, 0.05f, 4, 0.0f, nullptr); | |
| 330 SkPaint paint; | 314 SkPaint paint; |
| 331 paint.setShader(shader); | 315 paint.setShader(SkPerlinNoiseShader::MakeFractalNoise( |
| 332 shader->unref(); | 316 0.05f, 0.05f, 4, 0.0f, nullptr)); |
| 333 canvas->drawPaint(paint); | 317 canvas->drawPaint(paint); |
| 334 | 318 |
| 335 <a href="https://fiddle.skia.org/c/cc45c5349c3b31f97da7c1af7f84162a"> | 319 <a href='https://fiddle.skia.org/c/@skpaint_perlin'><img |
| 336 <img src="https://fiddle.skia.org/i/cc45c5349c3b31f97da7c1af7f84162a_raster. png"></a> | 320 src='https://fiddle.skia.org/c/@skpaint_perlin_raster.png'></a> |
| 337 | 321 |
| 338 * Turbulence Perlin Noise Shader | 322 * Turbulence Perlin Noise Shader |
| 339 | 323 |
| 340 <!--?prettify lang=cc?--> | 324 <!--?prettify lang=cc?--> |
| 341 | 325 |
| 342 canvas->clear(SK_ColorWHITE); | 326 canvas->clear(SK_ColorWHITE); |
| 343 SkShader* shader = SkPerlinNoiseShader::CreateTurbulence( | |
| 344 0.05f, 0.05f, 4, 0.0f, nullptr); | |
| 345 SkPaint paint; | 327 SkPaint paint; |
| 346 paint.setShader(shader); | 328 paint.setShader(SkPerlinNoiseShader::MakeTurbulence( |
| 347 shader->unref(); | 329 0.05f, 0.05f, 4, 0.0f, nullptr)); |
| 348 canvas->drawPaint(paint); | 330 canvas->drawPaint(paint); |
| 349 | 331 |
| 350 <a href="https://fiddle.skia.org/c/52729ed3a71b89a6dba4f60e8eb67727"> | 332 <a href='https://fiddle.skia.org/c/@skpaint_turb'><img |
| 351 <img src="https://fiddle.skia.org/i/52729ed3a71b89a6dba4f60e8eb67727_raster. png"></a> | 333 src='https://fiddle.skia.org/c/@skpaint_turb_raster.png'></a> |
| 352 | 334 |
| 353 * Compose Shader | 335 * Compose Shader |
| 354 | 336 |
| 355 <!--?prettify lang=cc?--> | 337 <!--?prettify lang=cc?--> |
| 356 | 338 |
| 357 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; | 339 SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; |
| 358 SkShader* shader1 = | 340 SkPaint paint; |
| 359 SkGradientShader::CreateRadial( | 341 paint.setShader( |
| 342 SkShader::MakeComposeShader( | |
| 343 SkGradientShader::MakeRadial( | |
| 360 SkPoint::Make(128.0f, 128.0f), 180.0f, | 344 SkPoint::Make(128.0f, 128.0f), 180.0f, |
| 361 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr); | 345 colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr), |
| 362 SkShader* shader2 = SkPerlinNoiseShader::CreateTurbulence( | 346 SkPerlinNoiseShader::MakeTurbulence(0.025f, 0.025f, 2, 0.0f, nul lptr), |
| 363 0.025f, 0.025f, 2, 0.0f, nullptr); | 347 SkXfermode::kDifference_Mode) |
| 364 SkShader* shader = | 348 ); |
| 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); | 349 canvas->drawPaint(paint); |
| 372 | 350 |
| 373 <a href="https://fiddle.skia.org/c/1209b7a29d870302edcc43dc0916e8d5"> | 351 <a href='https://fiddle.skia.org/c/@skpaint_compose_shader'><img |
| 374 <img src="https://fiddle.skia.org/i/1209b7a29d870302edcc43dc0916e8d5_raster. png"></a> | 352 src='https://fiddle.skia.org/c/@skpaint_compose_shader_raster.png'></a> |
| 375 | 353 |
| 376 | 354 |
| 377 <span id="SkMaskFilter"></span> | 355 <span id="SkMaskFilter"></span> |
| 378 | 356 |
| 379 SkMaskFilter | 357 SkMaskFilter |
| 380 ------------ | 358 ------------ |
| 381 | 359 |
| 382 * Blur Mask Filter | 360 * Blur Mask Filter |
| 383 | 361 |
| 384 <!--?prettify lang=cc?--> | 362 <!--?prettify lang=cc?--> |
| 385 | 363 |
| 364 canvas->drawText(text, strlen(text), 0, 160, paint); | |
| 386 canvas->drawColor(SK_ColorWHITE); | 365 canvas->drawColor(SK_ColorWHITE); |
| 387 SkPaint paint; | 366 SkPaint paint; |
| 388 paint.setAntiAlias(true); | 367 paint.setAntiAlias(true); |
| 389 paint.setTextSize(120); | 368 paint.setTextSize(120); |
| 390 SkMaskFilter* filter = | 369 paint.setMaskFilter(SkBlurMaskFilter::Make( |
| 391 SkBlurMaskFilter::Create( | 370 kNormal_SkBlurStyle, 5.0f, 0)); |
| 392 kNormal_SkBlurStyle, 5.0f, 0); | |
| 393 paint.setMaskFilter(filter); | |
| 394 filter->unref(); | |
| 395 const char text[] = "Skia"; | 371 const char text[] = "Skia"; |
| 396 canvas->drawText(text, strlen(text), 0, 160, paint); | 372 canvas->drawText(text, strlen(text), 0, 160, paint); |
| 397 | 373 |
| 398 <a href="https://fiddle.skia.org/c/0e004664122851691d67a291007b64d7"> | 374 <a href='https://fiddle.skia.org/c/@skpaint_blur_mask_filter'><img |
| 399 <img src="https://fiddle.skia.org/i/0e004664122851691d67a291007b64d7_raster. png"></a> | 375 src='https://fiddle.skia.org/c/@skpaint_blur_mask_filter_raster.png'></a> |
| 400 | 376 |
| 401 * Emboss Mask Filter | 377 * Emboss Mask Filter |
| 402 | 378 |
| 403 <!--?prettify lang=cc?--> | 379 <!--?prettify lang=cc?--> |
| 404 | 380 |
| 405 canvas->drawColor(SK_ColorWHITE); | 381 canvas->drawColor(SK_ColorWHITE); |
| 406 SkPaint paint; | 382 SkPaint paint; |
| 407 paint.setAntiAlias(true); | 383 paint.setAntiAlias(true); |
| 408 paint.setTextSize(120); | 384 paint.setTextSize(120); |
| 409 SkScalar direction[3] = {1.0f, 1.0f, 1.0f}; | 385 SkScalar direction[3] = {1.0f, 1.0f, 1.0f}; |
| 410 SkMaskFilter* filter = | 386 paint.setMaskFilter(SkBlurMaskFilter::MakeEmboss( |
| 411 SkBlurMaskFilter::CreateEmboss( | 387 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"; | 388 const char text[] = "Skia"; |
| 416 canvas->drawText(text, strlen(text), 0, 160, paint); | 389 canvas->drawText(text, strlen(text), 0, 160, paint); |
| 417 | 390 |
| 418 <a href="https://fiddle.skia.org/c/1ef71be7fb749a2d81a55721b2d2c77d"> | 391 <a href='https://fiddle.skia.org/c/@skpaint_emboss'><img |
| 419 <img src="https://fiddle.skia.org/i/1ef71be7fb749a2d81a55721b2d2c77d_raster. png"></a> | 392 src='https://fiddle.skia.org/c/@skpaint_emboss_raster.png'></a> |
| 420 | 393 |
| 421 | 394 |
| 422 <span id="SkColorFilter"></span> | 395 <span id="SkColorFilter"></span> |
| 423 | 396 |
| 424 SkColorFilter | 397 SkColorFilter |
| 425 ------------- | 398 ------------- |
| 426 | 399 |
| 427 * Color Matrix Color Filter | 400 * Color Matrix Color Filter |
| 428 | 401 |
| 429 <!--?prettify lang=cc?--> | 402 <!--?prettify lang=cc?--> |
| 430 | 403 |
| 431 void f(SkCanvas* c, SkScalar x, SkScalar y, SkScalar colorMatrix[20]) { | 404 void f(SkCanvas* c, SkScalar x, SkScalar y, SkScalar colorMatrix[20]) { |
| 432 SkColorFilter* cf = SkColorMatrixFilter::Create(colorMatrix); | |
| 433 SkPaint paint; | 405 SkPaint paint; |
| 434 paint.setColorFilter(cf); | 406 paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(colo rMatrix)); |
| 435 cf->unref(); | |
| 436 c->drawBitmap(source, x, y, &paint); | 407 c->drawBitmap(source, x, y, &paint); |
| 437 } | 408 } |
| 409 | |
| 438 void draw(SkCanvas* c) { | 410 void draw(SkCanvas* c) { |
| 439 c->scale(0.25, 0.25); | 411 c->scale(0.25, 0.25); |
| 440 SkScalar colorMatrix1[20] = { | 412 SkScalar colorMatrix1[20] = { |
| 441 0, 1, 0, 0, 0, | 413 0, 1, 0, 0, 0, |
| 442 0, 0, 1, 0, 0, | 414 0, 0, 1, 0, 0, |
| 443 1, 0, 0, 0, 0, | 415 1, 0, 0, 0, 0, |
| 444 0, 0, 0, 1, 0}; | 416 0, 0, 0, 1, 0}; |
| 445 f(c, 0, 0, colorMatrix1); | 417 f(c, 0, 0, colorMatrix1); |
| 446 | 418 |
| 447 SkScalar grayscale[20] = { | 419 SkScalar grayscale[20] = { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 f(c, 1536, 0, sepia); | 459 f(c, 1536, 0, sepia); |
| 488 | 460 |
| 489 SkScalar inverter[20] = { | 461 SkScalar inverter[20] = { |
| 490 -1, 0, 0, 0, 255, | 462 -1, 0, 0, 0, 255, |
| 491 0, -1, 0, 0, 255, | 463 0, -1, 0, 0, 255, |
| 492 0, 0, -1, 0, 255, | 464 0, 0, -1, 0, 255, |
| 493 0, 0, 0, 1, 0}; | 465 0, 0, 0, 1, 0}; |
| 494 f(c, 1536, 512, inverter); | 466 f(c, 1536, 512, inverter); |
| 495 } | 467 } |
| 496 | 468 |
| 497 <a href="https://fiddle.skia.org/c/91fb5341ee7903c9682df20bb3d73dbb"> | 469 <a href='https://fiddle.skia.org/c/@skpaint_matrix_color_filter'><img |
| 498 <img src="https://fiddle.skia.org/i/91fb5341ee7903c9682df20bb3d73dbb_raster. png"></a> | 470 src='https://fiddle.skia.org/c/@skpaint_matrix_color_filter_raster.png'></a> |
| 499 | 471 |
| 500 * Color Table Color Filter | 472 * Color Table Color Filter |
| 501 | 473 |
| 502 <!--?prettify lang=cc?--> | 474 <!--?prettify lang=cc?--> |
| 503 | 475 |
| 504 canvas->scale(0.5, 0.5); | 476 void draw(SkCanvas* canvas) { |
| 505 uint8_t ct[256]; | 477 canvas->scale(0.5, 0.5); |
| 506 for (int i = 0; i < 256; ++i) { | 478 uint8_t ct[256]; |
| 507 int x = (i - 96) * 255 / 64; | 479 for (int i = 0; i < 256; ++i) { |
| 508 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; | 480 int x = (i - 96) * 255 / 64; |
| 481 ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; | |
| 482 } | |
| 483 SkPaint paint; | |
| 484 paint.setColorFilter(SkTableColorFilter::MakeARGB(nullptr, ct, ct, ct) ); | |
| 485 canvas->drawBitmap(source, 0, 0, &paint); | |
| 509 } | 486 } |
| 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 | 487 |
| 516 <a href="https://fiddle.skia.org/c/0d3d339543afa1b10c60f9826f264c3f"> | 488 <a href='https://fiddle.skia.org/c/@skpaint_color_table_filter'><img |
| 517 <img src="https://fiddle.skia.org/i/0d3d339543afa1b10c60f9826f264c3f_raster. png"></a> | 489 src='https://fiddle.skia.org/c/@skpaint_color_table_filter_raster.png'></a > |
| 518 | 490 |
| 519 | 491 |
| 520 <span id="SkPathEffect"></span> | 492 <span id="SkPathEffect"></span> |
| 521 | 493 |
| 522 SkPathEffect | 494 SkPathEffect |
| 523 ------------ | 495 ------------ |
| 524 | 496 |
| 525 * SkPath2DPathEffect: Stamp the specified path to fill the shape, | 497 * SkPath2DPathEffect: Stamp the specified path to fill the shape, |
| 526 using the matrix to define the latice. | 498 using the matrix to define the latice. |
| 527 | 499 |
| 528 <!--?prettify lang=cc?--> | 500 <!--?prettify lang=cc?--> |
| 529 | 501 |
| 530 void draw(SkCanvas* canvas) { | 502 void draw(SkCanvas* canvas) { |
| 531 SkScalar scale = 10.0f; | 503 SkScalar scale = 10.0f; |
| 532 SkPath path; | 504 SkPath path; |
| 533 static const int8_t pts[] = { 2, 2, 1, 3, 0, 3, 2, 1, 3, 1, | 505 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 }; | 506 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); | 507 path.moveTo(2 * scale, 3 * scale); |
| 536 for (size_t i = 0 ; i < sizeof(pts)/sizeof(pts[0]); i += 2) { | 508 for (size_t i = 0 ; i < sizeof(pts)/sizeof(pts[0]); i += 2) { |
| 537 path.lineTo(pts[i] * scale, pts[i + 1] * scale); | 509 path.lineTo(pts[i] * scale, pts[i + 1] * scale); |
| 538 } | 510 } |
| 539 path.close(); | 511 path.close(); |
| 540 SkMatrix matrix = SkMatrix::MakeScale(4 * scale); | 512 SkMatrix matrix = SkMatrix::MakeScale(4 * scale); |
| 541 SkAutoTUnref<SkPathEffect> pathEffect( | |
| 542 SkPath2DPathEffect::Create(matrix, path)); | |
| 543 SkPaint paint; | 513 SkPaint paint; |
| 544 paint.setPathEffect(pathEffect); | 514 paint.setPathEffect(SkPath2DPathEffect::Make(matrix, path)); |
| 545 paint.setAntiAlias(true); | 515 paint.setAntiAlias(true); |
| 546 canvas->clear(SK_ColorWHITE); | 516 canvas->clear(SK_ColorWHITE); |
| 547 SkRect bounds; | 517 SkRect bounds; |
| 548 (void)canvas->getClipBounds(&bounds); | 518 (void)canvas->getClipBounds(&bounds); |
| 549 bounds.outset(2 * scale, 2 * scale); | 519 bounds.outset(2 * scale, 2 * scale); |
| 550 canvas->drawRect(bounds, paint); | 520 canvas->drawRect(bounds, paint); |
| 551 } | 521 } |
| 552 | 522 |
| 553 <a href="https://fiddle.skia.org/c/aae271e4f0178455f0e128981d714d73"><img sr c="https://fiddle.skia.org/i/aae271e4f0178455f0e128981d714d73_raster.png" alt="" ></a> | 523 <a href='https://fiddle.skia.org/c/@skpaint_path_2d_path_effect'><img |
| 524 src='https://fiddle.skia.org/c/@skpaint_path_2d_path_effect_raster.png'></ a> | |
| 554 | 525 |
| 555 * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the | 526 * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the |
| 556 path is a straight line to be stroked, not a path to be filled. | 527 path is a straight line to be stroked, not a path to be filled. |
| 557 | 528 |
| 558 <!--?prettify lang=cc?--> | 529 <!--?prettify lang=cc?--> |
| 559 | 530 |
| 560 void draw(SkCanvas* canvas) { | 531 void draw(SkCanvas* canvas) { |
| 561 SkPaint paint; | 532 SkPaint paint; |
| 562 SkMatrix lattice; | 533 SkMatrix lattice; |
| 563 lattice.setScale(8.0f, 8.0f); | 534 lattice.setScale(8.0f, 8.0f); |
| 564 lattice.preRotate(30.0f); | 535 lattice.preRotate(30.0f); |
| 565 SkAutoTUnref<SkPathEffect> pe( | 536 paint.setPathEffect(SkLine2DPathEffect::Make(0.0f, lattice)); |
| 566 SkLine2DPathEffect::Create(0.0f, lattice)); | |
| 567 paint.setPathEffect(pe); | |
| 568 paint.setAntiAlias(true); | 537 paint.setAntiAlias(true); |
| 569 SkRect bounds; | 538 SkRect bounds; |
| 570 (void)canvas->getClipBounds(&bounds); | 539 (void)canvas->getClipBounds(&bounds); |
| 571 bounds.outset(8.0f, 8.0f); | 540 bounds.outset(8.0f, 8.0f); |
| 572 canvas->clear(SK_ColorWHITE); | 541 canvas->clear(SK_ColorWHITE); |
| 573 canvas->drawRect(bounds, paint); | 542 canvas->drawRect(bounds, paint); |
| 574 } | 543 } |
| 575 | 544 |
| 576 <a href="https://fiddle.skia.org/c/3f49502145886920f95d43912e0f550d"><img sr c="https://fiddle.skia.org/i/3f49502145886920f95d43912e0f550d_raster.png" alt="" ></a> | 545 <a href='https://fiddle.skia.org/c/@skpaint_line_2d_path_effect'><img |
| 546 src='https://fiddle.skia.org/c/@skpaint_line_2d_path_effect_raster.png'></ a> | |
| 577 | 547 |
| 578 * SkPath1DPathEffect: create dash-like effects by replicating the specified pa th along the drawn path. | 548 * SkPath1DPathEffect: create dash-like effects by replicating the specified pa th along the drawn path. |
| 579 | 549 |
| 580 <!--?prettify lang=cc?--> | 550 <!--?prettify lang=cc?--> |
| 581 | 551 |
| 582 void draw(SkCanvas* canvas) { | 552 void draw(SkCanvas* canvas) { |
| 583 SkPaint paint; | 553 SkPaint paint; |
| 584 SkPath path; | 554 SkPath path; |
| 585 path.addOval(SkRect::MakeWH(16.0f, 6.0f)); | 555 path.addOval(SkRect::MakeWH(16.0f, 6.0f)); |
| 586 SkAutoTUnref<SkPathEffect> pe( | 556 paint.setPathEffect(SkPath1DPathEffect::Make( |
| 587 SkPath1DPathEffect::Create( | |
| 588 path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style)); | 557 path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style)); |
| 589 paint.setPathEffect(pe); | |
| 590 paint.setAntiAlias(true); | 558 paint.setAntiAlias(true); |
| 591 canvas->clear(SK_ColorWHITE); | 559 canvas->clear(SK_ColorWHITE); |
| 592 canvas->drawCircle(128.0f, 128.0f, 122.0f, paint); | 560 canvas->drawCircle(128.0f, 128.0f, 122.0f, paint); |
| 593 } | 561 } |
| 594 | 562 |
| 595 <a href="https://fiddle.skia.org/c/756a8cdb9458c05f6c1c7c398d979dac"><img sr c="https://fiddle.skia.org/i/756a8cdb9458c05f6c1c7c398d979dac_raster.png" alt="" ></a> | 563 <a href='https://fiddle.skia.org/c/@skpaint_path_1d_path_effect'><img |
| 564 src='https://fiddle.skia.org/c/@skpaint_path_1d_path_effect_raster.png'></ a> | |
| 596 | 565 |
| 597 * SkArcToPathEffect | 566 * SkArcToPathEffect |
| 598 | 567 |
| 599 The following few examples use this function: | 568 The following few examples use this function: |
| 600 | 569 |
| 601 <!--?prettify lang=cc?--> | 570 <!--?prettify lang=cc?--> |
| 602 | 571 |
| 603 SkPath star() { | 572 SkPath star() { |
| 604 const SkScalar R = 115.2f, C = 128.0f; | 573 const SkScalar R = 115.2f, C = 128.0f; |
| 605 SkPath path; | 574 SkPath path; |
| 606 path.moveTo(C + R, C); | 575 path.moveTo(C + R, C); |
| 607 for (int i = 1; i < 7; ++i) { | 576 for (int i = 1; i < 8; ++i) { |
| 608 SkScalar a = 2.6927937f * i; | 577 SkScalar a = 2.6927937f * i; |
| 609 path.lineTo(C + R * cos(a), C + R * sin(a)); | 578 path.lineTo(C + R * cos(a), C + R * sin(a)); |
| 610 } | 579 } |
| 611 path.close(); | |
| 612 return path; | 580 return path; |
| 613 } | 581 } |
| 614 | |
| 615 <!--?prettify lang=cc?--> | |
| 616 | |
| 617 void draw(SkCanvas* canvas) { | 582 void draw(SkCanvas* canvas) { |
| 618 SkPaint paint; | 583 SkPaint paint; |
| 619 SkAutoTUnref<SkPathEffect> pe( | 584 paint.setPathEffect(SkArcToPathEffect::Make(8.0f)); |
| 620 SkArcToPathEffect::Create(8.0f)); | |
| 621 paint.setPathEffect(pe); | |
| 622 paint.setStyle(SkPaint::kStroke_Style); | 585 paint.setStyle(SkPaint::kStroke_Style); |
| 623 paint.setAntiAlias(true); | 586 paint.setAntiAlias(true); |
| 624 canvas->clear(SK_ColorWHITE); | 587 canvas->clear(SK_ColorWHITE); |
| 625 SkPath path(star()); | 588 SkPath path(star()); |
| 626 canvas->drawPath(path, paint); | 589 canvas->drawPath(path, paint); |
| 627 } | 590 } |
| 628 | 591 |
| 629 <a href="https://fiddle.skia.org/c/1cc2a1363dd0e96954e084f7ca29aa5f"><img sr c="https://fiddle.skia.org/i/1cc2a1363dd0e96954e084f7ca29aa5f_raster.png" alt="" ></a> | 592 <a href='https://fiddle.skia.org/c/@skpaint_arc_to_path_effect'><img |
| 593 src='https://fiddle.skia.org/c/@skpaint_arc_to_path_effect_raster.png'></a > | |
| 594 | |
| 630 | 595 |
| 631 * SkCornerPathEffect: a path effect that can turn sharp corners into | 596 * SkCornerPathEffect: a path effect that can turn sharp corners into |
| 632 various treatments (e.g. rounded corners). | 597 various treatments (e.g. rounded corners). |
| 633 | 598 |
| 634 <!--?prettify lang=cc?--> | 599 <!--?prettify lang=cc?--> |
| 635 | 600 |
| 636 void draw(SkCanvas* canvas) { | 601 void draw(SkCanvas* canvas) { |
| 637 SkPaint paint; | 602 SkPaint paint; |
| 638 SkAutoTUnref<SkPathEffect> pe( | 603 paint.setPathEffect(SkCornerPathEffect::Make(32.0f)); |
| 639 SkCornerPathEffect::Create(32.0f)); | |
| 640 paint.setPathEffect(pe); | |
| 641 paint.setStyle(SkPaint::kStroke_Style); | 604 paint.setStyle(SkPaint::kStroke_Style); |
| 642 paint.setAntiAlias(true); | 605 paint.setAntiAlias(true); |
| 643 canvas->clear(SK_ColorWHITE); | 606 canvas->clear(SK_ColorWHITE); |
| 644 const SkScalar R = 115.2f; | 607 const SkScalar R = 115.2f; |
| 645 SkPath path(star()); | 608 SkPath path(star()); |
| 646 canvas->drawPath(path, paint); | 609 canvas->drawPath(path, paint); |
| 647 } | 610 } |
| 648 | 611 |
| 649 <a href="https://fiddle.skia.org/c/f5361bbb33ad43c656dd40bb03ee2114"><img sr c="https://fiddle.skia.org/i/f5361bbb33ad43c656dd40bb03ee2114_raster.png" alt="" ></a> | 612 <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 | 613 |
| 651 * SkDashPathEffect: a path effect that implements dashing. | 614 * SkDashPathEffect: a path effect that implements dashing. |
| 652 | 615 |
| 653 <!--?prettify lang=cc?--> | 616 <!--?prettify lang=cc?--> |
| 654 | 617 |
| 655 void draw(SkCanvas* canvas) { | 618 void draw(SkCanvas* canvas) { |
| 656 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; | 619 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; |
| 657 size_t count = sizeof(intervals) / sizeof(intervals[0]); | 620 size_t count = sizeof(intervals) / sizeof(intervals[0]); |
| 658 SkAutoTUnref<SkPathEffect> pe( | |
| 659 SkDashPathEffect::Create(intervals, count, 0.0f)); | |
| 660 SkPaint paint; | 621 SkPaint paint; |
| 661 paint.setPathEffect(pe); | 622 paint.setPathEffect(SkDashPathEffect::Make(intervals, count, 0.0f)); |
| 662 paint.setStyle(SkPaint::kStroke_Style); | 623 paint.setStyle(SkPaint::kStroke_Style); |
| 663 paint.setStrokeWidth(2.0f); | 624 paint.setStrokeWidth(2.0f); |
| 664 paint.setAntiAlias(true); | 625 paint.setAntiAlias(true); |
| 665 canvas->clear(SK_ColorWHITE); | 626 canvas->clear(SK_ColorWHITE); |
| 666 SkPath path(star()); | 627 SkPath path(star()); |
| 667 canvas->drawPath(path, paint); | 628 canvas->drawPath(path, paint); |
| 668 } | 629 } |
| 669 | 630 |
| 670 <a href="https://fiddle.skia.org/c/d221ced999a80ac23870d0301ffeedad"><img sr c="https://fiddle.skia.org/i/d221ced999a80ac23870d0301ffeedad_raster.png" alt="" ></a> | 631 <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 | 632 |
| 672 * SkDiscretePathEffect: This path effect chops a path into discrete | 633 * SkDiscretePathEffect: This path effect chops a path into discrete |
| 673 segments, and randomly displaces them. | 634 segments, and randomly displaces them. |
| 674 | 635 |
| 675 <!--?prettify lang=cc?--> | 636 <!--?prettify lang=cc?--> |
| 676 | 637 |
| 677 void draw(SkCanvas* canvas) { | 638 void draw(SkCanvas* canvas) { |
| 678 SkAutoTUnref<SkPathEffect> pe( | |
| 679 SkDiscretePathEffect::Create(10.0f, 4.0f)); | |
| 680 SkPaint paint; | 639 SkPaint paint; |
| 681 paint.setPathEffect(pe); | 640 paint.setPathEffect(SkDiscretePathEffect::Make(10.0f, 4.0f)); |
| 682 paint.setStyle(SkPaint::kStroke_Style); | 641 paint.setStyle(SkPaint::kStroke_Style); |
| 683 paint.setStrokeWidth(2.0f); | 642 paint.setStrokeWidth(2.0f); |
| 684 paint.setAntiAlias(true); | 643 paint.setAntiAlias(true); |
| 685 canvas->clear(SK_ColorWHITE); | 644 canvas->clear(SK_ColorWHITE); |
| 686 SkPath path(star()); | 645 SkPath path(star()); |
| 687 canvas->drawPath(path, paint); | 646 canvas->drawPath(path, paint); |
| 688 } | 647 } |
| 689 | 648 |
| 690 <a href="https://fiddle.skia.org/c/af2f177438b376ca45cfffc29cc0177a"><img sr c="https://fiddle.skia.org/i/af2f177438b376ca45cfffc29cc0177a_raster.png" alt="" ></a> | 649 <a href='https://fiddle.skia.org/c/@skpaint_discrete_path_effect'><img |
| 650 src='https://fiddle.skia.org/c/@skpaint_discrete_path_effect_raster.png'>< /a> | |
| 691 | 651 |
| 692 * SkComposePathEffect: a pathEffect whose effect is to apply | 652 * SkComposePathEffect: a pathEffect whose effect is to apply |
| 693 first the inner pathEffect and the the outer pathEffect (i.e. | 653 first the inner pathEffect and the the outer pathEffect (i.e. |
| 694 outer(inner(path))). | 654 outer(inner(path))). |
| 695 | 655 |
| 696 <!--?prettify lang=cc?--> | 656 <!--?prettify lang=cc?--> |
| 697 | 657 |
| 698 void draw(SkCanvas* canvas) { | 658 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 }; | 659 const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; |
| 702 size_t count = sizeof(intervals) / sizeof(intervals[0]); | 660 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; | 661 SkPaint paint; |
| 708 paint.setPathEffect(pe); | 662 paint.setPathEffect(SkComposePathEffect::Make( |
| 663 SkDashPathEffect::Make(intervals, count, 0.0f), | |
| 664 SkDiscretePathEffect::Make(10.0f, 4.0f) | |
| 665 )); | |
| 709 paint.setStyle(SkPaint::kStroke_Style); | 666 paint.setStyle(SkPaint::kStroke_Style); |
| 710 paint.setStrokeWidth(2.0f); | 667 paint.setStrokeWidth(2.0f); |
| 711 paint.setAntiAlias(true); | 668 paint.setAntiAlias(true); |
| 712 canvas->clear(SK_ColorWHITE); | 669 canvas->clear(SK_ColorWHITE); |
| 713 SkPath path(star()); | 670 SkPath path(star()); |
| 714 canvas->drawPath(path, paint); | 671 canvas->drawPath(path, paint); |
| 715 } | 672 } |
| 716 | 673 |
| 717 <a href="https://fiddle.skia.org/c/39a644161da79e8b5e49c193adac7173"><img sr c="https://fiddle.skia.org/i/39a644161da79e8b5e49c193adac7173_raster.png" alt="" ></a> | 674 <a href='https://fiddle.skia.org/c/@skpaint_compose_path_effect'><img |
| 675 src='https://fiddle.skia.org/c/@skpaint_compose_path_effect_raster.png'></ a> | |
| 718 | 676 |
| 719 * SkSumPathEffect: a pathEffect whose effect is to apply two effects, | 677 * SkSumPathEffect: a pathEffect whose effect is to apply two effects, |
| 720 in sequence (i.e. first(path) + second(path)). | 678 in sequence (i.e. first(path) + second(path)). |
| 721 | 679 |
| 722 <!--?prettify lang=cc?--> | 680 <!--?prettify lang=cc?--> |
| 723 | 681 |
| 724 void draw(SkCanvas* canvas) { | 682 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; | 683 SkPaint paint; |
| 732 paint.setPathEffect(pe); | 684 paint.setPathEffect(SkSumPathEffect::Make( |
| 685 SkDiscretePathEffect::Make(10.0f, 4.0f), | |
| 686 SkDiscretePathEffect::Make(10.0f, 4.0f, 1245u) | |
| 687 )); | |
| 733 paint.setStyle(SkPaint::kStroke_Style); | 688 paint.setStyle(SkPaint::kStroke_Style); |
| 734 paint.setStrokeWidth(2.0f); | 689 paint.setStrokeWidth(2.0f); |
| 735 paint.setAntiAlias(true); | 690 paint.setAntiAlias(true); |
| 736 canvas->clear(SK_ColorWHITE); | 691 canvas->clear(SK_ColorWHITE); |
| 737 SkPath path(star()); | 692 SkPath path(star()); |
| 738 canvas->drawPath(path, paint); | 693 canvas->drawPath(path, paint); |
| 739 } | 694 } |
| 740 | 695 |
| 741 <a href="https://fiddle.skia.org/c/e5f7861072893bd08c305a076bf32958"><img sr c="https://fiddle.skia.org/i/e5f7861072893bd08c305a076bf32958_raster.png" alt="" ></a> | 696 <a href='https://fiddle.skia.org/c/@skpaint_sum_path_effect'><img |
| 697 src='https://fiddle.skia.org/c/@skpaint_sum_path_effect_raster.png'></a> | |
| 742 | 698 |
| 743 <!-- | |
| 744 <a href="https://fiddle.skia.org/c/"><img src="https://fiddle.skia.org/i/_ra ster.png" alt=""></a> | |
| 745 --> | |
| 746 | |
| OLD | NEW |