Skia
2D Graphics Library
SkPathEffect.h
Go to the documentation of this file.
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 
12 #include "include/core/SkPath.h"
13 #include "include/core/SkPoint.h"
14 #include "include/core/SkRect.h"
15 
16 class SkPath;
17 class SkStrokeRec;
18 
28 public:
37 
45 
61  bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect* cullR) const;
62 
67  void computeFastBounds(SkRect* dst, const SkRect& src) const;
68 
74  class PointData {
75  public:
77  : fFlags(0)
78  , fPoints(nullptr)
79  , fNumPoints(0) {
80  fSize.set(SK_Scalar1, SK_Scalar1);
81  // 'asPoints' needs to initialize/fill-in 'fClipRect' if it sets
82  // the kUseClip flag
83  }
85  delete [] fPoints;
86  }
87 
88  // TODO: consider using passed-in flags to limit the work asPoints does.
89  // For example, a kNoPath flag could indicate don't bother generating
90  // stamped solutions.
91 
92  // Currently none of these flags are supported.
93  enum PointFlags {
94  kCircles_PointFlag = 0x01, // draw points as circles (instead of rects)
95  kUsePath_PointFlag = 0x02, // draw points as stamps of the returned path
96  kUseClip_PointFlag = 0x04, // apply 'fClipRect' before drawing the points
97  };
98 
99  uint32_t fFlags; // flags that impact the drawing of the points
100  SkPoint* fPoints; // the center point of each generated point
101  int fNumPoints; // number of points in fPoints
102  SkVector fSize; // the size to draw the points
103  SkRect fClipRect; // clip required to draw the points (if kUseClip is set)
104  SkPath fPath; // 'stamp' to be used at each point (if kUsePath is set)
105 
106  SkPath fFirst; // If not empty, contains geometry for first point
107  SkPath fLast; // If not empty, contains geometry for last point
108  };
109 
114  bool asPoints(PointData* results, const SkPath& src,
115  const SkStrokeRec&, const SkMatrix&,
116  const SkRect* cullR) const;
117 
128  enum DashType {
131  };
132 
133  struct DashInfo {
134  DashInfo() : fIntervals(nullptr), fCount(0), fPhase(0) {}
135  DashInfo(SkScalar* intervals, int32_t count, SkScalar phase)
136  : fIntervals(intervals), fCount(count), fPhase(phase) {}
137 
139  // Even values represent ons, and odds offs
140  int32_t fCount;
142  // mod the sum of all intervals
143  };
144 
145  DashType asADash(DashInfo* info) const;
146 
147  static void RegisterFlattenables();
148 
150  return kSkPathEffect_Type;
151  }
152 
154  return kSkPathEffect_Type;
155  }
156 
157  static sk_sp<SkPathEffect> Deserialize(const void* data, size_t size,
158  const SkDeserialProcs* procs = nullptr) {
159  return sk_sp<SkPathEffect>(static_cast<SkPathEffect*>(
161  kSkPathEffect_Type, data, size, procs).release()));
162  }
163 
164 protected:
166 
167  virtual bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const = 0;
168  virtual SkRect onComputeFastBounds(const SkRect& src) const {
169  return src;
170  }
171  virtual bool onAsPoints(PointData*, const SkPath&, const SkStrokeRec&, const SkMatrix&,
172  const SkRect*) const {
173  return false;
174  }
175  virtual DashType onAsADash(DashInfo*) const {
176  return kNone_DashType;
177  }
178 
179 private:
180  // illegal
181  SkPathEffect(const SkPathEffect&);
182  SkPathEffect& operator=(const SkPathEffect&);
183 
184  using INHERITED = SkFlattenable;
185 };
186 
187 #endif
SkPathEffect::PointData::fFirst
SkPath fFirst
Definition: SkPathEffect.h:106
SkPathEffect::PointData::fNumPoints
int fNumPoints
Definition: SkPathEffect.h:101
SkFlattenable.h
SkPathEffect::PointData::PointData
PointData()
Definition: SkPathEffect.h:76
SkPath
Definition: SkPath.h:44
SkPathEffect::DashInfo::DashInfo
DashInfo()
Definition: SkPathEffect.h:134
SkPathEffect::asPoints
bool asPoints(PointData *results, const SkPath &src, const SkStrokeRec &, const SkMatrix &, const SkRect *cullR) const
Does applying this path effect to 'src' yield a set of points? If so, optionally return the points in...
SkPathEffect::PointData
Definition: SkPathEffect.h:74
SkPathEffect::DashType
DashType
If the PathEffect can be represented as a dash pattern, asADash will return kDash_DashType and None o...
Definition: SkPathEffect.h:128
SkPathEffect::computeFastBounds
void computeFastBounds(SkRect *dst, const SkRect &src) const
Compute a conservative bounds for its effect, given the src bounds.
SkPathEffect::RegisterFlattenables
static void RegisterFlattenables()
SkRect.h
SkFlattenable::Deserialize
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
SkPathEffect
Definition: SkPathEffect.h:27
SkPathEffect::onAsPoints
virtual bool onAsPoints(PointData *, const SkPath &, const SkStrokeRec &, const SkMatrix &, const SkRect *) const
Definition: SkPathEffect.h:171
SkFlattenable::Type
Type
Definition: SkFlattenable.h:28
SkPathEffect::GetFlattenableType
static SkFlattenable::Type GetFlattenableType()
Definition: SkPathEffect.h:149
SkPathEffect::asADash
DashType asADash(DashInfo *info) const
SkPathEffect::DashInfo::fPhase
SkScalar fPhase
Offset into the dashed interval pattern.
Definition: SkPathEffect.h:141
SkPathEffect::MakeSum
static sk_sp< SkPathEffect > MakeSum(sk_sp< SkPathEffect > first, sk_sp< SkPathEffect > second)
Returns a patheffect that apples each effect (first and second) to the original path,...
SkFlattenable::kSkPathEffect_Type
@ kSkPathEffect_Type
Definition: SkFlattenable.h:34
sk_sp< SkPathEffect >
SkPoint
Definition: SkPoint.h:160
SkFlattenable::SkFlattenable
SkFlattenable()
Definition: SkFlattenable.h:45
SK_API
#define SK_API
Definition: SkTypes.h:181
SkStrokeRec
Definition: SkStrokeRec.h:17
SkPathEffect::DashInfo::fIntervals
SkScalar * fIntervals
Length of on/off intervals for dashed lines.
Definition: SkPathEffect.h:138
SkPathEffect::kNone_DashType
@ kNone_DashType
ignores the info parameter
Definition: SkPathEffect.h:129
SkPathEffect::getFlattenableType
SkFlattenable::Type getFlattenableType() const override
Definition: SkPathEffect.h:153
SkPathEffect::Deserialize
static sk_sp< SkPathEffect > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
Definition: SkPathEffect.h:157
SkPoint.h
SK_Scalar1
#define SK_Scalar1
Definition: SkScalar.h:18
SkPathEffect::MakeCompose
static sk_sp< SkPathEffect > MakeCompose(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
Returns a patheffect that applies the inner effect to the path, and then applies the outer effect to ...
SkPathEffect::PointData::fPoints
SkPoint * fPoints
Definition: SkPathEffect.h:100
SkPathEffect::PointData::fClipRect
SkRect fClipRect
Definition: SkPathEffect.h:103
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkPathEffect::onFilterPath
virtual bool onFilterPath(SkPath *, const SkPath &, SkStrokeRec *, const SkRect *) const =0
SkPathEffect::PointData::fFlags
uint32_t fFlags
Definition: SkPathEffect.h:99
SkPath.h
SkPathEffect::onComputeFastBounds
virtual SkRect onComputeFastBounds(const SkRect &src) const
Definition: SkPathEffect.h:168
SkPathEffect::PointData::fPath
SkPath fPath
Definition: SkPathEffect.h:104
SkPathEffect::kDash_DashType
@ kDash_DashType
fills in all of the info parameter
Definition: SkPathEffect.h:130
SkPathEffect::filterPath
bool filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *, const SkRect *cullR) const
Given a src path (input) and a stroke-rec (input and output), apply this effect to the src path,...
SkMatrix
Definition: SkMatrix.h:48
SkPathEffect::SkPathEffect
SkPathEffect()
Definition: SkPathEffect.h:165
SkPathEffect::PointData::PointFlags
PointFlags
Definition: SkPathEffect.h:93
SkPathEffect::PointData::~PointData
~PointData()
Definition: SkPathEffect.h:84
SkPathEffect::DashInfo::fCount
int32_t fCount
Number of intervals in the dash. Should be even number.
Definition: SkPathEffect.h:140
SkRect
Definition: SkRect.h:572
SkDeserialProcs
Definition: SkSerialProcs.h:61
SkPathEffect::PointData::fLast
SkPath fLast
Definition: SkPathEffect.h:107
SkPathEffect::onAsADash
virtual DashType onAsADash(DashInfo *) const
Definition: SkPathEffect.h:175
SkFlattenable
Definition: SkFlattenable.h:26
SkPathEffect::DashInfo::DashInfo
DashInfo(SkScalar *intervals, int32_t count, SkScalar phase)
Definition: SkPathEffect.h:135
SkPathEffect::PointData::fSize
SkVector fSize
Definition: SkPathEffect.h:102
SkPathEffect::DashInfo
Definition: SkPathEffect.h:133