Update LightingImageFilter to sk_sp
authorrobertphillips <robertphillips@google.com>
Fri, 8 Apr 2016 23:28:09 +0000 (16:28 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 8 Apr 2016 23:28:09 +0000 (16:28 -0700)
TBR=reed@google.com

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

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

bench/LightingBench.cpp
fuzz/FilterFuzz.cpp
gm/imagefiltersclipped.cpp
gm/imagefilterscropexpand.cpp
gm/imagefiltersscaled.cpp
gm/lighting.cpp
include/effects/SkLightingImageFilter.h
samplecode/SampleFilterFuzz.cpp
src/effects/SkLightingImageFilter.cpp
tests/ImageFilterTest.cpp

index 2c78749d9f01f2155c3d07c26d4686b2a3d8b610..72f37bf4d0e84bfe9b2d14dad03db7a18a45ce4c 100644 (file)
@@ -20,11 +20,11 @@ public:
     LightingBaseBench(bool small) : fIsSmall(small) { }
 
 protected:
-    void draw(int loops, SkCanvas* canvas, SkImageFilter* imageFilter) const {
+    void draw(int loops, SkCanvas* canvas, sk_sp<SkImageFilter> imageFilter) const {
         SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
                               SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
         SkPaint paint;
-        paint.setImageFilter(imageFilter)->unref();
+        paint.setImageFilter(std::move(imageFilter));
         for (int i = 0; i < loops; i++) {
             canvas->drawRect(r, paint);
         }
@@ -99,8 +99,7 @@ protected:
 
 class LightingPointLitDiffuseBench : public LightingBaseBench {
 public:
-    LightingPointLitDiffuseBench(bool small) : INHERITED(small) {
-    }
+    LightingPointLitDiffuseBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
@@ -108,10 +107,11 @@ protected:
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        draw(loops, canvas, SkLightingImageFilter::CreatePointLitDiffuse(GetPointLocation(),
-                                                                         GetWhite(),
-                                                                         GetSurfaceScale(),
-                                                                         GetKd()));
+        draw(loops, canvas, SkLightingImageFilter::MakePointLitDiffuse(GetPointLocation(),
+                                                                       GetWhite(),
+                                                                       GetSurfaceScale(),
+                                                                       GetKd(),
+                                                                       nullptr));
     }
 
 private:
@@ -120,8 +120,7 @@ private:
 
 class LightingDistantLitDiffuseBench : public LightingBaseBench {
 public:
-    LightingDistantLitDiffuseBench(bool small) : INHERITED(small) {
-    }
+    LightingDistantLitDiffuseBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
@@ -129,10 +128,11 @@ protected:
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        draw(loops, canvas, SkLightingImageFilter::CreateDistantLitDiffuse(GetDistantDirection(),
-                                                                           GetWhite(),
-                                                                           GetSurfaceScale(),
-                                                                           GetKd()));
+        draw(loops, canvas, SkLightingImageFilter::MakeDistantLitDiffuse(GetDistantDirection(),
+                                                                         GetWhite(),
+                                                                         GetSurfaceScale(),
+                                                                         GetKd(),
+                                                                         nullptr));
     }
 
 private:
@@ -141,8 +141,7 @@ private:
 
 class LightingSpotLitDiffuseBench : public LightingBaseBench {
 public:
-    LightingSpotLitDiffuseBench(bool small) : INHERITED(small) {
-    }
+    LightingSpotLitDiffuseBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
@@ -150,13 +149,14 @@ protected:
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        draw(loops, canvas, SkLightingImageFilter::CreateSpotLitDiffuse(GetSpotLocation(),
-                                                                        GetSpotTarget(),
-                                                                        GetSpotExponent(),
-                                                                        GetCutoffAngle(),
-                                                                        GetWhite(),
-                                                                        GetSurfaceScale(),
-                                                                        GetKd()));
+        draw(loops, canvas, SkLightingImageFilter::MakeSpotLitDiffuse(GetSpotLocation(),
+                                                                       GetSpotTarget(),
+                                                                       GetSpotExponent(),
+                                                                       GetCutoffAngle(),
+                                                                       GetWhite(),
+                                                                       GetSurfaceScale(),
+                                                                       GetKd(),
+                                                                       nullptr));
     }
 
 private:
@@ -165,8 +165,7 @@ private:
 
 class LightingPointLitSpecularBench : public LightingBaseBench {
 public:
-    LightingPointLitSpecularBench(bool small) : INHERITED(small) {
-    }
+    LightingPointLitSpecularBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
@@ -174,11 +173,12 @@ protected:
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        draw(loops, canvas, SkLightingImageFilter::CreatePointLitSpecular(GetPointLocation(),
-                                                                          GetWhite(),
-                                                                          GetSurfaceScale(),
-                                                                          GetKs(),
-                                                                          GetShininess()));
+        draw(loops, canvas, SkLightingImageFilter::MakePointLitSpecular(GetPointLocation(),
+                                                                        GetWhite(),
+                                                                        GetSurfaceScale(),
+                                                                        GetKs(),
+                                                                        GetShininess(),
+                                                                        nullptr));
     }
 
 private:
@@ -187,8 +187,7 @@ private:
 
 class LightingDistantLitSpecularBench : public LightingBaseBench {
 public:
-    LightingDistantLitSpecularBench(bool small) : INHERITED(small) {
-    }
+    LightingDistantLitSpecularBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
@@ -196,11 +195,12 @@ protected:
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        draw(loops, canvas, SkLightingImageFilter::CreateDistantLitSpecular(GetDistantDirection(),
-                                                                            GetWhite(),
-                                                                            GetSurfaceScale(),
-                                                                            GetKs(),
-                                                                            GetShininess()));
+        draw(loops, canvas, SkLightingImageFilter::MakeDistantLitSpecular(GetDistantDirection(),
+                                                                          GetWhite(),
+                                                                          GetSurfaceScale(),
+                                                                          GetKs(),
+                                                                          GetShininess(),
+                                                                          nullptr));
     }
 
 private:
@@ -209,8 +209,7 @@ private:
 
 class LightingSpotLitSpecularBench : public LightingBaseBench {
 public:
-    LightingSpotLitSpecularBench(bool small) : INHERITED(small) {
-    }
+    LightingSpotLitSpecularBench(bool small) : INHERITED(small) { }
 
 protected:
     const char* onGetName() override {
@@ -218,14 +217,15 @@ protected:
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
-        draw(loops, canvas, SkLightingImageFilter::CreateSpotLitSpecular(GetSpotLocation(),
-                                                                         GetSpotTarget(),
-                                                                         GetSpotExponent(),
-                                                                         GetCutoffAngle(),
-                                                                         GetWhite(),
-                                                                         GetSurfaceScale(),
-                                                                         GetKs(),
-                                                                         GetShininess()));
+        draw(loops, canvas, SkLightingImageFilter::MakeSpotLitSpecular(GetSpotLocation(),
+                                                                       GetSpotTarget(),
+                                                                       GetSpotExponent(),
+                                                                       GetCutoffAngle(),
+                                                                       GetWhite(),
+                                                                       GetSurfaceScale(),
+                                                                       GetKs(),
+                                                                       GetShininess(),
+                                                                       nullptr));
     }
 
 private:
index 1cd20c034e9ac33649a0468cd341faf6e6fa5baa..7c233b80bf8d9fc760f1a917657c84294f52cc82 100644 (file)
@@ -626,52 +626,46 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
     case COMPOSE:
         filter = SkComposeImageFilter::Make(make_image_filter(), make_image_filter());
         break;
-    case DISTANT_LIGHT: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case DISTANT_LIGHT:
         filter = (R(2) == 1)
-                 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
-                                                make_color(), make_scalar(), make_scalar(),
-                                                subFilter.get()))
-                 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
-                                                make_color(), make_scalar(),
-                                                make_scalar(), SkIntToScalar(R(10)),
-                                                subFilter.get()));
+                 ? SkLightingImageFilter::MakeDistantLitDiffuse(make_point(), make_color(),
+                                                                make_scalar(), make_scalar(),
+                                                                make_image_filter())
+                 : SkLightingImageFilter::MakeDistantLitSpecular(make_point(), make_color(),
+                                                                 make_scalar(), make_scalar(),
+                                                                 SkIntToScalar(R(10)),
+                                                                 make_image_filter());
         break;
-    }
-    case POINT_LIGHT: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case POINT_LIGHT:
         filter = (R(2) == 1)
-                 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffuse(make_point(),
-                                                make_color(), make_scalar(), make_scalar(),
-                                                subFilter.get()))
-                 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitSpecular(make_point(),
-                                                make_color(), make_scalar(), make_scalar(),
-                                                SkIntToScalar(R(10)),
-                                                subFilter.get()));
+                 ? SkLightingImageFilter::MakePointLitDiffuse(make_point(), make_color(),
+                                                              make_scalar(), make_scalar(),
+                                                              make_image_filter())
+                 : SkLightingImageFilter::MakePointLitSpecular(make_point(), make_color(),
+                                                               make_scalar(), make_scalar(),
+                                                               SkIntToScalar(R(10)),
+                                                               make_image_filter());
         break;
-    }
-    case SPOT_LIGHT: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case SPOT_LIGHT:
         filter = (R(2) == 1)
-                 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
-                                                 make_point(), make_scalar(), make_scalar(),
-                                                 make_color(), make_scalar(), make_scalar(),
-                                                 subFilter.get()))
-                 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0, 0, 0),
-                                                 make_point(), make_scalar(), make_scalar(),
-                                                 make_color(), make_scalar(), make_scalar(),
-                                                 SkIntToScalar(R(10)), subFilter.get()));
+                 ? SkLightingImageFilter::MakeSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
+                                                             make_point(), make_scalar(),
+                                                             make_scalar(), make_color(),
+                                                             make_scalar(), make_scalar(),
+                                                             make_image_filter())
+                 : SkLightingImageFilter::MakeSpotLitSpecular(SkPoint3::Make(0, 0, 0),
+                                                              make_point(), make_scalar(),
+                                                              make_scalar(), make_color(),
+                                                              make_scalar(), make_scalar(),
+                                                              SkIntToScalar(R(10)),
+                                                              make_image_filter());
         break;
-    }
     case NOISE: {
-        sk_sp<SkShader> shader((R(2) == 1) ?
-            SkPerlinNoiseShader::MakeFractalNoise(
-                make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
-            SkPerlinNoiseShader::MakeTurbulence(
-                make_scalar(true), make_scalar(true), R(10.0f), make_scalar()));
+        sk_sp<SkShader> shader((R(2) == 1)
+                ? SkPerlinNoiseShader::MakeFractalNoise(make_scalar(true), make_scalar(true),
+                                                        R(10.0f), make_scalar())
+                : SkPerlinNoiseShader::MakeTurbulence(make_scalar(true), make_scalar(true),
+                                                      R(10.0f), make_scalar()));
         SkPaint paint;
         paint.setShader(shader);
         SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
index b24ca5af727a6493b8c4472685712a64fa226424..f2434112fa0a752785ed3ffe1665f95e0ec113d0 100644 (file)
@@ -43,11 +43,11 @@ static sk_sp<SkImage> make_gradient_circle(int width, int height) {
     return surface->makeImageSnapshot();
 }
 
-static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, size_t i,
+static void draw_clipped_filter(SkCanvas* canvas, sk_sp<SkImageFilter> filter, size_t i,
                                 const SkRect& primBounds, const SkRect& clipBounds) {
     SkPaint paint;
     paint.setColor(SK_ColorWHITE);
-    paint.setImageFilter(filter);
+    paint.setImageFilter(std::move(filter));
     paint.setAntiAlias(true);
     canvas->save();
     canvas->clipRect(clipBounds);
@@ -93,23 +93,25 @@ protected:
         resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
         SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10));
 
-        SkImageFilter* filters[] = {
-            SkBlurImageFilter::Make(SkIntToScalar(12), SkIntToScalar(12), nullptr).release(),
-            SkDropShadowImageFilter::Make(SkIntToScalar(10), SkIntToScalar(10),
-                SkIntToScalar(3), SkIntToScalar(3), SK_ColorGREEN,
-                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
-                nullptr).release(),
-            SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelSelectorType,
+        sk_sp<SkImageFilter> filters[] = {
+            SkBlurImageFilter::Make(SkIntToScalar(12), SkIntToScalar(12), nullptr),
+            SkDropShadowImageFilter::Make(
+                                    SkIntToScalar(10), SkIntToScalar(10),
+                                    SkIntToScalar(3), SkIntToScalar(3), SK_ColorGREEN,
+                                    SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
+                                    nullptr),
+            sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(
+                                            SkDisplacementMapEffect::kR_ChannelSelectorType,
                                             SkDisplacementMapEffect::kR_ChannelSelectorType,
                                             SkIntToScalar(12),
                                             gradient.get(),
-                                            checkerboard.get()),
-            SkDilateImageFilter::Make(2, 2, checkerboard).release(),
-            SkErodeImageFilter::Make(2, 2, checkerboard).release(),
-            SkOffsetImageFilter::Make(SkIntToScalar(-16), SkIntToScalar(32), nullptr).release(),
-            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr).release(),
-            SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1,
-                                                         SkIntToScalar(2), checkerboard.get()),
+                                            checkerboard.get())),
+            SkDilateImageFilter::Make(2, 2, checkerboard),
+            SkErodeImageFilter::Make(2, 2, checkerboard),
+            SkOffsetImageFilter::Make(SkIntToScalar(-16), SkIntToScalar(32), nullptr),
+            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr),
+            SkLightingImageFilter::MakePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1,
+                                                       SkIntToScalar(2), checkerboard),
 
         };
 
@@ -131,10 +133,6 @@ protected:
         }
         canvas->restore();
 
-        for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
-            SkSafeUnref(filters[i]);
-        }
-
         SkPaint noisePaint;
         noisePaint.setShader(SkPerlinNoiseShader::MakeFractalNoise(0.1f, 0.05f, 1, 0));
 
@@ -142,7 +140,7 @@ protected:
         canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
         for (int xOffset = 0; xOffset < 80; xOffset += 16) {
             bounds.fLeft = SkIntToScalar(xOffset);
-            draw_clipped_filter(canvas, rectFilter.get(), 0, r, bounds);
+            draw_clipped_filter(canvas, rectFilter, 0, r, bounds);
             canvas->translate(0, r.height() + margin);
         }
     }
index 6f749dc7e53fcf0be8fac85d6c38f25419ba3c21..3d5fcf3612f217071fcb27d90e31fc12d71a82fc 100644 (file)
@@ -55,7 +55,7 @@ protected:
                                 0, 1, 0, 0, sk255,
                                 0, 0, 1, 0, 0,
                                 0, 0, 0, 0, sk255 };
-        auto cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+        sk_sp<SkColorFilter> cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
 
         SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
         SkScalar MARGIN = SkIntToScalar(12);
@@ -121,12 +121,12 @@ protected:
                                            &bigRect));
 
             Draw(canvas, checkerboard, rect,
-                 sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation,
-                                                                                   SK_ColorWHITE,
-                                                                                   surfaceScale,
-                                                                                   kd,
-                                                                                   noopCropped.get(),
-                                                                                   &bigRect)));
+                 SkLightingImageFilter::MakePointLitDiffuse(pointLocation,
+                                                            SK_ColorWHITE,
+                                                            surfaceScale,
+                                                            kd,
+                                                            noopCropped,
+                                                            &bigRect));
 
             canvas->restore();
             canvas->translate(0, SkIntToScalar(80));
index 46f998cc2841abb1aa98d7546501f54f9cfaa35c..4c48aec869549e68b83f8bf23bb3fd9051de388d 100644 (file)
 
 #define RESIZE_FACTOR SkIntToScalar(4)
 
+static sk_sp<SkImage> make_gradient_circle(int width, int height) {
+    SkScalar x = SkIntToScalar(width / 2);
+    SkScalar y = SkIntToScalar(height / 2);
+    SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIntToScalar(5));
+    sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(width, height));
+    SkCanvas* canvas = surface->getCanvas();
+    canvas->clear(0x00000000);
+    SkColor colors[2];
+    colors[0] = SK_ColorWHITE;
+    colors[1] = SK_ColorBLACK;
+    SkPaint paint;
+    paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+        2, SkShader::kClamp_TileMode));
+    canvas->drawCircle(x, y, radius, paint);
+
+    return surface->makeImageSnapshot();
+}
+
+
 namespace skiagm {
 
 class ImageFiltersScaledGM : public GM {
@@ -46,7 +65,7 @@ protected:
     void onOnceBeforeDraw() override {
         fCheckerboard = SkImage::MakeFromBitmap(
             sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF404040, 8));
-        fGradientCircle = MakeGradientCircle(64, 64);
+        fGradientCircle = make_gradient_circle(64, 64);
     }
 
     void onDraw(SkCanvas* canvas) override {
@@ -54,10 +73,10 @@ protected:
 
         sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle));
         sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard));
-        sk_sp<SkShader> noise(SkPerlinNoiseShader::MakeFractalNoise(
-            SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
+
         SkPaint noisePaint;
-        noisePaint.setShader(noise);
+        noisePaint.setShader(SkPerlinNoiseShader::MakeFractalNoise(SkDoubleToScalar(0.1),
+                                                                   SkDoubleToScalar(0.05), 1, 0));
 
         SkPoint3 pointLocation = SkPoint3::Make(0, 0, SkIntToScalar(10));
         SkPoint3 spotLocation = SkPoint3::Make(SkIntToScalar(-10),
@@ -72,24 +91,29 @@ protected:
         SkMatrix resizeMatrix;
         resizeMatrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
 
-        SkImageFilter* filters[] = {
-            SkBlurImageFilter::Make(SkIntToScalar(4), SkIntToScalar(4), nullptr).release(),
-            SkDropShadowImageFilter::Make(SkIntToScalar(5), SkIntToScalar(10),
-                SkIntToScalar(3), SkIntToScalar(3), SK_ColorYELLOW,
-                SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr).release(),
-            SkDisplacementMapEffect::Create(SkDisplacementMapEffect::kR_ChannelSelectorType,
+        sk_sp<SkImageFilter> filters[] = {
+            SkBlurImageFilter::Make(SkIntToScalar(4), SkIntToScalar(4), nullptr),
+            SkDropShadowImageFilter::Make(
+                                    SkIntToScalar(5), SkIntToScalar(10),
+                                    SkIntToScalar(3), SkIntToScalar(3), SK_ColorYELLOW,
+                                    SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
+                                    nullptr),
+            sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(
+                                            SkDisplacementMapEffect::kR_ChannelSelectorType,
                                             SkDisplacementMapEffect::kR_ChannelSelectorType,
                                             SkIntToScalar(12),
                                             gradient.get(),
-                                            checkerboard.get()),
-            SkDilateImageFilter::Make(1, 1, checkerboard).release(),
-            SkErodeImageFilter::Make(1, 1, checkerboard).release(),
-            SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr).release(),
-            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr).release(),
-            SkPaintImageFilter::Make(noisePaint).release(),
-            SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
-            SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
-                                                        cutoffAngle, white, surfaceScale, kd),
+                                            checkerboard.get())),
+            SkDilateImageFilter::Make(1, 1, checkerboard),
+            SkErodeImageFilter::Make(1, 1, checkerboard),
+            SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr),
+            SkImageFilter::MakeMatrixFilter(resizeMatrix, kNone_SkFilterQuality, nullptr),
+            SkPaintImageFilter::Make(noisePaint),
+            SkLightingImageFilter::MakePointLitDiffuse(pointLocation, white, surfaceScale, kd,
+                                                       nullptr),
+            SkLightingImageFilter::MakeSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
+                                                      cutoffAngle, white, surfaceScale, kd,
+                                                      nullptr),
         };
 
         SkVector scales[] = {
@@ -128,31 +152,9 @@ protected:
             canvas->restore();
             canvas->translate(0, r.height() * scales[j].fY + margin);
         }
-
-        for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
-            filters[i]->unref();
-        }
     }
 
 private:
-    static sk_sp<SkImage> MakeGradientCircle(int width, int height) {
-        SkScalar x = SkIntToScalar(width / 2);
-        SkScalar y = SkIntToScalar(height / 2);
-        SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIntToScalar(5));
-        auto surface(SkSurface::MakeRasterN32Premul(width, height));
-        SkCanvas* canvas = surface->getCanvas();
-        canvas->clear(0x00000000);
-        SkColor colors[2];
-        colors[0] = SK_ColorWHITE;
-        colors[1] = SK_ColorBLACK;
-        SkPaint paint;
-        paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
-                                                     2, SkShader::kClamp_TileMode));
-        canvas->drawCircle(x, y, radius, paint);
-
-        return surface->makeImageSnapshot();
-    }
-
     sk_sp<SkImage> fCheckerboard, fGradientCircle;
 
     typedef GM INHERITED;
index 08d09c2ecb14b88e8eecc1199124bae2198c97d6..7915c331d0d03edf4da18876a35093d97bb113f6 100644 (file)
@@ -93,64 +93,64 @@ protected:
         int y = 0;
         for (int i = 0; i < 3; i++) {
             const SkImageFilter::CropRect* cr = (i == 1) ? &cropRect : (i == 2) ? &fullSizeCropRect : nullptr;
-            SkImageFilter* input = (i == 2) ? noopCropped.get() : nullptr;
-            paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation,
+            sk_sp<SkImageFilter> input = (i == 2) ? noopCropped : nullptr;
+            paint.setImageFilter(SkLightingImageFilter::MakePointLitDiffuse(pointLocation,
+                                                                            white,
+                                                                            surfaceScale,
+                                                                            kd,
+                                                                            input,
+                                                                            cr));
+            drawClippedBitmap(canvas, paint, 0, y);
+
+            paint.setImageFilter(SkLightingImageFilter::MakeDistantLitDiffuse(distantDirection,
                                                                               white,
                                                                               surfaceScale,
                                                                               kd,
                                                                               input,
-                                                                              cr))->unref();
-            drawClippedBitmap(canvas, paint, 0, y);
-
-            paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection,
-                                                                                white,
-                                                                                surfaceScale,
-                                                                                kd,
-                                                                                input,
-                                                                                cr))->unref();
+                                                                              cr));
             drawClippedBitmap(canvas, paint, 110, y);
 
-            paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation,
-                                                                             spotTarget,
-                                                                             spotExponent,
-                                                                             cutoffAngle,
-                                                                             white,
-                                                                             surfaceScale,
-                                                                             kd,
-                                                                             input,
-                                                                             cr))->unref();
+            paint.setImageFilter(SkLightingImageFilter::MakeSpotLitDiffuse(spotLocation,
+                                                                           spotTarget,
+                                                                           spotExponent,
+                                                                           cutoffAngle,
+                                                                           white,
+                                                                           surfaceScale,
+                                                                           kd,
+                                                                           input,
+                                                                           cr));
             drawClippedBitmap(canvas, paint, 220, y);
 
             y += 110;
 
-            paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation,
+            paint.setImageFilter(SkLightingImageFilter::MakePointLitSpecular(pointLocation,
+                                                                             white,
+                                                                             surfaceScale,
+                                                                             ks,
+                                                                             shininess,
+                                                                             input,
+                                                                             cr));
+            drawClippedBitmap(canvas, paint, 0, y);
+
+            paint.setImageFilter(SkLightingImageFilter::MakeDistantLitSpecular(distantDirection,
                                                                                white,
                                                                                surfaceScale,
                                                                                ks,
                                                                                shininess,
                                                                                input,
-                                                                               cr))->unref();
-            drawClippedBitmap(canvas, paint, 0, y);
-
-            paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection,
-                                                                                 white,
-                                                                                 surfaceScale,
-                                                                                 ks,
-                                                                                 shininess,
-                                                                                 input,
-                                                                                 cr))->unref();
+                                                                               cr));
             drawClippedBitmap(canvas, paint, 110, y);
 
-            paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation,
-                                                                              spotTarget,
-                                                                              spotExponent,
-                                                                              cutoffAngle,
-                                                                              white,
-                                                                              surfaceScale,
-                                                                              ks,
-                                                                              shininess,
-                                                                              input,
-                                                                              cr))->unref();
+            paint.setImageFilter(SkLightingImageFilter::MakeSpotLitSpecular(spotLocation,
+                                                                            spotTarget,
+                                                                            spotExponent,
+                                                                            cutoffAngle,
+                                                                            white,
+                                                                            surfaceScale,
+                                                                            ks,
+                                                                            shininess,
+                                                                            input,
+                                                                            cr));
             drawClippedBitmap(canvas, paint, 220, y);
 
             y += 110;
index fb356c52e43413a019d57ee7514b86713ae4a28d..3ba3348ca96aa3bd8d35c730a591f43325b41d3e 100644 (file)
@@ -17,34 +17,76 @@ struct SkPoint3;
 
 class SK_API SkLightingImageFilter : public SkImageFilter {
 public:
-    static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction,
+    static sk_sp<SkImageFilter> MakeDistantLitDiffuse(const SkPoint3& direction,
         SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
-        SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
+        sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
+    static sk_sp<SkImageFilter> MakePointLitDiffuse(const SkPoint3& location,
+        SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
+        sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
+    static sk_sp<SkImageFilter> MakeSpotLitDiffuse(const SkPoint3& location,
+        const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
+        SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
+        sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
+    static sk_sp<SkImageFilter> MakeDistantLitSpecular(const SkPoint3& direction,
+        SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
+        SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
+    static sk_sp<SkImageFilter> MakePointLitSpecular(const SkPoint3& location,
+        SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
+        SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
+    static sk_sp<SkImageFilter> MakeSpotLitSpecular(const SkPoint3& location,
+        const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
+        SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
+        SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
+
+    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
+
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+     static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction,
+        SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
+        SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
+        return MakeDistantLitDiffuse(direction, lightColor, surfaceScale, kd,
+                                     sk_ref_sp<SkImageFilter>(input), cropRect).release();
+    }
     static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location,
         SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
-        SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
+        SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
+        return MakePointLitDiffuse(location, lightColor, surfaceScale, kd,
+                                   sk_ref_sp<SkImageFilter>(input), cropRect).release();
+    }
     static SkImageFilter* CreateSpotLitDiffuse(const SkPoint3& location,
         const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
         SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
-        SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
+        SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
+        return MakeSpotLitDiffuse(location, target, specularExponent, cutoffAngle,
+                                  lightColor, surfaceScale, kd,
+                                  sk_ref_sp<SkImageFilter>(input), cropRect).release();
+    }
     static SkImageFilter* CreateDistantLitSpecular(const SkPoint3& direction,
         SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
-        SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
+        SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
+        return MakeDistantLitSpecular(direction, lightColor, surfaceScale, ks, shininess,
+                                      sk_ref_sp<SkImageFilter>(input), cropRect).release();
+    }
     static SkImageFilter* CreatePointLitSpecular(const SkPoint3& location,
         SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
-        SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
+        SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
+        return MakePointLitSpecular(location, lightColor, surfaceScale, ks, shininess,
+                                    sk_ref_sp<SkImageFilter>(input), cropRect).release();
+    }
     static SkImageFilter* CreateSpotLitSpecular(const SkPoint3& location,
         const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
         SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
-        SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL);
-    ~SkLightingImageFilter();
-
-    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
+        SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
+        return MakeSpotLitSpecular(location, target, specularExponent, cutoffAngle,
+                                   lightColor, surfaceScale, ks, shininess,
+                                   sk_ref_sp<SkImageFilter>(input), cropRect).release();
+    }
+#endif
 
 protected:
-    SkLightingImageFilter(SkImageFilterLight* light,
+    SkLightingImageFilter(sk_sp<SkImageFilterLight> light,
                           SkScalar surfaceScale,
-                          SkImageFilter* input,
+                          sk_sp<SkImageFilter> input,
                           const CropRect* cropRect);
     void flatten(SkWriteBuffer&) const override;
     const SkImageFilterLight* light() const { return fLight.get(); }
@@ -52,9 +94,10 @@ protected:
     bool affectsTransparentBlack() const override { return true; }
 
 private:
-    typedef SkImageFilter INHERITED;
-    SkAutoTUnref<SkImageFilterLight> fLight;
+    sk_sp<SkImageFilterLight> fLight;
     SkScalar fSurfaceScale;
+
+    typedef SkImageFilter INHERITED;
 };
 
 #endif
index f09c6a57a015c4f217f5991a768a72fbe81a5693..5f06731ae5203128d46f7f8cbb3a0d65b0c0d9af 100644 (file)
@@ -629,52 +629,46 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
     case COMPOSE:
         filter = SkComposeImageFilter::Make(make_image_filter(), make_image_filter());
         break;
-    case DISTANT_LIGHT: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case DISTANT_LIGHT:
         filter = (R(2) == 1)
-                 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
-                                                make_color(), make_scalar(), make_scalar(),
-                                                subFilter.get()))
-                 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
-                                                make_color(), make_scalar(),
-                                                make_scalar(), SkIntToScalar(R(10)),
-                                                subFilter.get()));
+                 ? SkLightingImageFilter::MakeDistantLitDiffuse(make_point(), make_color(),
+                                                                make_scalar(), make_scalar(),
+                                                                make_image_filter())
+                 : SkLightingImageFilter::MakeDistantLitSpecular(make_point(), make_color(),
+                                                                 make_scalar(), make_scalar(),
+                                                                 SkIntToScalar(R(10)),
+                                                                 make_image_filter());
         break;
-    }
-    case POINT_LIGHT: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case POINT_LIGHT:
         filter = (R(2) == 1)
-                 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffuse(make_point(),
-                                                make_color(), make_scalar(), make_scalar(),
-                                                subFilter.get()))
-                 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitSpecular(make_point(),
-                                                make_color(), make_scalar(), make_scalar(),
-                                                SkIntToScalar(R(10)),
-                                                subFilter.get()));
+                 ? SkLightingImageFilter::MakePointLitDiffuse(make_point(), make_color(),
+                                                              make_scalar(), make_scalar(),
+                                                              make_image_filter())
+                 : SkLightingImageFilter::MakePointLitSpecular(make_point(), make_color(),
+                                                               make_scalar(), make_scalar(),
+                                                               SkIntToScalar(R(10)),
+                                                               make_image_filter());
         break;
-    }
-    case SPOT_LIGHT: {
-        sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+    case SPOT_LIGHT:
         filter = (R(2) == 1)
-                 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
-                                                 make_point(), make_scalar(), make_scalar(),
-                                                 make_color(), make_scalar(), make_scalar(),
-                                                 subFilter.get()))
-                 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0, 0, 0),
-                                                 make_point(), make_scalar(), make_scalar(),
-                                                 make_color(), make_scalar(), make_scalar(),
-                                                 SkIntToScalar(R(10)), subFilter.get()));
+                 ? SkLightingImageFilter::MakeSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
+                                                             make_point(), make_scalar(),
+                                                             make_scalar(), make_color(),
+                                                             make_scalar(), make_scalar(),
+                                                             make_image_filter())
+                 : SkLightingImageFilter::MakeSpotLitSpecular(SkPoint3::Make(0, 0, 0),
+                                                              make_point(), make_scalar(),
+                                                              make_scalar(), make_color(), 
+                                                              make_scalar(), make_scalar(),
+                                                              SkIntToScalar(R(10)),
+                                                              make_image_filter());
         break;
-    }
     case NOISE: {
-        sk_sp<SkShader> shader((R(2) == 1) ?
-            SkPerlinNoiseShader::MakeFractalNoise(
-                make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
-            SkPerlinNoiseShader::MakeTurbulence(
-                make_scalar(true), make_scalar(true), R(10.0f), make_scalar()));
+        sk_sp<SkShader> shader((R(2) == 1)
+                ? SkPerlinNoiseShader::MakeFractalNoise(make_scalar(true), make_scalar(true),
+                                                        R(10.0f), make_scalar())
+                : SkPerlinNoiseShader::MakeTurbulence(make_scalar(true), make_scalar(true),
+                                                      R(10.0f), make_scalar()));
         SkPaint paint;
         paint.setShader(shader);
         SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
index e276dc0fde1b7ba3b10126a5d375d7f7b25166e0..53d6327d909b599ceee5243737e5232bc02d5923 100644 (file)
@@ -347,11 +347,12 @@ enum BoundaryMode {
 
 class SkLightingImageFilterInternal : public SkLightingImageFilter {
 protected:
-    SkLightingImageFilterInternal(SkImageFilterLight* light,
+    SkLightingImageFilterInternal(sk_sp<SkImageFilterLight> light,
                                   SkScalar surfaceScale,
-                                  SkImageFilter* input,
+                                  sk_sp<SkImageFilter> input,
                                   const CropRect* cropRect)
-      : INHERITED(light, surfaceScale, input, cropRect) {}
+        : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect) {
+    }
 
 #if SK_SUPPORT_GPU
     bool canFilterImageGPU() const override { return true; }
@@ -476,17 +477,20 @@ bool SkLightingImageFilterInternal::filterImageGPUDeprecated(Proxy* proxy,
 
 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal {
 public:
-    static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScale,
-                                 SkScalar kd, SkImageFilter*,
-                                 const CropRect*);
+    static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilterLight> light,
+                                     SkScalar surfaceScale,
+                                     SkScalar kd,
+                                     sk_sp<SkImageFilter>,
+                                     const CropRect*);
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFilter)
     SkScalar kd() const { return fKD; }
 
 protected:
-    SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScale,
-                                 SkScalar kd, SkImageFilter* input, const CropRect* cropRect);
+    SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLight> light, SkScalar surfaceScale,
+                                 SkScalar kd,
+                                 sk_sp<SkImageFilter> input, const CropRect* cropRect);
     void flatten(SkWriteBuffer& buffer) const override;
     bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
                                  SkBitmap* result, SkIPoint* offset) const override;
@@ -503,8 +507,10 @@ private:
 
 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal {
 public:
-    static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScale,
-                                 SkScalar ks, SkScalar shininess, SkImageFilter*, const CropRect*);
+    static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilterLight> light,
+                                     SkScalar surfaceScale,
+                                     SkScalar ks, SkScalar shininess,
+                                     sk_sp<SkImageFilter>, const CropRect*);
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageFilter)
@@ -513,8 +519,10 @@ public:
     SkScalar shininess() const { return fShininess; }
 
 protected:
-    SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScale, SkScalar ks,
-                                  SkScalar shininess, SkImageFilter* input, const CropRect*);
+    SkSpecularLightingImageFilter(sk_sp<SkImageFilterLight> light,
+                                  SkScalar surfaceScale, SkScalar ks,
+                                  SkScalar shininess,
+                                  sk_sp<SkImageFilter> input, const CropRect*);
     void flatten(SkWriteBuffer& buffer) const override;
     bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
                                  SkBitmap* result, SkIPoint* offset) const override;
@@ -1094,86 +1102,91 @@ void SkImageFilterLight::flattenLight(SkWriteBuffer& buffer) const {
 }
 ///////////////////////////////////////////////////////////////////////////////
 
-SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScale,
-                                             SkImageFilter* input, const CropRect* cropRect)
-  : INHERITED(1, &input, cropRect)
-  , fLight(SkRef(light))
-  , fSurfaceScale(surfaceScale / 255)
-{}
-
-SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& direction,
-                                                              SkColor lightColor,
-                                                              SkScalar surfaceScale,
-                                                              SkScalar kd,
-                                                              SkImageFilter* input,
-                                                              const CropRect* cropRect) {
-    SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightColor));
-    return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect);
-}
-
-SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& location,
-                                                            SkColor lightColor,
-                                                            SkScalar surfaceScale,
-                                                            SkScalar kd,
-                                                            SkImageFilter* input,
-                                                            const CropRect* cropRect) {
-    SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor));
-    return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect);
-}
-
-SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& location,
-                                                           const SkPoint3& target,
-                                                           SkScalar specularExponent,
-                                                           SkScalar cutoffAngle,
-                                                           SkColor lightColor,
-                                                           SkScalar surfaceScale,
-                                                           SkScalar kd,
-                                                           SkImageFilter* input,
-                                                           const CropRect* cropRect) {
-    SkAutoTUnref<SkImageFilterLight> light(
-            new SkSpotLight(location, target, specularExponent, cutoffAngle, lightColor));
-    return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect);
-}
-
-SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& direction,
+SkLightingImageFilter::SkLightingImageFilter(sk_sp<SkImageFilterLight> light,
+                                             SkScalar surfaceScale,
+                                             sk_sp<SkImageFilter> input, const CropRect* cropRect)
+    : INHERITED(&input, 1, cropRect)
+    , fLight(std::move(light))
+    , fSurfaceScale(surfaceScale / 255) {
+}
+
+sk_sp<SkImageFilter> SkLightingImageFilter::MakeDistantLitDiffuse(const SkPoint3& direction,
+                                                                  SkColor lightColor,
+                                                                  SkScalar surfaceScale,
+                                                                  SkScalar kd,
+                                                                  sk_sp<SkImageFilter> input,
+                                                                  const CropRect* cropRect) {
+    sk_sp<SkImageFilterLight> light(new SkDistantLight(direction, lightColor));
+    return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd, 
+                                              std::move(input), cropRect);
+}
+
+sk_sp<SkImageFilter> SkLightingImageFilter::MakePointLitDiffuse(const SkPoint3& location,
+                                                                SkColor lightColor,
+                                                                SkScalar surfaceScale,
+                                                                SkScalar kd,
+                                                                sk_sp<SkImageFilter> input,
+                                                                const CropRect* cropRect) {
+    sk_sp<SkImageFilterLight> light(new SkPointLight(location, lightColor));
+    return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd,
+                                              std::move(input), cropRect);
+}
+
+sk_sp<SkImageFilter> SkLightingImageFilter::MakeSpotLitDiffuse(const SkPoint3& location,
+                                                               const SkPoint3& target,
+                                                               SkScalar specularExponent,
+                                                               SkScalar cutoffAngle,
                                                                SkColor lightColor,
                                                                SkScalar surfaceScale,
-                                                               SkScalar ks,
-                                                               SkScalar shine,
-                                                               SkImageFilter* input,
+                                                               SkScalar kd,
+                                                               sk_sp<SkImageFilter> input,
                                                                const CropRect* cropRect) {
-    SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightColor));
-    return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
-}
-
-SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& location,
-                                                             SkColor lightColor,
-                                                             SkScalar surfaceScale,
-                                                             SkScalar ks,
-                                                             SkScalar shine,
-                                                             SkImageFilter* input,
-                                                             const CropRect* cropRect) {
-    SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor));
-    return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
-}
-
-SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& location,
-                                                            const SkPoint3& target,
-                                                            SkScalar specularExponent,
-                                                            SkScalar cutoffAngle,
-                                                            SkColor lightColor,
-                                                            SkScalar surfaceScale,
-                                                            SkScalar ks,
-                                                            SkScalar shine,
-                                                            SkImageFilter* input,
-                                                            const CropRect* cropRect) {
-    SkAutoTUnref<SkImageFilterLight> light(
+    sk_sp<SkImageFilterLight> light(
+            new SkSpotLight(location, target, specularExponent, cutoffAngle, lightColor));
+    return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd,
+                                              std::move(input), cropRect);
+}
+
+sk_sp<SkImageFilter> SkLightingImageFilter::MakeDistantLitSpecular(const SkPoint3& direction,
+                                                                   SkColor lightColor,
+                                                                   SkScalar surfaceScale,
+                                                                   SkScalar ks,
+                                                                   SkScalar shine,
+                                                                   sk_sp<SkImageFilter> input,
+                                                                   const CropRect* cropRect) {
+    sk_sp<SkImageFilterLight> light(new SkDistantLight(direction, lightColor));
+    return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, ks, shine,
+                                               std::move(input), cropRect);
+}
+
+sk_sp<SkImageFilter> SkLightingImageFilter::MakePointLitSpecular(const SkPoint3& location,
+                                                                 SkColor lightColor,
+                                                                 SkScalar surfaceScale,
+                                                                 SkScalar ks,
+                                                                 SkScalar shine,
+                                                                 sk_sp<SkImageFilter> input,
+                                                                 const CropRect* cropRect) {
+    sk_sp<SkImageFilterLight> light(new SkPointLight(location, lightColor));
+    return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, ks, shine,
+                                               std::move(input), cropRect);
+}
+
+sk_sp<SkImageFilter> SkLightingImageFilter::MakeSpotLitSpecular(const SkPoint3& location,
+                                                                const SkPoint3& target,
+                                                                SkScalar specularExponent,
+                                                                SkScalar cutoffAngle,
+                                                                SkColor lightColor,
+                                                                SkScalar surfaceScale,
+                                                                SkScalar ks,
+                                                                SkScalar shine,
+                                                                sk_sp<SkImageFilter> input,
+                                                                const CropRect* cropRect) {
+    sk_sp<SkImageFilterLight> light(
             new SkSpotLight(location, target, specularExponent, cutoffAngle, lightColor));
-    return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect);
+    return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, ks, shine,
+                                               std::move(input), cropRect);
 }
 
-SkLightingImageFilter::~SkLightingImageFilter() {}
-
 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
     this->INHERITED::flatten(buffer);
     fLight->flattenLight(buffer);
@@ -1182,12 +1195,12 @@ void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light,
-                                                    SkScalar surfaceScale,
-                                                    SkScalar kd,
-                                                    SkImageFilter* input,
-                                                    const CropRect* cropRect) {
-    if (nullptr == light) {
+sk_sp<SkImageFilter> SkDiffuseLightingImageFilter::Make(sk_sp<SkImageFilterLight> light,
+                                                        SkScalar surfaceScale,
+                                                        SkScalar kd,
+                                                        sk_sp<SkImageFilter> input,
+                                                        const CropRect* cropRect) {
+    if (!light) {
         return nullptr;
     }
     if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) {
@@ -1198,26 +1211,25 @@ SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light,
     if (kd < 0) {
         return nullptr;
     }
-    return new SkDiffuseLightingImageFilter(light, surfaceScale, kd, input, cropRect);
+    return sk_sp<SkImageFilter>(new SkDiffuseLightingImageFilter(std::move(light), surfaceScale, 
+                                                                 kd, std::move(input), cropRect));
 }
 
-SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* light,
+SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLight> light,
                                                            SkScalar surfaceScale,
                                                            SkScalar kd,
-                                                           SkImageFilter* input,
+                                                           sk_sp<SkImageFilter> input,
                                                            const CropRect* cropRect)
-  : INHERITED(light, surfaceScale, input, cropRect),
-    fKD(kd)
-{
+    : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
+    , fKD(kd) {
 }
 
 sk_sp<SkFlattenable> SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
-    SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer));
+    sk_sp<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer));
     SkScalar surfaceScale = buffer.readScalar();
     SkScalar kd = buffer.readScalar();
-    return sk_sp<SkFlattenable>(Create(light, surfaceScale, kd, common.getInput(0).get(),
-                                       &common.cropRect()));
+    return Make(std::move(light), surfaceScale, kd, common.getInput(0), &common.cropRect());
 }
 
 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
@@ -1322,13 +1334,13 @@ GrFragmentProcessor* SkDiffuseLightingImageFilter::getFragmentProcessor(
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light,
-                                                     SkScalar surfaceScale,
-                                                     SkScalar ks,
-                                                     SkScalar shininess,
-                                                     SkImageFilter* input,
-                                                     const CropRect* cropRect) {
-    if (nullptr == light) {
+sk_sp<SkImageFilter> SkSpecularLightingImageFilter::Make(sk_sp<SkImageFilterLight> light,
+                                                         SkScalar surfaceScale,
+                                                         SkScalar ks,
+                                                         SkScalar shininess,
+                                                         sk_sp<SkImageFilter> input,
+                                                         const CropRect* cropRect) {
+    if (!light) {
         return nullptr;
     }
     if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsFinite(shininess)) {
@@ -1339,29 +1351,30 @@ SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light,
     if (ks < 0) {
         return nullptr;
     }
-    return new SkSpecularLightingImageFilter(light, surfaceScale, ks, shininess, input, cropRect);
+    return sk_sp<SkImageFilter>(new SkSpecularLightingImageFilter(std::move(light), surfaceScale,
+                                                                  ks, shininess,
+                                                                  std::move(input), cropRect));
 }
 
-SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight* light,
+SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(sk_sp<SkImageFilterLight> light,
                                                              SkScalar surfaceScale,
                                                              SkScalar ks,
                                                              SkScalar shininess,
-                                                             SkImageFilter* input,
+                                                             sk_sp<SkImageFilter> input,
                                                              const CropRect* cropRect)
-  : INHERITED(light, surfaceScale, input, cropRect),
-    fKS(ks),
-    fShininess(shininess)
-{
+    : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
+    , fKS(ks)
+    , fShininess(shininess) {
 }
 
 sk_sp<SkFlattenable> SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buffer) {
     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
-    SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer));
+    sk_sp<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer));
     SkScalar surfaceScale = buffer.readScalar();
     SkScalar ks = buffer.readScalar();
     SkScalar shine = buffer.readScalar();
-    return sk_sp<SkFlattenable>(Create(light, surfaceScale, ks, shine, common.getInput(0).get(),
-                                       &common.cropRect()));
+    return Make(std::move(light), surfaceScale, ks, shine, common.getInput(0),
+                &common.cropRect());
 }
 
 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const {
index b37f9589f78223f591491c2a7c89da6e9b57fdda..81f8a9993820d0557f6dd163ffc7108ffd718e18 100644 (file)
@@ -145,59 +145,61 @@ class FilterList {
 public:
     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),
-            SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
-            SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
-        };
-        const SkISize kernelSize = SkISize::Make(3, 3);
-        const SkScalar gain = SK_Scalar1, bias = 0;
         const SkScalar five = SkIntToScalar(5);
 
-        SkMatrix matrix;
-
-        matrix.setTranslate(SK_Scalar1, SK_Scalar1);
-        matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
-
         {
             sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
                                                                   SkXfermode::kSrcIn_Mode));
 
             this->addFilter("color filter",
-                SkColorFilterImageFilter::Make(cf, input, cropRect).release());
+                SkColorFilterImageFilter::Make(std::move(cf), input, cropRect));
         }
 
         {
             sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64, 64)));
             sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gradientImage)));
 
-            this->addFilter("displacement map", SkDisplacementMapEffect::Create(
-                SkDisplacementMapEffect::kR_ChannelSelectorType,
-                SkDisplacementMapEffect::kB_ChannelSelectorType,
-                20.0f, gradientSource.get(), input.get(), cropRect));
+            this->addFilter("displacement map", 
+                sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(
+                                        SkDisplacementMapEffect::kR_ChannelSelectorType,
+                                        SkDisplacementMapEffect::kB_ChannelSelectorType,
+                                        20.0f, gradientSource.get(), input.get(), cropRect)));
         }
 
         this->addFilter("blur", SkBlurImageFilter::Make(SK_Scalar1,
                                                         SK_Scalar1,
                                                         input,
-                                                        cropRect).release());
+                                                        cropRect));
         this->addFilter("drop shadow", SkDropShadowImageFilter::Make(
                   SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN,
                   SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
-                  input, cropRect).release());
-        this->addFilter("diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse(
-                  location, SK_ColorGREEN, 0, 0, input.get(), cropRect));
+                  input, cropRect));
+        this->addFilter("diffuse lighting",
+                  SkLightingImageFilter::MakePointLitDiffuse(location, SK_ColorGREEN, 0, 0,
+                                                             input, cropRect));
         this->addFilter("specular lighting",
-                  SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0,
-                                                                input.get(), cropRect));
-        this->addFilter("matrix convolution",
+                  SkLightingImageFilter::MakePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0,
+                                                              input, cropRect));
+        {
+            SkScalar kernel[9] = {
+                SkIntToScalar(1), SkIntToScalar(1), SkIntToScalar(1),
+                SkIntToScalar(1), SkIntToScalar(-7), SkIntToScalar(1),
+                SkIntToScalar(1), SkIntToScalar(1), SkIntToScalar(1),
+            };
+            const SkISize kernelSize = SkISize::Make(3, 3);
+            const SkScalar gain = SK_Scalar1, bias = 0;
+
+            this->addFilter("matrix convolution",
                   SkMatrixConvolutionImageFilter::Make(
                       kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1),
                       SkMatrixConvolutionImageFilter::kRepeat_TileMode, false,
-                      input, cropRect).release());
+                      input, cropRect));
+        }
+
         this->addFilter("merge", SkMergeImageFilter::Make(input, input,
                                                           SkXfermode::kSrcOver_Mode,
-                                                          cropRect).release());
+                                                          cropRect));
+
         {
             SkPaint greenColorShaderPaint;
             greenColorShaderPaint.setShader(SkShader::MakeColorShader(SK_ColorGREEN));
@@ -212,29 +214,34 @@ public:
 
             this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Make(
                   std::move(paintFilterLeft), std::move(paintFilterRight),
-                  SkXfermode::kSrcOver_Mode, cropRect).release());
+                  SkXfermode::kSrcOver_Mode, cropRect));
         }
 
         this->addFilter("offset",
                         SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1, input,
-                                                  cropRect).release());
-        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(
+                                                  cropRect));
+        this->addFilter("dilate", SkDilateImageFilter::Make(3, 2, input, cropRect));
+        this->addFilter("erode", SkErodeImageFilter::Make(2, 3, input, cropRect));
+        this->addFilter("tile", sk_sp<SkImageFilter>(SkTileImageFilter::Create(
             SkRect::MakeXYWH(0, 0, 50, 50),
             cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100),
-            input.get()));
+            input.get())));
+
         if (!cropRect) {
+            SkMatrix matrix;
+
+            matrix.setTranslate(SK_Scalar1, SK_Scalar1);
+            matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
+
             this->addFilter("matrix",
-                SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, input).release());
+                SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, input));
         }
-
         {
             sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five, input));
 
             this->addFilter("blur and offset", SkOffsetImageFilter::Make(five, five,
                                                                          std::move(blur),
-                                                                         cropRect).release());
+                                                                         cropRect));
         }
         {
             SkRTreeFactory factory;
@@ -249,7 +256,7 @@ public:
 
             this->addFilter("picture and blur", SkBlurImageFilter::Make(five, five,
                                                                         std::move(pictureFilter),
-                                                                        cropRect).release());
+                                                                        cropRect));
         }
         {
             SkPaint paint;
@@ -258,23 +265,26 @@ public:
 
             this->addFilter("paint and blur", SkBlurImageFilter::Make(five, five,
                                                                       std::move(paintFilter),
-                                                                      cropRect).release());
+                                                                      cropRect));
         }
         this->addFilter("xfermode", SkXfermodeImageFilter::Make(
-            SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).release());
+            SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect));
     }
     int count() const { return fFilters.count(); }
     SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }
     const char* getName(int index) const { return fFilters[index].fName; }
 private:
     struct Filter {
-        Filter() : fName(nullptr), fFilter(nullptr) {}
-        Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(filter) {}
+        Filter() : fName(nullptr) {}
+        Filter(const char* name, sk_sp<SkImageFilter> filter)
+            : fName(name)
+            , fFilter(std::move(filter)) {
+        }
         const char*                 fName;
         sk_sp<SkImageFilter>        fFilter;
     };
-    void addFilter(const char* name, SkImageFilter* filter) {
-        fFilters.push_back(Filter(name, filter));
+    void addFilter(const char* name, sk_sp<SkImageFilter> filter) {
+        fFilters.push_back(Filter(name, std::move(filter)));
     }
 
     SkTArray<Filter> fFilters;
@@ -500,10 +510,10 @@ DEF_TEST(ImageFilter, reporter) {
 
             sk_sp<SkImageFilter> bmSrc(SkImageSource::Make(std::move(image)));
             SkPaint paint;
-            paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
+            paint.setImageFilter(SkLightingImageFilter::MakeSpotLitSpecular(
                     location, target, specularExponent, 180,
                     0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
-                    bmSrc.get()))->unref();
+                    std::move(bmSrc)));
             SkCanvas canvas(result);
             SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize),
                                       SkIntToScalar(kBitmapSize));
@@ -625,8 +635,8 @@ static void run_raster_test(skiatest::Reporter* reporter,
 
     const SkImageInfo info = SkImageInfo::MakeN32Premul(widthHeight, widthHeight);
 
-    SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
-    SkImageFilter::DeviceProxy proxy(device);
+    sk_sp<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
+    SkImageFilter::DeviceProxy proxy(device.get());
 
     (*test)(&proxy, reporter, nullptr);
 }
@@ -638,14 +648,14 @@ static void run_gpu_test(skiatest::Reporter* reporter,
                          PFTest test) {
     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
 
-    SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
-                                                         SkBudgeted::kNo,
-                                                         SkImageInfo::MakeN32Premul(widthHeight,
-                                                                                    widthHeight),
-                                                         0,
-                                                         &props,
-                                                         SkGpuDevice::kUninit_InitContents));
-    SkImageFilter::DeviceProxy proxy(device);
+    sk_sp<SkGpuDevice> device(SkGpuDevice::Create(context,
+                                                  SkBudgeted::kNo,
+                                                  SkImageInfo::MakeN32Premul(widthHeight,
+                                                                             widthHeight),
+                                                  0,
+                                                  &props,
+                                                  SkGpuDevice::kUninit_InitContents));
+    SkImageFilter::DeviceProxy proxy(device.get());
 
     (*test)(&proxy, reporter, context);
 }
@@ -1158,8 +1168,8 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
     // Check that, for now, SkPictureImageFilter does not serialize or
     // deserialize its contained picture when the filter is serialized
     // cross-process. Do this by "laundering" it through SkValidatingReadBuffer.
-    SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get()));
-    SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
+    sk_sp<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get()));
+    sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
         data->data(), data->size(), SkImageFilter::GetFlattenableType()));
     SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
 
@@ -1551,10 +1561,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(PartialCropRect_Gpu, reporter, ctxInfo) {
 
 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
 
-    SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
-    SkAutoTUnref<SkImageFilter> lighting(SkLightingImageFilter::CreatePointLitDiffuse(
-          location, SK_ColorGREEN, 0, 0));
-    REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds());
+    {
+        SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
+        sk_sp<SkImageFilter> lighting(SkLightingImageFilter::MakePointLitDiffuse(location,
+                                                                                 SK_ColorGREEN,
+                                                                                 0, 0, nullptr));
+        REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds());
+    }
 
     {
         sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
@@ -1685,13 +1698,13 @@ DEF_TEST(BlurLargeImage, reporter) {
 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(HugeBlurImageFilter_Gpu, reporter, ctxInfo) {
     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
 
-    SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext,
-                                                         SkBudgeted::kNo,
-                                                         SkImageInfo::MakeN32Premul(100, 100),
-                                                         0,
-                                                         &props,
-                                                         SkGpuDevice::kUninit_InitContents));
-    SkCanvas canvas(device);
+    sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext,
+                                                  SkBudgeted::kNo,
+                                                  SkImageInfo::MakeN32Premul(100, 100),
+                                                  0,
+                                                  &props,
+                                                  SkGpuDevice::kUninit_InitContents));
+    SkCanvas canvas(device.get());
 
     test_huge_blur(&canvas, reporter);
 }
@@ -1699,13 +1712,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(HugeBlurImageFilter_Gpu, reporter, ctxInfo
 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, reporter, ctxInfo) {
     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
 
-    SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext,
-                                                         SkBudgeted::kNo,
-                                                         SkImageInfo::MakeN32Premul(1, 1),
-                                                         0,
-                                                         &props,
-                                                         SkGpuDevice::kUninit_InitContents));
-    SkCanvas canvas(device);
+    sk_sp<SkGpuDevice> device(SkGpuDevice::Create(ctxInfo.fGrContext,
+                                                  SkBudgeted::kNo,
+                                                  SkImageInfo::MakeN32Premul(1, 1),
+                                                  0,
+                                                  &props,
+                                                  SkGpuDevice::kUninit_InitContents));
+    SkCanvas canvas(device.get());
 
     test_xfermode_cropped_input(&canvas, reporter);
 }