begin to hide details of SkPathEffect
authorMike Reed <reed@google.com>
Sun, 26 Feb 2017 03:34:32 +0000 (22:34 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Sun, 26 Feb 2017 18:36:11 +0000 (18:36 +0000)
BUG=skia:

Change-Id: I155d2370ae894e6000b6a768d02cf06bf5b3de6e
Reviewed-on: https://skia-review.googlesource.com/8977
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>

12 files changed:
fuzz/FilterFuzz.cpp
gm/patheffects.cpp
gn/android_framework_defines.gni
include/core/SkPathEffect.h
public.bzl
samplecode/SampleAll.cpp
samplecode/SampleFilterFuzz.cpp
samplecode/SamplePathEffects.cpp
samplecode/SampleSlides.cpp
src/core/SkGlobalInitialization_core.cpp
src/core/SkPathEffect.cpp
src/ports/SkGlobalInitialization_default.cpp

index bd9e5fd..312f932 100644 (file)
@@ -424,7 +424,7 @@ static sk_sp<SkPathEffect> make_path_effect(bool canBeNull = true) {
         case 1: {
             sk_sp<SkPathEffect> a = make_path_effect(false);
             sk_sp<SkPathEffect> b = make_path_effect(false);
-            pathEffect = SkComposePathEffect::Make(a, b);
+            pathEffect = SkPathEffect::MakeCompose(a, b);
             break;
         }
         case 2: {
@@ -473,7 +473,7 @@ static sk_sp<SkPathEffect> make_path_effect(bool canBeNull = true) {
         default: {
             sk_sp<SkPathEffect> a = make_path_effect(false);
             sk_sp<SkPathEffect> b = make_path_effect(false);
-            pathEffect = SkSumPathEffect::Make(a, b);
+            pathEffect = SkPathEffect::MakeCompose(a, b);
             break;
         }
     }
index 9a1f62d..744817a 100644 (file)
@@ -20,7 +20,7 @@ static void compose_pe(SkPaint* paint) {
     sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25);
     sk_sp<SkPathEffect> compose;
     if (pe) {
-        compose = SkComposePathEffect::Make(sk_ref_sp(pe), corner);
+        compose = SkPathEffect::MakeCompose(sk_ref_sp(pe), corner);
     } else {
         compose = corner;
     }
index 386cba3..34f7899 100644 (file)
@@ -18,4 +18,5 @@ android_framework_defines = [
   "SK_SUPPORT_EXOTIC_CLIPOPS",
   "SK_SUPPORT_LEGACY_CANVAS_HELPERS",
   "SK_SUPPORT_LEGACY_PAINT_TEXTDECORATION",
+  "SK_SUPPORT_LEGACY_PATHEFFECT_SUBCLASSES",
 ]
index ff3fa01..62f8993 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #ifndef SkPathEffect_DEFINED
 #define SkPathEffect_DEFINED
 
@@ -28,6 +26,9 @@ class SkStrokeRec;
 */
 class SK_API SkPathEffect : public SkFlattenable {
 public:
+    static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second);
+    static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner);
+
     /**
      *  Given a src path (input) and a stroke-rec (input and output), apply
      *  this effect to the src path, returning the new path in dst, and return
@@ -138,6 +139,8 @@ public:
     virtual bool exposedInAndroidJavaAPI() const { return false; }
 #endif
 
+    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
+
 protected:
     SkPathEffect() {}
 
@@ -149,6 +152,8 @@ private:
     typedef SkFlattenable INHERITED;
 };
 
+#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_SUBCLASSES
+
 /** \class SkPairPathEffect
 
     Common baseclass for Compose and Sum. This subclass manages two pathEffects,
@@ -211,6 +216,7 @@ private:
     // illegal
     SkComposePathEffect(const SkComposePathEffect&);
     SkComposePathEffect& operator=(const SkComposePathEffect&);
+    friend class SkPathEffect;
 
     typedef SkPairPathEffect INHERITED;
 };
@@ -255,8 +261,10 @@ private:
     // illegal
     SkSumPathEffect(const SkSumPathEffect&);
     SkSumPathEffect& operator=(const SkSumPathEffect&);
+    friend class SkPathEffect;
 
     typedef SkPairPathEffect INHERITED;
 };
+#endif
 
 #endif
index f4b9ef9..2fa7a54 100644 (file)
@@ -599,6 +599,7 @@ DEFINES_ALL = [
     "SK_NO_ANALYTIC_AA",
     "SK_SUPPORT_LEGACY_BITMAP_SETPIXELREF",
     "SK_SUPPORT_LEGACY_CLIPOP_EXOTIC_NAMES",
+    "SK_SUPPORT_LEGACY_PATHEFFECT_SUBCLASSES",
 ]
 
 ################################################################################
index a098eb6..37a0c4b 100644 (file)
@@ -490,7 +490,7 @@ protected:
             gPhase, SkPath1DPathEffect::kRotate_Style);
         auto inner = SkDiscretePathEffect::Make(SkIntToScalar(2),
             SkIntToScalar(1)/10); // SkCornerPathEffect(SkIntToScalar(2));
-        return SkComposePathEffect::Make(outer, inner);
+        return SkPathEffect::MakeCompose(outer, inner);
     }
 
     sk_sp<SkShader> shaderTest() {
index d90476a..5524f1e 100644 (file)
@@ -422,7 +422,7 @@ static sk_sp<SkPathEffect> make_path_effect(bool canBeNull = true) {
             pathEffect = SkArcToPathEffect::Make(make_scalar(true));
             break;
         case 1:
-            pathEffect = SkComposePathEffect::Make(make_path_effect(false),
+            pathEffect = SkPathEffect::MakeCompose(make_path_effect(false),
                                                    make_path_effect(false));
             break;
         case 2:
@@ -452,7 +452,7 @@ static sk_sp<SkPathEffect> make_path_effect(bool canBeNull = true) {
             break;
         case 8:
         default:
-            pathEffect = SkSumPathEffect::Make(make_path_effect(false),
+            pathEffect = SkPathEffect::MakeSum(make_path_effect(false),
                                                make_path_effect(false));
             break;
     }
index 1f9915d..3d9ba9c 100644 (file)
@@ -45,7 +45,7 @@ static sk_sp<SkPathEffect> make_pe(int flags, SkScalar phase) {
 
     auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS));
 
-    return SkComposePathEffect::Make(outer, inner);
+    return SkPathEffect::MakeCompose(outer, inner);
 }
 
 static sk_sp<SkPathEffect> make_warp_pe(SkScalar phase) {
@@ -61,7 +61,7 @@ static sk_sp<SkPathEffect> make_warp_pe(SkScalar phase) {
         path, 12, phase, SkPath1DPathEffect::kMorph_Style);
     auto inner = SkCornerPathEffect::Make(SkIntToScalar(CORNER_RADIUS));
 
-    return SkComposePathEffect::Make(outer, inner);
+    return SkPathEffect::MakeCompose(outer, inner);
 }
 
 ///////////////////////////////////////////////////////////
index c1c49b4..2322c24 100644 (file)
@@ -34,7 +34,7 @@ static void compose_pe(SkPaint* paint) {
     sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25);
     sk_sp<SkPathEffect> compose;
     if (pe) {
-        compose = SkComposePathEffect::Make(sk_ref_sp(pe), corner);
+        compose = SkPathEffect::MakeCompose(sk_ref_sp(pe), corner);
     } else {
         compose = corner;
     }
index 6f8f8d6..298357e 100644 (file)
@@ -36,18 +36,13 @@ void SkFlattenable::PrivateInitializer::InitCore() {
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLocalMatrixShader)
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPictureShader)
 
-    // PathEffect
-    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkComposePathEffect)
 
     // ImageFilter
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkMatrixImageFilter)
 
-    // ColorFilter
     SkColorFilter::InitializeFlattenables();
-
+    SkPathEffect::InitializeFlattenables();
     SkShader::InitializeFlattenables();
-
-    // Xfermode
     SkXfermode::InitializeFlattenables();
 
     // Drawable
index 1178348..6f953c5 100644 (file)
@@ -27,6 +27,121 @@ SkPathEffect::DashType SkPathEffect::asADash(DashInfo* info) const {
 
 ///////////////////////////////////////////////////////////////////////////////
 
+#ifndef SK_SUPPORT_LEGACY_PATHEFFECT_SUBCLASSES
+
+/** \class SkPairPathEffect
+
+ Common baseclass for Compose and Sum. This subclass manages two pathEffects,
+ including flattening them. It does nothing in filterPath, and is only useful
+ for managing the lifetimes of its two arguments.
+ */
+class SK_API SkPairPathEffect : public SkPathEffect {
+protected:
+    SkPairPathEffect(sk_sp<SkPathEffect> pe0, sk_sp<SkPathEffect> pe1);
+
+    void flatten(SkWriteBuffer&) const override;
+
+    // these are visible to our subclasses
+    sk_sp<SkPathEffect> fPE0;
+    sk_sp<SkPathEffect> fPE1;
+
+    SK_TO_STRING_OVERRIDE()
+
+private:
+    typedef SkPathEffect INHERITED;
+};
+
+/** \class SkComposePathEffect
+
+ This subclass of SkPathEffect composes its two arguments, to create
+ a compound pathEffect.
+ */
+class SK_API SkComposePathEffect : public SkPairPathEffect {
+public:
+    /** Construct a pathEffect whose effect is to apply first the inner pathEffect
+     and the the outer pathEffect (e.g. outer(inner(path)))
+     The reference counts for outer and inner are both incremented in the constructor,
+     and decremented in the destructor.
+     */
+    static sk_sp<SkPathEffect> Make(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner) {
+        if (!outer) {
+            return inner;
+        }
+        if (!inner) {
+            return outer;
+        }
+        return sk_sp<SkPathEffect>(new SkComposePathEffect(outer, inner));
+    }
+
+    virtual bool filterPath(SkPath* dst, const SkPath& src,
+                            SkStrokeRec*, const SkRect*) const override;
+
+    SK_TO_STRING_OVERRIDE()
+    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
+
+#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
+    bool exposedInAndroidJavaAPI() const override { return true; }
+#endif
+
+protected:
+    SkComposePathEffect(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner)
+    : INHERITED(outer, inner) {}
+
+private:
+    // illegal
+    SkComposePathEffect(const SkComposePathEffect&);
+    SkComposePathEffect& operator=(const SkComposePathEffect&);
+    friend class SkPathEffect;
+
+    typedef SkPairPathEffect INHERITED;
+};
+
+/** \class SkSumPathEffect
+
+ This subclass of SkPathEffect applies two pathEffects, one after the other.
+ Its filterPath() returns true if either of the effects succeeded.
+ */
+class SK_API SkSumPathEffect : public SkPairPathEffect {
+public:
+    /** Construct a pathEffect whose effect is to apply two effects, in sequence.
+     (e.g. first(path) + second(path))
+     The reference counts for first and second are both incremented in the constructor,
+     and decremented in the destructor.
+     */
+    static sk_sp<SkPathEffect> Make(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second) {
+        if (!first) {
+            return second;
+        }
+        if (!second) {
+            return first;
+        }
+        return sk_sp<SkPathEffect>(new SkSumPathEffect(first, second));
+    }
+
+    virtual bool filterPath(SkPath* dst, const SkPath& src,
+                            SkStrokeRec*, const SkRect*) const override;
+
+    SK_TO_STRING_OVERRIDE()
+    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
+
+#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
+    bool exposedInAndroidJavaAPI() const override { return true; }
+#endif
+
+protected:
+    SkSumPathEffect(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second)
+    : INHERITED(first, second) {}
+
+private:
+    // illegal
+    SkSumPathEffect(const SkSumPathEffect&);
+    SkSumPathEffect& operator=(const SkSumPathEffect&);
+    friend class SkPathEffect;
+
+    typedef SkPairPathEffect INHERITED;
+};
+#endif
+
 SkPairPathEffect::SkPairPathEffect(sk_sp<SkPathEffect> pe0, sk_sp<SkPathEffect> pe1)
     : fPE0(std::move(pe0)), fPE1(std::move(pe1))
 {
@@ -106,3 +221,19 @@ void SkSumPathEffect::toString(SkString* str) const {
     str->appendf(")");
 }
 #endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+sk_sp<SkPathEffect> SkPathEffect::MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second) {
+    return SkSumPathEffect::Make(std::move(first), std::move(second));
+}
+
+sk_sp<SkPathEffect> SkPathEffect::MakeCompose(sk_sp<SkPathEffect> outer,
+                                              sk_sp<SkPathEffect> inner) {
+    return SkComposePathEffect::Make(std::move(outer), std::move(inner));
+}
+
+SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkPathEffect)
+    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkComposePathEffect)
+    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
+SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
index 60213bd..97d3b67 100644 (file)
@@ -104,7 +104,6 @@ void SkFlattenable::PrivateInitializer::InitEffects() {
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPath1DPathEffect)
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLine2DPathEffect)
     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPath2DPathEffect)
-    SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
 
     // ImageFilter
     SkImageFilter::InitializeFlattenables();