sk_sp versions of newWithColorFilter and newWithLocalMatrix
authorreed <reed@google.com>
Thu, 10 Mar 2016 14:36:49 +0000 (06:36 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 10 Mar 2016 14:36:49 +0000 (06:36 -0800)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1782703002

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

gm/colorfilterimagefilter.cpp
gm/perlinnoise.cpp
include/core/SkShader.h
samplecode/SamplePatch.cpp
src/core/SkBlitter.cpp
src/core/SkColorFilterShader.cpp
src/core/SkLocalMatrixShader.cpp
tests/SkColor4fTest.cpp

index b0f67bff300e8beb8bea7099a262573efc56a722..fa33a9c5cba739b80f6e80df8a2a9bfd5ea2fb55 100644 (file)
@@ -212,7 +212,7 @@ DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
         for (int x = -1; x < filters.count(); ++x) {
             SkColorFilter* filter = x >= 0 ? filters[x] : nullptr;
 
-            paint.setShader(shader->newWithColorFilter(filter))->unref();
+            paint.setShader(shader->makeWithColorFilter(filter));
             canvas->drawRect(r, paint);
             canvas->translate(150, 0);
         }
index 7e6f70e5de41520c4dbd1aa6126ad389fb67eb09..92f0f963c3ee70bcb4b0efe53b713237cd10974d 100644 (file)
@@ -154,7 +154,7 @@ protected:
 
         SkMatrix lm;
         lm.setScale(2, 2);
-        paint.setShader(paint.getShader()->newWithLocalMatrix(lm))->unref();
+        paint.setShader(paint.getShader()->makeWithLocalMatrix(lm));
         r.fRight += r.width();
         r.fBottom += r.height();
 
index 3e4093645cc2f6ddc301171fc1021f0978293b1a..0bcb98a07e98ebc58e3014911b60b00273bb975a 100644 (file)
@@ -323,13 +323,13 @@ public:
      *  Return a shader that will apply the specified localMatrix to this shader.
      *  The specified matrix will be applied before any matrix associated with this shader.
      */
-    SkShader* newWithLocalMatrix(const SkMatrix&) const;
+    sk_sp<SkShader> makeWithLocalMatrix(const SkMatrix&) const;
 
     /**
      *  Create a new shader that produces the same colors as invoking this shader and then applying
      *  the colorfilter.
      */
-    SkShader* newWithColorFilter(SkColorFilter*) const;
+    sk_sp<SkShader> makeWithColorFilter(SkColorFilter*) const;
 
     //////////////////////////////////////////////////////////////////////////
     //  Factory methods for stock shaders
@@ -359,6 +359,13 @@ public:
     static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode* xfer);
     static SkShader* CreatePictureShader(const SkPicture* src, TileMode tmx, TileMode tmy,
                                          const SkMatrix* localMatrix, const SkRect* tile);
+
+    SkShader* newWithLocalMatrix(const SkMatrix& matrix) const {
+        return this->makeWithLocalMatrix(matrix).release();
+    }
+    SkShader* newWithColorFilter(SkColorFilter* filter) const {
+        return this->makeWithColorFilter(filter).release();
+    }
 #endif
 
     /**
index c9ecb709900da8fa6293d947843763264099420f..3ce350ac478aa6843d06c5c7fa29f19d26b2fda3 100644 (file)
@@ -289,14 +289,12 @@ protected:
         if (true) {
             SkMatrix m;
             m.setSkew(1, 0);
-            SkShader* s = paint.getShader()->newWithLocalMatrix(m);
-            paint.setShader(s)->unref();
+            paint.setShader(paint.getShader()->makeWithLocalMatrix(m));
         }
         if (true) {
             SkMatrix m;
             m.setRotate(fAngle);
-            SkShader* s = paint.getShader()->newWithLocalMatrix(m);
-            paint.setShader(s)->unref();
+            paint.setShader(paint.getShader()->makeWithLocalMatrix(m));
         }
         patch.setBounds(fSize1.fX, fSize1.fY);
         drawpatches(canvas, paint, nu, nv, &patch);
index 9fcab9c98225ec5ea18ccb1e8f8b40a0eb772fe7..04897e3828af4ec077ec27102e88b279437969a8 100644 (file)
@@ -867,8 +867,8 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
 
     if (cf) {
         SkASSERT(shader);
-        shader = shader->newWithColorFilter(cf);
-        paint.writable()->setShader(shader)->unref();
+        paint.writable()->setShader(shader->makeWithColorFilter(cf));
+        shader = paint->getShader();
         // blitters should ignore the presence/absence of a filter, since
         // if there is one, the shader will take care of it.
     }
index f5a3b9c9e16e20e781308aa09d20d01a10f8dda1..2e426a17eded3255f99f12f562cda2b86f510691 100644 (file)
@@ -137,10 +137,10 @@ void SkColorFilterShader::toString(SkString* str) const {
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-SkShader* SkShader::newWithColorFilter(SkColorFilter* filter) const {
+sk_sp<SkShader> SkShader::makeWithColorFilter(SkColorFilter* filter) const {
     SkShader* base = const_cast<SkShader*>(this);
     if (!filter) {
-        return SkRef(base);
+        return sk_ref_sp(base);
     }
-    return new SkColorFilterShader(base, filter);
+    return sk_make_sp<SkColorFilterShader>(base, filter);
 }
index 42b378d61a69d033fd1090af18239d1587f7e5f2..ddd6114ca870c95c6e9095bf5428c314c6d38134 100644 (file)
@@ -14,7 +14,7 @@ SkFlattenable* SkLocalMatrixShader::CreateProc(SkReadBuffer& buffer) {
     if (!baseShader) {
         return nullptr;
     }
-    return baseShader->newWithLocalMatrix(lm);
+    return baseShader->makeWithLocalMatrix(lm).release();
 }
 
 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const {
@@ -47,9 +47,9 @@ void SkLocalMatrixShader::toString(SkString* str) const {
 }
 #endif
 
-SkShader* SkShader::newWithLocalMatrix(const SkMatrix& localMatrix) const {
+sk_sp<SkShader> SkShader::makeWithLocalMatrix(const SkMatrix& localMatrix) const {
     if (localMatrix.isIdentity()) {
-        return SkRef(const_cast<SkShader*>(this));
+        return sk_ref_sp(const_cast<SkShader*>(this));
     }
 
     const SkMatrix* lm = &localMatrix;
@@ -63,5 +63,5 @@ SkShader* SkShader::newWithLocalMatrix(const SkMatrix& localMatrix) const {
         baseShader = proxy.get();
     }
 
-    return new SkLocalMatrixShader(baseShader, *lm);
+    return sk_make_sp<SkLocalMatrixShader>(baseShader, *lm);
 }
index 62eed211dfdbc5b412839bc0d48be316a968922e..0b5a4e05f7d6adf90ffbe13487039b0cb530b5df 100644 (file)
@@ -125,8 +125,7 @@ static sk_sp<SkShader> make_grad_sh() {
 
 static sk_sp<SkShader> make_cf_sh() {
     SkAutoTUnref<SkColorFilter> filter(make_mx_cf());
-    sk_sp<SkShader> shader(make_color_sh());
-    return sk_sp<SkShader>(shader->newWithColorFilter(filter));
+    return make_color_sh()->makeWithColorFilter(filter);
 }
 
 static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int count,