From: jcgregorio Date: Fri, 22 Apr 2016 18:25:43 +0000 (-0700) Subject: skia.org: Update all fiddles for fiddle 2.0. X-Git-Tag: submit/tizen/20180928.044319~129^2~854 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c2a2fe3c81af0d5b35224dc06cbd1a82a474ec7;p=platform%2Fupstream%2FlibSkiaSharp.git skia.org: Update all fiddles for fiddle 2.0. The images won't show up in the preview, which won't happen until I switch over to fiddle 2.0 in production later today. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1910593005 NOTRY=true DOCS_PREVIEW= https://skia.org/?cl=1910593005 Review URL: https://codereview.chromium.org/1910593005 --- diff --git a/site/index.md b/site/index.md index cbd1a7f17c..92269a2229 100644 --- a/site/index.md +++ b/site/index.md @@ -19,39 +19,39 @@ Click on any image below to see the source code that generated the image. ShapesBézier Curves - + - + Translations and RotationsText Rendering - + - + Discrete Path EffectsComposed Path Effects - + - + Sum Path EffectsShaders - + - + diff --git a/site/user/api/skcanvas.md b/site/user/api/skcanvas.md index 5750814963..03f09556b3 100644 --- a/site/user/api/skcanvas.md +++ b/site/user/api/skcanvas.md @@ -32,8 +32,8 @@ heptagram. This function can be cut and pasted into canvas->drawPath(path, p); } - - + Details ------- @@ -59,8 +59,8 @@ SkPaint. canvas->restore(); } - - + The code above will draw a rectangle rotated by 45 degrees. Exactly what color and style the rect will be drawn in is described by the @@ -132,15 +132,16 @@ parameter. canvas->drawBitmap(source, 128, 128, &paint); SkRect rect2 = SkRect::MakeXYWH(0, 0, 40, 60); - canvas->drawBitmapRect(source, rect2); + canvas->drawBitmapRect(source, rect2, &paint); SkPaint paint2; const char text[] = "Hello, Skia!"; canvas->drawText(text, strlen(text), 50, 25, paint2); } - - + + In some of the calls, we pass a pointer, rather than a reference, to the paint. In those instances, the paint parameter may be null. In all diff --git a/site/user/api/skpaint.md b/site/user/api/skpaint.md index 0323da554c..f6b81692ba 100644 --- a/site/user/api/skpaint.md +++ b/site/user/api/skpaint.md @@ -18,7 +18,7 @@ Unlike `SkCanvas`, paints do not maintain an internal stack of state (i.e. there is no save/restore on a paint). However, paints are relatively light-weight, so the client may create and maintain any number of paint objects, each set up for a particular use. Factoring -all of these color and stylistic attribute out of the canvas state, +all of these color and stylistic attributes out of the canvas state, and into (multiple) paint objects, allows canvas' save/restore to be that much more efficient, as all they have to do is maintain the stack of matrix and clip settings. @@ -52,8 +52,8 @@ of matrix and clip settings. canvas->drawText(text, strlen(text), 20.0f, 224.0f, paint3); } - - + This shows three different paints, each set up to draw in a different style. Now the caller can intermix these paints freely, either using @@ -78,8 +78,8 @@ them as is, or modifying them as the drawing proceeds. paint3.setColor(SK_ColorBLUE); canvas->drawText("SKIA", 4, 20, 220, paint3); - - + Beyond simple attributes such as color, strokes, and text values, paints support effects. These are subclasses of different aspects of @@ -92,25 +92,24 @@ assign a SkShader to the paint. - SkPoint points[2] = { - SkPoint::Make(0.0f, 0.0f), - SkPoint::Make(256.0f, 256.0f) - }; - SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; - SkShader* shader = - SkGradientShader::CreateLinear( - points, colors, nullptr, 2, - SkShader::kClamp_TileMode, 0, nullptr); - SkPaint paint; - paint.setShader(shader); - shader->unref(); - canvas->drawPaint(paint); - - - + void draw(SkCanvas* canvas) { + SkPoint points[2] = { + SkPoint::Make(0.0f, 0.0f), + SkPoint::Make(256.0f, 256.0f) + }; + SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear( + points, colors, nullptr, 2, + SkShader::kClamp_TileMode, 0, nullptr)); + canvas->drawPaint(paint); + } + + Now, anything drawn with that paint will be drawn with the gradient -specified in the call to `CreateLinear()`. The shader object that is +specified in the call to `MakeLinear()`. The shader object that is returned is reference-counted. Whenever any effects object, like a shader, is assigned to a paint, its reference-count is increased by the paint. To balance this, the caller in the above example calls @@ -156,87 +155,86 @@ with a vertical alpha gradient. - SkXfermode::Mode modes[] = { - SkXfermode::kClear_Mode, - SkXfermode::kSrc_Mode, - SkXfermode::kDst_Mode, - SkXfermode::kSrcOver_Mode, - SkXfermode::kDstOver_Mode, - SkXfermode::kSrcIn_Mode, - SkXfermode::kDstIn_Mode, - SkXfermode::kSrcOut_Mode, - SkXfermode::kDstOut_Mode, - SkXfermode::kSrcATop_Mode, - SkXfermode::kDstATop_Mode, - SkXfermode::kXor_Mode, - SkXfermode::kPlus_Mode, - SkXfermode::kModulate_Mode, - SkXfermode::kScreen_Mode, - SkXfermode::kOverlay_Mode, - SkXfermode::kDarken_Mode, - SkXfermode::kLighten_Mode, - SkXfermode::kColorDodge_Mode, - SkXfermode::kColorBurn_Mode, - SkXfermode::kHardLight_Mode, - SkXfermode::kSoftLight_Mode, - SkXfermode::kDifference_Mode, - SkXfermode::kExclusion_Mode, - SkXfermode::kMultiply_Mode, - SkXfermode::kHue_Mode, - SkXfermode::kSaturation_Mode, - SkXfermode::kColor_Mode, - SkXfermode::kLuminosity_Mode, - }; - SkRect rect = SkRect::MakeWH(64.0f, 64.0f); - SkPaint text, stroke, src, dst; - stroke.setStyle(SkPaint::kStroke_Style); - text.setTextSize(24.0f); - text.setAntiAlias(true); - SkPoint srcPoints[2] = { - SkPoint::Make(0.0f, 0.0f), - SkPoint::Make(64.0f, 0.0f) - }; - SkColor srcColors[2] = { - SK_ColorMAGENTA & 0x00FFFFFF, - SK_ColorMAGENTA}; - SkAutoTUnref srcShader( - SkGradientShader::CreateLinear( - srcPoints, srcColors, nullptr, 2, - SkShader::kClamp_TileMode, 0, nullptr)); - src.setShader(srcShader); - - SkPoint dstPoints[2] = { - SkPoint::Make(0.0f, 0.0f), - SkPoint::Make(0.0f, 64.0f) - }; - SkColor dstColors[2] = { - SK_ColorCYAN & 0x00FFFFFF, - SK_ColorCYAN}; - SkAutoTUnref dstShader( - SkGradientShader::CreateLinear( - dstPoints, dstColors, nullptr, 2, - SkShader::kClamp_TileMode, 0, nullptr)); - dst.setShader(dstShader); - canvas->clear(SK_ColorWHITE); - size_t N = sizeof(modes) / sizeof(modes[0]); - size_t K = (N - 1) / 3 + 1; - SkASSERT(K * 64 == 640); // tall enough - for (size_t i = 0; i < N; ++i) { - SkAutoCanvasRestore autoCanvasRestore(canvas, true); - canvas->translate(192.0f * (i / K), 64.0f * (i % K)); - const char* desc = SkXfermode::ModeName(modes[i]); - canvas->drawText(desc, strlen(desc), 68.0f, 30.0f, text); - canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f)); - canvas->drawColor(SK_ColorLTGRAY); - (void)canvas->saveLayer(nullptr, nullptr); - canvas->clear(SK_ColorTRANSPARENT); - canvas->drawPaint(dst); - src.setXfermodeMode(modes[i]); - canvas->drawPaint(src); - canvas->drawRect(rect, stroke); + void draw(SkCanvas* canvas) { + SkXfermode::Mode modes[] = { + SkXfermode::kClear_Mode, + SkXfermode::kSrc_Mode, + SkXfermode::kDst_Mode, + SkXfermode::kSrcOver_Mode, + SkXfermode::kDstOver_Mode, + SkXfermode::kSrcIn_Mode, + SkXfermode::kDstIn_Mode, + SkXfermode::kSrcOut_Mode, + SkXfermode::kDstOut_Mode, + SkXfermode::kSrcATop_Mode, + SkXfermode::kDstATop_Mode, + SkXfermode::kXor_Mode, + SkXfermode::kPlus_Mode, + SkXfermode::kModulate_Mode, + SkXfermode::kScreen_Mode, + SkXfermode::kOverlay_Mode, + SkXfermode::kDarken_Mode, + SkXfermode::kLighten_Mode, + SkXfermode::kColorDodge_Mode, + SkXfermode::kColorBurn_Mode, + SkXfermode::kHardLight_Mode, + SkXfermode::kSoftLight_Mode, + SkXfermode::kDifference_Mode, + SkXfermode::kExclusion_Mode, + SkXfermode::kMultiply_Mode, + SkXfermode::kHue_Mode, + SkXfermode::kSaturation_Mode, + SkXfermode::kColor_Mode, + SkXfermode::kLuminosity_Mode, + }; + SkRect rect = SkRect::MakeWH(64.0f, 64.0f); + SkPaint text, stroke, src, dst; + stroke.setStyle(SkPaint::kStroke_Style); + text.setTextSize(24.0f); + text.setAntiAlias(true); + SkPoint srcPoints[2] = { + SkPoint::Make(0.0f, 0.0f), + SkPoint::Make(64.0f, 0.0f) + }; + SkColor srcColors[2] = { + SK_ColorMAGENTA & 0x00FFFFFF, + SK_ColorMAGENTA}; + src.setShader(SkGradientShader::MakeLinear( + srcPoints, srcColors, nullptr, 2, + SkShader::kClamp_TileMode, 0, nullptr)); + + SkPoint dstPoints[2] = { + SkPoint::Make(0.0f, 0.0f), + SkPoint::Make(0.0f, 64.0f) + }; + SkColor dstColors[2] = { + SK_ColorCYAN & 0x00FFFFFF, + SK_ColorCYAN}; + dst.setShader(SkGradientShader::MakeLinear( + dstPoints, dstColors, nullptr, 2, + SkShader::kClamp_TileMode, 0, nullptr)); + canvas->clear(SK_ColorWHITE); + size_t N = sizeof(modes) / sizeof(modes[0]); + size_t K = (N - 1) / 3 + 1; + SkASSERT(K * 64 == 640); // tall enough + for (size_t i = 0; i < N; ++i) { + SkAutoCanvasRestore autoCanvasRestore(canvas, true); + canvas->translate(192.0f * (i / K), 64.0f * (i % K)); + const char* desc = SkXfermode::ModeName(modes[i]); + canvas->drawText(desc, strlen(desc), 68.0f, 30.0f, text); + canvas->clipRect(SkRect::MakeWH(64.0f, 64.0f)); + canvas->drawColor(SK_ColorLTGRAY); + (void)canvas->saveLayer(nullptr, nullptr); + canvas->clear(SK_ColorTRANSPARENT); + canvas->drawPaint(dst); + src.setXfermodeMode(modes[i]); + canvas->drawPaint(src); + canvas->drawRect(rect, stroke); + } } - + @@ -253,54 +251,44 @@ Several shaders are defined (besides the linear gradient already mentioned): SkMatrix matrix; matrix.setScale(0.75f, 0.75f); matrix.preRotate(30.0f); - SkShader* shader = - SkShader::CreateBitmapShader( - source, - SkShader::kRepeat_TileMode , - SkShader::kRepeat_TileMode , - &matrix); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(SkShader::MakeBitmapShader(source, + SkShader::kRepeat_TileMode, + SkShader::kRepeat_TileMode, + &matrix)); canvas->drawPaint(paint); - - + * Radial Gradient Shader SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; - SkShader* shader = - SkGradientShader::CreateRadial( - SkPoint::Make(128.0f, 128.0f), 180.0f, - colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(SkGradientShader::MakeRadial( + SkPoint::Make(128.0f, 128.0f), 180.0f, + colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); canvas->drawPaint(paint); - - + * Two-Point Conical Gradient Shader SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; - SkShader* shader = - SkGradientShader::CreateTwoPointConical( - SkPoint::Make(128.0f, 128.0f), 128.0f, - SkPoint::Make(128.0f, 16.0f), 16.0f, - colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(SkGradientShader::MakeTwoPointConical( + SkPoint::Make(128.0f, 128.0f), 128.0f, + SkPoint::Make(128.0f, 16.0f), 16.0f, + colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr)); canvas->drawPaint(paint); - - + * Sweep Gradient Shader @@ -309,69 +297,58 @@ Several shaders are defined (besides the linear gradient already mentioned): SkColor colors[4] = { SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, SK_ColorCYAN}; - SkShader* shader = - SkGradientShader::CreateSweep( - 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(SkGradientShader::MakeSweep( + 128.0f, 128.0f, colors, nullptr, 4, 0, nullptr)); canvas->drawPaint(paint); - - + * Fractal Perlin Noise Shader canvas->clear(SK_ColorWHITE); - SkShader* shader = SkPerlinNoiseShader::CreateFractalNoise( - 0.05f, 0.05f, 4, 0.0f, nullptr); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(SkPerlinNoiseShader::MakeFractalNoise( + 0.05f, 0.05f, 4, 0.0f, nullptr)); canvas->drawPaint(paint); - - + * Turbulence Perlin Noise Shader canvas->clear(SK_ColorWHITE); - SkShader* shader = SkPerlinNoiseShader::CreateTurbulence( - 0.05f, 0.05f, 4, 0.0f, nullptr); SkPaint paint; - paint.setShader(shader); - shader->unref(); + paint.setShader(SkPerlinNoiseShader::MakeTurbulence( + 0.05f, 0.05f, 4, 0.0f, nullptr)); canvas->drawPaint(paint); - - + * Compose Shader SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW}; - SkShader* shader1 = - SkGradientShader::CreateRadial( - SkPoint::Make(128.0f, 128.0f), 180.0f, - colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr); - SkShader* shader2 = SkPerlinNoiseShader::CreateTurbulence( - 0.025f, 0.025f, 2, 0.0f, nullptr); - SkShader* shader = - new SkComposeShader(shader1, shader2); SkPaint paint; - paint.setShader(shader); - shader->unref(); - shader2->unref(); - shader1->unref(); + paint.setShader( + SkShader::MakeComposeShader( + SkGradientShader::MakeRadial( + SkPoint::Make(128.0f, 128.0f), 180.0f, + colors, nullptr, 2, SkShader::kClamp_TileMode, 0, nullptr), + SkPerlinNoiseShader::MakeTurbulence(0.025f, 0.025f, 2, 0.0f, nullptr), + SkXfermode::kDifference_Mode) + ); canvas->drawPaint(paint); - - + @@ -383,20 +360,18 @@ SkMaskFilter + canvas->drawText(text, strlen(text), 0, 160, paint); canvas->drawColor(SK_ColorWHITE); SkPaint paint; paint.setAntiAlias(true); paint.setTextSize(120); - SkMaskFilter* filter = - SkBlurMaskFilter::Create( - kNormal_SkBlurStyle, 5.0f, 0); - paint.setMaskFilter(filter); - filter->unref(); + paint.setMaskFilter(SkBlurMaskFilter::Make( + kNormal_SkBlurStyle, 5.0f, 0)); const char text[] = "Skia"; canvas->drawText(text, strlen(text), 0, 160, paint); - - + * Emboss Mask Filter @@ -407,16 +382,13 @@ SkMaskFilter paint.setAntiAlias(true); paint.setTextSize(120); SkScalar direction[3] = {1.0f, 1.0f, 1.0f}; - SkMaskFilter* filter = - SkBlurMaskFilter::CreateEmboss( - 2.0f, direction, 0.3f, 0.1f); - paint.setMaskFilter(filter); - filter->unref(); + paint.setMaskFilter(SkBlurMaskFilter::MakeEmboss( + 2.0f, direction, 0.3f, 0.1f)); const char text[] = "Skia"; canvas->drawText(text, strlen(text), 0, 160, paint); - - + @@ -429,12 +401,11 @@ SkColorFilter void f(SkCanvas* c, SkScalar x, SkScalar y, SkScalar colorMatrix[20]) { - SkColorFilter* cf = SkColorMatrixFilter::Create(colorMatrix); SkPaint paint; - paint.setColorFilter(cf); - cf->unref(); + paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(colorMatrix)); c->drawBitmap(source, x, y, &paint); } + void draw(SkCanvas* c) { c->scale(0.25, 0.25); SkScalar colorMatrix1[20] = { @@ -494,27 +465,27 @@ SkColorFilter f(c, 1536, 512, inverter); } - - + * Color Table Color Filter - canvas->scale(0.5, 0.5); - uint8_t ct[256]; - for (int i = 0; i < 256; ++i) { - int x = (i - 96) * 255 / 64; - ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; + void draw(SkCanvas* canvas) { + canvas->scale(0.5, 0.5); + uint8_t ct[256]; + for (int i = 0; i < 256; ++i) { + int x = (i - 96) * 255 / 64; + ct[i] = x < 0 ? 0 : x > 255 ? 255 : x; + } + SkPaint paint; + paint.setColorFilter(SkTableColorFilter::MakeARGB(nullptr, ct, ct, ct)); + canvas->drawBitmap(source, 0, 0, &paint); } - SkColorFilter* cf = SkTableColorFilter::CreateARGB(nullptr, ct, ct, ct); - SkPaint paint; - paint.setColorFilter(cf); - cf->unref(); - canvas->drawBitmap(source, 0, 0, &paint); - - + @@ -528,8 +499,8 @@ SkPathEffect void draw(SkCanvas* canvas) { - SkScalar scale = 10.0f; - SkPath path; + SkScalar scale = 10.0f; + SkPath path; static const int8_t pts[] = { 2, 2, 1, 3, 0, 3, 2, 1, 3, 1, 4, 0, 4, 1, 5, 1, 4, 2, 4, 3, 2, 5, 2, 4, 3, 3, 2, 3 }; path.moveTo(2 * scale, 3 * scale); @@ -538,10 +509,8 @@ SkPathEffect } path.close(); SkMatrix matrix = SkMatrix::MakeScale(4 * scale); - SkAutoTUnref pathEffect( - SkPath2DPathEffect::Create(matrix, path)); SkPaint paint; - paint.setPathEffect(pathEffect); + paint.setPathEffect(SkPath2DPathEffect::Make(matrix, path)); paint.setAntiAlias(true); canvas->clear(SK_ColorWHITE); SkRect bounds; @@ -550,7 +519,8 @@ SkPathEffect canvas->drawRect(bounds, paint); } - + * SkLine2DPathEffect: a special case of SkPath2DPathEffect where the path is a straight line to be stroked, not a path to be filled. @@ -562,9 +532,7 @@ SkPathEffect SkMatrix lattice; lattice.setScale(8.0f, 8.0f); lattice.preRotate(30.0f); - SkAutoTUnref pe( - SkLine2DPathEffect::Create(0.0f, lattice)); - paint.setPathEffect(pe); + paint.setPathEffect(SkLine2DPathEffect::Make(0.0f, lattice)); paint.setAntiAlias(true); SkRect bounds; (void)canvas->getClipBounds(&bounds); @@ -573,7 +541,8 @@ SkPathEffect canvas->drawRect(bounds, paint); } - + * SkPath1DPathEffect: create dash-like effects by replicating the specified path along the drawn path. @@ -583,16 +552,15 @@ SkPathEffect SkPaint paint; SkPath path; path.addOval(SkRect::MakeWH(16.0f, 6.0f)); - SkAutoTUnref pe( - SkPath1DPathEffect::Create( + paint.setPathEffect(SkPath1DPathEffect::Make( path, 32.0f, 0.0f, SkPath1DPathEffect::kRotate_Style)); - paint.setPathEffect(pe); paint.setAntiAlias(true); canvas->clear(SK_ColorWHITE); canvas->drawCircle(128.0f, 128.0f, 122.0f, paint); } - + * SkArcToPathEffect @@ -604,21 +572,15 @@ SkPathEffect const SkScalar R = 115.2f, C = 128.0f; SkPath path; path.moveTo(C + R, C); - for (int i = 1; i < 7; ++i) { + for (int i = 1; i < 8; ++i) { SkScalar a = 2.6927937f * i; path.lineTo(C + R * cos(a), C + R * sin(a)); } - path.close(); return path; } - - - void draw(SkCanvas* canvas) { SkPaint paint; - SkAutoTUnref pe( - SkArcToPathEffect::Create(8.0f)); - paint.setPathEffect(pe); + paint.setPathEffect(SkArcToPathEffect::Make(8.0f)); paint.setStyle(SkPaint::kStroke_Style); paint.setAntiAlias(true); canvas->clear(SK_ColorWHITE); @@ -626,7 +588,9 @@ SkPathEffect canvas->drawPath(path, paint); } - + + * SkCornerPathEffect: a path effect that can turn sharp corners into various treatments (e.g. rounded corners). @@ -635,9 +599,7 @@ SkPathEffect void draw(SkCanvas* canvas) { SkPaint paint; - SkAutoTUnref pe( - SkCornerPathEffect::Create(32.0f)); - paint.setPathEffect(pe); + paint.setPathEffect(SkCornerPathEffect::Make(32.0f)); paint.setStyle(SkPaint::kStroke_Style); paint.setAntiAlias(true); canvas->clear(SK_ColorWHITE); @@ -646,7 +608,7 @@ SkPathEffect canvas->drawPath(path, paint); } - + * SkDashPathEffect: a path effect that implements dashing. @@ -655,10 +617,8 @@ SkPathEffect void draw(SkCanvas* canvas) { const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; size_t count = sizeof(intervals) / sizeof(intervals[0]); - SkAutoTUnref pe( - SkDashPathEffect::Create(intervals, count, 0.0f)); SkPaint paint; - paint.setPathEffect(pe); + paint.setPathEffect(SkDashPathEffect::Make(intervals, count, 0.0f)); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(2.0f); paint.setAntiAlias(true); @@ -667,7 +627,7 @@ SkPathEffect canvas->drawPath(path, paint); } - + * SkDiscretePathEffect: This path effect chops a path into discrete segments, and randomly displaces them. @@ -675,10 +635,8 @@ SkPathEffect void draw(SkCanvas* canvas) { - SkAutoTUnref pe( - SkDiscretePathEffect::Create(10.0f, 4.0f)); SkPaint paint; - paint.setPathEffect(pe); + paint.setPathEffect(SkDiscretePathEffect::Make(10.0f, 4.0f)); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(2.0f); paint.setAntiAlias(true); @@ -687,7 +645,8 @@ SkPathEffect canvas->drawPath(path, paint); } - + * SkComposePathEffect: a pathEffect whose effect is to apply first the inner pathEffect and the the outer pathEffect (i.e. @@ -696,16 +655,13 @@ SkPathEffect void draw(SkCanvas* canvas) { - SkAutoTUnref pe0( - SkDiscretePathEffect::Create(10.0f, 4.0f)); const SkScalar intervals[] = { 10.0f, 5.0f, 2.0f, 5.0f }; size_t count = sizeof(intervals) / sizeof(intervals[0]); - SkAutoTUnref pe1( - SkDashPathEffect::Create(intervals, count, 0.0f)); - SkAutoTUnref pe( - SkComposePathEffect::Create(pe1, pe0)); SkPaint paint; - paint.setPathEffect(pe); + paint.setPathEffect(SkComposePathEffect::Make( + SkDashPathEffect::Make(intervals, count, 0.0f), + SkDiscretePathEffect::Make(10.0f, 4.0f) + )); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(2.0f); paint.setAntiAlias(true); @@ -714,7 +670,8 @@ SkPathEffect canvas->drawPath(path, paint); } - + * SkSumPathEffect: a pathEffect whose effect is to apply two effects, in sequence (i.e. first(path) + second(path)). @@ -722,14 +679,11 @@ SkPathEffect void draw(SkCanvas* canvas) { - SkAutoTUnref pe0( - SkDiscretePathEffect::Create(10.0f, 4.0f)); - SkAutoTUnref pe1( - SkDiscretePathEffect::Create(10.0f, 4.0f, 1245u)); - SkAutoTUnref pe( - SkSumPathEffect::Create(pe1, pe0)); SkPaint paint; - paint.setPathEffect(pe); + paint.setPathEffect(SkSumPathEffect::Make( + SkDiscretePathEffect::Make(10.0f, 4.0f), + SkDiscretePathEffect::Make(10.0f, 4.0f, 1245u) + )); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(2.0f); paint.setAntiAlias(true); @@ -738,9 +692,6 @@ SkPathEffect canvas->drawPath(path, paint); } - - - + diff --git a/site/user/tips.md b/site/user/tips.md index e59e16075b..91d1de597b 100644 --- a/site/user/tips.md +++ b/site/user/tips.md @@ -87,7 +87,8 @@ drawBitmapNine(): bitmap.extractSubset(&subset, rect); canvas->drawBitmapNine(subset, ...); -[An example](https://fiddle.skia.org/c/c91694020f0810994917b56c323e4559) +[An example](https://fiddle.skia.org/c/@subset_example) + * * *