Update SkMorphology ImageFilters to sk_sp
authorrobertphillips <robertphillips@google.com>
Tue, 5 Apr 2016 16:09:36 +0000 (09:09 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 5 Apr 2016 16:09:37 +0000 (09:09 -0700)
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

15 files changed:
bench/MorphologyBench.cpp
gm/imagefilters.cpp
gm/imagefiltersclipped.cpp
gm/imagefilterscropexpand.cpp
gm/imagefilterscropped.cpp
gm/imagefiltersgraph.cpp
gm/imagefiltersscaled.cpp
gm/imagefilterstransformed.cpp
gm/localmatriximagefilter.cpp
gm/morphology.cpp
include/effects/SkMorphologyImageFilter.h
samplecode/SampleFilterFuzz.cpp
samplecode/SampleLayers.cpp
src/effects/SkMorphologyImageFilter.cpp
tests/ImageFilterTest.cpp

index fd60ebed466b5f7bdb805d7784f196024bf5305b..5edae6e299525e4078b3a41087b1bb2f55f8ba17 100644 (file)
@@ -46,11 +46,11 @@ public:
     }
 
 protected:
-    virtual const char* onGetName() {
+    const char* onGetName() override {
         return fName.c_str();
     }
 
-    virtual void onDraw(int loops, SkCanvas* canvas) {
+    void onDraw(int loops, SkCanvas* canvas) override {
         SkPaint paint;
         this->setupPaint(&paint);
 
@@ -63,18 +63,20 @@ protected:
             r.offset(fRadius, fRadius);
 
             if (fRadius > 0) {
-                SkImageFilter* mf = nullptr;
+                sk_sp<SkImageFilter> mf;
                 switch (fStyle) {
                 case kDilate_MT:
-                    mf = SkDilateImageFilter::Create(SkScalarFloorToInt(fRadius),
-                                                    SkScalarFloorToInt(fRadius));
+                    mf = SkDilateImageFilter::Make(SkScalarFloorToInt(fRadius),
+                                                   SkScalarFloorToInt(fRadius),
+                                                   nullptr);
                     break;
                 case kErode_MT:
-                    mf = SkErodeImageFilter::Create(SkScalarFloorToInt(fRadius),
-                                                    SkScalarFloorToInt(fRadius));
+                    mf = SkErodeImageFilter::Make(SkScalarFloorToInt(fRadius),
+                                                  SkScalarFloorToInt(fRadius),
+                                                  nullptr);
                     break;
                 }
-                paint.setImageFilter(mf)->unref();
+                paint.setImageFilter(std::move(mf));
             }
             canvas->drawOval(r, paint);
         }
index 10072c897ef3a71320fd1332fd8ea71268321d92..f1f1b80ac9e121757364a99a4a3ab55caa65b533 100644 (file)
@@ -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),
index 85c5438bca9c929312aafeb30e6495d5849f22ec..b123094a80495d11569657fc83d582776c4ec641 100644 (file)
@@ -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()),
index f1a132369ac723edb88290b74be2836439524250..8f36ba90418072d5b468d43a17cd5abd2b369bf4 100644 (file)
@@ -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(
index 1e880fe68a96e67c93ce1d54448a96676833b62c..66e4d870e9eea9263d7d599dde1c4ec1a01af0f2 100644 (file)
@@ -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:
index e7bcf707c38ff12a28434fa38366379fb37ea555..eb5519a761480e4f05e959342d7ed1358705f674 100644 (file)
@@ -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);
index 56a1484f219dc59bfcd65d268ea56943897cfabe..3f819d874a71ae24f75b6b38283922f8b840ab4c 100644 (file)
@@ -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(),
index 687e458f1fe04129020de05998ae372b408cfaae..1ab52b9f58044649ceba8d27df71063657b283ce 100644 (file)
@@ -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);
index baa44b9d0b13ce0b218757ca1c06ed7b4e25fa81..d5b7e3e50d8a38dc155c5c5b7f0e53f1a5e86a5d 100644 (file)
@@ -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[] = {
index c3326f9397ca91cd29e3f4ca325d49d2a109a19b..f60079b873f2a0c514c6dd46a74ec10eca1e7d1e 100644 (file)
@@ -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);
             }
index 4e699a7633eaa9b924b32e675ef86e1dfdb2b14a..27608ecd07f8d727e0e91a81400312b7af75a508 100644 (file)
@@ -36,7 +36,8 @@ protected:
 
     virtual Op op() const = 0;
 
-    SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input,
+    SkMorphologyImageFilter(int radiusX, int radiusY,
+                            sk_sp<SkImageFilter> input,
                             const CropRect* cropRect);
     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source,
                                         const Context&,
@@ -54,23 +55,37 @@ private:
 ///////////////////////////////////////////////////////////////////////////////
 class SK_API SkDilateImageFilter : public SkMorphologyImageFilter {
 public:
-    static SkImageFilter* Create(int radiusX, int radiusY,
-                                 SkImageFilter* input = nullptr,
-                                 const CropRect* cropRect = nullptr) {
+    static sk_sp<SkImageFilter> Make(int radiusX, int radiusY,
+                                     sk_sp<SkImageFilter> input,
+                                     const CropRect* cropRect = nullptr) {
         if (radiusX < 0 || radiusY < 0) {
             return nullptr;
         }
-        return new SkDilateImageFilter(radiusX, radiusY, input, cropRect);
+        return sk_sp<SkImageFilter>(new SkDilateImageFilter(radiusX, radiusY,
+                                                            std::move(input),
+                                                            cropRect));
     }
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter)
 
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+    static SkImageFilter* Create(int radiusX, int radiusY,
+                                 SkImageFilter* input = nullptr,
+                                 const CropRect* cropRect = nullptr) {
+        return Make(radiusX, radiusY,
+                    sk_ref_sp<SkImageFilter>(input),
+                    cropRect).release();
+    }
+#endif
+
 protected:
     Op op() const override { return kDilate_Op; }
 
 private:
-    SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect)
+    SkDilateImageFilter(int radiusX, int radiusY,
+                        sk_sp<SkImageFilter> input,
+                        const CropRect* cropRect)
         : INHERITED(radiusX, radiusY, input, cropRect) {}
 
     typedef SkMorphologyImageFilter INHERITED;
@@ -79,23 +94,36 @@ private:
 ///////////////////////////////////////////////////////////////////////////////
 class SK_API SkErodeImageFilter : public SkMorphologyImageFilter {
 public:
-    static SkImageFilter* Create(int radiusX, int radiusY,
-                                 SkImageFilter* input = nullptr,
-                                 const CropRect* cropRect = nullptr) {
+    static sk_sp<SkImageFilter> Make(int radiusX, int radiusY,
+                                     sk_sp<SkImageFilter> input,
+                                     const CropRect* cropRect = nullptr) {
         if (radiusX < 0 || radiusY < 0) {
             return nullptr;
         }
-        return new SkErodeImageFilter(radiusX, radiusY, input, cropRect);
+        return sk_sp<SkImageFilter>(new SkErodeImageFilter(radiusX, radiusY,
+                                                           std::move(input),
+                                                           cropRect));
     }
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter)
 
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+    static SkImageFilter* Create(int radiusX, int radiusY,
+                                 SkImageFilter* input = nullptr,
+                                 const CropRect* cropRect = nullptr) {
+        return Make(radiusX, radiusY,
+                    sk_ref_sp<SkImageFilter>(input),
+                    cropRect).release();
+    }
+#endif
+
 protected:
     Op op() const override { return kErode_Op; }
 
 private:
-    SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect)
+    SkErodeImageFilter(int radiusX, int radiusY,
+                       sk_sp<SkImageFilter> input, const CropRect* cropRect)
         : INHERITED(radiusX, radiusY, input, cropRect) {}
 
     typedef SkMorphologyImageFilter INHERITED;
index 1b7d30be1de12ff32d473ce4a6e250cbf469433a..5d433b5748b22c339b6a5a2d61b3da3d61d1c0f3 100644 (file)
@@ -705,20 +705,17 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
                                                                       nullptr));
         break;
     }
-    case MORPHOLOGY: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case MORPHOLOGY:
         if (R(2) == 1) {
-            filter = sk_sp<SkImageFilter>(SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSize)),
-                                                R(static_cast<float>(kBitmapSize)),
-                                                subFilter.get()));
+            filter = SkDilateImageFilter::Make(R(static_cast<float>(kBitmapSize)),
+                                               R(static_cast<float>(kBitmapSize)),
+                                               make_image_filter());
         } else {
-            filter = sk_sp<SkImageFilter>(SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize)),
-                                                R(static_cast<float>(kBitmapSize)),
-                                                subFilter.get()));
+            filter = SkErodeImageFilter::Make(R(static_cast<float>(kBitmapSize)),
+                                              R(static_cast<float>(kBitmapSize)),
+                                              make_image_filter());
         }
         break;
-    }
     case BITMAP: {
         sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap()));
         if (R(2) == 1) {
index 8c2724ce95e4464bd8b17f19e28d82ca180abff5..194f0a70a92505882f01beab8633c8cf0a5c9cf7 100644 (file)
@@ -245,13 +245,13 @@ class BackdropView : public SampleView {
     SkPoint fCenter;
     SkScalar fAngle;
     sk_sp<SkImage> fImage;
-    SkAutoTUnref<SkImageFilter> fFilter;
+    sk_sp<SkImageFilter> fFilter;
 public:
     BackdropView() {
         fCenter.set(200, 150);
         fAngle = 0;
         fImage = GetResourceAsImage("mandrill_512.png");
-        fFilter.reset(SkDilateImageFilter::Create(8, 8));
+        fFilter = SkDilateImageFilter::Make(8, 8, nullptr);
     }
 
 protected:
@@ -281,7 +281,7 @@ protected:
 
         SkPaint paint;
         paint.setAlpha(0xCC);
-        canvas->saveLayer({ &bounds, &paint, fFilter, 0 });
+        canvas->saveLayer({ &bounds, &paint, fFilter.get(), 0 });
 
         canvas->restore();
     }
index bf8811b88702a7caf69e8cacde999b200a1194ac..ea714e59f69b1579bc26d2e87c95c8c58915a6f5 100644 (file)
@@ -30,9 +30,9 @@
 
 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX,
                                                  int radiusY,
-                                                 SkImageFilter* input,
+                                                 sk_sp<SkImageFilter> input,
                                                  const CropRect* cropRect)
-    : INHERITED(1, &input, cropRect)
+    : INHERITED(&input, 1, cropRect)
     , fRadius(SkISize::Make(radiusX, radiusY)) {
 }
 
@@ -76,16 +76,14 @@ sk_sp<SkFlattenable> SkErodeImageFilter::CreateProc(SkReadBuffer& buffer) {
     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
     const int width = buffer.readInt();
     const int height = buffer.readInt();
-    return sk_sp<SkFlattenable>(Create(width, height, common.getInput(0).get(),
-                                       &common.cropRect()));
+    return Make(width, height, common.getInput(0), &common.cropRect());
 }
 
 sk_sp<SkFlattenable> SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) {
     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
     const int width = buffer.readInt();
     const int height = buffer.readInt();
-    return sk_sp<SkFlattenable>(Create(width, height, common.getInput(0).get(),
-                                       &common.cropRect()));
+    return Make(width, height, common.getInput(0), &common.cropRect());
 }
 
 #ifndef SK_IGNORE_TO_STRING
index 21ddc162d2cd97eadb39a7bfa994767012eff01d..58dc1a7161a0093b8c46913dc0f347a6e6ba80ba 100644 (file)
@@ -143,7 +143,7 @@ SkBitmap make_gradient_circle(int width, int height) {
 
 class FilterList {
 public:
-    FilterList(SkImageFilter* input = nullptr, const SkImageFilter::CropRect* cropRect = nullptr) {
+    FilterList(sk_sp<SkImageFilter> input, const SkImageFilter::CropRect* cropRect = nullptr) {
         SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
         SkScalar kernel[9] = {
             SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
@@ -164,7 +164,7 @@ public:
                                                                   SkXfermode::kSrcIn_Mode));
 
             this->addFilter("color filter",
-                SkColorFilterImageFilter::Create(cf.get(), input, cropRect));
+                SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect));
         }
 
         {
@@ -174,27 +174,28 @@ public:
             this->addFilter("displacement map", SkDisplacementMapEffect::Create(
                 SkDisplacementMapEffect::kR_ChannelSelectorType,
                 SkDisplacementMapEffect::kB_ChannelSelectorType,
-                20.0f, gradientSource.get(), input, cropRect));
+                20.0f, gradientSource.get(), input.get(), cropRect));
         }
 
         this->addFilter("blur", SkBlurImageFilter::Make(SK_Scalar1,
                                                         SK_Scalar1,
-                                                        sk_ref_sp<SkImageFilter>(input),
+                                                        input,
                                                         cropRect).release());
         this->addFilter("drop shadow", SkDropShadowImageFilter::Create(
                   SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN,
-                  SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, input, cropRect));
+                  SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
+                  input.get(), cropRect));
         this->addFilter("diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse(
-                  location, SK_ColorGREEN, 0, 0, input, cropRect));
+                  location, SK_ColorGREEN, 0, 0, input.get(), cropRect));
         this->addFilter("specular lighting",
                   SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0,
-                                                                input, cropRect));
+                                                                input.get(), cropRect));
         this->addFilter("matrix convolution",
                   SkMatrixConvolutionImageFilter::Create(
                       kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1),
-                      SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, input, cropRect));
-        this->addFilter("merge", SkMergeImageFilter::Make(sk_ref_sp<SkImageFilter>(input),
-                                                          sk_ref_sp<SkImageFilter>(input),
+                      SkMatrixConvolutionImageFilter::kRepeat_TileMode, false,
+                      input.get(), cropRect));
+        this->addFilter("merge", SkMergeImageFilter::Make(input, input,
                                                           SkXfermode::kSrcOver_Mode,
                                                           cropRect).release());
         {
@@ -215,23 +216,21 @@ public:
         }
 
         this->addFilter("offset",
-                        SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1,
-                                                  sk_ref_sp<SkImageFilter>(input),
+                        SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1, input,
                                                   cropRect).release());
-        this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropRect));
-        this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRect));
+        this->addFilter("dilate", SkDilateImageFilter::Make(3, 2, input, cropRect).release());
+        this->addFilter("erode", SkErodeImageFilter::Make(2, 3, input, cropRect).release());
         this->addFilter("tile", SkTileImageFilter::Create(
             SkRect::MakeXYWH(0, 0, 50, 50),
             cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100),
-            input));
+            input.get()));
         if (!cropRect) {
             this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
-                matrix, kLow_SkFilterQuality, input));
+                matrix, kLow_SkFilterQuality, input.get()));
         }
 
         {
-            sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five, 
-                                                              sk_ref_sp<SkImageFilter>(input)));
+            sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five, input));
 
             this->addFilter("blur and offset", SkOffsetImageFilter::Make(five, five,
                                                                          std::move(blur),
@@ -262,7 +261,8 @@ public:
                                                                       cropRect).release());
         }
         this->addFilter("xfermode", SkXfermodeImageFilter::Make(
-            SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).release());
+            SkXfermode::Make(SkXfermode::kSrc_Mode), input.get(), input.get(),
+            cropRect).release());
     }
     int count() const { return fFilters.count(); }
     SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }
@@ -519,9 +519,9 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy,
 
     SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
     SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
-    SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
+    sk_sp<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
 
-    FilterList filters(input.get(), &cropRect);
+    FilterList filters(input, &cropRect);
 
     for (int i = 0; i < filters.count(); ++i) {
         SkImageFilter* filter = filters.getFilter(i);
@@ -742,7 +742,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
     // match the same filters drawn with a single full-canvas bitmap draw.
     // Tests pass by not asserting.
 
-    FilterList filters;
+    FilterList filters(nullptr);
 
     SkBitmap untiledResult, tiledResult;
     const int width = 64, height = 64;
@@ -875,7 +875,7 @@ DEF_TEST(ImageFilterShadowThenBlurBounds, reporter) {
 }
 
 DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) {
-    sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2));
+    sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Make(2, 2, nullptr));
     sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1)));
 
     SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100);