Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPathEffect.h
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkPathEffect_DEFINED
11 #define SkPathEffect_DEFINED
12 
13 #include "SkFlattenable.h"
14 #include "SkPath.h"
15 #include "SkPoint.h"
16 #include "SkRect.h"
17 
18 class SkPath;
19 class SkStrokeRec;
20 
29 class SK_API SkPathEffect : public SkFlattenable {
30 public:
46  virtual bool filterPath(SkPath* dst, const SkPath& src,
47  SkStrokeRec*, const SkRect* cullR) const = 0;
48 
53  virtual void computeFastBounds(SkRect* dst, const SkRect& src) const;
54 
60  class PointData {
61  public:
62  PointData()
63  : fFlags(0)
64  , fPoints(NULL)
65  , fNumPoints(0) {
66  fSize.set(SK_Scalar1, SK_Scalar1);
67  // 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets
68  // the kUseClip flag
69  };
70  ~PointData() {
71  delete [] fPoints;
72  }
73 
74  // TODO: consider using passed-in flags to limit the work asPoints does.
75  // For example, a kNoPath flag could indicate don't bother generating
76  // stamped solutions.
77 
78  // Currently none of these flags are supported.
79  enum PointFlags {
80  kCircles_PointFlag = 0x01, // draw points as circles (instead of rects)
81  kUsePath_PointFlag = 0x02, // draw points as stamps of the returned path
82  kUseClip_PointFlag = 0x04, // apply 'fClipRect' before drawing the points
83  };
84 
85  uint32_t fFlags; // flags that impact the drawing of the points
86  SkPoint* fPoints; // the center point of each generated point
87  int fNumPoints; // number of points in fPoints
88  SkVector fSize; // the size to draw the points
89  SkRect fClipRect; // clip required to draw the points (if kUseClip is set)
90  SkPath fPath; // 'stamp' to be used at each point (if kUsePath is set)
91 
92  SkPath fFirst; // If not empty, contains geometry for first point
93  SkPath fLast; // If not empty, contains geometry for last point
94  };
95 
100  virtual bool asPoints(PointData* results, const SkPath& src,
101  const SkStrokeRec&, const SkMatrix&,
102  const SkRect* cullR) const;
103 
114  enum DashType {
117  };
118 
119  struct DashInfo {
120  DashInfo() : fIntervals(NULL), fCount(0), fPhase(0) {}
121  DashInfo(SkScalar* intervals, int32_t count, SkScalar phase)
122  : fIntervals(intervals), fCount(count), fPhase(phase) {}
123 
124  SkScalar* fIntervals;
125  // Even values represent ons, and odds offs
126  int32_t fCount;
127  SkScalar fPhase;
128  // mod the sum of all intervals
129  };
130 
131  virtual DashType asADash(DashInfo* info) const;
132 
133  SK_TO_STRING_PUREVIRT()
134  SK_DEFINE_FLATTENABLE_TYPE(SkPathEffect)
135 
136 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
137  virtual bool exposedInAndroidJavaAPI() const { return false; }
139 #endif
140 
141 protected:
142  SkPathEffect() {}
143 
144 private:
145  // illegal
146  SkPathEffect(const SkPathEffect&);
147  SkPathEffect& operator=(const SkPathEffect&);
148 
149  typedef SkFlattenable INHERITED;
150 };
151 
158 class SK_API SkPairPathEffect : public SkPathEffect {
159 protected:
161 
162  void flatten(SkWriteBuffer&) const override;
163 
164  // these are visible to our subclasses
165  sk_sp<SkPathEffect> fPE0;
166  sk_sp<SkPathEffect> fPE1;
167 
168  SK_TO_STRING_OVERRIDE()
169 
170 private:
171  typedef SkPathEffect INHERITED;
172 };
173 
179 class SK_API SkComposePathEffect : public SkPairPathEffect {
180 public:
187  if (!outer) {
188  return inner;
189  }
190  if (!inner) {
191  return outer;
192  }
193  return sk_sp<SkPathEffect>(new SkComposePathEffect(outer, inner));
194  }
195 
196 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
197  static SkPathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) {
198  return Make(sk_ref_sp(outer), sk_ref_sp(inner)).release();
199  }
200 #endif
201 
202  virtual bool filterPath(SkPath* dst, const SkPath& src,
203  SkStrokeRec*, const SkRect*) const override;
204 
205  SK_TO_STRING_OVERRIDE()
206  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect)
207 
208 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
209  bool exposedInAndroidJavaAPI() const override { return true; }
210 #endif
211 
212 protected:
214  : INHERITED(outer, inner) {}
215 
216 private:
217  // illegal
219  SkComposePathEffect& operator=(const SkComposePathEffect&);
220 
221  typedef SkPairPathEffect INHERITED;
222 };
223 
229 class SK_API SkSumPathEffect : public SkPairPathEffect {
230 public:
237  if (!first) {
238  return second;
239  }
240  if (!second) {
241  return first;
242  }
243  return sk_sp<SkPathEffect>(new SkSumPathEffect(first, second));
244  }
245 
246 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
247  static SkPathEffect* Create(SkPathEffect* first, SkPathEffect* second) {
248  return Make(sk_ref_sp(first), sk_ref_sp(second)).release();
249  }
250 #endif
251  virtual bool filterPath(SkPath* dst, const SkPath& src,
252  SkStrokeRec*, const SkRect*) const override;
253 
254  SK_TO_STRING_OVERRIDE()
255  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect)
256 
257 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
258  bool exposedInAndroidJavaAPI() const override { return true; }
259 #endif
260 
261 protected:
263  : INHERITED(first, second) {}
264 
265 private:
266  // illegal
268  SkSumPathEffect& operator=(const SkSumPathEffect&);
269 
270  typedef SkPairPathEffect INHERITED;
271 };
272 
273 #endif
Common baseclass for Compose and Sum.
Definition: SkPathEffect.h:158
Definition: SkPathEffect.h:119
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
SkPathEffect is the base class for objects in the SkPaint that affect the geometry of a drawing primi...
Definition: SkPathEffect.h:29
DashType
If the PathEffect can be represented as a dash pattern, asADash will return kDash_DashType and None o...
Definition: SkPathEffect.h:114
Definition: SkStrokeRec.h:16
Definition: SkPoint.h:156
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
Definition: SkRefCnt.h:135
SkScalar fPhase
Offset into the dashed interval pattern.
Definition: SkPathEffect.h:127
virtual bool filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *, const SkRect *cullR) const =0
Given a src path (input) and a stroke-rec (input and output), apply this effect to the src path...
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:70
ignores the info parameter
Definition: SkPathEffect.h:115
static sk_sp< SkPathEffect > Make(sk_sp< SkPathEffect > first, sk_sp< SkPathEffect > second)
Construct a pathEffect whose effect is to apply two effects, in sequence.
Definition: SkPathEffect.h:236
int32_t fCount
Number of intervals in the dash. Should be even number.
Definition: SkPathEffect.h:126
This subclass of SkPathEffect applies two pathEffects, one after the other.
Definition: SkPathEffect.h:229
Definition: SkWriteBuffer.h:26
Definition: SkRect.h:390
virtual void flatten(SkWriteBuffer &) const
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
Definition: SkFlattenable.h:117
SkScalar * fIntervals
Length of on/off intervals for dashed lines.
Definition: SkPathEffect.h:124
fills in all of the info parameter
Definition: SkPathEffect.h:116
PointData aggregates all the information needed to draw the point primitives returned by an 'asPoints...
Definition: SkPathEffect.h:60
This subclass of SkPathEffect composes its two arguments, to create a compound pathEffect.
Definition: SkPathEffect.h:179
static sk_sp< SkPathEffect > Make(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
Construct a pathEffect whose effect is to apply first the inner pathEffect and the the outer pathEffe...
Definition: SkPathEffect.h:186