3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkPathEffect_DEFINED
11 #define SkPathEffect_DEFINED
13 #include "SkFlattenable.h"
17 #include "SkStrokeRec.h"
18 #include "SkTDArray.h"
22 /** \class SkPathEffect
24 SkPathEffect is the base class for objects in the SkPaint that affect
25 the geometry of a drawing primitive before it is transformed by the
26 canvas' matrix and drawn.
28 Dashing is implemented as a subclass of SkPathEffect.
30 class SK_API SkPathEffect : public SkFlattenable {
32 SK_DECLARE_INST_COUNT(SkPathEffect)
37 * Given a src path (input) and a stroke-rec (input and output), apply
38 * this effect to the src path, returning the new path in dst, and return
39 * true. If this effect cannot be applied, return false and ignore dst
42 * The stroke-rec specifies the initial request for stroking (if any).
43 * The effect can treat this as input only, or it can choose to change
44 * the rec as well. For example, the effect can decide to change the
45 * stroke's width or join, or the effect can change the rec from stroke
46 * to fill (or fill to stroke) in addition to returning a new (dst) path.
48 * If this method returns true, the caller will apply (as needed) the
49 * resulting stroke-rec to dst and then draw.
51 virtual bool filterPath(SkPath* dst, const SkPath& src,
52 SkStrokeRec*, const SkRect* cullR) const = 0;
55 * Compute a conservative bounds for its effect, given the src bounds.
56 * The baseline implementation just assigns src to dst.
58 virtual void computeFastBounds(SkRect* dst, const SkRect& src) const;
62 PointData aggregates all the information needed to draw the point
63 primitives returned by an 'asPoints' call.
71 fSize.set(SK_Scalar1, SK_Scalar1);
72 // 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets
79 // TODO: consider using passed-in flags to limit the work asPoints does.
80 // For example, a kNoPath flag could indicate don't bother generating
83 // Currently none of these flags are supported.
85 kCircles_PointFlag = 0x01, // draw points as circles (instead of rects)
86 kUsePath_PointFlag = 0x02, // draw points as stamps of the returned path
87 kUseClip_PointFlag = 0x04, // apply 'fClipRect' before drawing the points
90 uint32_t fFlags; // flags that impact the drawing of the points
91 SkPoint* fPoints; // the center point of each generated point
92 int fNumPoints; // number of points in fPoints
93 SkVector fSize; // the size to draw the points
94 SkRect fClipRect; // clip required to draw the points (if kUseClip is set)
95 SkPath fPath; // 'stamp' to be used at each point (if kUsePath is set)
97 SkPath fFirst; // If not empty, contains geometry for first point
98 SkPath fLast; // If not empty, contains geometry for last point
102 * Does applying this path effect to 'src' yield a set of points? If so,
103 * optionally return the points in 'results'.
105 virtual bool asPoints(PointData* results, const SkPath& src,
106 const SkStrokeRec&, const SkMatrix&,
107 const SkRect* cullR) const;
109 SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
112 SkPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
116 SkPathEffect(const SkPathEffect&);
117 SkPathEffect& operator=(const SkPathEffect&);
119 typedef SkFlattenable INHERITED;
122 /** \class SkPairPathEffect
124 Common baseclass for Compose and Sum. This subclass manages two pathEffects,
125 including flattening them. It does nothing in filterPath, and is only useful
126 for managing the lifetimes of its two arguments.
128 class SkPairPathEffect : public SkPathEffect {
130 SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1);
131 virtual ~SkPairPathEffect();
134 SkPairPathEffect(SkFlattenableReadBuffer&);
135 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
137 // these are visible to our subclasses
138 SkPathEffect* fPE0, *fPE1;
141 typedef SkPathEffect INHERITED;
144 /** \class SkComposePathEffect
146 This subclass of SkPathEffect composes its two arguments, to create
147 a compound pathEffect.
149 class SkComposePathEffect : public SkPairPathEffect {
151 /** Construct a pathEffect whose effect is to apply first the inner pathEffect
152 and the the outer pathEffect (e.g. outer(inner(path)))
153 The reference counts for outer and inner are both incremented in the constructor,
154 and decremented in the destructor.
156 SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner)
157 : INHERITED(outer, inner) {}
159 virtual bool filterPath(SkPath* dst, const SkPath& src,
160 SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
162 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
165 SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
169 SkComposePathEffect(const SkComposePathEffect&);
170 SkComposePathEffect& operator=(const SkComposePathEffect&);
172 typedef SkPairPathEffect INHERITED;
175 /** \class SkSumPathEffect
177 This subclass of SkPathEffect applies two pathEffects, one after the other.
178 Its filterPath() returns true if either of the effects succeeded.
180 class SkSumPathEffect : public SkPairPathEffect {
182 /** Construct a pathEffect whose effect is to apply two effects, in sequence.
183 (e.g. first(path) + second(path))
184 The reference counts for first and second are both incremented in the constructor,
185 and decremented in the destructor.
187 SkSumPathEffect(SkPathEffect* first, SkPathEffect* second)
188 : INHERITED(first, second) {}
190 virtual bool filterPath(SkPath* dst, const SkPath& src,
191 SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
193 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
196 SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
200 SkSumPathEffect(const SkSumPathEffect&);
201 SkSumPathEffect& operator=(const SkSumPathEffect&);
203 typedef SkPairPathEffect INHERITED;