Reland of "switch patheffects over to sk_sp (patchset #5 id:80001 of https://codereview.chromium.org/1813553005/ )"

This reverts commit f28ad894272018fd2855e3f77ea1236ea0cce1c0.

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

TBR=

Review URL: https://codereview.chromium.org/1813123003
diff --git a/src/animator/SkDrawPaint.cpp b/src/animator/SkDrawPaint.cpp
index d1af4f4..5f6efd8 100644
--- a/src/animator/SkDrawPaint.cpp
+++ b/src/animator/SkDrawPaint.cpp
@@ -233,7 +233,7 @@
     if (pathEffect == nullptr)
         paint->setPathEffect(nullptr);
     else if (pathEffect != (SkDrawPathEffect*) -1)
-        SkSafeUnref(paint->setPathEffect(pathEffect->getPathEffect()));
+        paint->setPathEffect(sk_ref_sp(pathEffect->getPathEffect()));
     if (shader == nullptr)
         paint->setShader(nullptr);
     else if (shader != (SkDrawShader*) -1)
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index c35247b..60db401 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1615,7 +1615,7 @@
 
     // Now restore the original settings, so we "draw" with whatever style/stroking.
     paint.setStyle(origPaint.getStyle());
-    paint.setPathEffect(origPaint.getPathEffect());
+    paint.setPathEffect(sk_ref_sp(origPaint.getPathEffect()));
 
     while (text < stop) {
         const SkGlyph& glyph = glyphCacheProc(cache.get(), &text);
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 5e813f7..331f779 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -375,7 +375,9 @@
 SET_PTR(Shader)
 SET_PTR(ColorFilter)
 SET_PTR(Xfermode)
+#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
 SET_PTR(PathEffect)
+#endif
 SET_PTR(MaskFilter)
 #undef SET_PTR
 
@@ -1930,7 +1932,7 @@
     }
 
     if (flatFlags & kHasEffects_FlatFlag) {
-        SkSafeUnref(this->setPathEffect(buffer.readPathEffect()));
+        this->setPathEffect(buffer.readPathEffect());
         this->setShader(buffer.readShader());
         SkSafeUnref(this->setXfermode(buffer.readXfermode()));
         SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
@@ -2250,11 +2252,11 @@
     fCache = fPaint.detachCache(nullptr, SkPaint::FakeGamma::On, nullptr);
 
     SkPaint::Style  style = SkPaint::kFill_Style;
-    SkPathEffect*   pe = nullptr;
+    sk_sp<SkPathEffect> pe;
 
     if (!applyStrokeAndPathEffects) {
         style = paint.getStyle();   // restore
-        pe = paint.getPathEffect();     // restore
+        pe = sk_ref_sp(paint.getPathEffect());     // restore
     }
     fPaint.setStyle(style);
     fPaint.setPathEffect(pe);
diff --git a/src/core/SkPathEffect.cpp b/src/core/SkPathEffect.cpp
index 293bb53..b2e29bc 100644
--- a/src/core/SkPathEffect.cpp
+++ b/src/core/SkPathEffect.cpp
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -28,25 +27,19 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1)
-        : fPE0(pe0), fPE1(pe1) {
-    SkASSERT(pe0);
-    SkASSERT(pe1);
-    fPE0->ref();
-    fPE1->ref();
-}
-
-SkPairPathEffect::~SkPairPathEffect() {
-    SkSafeUnref(fPE0);
-    SkSafeUnref(fPE1);
+SkPairPathEffect::SkPairPathEffect(sk_sp<SkPathEffect> pe0, sk_sp<SkPathEffect> pe1)
+    : fPE0(std::move(pe0)), fPE1(std::move(pe1))
+{
+    SkASSERT(fPE0.get());
+    SkASSERT(fPE1.get());
 }
 
 /*
     Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data]
 */
 void SkPairPathEffect::flatten(SkWriteBuffer& buffer) const {
-    buffer.writeFlattenable(fPE0);
-    buffer.writeFlattenable(fPE1);
+    buffer.writeFlattenable(fPE0.get());
+    buffer.writeFlattenable(fPE1.get());
 }
 
 #ifndef SK_IGNORE_TO_STRING
@@ -65,22 +58,13 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 SkFlattenable* SkComposePathEffect::CreateProc(SkReadBuffer& buffer) {
-    SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect());
-    SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect());
-    if (pe0 && pe1) {
-        return SkComposePathEffect::Create(pe0, pe1);
-    } else {
-        return nullptr;
-    }
+    sk_sp<SkPathEffect> pe0(buffer.readPathEffect());
+    sk_sp<SkPathEffect> pe1(buffer.readPathEffect());
+    return SkComposePathEffect::Make(std::move(pe0), std::move(pe1)).release();
 }
 
 bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
                              SkStrokeRec* rec, const SkRect* cullRect) const {
-    // we may have failed to unflatten these, so we have to check
-    if (!fPE0 || !fPE1) {
-        return false;
-    }
-
     SkPath          tmp;
     const SkPath*   ptr = &src;
 
@@ -102,13 +86,9 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 SkFlattenable* SkSumPathEffect::CreateProc(SkReadBuffer& buffer) {
-    SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect());
-    SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect());
-    if (pe0 && pe1) {
-        return SkSumPathEffect::Create(pe0, pe1);
-    } else {
-        return nullptr;
-    }
+    sk_sp<SkPathEffect> pe0(buffer.readPathEffect());
+    sk_sp<SkPathEffect> pe1(buffer.readPathEffect());
+    return SkSumPathEffect::Make(pe0, pe1).release();
 }
 
 bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index 7ce6d04..c7ac848 100644
--- a/src/core/SkReadBuffer.h
+++ b/src/core/SkReadBuffer.h
@@ -134,7 +134,9 @@
     SkDrawLooper*  readDrawLooper()  { return this->readFlattenable<SkDrawLooper>(); }
     SkImageFilter* readImageFilter() { return this->readFlattenable<SkImageFilter>(); }
     SkMaskFilter*  readMaskFilter()  { return this->readFlattenable<SkMaskFilter>(); }
-    SkPathEffect*  readPathEffect()  { return this->readFlattenable<SkPathEffect>(); }
+    sk_sp<SkPathEffect> readPathEffect()  {
+        return sk_sp<SkPathEffect>(this->readFlattenable<SkPathEffect>());
+    }
     SkRasterizer*  readRasterizer()  { return this->readFlattenable<SkRasterizer>(); }
     sk_sp<SkShader> readShader()     { return sk_sp<SkShader>(this->readFlattenable<SkShader>()); }
     SkXfermode*    readXfermode()    { return this->readFlattenable<SkXfermode>(); }
diff --git a/src/effects/Sk1DPathEffect.cpp b/src/effects/Sk1DPathEffect.cpp
index 4be6f97..1d147bd 100644
--- a/src/effects/Sk1DPathEffect.cpp
+++ b/src/effects/Sk1DPathEffect.cpp
@@ -153,7 +153,7 @@
         buffer.readPath(&path);
         SkScalar phase = buffer.readScalar();
         Style style = (Style)buffer.readUInt();
-        return SkPath1DPathEffect::Create(path, advance, phase, style);
+        return SkPath1DPathEffect::Make(path, advance, phase, style).release();
     }
     return nullptr;
 }
@@ -204,10 +204,10 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-SkPathEffect* SkPath1DPathEffect::Create(const SkPath& path, SkScalar advance, SkScalar phase,
-                                         Style style) {
+sk_sp<SkPathEffect> SkPath1DPathEffect::Make(const SkPath& path, SkScalar advance, SkScalar phase,
+                                             Style style) {
     if (advance <= 0 || path.isEmpty()) {
         return nullptr;
     }
-    return new SkPath1DPathEffect(path, advance, phase, style);
+    return sk_sp<SkPathEffect>(new SkPath1DPathEffect(path, advance, phase, style));
 }
diff --git a/src/effects/Sk2DPathEffect.cpp b/src/effects/Sk2DPathEffect.cpp
index 7144526..a54f453 100644
--- a/src/effects/Sk2DPathEffect.cpp
+++ b/src/effects/Sk2DPathEffect.cpp
@@ -111,7 +111,7 @@
     SkMatrix matrix;
     buffer.readMatrix(&matrix);
     SkScalar width = buffer.readScalar();
-    return SkLine2DPathEffect::Create(width, matrix);
+    return SkLine2DPathEffect::Make(width, matrix).release();
 }
 
 void SkLine2DPathEffect::flatten(SkWriteBuffer &buffer) const {
@@ -140,7 +140,7 @@
     buffer.readMatrix(&matrix);
     SkPath path;
     buffer.readPath(&path);
-    return SkPath2DPathEffect::Create(matrix, path);
+    return SkPath2DPathEffect::Make(matrix, path).release();
 }
 
 void SkPath2DPathEffect::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/effects/SkArcToPathEffect.cpp b/src/effects/SkArcToPathEffect.cpp
index 06cba96..c660de9 100644
--- a/src/effects/SkArcToPathEffect.cpp
+++ b/src/effects/SkArcToPathEffect.cpp
@@ -62,7 +62,7 @@
 }
 
 SkFlattenable* SkArcToPathEffect::CreateProc(SkReadBuffer& buffer) {
-    return SkArcToPathEffect::Create(buffer.readScalar());
+    return SkArcToPathEffect::Make(buffer.readScalar()).release();
 }
 
 void SkArcToPathEffect::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/effects/SkCornerPathEffect.cpp b/src/effects/SkCornerPathEffect.cpp
index 4b81f26..325e2ca 100644
--- a/src/effects/SkCornerPathEffect.cpp
+++ b/src/effects/SkCornerPathEffect.cpp
@@ -140,7 +140,7 @@
 }
 
 SkFlattenable* SkCornerPathEffect::CreateProc(SkReadBuffer& buffer) {
-    return SkCornerPathEffect::Create(buffer.readScalar());
+    return SkCornerPathEffect::Make(buffer.readScalar()).release();
 }
 
 void SkCornerPathEffect::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index 3816499..51bf548 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -365,7 +365,7 @@
     uint32_t count = buffer.getArrayCount();
     SkAutoSTArray<32, SkScalar> intervals(count);
     if (buffer.readScalarArray(intervals.get(), count)) {
-        return Create(intervals.get(), SkToInt(count), phase);
+        return Make(intervals.get(), SkToInt(count), phase).release();
     }
     return nullptr;
 }
@@ -386,9 +386,9 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
-SkPathEffect* SkDashPathEffect::Create(const SkScalar intervals[], int count, SkScalar phase) {
+sk_sp<SkPathEffect> SkDashPathEffect::Make(const SkScalar intervals[], int count, SkScalar phase) {
     if (!SkDashPath::ValidDashPath(phase, intervals, count)) {
         return nullptr;
     }
-    return new SkDashPathEffect(intervals, count, phase);
+    return sk_sp<SkPathEffect>(new SkDashPathEffect(intervals, count, phase));
 }
diff --git a/src/effects/SkDiscretePathEffect.cpp b/src/effects/SkDiscretePathEffect.cpp
index acde041..1989d9d 100644
--- a/src/effects/SkDiscretePathEffect.cpp
+++ b/src/effects/SkDiscretePathEffect.cpp
@@ -13,6 +13,11 @@
 #include "SkPathMeasure.h"
 #include "SkStrokeRec.h"
 
+sk_sp<SkPathEffect> SkDiscretePathEffect::Make(SkScalar segLength, SkScalar deviation,
+                                               uint32_t seedAssist) {
+    return sk_sp<SkPathEffect>(new SkDiscretePathEffect(segLength, deviation, seedAssist));
+}
+
 static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) {
     SkVector normal = tangent;
     normal.rotateCCW();
@@ -121,7 +126,7 @@
     SkScalar segLength = buffer.readScalar();
     SkScalar perterb = buffer.readScalar();
     uint32_t seed = buffer.readUInt();
-    return Create(segLength, perterb, seed);
+    return Make(segLength, perterb, seed).release();
 }
 
 void SkDiscretePathEffect::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp
index bca65ef..83f21e5 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -93,7 +93,7 @@
     }
 
     if (bits & kPathEffect_Bit) {
-        dst->setPathEffect(src.getPathEffect());
+        dst->setPathEffect(sk_ref_sp(src.getPathEffect()));
     }
     if (bits & kMaskFilter_Bit) {
         dst->setMaskFilter(src.getMaskFilter());
diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp
index c46ea73..edf813d 100644
--- a/src/gpu/text/GrTextUtils.cpp
+++ b/src/gpu/text/GrTextUtils.cpp
@@ -517,7 +517,7 @@
 
     // Now restore the original settings, so we "draw" with whatever style/stroking.
     paint.setStyle(origPaint.getStyle());
-    paint.setPathEffect(origPaint.getPathEffect());
+    paint.setPathEffect(sk_ref_sp(origPaint.getPathEffect()));
 
     while (text < stop) {
         const SkGlyph& glyph = glyphCacheProc(cache, &text);
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 6e0dd4b..f5e341b 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -15,6 +15,7 @@
 #include "SkGlyphCache.h"
 #include "SkPaint.h"
 #include "SkPath.h"
+#include "SkPathEffect.h"
 #include "SkPathOps.h"
 #include "SkPDFBitmap.h"
 #include "SkPDFCanon.h"
diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp
index 5d12c49..febd027 100644
--- a/src/xps/SkXPSDevice.cpp
+++ b/src/xps/SkXPSDevice.cpp
@@ -32,6 +32,7 @@
 #include "SkIStream.h"
 #include "SkMaskFilter.h"
 #include "SkPaint.h"
+#include "SkPathEffect.h"
 #include "SkPathOps.h"
 #include "SkPoint.h"
 #include "SkRasterizer.h"