Skia
2D Graphics Library
SkSGGeometryEffect.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Google Inc.
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 SkSGGeometryEffect_DEFINED
9 #define SkSGGeometryEffect_DEFINED
10 
12 
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkPath.h"
17 
18 namespace sksg {
19 
23 class GeometryEffect : public GeometryNode {
24 protected:
26  ~GeometryEffect() override;
27 
28  void onClip(SkCanvas*, bool antiAlias) const final;
29  void onDraw(SkCanvas*, const SkPaint&) const final;
30  bool onContains(const SkPoint&) const final;
31 
33  SkPath onAsPath() const final;
34 
36 
37 private:
38  const sk_sp<GeometryNode> fChild;
39  SkPath fPath; // transformed child cache.
40 
41  using INHERITED = GeometryNode;
42 };
43 
47 class TrimEffect final : public GeometryEffect {
48 public:
50  return child ? sk_sp<TrimEffect>(new TrimEffect(std::move(child))) : nullptr;
51  }
52 
53  SG_ATTRIBUTE(Start , SkScalar , fStart )
54  SG_ATTRIBUTE(Stop , SkScalar , fStop )
55  SG_ATTRIBUTE(Mode , SkTrimPathEffect::Mode, fMode )
56 
57 private:
58  explicit TrimEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
59 
61 
62  SkScalar fStart = 0,
63  fStop = 1;
65 
66  using INHERITED = GeometryEffect;
67 };
68 
72 class GeometryTransform final : public GeometryEffect {
73 public:
75  return child && transform
76  ? sk_sp<GeometryTransform>(new GeometryTransform(std::move(child),
77  std::move(transform)))
78  : nullptr;
79  }
80 
81  ~GeometryTransform() override;
82 
83  const sk_sp<Transform>& getTransform() const { return fTransform; }
84 
85 private:
87 
89 
90  const sk_sp<Transform> fTransform;
91 
92  using INHERITED = GeometryEffect;
93 };
94 
102 class DashEffect final : public GeometryEffect {
103 public:
105  return child ? sk_sp<DashEffect>(new DashEffect(std::move(child))) : nullptr;
106  }
107 
108  SG_ATTRIBUTE(Intervals, std::vector<float>, fIntervals)
109  SG_ATTRIBUTE(Phase, float , fPhase )
110 
111 private:
112  explicit DashEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
113 
115 
116  std::vector<float> fIntervals;
117  float fPhase = 0;
118 
119  using INHERITED = GeometryEffect;
120 };
121 
125 class RoundEffect final : public GeometryEffect {
126 public:
128  return child ? sk_sp<RoundEffect>(new RoundEffect(std::move(child))) : nullptr;
129  }
130 
131  SG_ATTRIBUTE(Radius, SkScalar, fRadius)
132 
133 private:
134  explicit RoundEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
135 
137 
138  SkScalar fRadius = 0;
139 
140  using INHERITED = GeometryEffect;
141 };
142 
146 class OffsetEffect final : public GeometryEffect {
147 public:
149  return child ? sk_sp<OffsetEffect>(new OffsetEffect(std::move(child))) : nullptr;
150  }
151 
152  SG_ATTRIBUTE(Offset , SkScalar , fOffset )
153  SG_ATTRIBUTE(MiterLimit , SkScalar , fMiterLimit)
154  SG_ATTRIBUTE(Join , SkPaint::Join, fJoin )
155 
156 private:
157  explicit OffsetEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
158 
160 
161  SkScalar fOffset = 0,
162  fMiterLimit = 4;
164 
165  using INHERITED = GeometryEffect;
166 };
167 
168 } // namespace sksg
169 
170 #endif // SkSGGeometryEffect_DEFINED
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:99
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
Join
Definition: SkPaint.h:358
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
SkPath contain geometry.
Definition: SkPath.h:58
Mode
Definition: SkTrimPathEffect.h:19
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Apply a dash effect to the child geometry.
Definition: SkSGGeometryEffect.h:102
static sk_sp< DashEffect > Make(sk_sp< GeometryNode > child)
Definition: SkSGGeometryEffect.h:104
Base class for geometry effects.
Definition: SkSGGeometryEffect.h:23
void onDraw(SkCanvas *, const SkPaint &) const final
~GeometryEffect() override
bool onContains(const SkPoint &) const final
virtual SkPath onRevalidateEffect(const sk_sp< GeometryNode > &)=0
void onClip(SkCanvas *, bool antiAlias) const final
GeometryEffect(sk_sp< GeometryNode >)
SkRect onRevalidate(InvalidationController *, const SkMatrix &) final
SkPath onAsPath() const final
Base class for nodes which provide 'geometry' (as opposed to paint) for drawing.
Definition: SkSGGeometryNode.h:25
Apply a transform to a GeometryNode.
Definition: SkSGGeometryEffect.h:72
~GeometryTransform() override
static sk_sp< GeometryTransform > Make(sk_sp< GeometryNode > child, sk_sp< Transform > transform)
Definition: SkSGGeometryEffect.h:74
const sk_sp< Transform > & getTransform() const
Definition: SkSGGeometryEffect.h:83
Receiver for invalidation events.
Definition: SkSGInvalidationController.h:25
Apply an offset effect to the child geometry.
Definition: SkSGGeometryEffect.h:146
static sk_sp< OffsetEffect > Make(sk_sp< GeometryNode > child)
Definition: SkSGGeometryEffect.h:148
Apply a rounded-corner effect to the child geometry.
Definition: SkSGGeometryEffect.h:125
static sk_sp< RoundEffect > Make(sk_sp< GeometryNode > child)
Definition: SkSGGeometryEffect.h:127
Apply a trim effect to the child geometry.
Definition: SkSGGeometryEffect.h:47
static sk_sp< TrimEffect > Make(sk_sp< GeometryNode > child)
Definition: SkSGGeometryEffect.h:49
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582