more shader-->sp conversions
authorreed <reed@google.com>
Sun, 13 Mar 2016 19:32:36 +0000 (12:32 -0700)
committerCommit bot <commit-bot@chromium.org>
Sun, 13 Mar 2016 19:32:36 +0000 (12:32 -0700)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1789633002

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

61 files changed:
gm/gradientDirtyLaundry.cpp
gm/gradient_matrix.cpp
gm/gradients.cpp
gm/gradients_2pt_conical.cpp
gm/gradients_no_texture.cpp
gm/gradtext.cpp
gm/hairmodes.cpp
gm/imagefiltersclipped.cpp
gm/imagefilterscropexpand.cpp
gm/imagefiltersscaled.cpp
gm/imagefilterstransformed.cpp
gm/imagefromyuvtextures.cpp
gm/imagetoyuvplanes.cpp
gm/lcdblendmodes.cpp
gm/lumafilter.cpp
gm/matrixconvolution.cpp
gm/modecolorfilters.cpp
gm/ovals.cpp
gm/patch.cpp
gm/perspshaders.cpp
gm/pictureimagegenerator.cpp
gm/pictureshader.cpp
gm/pictureshadertile.cpp
gm/rectangletexture.cpp
gm/rects.cpp
gm/roundrects.cpp
gm/samplerstress.cpp
gm/shaderbounds.cpp
gm/shadertext.cpp
gm/shadertext2.cpp
gm/shadertext3.cpp
gm/shadows.cpp
gm/shallowgradient.cpp
gm/skbug_257.cpp
gm/srcmode.cpp
gm/surface.cpp
gm/tablecolorfilter.cpp
gm/textbloblooper.cpp
gm/textblobshader.cpp
gm/texturedomaineffect.cpp
gm/tiledscaledbitmap.cpp
gm/tilemodes.cpp
gm/tilemodes_scaled.cpp
gm/tinybitmap.cpp
gm/transparency.cpp
gm/vertices.cpp
gm/verylargebitmap.cpp
gm/xfermodes.cpp
gm/xfermodes2.cpp
gm/xfermodes3.cpp
tests/BitmapHeapTest.cpp
tests/BlitRowTest.cpp
tests/CanvasTest.cpp
tests/DrawBitmapRectTest.cpp
tests/GradientTest.cpp
tests/ImageFilterTest.cpp
tests/PaintImageFilterTest.cpp
tests/PictureShaderTest.cpp
tests/PictureTest.cpp
tests/RecorderTest.cpp
tests/ShaderOpacityTest.cpp

index 8ef5fc92292ccc4ad8915b2d4276a81d90e4f85e..3fca7f276c8896f64adfd74c4dbfe1f587ad67a4 100644 (file)
@@ -35,27 +35,22 @@ static const GradData gGradData[] = {
     //  { 2, gCol2, nullptr },
 };
 
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
-    return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+    return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
 }
 
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
-    SkPoint center;
-    center.set(SkScalarAve(pts[0].fX, pts[1].fX),
-               SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
-                                          data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+    const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
+    return SkGradientShader::MakeRadial(pt, pt.fX, data.fColors, data.fPos, data.fCount, tm);
 }
 
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
-    SkPoint center;
-    center.set(SkScalarAve(pts[0].fX, pts[1].fX),
-               SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
+    const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
+    return SkGradientShader::MakeSweep(pt.fX, pt.fY, data.fColors, data.fPos, data.fCount);
 }
 
 
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkShader::TileMode);
 
 static const GradMaker gGradMakers[] = {
     MakeLinear, MakeRadial, MakeSweep,
@@ -86,8 +81,7 @@ protected:
         for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
             canvas->save();
             for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
-                SkShader* shader = gGradMakers[j](pts, gGradData[i], tm);
-                paint.setShader(shader)->unref();
+                paint.setShader(gGradMakers[j](pts, gGradData[i], tm));
                 canvas->drawRect(r, paint);
                 canvas->translate(0, SkIntToScalar(120));
             }
index 8f665a1b945eb0db671f44840a92d6b27734a0b7..816891847ddf4a521898028a27b89c9349bc74a3 100644 (file)
@@ -61,22 +61,22 @@ static const SkScalar TESTGRID_Y = SkIntToScalar(200);
 
 static const int IMAGES_X = 4;             // number of images per row
 
-static SkShader* make_linear_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
-    return SkGradientShader::CreateLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gColors),
-                                          SkShader::kClamp_TileMode, 0, &localMatrix);
+static sk_sp<SkShader> make_linear_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
+    return SkGradientShader::MakeLinear(pts, gColors, nullptr, SK_ARRAY_COUNT(gColors),
+                                        SkShader::kClamp_TileMode, 0, &localMatrix);
 }
 
-static SkShader* make_radial_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
+static sk_sp<SkShader> make_radial_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
     float radius = (center - pts[0]).length();
-    return SkGradientShader::CreateRadial(center, radius, gColors, nullptr, SK_ARRAY_COUNT(gColors),
-                                          SkShader::kClamp_TileMode, 0, &localMatrix);
+    return SkGradientShader::MakeRadial(center, radius, gColors, nullptr, SK_ARRAY_COUNT(gColors),
+                                        SkShader::kClamp_TileMode, 0, &localMatrix);
 }
 
 static void draw_gradients(SkCanvas* canvas,
-                           SkShader* (*makeShader)(const SkPoint[2], const SkMatrix&),
+                           sk_sp<SkShader> (*makeShader)(const SkPoint[2], const SkMatrix&),
                            const SkPoint ptsArray[][2], int numImages) {
     // Use some nice prime numbers for the rectangle and matrix with
     // different scaling along the x and y axes (which is the bug this
@@ -97,11 +97,8 @@ static void draw_gradients(SkCanvas* canvas,
             canvas->save();
         }
 
-        // Setup shader and draw.
-        SkAutoTUnref<SkShader> shader(makeShader(*ptsArray, shaderMat));
-
         SkPaint paint;
-        paint.setShader(shader);
+        paint.setShader(makeShader(*ptsArray, shaderMat));
         canvas->drawRect(rectGrad, paint);
 
         // Advance to next position.
index eeb5bcb9ff86ccba7e8116b6e501667b12bff702..29d0f31e960fe54a52c38738f6d3d6ae502269e1 100644 (file)
@@ -40,59 +40,57 @@ static const GradData gGradData[] = {
     { 4, gColorClamp, gPosClamp }
 };
 
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
-                            SkShader::TileMode tm, const SkMatrix& localMatrix) {
-    return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
-                                          data.fCount, tm, 0, &localMatrix);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data,
+                                  SkShader::TileMode tm, const SkMatrix& localMatrix) {
+    return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm, 0,
+                                        &localMatrix);
 }
 
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
-                            SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data,
+                                  SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
-                                          data.fPos, data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount,
+                                        tm, 0, &localMatrix);
 }
 
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
-                           SkShader::TileMode, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data,
+                                 SkShader::TileMode, const SkMatrix& localMatrix) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
-                                         data.fPos, data.fCount, 0, &localMatrix);
+    return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount,
+                                       0, &localMatrix);
 }
 
-static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2Radial(const SkPoint pts[2], const GradData& data,
+                                   SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(
-                                                   center1, (pts[1].fX - pts[0].fX) / 7,
-                                                   center0, (pts[1].fX - pts[0].fX) / 2,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
+                                                 center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data,
                              SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
     center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
-    return SkGradientShader::CreateTwoPointConical(center1, radius1,
-                                                   center0, radius0,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0,
+                                                 data.fColors, data.fPos,
+                                                 data.fCount, tm, 0, &localMatrix);
 }
 
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
-                               SkShader::TileMode tm, const SkMatrix& localMatrix);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
+                                     SkShader::TileMode tm, const SkMatrix& localMatrix);
 static const GradMaker gGradMakers[] = {
     MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical
 };
@@ -136,11 +134,8 @@ protected:
                     scale.postTranslate(25.f, 25.f);
                 }
 
-                SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, scale);
-
-                paint.setShader(shader);
+                paint.setShader(gGradMakers[j](pts, gGradData[i], tm, scale));
                 canvas->drawRect(r, paint);
-                shader->unref();
                 canvas->translate(0, SkIntToScalar(120));
             }
             canvas->restore();
@@ -196,11 +191,8 @@ protected:
                 perspective.setPerspY(SkIntToScalar(i+1) / 500);
                 perspective.setSkewX(SkIntToScalar(i+1) / 10);
 
-                SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspective);
-
-                paint.setShader(shader);
+                paint.setShader(gGradMakers[j](pts, gGradData[i], tm, perspective));
                 canvas->drawRect(r, paint);
-                shader->unref();
                 canvas->translate(0, SkIntToScalar(120));
             }
             canvas->restore();
@@ -287,12 +279,11 @@ protected:
         SkPoint c1;
         c1.iset(0, 25);
         SkScalar r1 = SkIntToScalar(150);
-        SkShader* s = SkGradientShader::CreateTwoPointConical(c0, r0, c1, r1, colors,
-                                                              pos, SK_ARRAY_COUNT(pos),
-                                                              SkShader::kClamp_TileMode);
         SkPaint paint;
+        paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors,
+                                                              pos, SK_ARRAY_COUNT(pos),
+                                                              SkShader::kClamp_TileMode));
         paint.setDither(fDither);
-        paint.setShader(s)->unref();
         canvas->drawPaint(paint);
     }
 
@@ -329,13 +320,13 @@ DEF_SIMPLE_GM(small_color_stop, canvas, 100, 150) {
     SkScalar r0 = 20;
     SkPoint c1 = { 200, 25 };
     SkScalar r1 = 10;
-    SkShader* s = SkGradientShader::CreateTwoPointConical(c0, r0, c1, r1, colors,
-                                                          pos, SK_ARRAY_COUNT(pos),
-                                                          SkShader::kClamp_TileMode);
+
     SkPaint paint;
     paint.setColor(SK_ColorYELLOW);
     canvas->drawRect(SkRect::MakeWH(100, 150), paint);
-    paint.setShader(s)->unref();
+    paint.setShader(SkGradientShader::MakeTwoPointConical(c0, r0, c1, r1, colors, pos,
+                                                          SK_ARRAY_COUNT(pos),
+                                                          SkShader::kClamp_TileMode));
     canvas->drawRect(SkRect::MakeWH(100, 150), paint);
 }
 
@@ -368,13 +359,11 @@ protected:
         SkPoint center;
         center.iset(0, 300);
         canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
-        SkShader* shader = SkGradientShader::CreateRadial(
+        paint.setShader(SkGradientShader::MakeRadial(
             SkPoint(center),
             SkIntToScalar(200), gColors, nullptr, 5,
-            SkShader::kClamp_TileMode);
-        paint.setShader(shader);
+            SkShader::kClamp_TileMode));
         canvas->drawRect(r, paint);
-        shader->unref();
     }
 
 private:
@@ -413,11 +402,9 @@ protected:
         const SkScalar pos[] = { 0.0f,
                              0.35f,
                              1.0f };
-        SkShader* shader =
-            SkGradientShader::CreateRadial(center, radius, colors,
-                                           pos, SK_ARRAY_COUNT(pos),
-                                           SkShader::kClamp_TileMode);
-        paint.setShader(shader)->unref();
+        paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, pos,
+                                                     SK_ARRAY_COUNT(pos),
+                                                     SkShader::kClamp_TileMode));
         SkRect r = {
             0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height())
         };
@@ -464,25 +451,19 @@ protected:
         const uint32_t flags[] = { 0, SkGradientShader::kInterpolateColorsInPremul_Flag };
 
         for (size_t i = 0; i < SK_ARRAY_COUNT(flags); i++) {
-            SkAutoTUnref<SkShader> sweep(
-                    SkGradientShader::CreateSweep(cx, cy, sweep_colors,
-                                                  nullptr, SK_ARRAY_COUNT(sweep_colors),
-                                                  flags[i], nullptr));
-            SkAutoTUnref<SkShader> radial1(
-                    SkGradientShader::CreateRadial(center, radius, colors1,
-                                                   nullptr, SK_ARRAY_COUNT(colors1),
-                                                   SkShader::kClamp_TileMode,
-                                                   flags[i], nullptr));
-            SkAutoTUnref<SkShader> radial2(
-                    SkGradientShader::CreateRadial(center, radius, colors2,
-                                                   nullptr, SK_ARRAY_COUNT(colors2),
-                                                   SkShader::kClamp_TileMode,
-                                                   flags[i], nullptr));
-            paint1.setShader(sweep);
+            paint1.setShader(SkGradientShader::MakeSweep(cx, cy, sweep_colors,
+                                                         nullptr, SK_ARRAY_COUNT(sweep_colors),
+                                                         flags[i], nullptr));
+            paint2.setShader(SkGradientShader::MakeRadial(center, radius, colors1,
+                                                          nullptr, SK_ARRAY_COUNT(colors1),
+                                                          SkShader::kClamp_TileMode,
+                                                          flags[i], nullptr));
+            paint3.setShader(SkGradientShader::MakeRadial(center, radius, colors2,
+                                                          nullptr, SK_ARRAY_COUNT(colors2),
+                                                          SkShader::kClamp_TileMode,
+                                                          flags[i], nullptr));
             paint1.setDither(fDither);
-            paint2.setShader(radial1);
             paint2.setDither(fDither);
-            paint3.setShader(radial2);
             paint3.setDither(fDither);
 
             canvas->drawCircle(cx, cy, radius, paint1);
@@ -519,8 +500,8 @@ protected:
         const SkPoint center = { 0, 0 };
         const SkScalar kRadius = 3000;
         const SkColor gColors[] = { 0xFFFFFFFF, 0xFF000000 };
-        fShader.reset(SkGradientShader::CreateRadial(center, kRadius, gColors, nullptr, 2,
-                                                     SkShader::kClamp_TileMode));
+        fShader = SkGradientShader::MakeRadial(center, kRadius, gColors, nullptr, 2,
+                                               SkShader::kClamp_TileMode);
     }
 
     void onDraw(SkCanvas* canvas) override {
@@ -531,7 +512,7 @@ protected:
     }
     
 private:
-    SkAutoTUnref<SkShader> fShader;
+    sk_sp<SkShader> fShader;
     bool fDither;
 
     typedef GM INHERITED;
@@ -556,8 +537,8 @@ protected:
         const SkColor colors[] = { SK_ColorRED, SK_ColorRED, SK_ColorWHITE, SK_ColorWHITE,
                 SK_ColorRED };
         const SkScalar pos[] = { 0, .4f, .4f, .8f, .8f, 1 };
-        fShader.reset(SkGradientShader::CreateRadial(center, kRadius, colors, pos, 
-                SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode));
+        fShader = SkGradientShader::MakeRadial(center, kRadius, colors, pos,
+                                               SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode);
     }
 
     void onDraw(SkCanvas* canvas) override {
@@ -569,7 +550,7 @@ protected:
     }
     
 private:
-    SkAutoTUnref<SkShader> fShader;
+    sk_sp<SkShader> fShader;
     bool fDither;
 
     typedef GM INHERITED;
@@ -604,8 +585,8 @@ protected:
             for (int inner = 0; inner < (int) SK_ARRAY_COUNT(unitPos); ++inner) {
                 pos[inner] = unitPos[inner] / (kMinWidth + index * kWidthBump);
             }
-            fShader[index].reset(SkGradientShader::CreateLinear(pts, colors, pos, 
-                    SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode));
+            fShader[index] = SkGradientShader::MakeLinear(pts, colors, pos,
+                    SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode);
         }
     }
 
@@ -621,7 +602,7 @@ protected:
     }
     
 private:
-    SkAutoTUnref<SkShader> fShader[100];
+    sk_sp<SkShader> fShader[100];
     bool fDither;
 
     typedef GM INHERITED;
@@ -673,13 +654,12 @@ protected:
         SkPaint paint;
         for (unsigned i = 0; i < SK_ARRAY_COUNT(configs); ++i) {
             SkAutoCanvasRestore acr(canvas, true);
-            SkAutoTUnref<SkShader> gradient(
-                SkGradientShader::CreateLinear(configs[i].pts, colors, configs[i].pos, kStopCount,
-                                               SkShader::kClamp_TileMode, fFlags, nullptr));
+            paint.setShader(SkGradientShader::MakeLinear(configs[i].pts, colors, configs[i].pos,
+                                                         kStopCount, SkShader::kClamp_TileMode,
+                                                         fFlags, nullptr));
             canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f),
                               kRectSize * ((i / 4) * 1.5f + 0.25f));
 
-            paint.setShader(gradient);
             canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint);
         }
     }
@@ -704,27 +684,27 @@ struct GradRun {
 
 #define SIZE 121
 
-static SkShader* make_linear(const GradRun& run, SkShader::TileMode mode) {
+static sk_sp<SkShader> make_linear(const GradRun& run, SkShader::TileMode mode) {
     const SkPoint pts[] { { 30, 30 }, { SIZE - 30, SIZE - 30 } };
-    return SkGradientShader::CreateLinear(pts, run.fColors, run.fPos, run.fCount, mode);
+    return SkGradientShader::MakeLinear(pts, run.fColors, run.fPos, run.fCount, mode);
 }
 
-static SkShader* make_radial(const GradRun& run, SkShader::TileMode mode) {
+static sk_sp<SkShader> make_radial(const GradRun& run, SkShader::TileMode mode) {
     const SkScalar half = SIZE * 0.5f;
-    return SkGradientShader::CreateRadial({half,half}, half - 10,
-                                          run.fColors, run.fPos, run.fCount, mode);
+    return SkGradientShader::MakeRadial({half,half}, half - 10, run.fColors, run.fPos,
+                                        run.fCount, mode);
 }
 
-static SkShader* make_conical(const GradRun& run, SkShader::TileMode mode) {
+static sk_sp<SkShader> make_conical(const GradRun& run, SkShader::TileMode mode) {
     const SkScalar half = SIZE * 0.5f;
     const SkPoint center { half, half };
-    return SkGradientShader::CreateTwoPointConical(center, 20, center, half - 10,
-                                          run.fColors, run.fPos, run.fCount, mode);
+    return SkGradientShader::MakeTwoPointConical(center, 20, center, half - 10,
+                                                 run.fColors, run.fPos, run.fCount, mode);
 }
 
-static SkShader* make_sweep(const GradRun& run, SkShader::TileMode) {
+static sk_sp<SkShader> make_sweep(const GradRun& run, SkShader::TileMode) {
     const SkScalar half = SIZE * 0.5f;
-    return SkGradientShader::CreateSweep(half, half, run.fColors, run.fPos, run.fCount);
+    return SkGradientShader::MakeSweep(half, half, run.fColors, run.fPos, run.fCount);
 }
 
 /*
@@ -762,7 +742,7 @@ DEF_SIMPLE_GM(gradients_dup_color_stops, canvas, 704, 564) {
             4,
         },
     };
-    SkShader* (*factories[])(const GradRun&, SkShader::TileMode) {
+    sk_sp<SkShader> (*factories[])(const GradRun&, SkShader::TileMode) {
         make_linear, make_radial, make_conical, make_sweep
     };
 
@@ -777,7 +757,7 @@ DEF_SIMPLE_GM(gradients_dup_color_stops, canvas, 704, 564) {
         canvas->translate(0, dy);
         SkAutoCanvasRestore acr(canvas, true);
         for (const auto& run : runs) {
-            paint.setShader(factory(run, mode))->unref();
+            paint.setShader(factory(run, mode));
             canvas->drawRect(rect, paint);
             canvas->translate(dx, 0);
         }
@@ -799,11 +779,9 @@ static void draw_many_stops(SkCanvas* canvas, uint32_t flags) {
         }
     }
 
-    SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(
-        pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, flags, nullptr));
-
     SkPaint p;
-    p.setShader(shader);
+    p.setShader(SkGradientShader::MakeLinear(
+        pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, flags, nullptr));
 
     canvas->drawRect(SkRect::MakeXYWH(0, 0, 500, 500), p);
 }
index 39ebb4a1f9ec540d19639e8a3d605486db360638..28ed8bb965ea6ad4f53a29f9ffb1ef19c035bed2 100644 (file)
@@ -37,235 +37,218 @@ static const GradData gGradData[] = {
     { 4, gColorClamp, gPosClamp }
 };
 
-static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
-                                     SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
+                                           SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
     center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
                              SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
     center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
-    return SkGradientShader::CreateTwoPointConical(center1, radius1,
-                                                   center0, radius0,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalInside(const SkPoint pts[2], const GradData& data,
+                                          SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
-                                                   center0, (pts[1].fX - pts[0].fX) / 2,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
+                                                 center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
+                                              SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
-                                                   center1, (pts[1].fX - pts[0].fX) / 7,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 center1, (pts[1].fX - pts[0].fX) / 7,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
                              SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
-                                                   center0, (pts[1].fX - pts[0].fX) / 2,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
+                                                 center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
+                                           SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center1, 0.f,
-                                                   center0, (pts[1].fX - pts[0].fX) / 2,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, 0.f,
+                                                 center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
+                                               SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
-                                                   center0, 0.f,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
+                                                 center0, 0.f,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
                              SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center0, 0.f,
-                                                   center0, (pts[1].fX - pts[0].fX) / 2,
-                                                   data.fColors, data.fPos, data.fCount, tm,
-                                                   0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, 0.f, center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 data.fColors, data.fPos, data.fCount, tm,
+                                                 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
+                                                  SkShader::TileMode tm,
+                                                  const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = 0.f;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
     center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1,
+                                                 data.fColors, data.fPos,
+                                                 data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
+                                                      SkShader::TileMode tm,
+                                                      const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = 0.f;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
     center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
-    return SkGradientShader::CreateTwoPointConical(center1, radius1,
-                                                   center0, radius0,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center1, radius1, center0, radius0, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
+                                         SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center0.set(center1.fX + radius1, center1.fY);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
+                                         SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center0.set(center1.fX, center1.fY + radius1);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
+                                                SkShader::TileMode tm,
+                                                const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = 0.f;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center0.set(center1.fX + radius1, center1.fY);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
+                                                SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = 0.f;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center0.set(center1.fX, center1.fY + radius1);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
+                                          SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center0.set(center1.fX - radius1 + radius0, center1.fY);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
-                             SkShader::TileMode tm, const SkMatrix& localMatrix) {
+static sk_sp<SkShader> Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
+                                          SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 7;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center0.set(center1.fX, center1.fY + radius1 - radius0);
-    return SkGradientShader::CreateTwoPointConical(center0, radius0,
-                                                   center1, radius1,
-                                                   data.fColors, data.fPos,
-                                                   data.fCount, tm, 0, &localMatrix);
+    return SkGradientShader::MakeTwoPointConical(center0, radius0, center1, radius1, data.fColors,
+                                                 data.fPos, data.fCount, tm, 0, &localMatrix);
 }
 
-static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
+static sk_sp<SkShader> Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
                              SkShader::TileMode tm, const SkMatrix& localMatrix) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(center0, 0.0000000000000000001f,
+    return SkGradientShader::MakeTwoPointConical(center0, 0.0000000000000000001f,
                                                    center0, (pts[1].fX - pts[0].fX) / 2,
                                                    data.fColors, data.fPos, data.fCount, tm,
                                                    0, &localMatrix);
 }
 
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
-                               SkShader::TileMode tm, const SkMatrix& localMatrix);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
+                                     SkShader::TileMode tm, const SkMatrix& localMatrix);
 
 static const GradMaker gGradMakersOutside[] = {
     Make2ConicalOutside, Make2ConicalOutsideFlip,
@@ -347,10 +330,8 @@ protected:
                     scale.postTranslate(25.f, 25.f);
                 }
 
-                SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale);
-                paint.setShader(shader);
+                paint.setShader(gradMaker[j](pts, gGradData[i], tm, scale));
                 canvas->drawRect(r, paint);
-                shader->unref();
                 canvas->translate(0, SkIntToScalar(120));
             }
             canvas->restore();
index 00c865c1781186117ded3b83db6a339f8df5722d..b688aab4cb5c326158e4763191dd9e24db499b09 100644 (file)
@@ -26,51 +26,50 @@ static const GradData gGradData[] = {
     { 4, gColors, nullptr },
 };
 
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
-    return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+    return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
 }
 
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
-                                          data.fPos, data.fCount, tm);
+    return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount, tm);
 }
 
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
+    return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
 }
 
-static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(
+    return SkGradientShader::MakeTwoPointConical(
         center1, (pts[1].fX - pts[0].fX) / 7,
         center0, (pts[1].fX - pts[0].fX) / 2,
         data.fColors, data.fPos, data.fCount, tm);
 }
 
-static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
     SkPoint center0, center1;
     SkScalar radius0 = (pts[1].fX - pts[0].fX) / 10;
     SkScalar radius1 = (pts[1].fX - pts[0].fX) / 3;
     center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
     center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
-    return SkGradientShader::CreateTwoPointConical(center1, radius1,
+    return SkGradientShader::MakeTwoPointConical(center1, radius1,
                                                    center0, radius0,
                                                    data.fColors, data.fPos,
                                                    data.fCount, tm);
 }
 
 
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
 
 static const GradMaker gGradMakers[] = {
     MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical,
@@ -107,8 +106,7 @@ protected:
             for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) {
                 canvas->save();
                 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) {
-                    SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM);
-                    paint.setShader(shader)->unref();
+                    paint.setShader(gGradMakers[j](kPts, gGradData[i], kTM));
                     paint.setAlpha(kAlphas[a]);
                     canvas->drawRect(kRect, paint);
                     canvas->translate(0, SkIntToScalar(kRect.height() + 20));
@@ -256,9 +254,8 @@ protected:
         for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
             ColorPos rec;
             procs[i](&rec);
-            SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.fPos, rec.fCount,
-                                                         SkShader::kClamp_TileMode);
-            paint.setShader(s)->unref();
+            paint.setShader(SkGradientShader::MakeLinear(pts, rec.fColors, rec.fPos, rec.fCount,
+                                                         SkShader::kClamp_TileMode));
             canvas->drawRect(drawR, paint);
 
             canvas->save();
index acb88d6e52a3676e192eaf37ddbe49c3e2b7a8de..d66454760bdd13b9a031dd592852931dc66eb44e 100644 (file)
 #include "SkTypeface.h"
 
 // test shader w/ transparency
-static SkShader* make_grad(SkScalar width) {
+static sk_sp<SkShader> make_grad(SkScalar width) {
     SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE };
     SkPoint pts[] = { { 0, 0 }, { width, 0 } };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr,
-                                          SK_ARRAY_COUNT(colors),
-                                          SkShader::kMirror_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kMirror_TileMode);
 }
 
 // test opaque shader
-static SkShader* make_grad2(SkScalar width) {
+static sk_sp<SkShader> make_grad2(SkScalar width) {
     SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
     SkPoint pts[] = { { 0, 0 }, { width, 0 } };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr,
-                                          SK_ARRAY_COUNT(colors),
-                                          SkShader::kMirror_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kMirror_TileMode);
 }
 
-static SkShader* make_chrome_solid() {
+static sk_sp<SkShader> make_chrome_solid() {
     SkColor colors[] = { SK_ColorGREEN, SK_ColorGREEN };
     SkPoint pts[] = { { 0, 0 }, { 1, 0 } };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
-                                          SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 }
 
 namespace skiagm {
@@ -56,7 +53,7 @@ protected:
         canvas->drawRect(r, paint);
 
         // Minimal repro doesn't require AA, LCD, or a nondefault typeface
-        paint.setShader(make_chrome_solid())->unref();
+        paint.setShader(make_chrome_solid());
         paint.setTextSize(SkIntToScalar(500));
 
         canvas->drawText("I", 1, 0, 100, paint);
@@ -84,7 +81,7 @@ protected:
         canvas->drawText("Normal Stroke Text", 18, 0, 100, paint);
 
         // Minimal repro doesn't require AA, LCD, or a nondefault typeface
-        paint.setShader(make_chrome_solid())->unref();
+        paint.setShader(make_chrome_solid());
 
         paint.setStyle(SkPaint::kFill_Style);
         canvas->drawText("Gradient Fill Text", 18, 0, 150, paint);
@@ -140,12 +137,12 @@ protected:
         canvas->translate(SkIntToScalar(20), paint.getTextSize());
 
         for (int i = 0; i < 2; ++i) {
-            paint.setShader(make_grad(SkIntToScalar(80)))->unref();
+            paint.setShader(make_grad(SkIntToScalar(80)));
             draw_text3(canvas, paint);
 
             canvas->translate(0, paint.getTextSize() * 2);
 
-            paint.setShader(make_grad2(SkIntToScalar(80)))->unref();
+            paint.setShader(make_grad2(SkIntToScalar(80)));
             draw_text3(canvas, paint);
 
             canvas->translate(0, paint.getTextSize() * 2);
index 4f85c198836d5d3c607c63799b109d30c27e5df6..15e75fe847fa5a74c278857ec732ca6d1f6dfc3a 100644 (file)
@@ -58,7 +58,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode, SkAlpha a0, SkAlpha
     return H;
 }
 
-static SkShader* make_bg_shader() {
+static sk_sp<SkShader> make_bg_shader() {
     SkBitmap bm;
     bm.allocN32Pixels(2, 2);
     *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
@@ -66,10 +66,8 @@ static SkShader* make_bg_shader() {
 
     SkMatrix m;
     m.setScale(SkIntToScalar(6), SkIntToScalar(6));
-    return SkShader::CreateBitmapShader(bm,
-                                        SkShader::kRepeat_TileMode,
-                                        SkShader::kRepeat_TileMode,
-                                        &m);
+    return SkShader::MakeBitmapShader(bm,
+                                      SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &m);
 }
 
 namespace skiagm {
@@ -85,7 +83,7 @@ namespace skiagm {
         virtual SkISize onISize() override { return SkISize::Make(640, 480); }
 
         void onOnceBeforeDraw() override {
-            fBGPaint.setShader(make_bg_shader())->unref();
+            fBGPaint.setShader(make_bg_shader());
         }
 
         void onDraw(SkCanvas* canvas) override {
index f5c9cefbb2866e1cc9a6ef0c95176ca8c07ebfe4..033b80638f63a72b8ebd4a7f4856759ad2287f1e 100644 (file)
@@ -53,12 +53,9 @@ protected:
         SkColor colors[2];
         colors[0] = SK_ColorWHITE;
         colors[1] = SK_ColorBLACK;
-        SkAutoTUnref<SkShader> shader(
-            SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
-                                           SkShader::kClamp_TileMode)
-        );
         SkPaint paint;
-        paint.setShader(shader);
+        paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+                                                     2, SkShader::kClamp_TileMode));
         canvas->drawCircle(x, y, radius, paint);
         fGradientCircle.reset(surface->newImageSnapshot());
     }
index 9ceab2036a6e667ec282e8dc68eebb2b226eab00..185bbde0a6628c7103a73b1c8fe9426f8303a51d 100644 (file)
@@ -151,12 +151,9 @@ private:
         SkColor colors[2];
         colors[0] = SK_ColorWHITE;
         colors[1] = SK_ColorBLACK;
-        SkAutoTUnref<SkShader> shader(
-            SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
-                                           SkShader::kClamp_TileMode)
-        );
         SkPaint paint;
-        paint.setShader(shader);
+        paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+                                                     2, SkShader::kClamp_TileMode));
         canvas->drawCircle(x, y, radius, paint);
 
         return surface->newImageSnapshot();
index 7576ee1375edc213f5dc5372d906725b3d0c7f7f..da4467882bccc773b2a2820051ca642c6231367b 100644 (file)
@@ -145,12 +145,9 @@ private:
         SkColor colors[2];
         colors[0] = SK_ColorWHITE;
         colors[1] = SK_ColorBLACK;
-        SkAutoTUnref<SkShader> shader(
-            SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
-                                           SkShader::kClamp_TileMode)
-        );
         SkPaint paint;
-        paint.setShader(shader);
+        paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
+                                                     2, SkShader::kClamp_TileMode));
         canvas->drawCircle(x, y, radius, paint);
 
         return surface->newImageSnapshot();
index 8e59b9242c4b0545bc1133c3a1698cf7130cd4cd..5b9d702efb0f9e40049c9c1294c2c06fc9bd6138 100644 (file)
@@ -36,12 +36,9 @@ static SkImage* make_gradient_circle(int width, int height) {
     SkColor colors[2];
     colors[0] = SK_ColorWHITE;
     colors[1] = SK_ColorBLACK;
-    SkAutoTUnref<SkShader> shader(
-        SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
-                                       SkShader::kClamp_TileMode)
-    );
     SkPaint paint;
-    paint.setShader(shader);
+    paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
+                                                 SkShader::kClamp_TileMode));
     canvas->drawCircle(x, y, radius, paint);
 
     return surface->newImageSnapshot();
index c53df295cd0c6ba843347de382fbea49758524b2..6280ae740b98442c8100098e0da1772d2625f00d 100644 (file)
@@ -40,9 +40,9 @@ protected:
         SkPaint paint;
         static const SkColor kColors[] =
             { SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE };
-        paint.setShader(SkGradientShader::CreateRadial(SkPoint::Make(0,0), kBmpSize / 2.f, kColors,
-                                                       nullptr, SK_ARRAY_COUNT(kColors),
-                                                       SkShader::kMirror_TileMode))->unref();
+        paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), kBmpSize / 2.f, kColors,
+                                                     nullptr, SK_ARRAY_COUNT(kColors),
+                                                     SkShader::kMirror_TileMode));
         SkBitmap rgbBmp;
         rgbBmp.allocN32Pixels(kBmpSize, kBmpSize, true);
         SkCanvas canvas(rgbBmp);
index 09b3dbb98b92240a43989a91f9eabcab40b4a78a..87bff8ee64948c241d3737aa927db62c0224d41e 100644 (file)
@@ -28,9 +28,9 @@ static SkImage* create_image(GrContext* context, int width, int height) {
     static const SkColor kColors[] =
             { SK_ColorBLUE, SK_ColorYELLOW, SK_ColorGREEN, SK_ColorWHITE };
     SkScalar r = (width + height) / 4.f;
-    paint.setShader(SkGradientShader::CreateRadial(SkPoint::Make(0,0), r, kColors,
-                                                   nullptr, SK_ARRAY_COUNT(kColors),
-                                                   SkShader::kMirror_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(0,0), r, kColors,
+                                                 nullptr, SK_ARRAY_COUNT(kColors),
+                                                 SkShader::kMirror_TileMode));
 
     surface->getCanvas()->drawPaint(paint);
     return surface->newImageSnapshot();
index d7a9024204bffbbfeea4abbe3269a6e51623fbb2..c3fe9ff1493f39add95bdeaa719f15064a32abb2 100644 (file)
@@ -22,7 +22,7 @@ static const int kNumCols = 4;
 static const int kWidth = kColWidth * kNumCols;
 static const int kHeight = 750;
 
-static SkShader* make_shader(const SkRect& bounds) {
+static sk_sp<SkShader> make_shader(const SkRect& bounds) {
     const SkPoint pts[] = {
         { bounds.left(), bounds.top() },
         { bounds.right(), bounds.bottom() },
@@ -30,9 +30,8 @@ static SkShader* make_shader(const SkRect& bounds) {
     const SkColor colors[] = {
         SK_ColorRED, SK_ColorGREEN,
     };
-    return SkGradientShader::CreateLinear(pts,
-                                          colors, nullptr, SK_ARRAY_COUNT(colors),
-                                          SkShader::kRepeat_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kRepeat_TileMode);
 }
 
 class LcdBlendGM : public skiagm::GM {
@@ -136,7 +135,7 @@ protected:
             if (useGrad) {
                 SkRect r;
                 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHeight);
-                paint.setShader(make_shader(r))->unref();
+                paint.setShader(make_shader(r));
             }
             SkString string(gModes[m].fLabel);
             canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint);
index 3244b2b055628f7fe3497d17a6fae87ab37d6e0a..adffd008c10bbe571d495d007e3ce827d8c95b61 100644 (file)
@@ -26,9 +26,8 @@ static void draw_label(SkCanvas* canvas, const char* label,
                      paint);
 }
 
-static void draw_scene(SkCanvas* canvas, SkColorFilter* filter,
-                       SkXfermode::Mode mode, SkShader* s1,
-                       SkShader* s2) {
+static void draw_scene(SkCanvas* canvas, SkColorFilter* filter, SkXfermode::Mode mode,
+                       const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) {
     SkPaint paint;
     paint.setAntiAlias(true);
     SkRect r, c, bounds = SkRect::MakeWH(kSize, kSize);
@@ -85,16 +84,10 @@ public:
         SkScalar pos[] = { 0.2f, 1.0f };
 
         fFilter.reset(SkLumaColorFilter::Create());
-        fGr1.reset(SkGradientShader::CreateLinear(g1Points,
-                                                  g1Colors,
-                                                  pos,
-                                                  SK_ARRAY_COUNT(g1Colors),
-                                                  SkShader::kClamp_TileMode));
-        fGr2.reset(SkGradientShader::CreateLinear(g2Points,
-                                                  g2Colors,
-                                                  pos,
-                                                  SK_ARRAY_COUNT(g2Colors),
-                                                  SkShader::kClamp_TileMode));
+        fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors),
+                                            SkShader::kClamp_TileMode);
+        fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_COUNT(g2Colors),
+                                            SkShader::kClamp_TileMode);
     }
 
 protected:
@@ -116,8 +109,8 @@ protected:
                                      SkXfermode::kDstIn_Mode,
                                    };
         struct {
-            SkShader*   fShader1;
-            SkShader*   fShader2;
+            const sk_sp<SkShader>& fShader1;
+            const sk_sp<SkShader>& fShader2;
         } shaders[] = {
             { nullptr, nullptr },
             { nullptr, fGr2 },
@@ -145,7 +138,7 @@ protected:
 
 private:
     SkAutoTUnref<SkColorFilter> fFilter;
-    SkAutoTUnref<SkShader>      fGr1, fGr2;
+    sk_sp<SkShader>             fGr1, fGr2;
 
     typedef skiagm::GM INHERITED;
 };
index 3b159f455bd084df5255f3b4dcff62ad01d46030..b02f743f2933321cc38f27bb7d5dddf68eaa693c 100644 (file)
@@ -37,8 +37,8 @@ protected:
                            SkPoint::Make(0, SkIntToScalar(80)) };
         SkColor colors[2] = { 0xFFFFFFFF, 0x40404040 };
         SkScalar pos[2] = { 0, SkIntToScalar(80) };
-        paint.setShader(SkGradientShader::CreateLinear(
-            pts, colors, pos, 2, SkShader::kClamp_TileMode))->unref();
+        paint.setShader(SkGradientShader::MakeLinear(
+            pts, colors, pos, 2, SkShader::kClamp_TileMode));
         const char* str = "e";
         canvas.drawText(str, strlen(str), SkIntToScalar(-10), SkIntToScalar(80), paint);
     }
index b5ede710f1cc2fd3293d7d93fcb51277bec548fd..de6a18a41c85e2320773743e82ee0d9fa92728b3 100644 (file)
@@ -6,7 +6,6 @@
  */
 
 #include "gm.h"
-#include "SkBitmapProcShader.h"
 #include "SkColorFilter.h"
 #include "SkGradientShader.h"
 
 namespace skiagm {
 
 // Using gradients because GPU doesn't currently have an implementation of SkColorShader (duh!)
-static SkShader* make_color_shader(SkColor color) {
+static sk_sp<SkShader> make_color_shader(SkColor color) {
     static const SkPoint kPts[] = {{0, 0}, {1, 1}};
     SkColor colors[] = {color, color};
 
-    return SkGradientShader::CreateLinear(kPts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(kPts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 }
 
-static SkShader* make_solid_shader() {
+static sk_sp<SkShader> make_solid_shader() {
     return make_color_shader(SkColorSetARGB(0xFF, 0x42, 0x82, 0x21));
 }
 
-static SkShader* make_transparent_shader() {
+static sk_sp<SkShader> make_transparent_shader() {
     return make_color_shader(SkColorSetARGB(0x80, 0x10, 0x70, 0x20));
 }
 
-static SkShader* make_trans_black_shader() {
+static sk_sp<SkShader> make_trans_black_shader() {
     return make_color_shader(0x0);
 }
 
 // draws a background behind each test rect to see transparency
-static SkShader* make_bg_shader(int checkSize) {
+static sk_sp<SkShader> make_bg_shader(int checkSize) {
     SkBitmap bmp;
     bmp.allocN32Pixels(2 * checkSize, 2 * checkSize);
     SkCanvas canvas(bmp);
@@ -49,7 +48,7 @@ static SkShader* make_bg_shader(int checkSize) {
                                     SkIntToScalar(checkSize), SkIntToScalar(checkSize));
     canvas.drawRect(rect1, paint);
     canvas.drawRect(rect0, paint);
-    return new SkBitmapProcShader(bmp, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
+    return SkShader::MakeBitmapShader(bmp, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
 }
 
 class ModeColorFilterGM : public GM {
@@ -59,15 +58,15 @@ public:
     }
 
 protected:
-    virtual SkString onShortName() {
+    SkString onShortName() override  {
         return SkString("modecolorfilters");
     }
 
-    virtual SkISize onISize() {
+    SkISize onISize() override  {
         return SkISize::Make(WIDTH, HEIGHT);
     }
 
-    virtual void onDraw(SkCanvas* canvas) {
+    void onDraw(SkCanvas* canvas) override {
         // size of rect for each test case
         static const int kRectWidth  = 20;
         static const int kRectHeight = 20;
@@ -75,13 +74,13 @@ protected:
         static const int kCheckSize  = 10;
 
         if (!fBmpShader) {
-            fBmpShader.reset(make_bg_shader(kCheckSize));
+            fBmpShader = make_bg_shader(kCheckSize);
         }
         SkPaint bgPaint;
         bgPaint.setShader(fBmpShader);
         bgPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
 
-        SkShader* shaders[] = {
+        sk_sp<SkShader> shaders[] = {
             nullptr,                                   // use a paint color instead of a shader
             make_solid_shader(),
             make_transparent_shader(),
@@ -146,14 +145,10 @@ protected:
                 }
             }
         }
-
-        for (size_t i = 0; i < SK_ARRAY_COUNT(shaders); ++i) {
-            SkSafeUnref(shaders[i]);
-        }
     }
 
 private:
-    SkAutoTUnref<SkShader> fBmpShader;
+    sk_sp<SkShader> fBmpShader;
     typedef GM INHERITED;
 };
 
index e4cc46eb210c714dfc3a96cf6f44957c2725c32a..580426b2442c15a2442b37c90dbe1aa12b8da4a6 100755 (executable)
@@ -246,12 +246,8 @@ protected:
         SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
         SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
         SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
-        SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center,
-                                                     SkIntToScalar(20),
-                                                     colors,
-                                                     pos,
-                                                     SK_ARRAY_COUNT(colors),
-                                                     SkShader::kClamp_TileMode));
+        auto shader = SkGradientShader::MakeRadial(center, 20, colors, pos, SK_ARRAY_COUNT(colors),
+                                                   SkShader::kClamp_TileMode);
 
         for (int i = 0; i < fPaints.count(); ++i) {
             canvas->save();
index d9f6d57d6f940f4e232b188ef78073ab9787057c..5b661f4b7c65e910150cadff8d0c43db30a48b89 100644 (file)
 #include "SkGradientShader.h"
 #include "SkPatchUtils.h"
 
-static SkShader* make_shader() {
+static sk_sp<SkShader> make_shader() {
     const SkColor colors[] = {
         SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, SK_ColorMAGENTA, SK_ColorBLUE,
         SK_ColorYELLOW,
     };
     const SkPoint pts[] = { { 100.f / 4.f, 0.f }, { 3.f * 100.f / 4.f, 100.f } };
     
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
-                                          SkShader::kMirror_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kMirror_TileMode);
 }
 
 static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) {
@@ -92,7 +92,7 @@ DEF_SIMPLE_GM(patch_primitive, canvas, 800, 800) {
             SkXfermode::kModulate_Mode,
         };
         
-        SkAutoTUnref<SkShader> shader(make_shader());
+        sk_sp<SkShader> shader(make_shader());
         
         canvas->save();
         for (int y = 0; y < 3; y++) {
index 59fab47fc8ed2d5c66b76d7f3bab373a7f87687f..a29ef52f460305dff7d1f01febf1b0d07c820f27 100644 (file)
@@ -46,9 +46,8 @@ protected:
                                                             SK_ColorBLUE, SK_ColorYELLOW,
                                                             kCellSize/10);
 
-        fBitmapShader.reset(SkShader::CreateBitmapShader(fBitmap,
-                                                         SkShader::kClamp_TileMode,
-                                                         SkShader::kClamp_TileMode));
+        fBitmapShader = SkShader::MakeBitmapShader(fBitmap, SkShader::kClamp_TileMode,
+                                                   SkShader::kClamp_TileMode);
         SkPoint pts1[] = {
             { 0, 0 },
             { SkIntToScalar(kCellSize), SkIntToScalar(kCellSize) }
@@ -62,12 +61,10 @@ protected:
         };
         static const SkScalar pos[] = { 0, 0.25f, 0.5f, 0.75f, SK_Scalar1 };
 
-        fLinearGrad1.reset(SkGradientShader::CreateLinear(pts1, colors, pos,
-                                                          SK_ARRAY_COUNT(colors),
-                                                          SkShader::kClamp_TileMode));
-        fLinearGrad2.reset(SkGradientShader::CreateLinear(pts2, colors, pos,
-                                                          SK_ARRAY_COUNT(colors),
-                                                          SkShader::kClamp_TileMode));
+        fLinearGrad1 = SkGradientShader::MakeLinear(pts1, colors, pos, SK_ARRAY_COUNT(colors),
+                                                    SkShader::kClamp_TileMode);
+        fLinearGrad2 = SkGradientShader::MakeLinear(pts2, colors, pos, SK_ARRAY_COUNT(colors),
+                                                    SkShader::kClamp_TileMode);
 
         fPerspMatrix.reset();
         fPerspMatrix.setPerspY(SK_Scalar1 / 50);
@@ -160,9 +157,9 @@ private:
 
     bool                    fDoAA;
     SkPath                  fPath;
-    SkAutoTUnref<SkShader>  fBitmapShader;
-    SkAutoTUnref<SkShader>  fLinearGrad1;
-    SkAutoTUnref<SkShader>  fLinearGrad2;
+    sk_sp<SkShader>         fBitmapShader;
+    sk_sp<SkShader>         fLinearGrad1;
+    sk_sp<SkShader>         fLinearGrad2;
     SkMatrix                fPerspMatrix;
     SkAutoTUnref<SkImage>   fImage;
     SkBitmap                fBitmap;
index 829006d80876e86759b020b1f90af659a1522edc..2d50f3a6bedde651d0a90c2bcf9930314512cf19 100644 (file)
@@ -68,10 +68,8 @@ static void draw_vector_logo(SkCanvas* canvas, const SkRect& viewBox) {
     const SkScalar pos1[] = { 0, 0.75f };
     const SkColor colors1[] = { SK_ColorTRANSPARENT, SK_ColorBLACK };
     SkASSERT(SK_ARRAY_COUNT(pos1) == SK_ARRAY_COUNT(colors1));
-    SkAutoTUnref<SkShader> gradient1(SkGradientShader::CreateLinear(pts1, colors1, pos1,
-                                                                    SK_ARRAY_COUNT(pos1),
-                                                                    SkShader::kClamp_TileMode));
-    paint.setShader(gradient1.get());
+    paint.setShader(SkGradientShader::MakeLinear(pts1, colors1, pos1, SK_ARRAY_COUNT(pos1),
+                                                 SkShader::kClamp_TileMode));
     canvas->drawRect(underlineRect, paint);
 
     const SkPoint pts2[] = { SkPoint::Make(iBox.x() - iBox.width() * kGradientPad, 0),
@@ -88,10 +86,8 @@ static void draw_vector_logo(SkCanvas* canvas, const SkRect& viewBox) {
         SK_ColorBLACK
     };
     SkASSERT(SK_ARRAY_COUNT(pos2) == SK_ARRAY_COUNT(colors2));
-    SkAutoTUnref<SkShader> gradient2(SkGradientShader::CreateLinear(pts2, colors2, pos2,
-                                                                    SK_ARRAY_COUNT(pos2),
-                                                                    SkShader::kClamp_TileMode));
-    paint.setShader(gradient2.get());
+    paint.setShader(SkGradientShader::MakeLinear(pts2, colors2, pos2, SK_ARRAY_COUNT(pos2),
+                                                 SkShader::kClamp_TileMode));
     canvas->drawText(kSkiaStr, textLen, 0, 0, paint);
 }
 
index c35c5c964edea5199089c231a0ba5b5df9836767..f27c4eda4780317400d0c40d4f82751b2152f77c 100644 (file)
@@ -150,20 +150,17 @@ private:
         canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint);
         canvas->drawRect(SkRect::MakeXYWH(fSceneSize * 1.1f, 0, fSceneSize, fSceneSize), paint);
 
-        SkAutoTUnref<SkShader> pictureShader(
-                SkShader::CreatePictureShader(fPicture, kTileConfigs[tileMode].tmx,
-                                              kTileConfigs[tileMode].tmy, &localMatrix, nullptr));
-        paint.setShader(pictureShader.get());
+        paint.setShader(SkShader::MakePictureShader(fPicture, kTileConfigs[tileMode].tmx,
+                                                    kTileConfigs[tileMode].tmy, &localMatrix,
+                                                    nullptr));
         canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint);
 
         canvas->translate(fSceneSize * 1.1f, 0);
 
-        SkAutoTUnref<SkShader> bitmapShader(SkShader::CreateBitmapShader(
-                    fBitmap,
-                    kTileConfigs[tileMode].tmx,
-                    kTileConfigs[tileMode].tmy,
-                    &localMatrix));
-        paint.setShader(bitmapShader.get());
+        paint.setShader(SkShader::MakeBitmapShader(fBitmap,
+                                                   kTileConfigs[tileMode].tmx,
+                                                   kTileConfigs[tileMode].tmy,
+                                                   &localMatrix));
         canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint);
 
         canvas->restore();
@@ -172,7 +169,7 @@ private:
     SkScalar    fTileSize;
     SkScalar    fSceneSize;
 
-    SkAutoTUnref<SkPicture> fPicture;
+    sk_sp<SkPicture> fPicture;
     SkBitmap fBitmap;
 
     typedef GM INHERITED;
@@ -196,10 +193,10 @@ DEF_SIMPLE_GM(tiled_picture_shader, canvas, 400, 400) {
     p.setStrokeWidth(10);
     c->drawLine(20, 20, 80, 80, p);
 
-    SkAutoTUnref<SkPicture> picture(recorder.endRecording());
-    SkAutoTUnref<SkShader> shader(
-            SkShader::CreatePictureShader(picture.get(), SkShader::kRepeat_TileMode,
-                                          SkShader::kRepeat_TileMode, nullptr, nullptr));
+    sk_sp<SkPicture> picture(recorder.endRecording());
+    sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepeat_TileMode,
+                                                       SkShader::kRepeat_TileMode,
+                                                       nullptr, nullptr));
 
     p.setColor(sk_tool_utils::color_to_565(0xFF8BC34A));  // green
     canvas->drawPaint(p);
index 30776c338b4e1c939808a68437bfa13741609bfe..68e65f87bb99663c361baf0fac0b14215de23776 100644 (file)
@@ -95,14 +95,14 @@ protected:
         SkPictureRecorder recorder;
         SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
         draw_scene(pictureCanvas, kPictureSize);
-        SkAutoTUnref<SkPicture> picture(recorder.endRecording());
+        sk_sp<SkPicture> picture(recorder.endRecording());
 
         SkPoint offset = SkPoint::Make(100, 100);
         pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
                                                                  kPictureSize, kPictureSize));
         pictureCanvas->translate(offset.x(), offset.y());
         draw_scene(pictureCanvas, kPictureSize);
-        SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording());
+        sk_sp<SkPicture> offsetPicture(recorder.endRecording());
 
         for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
             SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
@@ -115,20 +115,18 @@ protected:
             localMatrix.postScale(kFillSize / (2 * kPictureSize),
                                   kFillSize / (2 * kPictureSize));
 
-            SkPicture* picturePtr = picture.get();
+            sk_sp<SkPicture>& pictureRef = picture;
             SkRect* tilePtr = &tile;
 
             if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
                 // When the tile == picture bounds, exercise the picture + offset path.
-                picturePtr = offsetPicture.get();
+                pictureRef = offsetPicture;
                 tilePtr = nullptr;
             }
 
-            fShaders[i].reset(SkShader::CreatePictureShader(picturePtr,
-                                                            SkShader::kRepeat_TileMode,
-                                                            SkShader::kRepeat_TileMode,
-                                                            &localMatrix,
-                                                            tilePtr));
+            fShaders[i] = SkShader::MakePictureShader(pictureRef, SkShader::kRepeat_TileMode,
+                                                      SkShader::kRepeat_TileMode, &localMatrix,
+                                                      tilePtr);
         }
     }
 
@@ -150,7 +148,7 @@ protected:
     }
 
 private:
-    SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
+    sk_sp<SkShader> fShaders[SK_ARRAY_COUNT(tiles)];
 
     typedef GM INHERITED;
 };
index 20f2ead593674d3dfa52b2b006530769e5beb849..4bdb4c9f1193ad38646240557ff0e318b76df16b 100644 (file)
@@ -42,14 +42,14 @@ protected:
         SkCanvas canvas(bmp);
         SkPoint pts[] = { {0, 0}, {0, SkIntToScalar(height)} };
         SkColor colors0[] = { 0xFF1060B0 , 0xFF102030 };
-        paint.setShader(SkGradientShader::CreateLinear(pts, colors0, nullptr, 2,
-                                                       SkShader::kClamp_TileMode))->unref();
+        paint.setShader(SkGradientShader::MakeLinear(pts, colors0, nullptr, 2,
+                                                     SkShader::kClamp_TileMode));
         canvas.drawPaint(paint);
 
         SkColor colors1[] = { 0xFFA07010 , 0xFFA02080 };
         paint.setAntiAlias(true);
-        paint.setShader(SkGradientShader::CreateLinear(pts, colors1, nullptr, 2,
-                                                       SkShader::kClamp_TileMode))->unref();
+        paint.setShader(SkGradientShader::MakeLinear(pts, colors1, nullptr, 2,
+                                                     SkShader::kClamp_TileMode));
         canvas.drawCircle(SkIntToScalar(width) / 2, SkIntToScalar(height) / 2,
                           SkIntToScalar(width + height) / 5, paint);
     }
index 38108fed22a2e2bdae0e8b1faf7f1db38dd0daa4..6f4c75e22f066ae959f04c9078b2e28573b8f885 100644 (file)
@@ -80,13 +80,9 @@ protected:
             SkPoint center = SkPoint::Make(SkIntToScalar(-5), SkIntToScalar(30));
             SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
             SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
-            SkShader* s = SkGradientShader::CreateRadial(center,
-                                                         SkIntToScalar(20),
-                                                         colors,
-                                                         pos,
-                                                         SK_ARRAY_COUNT(colors),
-                                                         SkShader::kClamp_TileMode);
-            p.setShader(s)->unref();
+            p.setShader(SkGradientShader::MakeRadial(center, 20, colors, pos,
+                                                     SK_ARRAY_COUNT(colors),
+                                                     SkShader::kClamp_TileMode));
             fPaints.push_back(p);
         }
 
index b616e4d1cff22fd1782d6d3f3a38f58233a7c597..d0401f059568b90c582cb79fe8655f0c1711135a 100644 (file)
@@ -261,12 +261,8 @@ protected:
         SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0));
         SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN };
         SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
-        SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center,
-                                                     SkIntToScalar(20),
-                                                     colors,
-                                                     pos,
-                                                     SK_ARRAY_COUNT(colors),
-                                                     SkShader::kClamp_TileMode));
+        auto shader = SkGradientShader::MakeRadial(center, 20, colors, pos, SK_ARRAY_COUNT(colors),
+                                                   SkShader::kClamp_TileMode);
 
         for (int i = 0; i < fPaints.count(); ++i) {
             canvas->save();
index 4bec6784a891ed11830270d322dd03201bd1b7cb..f317cf9103d0ac6b9abcb44a59f0e00fd5a50db6 100644 (file)
@@ -21,13 +21,9 @@ class SamplerStressGM : public GM {
 public:
     SamplerStressGM()
     : fTextureCreated(false)
-    , fShader(nullptr)
     , fMaskFilter(nullptr) {
     }
 
-    virtual ~SamplerStressGM() {
-    }
-
 protected:
 
     SkString onShortName() override {
@@ -69,15 +65,14 @@ protected:
     }
 
     void createShader() {
-        if (fShader.get()) {
+        if (fShader) {
             return;
         }
 
         createTexture();
 
-        fShader.reset(SkShader::CreateBitmapShader(fTexture,
-                                                   SkShader::kRepeat_TileMode,
-                                                   SkShader::kRepeat_TileMode));
+        fShader = SkShader::MakeBitmapShader(fTexture, SkShader::kRepeat_TileMode,
+                                             SkShader::kRepeat_TileMode);
     }
 
     void createMaskFilter() {
@@ -140,9 +135,9 @@ protected:
     }
 
 private:
-    SkBitmap      fTexture;
-    bool          fTextureCreated;
-    SkAutoTUnref<SkShader>     fShader;
+    SkBitmap        fTexture;
+    bool            fTextureCreated;
+    sk_sp<SkShader> fShader;
     SkAutoTUnref<SkMaskFilter> fMaskFilter;
 
     typedef GM INHERITED;
index fd42973dba6295a049b7e9f07b92ea7b185ac588..503f8f5b1eaafa191fc83cab876a7543b0f610d3 100644 (file)
@@ -4,30 +4,31 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "gm.h"
 #include "SkGradientShader.h"
 
 namespace skiagm {
 
-static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate,
+static sk_sp<SkShader> MakeLinear(SkScalar width, SkScalar height, bool alternate,
                             const SkMatrix& localMatrix) {
-  SkPoint pts[2] = { {0, 0}, {width, height}};
-  SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
-  if (alternate) {
-    pts[1].fY = 0;
-    colors[0] = SK_ColorBLUE;
-    colors[1] = SK_ColorYELLOW;
-  }
-  return SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
-                                        SkShader::kClamp_TileMode, 0, &localMatrix);
+    SkPoint pts[2] = { {0, 0}, {width, height}};
+    SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
+    if (alternate) {
+        pts[1].fY = 0;
+        colors[0] = SK_ColorBLUE;
+        colors[1] = SK_ColorYELLOW;
+    }
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode,
+                                        0, &localMatrix);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 class ShaderBoundsGM : public GM {
 public:
-    typedef SkShader* (*ShaderGenFunc)(SkScalar width, SkScalar height,
-                                       bool alternate, const SkMatrix& localMatrix);
+    typedef sk_sp<SkShader> (*ShaderGenFunc)(SkScalar width, SkScalar height,
+                                             bool alternate, const SkMatrix& localMatrix);
     ShaderBoundsGM(ShaderGenFunc maker, const SkString& name)
         : fShaderMaker(maker),
           fName(name) {
@@ -62,20 +63,20 @@ protected:
 
         // Background shader.
         SkPaint paint;
-        paint.setShader(MakeShader(559, 387, false))->unref();
+        paint.setShader(MakeShader(559, 387, false));
         SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41),
                                     SkIntToScalar(571), SkIntToScalar(428));
         canvas->drawRect(r, paint);
 
         // Constrained shader.
-        paint.setShader(MakeShader(101, 151, true))->unref();
+        paint.setShader(MakeShader(101, 151, true));
         r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71),
                              SkIntToScalar(101), SkIntToScalar(151));
         canvas->clipRect(r);
         canvas->drawRect(r, paint);
     }
 
-    SkShader* MakeShader(int width, int height, bool background) {
+    sk_sp<SkShader> MakeShader(int width, int height, bool background) {
         SkScalar scale = 0.5f;
         if (background) {
             scale = 0.6f;
@@ -83,8 +84,7 @@ protected:
         SkScalar shaderWidth = width / scale;
         SkScalar shaderHeight = height / scale;
         SkMatrix shaderScale = SkMatrix::MakeScale(scale);
-        SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background, shaderScale);
-        return shader;
+        return fShaderMaker(shaderWidth, shaderHeight, background, shaderScale);
     }
 
 private:
@@ -93,7 +93,7 @@ private:
     ShaderGenFunc fShaderMaker;
     SkString fName;
 
-    SkShader* MakeShader(bool background);
+    sk_sp<SkShader> MakeShader(bool background);
 };
 
 ///////////////////////////////////////////////////////////////////////////////
index e68ee98df04c1a419fd8c2569d3b6c145174b3da..13fa28325bb3b80cd9e492cc05cf50cb334fd6db 100644 (file)
@@ -24,8 +24,8 @@ static void makebm(SkBitmap* bm, int w, int h) {
     SkPaint     paint;
 
     paint.setDither(true);
-    paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
-                SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, SK_ARRAY_COUNT(colors),
+                                                 SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
 }
 
@@ -46,38 +46,38 @@ static const GradData gGradData[] = {
     { 5, gColors, nullptr },
 };
 
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
-    return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
+static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+    return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
 }
 
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
-                                          data.fPos, data.fCount, tm);
+    return SkGradientShader::MakeRadial(center, center.fX, data.fColors, data.fPos, data.fCount,
+                                        tm);
 }
 
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
+static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
     SkPoint center;
     center.set(SkScalarAve(pts[0].fX, pts[1].fX),
                SkScalarAve(pts[0].fY, pts[1].fY));
-    return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
+    return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
 }
 
-static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
+static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
     SkPoint center0, center1;
     center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
                 SkScalarAve(pts[0].fY, pts[1].fY));
     center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
                 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
-    return SkGradientShader::CreateTwoPointConical(
+    return SkGradientShader::MakeTwoPointConical(
                             center1, (pts[1].fX - pts[0].fX) / 7,
                             center0, (pts[1].fX - pts[0].fX) / 2,
                             data.fColors, data.fPos, data.fCount, tm);
 }
 
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
+typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
 
 static const GradMaker gGradMakers[] = {
     MakeLinear, MakeRadial, MakeSweep, Make2Conical
@@ -123,7 +123,7 @@ protected:
                                      SK_ARRAY_COUNT(gGradMakers);
         static const int bmpCount = SK_ARRAY_COUNT(tileModes) *
                                     SK_ARRAY_COUNT(tileModes);
-        SkShader* shaders[gradCount + bmpCount];
+        sk_sp<SkShader> shaders[gradCount + bmpCount];
 
         int shdIdx = 0;
         for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) {
@@ -138,7 +138,7 @@ protected:
         makebm(&bm, w/16, h/4);
         for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) {
             for (size_t ty = 0; ty < SK_ARRAY_COUNT(tileModes); ++ty) {
-                shaders[shdIdx++] = SkShader::CreateBitmapShader(bm, tileModes[tx], tileModes[ty]);
+                shaders[shdIdx++] = SkShader::MakeBitmapShader(bm, tileModes[tx], tileModes[ty]);
             }
         }
 
@@ -167,7 +167,7 @@ protected:
             int i = 2*s;
             canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth),
                               SkIntToScalar((i % testsPerCol) * rowHeight));
-            paint.setShader(shaders[s])->unref();
+            paint.setShader(shaders[s]);
             canvas->drawText(text, textLen, 0, textBase, paint);
             canvas->restore();
             canvas->save();
index 74f01a0c9d30e37105696718a90661bf4117a614..2ec195259928ed86580e385eb68ad1f744daedd7 100644 (file)
@@ -24,11 +24,11 @@ static void makebm(SkBitmap* bm, int w, int h) {
 
     SkPaint     paint;
 
-    paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
-                    SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
+                    SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
-    paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
-                    SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
+                    SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
 }
 
@@ -136,11 +136,9 @@ DEF_SIMPLE_GM_BG(shadertext2, canvas, 1800, 900,
                 canvas->translate(0, kPadY / 2 + kPointSize);
                 columnH += kPadY / 2 + kPointSize;
                 for (int lm = 0; lm < localMatrices.count(); ++lm) {
-                    paint.setShader(
-                            SkShader::CreateBitmapShader(bmp,
-                                                         SkShader::kMirror_TileMode,
-                                                         SkShader::kRepeat_TileMode,
-                                                         &localMatrices[lm].fMatrix))->unref();
+                    paint.setShader(SkShader::MakeBitmapShader(bmp, SkShader::kMirror_TileMode,
+                                                               SkShader::kRepeat_TileMode,
+                                                               &localMatrices[lm].fMatrix));
 
                     canvas->save();
                         canvas->concat(matrices[m].fMatrix);
index 07ecd7184b7305b117ed7667a799cf60370fd79a..0d1c03e345a20846d3f77cf1d6b9e382bcf02547 100644 (file)
@@ -26,11 +26,11 @@ static void makebm(SkBitmap* bm, int w, int h) {
 
     SkPaint     paint;
 
-    paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
-                    SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(kPts0, kColors0, kPos,
+                    SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
-    paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
-                    SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(kPts1, kColors1, kPos,
+                    SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
 }
 
@@ -100,17 +100,13 @@ protected:
                 localM.postRotate(20);
                 localM.postScale(1.15f, .85f);
 
-                SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(fBmp,
-                                                                           kTileModes[tm0],
-                                                                           kTileModes[tm1],
-                                                                           &localM));
-
                 SkPaint fillPaint;
                 fillPaint.setAntiAlias(true);
                 sk_tool_utils::set_portable_typeface(&fillPaint);
                 fillPaint.setTextSize(SkIntToScalar(kPointSize));
                 fillPaint.setFilterQuality(kLow_SkFilterQuality);
-                fillPaint.setShader(shader);
+                fillPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTileModes[tm0],
+                                                               kTileModes[tm1], &localM));
 
                 canvas->drawText(kText, kTextLen, 0, 0, fillPaint);
                 canvas->drawText(kText, kTextLen, 0, 0, outlinePaint);
index bb2bf3c5bd3cd287ed316f2f3005068d1126a85f..5696240d21ed3ca00b7603b0b8ce0ff53b6e3c85 100644 (file)
@@ -128,12 +128,11 @@ protected:
             canvas->drawBitmap(fBitmap, 10, 10, &paint);
 
             canvas->translate(0, 40);
-            SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(
+            paint.setShader(SkShader::MakeBitmapShader(
                                           fBitmap, SkShader::kRepeat_TileMode,
                                           SkShader::kRepeat_TileMode));
 
             // see bug.skia.org/562 (shows bug as reported)
-            paint.setShader(shader);
             paint.setStyle(SkPaint::kFill_Style);
             canvas->drawRect(SkRect::MakeXYWH(10, 10, 20, 20), paint);
             paint.setShader(nullptr);
index 764b1a50342c710da213046e2cd0c66ea5b1cf15..6990ba7c938da6f38dac23b968d80f8cccc58af8 100644 (file)
@@ -8,31 +8,27 @@
 #include "gm.h"
 #include "SkGradientShader.h"
 
-typedef SkShader* (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
+typedef sk_sp<SkShader> (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
 
-static SkShader* shader_linear(const SkColor colors[], int count, const SkSize& size) {
+static sk_sp<SkShader> shader_linear(const SkColor colors[], int count, const SkSize& size) {
     SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, count,
-                                          SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, count, SkShader::kClamp_TileMode);
 }
 
-static SkShader* shader_radial(const SkColor colors[], int count, const SkSize& size) {
+static sk_sp<SkShader> shader_radial(const SkColor colors[], int count, const SkSize& size) {
     SkPoint center = { size.width()/2, size.height()/2 };
-    return SkGradientShader::CreateRadial(center, size.width()/2, colors, nullptr, count,
-                                          SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeRadial(center, size.width()/2, colors, nullptr, count,
+                                        SkShader::kClamp_TileMode);
 }
 
-static SkShader* shader_conical(const SkColor colors[], int count, const SkSize& size) {
+static sk_sp<SkShader> shader_conical(const SkColor colors[], int count, const SkSize& size) {
     SkPoint center = { size.width()/2, size.height()/2 };
-    return SkGradientShader::CreateTwoPointConical(center, size.width()/64,
-                                                   center, size.width()/2,
-                                                   colors, nullptr, count,
-                                                   SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeTwoPointConical(center, size.width()/64, center, size.width()/2,
+                                                colors, nullptr, count, SkShader::kClamp_TileMode);
 }
 
-static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& size) {
-    return SkGradientShader::CreateSweep(size.width()/2, size.height()/2,
-                                         colors, nullptr, count);
+static sk_sp<SkShader> shader_sweep(const SkColor colors[], int count, const SkSize& size) {
+    return SkGradientShader::MakeSweep(size.width()/2, size.height()/2, colors, nullptr, count);
 }
 
 class ShallowGradientGM : public skiagm::GM {
@@ -62,7 +58,7 @@ protected:
         SkSize size = SkSize::Make(r.width(), r.height());
 
         SkPaint paint;
-        paint.setShader(fProc(colors, colorCount, size))->unref();
+        paint.setShader(fProc(colors, colorCount, size));
         paint.setDither(fDither);
         canvas->drawRect(r, paint);
     }
index 052884236a8c22a3fb2130f6c9fa8ad560c07e19..b11487d6c561d05614e7a4e7aa9e7f9027135996 100644 (file)
@@ -21,10 +21,9 @@ static void rotated_checkerboard_shader(SkPaint* paint,
     SkMatrix matrix;
     matrix.setScale(0.75f, 0.75f);
     matrix.preRotate(30.0f);
-    SkAutoTUnref<SkShader> shader(
-            SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
-                                         SkShader::kRepeat_TileMode, &matrix));
-    paint->setShader(shader);
+    paint->setShader(
+            SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
+                                       &matrix));
 }
 
 static void exercise_draw_pos_text(SkCanvas* canvas,
index 86fe89bd1a4be4e843edf2d9a1ea2ad92e6e1af8..28bb04bd4eab70e8ab30a5c623ec448f3a87017c 100644 (file)
@@ -27,10 +27,8 @@ static void identity_paintproc(SkPaint* paint) {
 static void gradient_paintproc(SkPaint* paint) {
     const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
     const SkPoint pts[] = { { 0, 0 }, { W, H } };
-    SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr,
-                                                 SK_ARRAY_COUNT(colors),
-                                                 SkShader::kClamp_TileMode);
-    paint->setShader(s)->unref();
+    paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                                  SkShader::kClamp_TileMode));
 }
 
 typedef void (*Proc)(SkCanvas*, const SkPaint&);
index c3eaf9e8d2075a870ead5645c1e4e0e16c3c7f9f..6874b5bea32e8ab4962a15e4276bb8f1533cfdf1 100644 (file)
 #define W 200
 #define H 100
 
-static SkShader* make_shader() {
+static sk_sp<SkShader> make_shader() {
     int a = 0x99;
     int b = 0xBB;
     SkPoint pts[] = { { 0, 0 }, { W, H } };
     SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 }
 
 static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelGeometry geo,
@@ -46,7 +46,7 @@ static void test_draw(SkCanvas* canvas, const char label[]) {
     paint.setLCDRenderText(true);
     paint.setDither(true);
 
-    paint.setShader(make_shader())->unref();
+    paint.setShader(make_shader());
     canvas->drawRect(SkRect::MakeWH(W, H), paint);
     paint.setShader(nullptr);
 
index 1053bb25181bc71bbd3af3eb1ecd40f906d0db6e..dcc29f37cf3d8de45cb099f15a8f3aff0259c55a 100644 (file)
 #include "SkGradientShader.h"
 #include "SkTableColorFilter.h"
 
-static SkShader* make_shader0(int w, int h) {
+static sk_sp<SkShader> make_shader0(int w, int h) {
     SkPoint pts[] = { {0, 0}, {SkIntToScalar(w), SkIntToScalar(h)} };
     SkColor colors[] = {
         SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN,
         SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE
     };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
-                                          SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kClamp_TileMode);
 }
 static void make_bm0(SkBitmap* bm) {
     int W = 120;
@@ -28,17 +28,17 @@ static void make_bm0(SkBitmap* bm) {
 
     SkCanvas canvas(*bm);
     SkPaint paint;
-    paint.setShader(make_shader0(W, H))->unref();
+    paint.setShader(make_shader0(W, H));
     canvas.drawPaint(paint);
 }
-static SkShader* make_shader1(int w, int h) {
+static sk_sp<SkShader> make_shader1(int w, int h) {
     SkScalar cx = SkIntToScalar(w)/2;
     SkScalar cy = SkIntToScalar(h)/2;
     SkColor colors[] = {
         SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
     };
-    return SkGradientShader::CreateRadial(SkPoint::Make(cx, cy), cx, colors, nullptr,
-                                          SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeRadial(SkPoint::Make(cx, cy), cx, colors, nullptr,
+                                        SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode);
 }
 static void make_bm1(SkBitmap* bm) {
     int W = 120;
@@ -50,7 +50,7 @@ static void make_bm1(SkBitmap* bm) {
 
     SkCanvas canvas(*bm);
     SkPaint paint;
-    paint.setShader(make_shader1(W, H))->unref();
+    paint.setShader(make_shader1(W, H));
     paint.setAntiAlias(true);
     canvas.drawCircle(cx, cy, cx, paint);
 }
@@ -234,7 +234,7 @@ protected:
         }
 
         SkPaint paint;
-        paint.setShader(make_shader1(50, 50))->unref();
+        paint.setShader(make_shader1(50, 50));
         SkRect r = SkRect::MakeWH(50, 50);
         const SkScalar spacer = 10;
 
index fef3e248f49fe0c64c76cd534706bab745cf890e..8d462c9b0902658cd8d29dcd1bdf7824c615cc1f 100644 (file)
@@ -80,7 +80,7 @@ static void path_effect(SkPaint* paint) {
     paint->setPathEffect(make_tile_effect())->unref();
 }
 
-static SkShader* make_shader(const SkRect& bounds) {
+static sk_sp<SkShader> make_shader(const SkRect& bounds) {
     const SkPoint pts[] = {
         { bounds.left(), bounds.top() },
         { bounds.right(), bounds.bottom() },
@@ -89,15 +89,14 @@ static SkShader* make_shader(const SkRect& bounds) {
         SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
         SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
     };
-    return SkGradientShader::CreateLinear(pts,
-                                          colors, nullptr, SK_ARRAY_COUNT(colors),
-                                          SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kClamp_TileMode);
 }
 
 static void color_filter(SkPaint* paint) {
     SkRect r;
     r.setWH(SkIntToScalar(kWidth), 50);
-    paint->setShader(make_shader(r))->unref();
+    paint->setShader(make_shader(r));
     paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(0xF0F0F0, 0))->unref();
 }
 
index 30674e1d6877521c3595ffa94fc3775bdc7ff9d3..6a8fa49289996268f4b1af669bdf99ec0ee3736d 100644 (file)
@@ -68,11 +68,11 @@ protected:
         }
 
         SkISize sz = this->onISize();
-        fShader.reset(SkGradientShader::CreateRadial(SkPoint::Make(SkIntToScalar(sz.width() / 2),
-                                                                   SkIntToScalar(sz.height() / 2)),
-                                                     sz.width() * .66f, colors, pos,
-                                                     SK_ARRAY_COUNT(colors),
-                                                     SkShader::kRepeat_TileMode));
+        fShader = SkGradientShader::MakeRadial(SkPoint::Make(SkIntToScalar(sz.width() / 2),
+                                               SkIntToScalar(sz.height() / 2)),
+                                               sz.width() * .66f, colors, pos,
+                                               SK_ARRAY_COUNT(colors),
+                                               SkShader::kRepeat_TileMode);
     }
 
     SkString onShortName() override {
@@ -104,7 +104,7 @@ protected:
 private:
     SkTDArray<uint16_t>            fGlyphs;
     SkAutoTUnref<const SkTextBlob> fBlob;
-    SkAutoTUnref<SkShader>         fShader;
+    sk_sp<SkShader>                fShader;
 
     typedef skiagm::GM INHERITED;
 };
index 72e40feb49396221fc29788b7d94ec16f8459a18..6bd6490c660ba7064bff0a873b632474210832b0 100644 (file)
@@ -50,24 +50,24 @@ protected:
         SkPaint paint;
 
         SkColor colors1[] = { SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorGRAY };
-        paint.setShader(SkGradientShader::CreateSweep(65.f, 75.f, colors1,
-                                                      nullptr, SK_ARRAY_COUNT(colors1)))->unref();
-        canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
-                                         fBmp.width() + 10.f, fBmp.height() + 10.f), paint);
+        paint.setShader(SkGradientShader::MakeSweep(65.f, 75.f, colors1, nullptr,
+                                                    SK_ARRAY_COUNT(colors1)));
+        canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, fBmp.width() + 10.f, fBmp.height() + 10.f),
+                        paint);
 
         SkColor colors2[] = { SK_ColorMAGENTA, SK_ColorLTGRAY, SK_ColorYELLOW };
-        paint.setShader(SkGradientShader::CreateSweep(45.f, 55.f, colors2, nullptr,
-                                                      SK_ARRAY_COUNT(colors2)))->unref();
+        paint.setShader(SkGradientShader::MakeSweep(45.f, 55.f, colors2, nullptr,
+                                                    SK_ARRAY_COUNT(colors2)));
         paint.setXfermodeMode(SkXfermode::kDarken_Mode);
-        canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
-                                         fBmp.width() + 10.f, fBmp.height() + 10.f), paint);
+        canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, fBmp.width() + 10.f, fBmp.height() + 10.f),
+                        paint);
 
         SkColor colors3[] = { SK_ColorBLUE, SK_ColorLTGRAY, SK_ColorGREEN };
-        paint.setShader(SkGradientShader::CreateSweep(25.f, 35.f, colors3, nullptr,
-                                                      SK_ARRAY_COUNT(colors3)))->unref();
+        paint.setShader(SkGradientShader::MakeSweep(25.f, 35.f, colors3, nullptr,
+                                                    SK_ARRAY_COUNT(colors3)));
         paint.setXfermodeMode(SkXfermode::kLighten_Mode);
-        canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f,
-                                         fBmp.width() + 10.f, fBmp.height() + 10.f), paint);
+        canvas.drawOval(SkRect::MakeXYWH(-5.f, -5.f, fBmp.width() + 10.f, fBmp.height() + 10.f),
+                        paint);
     }
 
     void onDraw(SkCanvas* canvas) override {
index daecbb05e23ce1d0ac34aada9e66b283b97565dd..d74d40bf49610051605ac3c4a81a74ff0fbb9aeb 100644 (file)
@@ -1,10 +1,10 @@
-
 /*
  * Copyright 2014 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "gm.h"
 
 #include "Resources.h"
@@ -14,7 +14,6 @@
 #include "SkShader.h"
 #include "SkStream.h"
 
-
  /***
   *
   * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
@@ -64,10 +63,8 @@ protected:
         mat.setScale(121.f/360.f, 93.f/288.f);
         mat.postTranslate(-72, -72);
 
-        SkShader *shader = SkShader::CreateBitmapShader(fBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &mat);
-        paint.setShader(shader);
-
-        SkSafeUnref(shader);
+        paint.setShader(SkShader::MakeBitmapShader(fBitmap, SkShader::kRepeat_TileMode,
+                                                   SkShader::kRepeat_TileMode, &mat));
         canvas->drawRectCoords(8,8,1008, 608, paint);
     }
 
index 26b83486e86c7e197524ee643f82df4908b95bcb..d774939648d3ea7fa6b1f9e8ccc87f2d242056e8 100644 (file)
@@ -27,15 +27,14 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
     SkPaint     paint;
 
     paint.setDither(true);
-    paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
-                SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, SK_ARRAY_COUNT(colors),
+                                                 SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
 }
 
 static void setup(SkPaint* paint, const SkBitmap& bm, bool filter,
                   SkShader::TileMode tmx, SkShader::TileMode tmy) {
-    SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy);
-    paint->setShader(shader)->unref();
+    paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
     paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
 }
 
@@ -156,13 +155,13 @@ private:
 static const int gWidth = 32;
 static const int gHeight = 32;
 
-static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
     SkBitmap bm;
     makebm(&bm, kN32_SkColorType, gWidth, gHeight);
-    return SkShader::CreateBitmapShader(bm, tx, ty);
+    return SkShader::MakeBitmapShader(bm, tx, ty);
 }
 
-static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
     SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
     SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
     SkScalar rad = SkIntToScalar(gWidth)/2;
@@ -171,17 +170,16 @@ static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
     int index = (int)ty;
     switch (index % 3) {
         case 0:
-            return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+            return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
         case 1:
-            return SkGradientShader::CreateRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+            return SkGradientShader::MakeRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
         case 2:
-            return SkGradientShader::CreateSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
+            return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
     }
-
     return nullptr;
 }
 
-typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
+typedef sk_sp<SkShader> (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
 
 class Tiling2GM : public skiagm::GM {
     ShaderProc fProc;
@@ -239,7 +237,7 @@ protected:
             x += SkIntToScalar(50);
             for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
                 SkPaint paint;
-                paint.setShader(fProc(gModes[kx], gModes[ky]))->unref();
+                paint.setShader(fProc(gModes[kx], gModes[ky]));
 
                 canvas->save();
                 canvas->translate(x, y);
index 0d46fb66c54ffc764a205d22730eb13cf9fc75f8..21224b44e888f70059cb1e0020d77d965fdac5c6 100644 (file)
@@ -27,15 +27,14 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
     SkPaint     paint;
 
     paint.setDither(true);
-    paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
-                SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos,
+                SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
     canvas.drawPaint(paint);
 }
 
 static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_level,
                   SkShader::TileMode tmx, SkShader::TileMode tmy) {
-    SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy);
-    paint->setShader(shader)->unref();
+    paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
     paint->setFilterQuality(filter_level);
 }
 
@@ -160,13 +159,13 @@ private:
 static const int gWidth = 32;
 static const int gHeight = 32;
 
-static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
     SkBitmap bm;
     makebm(&bm, kN32_SkColorType, gWidth, gHeight);
-    return SkShader::CreateBitmapShader(bm, tx, ty);
+    return SkShader::MakeBitmapShader(bm, tx, ty);
 }
 
-static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
+static sk_sp<SkShader> make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
     SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
     SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
     SkScalar rad = SkIntToScalar(gWidth)/2;
@@ -175,17 +174,17 @@ static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
     int index = (int)ty;
     switch (index % 3) {
         case 0:
-            return SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+            return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
         case 1:
-            return SkGradientShader::CreateRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
+            return SkGradientShader::MakeRadial(center, rad, colors, nullptr, SK_ARRAY_COUNT(colors), tx);
         case 2:
-            return SkGradientShader::CreateSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
+            return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nullptr, SK_ARRAY_COUNT(colors));
     }
 
     return nullptr;
 }
 
-typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
+typedef sk_sp<SkShader> (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
 
 class ScaledTiling2GM : public skiagm::GM {
     ShaderProc fProc;
@@ -243,7 +242,7 @@ protected:
             x += SkIntToScalar(50);
             for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
                 SkPaint paint;
-                paint.setShader(fProc(gModes[kx], gModes[ky]))->unref();
+                paint.setShader(fProc(gModes[kx], gModes[ky]));
 
                 canvas->save();
                 canvas->translate(x, y);
index 7942b4266afb3e27a492ac5e4f29ecd725e0ab1f..1162b2d2d13adaccd7f0b09ec6f482f2cc11fc2e 100644 (file)
@@ -44,12 +44,10 @@ protected:
 
     virtual void onDraw(SkCanvas* canvas) {
         SkBitmap bm = make_bitmap();
-        SkShader* s =
-            SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
-                                         SkShader::kMirror_TileMode);
         SkPaint paint;
         paint.setAlpha(0x80);
-        paint.setShader(s)->unref();
+        paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
+                                                   SkShader::kMirror_TileMode));
         canvas->drawPaint(paint);
     }
 
index 73bd8b20235f3add7320fdfd8575bb267d89d8be..5e057617d4349828e346359af0b51a6dbbd1a53a 100644 (file)
@@ -9,9 +9,7 @@
 #include "SkSurface.h"
 #include "gm.h"
 
-static void make_transparency(SkCanvas* canvas,
-                              SkScalar width,
-                              SkScalar height) {
+static void make_transparency(SkCanvas* canvas, SkScalar width, SkScalar height) {
     SkPoint pts[2];
     pts[0] = SkPoint::Make(0, 0);
     pts[1] = SkPoint::Make(width, 0);
@@ -31,30 +29,27 @@ static void make_transparency(SkCanvas* canvas,
         SkColor shaderColors[2];
         shaderColors[0] = SK_AlphaTRANSPARENT;
         shaderColors[1] = kColors[i];
-        SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(
-                pts, shaderColors, nullptr, 2, SkShader::kClamp_TileMode));
-        SkRect r = SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight);
         SkPaint p;
-        p.setShader(shader);
-        canvas->drawRect(r, p);
+        p.setShader(SkGradientShader::MakeLinear(pts, shaderColors, nullptr, 2,
+                                                 SkShader::kClamp_TileMode));
+        canvas->drawRect(SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight), p);
     }
 }
 
 // http://crrev.com/834303005
-static SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
+static sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
     SkBitmap bm;
     bm.allocN32Pixels(2 * size, 2 * size);
     bm.eraseColor(c1);
     bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
     bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
-    return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
-                                        SkShader::kRepeat_TileMode);
+    return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
 }
 
 // http://crrev.com/834303005
 static void checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) {
     SkPaint paint;
-    paint.setShader(create_checkerboard_shader(c1, c2, size))->unref();
+    paint.setShader(create_checkerboard_shader(c1, c2, size));
     canvas->drawPaint(paint);
 }
 
index 31fb3527248b5f38ee4e057a4ab073deffb3a58c..177dc43c2b7bc83b4d7838defc0cea3bc405cb52 100644 (file)
 #include "SkGradientShader.h"
 #include "SkRandom.h"
 
-static SkShader* make_shader1(SkScalar w, SkScalar h) {
+static sk_sp<SkShader> make_shader1(SkScalar w, SkScalar h) {
     const SkColor colors[] = {
         SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
         SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW,
     };
     const SkPoint pts[] = { { w/4, 0 }, { 3*w/4, h } };
 
-    return SkGradientShader::CreateLinear(pts, colors, nullptr,
-                                          SK_ARRAY_COUNT(colors),
-                                          SkShader::kMirror_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                        SkShader::kMirror_TileMode);
 }
 
-static SkShader* make_shader2() {
-    return SkShader::CreateColorShader(SK_ColorBLUE);
+static sk_sp<SkShader> make_shader2() {
+    return SkShader::MakeColorShader(SK_ColorBLUE);
 }
 
 static SkColorFilter* make_color_filter() {
@@ -35,8 +34,8 @@ class VerticesGM : public skiagm::GM {
     SkPoint                     fPts[9];
     SkPoint                     fTexs[9];
     SkColor                     fColors[9];
-    SkAutoTUnref<SkShader>      fShader1;
-    SkAutoTUnref<SkShader>      fShader2;
+    sk_sp<SkShader>             fShader1;
+    sk_sp<SkShader>             fShader2;
     SkAutoTUnref<SkColorFilter> fColorFilter;
 
 public:
@@ -59,8 +58,8 @@ protected:
         fTexs[3].set(0, h/2);   fTexs[4].set(w/2, h/2); fTexs[5].set(w, h/2);
         fTexs[6].set(0, h);     fTexs[7].set(w/2, h);   fTexs[8].set(w, h);
 
-        fShader1.reset(make_shader1(w, h));
-        fShader2.reset(make_shader2());
+        fShader1 = make_shader1(w, h);
+        fShader2 = make_shader2();
         fColorFilter.reset(make_color_filter());
 
         SkRandom rand;
@@ -86,11 +85,11 @@ protected:
         };
 
         const struct {
-            const SkColor*  fColors;
-            const SkPoint*  fTexs;
-            SkShader*       fShader;
-            SkColorFilter*  fColorFilter;
-            uint8_t         fAlpha;
+            const SkColor*          fColors;
+            const SkPoint*          fTexs;
+            const sk_sp<SkShader>&  fShader;
+            SkColorFilter*          fColorFilter;
+            uint8_t                 fAlpha;
         } rec[] = {
             { fColors,  nullptr, fShader1, nullptr     , 0xFF },
             { nullptr,  fTexs  , fShader1, nullptr     , 0xFF },
index 5c67e77e3e99eef57c35ccf386266125e822ef2d..ab6821dc1abc651b01b40e57a9075a3afcb11145 100644 (file)
 static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
     const SkPoint center = { SkIntToScalar(width)/2, SkIntToScalar(height)/2 };
     const SkScalar radius = 40;
-    SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nullptr, 2,
-                                                      SkShader::kMirror_TileMode);
     SkPaint paint;
-    paint.setShader(shader)->unref();
+    paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, nullptr, 2,
+                                                 SkShader::kMirror_TileMode));
     paint.setXfermodeMode(SkXfermode::kSrc_Mode);
     canvas->drawPaint(paint);
 }
index 1a71255d3e0b94ca06e9e18ef278391a9bd2ef1c..a1427cf212e4a92b78d962c8898b06558ab8b2bd 100644 (file)
@@ -261,10 +261,8 @@ protected:
         const SkScalar h = SkIntToScalar(H);
         SkMatrix m;
         m.setScale(SkIntToScalar(6), SkIntToScalar(6));
-        SkShader* s = SkShader::CreateBitmapShader(fBG,
-                                                   SkShader::kRepeat_TileMode,
-                                                   SkShader::kRepeat_TileMode,
-                                                   &m);
+        auto s = SkShader::MakeBitmapShader(fBG, SkShader::kRepeat_TileMode,
+                                            SkShader::kRepeat_TileMode, &m);
 
         SkPaint labelP;
         labelP.setAntiAlias(true);
@@ -325,7 +323,6 @@ protected:
                 y0 = 0;
             }
         }
-        s->unref();
     }
 
 private:
index db48c03d20788118dc47aa5634c9d0dff3162854..397f4e1e2963a3f1cc3464af8911fff992bfea6a 100644 (file)
@@ -99,10 +99,8 @@ private:
 
         SkMatrix lm;
         lm.setScale(SkIntToScalar(16), SkIntToScalar(16));
-        fBG.reset(SkShader::CreateBitmapShader(bg,
-                                               SkShader::kRepeat_TileMode,
-                                               SkShader::kRepeat_TileMode,
-                                               &lm));
+        fBG = SkShader::MakeBitmapShader(bg, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
+                                         &lm);
 
         SkBitmap srcBmp;
         srcBmp.allocN32Pixels(kSize, kSize);
@@ -115,9 +113,8 @@ private:
                 pixels[kSize * y + x] = rowColor;
             }
         }
-        fSrc.reset(SkShader::CreateBitmapShader(srcBmp,
-                                                SkShader::kClamp_TileMode,
-                                                SkShader::kClamp_TileMode));
+        fSrc = SkShader::MakeBitmapShader(srcBmp, SkShader::kClamp_TileMode,
+                                          SkShader::kClamp_TileMode);
         SkBitmap dstBmp;
         dstBmp.allocN32Pixels(kSize, kSize);
         pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels());
@@ -129,9 +126,8 @@ private:
                 pixels[kSize * y + x] = colColor;
             }
         }
-        fDst.reset(SkShader::CreateBitmapShader(dstBmp,
-                                                SkShader::kClamp_TileMode,
-                                                SkShader::kClamp_TileMode));
+        fDst = SkShader::MakeBitmapShader(dstBmp, SkShader::kClamp_TileMode,
+                                          SkShader::kClamp_TileMode);
     }
 
     enum {
@@ -139,9 +135,9 @@ private:
         kSize = 256 >> kShift,
     };
 
-    SkAutoTUnref<SkShader> fBG;
-    SkAutoTUnref<SkShader> fSrc;
-    SkAutoTUnref<SkShader> fDst;
+    sk_sp<SkShader> fBG;
+    sk_sp<SkShader> fSrc;
+    sk_sp<SkShader> fDst;
 
     typedef GM INHERITED;
 };
index 8c24bf72d1abb80f823d95df71c51445da7b4fe4..4cd05df5c40c4f436209393f67b33d3bbe8750c1 100644 (file)
@@ -185,21 +185,17 @@ private:
 
         SkMatrix lm;
         lm.setScale(SkIntToScalar(kCheckSize), SkIntToScalar(kCheckSize));
-        fBGShader.reset(SkShader::CreateBitmapShader(bg,
-                                                     SkShader::kRepeat_TileMode,
-                                                     SkShader::kRepeat_TileMode,
-                                                     &lm));
+        fBGShader = SkShader::MakeBitmapShader(bg, SkShader::kRepeat_TileMode,
+                                               SkShader::kRepeat_TileMode, &lm);
 
         SkPaint bmpPaint;
-        static const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar(kSize) / 2 };
-        static const SkColor kColors[] = { SK_ColorTRANSPARENT, 0x80800000,
-                                          0xF020F060, SK_ColorWHITE };
-        bmpPaint.setShader(SkGradientShader::CreateRadial(kCenter,
-                                                          3 * SkIntToScalar(kSize) / 4,
-                                                          kColors,
-                                                          nullptr,
-                                                          SK_ARRAY_COUNT(kColors),
-                                                          SkShader::kRepeat_TileMode))->unref();
+        const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar(kSize) / 2 };
+        const SkColor kColors[] = {
+            SK_ColorTRANSPARENT, 0x80800000, 0xF020F060, SK_ColorWHITE
+        };
+        bmpPaint.setShader(SkGradientShader::MakeRadial(kCenter, 3 * SkIntToScalar(kSize) / 4,
+                                                        kColors, nullptr, SK_ARRAY_COUNT(kColors),
+                                                        SkShader::kRepeat_TileMode));
 
         SkBitmap bmp;
         bmp.allocN32Pixels(kSize, kSize);
@@ -210,9 +206,8 @@ private:
                         7 * SkIntToScalar(kSize) / 8, 7 * SkIntToScalar(kSize) / 8};
         bmpCanvas.drawRect(rect, bmpPaint);
 
-        fBmpShader.reset(SkShader::CreateBitmapShader(bmp,
-                                                      SkShader::kClamp_TileMode,
-                                                      SkShader::kClamp_TileMode));
+        fBmpShader = SkShader::MakeBitmapShader(bmp, SkShader::kClamp_TileMode,
+                                                SkShader::kClamp_TileMode);
     }
 
     enum {
@@ -221,8 +216,8 @@ private:
         kTestsPerRow = 15,
     };
 
-    SkAutoTUnref<SkShader> fBGShader;
-    SkAutoTUnref<SkShader> fBmpShader;
+    sk_sp<SkShader> fBGShader;
+    sk_sp<SkShader> fBmpShader;
 
     typedef GM INHERITED;
 };
index eb86283618c77d5c1fd88d30bb575d508a7d3407..89e6faf76491089c8c361d4dcba1d9af589c5d06 100644 (file)
@@ -50,9 +50,8 @@ DEF_TEST(BitmapHeap, reporter) {
     uint32_t* pixel = bm.getAddr32(1,0);
     *pixel = SK_ColorBLUE;
 
-    SkShader* bitmapShader = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
-                                                          SkShader::kRepeat_TileMode);
-    SkAutoTUnref<SkShader> aur(bitmapShader);
+    auto bitmapShader = SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
+                                                   SkShader::kRepeat_TileMode);
 
     // Flatten, storing it in the bitmap heap.
     SkBitmapHeap heap(1, 1);
index b6a24eb98d4cae5b8d93ca3c25338808aae7413b..032acdac3942b0ba658fa933704c0103184d6ad5 100644 (file)
@@ -166,10 +166,8 @@ struct Mesh {
         fPts[1].set(w, 0);
         fPts[2].set(w, h);
         fPts[3].set(0, h);
-        SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
-                                                   SkShader::kClamp_TileMode);
-        paint->setShader(s)->unref();
-
+        paint->setShader(SkShader::MakeBitmapShader(bm, SkShader::kClamp_TileMode,
+                                                    SkShader::kClamp_TileMode));
     }
 
     void draw(SkCanvas* canvas, SkPaint* paint) {
index f34430f475aea5bd1be0ccccc22f1e553760233c..8681ca4f180651823ed2be6f22bbdf73541c9293 100644 (file)
@@ -415,9 +415,8 @@ static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& d,
     pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight));
     pts[3].set(0, SkIntToScalar(d.fHeight));
     SkPaint paint;
-    SkShader* shader = SkShader::CreateBitmapShader(d.fBitmap,
-        SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
-    paint.setShader(shader)->unref();
+    paint.setShader(SkShader::MakeBitmapShader(d.fBitmap, SkShader::kClamp_TileMode,
+                                               SkShader::kClamp_TileMode));
     canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts,
                          nullptr, nullptr, nullptr, 0, paint);
 }
index 88b9437935cebe326a2ce51b0ebe7c7ecdfc91b0..8928d4c90959d2d32f609609fd31126041ad2de1 100644 (file)
@@ -195,11 +195,9 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
                   0.0078740157f,
                   SkIntToScalar(239),
                   0, 0, SK_Scalar1);
-    SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
-                                               SkShader::kRepeat_TileMode, &matrix);
-
     SkPaint paint;
-    paint.setShader(s)->unref();
+    paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
+                                               SkShader::kRepeat_TileMode, &matrix));
 
     SkRect r = SkRect::MakeXYWH(681, 239, 695, 253);
     c.drawRect(r, paint);
index cc94cbaf7591d3e7ecbca31cfc3422754854d55b..65210705526e47e6574dcdf061313f77c4ed2ae2 100644 (file)
@@ -20,9 +20,9 @@
 static void test_big_grad(skiatest::Reporter* reporter) {
     const SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
     const SkPoint pts[] = {{ 15, 14.7112684f }, { 0.709064007f, 12.6108112f }};
-    SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
     SkPaint paint;
-    paint.setShader(s)->unref();
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+                                                 SkShader::kClamp_TileMode));
 
     SkBitmap bm;
     bm.allocN32Pixels(2000, 1);
@@ -46,7 +46,7 @@ struct GradRec {
     const SkScalar* fRadius; // 2
     SkShader::TileMode fTileMode;
 
-    void gradCheck(skiatest::Reporter* reporter, SkShader* shader,
+    void gradCheck(skiatest::Reporter* reporter, const sk_sp<SkShader>& shader,
                    SkShader::GradientInfo* info,
                    SkShader::GradientType gt) const {
         SkAutoTMalloc<SkColor> colorStorage(fColorCount);
@@ -68,7 +68,7 @@ struct GradRec {
 
 
 static void none_gradproc(skiatest::Reporter* reporter, const GradRec&) {
-    SkAutoTUnref<SkShader> s(SkShader::CreateEmptyShader());
+    sk_sp<SkShader> s(SkShader::MakeEmptyShader());
     REPORTER_ASSERT(reporter, SkShader::kNone_GradientType == s->asAGradient(nullptr));
 }
 
@@ -84,11 +84,8 @@ static void color_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
 }
 
 static void linear_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(rec.fPoint,
-                                                            rec.fColors,
-                                                            rec.fPos,
-                                                            rec.fColorCount,
-                                                            rec.fTileMode));
+    sk_sp<SkShader> s(SkGradientShader::MakeLinear(rec.fPoint, rec.fColors, rec.fPos,
+                                                   rec.fColorCount, rec.fTileMode));
 
     SkShader::GradientInfo info;
     rec.gradCheck(reporter, s, &info, SkShader::kLinear_GradientType);
@@ -96,12 +93,8 @@ static void linear_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
 }
 
 static void radial_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial(rec.fPoint[0],
-                                                            rec.fRadius[0],
-                                                            rec.fColors,
-                                                            rec.fPos,
-                                                            rec.fColorCount,
-                                                            rec.fTileMode));
+    sk_sp<SkShader> s(SkGradientShader::MakeRadial(rec.fPoint[0], rec.fRadius[0], rec.fColors,
+                                                   rec.fPos, rec.fColorCount, rec.fTileMode));
 
     SkShader::GradientInfo info;
     rec.gradCheck(reporter, s, &info, SkShader::kRadial_GradientType);
@@ -110,11 +103,8 @@ static void radial_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
 }
 
 static void sweep_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateSweep(rec.fPoint[0].fX,
-                                                           rec.fPoint[0].fY,
-                                                           rec.fColors,
-                                                           rec.fPos,
-                                                           rec.fColorCount));
+    sk_sp<SkShader> s(SkGradientShader::MakeSweep(rec.fPoint[0].fX, rec.fPoint[0].fY, rec.fColors,
+                                                  rec.fPos, rec.fColorCount));
 
     SkShader::GradientInfo info;
     rec.gradCheck(reporter, s, &info, SkShader::kSweep_GradientType);
@@ -122,14 +112,14 @@ static void sweep_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
 }
 
 static void conical_gradproc(skiatest::Reporter* reporter, const GradRec& rec) {
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateTwoPointConical(rec.fPoint[0],
-                                                             rec.fRadius[0],
-                                                             rec.fPoint[1],
-                                                             rec.fRadius[1],
-                                                             rec.fColors,
-                                                             rec.fPos,
-                                                             rec.fColorCount,
-                                                             rec.fTileMode));
+    sk_sp<SkShader> s(SkGradientShader::MakeTwoPointConical(rec.fPoint[0],
+                                                            rec.fRadius[0],
+                                                            rec.fPoint[1],
+                                                            rec.fRadius[1],
+                                                            rec.fColors,
+                                                            rec.fPos,
+                                                            rec.fColorCount,
+                                                            rec.fTileMode));
 
     SkShader::GradientInfo info;
     rec.gradCheck(reporter, s, &info, SkShader::kConical_GradientType);
@@ -145,15 +135,10 @@ static void TestConstantGradient(skiatest::Reporter*) {
     };
     SkColor colors[] = { SK_ColorBLUE, SK_ColorBLUE };
     const SkScalar pos[] = { 0, SK_Scalar1 };
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateLinear(pts,
-                                                            colors,
-                                                            pos,
-                                                            2,
-                                                            SkShader::kClamp_TileMode));
+    SkPaint paint;
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode));
     SkBitmap outBitmap;
     outBitmap.allocN32Pixels(10, 1);
-    SkPaint paint;
-    paint.setShader(s.get());
     SkCanvas canvas(outBitmap);
     canvas.drawPaint(paint);
     SkAutoLockPixels alp(outBitmap);
@@ -204,11 +189,8 @@ static void test_nearly_vertical(skiatest::Reporter* reporter) {
     const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
     const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
     const SkScalar pos[] = { 0, 1 };
-    SkAutoTUnref<SkShader> gradient(
-        SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode));
-
     SkPaint paint;
-    paint.setShader(gradient);
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader::kClamp_TileMode));
 
     surface->getCanvas()->drawPaint(paint);
 }
@@ -224,12 +206,9 @@ static void test_linear_fuzz(skiatest::Reporter* reporter) {
     const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE };
     const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
 
-
-    SkAutoTUnref<SkShader> gradient(
-                   SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode));
-
     SkPaint paint;
-    paint.setShader(gradient);
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode));
+
     SkRect r = {0, 83, 1254, 620};
     surface->getCanvas()->drawRect(r, paint);
 }
@@ -241,12 +220,11 @@ static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) {
     surface->getCanvas()->clear(SK_ColorRED);
 
     const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
-    SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(
+    SkPaint p;
+    p.setShader(SkGradientShader::MakeTwoPointConical(
         SkPoint::Make(2.5f, 2.5f), 0,
         SkPoint::Make(3.0f, 3.0f), 10,
         colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
-    SkPaint p;
-    p.setShader(shader);
     surface->getCanvas()->drawPaint(p);
 
     // r == 0 for the center pixel.
index 3def8f5cca82134f36ef733f9e20d38f7381bb22..dfb0d35e484a0a0350804f34806dca015f774d4e 100644 (file)
@@ -374,12 +374,9 @@ static SkBitmap make_gradient_circle(int width, int height) {
     SkColor colors[2];
     colors[0] = SK_ColorWHITE;
     colors[1] = SK_ColorBLACK;
-    SkAutoTUnref<SkShader> shader(
-        SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
-                                       SkShader::kClamp_TileMode)
-    );
     SkPaint paint;
-    paint.setShader(shader);
+    paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2,
+                                                 SkShader::kClamp_TileMode));
     canvas.drawCircle(x, y, radius, paint);
     return bitmap;
 }
index b71fe471196f88b9604730b582cf53a191e80542..f1c0c2eb9739bd563273e15da4c0c4ff19f60a5a 100644 (file)
@@ -30,10 +30,9 @@ static void test_unscaled(skiatest::Reporter* reporter) {
     SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
     SkScalar radius = SkIntToScalar(5);
 
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial(
-        center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
     SkPaint gradientPaint;
-    gradientPaint.setShader(s);
+    gradientPaint.setShader(SkGradientShader::MakeRadial(
+        center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
 
     // Test using the image filter
     {
@@ -77,10 +76,9 @@ static void test_scaled(skiatest::Reporter* reporter) {
     SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
     SkScalar radius = SkIntToScalar(5);
 
-    SkAutoTUnref<SkShader> s(SkGradientShader::CreateRadial(
-        center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
     SkPaint gradientPaint;
-    gradientPaint.setShader(s);
+    gradientPaint.setShader(SkGradientShader::MakeRadial(
+        center, radius, colors, pos, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
 
     // Test using the image filter
     {
index 14bdcf2d81fbecf110430d961c77a4f9c2212791..4da7aab5116d1fc481806a04d7cda00d70bda76a 100644 (file)
@@ -22,9 +22,8 @@ DEF_TEST(PictureShader_empty, reporter) {
     SkCanvas canvas(bitmap);
     canvas.clear(SK_ColorGREEN);
 
-    SkShader* shader = SkShader::CreatePictureShader(
-            nullptr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
-    paint.setShader(shader)->unref();
+    paint.setShader(SkShader::MakePictureShader(
+            nullptr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr));
 
     canvas.drawRect(SkRect::MakeWH(1,1), paint);
     REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
@@ -32,10 +31,9 @@ DEF_TEST(PictureShader_empty, reporter) {
 
     SkPictureRecorder factory;
     factory.beginRecording(0, 0, nullptr, 0);
-    SkAutoTUnref<SkPicture> picture(factory.endRecording());
-    shader = SkShader::CreatePictureShader(
-            picture.get(), SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
-    paint.setShader(shader)->unref();
+    sk_sp<SkPicture> picture(factory.endRecording());
+    paint.setShader(SkShader::MakePictureShader(std::move(picture), SkShader::kClamp_TileMode,
+                                                SkShader::kClamp_TileMode, nullptr, nullptr));
 
     canvas.drawRect(SkRect::MakeWH(1,1), paint);
     REPORTER_ASSERT(reporter, *bitmap.getAddr32(0,0) == SK_ColorGREEN);
index 448e079958ef5a01444fc0c5a9b009c16325b27e..3654a77173e9fcd1e872d22c1b47dbba2e727f10 100644 (file)
@@ -79,10 +79,9 @@ static void test_analysis(skiatest::Reporter* reporter) {
         bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
         bitmap.eraseColor(SK_ColorBLUE);
         *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
-        SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode,
-                                                        SkShader::kClamp_TileMode);
-        paint.setShader(shader)->unref();
-        REPORTER_ASSERT(reporter, shader->isABitmap());
+        paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_TileMode,
+                                                   SkShader::kClamp_TileMode));
+        REPORTER_ASSERT(reporter, paint.getShader()->isABitmap());
 
         canvas->drawRect(SkRect::MakeWH(10, 10), paint);
     }
@@ -1389,7 +1388,7 @@ DEF_TEST(Picture_getRecordingCanvas, r) {
 DEF_TEST(MiniRecorderLeftHanging, r) {
     // Any shader or other ref-counted effect will do just fine here.
     SkPaint paint;
-    paint.setShader(SkShader::CreateColorShader(SK_ColorRED))->unref();
+    paint.setShader(SkShader::MakeColorShader(SK_ColorRED));
 
     SkMiniRecorder rec;
     REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint));
index b4bc58dddde0333d8c081d4fc71bdb5dc026fb74..9d7fda5483d5b026b4bd0aaa3d7a5f8fd0da3cc7 100644 (file)
@@ -58,7 +58,7 @@ DEF_TEST(Recorder_RefLeaking, r) {
 
     SkRect bounds = SkRect::MakeWH(320, 240);
     SkPaint paint;
-    paint.setShader(SkShader::CreateEmptyShader())->unref();
+    paint.setShader(SkShader::MakeEmptyShader());
 
     REPORTER_ASSERT(r, paint.getShader()->unique());
     {
index 90d25d731acfaa43467f0b60c0b5b3c52c963a91..698d5442d8eea115ba1769c47e82fe3938bc2e33 100644 (file)
@@ -17,42 +17,36 @@ static void test_bitmap(skiatest::Reporter* reporter) {
     bmp.setInfo(info);
 
     // test 1: bitmap without pixel data
-    SkShader* shader = SkShader::CreateBitmapShader(bmp,
+    auto shader = SkShader::MakeBitmapShader(bmp,
         SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
     REPORTER_ASSERT(reporter, shader);
     REPORTER_ASSERT(reporter, !shader->isOpaque());
-    shader->unref();
 
     // From this point on, we have pixels
     bmp.allocPixels(info);
 
     // test 2: not opaque by default
-    shader = SkShader::CreateBitmapShader(bmp,
+    shader = SkShader::MakeBitmapShader(bmp,
         SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
     REPORTER_ASSERT(reporter, shader);
     REPORTER_ASSERT(reporter, !shader->isOpaque());
-    shader->unref();
 
     // test 3: explicitly opaque
     bmp.setAlphaType(kOpaque_SkAlphaType);
-    shader = SkShader::CreateBitmapShader(bmp,
+    shader = SkShader::MakeBitmapShader(bmp,
         SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
     REPORTER_ASSERT(reporter, shader);
     REPORTER_ASSERT(reporter, shader->isOpaque());
-    shader->unref();
 
     // test 4: explicitly not opaque
     bmp.setAlphaType(kPremul_SkAlphaType);
-    shader = SkShader::CreateBitmapShader(bmp,
+    shader = SkShader::MakeBitmapShader(bmp,
         SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
     REPORTER_ASSERT(reporter, shader);
     REPORTER_ASSERT(reporter, !shader->isOpaque());
-    shader->unref();
-
 }
 
-static void test_gradient(skiatest::Reporter* reporter)
-{
+static void test_gradient(skiatest::Reporter* reporter) {
     SkPoint pts[2];
     pts[0].iset(0, 0);
     pts[1].iset(1, 0);
@@ -64,39 +58,33 @@ static void test_gradient(skiatest::Reporter* reporter)
     // test 1: all opaque
     colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
     colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
-    SkShader* grad = SkGradientShader::CreateLinear(pts, colors, pos, count,
-                                                    mode);
+    auto grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
     REPORTER_ASSERT(reporter, grad);
     REPORTER_ASSERT(reporter, grad->isOpaque());
-    grad->unref();
 
     // test 2: all 0 alpha
     colors[0] = SkColorSetARGB(0, 0, 0, 0);
     colors[1] = SkColorSetARGB(0, 0, 0, 0);
-    grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
+    grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
     REPORTER_ASSERT(reporter, grad);
     REPORTER_ASSERT(reporter, !grad->isOpaque());
-    grad->unref();
 
     // test 3: one opaque, one transparent
     colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
     colors[1] = SkColorSetARGB(0x40, 0, 0, 0);
-    grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
+    grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
     REPORTER_ASSERT(reporter, grad);
     REPORTER_ASSERT(reporter, !grad->isOpaque());
-    grad->unref();
 
     // test 4: test 3, swapped
     colors[0] = SkColorSetARGB(0x40, 0, 0, 0);
     colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
-    grad = SkGradientShader::CreateLinear(pts, colors, pos, count, mode);
+    grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
     REPORTER_ASSERT(reporter, grad);
     REPORTER_ASSERT(reporter, !grad->isOpaque());
-    grad->unref();
 }
 
-static void test_color(skiatest::Reporter* reporter)
-{
+static void test_color(skiatest::Reporter* reporter) {
     SkColorShader colorShader1(SkColorSetARGB(0,0,0,0));
     REPORTER_ASSERT(reporter, !colorShader1.isOpaque());
     SkColorShader colorShader2(SkColorSetARGB(0xFF,0,0,0));