1 /* 2 * Copyright 2006 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkPathEffect_DEFINED 9 #define SkPathEffect_DEFINED 10 11 #include "include/core/SkFlattenable.h" 12 #include "include/core/SkRefCnt.h" 13 #include "include/private/base/SkAPI.h" 14 15 // TODO(kjlubick) update clients and remove this unnecessary #include 16 #include "include/core/SkPath.h" // IWYU pragma: keep 17 18 #include <cstddef> 19 20 class SkMatrix; 21 class SkStrokeRec; 22 struct SkDeserialProcs; 23 struct SkRect; 24 25 /** \class SkPathEffect 26 27 SkPathEffect is the base class for objects in the SkPaint that affect 28 the geometry of a drawing primitive before it is transformed by the 29 canvas' matrix and drawn. 30 31 Dashing is implemented as a subclass of SkPathEffect. 32 */ 33 class SK_API SkPathEffect : public SkFlattenable { 34 public: 35 /** 36 * Returns a patheffect that apples each effect (first and second) to the original path, 37 * and returns a path with the sum of these. 38 * 39 * result = first(path) + second(path) 40 * 41 */ 42 static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second); 43 44 /** 45 * Returns a patheffect that applies the inner effect to the path, and then applies the 46 * outer effect to the result of the inner's. 47 * 48 * result = outer(inner(path)) 49 */ 50 static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner); 51 GetFlattenableType()52 static SkFlattenable::Type GetFlattenableType() { 53 return kSkPathEffect_Type; 54 } 55 56 /** 57 * Given a src path (input) and a stroke-rec (input and output), apply 58 * this effect to the src path, returning the new path in dst, and return 59 * true. If this effect cannot be applied, return false and ignore dst 60 * and stroke-rec. 61 * 62 * The stroke-rec specifies the initial request for stroking (if any). 63 * The effect can treat this as input only, or it can choose to change 64 * the rec as well. For example, the effect can decide to change the 65 * stroke's width or join, or the effect can change the rec from stroke 66 * to fill (or fill to stroke) in addition to returning a new (dst) path. 67 * 68 * If this method returns true, the caller will apply (as needed) the 69 * resulting stroke-rec to dst and then draw. 70 */ 71 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR) const; 72 73 /** Version of filterPath that can be called when the CTM is known. */ 74 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR, 75 const SkMatrix& ctm) const; 76 77 /** True if this path effect requires a valid CTM */ 78 bool needsCTM() const; 79 80 static sk_sp<SkPathEffect> Deserialize(const void* data, size_t size, 81 const SkDeserialProcs* procs = nullptr); 82 83 private: 84 SkPathEffect() = default; 85 friend class SkPathEffectBase; 86 87 using INHERITED = SkFlattenable; 88 }; 89 90 #endif 91