diff options
author | robertphillips <robertphillips@google.com> | 2016-04-05 09:09:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-05 09:09:37 -0700 |
commit | fc11b0afe0ca922a42767d4a656ed640008da1bb (patch) | |
tree | eb84a2ba05f37c8e7b9c721f38bc93bac27b5bcb /gm | |
parent | b8797bb7b74adcab1d198de3ef4f0871b0bb6718 (diff) |
Update SkMorphology ImageFilters to sk_sp
TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1860573002
Review URL: https://codereview.chromium.org/1860573002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/imagefilters.cpp | 4 | ||||
-rw-r--r-- | gm/imagefiltersclipped.cpp | 8 | ||||
-rw-r--r-- | gm/imagefilterscropexpand.cpp | 14 | ||||
-rw-r--r-- | gm/imagefilterscropped.cpp | 67 | ||||
-rw-r--r-- | gm/imagefiltersgraph.cpp | 22 | ||||
-rw-r--r-- | gm/imagefiltersscaled.cpp | 4 | ||||
-rw-r--r-- | gm/imagefilterstransformed.cpp | 4 | ||||
-rw-r--r-- | gm/localmatriximagefilter.cpp | 10 | ||||
-rw-r--r-- | gm/morphology.cpp | 18 |
9 files changed, 75 insertions, 76 deletions
diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp index 10072c897e..f1f1b80ac9 100644 --- a/gm/imagefilters.cpp +++ b/gm/imagefilters.cpp @@ -139,11 +139,11 @@ static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) { DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) { SkColorMatrix cm; cm.setSaturation(10); - auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); + sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 }; SkImageFilter* filters[] = { SkBlurImageFilter::Make(10, 10, nullptr).release(), - SkDilateImageFilter::Create(8, 8), + SkDilateImageFilter::Make(8, 8, nullptr).release(), SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 }, SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, true), diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp index 85c5438bca..b123094a80 100644 --- a/gm/imagefiltersclipped.cpp +++ b/gm/imagefiltersclipped.cpp @@ -103,11 +103,9 @@ protected: SkIntToScalar(12), gradient.get(), checkerboard.get()), - SkDilateImageFilter::Create(2, 2, checkerboard.get()), - SkErodeImageFilter::Create(2, 2, checkerboard.get()), - SkOffsetImageFilter::Make(SkIntToScalar(-16), - SkIntToScalar(32), - nullptr).release(), + SkDilateImageFilter::Make(2, 2, checkerboard).release(), + SkErodeImageFilter::Make(2, 2, checkerboard).release(), + SkOffsetImageFilter::Make(SkIntToScalar(-16), SkIntToScalar(32), nullptr).release(), SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality), SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1, SkIntToScalar(2), checkerboard.get()), diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index f1a132369a..8f36ba9041 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -88,15 +88,13 @@ protected: noopCropped, &bigRect)); - Draw(canvas, checkerboard, rect, - sk_sp<SkImageFilter>(SkDilateImageFilter::Create(2, 2, - noopCropped.get(), - &bigRect))); + Draw(canvas, checkerboard, rect, SkDilateImageFilter::Make(2, 2, + noopCropped, + &bigRect)); - Draw(canvas, checkerboard, rect, - sk_sp<SkImageFilter>(SkErodeImageFilter::Create(2, 2, - noopCropped.get(), - &bigRect))); + Draw(canvas, checkerboard, rect, SkErodeImageFilter::Make(2, 2, + noopCropped, + &bigRect)); Draw(canvas, checkerboard, rect, sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create( diff --git a/gm/imagefilterscropped.cpp b/gm/imagefilterscropped.cpp index 1e880fe68a..66e4d870e9 100644 --- a/gm/imagefilterscropped.cpp +++ b/gm/imagefilterscropped.cpp @@ -20,9 +20,9 @@ /////////////////////////////////////////////////////////////////////////////// -static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { SkPaint paint; - paint.setImageFilter(imf); + paint.setImageFilter(std::move(imf)); paint.setColor(SK_ColorBLACK); canvas->save(); canvas->clipRect(r); @@ -30,17 +30,17 @@ static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->restore(); } -static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { SkPaint paint; paint.setColor(SK_ColorMAGENTA); - paint.setImageFilter(imf); + paint.setImageFilter(std::move(imf)); paint.setAntiAlias(true); canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint); } -static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { SkPaint paint; - paint.setImageFilter(imf); + paint.setImageFilter(std::move(imf)); paint.setColor(SK_ColorGREEN); paint.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&paint); @@ -49,7 +49,7 @@ static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint); } -static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { +static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { SkPaint paint; SkIRect bounds; @@ -61,7 +61,7 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { SkCanvas c(bm); draw_path(&c, r, nullptr); - paint.setImageFilter(imf); + paint.setImageFilter(std::move(imf)); canvas->drawBitmap(bm, 0, 0, &paint); } @@ -111,13 +111,16 @@ protected: } virtual void onDraw(SkCanvas* canvas) override { - void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { + void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = { draw_bitmap, draw_path, draw_paint, draw_text }; - auto cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); - SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge); - SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge); + sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, + SkXfermode::kSrcIn_Mode)); + SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), + SkImageFilter::CropRect::kHasAll_CropEdge); + SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), + SkImageFilter::CropRect::kHasAll_CropEdge); sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(SkIntToScalar(-10), SkIntToScalar(-10), @@ -125,25 +128,27 @@ protected: sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get())); - SkAutoTUnref<SkImageFilter> erodeX(SkErodeImageFilter::Create(8, 0, nullptr, &cropRect)); - SkAutoTUnref<SkImageFilter> erodeY(SkErodeImageFilter::Create(0, 8, nullptr, &cropRect)); + sk_sp<SkImageFilter> erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect)); + sk_sp<SkImageFilter> erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect)); - SkImageFilter* filters[] = { + sk_sp<SkImageFilter> filters[] = { nullptr, - SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect), - SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect).release(), - SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect).release(), - SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect).release(), - SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect).release(), - SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect).release(), - SkErodeImageFilter::Create(1, 1, nullptr, &cropRect), - SkErodeImageFilter::Create(8, 0, erodeY, &cropRect), - SkErodeImageFilter::Create(0, 8, erodeX, &cropRect), - SkErodeImageFilter::Create(8, 8, nullptr, &cropRect), - SkMergeImageFilter::Make(nullptr, std::move(cfOffset), - SkXfermode::kSrcOver_Mode, &cropRect).release(), - SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect).release(), - SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect), + sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect)), + SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect), + SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect), + SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect), + SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect), + SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect), + SkErodeImageFilter::Make(1, 1, nullptr, &cropRect), + SkErodeImageFilter::Make(8, 0, std::move(erodeY), &cropRect), + SkErodeImageFilter::Make(0, 8, std::move(erodeX), &cropRect), + SkErodeImageFilter::Make(8, 8, nullptr, &cropRect), + SkMergeImageFilter::Make(nullptr, + std::move(cfOffset), + SkXfermode::kSrcOver_Mode, + &cropRect), + SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect), + sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect)), }; SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); @@ -163,10 +168,6 @@ protected: canvas->restore(); canvas->translate(DX, 0); } - - for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { - SkSafeUnref(filters[j]); - } } private: diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index e7bcf707c3..eb5519a761 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -136,7 +136,7 @@ protected: sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource))); - sk_sp<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, blur.get())); + sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur)); sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get(), erode.get())); sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color)); @@ -146,7 +146,7 @@ protected: canvas->translate(SkIntToScalar(100), 0); } { - sk_sp<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5)); + sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr)); SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, 0, SK_Scalar1, 0, 0, 0, @@ -199,7 +199,7 @@ protected: // This tests that a filter using asFragmentProcessor (matrix // convolution) correctly handles a non-zero source offset // (supplied by the dilate). - SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5)); + sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr)); SkScalar kernel[9] = { SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), @@ -211,7 +211,7 @@ protected: SkIPoint kernelOffset = SkIPoint::Make(1, 1); auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode; bool convolveAlpha = false; - SkAutoTUnref<SkImageFilter> convolve( + sk_sp<SkImageFilter> convolve( SkMatrixConvolutionImageFilter::Create(kernelSize, kernel, gain, @@ -219,10 +219,10 @@ protected: kernelOffset, tileMode, convolveAlpha, - dilate)); + dilate.get())); SkPaint paint; - paint.setImageFilter(convolve); + paint.setImageFilter(std::move(convolve)); DrawClippedImage(canvas, fImage.get(), paint); canvas->translate(SkIntToScalar(100), 0); } @@ -234,11 +234,15 @@ protected: SkIntToScalar(80), SkIntToScalar(80))); SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(60), SkIntToScalar(60))); - SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(), nullptr, &outerRect)); - SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(), color1, &innerRect)); + sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(), + nullptr, + &outerRect)); + sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(), + color1.get(), + &innerRect)); SkPaint paint; - paint.setImageFilter(color2); + paint.setImageFilter(std::move(color2)); paint.setColor(SK_ColorRED); canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint); canvas->translate(SkIntToScalar(100), 0); diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp index 56a1484f21..3f819d874a 100644 --- a/gm/imagefiltersscaled.cpp +++ b/gm/imagefiltersscaled.cpp @@ -82,8 +82,8 @@ protected: SkIntToScalar(12), gradient.get(), checkerboard.get()), - SkDilateImageFilter::Create(1, 1, checkerboard.get()), - SkErodeImageFilter::Create(1, 1, checkerboard.get()), + SkDilateImageFilter::Make(1, 1, checkerboard).release(), + SkErodeImageFilter::Make(1, 1, checkerboard).release(), SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr).release(), SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality), SkPaintImageFilter::Make(noisePaint).release(), diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp index 687e458f1f..1ab52b9f58 100644 --- a/gm/imagefilterstransformed.cpp +++ b/gm/imagefilterstransformed.cpp @@ -74,8 +74,8 @@ protected: 12, gradient.get(), checkerboard.get()), - SkDilateImageFilter::Create(2, 2, checkerboard.get()), - SkErodeImageFilter::Create(2, 2, checkerboard.get()), + SkDilateImageFilter::Make(2, 2, checkerboard).release(), + SkErodeImageFilter::Make(2, 2, checkerboard).release(), }; const SkScalar margin = SkIntToScalar(20); diff --git a/gm/localmatriximagefilter.cpp b/gm/localmatriximagefilter.cpp index baa44b9d0b..d5b7e3e50d 100644 --- a/gm/localmatriximagefilter.cpp +++ b/gm/localmatriximagefilter.cpp @@ -28,7 +28,7 @@ static sk_sp<SkImage> make_image(SkCanvas* rootCanvas) { return surface->makeImageSnapshot(); } -typedef SkImageFilter* (*ImageFilterFactory)(); +typedef sk_sp<SkImageFilter> (*ImageFilterFactory)(); // +[]{...} did not work on windows (VS) // (ImageFilterFactory)[]{...} did not work on linux (gcc) @@ -65,10 +65,10 @@ protected: sk_sp<SkImage> image0(make_image(canvas)); const ImageFilterFactory factories[] = { - IFCCast([]{ return SkBlurImageFilter::Make(8, 8, nullptr).release(); }), - IFCCast([]{ return SkDilateImageFilter::Create(8, 8); }), - IFCCast([]{ return SkErodeImageFilter::Create(8, 8); }), - IFCCast([]{ return SkOffsetImageFilter::Make(8, 8, nullptr).release(); }), + IFCCast([]{ return SkBlurImageFilter::Make(8, 8, nullptr); }), + IFCCast([]{ return SkDilateImageFilter::Make(8, 8, nullptr); }), + IFCCast([]{ return SkErodeImageFilter::Make(8, 8, nullptr); }), + IFCCast([]{ return SkOffsetImageFilter::Make(8, 8, nullptr); }), }; const SkMatrix matrices[] = { diff --git a/gm/morphology.cpp b/gm/morphology.cpp index c3326f9397..f60079b873 100644 --- a/gm/morphology.cpp +++ b/gm/morphology.cpp @@ -70,17 +70,15 @@ protected: for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : nullptr; if (j & 0x01) { - paint.setImageFilter(SkErodeImageFilter::Create( - samples[i].fRadiusX, - samples[i].fRadiusY, - nullptr, - cr))->unref(); + paint.setImageFilter(SkErodeImageFilter::Make(samples[i].fRadiusX, + samples[i].fRadiusY, + nullptr, + cr)); } else { - paint.setImageFilter(SkDilateImageFilter::Create( - samples[i].fRadiusX, - samples[i].fRadiusY, - nullptr, - cr))->unref(); + paint.setImageFilter(SkDilateImageFilter::Make(samples[i].fRadiusX, + samples[i].fRadiusY, + nullptr, + cr)); } this->drawClippedBitmap(canvas, paint, i * 140, j * 140); } |