Update SkColorFilterImageFilter to sk_sp
authorrobertphillips <robertphillips@google.com>
Tue, 5 Apr 2016 18:50:42 +0000 (11:50 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 5 Apr 2016 18:50:42 +0000 (11:50 -0700)
TBR=reed@google.com

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1858813002

Review URL: https://codereview.chromium.org/1858813002

20 files changed:
bench/ColorFilterBench.cpp
bench/ImageFilterCollapse.cpp
gm/coloremoji.cpp
gm/colorfilterimagefilter.cpp
gm/dropshadowimagefilter.cpp
gm/fadefilter.cpp
gm/imagefilters.cpp
gm/imagefiltersbase.cpp
gm/imagefilterscropexpand.cpp
gm/imagefilterscropped.cpp
gm/imagefiltersgraph.cpp
gm/recordopts.cpp
gm/tablecolorfilter.cpp
gm/testimagefilters.cpp
gm/tileimagefilter.cpp
include/effects/SkColorFilterImageFilter.h
samplecode/SampleFilterFuzz.cpp
src/effects/SkColorFilterImageFilter.cpp
tests/ImageFilterTest.cpp
tests/PictureTest.cpp

index c4ba1e5dcb435e709aa103a9a5d54479c8290dd1..30bd3161a0566395d837e856d0b482ec00093454 100644 (file)
@@ -9,14 +9,39 @@
 #include "SkCanvas.h"
 #include "SkColorFilterImageFilter.h"
 #include "SkColorMatrixFilter.h"
-#include "SkLumaColorFilter.h"
-#include "SkTableColorFilter.h"
 
 #define FILTER_WIDTH_SMALL  SkIntToScalar(32)
 #define FILTER_HEIGHT_SMALL SkIntToScalar(32)
 #define FILTER_WIDTH_LARGE  SkIntToScalar(256)
 #define FILTER_HEIGHT_LARGE SkIntToScalar(256)
 
+static sk_sp<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> input) {
+    SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255));
+    SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
+                            0, 1, 0, 0, amount255,
+                            0, 0, 1, 0, amount255,
+                            0, 0, 0, 1, 0 };
+    sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
+static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
+    SkScalar matrix[20];
+    memset(matrix, 0, 20 * sizeof(SkScalar));
+    matrix[0] = matrix[5] = matrix[10] = 0.2126f;
+    matrix[1] = matrix[6] = matrix[11] = 0.7152f;
+    matrix[2] = matrix[7] = matrix[12] = 0.0722f;
+    matrix[18] = 1.0f;
+    sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
+static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) {
+    sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+                                                              SkXfermode::kSrcIn_Mode));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
 class ColorFilterBaseBench : public Benchmark {
 
 public:
@@ -24,34 +49,8 @@ public:
 
 protected:
     SkRect getFilterRect() const {
-        return isSmall() ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
-                           SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
-    }
-
-    static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullptr) {
-        SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255));
-        SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
-                                0, 1, 0, 0, amount255,
-                                0, 0, 1, 0, amount255,
-                                0, 0, 0, 1, 0 };
-        auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-        return SkColorFilterImageFilter::Create(filter.get(), input);
-    }
-
-    static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
-        SkScalar matrix[20];
-        memset(matrix, 0, 20 * sizeof(SkScalar));
-        matrix[0] = matrix[5] = matrix[10] = 0.2126f;
-        matrix[1] = matrix[6] = matrix[11] = 0.7152f;
-        matrix[2] = matrix[7] = matrix[12] = 0.0722f;
-        matrix[18] = 1.0f;
-        auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-        return SkColorFilterImageFilter::Create(filter.get(), input);
-    }
-
-    static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
-        auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
-        return SkColorFilterImageFilter::Create(filter.get(), input);
+        return this->isSmall() ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
+                                 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
     }
 
     inline bool isSmall() const { return fIsSmall; }
@@ -65,24 +64,22 @@ private:
 class ColorFilterDimBrightBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterDimBrightBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterDimBrightBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bright_large";
+        return this->isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bright_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
 
         for (int i = 0; i < loops; i++) {
             for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4f) {
-                SkAutoTUnref<SkImageFilter> dim(make_brightness(-brightness));
-                SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, dim));
-                paint.setImageFilter(bright);
+                sk_sp<SkImageFilter> dim(make_brightness(-brightness, nullptr));
+                paint.setImageFilter(make_brightness(brightness, std::move(dim)));
                 canvas->drawRect(r, paint);
             }
         }
@@ -95,22 +92,20 @@ private:
 class ColorFilterBrightGrayBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterBrightGrayBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterBrightGrayBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright_gray_large";
+        return this->isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright_gray_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f));
-            SkAutoTUnref<SkImageFilter> grayscale(make_grayscale(brightness));
-            paint.setImageFilter(grayscale);
+            sk_sp<SkImageFilter> brightness(make_brightness(0.9f, nullptr));
+            paint.setImageFilter(make_grayscale(std::move(brightness)));
             canvas->drawRect(r, paint);
         }
     }
@@ -122,22 +117,20 @@ private:
 class ColorFilterGrayBrightBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterGrayBrightBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterGrayBrightBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_bright_large";
+        return this->isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_bright_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> grayscale(make_grayscale());
-            SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f, grayscale));
-            paint.setImageFilter(brightness);
+            sk_sp<SkImageFilter> grayscale(make_grayscale(nullptr));
+            paint.setImageFilter(make_brightness(0.9f, std::move(grayscale)));
             canvas->drawRect(r, paint);
         }
     }
@@ -149,22 +142,20 @@ private:
 class ColorFilterBlueBrightBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterBlueBrightBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterBlueBrightBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_bright_large";
+        return this->isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_bright_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> blue(make_mode_blue());
-            SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f, blue));
-            paint.setImageFilter(brightness);
+            sk_sp<SkImageFilter> blue(make_mode_blue(nullptr));
+            paint.setImageFilter(make_brightness(1.0f, std::move(blue)));
             canvas->drawRect(r, paint);
         }
     }
@@ -176,22 +167,20 @@ private:
 class ColorFilterBrightBlueBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterBrightBlueBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterBrightBlueBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright_blue_large";
+        return this->isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright_blue_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f));
-            SkAutoTUnref<SkImageFilter> blue(make_mode_blue(brightness));
-            paint.setImageFilter(blue);
+            sk_sp<SkImageFilter> brightness(make_brightness(1.0f, nullptr));
+            paint.setImageFilter(make_mode_blue(std::move(brightness)));
             canvas->drawRect(r, paint);
         }
     }
@@ -203,21 +192,19 @@ private:
 class ColorFilterBrightBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterBrightBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterBrightBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_large";
+        return this->isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f));
-            paint.setImageFilter(brightness);
+            paint.setImageFilter(make_brightness(1.0f, nullptr));
             canvas->drawRect(r, paint);
         }
     }
@@ -229,21 +216,19 @@ private:
 class ColorFilterBlueBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterBlueBench(bool small) : INHERITED(small) {
-    }
+    ColorFilterBlueBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large";
+        return this->isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> blue(make_mode_blue());
-            paint.setImageFilter(blue);
+            paint.setImageFilter(make_mode_blue(nullptr));
             canvas->drawRect(r, paint);
         }
     }
@@ -255,20 +240,19 @@ private:
 class ColorFilterGrayBench : public ColorFilterBaseBench {
 
 public:
-    ColorFilterGrayBench(bool small) : INHERITED(small) {}
+    ColorFilterGrayBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
-        return isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large";
+        return this->isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large";
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        SkRect r = getFilterRect();
+        SkRect r = this->getFilterRect();
         SkPaint paint;
         paint.setColor(SK_ColorRED);
         for (int i = 0; i < loops; i++) {
-            SkAutoTUnref<SkImageFilter> grayscale(make_grayscale());
-            paint.setImageFilter(grayscale);
+            paint.setImageFilter(make_grayscale(nullptr));
             canvas->drawRect(r, paint);
         }
     }
index cafcd38c6e94cbf0054ea26fa5d6cd16f077e913..d85d1de330b74a3a0c806a6a08eeec323a975068 100644 (file)
 
 class BaseImageFilterCollapseBench : public Benchmark {
 public:
-    BaseImageFilterCollapseBench(): fImageFilter(nullptr) {}
-    ~BaseImageFilterCollapseBench() {
-        SkSafeUnref(fImageFilter);
-    }
+    BaseImageFilterCollapseBench() {}
 
 protected:
     void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) {
+        SkASSERT(!fImageFilter);
+
         // Create a chain of ImageFilters from colorFilters
-        fImageFilter = nullptr;
         for(int i = nFilters; i --> 0;) {
-            SkAutoTUnref<SkImageFilter> filter(
-                    SkColorFilterImageFilter::Create(colorFilters[i].get(), fImageFilter, nullptr)
-            );
-            SkRefCnt_SafeAssign(fImageFilter, filter.get());
+            fImageFilter = SkColorFilterImageFilter::Make(colorFilters[i], fImageFilter);
         }
     }
 
@@ -50,7 +45,7 @@ protected:
     }
 
 private:
-    SkImageFilter* fImageFilter;
+    sk_sp<SkImageFilter> fImageFilter;
     SkBitmap fBitmap;
 
     void makeBitmap() {
@@ -95,7 +90,7 @@ protected:
             SkTableColorFilter::Make(table3),
         };
 
-        doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
+        this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
     }
 
 private:
@@ -134,7 +129,7 @@ protected:
             make_brightness(-0.1f),
         };
 
-        doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
+        this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
     }
 };
 
index 5132d71ae048b4ae2ae67c5e4e8caebc7275054f..ebb3c6715c70855859619f4646055234f19c31e1 100644 (file)
@@ -35,7 +35,7 @@ static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
     matrix[2] = matrix[7] = matrix[12] = 0.0722f;
     matrix[18] = 1.0f;
     sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-    return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(filter.get(), input.get()));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
 }
 
 static sk_sp<SkImageFilter> make_blur(float amount, sk_sp<SkImageFilter> input) {
index 38ff0ddb227db1ee0c4832bc41052fcbc4b94925..6031ba76709100b8fbae82331560246fa30eb1c5 100644 (file)
@@ -92,30 +92,27 @@ static sk_sp<SkImageFilter> make_blur(float amount, sk_sp<SkImageFilter> input)
 }
 
 static sk_sp<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> input) {
-    return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf_make_brightness(amount).get(),
-                                                                 input.get()));
+    return SkColorFilterImageFilter::Make(cf_make_brightness(amount), std::move(input));
 }
 
 static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
-    return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf_make_grayscale().get(),
-                                                                 input.get()));
+    return SkColorFilterImageFilter::Make(cf_make_grayscale(), std::move(input));
 }
 
 static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) {
-    return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf_make_colorize(SK_ColorBLUE).get(),
-                                                                 input.get()));
+    return SkColorFilterImageFilter::Make(cf_make_colorize(SK_ColorBLUE), std::move(input));
 }
 
 static void draw_clipped_rect(SkCanvas* canvas,
                               const SkRect& r,
                               const SkPaint& paint,
                               float outset = 0.0f) {
-        canvas->save();
-        SkRect clip(r);
-        clip.outset(outset, outset);
-        canvas->clipRect(clip);
-        canvas->drawRect(r, paint);
-        canvas->restore();
+    canvas->save();
+    SkRect clip(r);
+    clip.outset(outset, outset);
+    canvas->clipRect(clip);
+    canvas->drawRect(r, paint);
+    canvas->restore();
 }
 
 DEF_SIMPLE_GM(colorfilterimagefilter, canvas, 400, 100){
@@ -179,10 +176,9 @@ DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) {
     SkAutoCanvasRestore autoCanvasRestore(canvas, false);
     SkColorMatrix cm;
     cm.setSaturation(0.0f);
-    auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
-    sk_sp<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf.get()));
+    sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
     SkPaint p;
-    p.setImageFilter(std::move(imf));
+    p.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
     canvas->saveLayer(NULL, &p);
     canvas->clear(SK_ColorRED);
 }
index 567ef803b59387b7dcd4547d9a6e9f1c384ce68b..11fa9a86fa7c8828779e2025d86dd677d6bcb1d6 100644 (file)
@@ -93,8 +93,9 @@ protected:
             draw_bitmap, draw_path, draw_paint, draw_text
         };
 
-        auto cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
-        SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
+        sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA,
+                                                              SkXfermode::kSrcIn_Mode));
+        sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
         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)),
@@ -109,7 +110,7 @@ protected:
             SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
                 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
             SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
-                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif, nullptr),
+                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif.get(), nullptr),
             SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
                 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &cropRect),
             SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
index 386e32b098c6a351430917d0fef4942e68394b95..c9c362b050ec947b3bb1293453103370a2feec6b 100644 (file)
@@ -15,9 +15,8 @@ DEF_SIMPLE_GM(fadefilter, canvas, 256, 256) {
                             0, 1, 0, 0, 128.0f,
                             0, 0, 1, 0, 128.0f,
                             0, 0, 0, 1, 0 };
-    auto colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-    SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(colorFilter.get()));
+    sk_sp<SkColorFilter> colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
     SkPaint layerPaint;
-    layerPaint.setImageFilter(filter);
+    layerPaint.setImageFilter(SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr));
     canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint);
 }
index f1f1b80ac9e121757364a99a4a3ab55caa65b533..18e353a099ef0745f2a8521fb885668e28aab086 100644 (file)
@@ -147,7 +147,7 @@ DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
         SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
                                            SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
                                                true),
-        SkColorFilterImageFilter::Create(cf.get()),
+        SkColorFilterImageFilter::Make(std::move(cf), nullptr).release(),
     };
 
     const struct {
index e2e92356e09f49e0777032e82a3c3d115ebc0d4b..ebbd8956a553c4cc7a8e8711767741f4ae7722c8 100644 (file)
@@ -106,9 +106,9 @@ void IdentityImageFilter::toString(SkString* str) const {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-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_ColorGREEN);
     canvas->save();
     canvas->clipRect(r);
@@ -116,7 +116,7 @@ static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
     canvas->restore();
 }
 
-static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_line(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
     SkPaint paint;
     paint.setColor(SK_ColorBLUE);
     paint.setImageFilter(imf);
@@ -124,7 +124,7 @@ static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
     canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
 }
 
-static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_rect(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
     SkPaint paint;
     paint.setColor(SK_ColorYELLOW);
     paint.setImageFilter(imf);
@@ -133,7 +133,7 @@ static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
     canvas->drawRect(rr, paint);
 }
 
-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);
@@ -141,7 +141,7 @@ static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
     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.setColor(SK_ColorCYAN);
@@ -152,9 +152,9 @@ 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;
-    paint.setImageFilter(imf);
+    paint.setImageFilter(std::move(imf));
 
     SkIRect bounds;
     r.roundOut(&bounds);
@@ -189,21 +189,22 @@ protected:
     }
 
     void onDraw(SkCanvas* canvas) override {
-        void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
+        void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
             draw_paint,
             draw_line, draw_rect, draw_path, draw_text,
             draw_bitmap,
         };
 
         auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode);
-        SkImageFilter* filters[] = {
+        sk_sp<SkImageFilter> filters[] = {
             nullptr,
-            IdentityImageFilter::Make(nullptr).release(),
-            FailImageFilter::Make().release(),
-            SkColorFilterImageFilter::Create(cf.get()),
-            SkBlurImageFilter::Make(12.0f, 0.0f, nullptr).release(),
-            SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
-                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
+            IdentityImageFilter::Make(nullptr),
+            FailImageFilter::Make(),
+            SkColorFilterImageFilter::Make(std::move(cf), nullptr),
+            SkBlurImageFilter::Make(12.0f, 0.0f, nullptr),
+            sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
+                                    10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
+                                    SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)),
         };
 
         SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
@@ -223,10 +224,6 @@ protected:
             canvas->restore();
             canvas->translate(DX, 0);
         }
-
-        for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
-            SkSafeUnref(filters[j]);
-        }
     }
 
 private:
index 8f36ba90418072d5b468d43a17cd5abd2b369bf4..907277fc6acd05d1ed3eaf5008a4e28eb8fe5374 100644 (file)
@@ -75,10 +75,9 @@ protected:
                         SkIntToScalar(outset));
             SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
 
-            Draw(canvas, checkerboard, rect,
-                 sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cfAlphaTrans.get(),
-                                                                       noopCropped.get(),
-                                                                       &bigRect)));
+            Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Make(cfAlphaTrans,
+                                                                            noopCropped,
+                                                                            &bigRect));
 
             Draw(canvas, checkerboard, rect, SkBlurImageFilter::Make(0.3f, 0.3f,
                                                                      noopCropped,
index 66e4d870e9eea9263d7d599dde1c4ec1a01af0f2..0c04e52b4899b1bdad7d13910864abc9760303ac 100644 (file)
@@ -106,11 +106,11 @@ protected:
         canvas->drawRect(r, paint);
     }
 
-    virtual void onOnceBeforeDraw() override{
+    void onOnceBeforeDraw() override{
         make_checkerboard();
     }
 
-    virtual void onDraw(SkCanvas* canvas) override {
+    void onDraw(SkCanvas* canvas) override {
         void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
             draw_bitmap, draw_path, draw_paint, draw_text
         };
@@ -126,14 +126,14 @@ protected:
                                                               SkIntToScalar(-10),
                                                               nullptr));
 
-        sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get()));
+        sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Make(cf, std::move(offset)));
 
         sk_sp<SkImageFilter> erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect));
         sk_sp<SkImageFilter> erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect));
 
         sk_sp<SkImageFilter> filters[] = {
             nullptr,
-            sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect)),
+            SkColorFilterImageFilter::Make(cf, 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),
@@ -148,7 +148,7 @@ protected:
                                      SkXfermode::kSrcOver_Mode,
                                      &cropRect),
             SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect),
-            sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect)),
+            SkColorFilterImageFilter::Make(cf, nullptr, &bogusRect),
         };
 
         SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
index eb5519a761480e4f05e959342d7ed1358705f674..319884b0261bf88f831585fd86735ed8caa26cdc 100644 (file)
@@ -137,7 +137,8 @@ protected:
                                                                   SkXfermode::kSrcIn_Mode));
             sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource)));
             sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur));
-            sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get(), erode.get()));
+            sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf),
+                                                                      std::move(erode)));
             sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color));
 
             SkPaint paint;
@@ -154,8 +155,8 @@ protected:
                                     0, 0, 0, 0.5f, 0 };
 
             sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-            sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(),
-                                                                             morph.get()));
+            sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter),
+                                                                           std::move(morph)));
             SkPaint paint;
             paint.setImageFilter(SkXfermodeImageFilter::Make(
                                         SkXfermode::Make(SkXfermode::kSrcOver_Mode),
@@ -170,7 +171,8 @@ protected:
                                     0, 0, SK_Scalar1, 0, 0,
                                     0, 0, 0, 0.5f, 0 };
             sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-            sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get()));
+            sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF),
+                                                                             nullptr));
             sk_sp<SkImageFilter> offsetFilter(SimpleOffsetFilter::Make(10.0f, 10.f, matrixFilter));
 
             SkPaint paint;
@@ -228,18 +230,20 @@ protected:
         }
         {
             // Test that crop offsets are absolute, not relative to the parent's crop rect.
-            auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
-            auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
+            sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+                                                                   SkXfermode::kSrcIn_Mode));
+            sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
+                                                                   SkXfermode::kSrcIn_Mode));
             SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
                                                                SkIntToScalar(80), SkIntToScalar(80)));
             SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
                                                                SkIntToScalar(60), SkIntToScalar(60)));
-            sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(),
-                                                                         nullptr,
-                                                                         &outerRect));
-            sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(),
-                                                                         color1.get(),
-                                                                         &innerRect));
+            sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1),
+                                                                       nullptr,
+                                                                       &outerRect));
+            sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2),
+                                                                       std::move(color1),
+                                                                       &innerRect));
 
             SkPaint paint;
             paint.setImageFilter(std::move(color2));
index d920a1785b7399786faacda99d27265464631cba..25a88f73e54defdb3b57ff46ae03f5b414652ded 100644 (file)
@@ -39,10 +39,11 @@ static void install_detector_color_filter(SkPaint* drawPaint) {
 
 // This detector detects that image filter phase of the pixel pipeline receives the correct value.
 static void install_detector_image_filter(SkPaint* drawPaint) {
-    auto colorFilter(make_detector_color_filter());
-    SkImageFilter* imageFilter =
-            SkColorFilterImageFilter::Create(colorFilter.get(), drawPaint->getImageFilter());
-    drawPaint->setImageFilter(imageFilter)->unref();
+    sk_sp<SkColorFilter> colorFilter(make_detector_color_filter());
+    sk_sp<SkImageFilter> imageFilter(
+        SkColorFilterImageFilter::Make(std::move(colorFilter),
+                                       sk_ref_sp(drawPaint->getImageFilter())));
+    drawPaint->setImageFilter(std::move(imageFilter));
 }
 
 static void no_detector_install(SkPaint*) {
index a644bd105377a7f88409a65ef8f88f5641ecf8d8..26a3c2c4f19f2ac8e34aae69f8e2c7343d8f3521 100644 (file)
@@ -163,19 +163,19 @@ protected:
             paint.setColorFilter(nullptr);
 
             for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
-                auto colorFilter1(gColorFilterMakers[i]());
-                SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Create(
-                            colorFilter1.get(), nullptr, nullptr));
+                sk_sp<SkColorFilter> colorFilter1(gColorFilterMakers[i]());
+                sk_sp<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Make(
+                            std::move(colorFilter1), nullptr));
 
                 // Move down to the next line and draw it
                 // each draw being at xOffset of the previous one
                 y += yOffset;
                 x = 0;
                 for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j) {
-                    auto colorFilter2(gColorFilterMakers[j]());
-                    SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Create(
-                                colorFilter2.get(), imageFilter1, nullptr));
-                    paint.setImageFilter(imageFilter2);
+                    sk_sp<SkColorFilter> colorFilter2(gColorFilterMakers[j]());
+                    sk_sp<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Make(
+                                std::move(colorFilter2), imageFilter1, nullptr));
+                    paint.setImageFilter(std::move(imageFilter2));
                     canvas->drawBitmap(bm, x, y, &paint);
                     x += xOffset;
                 }
index ab277716d7869e6dab1d9268b20e233ba0cb6215..0174fc1d5ca60231b0bdba6cfbdb68334e2db600 100644 (file)
@@ -31,7 +31,7 @@ static sk_sp<SkImageFilter> make1() {
 
 static sk_sp<SkImageFilter> make2() {
     sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
-    return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get()));
+    return SkColorFilterImageFilter::Make(std::move(cf), nullptr);
 }
 
 static sk_sp<SkImageFilter> make3() {
@@ -62,7 +62,7 @@ static sk_sp<SkImageFilter> make6() {
     sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
 
     sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
-    sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
+    sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
 
     return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
 }
@@ -75,7 +75,7 @@ static sk_sp<SkImageFilter> make7() {
     sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
 
     sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
-    sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
+    sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
 
     return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
 }
index c0cca3c8950958d7ad7e3aa980cdee2e886524ed..fa5bb68bd50a6268ab8b2344ed35490eb91bebea 100644 (file)
@@ -91,12 +91,11 @@ protected:
                                         SkIntToScalar(fBitmap->height()));
         SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
                                         SkIntToScalar(fBitmap->height() * 2));
-        SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
-        auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+        sk_sp<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
+        sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
 
-        SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get(), tile.get()));
         SkPaint paint;
-        paint.setImageFilter(cfif);
+        paint.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), std::move(tile)));
         canvas->save();
         canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
         canvas->clipRect(dstRect);
@@ -114,11 +113,12 @@ protected:
         SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(5, 5, 40, 40));
         sk_sp<SkColorFilter> greenCF = SkColorFilter::MakeModeFilter(SK_ColorGREEN,
                                                                      SkXfermode::kSrc_Mode);
-        SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get(), nullptr,
-                                                                           &cropRect));
-        tile.reset(SkTileImageFilter::Create(srcRect, dstRect, green));
+        sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(std::move(greenCF),
+                                                                  nullptr,
+                                                                  &cropRect));
+        tile.reset(SkTileImageFilter::Create(srcRect, dstRect, green.get()));
         paint.setColor(SK_ColorRED);
-        paint.setImageFilter(tile);
+        paint.setImageFilter(std::move(tile));
         canvas->drawRect(dstRect, paint);
     }
 private:
index ebe263930d94d1f929edfa6a73cdc86143f4ce73..5ed051c0deece02e57a782a38c5a4807fc8a2c94 100644 (file)
@@ -14,12 +14,23 @@ class SkColorFilter;
 
 class SK_API SkColorFilterImageFilter : public SkImageFilter {
 public:
-    static SkImageFilter* Create(SkColorFilter* cf, SkImageFilter* input = NULL,
-                                 const CropRect* cropRect = NULL);
+    static sk_sp<SkImageFilter> Make(sk_sp<SkColorFilter> cf,
+                                     sk_sp<SkImageFilter> input,
+                                     const CropRect* cropRect = NULL);
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorFilterImageFilter)
 
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+    static SkImageFilter* Create(SkColorFilter* cf,
+                                 SkImageFilter* input = NULL,
+                                 const CropRect* cropRect = NULL) {
+        return Make(sk_ref_sp<SkColorFilter>(cf),
+                    sk_ref_sp<SkImageFilter>(input),
+                    cropRect).release();
+    }
+#endif
+
 protected:
     void flatten(SkWriteBuffer&) const override;
     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
@@ -28,8 +39,8 @@ protected:
     bool affectsTransparentBlack() const override;
 
 private:
-    SkColorFilterImageFilter(SkColorFilter* cf,
-                             SkImageFilter* input,
+    SkColorFilterImageFilter(sk_sp<SkColorFilter> cf,
+                             sk_sp<SkImageFilter> input,
                              const CropRect* cropRect);
 
     sk_sp<SkColorFilter> fColorFilter;
index 5d433b5748b22c339b6a5a2d61b3da3d61d1c0f3..2be6c318891c4239673e8621a01749770660fad0 100644 (file)
@@ -564,19 +564,15 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
         break;
     case COLOR: {
         sk_sp<SkColorFilter> cf(make_color_filter());
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-        filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(),
-                                                                            subFilter.get()))
+        filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter())
                     : nullptr;
         break;
     }
     case LUT3D: {
         int cubeDimension;
         sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
-        sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension));
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-        filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), 
-                                                                            subFilter.get()))
+        sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(std::move(lut3D), cubeDimension));
+        filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter())
                     : nullptr;
         break;
     }
index 1fdc668f9b42ae6a446452c6a7a5b23ec5baf53f..8d412cc2f5579967e9d304c443183f5b5855ae7b 100644 (file)
@@ -14,8 +14,9 @@
 #include "SkSpecialSurface.h"
 #include "SkWriteBuffer.h"
 
-SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter* input,
-                                                const CropRect* cropRect) {
+sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf,
+                                                    sk_sp<SkImageFilter> input,
+                                                    const CropRect* cropRect) {
     if (!cf) {
         return nullptr;
     }
@@ -24,27 +25,31 @@ SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter
     if (input && input->isColorFilterNode(&inputCF)) {
         // This is an optimization, as it collapses the hierarchy by just combining the two
         // colorfilters into a single one, which the new imagefilter will wrap.
-        sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf),
+        sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(cf,// can't move bc of fallthru
                                                                     sk_sp<SkColorFilter>(inputCF)));
         if (newCF) {
-            return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect);
+            return sk_sp<SkImageFilter>(new SkColorFilterImageFilter(std::move(newCF),
+                                                                     sk_ref_sp(input->getInput(0)),
+                                                                     cropRect));
         }
     }
 
-    return new SkColorFilterImageFilter(cf, input, cropRect);
+    return sk_sp<SkImageFilter>(new SkColorFilterImageFilter(std::move(cf),
+                                                             std::move(input),
+                                                             cropRect));
 }
 
-SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
-                                                   SkImageFilter* input,
+SkColorFilterImageFilter::SkColorFilterImageFilter(sk_sp<SkColorFilter> cf,
+                                                   sk_sp<SkImageFilter> input,
                                                    const CropRect* cropRect)
-    : INHERITED(1, &input, cropRect)
-    , fColorFilter(SkRef(cf)) {
+    : INHERITED(&input, 1, cropRect)
+    , fColorFilter(std::move(cf)) {
 }
 
 sk_sp<SkFlattenable> SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) {
     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
     sk_sp<SkColorFilter> cf(buffer.readColorFilter());
-    return sk_sp<SkFlattenable>(Create(cf.get(), common.getInput(0).get(), &common.cropRect()));
+    return Make(std::move(cf), common.getInput(0), &common.cropRect());
 }
 
 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
index 49455c9481629453cc344a6b324573127697adcc..42613a35c50257500c01a42dd7a039a09b355005 100644 (file)
@@ -164,7 +164,7 @@ public:
                                                                   SkXfermode::kSrcIn_Mode));
 
             this->addFilter("color filter",
-                SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect));
+                SkColorFilterImageFilter::Make(cf, input, cropRect).release());
         }
 
         {
@@ -333,30 +333,33 @@ static sk_sp<SkImage> make_small_image() {
     return surface->makeImageSnapshot();
 }
 
-static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
+static sk_sp<SkImageFilter> make_scale(float amount, sk_sp<SkImageFilter> input) {
     SkScalar s = amount;
     SkScalar matrix[20] = { s, 0, 0, 0, 0,
                             0, s, 0, 0, 0,
                             0, 0, s, 0, 0,
                             0, 0, 0, s, 0 };
-    auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-    return SkColorFilterImageFilter::Create(filter.get(), input);
+    sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
 }
 
-static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
+static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input,
+                                           const SkImageFilter::CropRect* cropRect) {
     SkScalar matrix[20];
     memset(matrix, 0, 20 * sizeof(SkScalar));
     matrix[0] = matrix[5] = matrix[10] = 0.2126f;
     matrix[1] = matrix[6] = matrix[11] = 0.7152f;
     matrix[2] = matrix[7] = matrix[12] = 0.0722f;
     matrix[18] = 1.0f;
-    auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
-    return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
+    sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
 }
 
-static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
-    auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
-    return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
+static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input,
+                                      const SkImageFilter::CropRect* cropRect) {
+    sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+                                                              SkXfermode::kSrcIn_Mode));
+    return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
 }
 
 static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
@@ -395,8 +398,8 @@ static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context,
 DEF_TEST(ImageFilter, reporter) {
     {
         // Check that two non-clipping color-matrice-filters concatenate into a single filter.
-        SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f));
-        SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrightness));
+        sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, nullptr));
+        sk_sp<SkImageFilter> quarterBrightness(make_scale(0.5f, std::move(halfBrightness)));
         REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0));
         SkColorFilter* cf;
         REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf));
@@ -407,8 +410,8 @@ DEF_TEST(ImageFilter, reporter) {
     {
         // Check that a clipping color-matrice-filter followed by a color-matrice-filters
         // concatenates into a single filter, but not a matrixfilter (due to clamping).
-        SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f));
-        SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBrightness));
+        sk_sp<SkImageFilter> doubleBrightness(make_scale(2.0f, nullptr));
+        sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, std::move(doubleBrightness)));
         REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0));
         SkColorFilter* cf;
         REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf));
@@ -419,25 +422,25 @@ DEF_TEST(ImageFilter, reporter) {
     {
         // Check that a color filter image filter without a crop rect can be
         // expressed as a color filter.
-        SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
+        sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
         REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
     }
 
     {
         // Check that a colorfilterimage filter without a crop rect but with an input
         // that is another colorfilterimage can be expressed as a colorfilter (composed).
-        SkAutoTUnref<SkImageFilter> mode(make_blue(nullptr, nullptr));
-        SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, nullptr));
+        sk_sp<SkImageFilter> mode(make_blue(nullptr, nullptr));
+        sk_sp<SkImageFilter> gray(make_grayscale(std::move(mode), nullptr));
         REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
     }
 
     {
         // Test that if we exceed the limit of what ComposeColorFilter can combine, we still
         // can build the DAG and won't assert if we call asColorFilter.
-        SkAutoTUnref<SkImageFilter> filter(make_blue(nullptr, nullptr));
+        sk_sp<SkImageFilter> filter(make_blue(nullptr, nullptr));
         const int kWayTooManyForComposeColorFilter = 100;
         for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) {
-            filter.reset(make_blue(filter, nullptr));
+            filter = make_blue(filter, nullptr);
             // the first few of these will succeed, but after we hit the internal limit,
             // it will then return false.
             (void)filter->asColorFilter(nullptr);
@@ -448,7 +451,7 @@ DEF_TEST(ImageFilter, reporter) {
         // Check that a color filter image filter with a crop rect cannot
         // be expressed as a color filter.
         SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
-        SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
+        sk_sp<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
         REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr));
     }
 
@@ -459,17 +462,19 @@ DEF_TEST(ImageFilter, reporter) {
         blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
         SkScalar redToGreenMatrix[20] = { 0 };
         redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
-        auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
-        SkAutoTUnref<SkImageFilter> filter1(SkColorFilterImageFilter::Create(blueToRed.get()));
-        auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
-        SkAutoTUnref<SkImageFilter> filter2(SkColorFilterImageFilter::Create(redToGreen.get(), filter1.get()));
+        sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
+        sk_sp<SkImageFilter> filter1(SkColorFilterImageFilter::Make(std::move(blueToRed),
+                                                                    nullptr));
+        sk_sp<SkColorFilter> redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
+        sk_sp<SkImageFilter> filter2(SkColorFilterImageFilter::Make(std::move(redToGreen),
+                                                                    std::move(filter1)));
 
         SkBitmap result;
         result.allocN32Pixels(kBitmapSize, kBitmapSize);
 
         SkPaint paint;
         paint.setColor(SK_ColorBLUE);
-        paint.setImageFilter(filter2.get());
+        paint.setImageFilter(std::move(filter2));
         SkCanvas canvas(result);
         canvas.clear(0x0);
         SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize));
@@ -714,8 +719,8 @@ static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy,
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr);
     sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
     SkASSERT(green->affectsTransparentBlack());
-    sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get(),
-                                                                      failFilter.get()));
+    sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(green),
+                                                                    std::move(failFilter)));
     SkIPoint offset;
     sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &offset));
     REPORTER_ASSERT(reporter, nullptr != result.get());
@@ -795,12 +800,14 @@ static void draw_saveLayer_picture(int width, int height, int tileSize,
     SkMatrix matrix;
     matrix.setTranslate(SkIntToScalar(50), 0);
 
-    auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
-    SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
-    SkAutoTUnref<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality, cfif.get()));
+    sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
+    sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
+    sk_sp<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix, 
+                                                                       kNone_SkFilterQuality,
+                                                                       cfif.get()));
 
     SkPaint paint;
-    paint.setImageFilter(imageFilter.get());
+    paint.setImageFilter(std::move(imageFilter));
     SkPictureRecorder recorder;
     SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
     SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
@@ -1220,11 +1227,11 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
     SkRTreeFactory factory;
     SkPictureRecorder recorder;
 
-    auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
-    SkAutoTUnref<SkImageFilter> imageFilter(
-        SkColorFilterImageFilter::Create(green.get()));
+    sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
+                                                             SkXfermode::kSrc_Mode));
+    sk_sp<SkImageFilter> imageFilter(SkColorFilterImageFilter::Make(green, nullptr));
     SkPaint imageFilterPaint;
-    imageFilterPaint.setImageFilter(imageFilter.get());
+    imageFilterPaint.setImageFilter(std::move(imageFilter));
     SkPaint colorFilterPaint;
     colorFilterPaint.setColorFilter(green);
 
@@ -1342,18 +1349,22 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
     bitmap.allocN32Pixels(1, 1);
     bitmap.eraseARGB(255, 255, 255, 255);
 
-    auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
-    SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get()));
+    sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
+                                                             SkXfermode::kSrcIn_Mode));
+    sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(green, nullptr));
     SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
-    SkAutoTUnref<SkImageFilter> croppedOut(
-        SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect));
+    sk_sp<SkImageFilter> croppedOut(SkColorFilterImageFilter::Make(green, nullptr, &cropRect));
 
     // Check that an xfermode image filter whose input has been cropped out still draws the other
     // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
     auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
-    auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr));
-    auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr));
-    auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedOut, nullptr));
+    auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode,
+                                                  greenFilter.get(), croppedOut.get(), nullptr));
+    auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode,
+                                                  croppedOut.get(), greenFilter.get(), nullptr));
+    auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode,
+                                                      croppedOut.get(),
+                                                      croppedOut.get(), nullptr));
 
     SkPaint paint;
     paint.setImageFilter(xfermodeNoFg);
@@ -1512,7 +1523,7 @@ static void test_partial_crop_rect(SkImageFilter::Proxy* proxy,
 
     SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
         SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge);
-    SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
+    sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
     SkIPoint offset;
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
 
@@ -1564,7 +1575,7 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
                                      0, 0, 0, 0, 0,
                                      0, 0, 0, 0, 1 };
         sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix));
-        sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get()));
+        sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(greenCF, nullptr));
 
         REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
         REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
@@ -1580,13 +1591,15 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
         allOne[i] = 255;
     }
 
-    auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, allOne));
-    SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create(identityCF.get()));
+    sk_sp<SkColorFilter> identityCF(SkTableColorFilter::MakeARGB(identity, identity,
+                                                                 identity, allOne));
+    sk_sp<SkImageFilter> identityFilter(SkColorFilterImageFilter::Make(identityCF, nullptr));
     REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
     REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds());
 
-    auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity));
-    SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(forceOpaqueCF.get()));
+    sk_sp<SkColorFilter> forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity,
+                                                                    identity, identity));
+    sk_sp<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Make(forceOpaqueCF, nullptr));
     REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
     REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
 }
index a57a1b2fb28b04e317e391ef219f3514ea2f5732..f6ed59e81a9af0e82a2491a7c4e8cfc8918e2954 100644 (file)
@@ -278,11 +278,11 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
     // optimize away
     SkScalar blueToRedMatrix[20] = { 0 };
     blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
-    auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
-    SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blueToRed.get()));
+    sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
+    sk_sp<SkImageFilter> filter(SkColorFilterImageFilter::Make(std::move(blueToRed), nullptr));
 
     SkPaint complexPaint;
-    complexPaint.setImageFilter(filter);
+    complexPaint.setImageFilter(std::move(filter));
 
     sk_sp<SkPicture> pict, child;
     SkRTreeFactory bbhFactory;