partial switch over to sp usage of shaders
authorreed <reed@google.com>
Wed, 9 Mar 2016 17:50:50 +0000 (09:50 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 9 Mar 2016 17:50:50 +0000 (09:50 -0800)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1776973003

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

28 files changed:
gm/aarectmodes.cpp
gm/bigmatrix.cpp
gm/bitmaprect.cpp
gm/bleed.cpp
gm/blurrect.cpp
gm/blurroundrect.cpp
gm/bmpfilterqualityrepeat.cpp
gm/circles.cpp
gm/clippedbitmapshaders.cpp
gm/color4f.cpp
gm/colorcube.cpp
gm/coloremoji.cpp
gm/colorfilterimagefilter.cpp
gm/colorfilters.cpp
gm/colormatrix.cpp
gm/colortype.cpp
gm/colortypexfermode.cpp
gm/composeshader.cpp
gm/constcolorprocessor.cpp
gm/convexpolyclip.cpp
gm/drawbitmaprect.cpp
gm/drawminibitmaprect.cpp
gm/filltypespersp.cpp
gm/gamma.cpp
gm/gammatext.cpp
gm/giantbitmap.cpp
gm/glyph_pos_align.cpp
src/utils/SkLua.cpp

index fb5145bc5f840dd049614c3df05d9fc3a4f9ac63..badd1ae450c6299b9ce08d49fa26b879eb9348f2 100644 (file)
@@ -107,7 +107,7 @@ static SkScalar drawCell(SkCanvas* canvas, SkXfermode* mode,
     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;
@@ -115,12 +115,8 @@ static SkShader* make_bg_shader() {
                                                              0xCF, 0xCE);
 
     const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(6), SkIntToScalar(6));
-    SkShader* s = SkShader::CreateBitmapShader(bm,
-                                               SkShader::kRepeat_TileMode,
-                                               SkShader::kRepeat_TileMode,
-                                               &m);
-
-    return s;
+    return SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
+                                      &m);
 }
 
 namespace skiagm {
@@ -129,7 +125,7 @@ namespace skiagm {
         SkPaint fBGPaint;
     public:
         AARectModesGM () {
-            fBGPaint.setShader(make_bg_shader())->unref();
+            fBGPaint.setShader(make_bg_shader());
         }
 
     protected:
index 2d2b7d9f7ee95a53f08c58a8b36f81db175b8293..b39f2eab73aeb9db2ff979624ef047cf0b2c566c 100644 (file)
@@ -55,12 +55,8 @@ DEF_SIMPLE_GM_BG(bigmatrix, canvas, 50, 50,
         SkMatrix s;
         s.reset();
         s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
-        SkShader* shader = SkShader::CreateBitmapShader(
-                                            bmp,
-                                            SkShader::kRepeat_TileMode,
-                                            SkShader::kRepeat_TileMode,
-                                            &s);
-        paint.setShader(shader)->unref();
+        paint.setShader(SkShader::MakeBitmapShader(bmp, SkShader::kRepeat_TileMode,
+                                                   SkShader::kRepeat_TileMode, &s));
         paint.setAntiAlias(false);
         paint.setFilterQuality(kLow_SkFilterQuality);
         rect.setLTRB(pt.fX - small, pt.fY - small,
index f855ad77c45bc6f94dac9ccca7857815cd2f7bb4..bf06adbe1d0b3c0f658474d6b8b9f0f4e193e47b 100644 (file)
@@ -1,10 +1,10 @@
-
 /*
  * Copyright 2011 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 "SkCanvas.h"
 #include "SkGradientShader.h"
@@ -23,8 +23,8 @@ static void make_bitmap(SkBitmap* bitmap) {
     paint.setAntiAlias(true);
     const SkPoint pts[] = { { 0, 0 }, { 64, 64 } };
     const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE };
-    paint.setShader(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
-                                                   SkShader::kClamp_TileMode))->unref();
+    paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+                                                 SkShader::kClamp_TileMode));
     canvas.drawCircle(32, 32, 32, paint);
 }
 
index 1a96fdbfec5bd4247091ef83ae2d41c2ac9aa06b..5a0416293887e072770f05b13c409ef9ceeabd40 100644 (file)
@@ -277,13 +277,13 @@ static bool make_ringed_oversized_alpha_texture_bitmap(GrContext* ctx, TestPixel
         ctx, result, width, height, kAlpha_8_GrPixelConfig, kZero, kOne, k3Q, kHalf, k1Q);
 }
 
-static SkShader* make_shader() {
+static sk_sp<SkShader> make_shader() {
     static const SkPoint pts[] = { {0, 0}, {20, 20} };
     static const SkColor colors[] = { SK_ColorGREEN, SK_ColorYELLOW };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kMirror_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kMirror_TileMode);
 }
 
-static SkShader* make_null_shader() { return nullptr; }
+static sk_sp<SkShader> make_null_shader() { return nullptr; }
 
 enum BleedTest {
     kUseBitmap_BleedTest,
@@ -300,7 +300,7 @@ enum BleedTest {
 const struct {
     const char* fName;
     bool (*fPixelMaker)(GrContext*, TestPixels* result, int width, int height);
-    SkShader* (*fShaderMaker)();
+    sk_sp<SkShader> (*fShaderMaker)();
 } gBleedRec[] = {
     { "bleed",                          make_ringed_color_bitmap,                   make_null_shader },
     { "bleed_texture_bmp",              make_ringed_oversized_color_texture_bitmap, make_null_shader },
@@ -468,7 +468,7 @@ protected:
             return;
         }
 
-        fShader.reset(gBleedRec[fBT].fShaderMaker());
+        fShader = gBleedRec[fBT].fShaderMaker();
 
         canvas->clear(SK_ColorGRAY);
         SkTDArray<SkMatrix> matrices;
@@ -582,13 +582,13 @@ private:
     static const int kSmallTextureSize = 6;
     static const int kMaxTileSize = 32;
 
-    bool                    fCreatedPixels;
-    TestPixels              fBigTestPixels;
-    TestPixels              fSmallTestPixels;
+    bool            fCreatedPixels;
+    TestPixels      fBigTestPixels;
+    TestPixels      fSmallTestPixels;
 
-    SkAutoTUnref<SkShader>  fShader;
+    sk_sp<SkShader> fShader;
 
-    const BleedTest         fBT;
+    const BleedTest fBT;
 
     typedef GM INHERITED;
 };
index 55c592b6276c85008a2db9e71df1de0d1f94e358..0fe866feb2b60d26d7a7fd467d44e46df5dcf15d 100644 (file)
@@ -58,7 +58,7 @@ static void draw_donut_skewed(SkCanvas* canvas, const SkRect& r, const SkPaint&
 /*
  * Spits out a dummy gradient to test blur with shader on paint
  */
-static SkShader* MakeRadial() {
+static sk_sp<SkShader> MakeRadial() {
     SkPoint pts[2] = {
         { 0, 0 },
         { SkIntToScalar(100), SkIntToScalar(100) }
@@ -74,10 +74,10 @@ static SkShader* MakeRadial() {
                 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,
-                                                  colors, pos, SK_ARRAY_COUNT(colors), tm,
-                                                  0, &scale);
+    return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
+                                                 center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 colors, pos, SK_ARRAY_COUNT(colors), tm,
+                                                 0, &scale);
 }
 
 typedef void (*PaintProc)(SkPaint*, SkScalar width);
@@ -123,7 +123,7 @@ protected:
                 paint.setAlpha(fAlpha);
 
                 SkPaint paintWithRadial = paint;
-                paintWithRadial.setShader(MakeRadial())->unref();
+                paintWithRadial.setShader(MakeRadial());
 
                 static const Proc procs[] = {
                     fill_rect, draw_donut, draw_donut_skewed
index c3cdb66673e19e3bde2ec4bf6aa1812cbd19fe7a..ef20e25860708b5da20c65d533333c3bfbb9bcd5 100644 (file)
@@ -92,7 +92,7 @@ private:
 /*
  * Spits out a dummy gradient to test blur with shader on paint
  */
-static SkShader* MakeRadial() {
+static sk_sp<SkShader> MakeRadial() {
     SkPoint pts[2] = {
         { 0, 0 },
         { SkIntToScalar(100), SkIntToScalar(100) }
@@ -108,10 +108,10 @@ static SkShader* MakeRadial() {
                 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,
-                                                   colors, pos, SK_ARRAY_COUNT(colors), tm,
-                                                   0, &scale);
+    return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
+                                                 center0, (pts[1].fX - pts[0].fX) / 2,
+                                                 colors, pos, SK_ARRAY_COUNT(colors), tm,
+                                                 0, &scale);
 }
 
 // Simpler blurred RR test cases where all the radii are the same.
@@ -153,7 +153,7 @@ protected:
 
                     bool useRadial = SkToBool(k);
                     if (useRadial) {
-                        paint.setShader(MakeRadial())->unref();
+                        paint.setShader(MakeRadial());
                     }
 
                     SkRRect rrect;
index c147014a87b5c1c1ab5a3b27b9b5426994d041ff..b32a99a454848108e2778be3ae2874d18187e8f2 100644 (file)
@@ -60,7 +60,7 @@ protected:
             lm.setTranslateY(330);
 
             static const SkShader::TileMode kTM = SkShader::kRepeat_TileMode;
-            bmpPaint.setShader(SkShader::CreateBitmapShader(fBmp, kTM, kTM, &lm))->unref();
+            bmpPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTM, kTM, &lm));
             SkRect rect = SkRect::MakeLTRB(20, 60, 220, 210);
             canvas->drawRect(rect, bmpPaint);
             paint.setAntiAlias(true);
index 369548cc5996d878aad3568dc818bd805b2a5fa5..4d3e33daee5aab875b025394984668ba33b923de 100644 (file)
@@ -67,13 +67,8 @@ protected:
         SkPoint center = SkPoint::Make(SkIntToScalar(40), SkIntToScalar(40));
         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 6225abeec1b983e31b8539b4b40afd5978ad6bea..4b77aba9d05f6e860d08f2c8ed4cd75aedc71459 100644 (file)
@@ -82,11 +82,8 @@ protected:
         s.reset();
         s.setScale(8, 8);
         s.postTranslate(SLIDE_SIZE / 2, SLIDE_SIZE / 2);
-        SkShader* shader = SkShader::CreateBitmapShader(
-                bmp, fMode, fMode, &s);
-
         SkPaint paint;
-        paint.setShader(shader)->unref();
+        paint.setShader(SkShader::MakeBitmapShader(bmp, fMode, fMode, &s));
 
         if (fHQ) {
             paint.setFilterQuality(kHigh_SkFilterQuality);
index 9e6fcf6060ed07b959b38adc2582fd2921c7d14d..2d5b7d2c1ae09a31e4d1f704916828b4941126db 100644 (file)
 #include "SkColorMatrixFilter.h"
 #include "SkGradientShader.h"
 
-static SkShader* make_opaque_color() {
-    return SkShader::CreateColorShader(0xFFFF0000);
+static sk_sp<SkShader> make_opaque_color() {
+    return SkShader::MakeColorShader(0xFFFF0000);
 }
 
-static SkShader* make_alpha_color() {
-    return SkShader::CreateColorShader(0x80FF0000);
+static sk_sp<SkShader> make_alpha_color() {
+    return SkShader::MakeColorShader(0x80FF0000);
 }
 
 static SkColorFilter* make_cf_null() {
@@ -51,12 +51,12 @@ static SkColorFilter* make_cf2() {
 
 static void draw_into_canvas(SkCanvas* canvas) {
     const SkRect r = SkRect::MakeWH(50, 100);
-    SkShader* (*shaders[])() { make_opaque_color, make_alpha_color };
+    sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color };
     SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
     
     SkPaint paint;
     for (auto shProc : shaders) {
-        paint.setShader(shProc())->unref();
+        paint.setShader(shProc());
         for (auto cfProc : filters) {
             SkSafeUnref(paint.setColorFilter(cfProc()));
             canvas->drawRect(r, paint);
index fa9eea9f99098d6b5020070fd233367288ec1ca5..01aaf156107968e1220681f6331317ae5ae95a04 100644 (file)
 
 namespace skiagm {
 
-static SkShader* MakeLinear() {
+static sk_sp<SkShader> MakeLinear() {
     static const SkPoint pts[2] = {
             { 0, 0 },
             { SkIntToScalar(80), SkIntToScalar(80) }
         };
     static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE };
-    return SkGradientShader::CreateLinear(
-        pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, &SkMatrix::I());
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0,
+                                        &SkMatrix::I());
 }
 
 class ColorCubeGM : public GM {
@@ -63,11 +63,8 @@ protected:
         canvas.clear(0x00000000);
         SkPaint paint;
         paint.setAntiAlias(true);
-        SkShader* shader = MakeLinear();
-        paint.setShader(shader);
-        SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) };
-        canvas.drawRect(r, paint);
-        shader->unref();
+        paint.setShader(MakeLinear());
+        canvas.drawRect(SkRect::MakeWH(80, 80), paint);
     }
 
     void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) {
index 6dddc0fdc6181dafe98ceb3d0f15a4c015b37526..78c347c079655442cafa65903fd6656fb24b5773 100644 (file)
 /*
  * Spits out a dummy gradient to test blur with shader on paint
  */
-static SkShader* MakeLinear() {
+static sk_sp<SkShader> MakeLinear() {
     static const SkPoint     kPts[] = { { 0, 0 }, { 32, 32 } };
     static const SkScalar    kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
     static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 };
-    return SkGradientShader::CreateLinear(kPts, kColors, kPos,
-                                          SK_ARRAY_COUNT(kColors), SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(kPts, kColors, kPos, SK_ARRAY_COUNT(kColors),
+                                        SkShader::kClamp_TileMode);
 }
 
 static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
@@ -94,7 +94,7 @@ protected:
                     SkPaint shaderPaint;
                     shaderPaint.setTypeface(paint.getTypeface());
                     if (SkToBool(makeLinear)) {
-                        shaderPaint.setShader(MakeLinear())->unref();
+                        shaderPaint.setShader(MakeLinear());
                     }
 
                     if (SkToBool(makeBlur) && SkToBool(makeGray)) {
index daebe0d3df92dca608e0f2142c5a02f87a260e3b..4ab91f1afbe4e539b79075ee11b9d0ecefc3eb83 100644 (file)
@@ -53,35 +53,36 @@ static void sk_gm_get_colorfilters(SkTDArray<SkColorFilter*>* array) {
 #include "SkImage.h"
 #include "Resources.h"
 
-static SkShader* sh_make_lineargradient0() {
+static sk_sp<SkShader> sh_make_lineargradient0() {
     const SkPoint pts[] = { { 0, 0 }, { 100, 100 } };
     const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
 }
 
-static SkShader* sh_make_lineargradient1() {
+static sk_sp<SkShader> sh_make_lineargradient1() {
     const SkPoint pts[] = { { 0, 0 }, { 100, 100 } };
     const SkColor colors[] = { SK_ColorRED, 0x0000FF00, SK_ColorBLUE };
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 3, SkShader::kRepeat_TileMode);
 }
 
-static SkShader* sh_make_image() {
+static sk_sp<SkShader> sh_make_image() {
     SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png"));
     if (!image) {
         return nullptr;
     }
-    return image->newShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
+    return sk_sp<SkShader>(image->newShader(SkShader::kRepeat_TileMode,
+                                            SkShader::kRepeat_TileMode));
 }
 
 static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) {
-    if (SkShader* shader = sh_make_lineargradient0()) {
-        *array->append() = shader;
+    if (auto shader = sh_make_lineargradient0()) {
+        *array->append() = shader.release();
     }
-    if (SkShader* shader = sh_make_lineargradient1()) {
-        *array->append() = shader;
+    if (auto shader = sh_make_lineargradient1()) {
+        *array->append() = shader.release();
     }
-    if (SkShader* shader = sh_make_image()) {
-        *array->append() = shader;
+    if (auto shader = sh_make_image()) {
+        *array->append() = shader.release();
     }
 }
 
index dcd24d9ce431536dbcd1a84b319985de86f5edb4..eaee39dd55b729df124a2e7fc1b3f58a27059e2d 100644 (file)
@@ -10,7 +10,7 @@
 #include "SkColorMatrixFilter.h"
 #include "SkGradientShader.h"
 
-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() },
@@ -19,9 +19,8 @@ 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);
 }
 
 typedef void (*InstallPaint)(SkPaint*, uint32_t, uint32_t);
@@ -53,7 +52,7 @@ protected:
         SkPaint paint;
         SkRect r;
         r.setWH(600, 50);
-        paint.setShader(make_shader(r))->unref();
+        paint.setShader(make_shader(r));
 
         const struct {
             InstallPaint    fProc;
index b466188c6a063c484a2899d6dc4ca3121508155f..b6e83d3ceb9a2a0f270eee7679ab8c0b4c53864f 100644 (file)
@@ -67,8 +67,8 @@ protected:
         SkPoint pts[] = {{0, 0}, {SkIntToScalar(width), SkIntToScalar(height)}};
         SkColor colors[] = {0x00000000, 0xFFFFFFFF};
         SkPaint paint;
-        paint.setShader(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
-                                                       SkShader::kClamp_TileMode))->unref();
+        paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+                                                     SkShader::kClamp_TileMode));
         canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)), paint);
         return SkImage::NewFromBitmap(bm);
     }
index 76b13817a945452e369a50075e6a95e7ca2ef8f4..c9314de2a456479eecd88b92fcd3cec6c41ac9e1 100644 (file)
@@ -28,15 +28,12 @@ protected:
         };
         SkMatrix local;
         local.setRotate(180);
-        SkShader* s = SkGradientShader::CreateSweep(0,0, colors, nullptr,
-                                                    SK_ARRAY_COUNT(colors), 0, &local);
-
         SkPaint paint;
         paint.setAntiAlias(true);
-        paint.setShader(s)->unref();
+        paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                                    0, &local));
 
-        SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif",
-                                                            SkTypeface::kBold);
+        SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
         if (nullptr == orig) {
             orig = SkTypeface::RefDefault();
         }
index 55d7697e3593ef68249be025b271bdbda7ce2901..3489f3655789f94c8284322a84a7bc12da4efa2c 100644 (file)
@@ -35,15 +35,12 @@ protected:
         };
         SkMatrix local;
         local.setRotate(180);
-        SkShader* s = SkGradientShader::CreateSweep(0,0, colors, nullptr,
-                                                    SK_ARRAY_COUNT(colors), 0, &local);
-
         SkPaint paint;
         paint.setAntiAlias(true);
-        paint.setShader(s)->unref();
+        paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                                    0, &local));
 
-        SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif",
-                                                            SkTypeface::kBold);
+        SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
         if (nullptr == orig) {
             orig = SkTypeface::RefDefault();
         }
@@ -105,10 +102,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);
@@ -153,7 +148,6 @@ protected:
                 y += h + SkIntToScalar(30);
             }
         }
-        s->unref();
     }
 
 private:
index 2f3d99d36453f5ec586d83ef9819254f6471fa60..c43b443a07f0725c7358b753ac18a94c72ca8462 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "gm.h"
 
-#include "SkBitmapProcShader.h"
 #include "SkCanvas.h"
 #include "SkGradientShader.h"
 #include "SkGraphics.h"
@@ -15,7 +14,7 @@
 #include "SkString.h"
 #include "SkXfermode.h"
 
-static SkShader* make_shader(SkXfermode::Mode mode) {
+static sk_sp<SkShader> make_shader(SkXfermode::Mode mode) {
     SkPoint pts[2];
     SkColor colors[2];
 
@@ -23,19 +22,17 @@ static SkShader* make_shader(SkXfermode::Mode mode) {
     pts[1].set(SkIntToScalar(100), 0);
     colors[0] = SK_ColorRED;
     colors[1] = SK_ColorBLUE;
-    SkAutoTUnref<SkShader> shaderA(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
-                                                                  SkShader::kClamp_TileMode));
+    auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 
     pts[0].set(0, 0);
     pts[1].set(0, SkIntToScalar(100));
     colors[0] = SK_ColorBLACK;
     colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
-    SkAutoTUnref<SkShader> shaderB(SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
-                                                                  SkShader::kClamp_TileMode));
+    auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 
     SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode));
 
-    return SkShader::CreateComposeShader(shaderA, shaderB, xfer);
+    return SkShader::MakeComposeShader(std::move(shaderA), std::move(shaderB), xfer);
 }
 
 class ComposeShaderGM : public skiagm::GM {
@@ -44,10 +41,6 @@ public:
         fShader = make_shader(SkXfermode::kDstIn_Mode);
     }
 
-    virtual ~ComposeShaderGM() {
-        SkSafeUnref(fShader);
-    }
-
 protected:
     SkString onShortName() override {
         return SkString("composeshader");
@@ -58,9 +51,7 @@ protected:
     }
 
     void onDraw(SkCanvas* canvas) override {
-
         SkPaint paint;
-
         paint.setColor(SK_ColorGREEN);
         canvas->drawRectCoords(0, 0, SkIntToScalar(100), SkIntToScalar(100), paint);
         paint.setShader(fShader);
@@ -68,7 +59,7 @@ protected:
     }
 
 protected:
-    SkShader*   fShader;
+    sk_sp<SkShader> fShader;
 
 private:
     typedef GM INHERITED ;
@@ -88,9 +79,10 @@ protected:
     }
 
     void onDraw(SkCanvas* canvas) override {
-        SkAutoTUnref<SkShader> shader0(make_shader(SkXfermode::kDstIn_Mode));
-        SkAutoTUnref<SkShader> shader1(make_shader(SkXfermode::kSrcOver_Mode));
-        SkShader* shaders[] = { shader0.get(), shader1.get() };
+        sk_sp<SkShader> shaders[] = {
+            make_shader(SkXfermode::kDstIn_Mode),
+            make_shader(SkXfermode::kSrcOver_Mode),
+        };
 
         SkPaint paint;
         paint.setColor(SK_ColorGREEN);
@@ -98,7 +90,6 @@ protected:
         const SkRect r = SkRect::MakeXYWH(5, 5, 100, 100);
 
         for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
-            SkShader* shader = shaders[y];
             canvas->save();
             for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
                 paint.setAlpha(0xFF);
@@ -106,7 +97,7 @@ protected:
                 canvas->drawRect(r, paint);
 
                 paint.setAlpha(alpha);
-                paint.setShader(shader);
+                paint.setShader(shaders[y]);
                 canvas->drawRect(r, paint);
 
                 canvas->translate(r.width() + 5, 0);
@@ -148,25 +139,20 @@ static void draw_alpha8_bm(SkBitmap* bm, int length) {
 }
 
 // creates a linear gradient shader
-static SkShader* make_linear_gradient_shader(int length) {
+static sk_sp<SkShader> make_linear_gradient_shader(int length) {
     SkPoint pts[2];
     SkColor colors[2];
     pts[0].set(0, 0);
     pts[1].set(SkIntToScalar(length), 0);
     colors[0] = SK_ColorBLUE;
     colors[1] = SkColorSetARGB(0, 0, 0, 0xFF);
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 }
 
 
 class ComposeShaderBitmapGM : public skiagm::GM {
 public:
     ComposeShaderBitmapGM() {}
-    ~ComposeShaderBitmapGM() {
-        SkSafeUnref(fColorBitmapShader);
-        SkSafeUnref(fAlpha8BitmapShader);
-        SkSafeUnref(fLinearGradientShader);
-    }
 
 protected:
     void onOnceBeforeDraw() override {
@@ -174,10 +160,10 @@ protected:
         draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
         SkMatrix s;
         s.reset();
-        fColorBitmapShader = new SkBitmapProcShader(fColorBitmap, SkShader::kRepeat_TileMode,
-                                                    SkShader::kRepeat_TileMode, &s);
-        fAlpha8BitmapShader = new SkBitmapProcShader(fAlpha8Bitmap, SkShader::kRepeat_TileMode,
-                                                     SkShader::kRepeat_TileMode, &s);
+        fColorBitmapShader = SkShader::MakeBitmapShader(fColorBitmap, SkShader::kRepeat_TileMode,
+                                                        SkShader::kRepeat_TileMode, &s);
+        fAlpha8BitmapShader = SkShader::MakeBitmapShader(fAlpha8Bitmap, SkShader::kRepeat_TileMode,
+                                                         SkShader::kRepeat_TileMode, &s);
         fLinearGradientShader = make_linear_gradient_shader(squareLength);
     }
 
@@ -192,16 +178,12 @@ protected:
     void onDraw(SkCanvas* canvas) override {
         SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode));
 
-        // gradient should appear over color bitmap
-        SkAutoTUnref<SkShader> shader0(SkShader::CreateComposeShader(fLinearGradientShader,
-                                                           fColorBitmapShader,
-                                                           xfer));
-        // gradient should appear over alpha8 bitmap colorized by the paint color
-        SkAutoTUnref<SkShader> shader1(SkShader::CreateComposeShader(fLinearGradientShader,
-                                                           fAlpha8BitmapShader,
-                                                           xfer));
-
-        SkShader* shaders[] = { shader0.get(), shader1.get() };
+        sk_sp<SkShader> shaders[] = {
+            // gradient should appear over color bitmap
+            SkShader::MakeComposeShader(fLinearGradientShader, fColorBitmapShader, xfer),
+            // gradient should appear over alpha8 bitmap colorized by the paint color
+            SkShader::MakeComposeShader(fLinearGradientShader, fAlpha8BitmapShader, xfer),
+        };
 
         SkPaint paint;
         paint.setColor(SK_ColorYELLOW);
@@ -210,11 +192,10 @@ protected:
                                           SkIntToScalar(squareLength));
 
         for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
-            SkShader* shader = shaders[y];
             canvas->save();
             for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
                 paint.setAlpha(alpha);
-                paint.setShader(shader);
+                paint.setShader(shaders[y]);
                 canvas->drawRect(r, paint);
 
                 canvas->translate(r.width() + 5, 0);
@@ -234,9 +215,9 @@ private:
 
     SkBitmap fColorBitmap;
     SkBitmap fAlpha8Bitmap;
-    SkShader* fColorBitmapShader{nullptr};
-    SkShader* fAlpha8BitmapShader{nullptr};
-    SkShader* fLinearGradientShader{nullptr};
+    sk_sp<SkShader> fColorBitmapShader;
+    sk_sp<SkShader> fAlpha8BitmapShader;
+    sk_sp<SkShader> fLinearGradientShader;
 
     typedef GM INHERITED;
 };
index 177a8c9e4fdc5c5d99b9c2ef7d988d4211b11190..8c91a722eccd07a11b94efda440c6ff41f6e9aa8 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2015 Google Inc.
  *
@@ -43,8 +42,8 @@ protected:
     void onOnceBeforeDraw() override {
         SkColor colors[] = { 0xFFFF0000, 0x2000FF00, 0xFF0000FF};
         SkPoint pts[] = { SkPoint::Make(0, 0), SkPoint::Make(kRectSize, kRectSize) };
-        fShader.reset(SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
-                       SkShader::kClamp_TileMode));
+        fShader = SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                               SkShader::kClamp_TileMode);
     }
 
     void onDraw(SkCanvas* canvas) override {
@@ -179,7 +178,7 @@ protected:
 
 private:
     // Use this as a way of generating and input FP
-    SkAutoTUnref<SkShader>      fShader;
+    sk_sp<SkShader> fShader;
 
     static const SkScalar       kPad;
     static const SkScalar       kRectSize;
index e6f967c35ec30cdfceff5840553c7a64975ad2ca..ff83a2622586029f2dcbcae1d8db6e06a75e4535 100644 (file)
@@ -44,12 +44,12 @@ static SkBitmap make_bmp(int w, int h) {
     SkRect rect = SkRect::MakeWH(wScalar, hScalar);
     SkMatrix mat = SkMatrix::I();
     for (int i = 0; i < 4; ++i) {
-        paint.setShader(SkGradientShader::CreateRadial(
+        paint.setShader(SkGradientShader::MakeRadial(
                         pt, radius,
                         colors, pos,
                         SK_ARRAY_COUNT(colors),
                         SkShader::kRepeat_TileMode,
-                        0, &mat))->unref();
+                        0, &mat));
         canvas.drawRect(rect, paint);
         rect.inset(wScalar / 8, hScalar / 8);
         mat.preTranslate(6 * wScalar, 6 * hScalar);
index c90ac2eaa1474951fc7a320db4b50cda068a67ec..7ee2271c5cb10f91b7aaad2d57fc0dc1165973f9 100644 (file)
@@ -70,12 +70,12 @@ static SkImage* makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, int h) {
     SkRect rect = SkRect::MakeWH(wScalar, hScalar);
     SkMatrix mat = SkMatrix::I();
     for (int i = 0; i < 4; ++i) {
-        paint.setShader(SkGradientShader::CreateRadial(
+        paint.setShader(SkGradientShader::MakeRadial(
                         pt, radius,
                         colors, pos,
                         SK_ARRAY_COUNT(colors),
                         SkShader::kRepeat_TileMode,
-                        0, &mat))->unref();
+                        0, &mat));
         canvas->drawRect(rect, paint);
         rect.inset(wScalar / 8, hScalar / 8);
         mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
index 85071c56c4a9b91f069e86c99718b53b9414b834..f0ce1a2db6d57cfbf7181c27f0552a4c08b8533a 100644 (file)
@@ -46,12 +46,12 @@ static SkImage* makebm(SkCanvas* caller, int w, int h) {
     SkRect rect = SkRect::MakeWH(wScalar, hScalar);
     SkMatrix mat = SkMatrix::I();
     for (int i = 0; i < 4; ++i) {
-        paint.setShader(SkGradientShader::CreateRadial(
+        paint.setShader(SkGradientShader::MakeRadial(
                         pt, radius,
                         colors, pos,
                         SK_ARRAY_COUNT(colors),
                         SkShader::kRepeat_TileMode,
-                        0, &mat))->unref();
+                        0, &mat));
         canvas->drawRect(rect, paint);
         rect.inset(wScalar / 8, hScalar / 8);
         mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
index cc09b95bdad62827fda6cb9c4b1a95b06a075e98..07220046625384b305c88abb31dada589f8682df 100644 (file)
@@ -55,13 +55,12 @@ protected:
         SkPoint center = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(100));
         SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN};
         SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
-        SkShader* s = SkGradientShader::CreateRadial(center,
+        paint.setShader(SkGradientShader::MakeRadial(center,
                                                      SkIntToScalar(100),
                                                      colors,
                                                      pos,
                                                      SK_ARRAY_COUNT(colors),
-                                                     SkShader::kClamp_TileMode);
-        paint.setShader(s)->unref();
+                                                     SkShader::kClamp_TileMode));
         paint.setAntiAlias(aa);
 
         showPath(canvas,   0,   0, SkPath::kWinding_FillType,
@@ -85,13 +84,12 @@ protected:
                             SK_ColorYELLOW, SK_ColorWHITE};
         SkScalar pos[] = {0, SK_ScalarHalf / 2,
                           3 * SK_ScalarHalf / 2, SK_Scalar1};
-        SkShader* s = SkGradientShader::CreateRadial(center,
-                                                     SkIntToScalar(1000),
-                                                     colors,
-                                                     pos,
-                                                     SK_ARRAY_COUNT(colors),
-                                                     SkShader::kClamp_TileMode);
-        bkgnrd.setShader(s)->unref();
+        bkgnrd.setShader(SkGradientShader::MakeRadial(center,
+                                                      SkIntToScalar(1000),
+                                                      colors,
+                                                      pos,
+                                                      SK_ARRAY_COUNT(colors),
+                                                      SkShader::kClamp_TileMode));
         canvas->save();
             canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
             SkMatrix mat;
index 003061baebff4e66760e36c46b97f2676d626df5..1699083471fb948f6a02612a656d09f3a43d64d3 100644 (file)
@@ -88,8 +88,7 @@ DEF_SIMPLE_GM(gamma, canvas, 500, 200) {
     canvas->save();
 
     // Black/white dither, pixel perfect. This is ground truth.
-    p.setShader(SkShader::CreateBitmapShader(
-        ditherBmp, rpt, rpt))->unref();
+    p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt));
     p.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality);
     nextRect("Dither", "Reference");
 
@@ -98,15 +97,13 @@ DEF_SIMPLE_GM(gamma, canvas, 500, 200) {
     // the raster pipeline into *not* snapping to nearest.
     SkMatrix offsetMatrix = SkMatrix::Concat(
         SkMatrix::MakeScale(-1.0f), SkMatrix::MakeTrans(0.5f, 0.0f));
-    p.setShader(SkShader::CreateBitmapShader(
-        ditherBmp, rpt, rpt, &offsetMatrix))->unref();
+    p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &offsetMatrix));
     p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
     nextRect("Dither", "Bilerp");
 
     // Black/white dither, scaled down by 2x. Tests minification.
     SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f);
-    p.setShader(SkShader::CreateBitmapShader(
-        ditherBmp, rpt, rpt, &scaleMatrix))->unref();
+    p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix));
     p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
     nextRect("Dither", "Scale");
 
@@ -121,8 +118,8 @@ DEF_SIMPLE_GM(gamma, canvas, 500, 200) {
         SkPoint::Make(sz + (sz * 10), 0)
     };
     SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE };
-    p.setShader(SkGradientShader::CreateLinear(
-        points, colors, nullptr, 2, SkShader::kClamp_TileMode))->unref();
+    p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2,
+                                             SkShader::kClamp_TileMode));
     nextRect("Gradient", 0);
 
     // 50% grey from linear bitmap, with drawBitmap
@@ -132,12 +129,12 @@ DEF_SIMPLE_GM(gamma, canvas, 500, 200) {
     nextBitmap(srgbGreyBmp, "sRGB BMP");
 
     // Bitmap wrapped in a shader (linear):
-    p.setShader(SkShader::CreateBitmapShader(linearGreyBmp, rpt, rpt))->unref();
+    p.setShader(SkShader::MakeBitmapShader(linearGreyBmp, rpt, rpt));
     p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
     nextRect("Lnr BMP", "Shader");
 
     // Bitmap wrapped in a shader (sRGB):
-    p.setShader(SkShader::CreateBitmapShader(srgbGreyBmp, rpt, rpt))->unref();
+    p.setShader(SkShader::MakeBitmapShader(srgbGreyBmp, rpt, rpt));
     p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
     nextRect("sRGB BMP", "Shader");
 
index 63acb40c134336ed493075661ced90b985a27e80..e978b6bc05dad8ebd7d18a74d00ae089e4e5a0ab 100644 (file)
 #include "SkGradientShader.h"
 #include "SkTypeface.h"
 
-static SkShader* make_heatGradient(const SkPoint pts[2]) {
+static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) {
     const SkColor bw[] = { SK_ColorBLACK, SK_ColorWHITE };
 
-    return SkGradientShader::CreateLinear(pts, bw, nullptr,
-                                          SK_ARRAY_COUNT(bw),
-                                          SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, bw, nullptr, SK_ARRAY_COUNT(bw),
+                                        SkShader::kClamp_TileMode);
 }
 
 static bool setFont(SkPaint* paint, const char name[]) {
@@ -50,12 +49,11 @@ protected:
     }
 
     static void drawGrad(SkCanvas* canvas) {
-        SkPoint pts[] = { { 0, 0 }, { 0, SkIntToScalar(HEIGHT) } };
-        SkShader* s = make_heatGradient(pts);
+        const SkPoint pts[] = { { 0, 0 }, { 0, SkIntToScalar(HEIGHT) } };
 
         canvas->clear(SK_ColorRED);
         SkPaint paint;
-        paint.setShader(s)->unref();
+        paint.setShader(make_heatGradient(pts));
         SkRect r = { 0, 0, SkIntToScalar(1024), SkIntToScalar(HEIGHT) };
         canvas->drawRect(r, paint);
     }
@@ -101,12 +99,12 @@ DEF_GM( return new GammaTextGM; )
 
 //////////////////////////////////////////////////////////////////////////////
 
-static SkShader* make_gradient(SkColor c) {
+static sk_sp<SkShader> make_gradient(SkColor c) {
     const SkPoint pts[] = { { 0, 0 }, { 240, 0 } };
     SkColor colors[2];
     colors[0] = c;
     colors[1] = SkColorSetA(c, 0);
-    return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+    return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
 }
 
 static void set_face(SkPaint* paint) {
@@ -114,37 +112,30 @@ static void set_face(SkPaint* paint) {
     SkSafeUnref(paint->setTypeface(face));
 }
 
-static void draw_pair(SkCanvas* canvas, SkPaint* paint, SkShader* shader) {
+static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) {
     const char text[] = "Now is the time for all good";
     const size_t len = strlen(text);
     
     paint->setShader(nullptr);
     canvas->drawText(text, len, 10, 20, *paint);
-    paint->setShader(SkShader::CreateColorShader(paint->getColor()))->unref();
+    paint->setShader(SkShader::MakeColorShader(paint->getColor()));
     canvas->drawText(text, len, 10, 40, *paint);
     paint->setShader(shader);
     canvas->drawText(text, len, 10, 60, *paint);
 }
 
 class GammaShaderTextGM : public skiagm::GM {
-    SkShader* fShaders[3];
+    sk_sp<SkShader> fShaders[3];
     SkColor fColors[3];
 
 public:
     GammaShaderTextGM() {
         const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE };
         for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
-            fShaders[i] = nullptr;
             fColors[i] = colors[i];
         }
     }
 
-    ~GammaShaderTextGM() override {
-        for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) {
-            SkSafeUnref(fShaders[i]);
-        }
-    }
-
 protected:
     SkString onShortName() override {
         return SkString("gammagradienttext");
index 4005359acae3d09f0b4f83b4b86c90a7d5212453..e1ba737d2f6814fdca0f1e0f112046ac91947c0e 100644 (file)
@@ -104,9 +104,7 @@ protected:
             SkScalar scale = 11*SK_Scalar1/12;
             m.setScale(scale, scale);
         }
-        SkShader* s = SkShader::CreateBitmapShader(getBitmap(), fMode, fMode, &m);
-
-        paint.setShader(s)->unref();
+        paint.setShader(SkShader::MakeBitmapShader(getBitmap(), fMode, fMode, &m));
         paint.setFilterQuality(fDoFilter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
 
         canvas->translate(SkIntToScalar(50), SkIntToScalar(50));
index e80955e1acc91d121b1ed663a1e2bc904db71cec..0ac877d0d0a2d3855e98b847bd2ea6185f448cc3 100644 (file)
@@ -25,12 +25,8 @@ DEF_SIMPLE_GM_BG(glyph_pos_align, canvas, kWidth, kHeight, SK_ColorBLACK) {
         paint.setFakeBoldText(true);
         const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
         const SkPoint pts[] = {{0, 0}, {kWidth, kHeight}};
-        SkAutoTUnref<SkShader> grad(SkGradientShader::CreateLinear(pts, colors, nullptr,
-                                                                   SK_ARRAY_COUNT(colors),
-                                                                   SkShader::kMirror_TileMode));
-        paint.setShader(grad);
-
-
+        paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
+                                                     SkShader::kMirror_TileMode));
         paint.setTextAlign(SkPaint::kRight_Align);
         drawTestCase(canvas, "Right Align", kTextHeight, paint);
 
index dd746404015f4e13e676b1435f22502c85060fdc..b84ba0f5188e844c14d1c3805eb91f7f71f22d05 100644 (file)
@@ -82,6 +82,12 @@ template <typename T> T* push_ref(lua_State* L, T* ref) {
     return ref;
 }
 
+template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) {
+    *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release();
+    luaL_getmetatable(L, get_mtname<T>());
+    lua_setmetatable(L, -2);
+}
+
 template <typename T> T* get_ref(lua_State* L, int index) {
     return *(T**)luaL_checkudata(L, index, get_mtname<T>());
 }
@@ -1977,11 +1983,11 @@ static int lsk_newLinearGradient(lua_State* L) {
 
     SkPoint pts[] = { { x0, y0 }, { x1, y1 } };
     SkColor colors[] = { c0, c1 };
-    SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
-    if (nullptr == s) {
+    auto s = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+    if (!s) {
         lua_pushnil(L);
     } else {
-        push_ref(L, s)->unref();
+        push_ref(L, std::move(s));
     }
     return 1;
 }