• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/core/SkScalar.h"
14 #include "include/private/base/SkAPI.h"
15 
16 // TODO(kjlubick) update clients and remove this unnecessary #include
17 #include "include/core/SkPath.h"  // IWYU pragma: keep
18 
19 #include <cstddef>
20 #include <cstdint>
21 
22 class SkMatrix;
23 class SkStrokeRec;
24 struct SkDeserialProcs;
25 struct SkRect;
26 
27 /** \class SkPathEffect
28 
29     SkPathEffect is the base class for objects in the SkPaint that affect
30     the geometry of a drawing primitive before it is transformed by the
31     canvas' matrix and drawn.
32 
33     Dashing is implemented as a subclass of SkPathEffect.
34 */
35 class SK_API SkPathEffect : public SkFlattenable {
36 public:
37     /**
38      *  Returns a patheffect that apples each effect (first and second) to the original path,
39      *  and returns a path with the sum of these.
40      *
41      *  result = first(path) + second(path)
42      *
43      */
44     static sk_sp<SkPathEffect> MakeSum(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second);
45 
46     /**
47      *  Returns a patheffect that applies the inner effect to the path, and then applies the
48      *  outer effect to the result of the inner's.
49      *
50      *  result = outer(inner(path))
51      */
52     static sk_sp<SkPathEffect> MakeCompose(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner);
53 
GetFlattenableType()54     static SkFlattenable::Type GetFlattenableType() {
55         return kSkPathEffect_Type;
56     }
57 
58     // move to base?
59 
60     enum DashType {
61         kNone_DashType, //!< ignores the info parameter
62         kDash_DashType, //!< fills in all of the info parameter
63     };
64 
65     struct DashInfo {
DashInfoDashInfo66         DashInfo() : fIntervals(nullptr), fCount(0), fPhase(0) {}
DashInfoDashInfo67         DashInfo(SkScalar* intervals, int32_t count, SkScalar phase)
68             : fIntervals(intervals), fCount(count), fPhase(phase) {}
69 
70         SkScalar*   fIntervals;         //!< Length of on/off intervals for dashed lines
71                                         //   Even values represent ons, and odds offs
72         int32_t     fCount;             //!< Number of intervals in the dash. Should be even number
73         SkScalar    fPhase;             //!< Offset into the dashed interval pattern
74                                         //   mod the sum of all intervals
75     };
76 
77     DashType asADash(DashInfo* info) const;
78 
79     /**
80      *  Given a src path (input) and a stroke-rec (input and output), apply
81      *  this effect to the src path, returning the new path in dst, and return
82      *  true. If this effect cannot be applied, return false and ignore dst
83      *  and stroke-rec.
84      *
85      *  The stroke-rec specifies the initial request for stroking (if any).
86      *  The effect can treat this as input only, or it can choose to change
87      *  the rec as well. For example, the effect can decide to change the
88      *  stroke's width or join, or the effect can change the rec from stroke
89      *  to fill (or fill to stroke) in addition to returning a new (dst) path.
90      *
91      *  If this method returns true, the caller will apply (as needed) the
92      *  resulting stroke-rec to dst and then draw.
93      */
94     bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR) const;
95 
96     /** Version of filterPath that can be called when the CTM is known. */
97     bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR,
98                     const SkMatrix& ctm) const;
99 
100     /** True if this path effect requires a valid CTM */
101     bool needsCTM() const;
102 
103     static sk_sp<SkPathEffect> Deserialize(const void* data, size_t size,
104                                            const SkDeserialProcs* procs = nullptr);
105 
106 private:
107     SkPathEffect() = default;
108     friend class SkPathEffectBase;
109 
110     using INHERITED = SkFlattenable;
111 };
112 
113 #endif
114