diff options
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleAARectModes.cpp | 35 | ||||
-rw-r--r-- | samplecode/SampleAll.cpp | 28 | ||||
-rw-r--r-- | samplecode/SampleApp.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleColorFilter.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleFatBits.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleFilterFuzz.cpp | 10 | ||||
-rw-r--r-- | samplecode/SampleFuzz.cpp | 10 | ||||
-rw-r--r-- | samplecode/SampleHairModes.cpp | 34 | ||||
-rw-r--r-- | samplecode/SampleLayerMask.cpp | 4 | ||||
-rw-r--r-- | samplecode/SampleLayers.cpp | 4 | ||||
-rw-r--r-- | samplecode/SamplePathClip.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleQuadStroker.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleRegion.cpp | 2 | ||||
-rw-r--r-- | samplecode/SampleSlides.cpp | 24 | ||||
-rw-r--r-- | samplecode/SampleXfer.cpp | 36 | ||||
-rw-r--r-- | samplecode/SampleXfermodesBlur.cpp | 51 |
16 files changed, 131 insertions, 117 deletions
diff --git a/samplecode/SampleAARectModes.cpp b/samplecode/SampleAARectModes.cpp index 0a50303935..65b1da1405 100644 --- a/samplecode/SampleAARectModes.cpp +++ b/samplecode/SampleAARectModes.cpp @@ -12,21 +12,21 @@ #include "SkShader.h" static const struct { - SkBlendMode fMode; - const char* fLabel; + SkXfermode::Mode fMode; + const char* fLabel; } gModes[] = { - { SkBlendMode::kClear, "Clear" }, - { SkBlendMode::kSrc, "Src" }, - { SkBlendMode::kDst, "Dst" }, - { SkBlendMode::kSrcOver, "SrcOver" }, - { SkBlendMode::kDstOver, "DstOver" }, - { SkBlendMode::kSrcIn, "SrcIn" }, - { SkBlendMode::kDstIn, "DstIn" }, - { SkBlendMode::kSrcOut, "SrcOut" }, - { SkBlendMode::kDstOut, "DstOut" }, - { SkBlendMode::kSrcATop, "SrcATop" }, - { SkBlendMode::kDstATop, "DstATop" }, - { SkBlendMode::kXor, "Xor" }, + { SkXfermode::kClear_Mode, "Clear" }, + { SkXfermode::kSrc_Mode, "Src" }, + { SkXfermode::kDst_Mode, "Dst" }, + { SkXfermode::kSrcOver_Mode, "SrcOver" }, + { SkXfermode::kDstOver_Mode, "DstOver" }, + { SkXfermode::kSrcIn_Mode, "SrcIn" }, + { SkXfermode::kDstIn_Mode, "DstIn" }, + { SkXfermode::kSrcOut_Mode, "SrcOut" }, + { SkXfermode::kDstOut_Mode, "DstOut" }, + { SkXfermode::kSrcATop_Mode, "SrcATop" }, + { SkXfermode::kDstATop_Mode, "DstATop" }, + { SkXfermode::kXor_Mode, "Xor" }, }; const int gWidth = 64; @@ -34,7 +34,7 @@ const int gHeight = 64; const SkScalar W = SkIntToScalar(gWidth); const SkScalar H = SkIntToScalar(gHeight); -static SkScalar drawCell(SkCanvas* canvas, SkBlendMode mode, SkAlpha a0, SkAlpha a1) { +static SkScalar drawCell(SkCanvas* canvas, const sk_sp<SkXfermode>& mode, SkAlpha a0, SkAlpha a1) { SkPaint paint; paint.setAntiAlias(true); @@ -47,7 +47,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkBlendMode mode, SkAlpha a0, SkAlpha paint.setColor(SK_ColorRED); paint.setAlpha(a1); - paint.setBlendMode(mode); + paint.setXfermode(mode); SkScalar offset = SK_Scalar1 / 3; SkRect rect = SkRect::MakeXYWH(W / 4 + offset, @@ -106,10 +106,11 @@ protected: canvas->translate(W * 5, 0); canvas->save(); } + sk_sp<SkXfermode> mode = SkXfermode::Make(gModes[i].fMode); canvas->drawRect(bounds, fBGPaint); canvas->saveLayer(&bounds, nullptr); - SkScalar dy = drawCell(canvas, gModes[i].fMode, gAlphaValue[alpha & 1], + SkScalar dy = drawCell(canvas, mode, gAlphaValue[alpha & 1], gAlphaValue[alpha & 2]); canvas->restore(); diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp index 8c1ace564a..29b5c66c74 100644 --- a/samplecode/SampleAll.cpp +++ b/samplecode/SampleAll.cpp @@ -89,7 +89,7 @@ static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { p.setAlpha(0x11); p.setStyle(SkPaint::kFill_Style); - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); rastBuilder->addLayer(p); } @@ -97,7 +97,7 @@ static void r1(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { rastBuilder->addLayer(p); p.setAlpha(0x40); - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1*2); rastBuilder->addLayer(p); @@ -110,7 +110,7 @@ static void r2(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1*3/2); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); } @@ -121,7 +121,7 @@ static void r3(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { p.setAlpha(0x20); p.setStyle(SkPaint::kFill_Style); - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); rastBuilder->addLayer(p); } @@ -130,10 +130,10 @@ static void r4(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); p.setAlpha(0xFF); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); - p.setBlendMode(SkBlendMode::kSrcOver); + p.setXfermode(nullptr); rastBuilder->addLayer(p); } @@ -141,7 +141,7 @@ static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { rastBuilder->addLayer(p); p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3)); - p.setBlendMode(SkBlendMode::kSrcOut); + p.setXfermodeMode(SkXfermode::kSrcOut_Mode); rastBuilder->addLayer(p); } @@ -152,7 +152,7 @@ static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { SkLayerRasterizer::Builder rastBuilder2; r5(&rastBuilder2, p); p.setRasterizer(rastBuilder2.detach()); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); } @@ -194,11 +194,11 @@ static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); lattice.postSkew(SK_Scalar1/3, 0, 0, 0); p.setPathEffect(sk_make_sp<Dot2DPathEffect>(SK_Scalar1*2, lattice)); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); p.setPathEffect(nullptr); - p.setBlendMode(SkBlendMode::kSrcOver); + p.setXfermode(nullptr); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1); rastBuilder->addLayer(p); @@ -211,11 +211,11 @@ static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) { lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); lattice.postRotate(SkIntToScalar(30), 0, 0); p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice)); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); p.setPathEffect(nullptr); - p.setBlendMode(SkBlendMode::kSrcOver); + p.setXfermode(nullptr); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1); rastBuilder->addLayer(p); @@ -401,10 +401,10 @@ protected: paint.setColor(SK_ColorGREEN); paint.setStrokeWidth(SkIntToScalar(10)); paint.setStyle(SkPaint::kStroke_Style); - paint.setBlendMode(SkBlendMode::kXor); + paint.setXfermode(SkXfermode::Make(SkXfermode::kXor_Mode)); paint.setColorFilter(lightingFilter); canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green - paint.setBlendMode(SkBlendMode::kSrcOver); + paint.setXfermode(nullptr); paint.setColorFilter(nullptr); // rectangle diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index d2374f5adf..233306c767 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -351,7 +351,7 @@ public: bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect(win->info()); SkPaint gammaPaint; - gammaPaint.setBlendMode(SkBlendMode::kSrc); + gammaPaint.setXfermodeMode(SkXfermode::kSrc_Mode); if (doGamma) { gammaPaint.setColorFilter(SkGammaColorFilter::Make(1.0f / 2.2f)); } diff --git a/samplecode/SampleColorFilter.cpp b/samplecode/SampleColorFilter.cpp index 67c7b2e13d..3da77a441f 100644 --- a/samplecode/SampleColorFilter.cpp +++ b/samplecode/SampleColorFilter.cpp @@ -100,7 +100,7 @@ static SkBitmap createBitmap(int n) { canvas.drawOval(r, paint); r.inset(SK_Scalar1*n/4, SK_Scalar1*n/4); - paint.setBlendMode(SkBlendMode::kSrc); + paint.setXfermodeMode(SkXfermode::kSrc_Mode); paint.setColor(0x800000FF); canvas.drawOval(r, paint); diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp index 82eb25fd70..8da6058f9d 100644 --- a/samplecode/SampleFatBits.cpp +++ b/samplecode/SampleFatBits.cpp @@ -163,7 +163,7 @@ private: canvas->restore(); SkPaint paint; - paint.setBlendMode(SkBlendMode::kClear); + paint.setXfermodeMode(SkXfermode::kClear_Mode); for (int iy = 1; iy < fH; ++iy) { SkScalar y = SkIntToScalar(iy * fZoom); canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint); diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 28aa5f4caf..755e8fb458 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -157,8 +157,8 @@ static SkMatrix make_matrix() { return m; } -static SkBlendMode make_xfermode() { - return static_cast<SkBlendMode>(R(SkXfermode::kLastMode+1)); +static SkXfermode::Mode make_xfermode() { + return static_cast<SkXfermode::Mode>(R(SkXfermode::kLastMode+1)); } static SkPaint::Align make_paint_align() { @@ -508,7 +508,7 @@ static SkPaint make_paint() { paint.setStrokeCap(make_paint_cap()); paint.setStrokeJoin(make_paint_join()); paint.setColorFilter(make_color_filter()); - paint.setBlendMode(make_xfermode()); + paint.setXfermodeMode(make_xfermode()); paint.setPathEffect(make_path_effect()); paint.setMaskFilter(make_mask_filter()); @@ -558,7 +558,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { case MERGE: filter = SkMergeImageFilter::Make(make_image_filter(), make_image_filter(), - (SkXfermode::Mode)make_xfermode()); + make_xfermode()); break; case COLOR: { sk_sp<SkColorFilter> cf(make_color_filter()); @@ -585,7 +585,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { make_image_filter()); break; case XFERMODE: - filter = SkXfermodeImageFilter::Make(make_xfermode(), + filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), make_image_filter(), make_image_filter(), nullptr); diff --git a/samplecode/SampleFuzz.cpp b/samplecode/SampleFuzz.cpp index c7d05782e3..76420f026a 100644 --- a/samplecode/SampleFuzz.cpp +++ b/samplecode/SampleFuzz.cpp @@ -153,15 +153,15 @@ static void do_fuzz(SkCanvas* canvas) { break; case 2: { - SkBlendMode mode; + SkXfermode::Mode mode; switch (R(3)) { - case 0: mode = SkBlendMode::kSrc; break; - case 1: mode = SkBlendMode::kXor; break; + case 0: mode = SkXfermode::kSrc_Mode; break; + case 1: mode = SkXfermode::kXor_Mode; break; case 2: default: // silence warning - mode = SkBlendMode::kSrcOver; break; + mode = SkXfermode::kSrcOver_Mode; break; } - paint.setBlendMode(mode); + paint.setXfermodeMode(mode); } break; diff --git a/samplecode/SampleHairModes.cpp b/samplecode/SampleHairModes.cpp index 5eeb6cbbba..26037d7dc9 100644 --- a/samplecode/SampleHairModes.cpp +++ b/samplecode/SampleHairModes.cpp @@ -12,21 +12,21 @@ #include "SkShader.h" static const struct { - SkBlendMode fMode; - const char* fLabel; + SkXfermode::Mode fMode; + const char* fLabel; } gModes[] = { - { SkBlendMode::kClear, "Clear" }, - { SkBlendMode::kSrc, "Src" }, - { SkBlendMode::kDst, "Dst" }, - { SkBlendMode::kSrcOver, "SrcOver" }, - { SkBlendMode::kDstOver, "DstOver" }, - { SkBlendMode::kSrcIn, "SrcIn" }, - { SkBlendMode::kDstIn, "DstIn" }, - { SkBlendMode::kSrcOut, "SrcOut" }, - { SkBlendMode::kDstOut, "DstOut" }, - { SkBlendMode::kSrcATop, "SrcATop" }, - { SkBlendMode::kDstATop, "DstATop" }, - { SkBlendMode::kXor, "Xor" }, + { SkXfermode::kClear_Mode, "Clear" }, + { SkXfermode::kSrc_Mode, "Src" }, + { SkXfermode::kDst_Mode, "Dst" }, + { SkXfermode::kSrcOver_Mode, "SrcOver" }, + { SkXfermode::kDstOver_Mode, "DstOver" }, + { SkXfermode::kSrcIn_Mode, "SrcIn" }, + { SkXfermode::kDstIn_Mode, "DstIn" }, + { SkXfermode::kSrcOut_Mode, "SrcOut" }, + { SkXfermode::kDstOut_Mode, "DstOut" }, + { SkXfermode::kSrcATop_Mode, "SrcATop" }, + { SkXfermode::kDstATop_Mode, "DstATop" }, + { SkXfermode::kXor_Mode, "Xor" }, }; const int gWidth = 64; @@ -34,7 +34,7 @@ const int gHeight = 64; const SkScalar W = SkIntToScalar(gWidth); const SkScalar H = SkIntToScalar(gHeight); -static SkScalar drawCell(SkCanvas* canvas, SkBlendMode mode, SkAlpha a0, SkAlpha a1) { +static SkScalar drawCell(SkCanvas* canvas, sk_sp<SkXfermode> mode, SkAlpha a0, SkAlpha a1) { SkPaint paint; paint.setAntiAlias(true); @@ -47,7 +47,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkBlendMode mode, SkAlpha a0, SkAlpha paint.setColor(SK_ColorRED); paint.setAlpha(a1); - paint.setBlendMode(mode); + paint.setXfermode(mode); for (int angle = 0; angle < 24; ++angle) { SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth; SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight; @@ -105,7 +105,7 @@ protected: } canvas->drawRect(bounds, fBGPaint); canvas->saveLayer(&bounds, nullptr); - SkScalar dy = drawCell(canvas, gModes[i].fMode, + SkScalar dy = drawCell(canvas, SkXfermode::Make(gModes[i].fMode), gAlphaValue[alpha & 1], gAlphaValue[alpha & 2]); canvas->restore(); diff --git a/samplecode/SampleLayerMask.cpp b/samplecode/SampleLayerMask.cpp index f0c6a40dc2..5fce85c4b7 100644 --- a/samplecode/SampleLayerMask.cpp +++ b/samplecode/SampleLayerMask.cpp @@ -44,13 +44,13 @@ protected: bounds.offset(-bounds.fLeft, -bounds.fTop); c.drawOval(bounds, paint); - paint.setBlendMode(SkBlendMode::kDstIn); + paint.setXfermodeMode(SkXfermode::kDstIn_Mode); canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint); } else { SkPath p; p.addOval(r); p.setFillType(SkPath::kInverseWinding_FillType); - paint.setBlendMode(SkBlendMode::kDstOut); + paint.setXfermodeMode(SkXfermode::kDstOut_Mode); canvas->drawPath(p, paint); } } diff --git a/samplecode/SampleLayers.cpp b/samplecode/SampleLayers.cpp index 71b2e8ba66..52e6593a85 100644 --- a/samplecode/SampleLayers.cpp +++ b/samplecode/SampleLayers.cpp @@ -31,7 +31,7 @@ static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) { SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } }; paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode, 0, &localMatrix)); - paint->setBlendMode(SkBlendMode::kDstIn); + paint->setXfermodeMode(SkXfermode::kDstIn_Mode); } // test drawing with strips of fading gradient above and below @@ -141,7 +141,7 @@ protected: canvas->saveLayer(&r, &p); canvas->drawColor(0xFFFF0000); p.setAlpha(0); // or 0 - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); canvas->drawOval(r, p); canvas->restore(); return; diff --git a/samplecode/SamplePathClip.cpp b/samplecode/SamplePathClip.cpp index af9608f0eb..a53fe7186b 100644 --- a/samplecode/SamplePathClip.cpp +++ b/samplecode/SamplePathClip.cpp @@ -225,7 +225,7 @@ protected: // We use a layer, so we can PLUS the different edge-colors, showing where two edges // canceled each other out. canvas->saveLayer(nullptr, nullptr); - p.setBlendMode(SkBlendMode::kPlus); + p.setXfermodeMode(SkXfermode::kPlus_Mode); for (int i = 0; i < N; ++i) { const int j = (i + 1) % N; p.setColor(fEdgeColor[i]); diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp index 30b8603bcf..ab65ff6d87 100644 --- a/samplecode/SampleQuadStroker.cpp +++ b/samplecode/SampleQuadStroker.cpp @@ -248,7 +248,7 @@ protected: canvas->restore(); SkPaint paint; - paint.setBlendMode(SkBlendMode::kClear); + paint.setXfermodeMode(SkXfermode::kClear_Mode); for (int iy = 1; iy < fH; ++iy) { SkScalar y = SkIntToScalar(iy * fZoom); canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint); diff --git a/samplecode/SampleRegion.cpp b/samplecode/SampleRegion.cpp index 082ff22286..1934dc74cb 100644 --- a/samplecode/SampleRegion.cpp +++ b/samplecode/SampleRegion.cpp @@ -80,7 +80,7 @@ static void drawFadingText(SkCanvas* canvas, SkPaint p; p.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 3, SkShader::kClamp_TileMode)); - p.setBlendMode(SkBlendMode::kDstIn); + p.setXfermodeMode(SkXfermode::kDstIn_Mode); canvas->drawRect(bounds, p); canvas->restore(); diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp index 521e9f6ead..5858d2674e 100644 --- a/samplecode/SampleSlides.cpp +++ b/samplecode/SampleSlides.cpp @@ -472,7 +472,7 @@ static void r0(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) p.setAlpha(0x11); p.setStyle(SkPaint::kFill_Style); - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); rastBuilder->addLayer(p); } @@ -481,7 +481,7 @@ static void r1(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) rastBuilder->addLayer(p); p.setAlpha(0x40); - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1*2); rastBuilder->addLayer(p); @@ -495,7 +495,7 @@ static void r2(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1*3/2); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); } @@ -507,7 +507,7 @@ static void r3(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) p.setAlpha(0x20); p.setStyle(SkPaint::kFill_Style); - p.setBlendMode(SkBlendMode::kSrc); + p.setXfermodeMode(SkXfermode::kSrc_Mode); rastBuilder->addLayer(p); } @@ -517,10 +517,10 @@ static void r4(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) rastBuilder->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); p.setAlpha(0xFF); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); - p.setBlendMode(SkBlendMode::kSrcOver); + p.setXfermode(nullptr); rastBuilder->addLayer(p); } @@ -531,7 +531,7 @@ static void r5(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) rastBuilder->addLayer(p); p.setPathEffect(SkDiscretePathEffect::Make(SK_Scalar1*4, SK_Scalar1*3)); - p.setBlendMode(SkBlendMode::kSrcOut); + p.setXfermodeMode(SkXfermode::kSrcOut_Mode); rastBuilder->addLayer(p); } @@ -543,7 +543,7 @@ static void r6(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) SkLayerRasterizer::Builder rastBuilder2; r5(&rastBuilder2, p); p.setRasterizer(rastBuilder2.detach()); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); } @@ -572,11 +572,11 @@ static void r8(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); lattice.postSkew(SK_Scalar1/3, 0, 0, 0); p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice)); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); p.setPathEffect(nullptr); - p.setBlendMode(SkBlendMode::kSrcOver); + p.setXfermode(nullptr); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1); rastBuilder->addLayer(p); @@ -590,11 +590,11 @@ static void r9(SkLayerRasterizer::Builder* rastBuilder, SkPaint& p) lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); lattice.postRotate(SkIntToScalar(30), 0, 0); p.setPathEffect(SkLine2DPathEffect::Make(SK_Scalar1*2, lattice)); - p.setBlendMode(SkBlendMode::kClear); + p.setXfermodeMode(SkXfermode::kClear_Mode); rastBuilder->addLayer(p); p.setPathEffect(nullptr); - p.setBlendMode(SkBlendMode::kSrcOver); + p.setXfermode(nullptr); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1); rastBuilder->addLayer(p); diff --git a/samplecode/SampleXfer.cpp b/samplecode/SampleXfer.cpp index c0ad000501..6aaffe59c9 100644 --- a/samplecode/SampleXfer.cpp +++ b/samplecode/SampleXfer.cpp @@ -18,18 +18,18 @@ #include "SkGradientShader.h" const struct { - SkBlendMode fMode; - const char* fName; + SkXfermode::Mode fMode; + const char* fName; } gModes[] = { - { SkBlendMode::kSrcOver, "src-over" }, - { SkBlendMode::kSrc, "src" }, - { SkBlendMode::kSrcIn, "src-in" }, - { SkBlendMode::kSrcOut, "src-out" }, - { SkBlendMode::kSrcATop, "src-atop" }, - { SkBlendMode::kDstOver, "dst-over" }, - { SkBlendMode::kDstIn, "dst-in" }, - { SkBlendMode::kDstOut, "dst-out" }, - { SkBlendMode::kDstATop, "dst-atop" }, + { SkXfermode::kSrcOver_Mode, "src-over" }, + { SkXfermode::kSrc_Mode, "src" }, + { SkXfermode::kSrcIn_Mode, "src-in" }, + { SkXfermode::kSrcOut_Mode, "src-out" }, + { SkXfermode::kSrcATop_Mode, "src-atop" }, + { SkXfermode::kDstOver_Mode, "dst-over" }, + { SkXfermode::kDstIn_Mode, "dst-in" }, + { SkXfermode::kDstOut_Mode, "dst-out" }, + { SkXfermode::kDstATop_Mode, "dst-atop" }, }; const int N_Modes = SK_ARRAY_COUNT(gModes); @@ -109,10 +109,10 @@ private: class ModeDrawable : public SkDrawable { public: - ModeDrawable() : fMode(SkBlendMode::kSrcOver), fLoc(SkPoint::Make(0, 0)) {} + ModeDrawable() : fMode(SkXfermode::kSrcOver_Mode), fLoc(SkPoint::Make(0, 0)) {} - SkBlendMode fMode; - SkPoint fLoc; + SkXfermode::Mode fMode; + SkPoint fLoc; bool hitTest(SkScalar x, SkScalar y) { SkRect target = SkRect::MakeXYWH(x - fLoc.x() - 1, y - fLoc.y() - 1, 3, 3); @@ -139,7 +139,7 @@ protected: } void onDraw(SkCanvas* canvas) override { - fPaint.setBlendMode(fMode); + fPaint.setXfermodeMode(fMode); canvas->save(); canvas->translate(fLoc.x(), fLoc.y()); canvas->drawOval(fBounds, fPaint); @@ -160,7 +160,7 @@ class XferDemo : public SampleView { SkScalar x = 10; SkScalar y = 10; for (int i = 0; i < N_Modes; ++i) { - SkAutoTUnref<SkView> v(new PushButtonWig(gModes[i].fName, (int)gModes[i].fMode)); + SkAutoTUnref<SkView> v(new PushButtonWig(gModes[i].fName, gModes[i].fMode)); v->setSize(70, 25); v->setLoc(x, y); v->setVisibleP(true); @@ -178,7 +178,7 @@ public: for (int i = 0; i < N; ++i) { fDrs[i].reset(new CircDrawable(200, colors[i])); fDrs[i]->fLoc.set(100.f + i * 100, 100.f + i * 100); - fDrs[i]->fMode = SkBlendMode::kSrcOver; + fDrs[i]->fMode = SkXfermode::kSrcOver_Mode; } fSelected = nullptr; @@ -189,7 +189,7 @@ protected: bool onEvent(const SkEvent& evt) override { if (evt.isType("push-button")) { if (fSelected) { - fSelected->fMode = (SkBlendMode)evt.getFast32(); + fSelected->fMode = (SkXfermode::Mode)evt.getFast32(); this->inval(nullptr); } return true; diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp index fe07c9b567..ef25114cf0 100644 --- a/samplecode/SampleXfermodesBlur.cpp +++ b/samplecode/SampleXfermodesBlur.cpp @@ -37,7 +37,8 @@ class XfermodesBlurView : public SampleView { SkBitmap fBG; SkBitmap fSrcB, fDstB; - void draw_mode(SkCanvas* canvas, SkBlendMode mode, int alpha, SkScalar x, SkScalar y) { + void draw_mode(SkCanvas* canvas, sk_sp<SkXfermode> mode, int alpha, + SkScalar x, SkScalar y) { SkPaint p; p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(5), @@ -54,7 +55,7 @@ class XfermodesBlurView : public SampleView { r.offset(x, y); canvas->drawOval(r, p); - p.setBlendMode(mode); + p.setXfermode(std::move(mode)); // draw a square overlapping the circle // in the lower right of the canvas @@ -109,23 +110,34 @@ protected: } const struct { - SkBlendMode fMode; - const char* fLabel; + SkXfermode::Mode fMode; + const char* fLabel; } gModes[] = { - { SkBlendMode::kClear, "Clear" }, - { SkBlendMode::kSrc, "Src" }, - { SkBlendMode::kDst, "Dst" }, - { SkBlendMode::kSrcOver, "SrcOver" }, - { SkBlendMode::kDstOver, "DstOver" }, - { SkBlendMode::kSrcIn, "SrcIn" }, - { SkBlendMode::kDstIn, "DstIn" }, - { SkBlendMode::kSrcOut, "SrcOut" }, - { SkBlendMode::kDstOut, "DstOut" }, - { SkBlendMode::kSrcATop, "SrcATop" }, - { SkBlendMode::kDstATop, "DstATop" }, - { SkBlendMode::kXor, "Xor" }, - - { SkBlendMode::kPlus, "Plus" }, + { SkXfermode::kClear_Mode, "Clear" }, + { SkXfermode::kSrc_Mode, "Src" }, + { SkXfermode::kDst_Mode, "Dst" }, + { SkXfermode::kSrcOver_Mode, "SrcOver" }, + { SkXfermode::kDstOver_Mode, "DstOver" }, + { SkXfermode::kSrcIn_Mode, "SrcIn" }, + { SkXfermode::kDstIn_Mode, "DstIn" }, + { SkXfermode::kSrcOut_Mode, "SrcOut" }, + { SkXfermode::kDstOut_Mode, "DstOut" }, + { SkXfermode::kSrcATop_Mode, "SrcATop" }, + { SkXfermode::kDstATop_Mode, "DstATop" }, + { SkXfermode::kXor_Mode, "Xor" }, + + { SkXfermode::kPlus_Mode, "Plus" }, + /*{ SkXfermode::kModulate_Mode, "Modulate" }, + { SkXfermode::kScreen_Mode, "Screen" }, + { SkXfermode::kOverlay_Mode, "Overlay" }, + { SkXfermode::kDarken_Mode, "Darken" }, + { SkXfermode::kLighten_Mode, "Lighten" }, + { SkXfermode::kColorDodge_Mode, "ColorDodge" }, + { SkXfermode::kColorBurn_Mode, "ColorBurn" }, + { SkXfermode::kHardLight_Mode, "HardLight" }, + { SkXfermode::kSoftLight_Mode, "SoftLight" }, + { SkXfermode::kDifference_Mode, "Difference" }, + { SkXfermode::kExclusion_Mode, "Exclusion" },*/ }; const SkScalar w = SkIntToScalar(W); @@ -156,7 +168,8 @@ protected: canvas->drawRect(r, p); canvas->saveLayer(&r, nullptr); - draw_mode(canvas, gModes[i].fMode, twice ? 0x88 : 0xFF, r.fLeft, r.fTop); + draw_mode(canvas, SkXfermode::Make(gModes[i].fMode), + twice ? 0x88 : 0xFF, r.fLeft, r.fTop); canvas->restore(); r.inset(-SK_ScalarHalf, -SK_ScalarHalf); |