SkShader* refAs... to sk_sp<SkShader> makeAs...

There appear to be no existing overriders of the refAs.. method outside
Skia.

Change-Id: Iab174e83023093b4d7fc0bd8907666b66ddb1eea
Reviewed-on: https://skia-review.googlesource.com/3746
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi
index 54ab773..9b59fb0 100644
--- a/gyp/skia_for_android_framework_defines.gypi
+++ b/gyp/skia_for_android_framework_defines.gypi
@@ -23,6 +23,7 @@
       'SK_SUPPORT_LEGACY_CLIP_REGIONOPS',
       'SK_SUPPORT_LEGACY_SHADER_ISABITMAP',
       'SK_SUPPORT_LEGACY_COLOR_SPACE_FACTORIES',
+      'SK_SUPPORT_LEGACY_SHADER_ASALOCALMATRIXSHADER',
     ],
   },
 }
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 161e608..c31ce73 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -469,6 +469,7 @@
     static sk_sp<SkShader> MakePictureShader(sk_sp<SkPicture> src, TileMode tmx, TileMode tmy,
                                              const SkMatrix* localMatrix, const SkRect* tile);
 
+#ifdef SK_SUPPORT_LEGACY_SHADER_ASALOCALMATRIXSHADER
     /**
      *  If this shader can be represented by another shader + a localMatrix, return that shader
      *  and, if not NULL, the localMatrix. If not, return NULL and ignore the localMatrix parameter.
@@ -476,7 +477,15 @@
      *  Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility
      *  of the caller to balance that with unref() when they are done.
      */
-    virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
+    SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const {
+        return this->makeAsALocalMatrixShader(localMatrix).release();
+    }
+#endif
+    /**
+     *  If this shader can be represented by another shader + a localMatrix, return that shader and
+     *  the localMatrix. If not, return nullptr and ignore the localMatrix parameter.
+     */
+    virtual sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const;
 
     SK_TO_STRING_VIRT()
     SK_DEFINE_FLATTENABLE_TYPE(SkShader)
diff --git a/public.bzl b/public.bzl
index 9308ecf..b27336b 100644
--- a/public.bzl
+++ b/public.bzl
@@ -614,6 +614,7 @@
     "SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
     "SK_SUPPORT_LEGACY_XFERMODE_OBJECT",
     "SK_SUPPORT_LEGACY_COLOR_SPACE_FACTORIES",
+    "SK_SUPPORT_LEGACY_SHADER_ASALOCALMATRIXSHADER",
 ]
 
 ################################################################################
diff --git a/src/core/SkLocalMatrixShader.cpp b/src/core/SkLocalMatrixShader.cpp
index cdd7533..506fd3e 100644
--- a/src/core/SkLocalMatrixShader.cpp
+++ b/src/core/SkLocalMatrixShader.cpp
@@ -70,14 +70,16 @@
 
     const SkMatrix* lm = &localMatrix;
 
-    SkShader* baseShader = const_cast<SkShader*>(this);
+    sk_sp<SkShader> baseShader;
     SkMatrix otherLocalMatrix;
-    SkAutoTUnref<SkShader> proxy(this->refAsALocalMatrixShader(&otherLocalMatrix));
+    sk_sp<SkShader> proxy(this->makeAsALocalMatrixShader(&otherLocalMatrix));
     if (proxy) {
         otherLocalMatrix.preConcat(localMatrix);
         lm = &otherLocalMatrix;
-        baseShader = proxy.get();
+        baseShader = proxy;
+    } else {
+        baseShader = sk_ref_sp(const_cast<SkShader*>(this));
     }
 
-    return sk_make_sp<SkLocalMatrixShader>(baseShader, *lm);
+    return sk_make_sp<SkLocalMatrixShader>(std::move(baseShader), *lm);
 }
diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h
index 849d9af..6bffb49 100644
--- a/src/core/SkLocalMatrixShader.h
+++ b/src/core/SkLocalMatrixShader.h
@@ -16,9 +16,9 @@
 
 class SkLocalMatrixShader : public SkShader {
 public:
-    SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix)
+    SkLocalMatrixShader(sk_sp<SkShader> proxy, const SkMatrix& localMatrix)
     : INHERITED(&localMatrix)
-    , fProxyShader(SkRef(proxy))
+    , fProxyShader(std::move(proxy))
     {}
 
     GradientType asAGradient(GradientInfo* info) const override {
@@ -29,11 +29,11 @@
     sk_sp<GrFragmentProcessor> asFragmentProcessor(const AsFPArgs&) const override;
 #endif
 
-    SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const override {
+    sk_sp<SkShader> makeAsALocalMatrixShader(SkMatrix* localMatrix) const override {
         if (localMatrix) {
             *localMatrix = this->getLocalMatrix();
         }
-        return SkRef(fProxyShader.get());
+        return fProxyShader;
     }
 
     SK_TO_STRING_OVERRIDE()
@@ -58,7 +58,7 @@
 #endif
 
 private:
-    SkAutoTUnref<SkShader> fProxyShader;
+    sk_sp<SkShader> fProxyShader;
 
     typedef SkShader INHERITED;
 };
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 15d7f4c..c452d07 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -230,7 +230,7 @@
 }
 #endif
 
-SkShader* SkShader::refAsALocalMatrixShader(SkMatrix*) const {
+sk_sp<SkShader> SkShader::makeAsALocalMatrixShader(SkMatrix*) const {
     return nullptr;
 }