Update SkMatrixImageFilter to sk_sp

TBR=reed@google.com

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

Review URL: https://codereview.chromium.org/1858353002
diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp
index c1513a8..87653a1 100644
--- a/fuzz/FilterFuzz.cpp
+++ b/fuzz/FilterFuzz.cpp
@@ -594,13 +594,11 @@
     case OFFSET:
         filter = SkOffsetImageFilter::Make(make_scalar(), make_scalar(), make_image_filter());
         break;
-    case MATRIX: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-        filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_matrix(),
-                                                                        (SkFilterQuality)R(4),
-                                                                        subFilter.get()));
+    case MATRIX:
+        filter = SkImageFilter::MakeMatrixFilter(make_matrix(),
+                                                 (SkFilterQuality)R(4),
+                                                 make_image_filter());
         break;
-    }
     case MATRIX_CONVOLUTION: {
         SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
                                                      SkIntToScalar(kBitmapSize)));
diff --git a/gm/filterfastbounds.cpp b/gm/filterfastbounds.cpp
index a254ec9..6ae4e74 100644
--- a/gm/filterfastbounds.cpp
+++ b/gm/filterfastbounds.cpp
@@ -95,7 +95,7 @@
         scale.setScale(2.0f, 2.0f);
 
         sk_sp<SkImageFilter> scaleMIF(
-            SkImageFilter::CreateMatrixFilter(scale, kLow_SkFilterQuality, source.get()));
+            SkImageFilter::MakeMatrixFilter(scale, kLow_SkFilterQuality, source));
 
         add_paint(paints, std::move(scaleMIF));
     }
@@ -105,7 +105,7 @@
         rot.setRotate(-33.3f);
 
         sk_sp<SkImageFilter> rotMIF(
-            SkImageFilter::CreateMatrixFilter(rot, kLow_SkFilterQuality, source.get()));
+            SkImageFilter::MakeMatrixFilter(rot, kLow_SkFilterQuality, source));
 
         add_paint(paints, std::move(rotMIF));
     }
diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp
index 18e353a..4343f8b 100644
--- a/gm/imagefilters.cpp
+++ b/gm/imagefilters.cpp
@@ -19,7 +19,7 @@
  *
  *  see https://bug.skia.org/3741
  */
-static void do_draw(SkCanvas* canvas, SkXfermode::Mode mode, SkImageFilter* imf) {
+static void do_draw(SkCanvas* canvas, SkXfermode::Mode mode, sk_sp<SkImageFilter> imf) {
         SkAutoCanvasRestore acr(canvas, true);
         canvas->clipRect(SkRect::MakeWH(220, 220));
 
@@ -39,7 +39,7 @@
         canvas->drawOval(r0, paint);
 
         paint.setColor(0x660000FF);
-        paint.setImageFilter(imf);
+        paint.setImageFilter(std::move(imf));
         paint.setXfermodeMode(mode);
         canvas->drawOval(r1, paint);
 }
@@ -48,8 +48,9 @@
         canvas->translate(10, 10);
 
         // just need an imagefilter to trigger the code-path (which creates a tmp layer)
-        SkAutoTUnref<SkImageFilter> imf(SkImageFilter::CreateMatrixFilter(SkMatrix::I(),
-                                                                          kNone_SkFilterQuality));
+        sk_sp<SkImageFilter> imf(SkImageFilter::MakeMatrixFilter(SkMatrix::I(),
+                                                                 kNone_SkFilterQuality,
+                                                                 nullptr));
 
         const SkXfermode::Mode modes[] = {
             SkXfermode::kSrcATop_Mode, SkXfermode::kDstIn_Mode
diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp
index b123094..7296fd5 100644
--- a/gm/imagefiltersclipped.cpp
+++ b/gm/imagefiltersclipped.cpp
@@ -106,7 +106,7 @@
             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),
+            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr).release(),
             SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1,
                                                          SkIntToScalar(2), checkerboard.get()),
 
diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp
index 3f819d8..a63e99a 100644
--- a/gm/imagefiltersscaled.cpp
+++ b/gm/imagefiltersscaled.cpp
@@ -85,7 +85,7 @@
             SkDilateImageFilter::Make(1, 1, checkerboard).release(),
             SkErodeImageFilter::Make(1, 1, checkerboard).release(),
             SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr).release(),
-            SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
+            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr).release(),
             SkPaintImageFilter::Make(noisePaint).release(),
             SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
             SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
diff --git a/gm/imagefiltersstroked.cpp b/gm/imagefiltersstroked.cpp
index 81f8145..cca8737 100644
--- a/gm/imagefiltersstroked.cpp
+++ b/gm/imagefiltersstroked.cpp
@@ -57,12 +57,12 @@
         SkMatrix resizeMatrix;
         resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
 
-        SkImageFilter* filters[] = {
-            SkBlurImageFilter::Make(5, 5, nullptr).release(),
-            SkDropShadowImageFilter::Create(10, 10, 3, 3, SK_ColorGREEN,
-                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
-            SkOffsetImageFilter::Make(-16, 32, nullptr).release(),
-            SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
+        sk_sp<SkImageFilter> filters[] = {
+            SkBlurImageFilter::Make(5, 5, nullptr),
+            sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(10, 10, 3, 3, SK_ColorGREEN,
+                            SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)),
+            SkOffsetImageFilter::Make(-16, 32, nullptr),
+            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr),
         };
 
         SkRect r = SkRect::MakeWH(64, 64);
@@ -95,10 +95,6 @@
             canvas->restore();
             canvas->translate(0, r.height());
         }
-
-        for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
-            SkSafeUnref(filters[i]);
-        }
     }
 
 private:
diff --git a/gm/imageresizetiled.cpp b/gm/imageresizetiled.cpp
index d925298..3c70a2c 100644
--- a/gm/imageresizetiled.cpp
+++ b/gm/imageresizetiled.cpp
@@ -18,9 +18,9 @@
         SkPaint paint;
         SkMatrix matrix;
         matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
-        SkAutoTUnref<SkImageFilter> imageFilter(
-            SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality));
-        paint.setImageFilter(imageFilter.get());
+        paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix,
+                                                             kNone_SkFilterQuality,
+                                                             nullptr));
         const SkScalar tile_size = SkIntToScalar(100);
         SkRect bounds;
         canvas->getClipBounds(&bounds);
diff --git a/gm/matriximagefilter.cpp b/gm/matriximagefilter.cpp
index 3b4c0f6..ef16ea4 100644
--- a/gm/matriximagefilter.cpp
+++ b/gm/matriximagefilter.cpp
@@ -11,10 +11,8 @@
 
 static void draw(SkCanvas* canvas, const SkRect& rect, const SkBitmap& bitmap,
                  const SkMatrix& matrix, SkFilterQuality filter) {
-        SkAutoTUnref<SkImageFilter> imageFilter(
-            SkImageFilter::CreateMatrixFilter(matrix, filter));
         SkPaint paint;
-        paint.setImageFilter(imageFilter.get());
+        paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix, filter, nullptr));
         canvas->saveLayer(&rect, &paint);
         canvas->drawBitmap(bitmap, 0, 0);
         canvas->restore();
diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp
index 28508fd..fe75616 100644
--- a/gm/resizeimagefilter.cpp
+++ b/gm/resizeimagefilter.cpp
@@ -39,9 +39,9 @@
         canvas->translate(-rect.x(), -rect.y());
         SkMatrix matrix;
         matrix.setScale(SkScalarInvert(deviceScaleX), SkScalarInvert(deviceScaleY));
-        sk_sp<SkImageFilter> filter(SkImageFilter::CreateMatrixFilter(matrix,
-                                                                      filterQuality,
-                                                                      input.get()));
+        sk_sp<SkImageFilter> filter(SkImageFilter::MakeMatrixFilter(matrix,
+                                                                    filterQuality,
+                                                                    std::move(input)));
         SkPaint filteredPaint;
         filteredPaint.setImageFilter(std::move(filter));
         canvas->saveLayer(&rect, &filteredPaint);
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 4493d28..8a8e512 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -270,9 +270,17 @@
     /**
      * Create an SkMatrixImageFilter, which transforms its input by the given matrix.
      */
+    static sk_sp<SkImageFilter> MakeMatrixFilter(const SkMatrix& matrix,
+                                                 SkFilterQuality,
+                                                 sk_sp<SkImageFilter> input);
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
     static SkImageFilter* CreateMatrixFilter(const SkMatrix& matrix,
-                                             SkFilterQuality,
-                                             SkImageFilter* input = NULL);
+                                             SkFilterQuality filterQuality,
+                                             SkImageFilter* input = nullptr) {
+        return MakeMatrixFilter(matrix, filterQuality, sk_ref_sp<SkImageFilter>(input)).release();
+    }
+#endif
+
 
     sk_sp<SkSpecialImage> filterInput(int index,
                                       SkSpecialImage* src,
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 31cd661..67c17fb 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -597,13 +597,11 @@
     case OFFSET:
         filter = SkOffsetImageFilter::Make(make_scalar(), make_scalar(), make_image_filter());
         break;
-    case MATRIX: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-        filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_matrix(),
-                                                                        (SkFilterQuality)R(4),
-                                                                        subFilter.get()));
+    case MATRIX:
+        filter = SkImageFilter::MakeMatrixFilter(make_matrix(),
+                                                 (SkFilterQuality)R(4),
+                                                 make_image_filter());
         break;
-    }
     case MATRIX_CONVOLUTION: {
         SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
                                                      SkIntToScalar(kBitmapSize)));
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 11a2f74..0e0df36 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -573,10 +573,10 @@
     return false;
 }
 
-SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix,
-                                                 SkFilterQuality filterQuality,
-                                                 SkImageFilter* input) {
-    return SkMatrixImageFilter::Create(matrix, filterQuality, input);
+sk_sp<SkImageFilter> SkImageFilter::MakeMatrixFilter(const SkMatrix& matrix,
+                                                     SkFilterQuality filterQuality,
+                                                     sk_sp<SkImageFilter> input) {
+    return SkMatrixImageFilter::Make(matrix, filterQuality, std::move(input));
 }
 
 sk_sp<SkImageFilter> SkImageFilter::makeWithLocalMatrix(const SkMatrix& matrix) const {
diff --git a/src/core/SkMatrixImageFilter.cpp b/src/core/SkMatrixImageFilter.cpp
index 70bc81a..6cd79f3 100644
--- a/src/core/SkMatrixImageFilter.cpp
+++ b/src/core/SkMatrixImageFilter.cpp
@@ -16,16 +16,18 @@
 
 SkMatrixImageFilter::SkMatrixImageFilter(const SkMatrix& transform,
                                          SkFilterQuality filterQuality,
-                                         SkImageFilter* input)
-    : INHERITED(1, &input)
+                                         sk_sp<SkImageFilter> input)
+    : INHERITED(&input, 1, nullptr)
     , fTransform(transform)
     , fFilterQuality(filterQuality) {
 }
 
-SkMatrixImageFilter* SkMatrixImageFilter::Create(const SkMatrix& transform,
-                                                 SkFilterQuality filterQuality,
-                                                 SkImageFilter* input) {
-    return new SkMatrixImageFilter(transform, filterQuality, input);
+sk_sp<SkImageFilter> SkMatrixImageFilter::Make(const SkMatrix& transform,
+                                               SkFilterQuality filterQuality,
+                                               sk_sp<SkImageFilter> input) {
+    return sk_sp<SkImageFilter>(new SkMatrixImageFilter(transform,
+                                                        filterQuality,
+                                                        std::move(input)));
 }
 
 sk_sp<SkFlattenable> SkMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
@@ -33,7 +35,7 @@
     SkMatrix matrix;
     buffer.readMatrix(&matrix);
     SkFilterQuality quality = static_cast<SkFilterQuality>(buffer.readInt());
-    return sk_sp<SkImageFilter>(Create(matrix, quality, common.getInput(0).get()));
+    return Make(matrix, quality, common.getInput(0));
 }
 
 void SkMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/core/SkMatrixImageFilter.h b/src/core/SkMatrixImageFilter.h
index d774566..e02541c 100644
--- a/src/core/SkMatrixImageFilter.h
+++ b/src/core/SkMatrixImageFilter.h
@@ -25,19 +25,27 @@
      *                       passed to filterImage() is used instead.
      */
 
-    static SkMatrixImageFilter* Create(const SkMatrix& transform,
-                                       SkFilterQuality filterQuality,
-                                       SkImageFilter* input = nullptr);
+    static sk_sp<SkImageFilter> Make(const SkMatrix& transform,
+                                     SkFilterQuality filterQuality,
+                                     sk_sp<SkImageFilter> input);
 
     SkRect computeFastBounds(const SkRect&) const override;
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixImageFilter)
 
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+    static SkImageFilter* Create(const SkMatrix& transform,
+                                 SkFilterQuality filterQuality,
+                                 SkImageFilter* input = nullptr) {
+        return Make(transform, filterQuality, sk_ref_sp<SkImageFilter>(input)).release();
+    }
+#endif
+
 protected:
     SkMatrixImageFilter(const SkMatrix& transform,
                         SkFilterQuality,
-                        SkImageFilter* input);
+                        sk_sp<SkImageFilter> input);
     void flatten(SkWriteBuffer&) const override;
 
     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index ea27d7b..b0b7349 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -225,8 +225,8 @@
             cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100),
             input.get()));
         if (!cropRect) {
-            this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
-                matrix, kLow_SkFilterQuality, input.get()));
+            this->addFilter("matrix",
+                SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, input).release());
         }
 
         {
@@ -801,9 +801,9 @@
 
     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()));
+    sk_sp<SkImageFilter> imageFilter(SkImageFilter::MakeMatrixFilter(matrix,
+                                                                     kNone_SkFilterQuality,
+                                                                     std::move(cfif)));
 
     SkPaint paint;
     paint.setImageFilter(std::move(imageFilter));
@@ -1397,15 +1397,15 @@
     SkMatrix matrix;
     matrix.setScale(SkIntToScalar(2), SkIntToScalar(2));
     matrix.postTranslate(SkIntToScalar(-20), SkIntToScalar(-20));
-    SkAutoTUnref<SkImageFilter> matrixFilter(
-        SkImageFilter::CreateMatrixFilter(matrix, kLow_SkFilterQuality));
+    sk_sp<SkImageFilter> matrixFilter(
+        SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, nullptr));
 
     // Test that saveLayer() with a filter nested inside another saveLayer() applies the
     // correct offset to the filter matrix.
     SkRect bounds1 = SkRect::MakeXYWH(10, 10, 30, 30);
     canvas.saveLayer(&bounds1, nullptr);
     SkPaint filterPaint;
-    filterPaint.setImageFilter(matrixFilter);
+    filterPaint.setImageFilter(std::move(matrixFilter));
     SkRect bounds2 = SkRect::MakeXYWH(20, 20, 10, 10);
     canvas.saveLayer(&bounds2, &filterPaint);
     SkPaint greenPaint;