move patheffect virtuals to protected and rename

- change filterPath to safely handle if src and dst are aliases

Bug: skia:8254
Change-Id: I125d19404ca0a610f73271abb5c5455d1d50f9ed
Reviewed-on: https://skia-review.googlesource.com/147466
Commit-Queue: Mike Reed <reed@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Auto-Submit: Mike Reed <reed@google.com>
diff --git a/src/core/SkPathEffect.cpp b/src/core/SkPathEffect.cpp
index e315275..ef0a473 100644
--- a/src/core/SkPathEffect.cpp
+++ b/src/core/SkPathEffect.cpp
@@ -12,17 +12,32 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
-    *dst = src;
-}
-
-bool SkPathEffect::asPoints(PointData* results, const SkPath& src,
-                    const SkStrokeRec&, const SkMatrix&, const SkRect*) const {
+bool SkPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+                              const SkRect* bounds) const {
+    SkPath tmp, *tmpDst = dst;
+    if (dst == &src) {
+        tmpDst = &tmp;
+    }
+    if (this->onFilterPath(tmpDst, src, rec, bounds)) {
+        if (dst == &src) {
+            *dst = tmp;
+        }
+        return true;
+    }
     return false;
 }
 
+void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const {
+    *dst = this->onComputeFastBounds(src);
+}
+
+bool SkPathEffect::asPoints(PointData* results, const SkPath& src,
+                    const SkStrokeRec& rec, const SkMatrix& mx, const SkRect* rect) const {
+    return this->onAsPoints(results, src, rec, mx, rect);
+}
+
 SkPathEffect::DashType SkPathEffect::asADash(DashInfo* info) const {
-    return kNone_DashType;
+    return this->onAsADash(info);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -79,18 +94,6 @@
         return sk_sp<SkPathEffect>(new SkComposePathEffect(outer, inner));
     }
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
-                    const SkRect* cullRect) const override {
-        SkPath          tmp;
-        const SkPath*   ptr = &src;
-
-        if (fPE1->filterPath(&tmp, src, rec, cullRect)) {
-            ptr = &tmp;
-        }
-        return fPE0->filterPath(dst, *ptr, rec, cullRect);
-    }
-
-
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
 
 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
@@ -101,6 +104,17 @@
     SkComposePathEffect(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner)
         : INHERITED(outer, inner) {}
 
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+                      const SkRect* cullRect) const override {
+        SkPath          tmp;
+        const SkPath*   ptr = &src;
+
+        if (fPE1->filterPath(&tmp, src, rec, cullRect)) {
+            ptr = &tmp;
+        }
+        return fPE0->filterPath(dst, *ptr, rec, cullRect);
+    }
+
 private:
     // illegal
     SkComposePathEffect(const SkComposePathEffect&);
@@ -140,14 +154,6 @@
         return sk_sp<SkPathEffect>(new SkSumPathEffect(first, second));
     }
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
-                    const SkRect* cullRect) const override {
-        // use bit-or so that we always call both, even if the first one succeeds
-        return fPE0->filterPath(dst, src, rec, cullRect) |
-               fPE1->filterPath(dst, src, rec, cullRect);
-    }
-
-
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
 
 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
@@ -156,7 +162,14 @@
 
 protected:
     SkSumPathEffect(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second)
-    : INHERITED(first, second) {}
+        : INHERITED(first, second) {}
+
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+                      const SkRect* cullRect) const override {
+        // use bit-or so that we always call both, even if the first one succeeds
+        return fPE0->filterPath(dst, src, rec, cullRect) |
+               fPE1->filterPath(dst, src, rec, cullRect);
+    }
 
 private:
     // illegal
diff --git a/src/effects/Sk1DPathEffect.cpp b/src/effects/Sk1DPathEffect.cpp
index 9195933..72a128d 100644
--- a/src/effects/Sk1DPathEffect.cpp
+++ b/src/effects/Sk1DPathEffect.cpp
@@ -16,8 +16,8 @@
 // Put in a governor to limit crash values from looping too long (and allocating too much ram).
 #define MAX_REASONABLE_ITERATIONS   100000
 
-bool Sk1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
-                                SkStrokeRec*, const SkRect*) const {
+bool Sk1DPathEffect::onFilterPath(SkPath* dst, const SkPath& src,
+                                  SkStrokeRec*, const SkRect*) const {
     SkPathMeasure   meas(src, false);
     do {
         int governor = MAX_REASONABLE_ITERATIONS;
@@ -69,10 +69,10 @@
     fStyle = style;
 }
 
-bool SkPath1DPathEffect::filterPath(SkPath* dst, const SkPath& src,
-                            SkStrokeRec* rec, const SkRect* cullRect) const {
+bool SkPath1DPathEffect::onFilterPath(SkPath* dst, const SkPath& src,
+                                      SkStrokeRec* rec, const SkRect* cullRect) const {
     rec->setFillStyle();
-    return this->INHERITED::filterPath(dst, src, rec, cullRect);
+    return this->INHERITED::onFilterPath(dst, src, rec, cullRect);
 }
 
 static bool morphpoints(SkPoint dst[], const SkPoint src[], int count,
diff --git a/src/effects/Sk2DPathEffect.cpp b/src/effects/Sk2DPathEffect.cpp
index 6c2c4c2..2458682 100644
--- a/src/effects/Sk2DPathEffect.cpp
+++ b/src/effects/Sk2DPathEffect.cpp
@@ -18,8 +18,8 @@
     fMatrixIsInvertible = fMatrix.invert(&fInverse);
 }
 
-bool Sk2DPathEffect::filterPath(SkPath* dst, const SkPath& src,
-                                SkStrokeRec*, const SkRect*) const {
+bool Sk2DPathEffect::onFilterPath(SkPath* dst, const SkPath& src,
+                                  SkStrokeRec*, const SkRect*) const {
     if (!fMatrixIsInvertible) {
         return false;
     }
@@ -76,8 +76,8 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-bool SkLine2DPathEffect::filterPath(SkPath* dst, const SkPath& src,
-                            SkStrokeRec* rec, const SkRect* cullRect) const {
+bool SkLine2DPathEffect::onFilterPath(SkPath* dst, const SkPath& src,
+                                      SkStrokeRec* rec, const SkRect* cullRect) const {
     if (this->INHERITED::filterPath(dst, src, rec, cullRect)) {
         rec->setStrokeStyle(fWidth);
         return true;
diff --git a/src/effects/SkCornerPathEffect.cpp b/src/effects/SkCornerPathEffect.cpp
index a88bc32..d8f2d70 100644
--- a/src/effects/SkCornerPathEffect.cpp
+++ b/src/effects/SkCornerPathEffect.cpp
@@ -35,8 +35,8 @@
     }
 }
 
-bool SkCornerPathEffect::filterPath(SkPath* dst, const SkPath& src,
-                                    SkStrokeRec*, const SkRect*) const {
+bool SkCornerPathEffect::onFilterPath(SkPath* dst, const SkPath& src,
+                                      SkStrokeRec*, const SkRect*) const {
     if (fRadius <= 0) {
         return false;
     }
diff --git a/src/effects/SkDashImpl.h b/src/effects/SkDashImpl.h
index 7f1de77..c1bf462 100644
--- a/src/effects/SkDashImpl.h
+++ b/src/effects/SkDashImpl.h
@@ -14,13 +14,6 @@
 public:
     SkDashImpl(const SkScalar intervals[], int count, SkScalar phase);
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
-
-    bool asPoints(PointData* results, const SkPath& src, const SkStrokeRec&, const SkMatrix&,
-                  const SkRect*) const override;
-
-    DashType asADash(DashInfo* info) const override;
-
     Factory getFactory() const override { return CreateProc; }
 
 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
@@ -30,6 +23,12 @@
 protected:
     ~SkDashImpl() override;
     void flatten(SkWriteBuffer&) const override;
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
+
+    bool onAsPoints(PointData* results, const SkPath& src, const SkStrokeRec&, const SkMatrix&,
+                    const SkRect*) const override;
+
+    DashType onAsADash(DashInfo* info) const override;
 
 private:
     static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
diff --git a/src/effects/SkDashPathEffect.cpp b/src/effects/SkDashPathEffect.cpp
index a243409..cc414f7 100644
--- a/src/effects/SkDashPathEffect.cpp
+++ b/src/effects/SkDashPathEffect.cpp
@@ -40,8 +40,8 @@
     sk_free(fIntervals);
 }
 
-bool SkDashImpl::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
-                            const SkRect* cullRect) const {
+bool SkDashImpl::onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+                              const SkRect* cullRect) const {
     return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals, fCount,
                                       fInitialDashLength, fInitialDashIndex, fIntervalLength);
 }
@@ -164,8 +164,8 @@
 // we need to:
 //      allow kRound_Cap capping (could allow rotations in the matrix with this)
 //      allow paths to be returned
-bool SkDashImpl::asPoints(PointData* results, const SkPath& src, const SkStrokeRec& rec,
-                          const SkMatrix& matrix, const SkRect* cullRect) const {
+bool SkDashImpl::onAsPoints(PointData* results, const SkPath& src, const SkStrokeRec& rec,
+                            const SkMatrix& matrix, const SkRect* cullRect) const {
     // width < 0 -> fill && width == 0 -> hairline so requiring width > 0 rules both out
     if (0 >= rec.getWidth()) {
         return false;
@@ -357,7 +357,7 @@
     return true;
 }
 
-SkPathEffect::DashType SkDashImpl::asADash(DashInfo* info) const {
+SkPathEffect::DashType SkDashImpl::onAsADash(DashInfo* info) const {
     if (info) {
         if (info->fCount >= fCount && info->fIntervals) {
             memcpy(info->fIntervals, fIntervals, fCount * sizeof(SkScalar));
diff --git a/src/effects/SkDiscretePathEffect.cpp b/src/effects/SkDiscretePathEffect.cpp
index 46cd42b..2c913d8 100644
--- a/src/effects/SkDiscretePathEffect.cpp
+++ b/src/effects/SkDiscretePathEffect.cpp
@@ -81,8 +81,8 @@
     uint32_t fSeed;
 };
 
-bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src,
-                                      SkStrokeRec* rec, const SkRect*) const {
+bool SkDiscretePathEffect::onFilterPath(SkPath* dst, const SkPath& src,
+                                        SkStrokeRec* rec, const SkRect*) const {
     bool doFill = rec->isFillStyle();
 
     SkPathMeasure   meas(src, doFill);
diff --git a/src/effects/SkOpPE.h b/src/effects/SkOpPE.h
index d6883d0..6f6e114 100644
--- a/src/effects/SkOpPE.h
+++ b/src/effects/SkOpPE.h
@@ -14,12 +14,11 @@
 public:
     SkOpPE(sk_sp<SkPathEffect> one, sk_sp<SkPathEffect> two, SkPathOp op);
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
-
     Factory getFactory() const override { return CreateProc; }
 
 protected:
     void flatten(SkWriteBuffer&) const override;
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
 
 private:
     static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
@@ -36,12 +35,11 @@
 public:
     SkMatrixPE(const SkMatrix&);
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
-
     Factory getFactory() const override { return CreateProc; }
 
 protected:
     void flatten(SkWriteBuffer&) const override;
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
 
 private:
     static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
@@ -56,12 +54,12 @@
 public:
     SkStrokePE(SkScalar width, SkPaint::Join, SkPaint::Cap, SkScalar miter);
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
-
     Factory getFactory() const override { return CreateProc; }
 
 protected:
     void flatten(SkWriteBuffer&) const override;
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
+    // TODO: override onComputeFastBounds (I think)
 
 private:
     static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
diff --git a/src/effects/SkOpPathEffect.cpp b/src/effects/SkOpPathEffect.cpp
index 3c09b9e..1623b86 100644
--- a/src/effects/SkOpPathEffect.cpp
+++ b/src/effects/SkOpPathEffect.cpp
@@ -18,8 +18,8 @@
 SkOpPE::SkOpPE(sk_sp<SkPathEffect> one, sk_sp<SkPathEffect> two, SkPathOp op)
     : fOne(std::move(one)), fTwo(std::move(two)), fOp(op) {}
 
-bool SkOpPE::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
-                        const SkRect* cull) const {
+bool SkOpPE::onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+                          const SkRect* cull) const {
     SkPath one, two;
     if (fOne) {
         if (!fOne->filterPath(&one, src, rec, cull)) {
@@ -71,7 +71,7 @@
     SkASSERT(matrix.isFinite());
 }
 
-bool SkMatrixPE::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const {
+bool SkMatrixPE::onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const {
     src.transform(fMatrix, dst);
     return true;
 }
@@ -99,7 +99,7 @@
 SkStrokePE::SkStrokePE(SkScalar width, SkPaint::Join join, SkPaint::Cap cap, SkScalar miter)
     : fWidth(width), fMiter(miter), fJoin(join), fCap(cap) {}
 
-bool SkStrokePE::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const {
+bool SkStrokePE::onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const {
     SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
     rec.setStrokeStyle(fWidth);
     rec.setStrokeParams(fCap, fJoin, fMiter);
diff --git a/src/effects/SkTrimPE.h b/src/effects/SkTrimPE.h
index 0f29987..cbaab89 100644
--- a/src/effects/SkTrimPE.h
+++ b/src/effects/SkTrimPE.h
@@ -17,12 +17,11 @@
 public:
     SkTrimPE(SkScalar startT, SkScalar stopT, SkTrimPathEffect::Mode);
 
-    bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
-
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTrimPE)
 
 protected:
     void flatten(SkWriteBuffer&) const override;
+    bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override;
 
 private:
     const SkScalar               fStartT,
diff --git a/src/effects/SkTrimPathEffect.cpp b/src/effects/SkTrimPathEffect.cpp
index 3a8d094..3ca70b5 100644
--- a/src/effects/SkTrimPathEffect.cpp
+++ b/src/effects/SkTrimPathEffect.cpp
@@ -53,7 +53,7 @@
 SkTrimPE::SkTrimPE(SkScalar startT, SkScalar stopT, SkTrimPathEffect::Mode mode)
     : fStartT(startT), fStopT(stopT), fMode(mode) {}
 
-bool SkTrimPE::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+bool SkTrimPE::onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
                             const SkRect* cullRect) const {
     if (fStartT >= fStopT) {
         SkASSERT(fMode == SkTrimPathEffect::Mode::kNormal);
diff --git a/src/gpu/GrTestUtils.cpp b/src/gpu/GrTestUtils.cpp
index e29e8f5..4f0dc3b 100644
--- a/src/gpu/GrTestUtils.cpp
+++ b/src/gpu/GrTestUtils.cpp
@@ -285,13 +285,13 @@
                                    &fInitialDashIndex, &fIntervalLength, &fPhase);
 }
 
-    bool TestDashPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
-                                     const SkRect* cullRect) const {
+    bool TestDashPathEffect::onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
+                                          const SkRect* cullRect) const {
     return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals.get(), fCount,
                                       fInitialDashLength, fInitialDashIndex, fIntervalLength);
 }
 
-SkPathEffect::DashType TestDashPathEffect::asADash(DashInfo* info) const {
+SkPathEffect::DashType TestDashPathEffect::onAsADash(DashInfo* info) const {
     if (info) {
         if (info->fCount >= fCount && info->fIntervals) {
             memcpy(info->fIntervals, fIntervals.get(), fCount * sizeof(SkScalar));
diff --git a/src/gpu/GrTestUtils.h b/src/gpu/GrTestUtils.h
index 64c7662..ffc48aa 100644
--- a/src/gpu/GrTestUtils.h
+++ b/src/gpu/GrTestUtils.h
@@ -72,10 +72,12 @@
         return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phase));
     }
 
-    bool filterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*) const override;
-    DashType asADash(DashInfo* info) const override;
     Factory getFactory() const override { return nullptr; }
 
+protected:
+    bool onFilterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*) const override;
+    DashType onAsADash(DashInfo* info) const override;
+
 private:
     TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase);