Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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#include "include/core/SkPath.h"
13#include "include/core/SkRect.h"
20
21#include <utility>
22#include <vector>
23
24class SkCanvas;
25class SkMatrix;
26struct SkPoint;
27
28namespace sksg {
29class InvalidationController;
30
31/**
32 * Base class for geometry effects.
33 */
35protected:
37 ~GeometryEffect() override;
38
39 void onClip(SkCanvas*, bool antiAlias) const final;
40 void onDraw(SkCanvas*, const SkPaint&) const final;
41 bool onContains(const SkPoint&) const final;
42
44 SkPath onAsPath() const final;
45
47
48private:
49 const sk_sp<GeometryNode> fChild;
50 SkPath fPath; // transformed child cache.
51
52 using INHERITED = GeometryNode;
53};
54
55/**
56 * Apply a trim effect to the child geometry.
57 */
58class TrimEffect final : public GeometryEffect {
59public:
61 return child ? sk_sp<TrimEffect>(new TrimEffect(std::move(child))) : nullptr;
62 }
63
64 SG_ATTRIBUTE(Start , SkScalar , fStart )
65 SG_ATTRIBUTE(Stop , SkScalar , fStop )
67
68private:
69 explicit TrimEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
70
72
73 SkScalar fStart = 0,
74 fStop = 1;
76
77 using INHERITED = GeometryEffect;
78};
79
80/**
81 * Apply a transform to a GeometryNode.
82 */
83class GeometryTransform final : public GeometryEffect {
84public:
86 return child && transform
87 ? sk_sp<GeometryTransform>(new GeometryTransform(std::move(child),
88 std::move(transform)))
89 : nullptr;
90 }
91
92 ~GeometryTransform() override;
93
94 const sk_sp<Transform>& getTransform() const { return fTransform; }
95
96private:
98
100
101 const sk_sp<Transform> fTransform;
102
103 using INHERITED = GeometryEffect;
104};
105
106/**
107 * Apply a dash effect to the child geometry.
108 *
109 * Follows the same semantics as SkDashPathEffect, with one minor tweak: when the number of
110 * intervals is odd, they are repeated once more to attain an even sequence (same as SVG
111 * stroke-dasharray: https://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty).
112 */
113class DashEffect final : public GeometryEffect {
114public:
116 return child ? sk_sp<DashEffect>(new DashEffect(std::move(child))) : nullptr;
117 }
118
119 SG_ATTRIBUTE(Intervals, std::vector<float>, fIntervals)
120 SG_ATTRIBUTE(Phase, float , fPhase )
121
122private:
123 explicit DashEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
124
126
127 std::vector<float> fIntervals;
128 float fPhase = 0;
129
130 using INHERITED = GeometryEffect;
131};
132
133/**
134 * Apply a rounded-corner effect to the child geometry.
135 */
136class RoundEffect final : public GeometryEffect {
137public:
139 return child ? sk_sp<RoundEffect>(new RoundEffect(std::move(child))) : nullptr;
140 }
141
142 SG_ATTRIBUTE(Radius, SkScalar, fRadius)
143
144private:
145 explicit RoundEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
146
148
149 SkScalar fRadius = 0;
150
151 using INHERITED = GeometryEffect;
152};
153
154/**
155 * Apply an offset effect to the child geometry.
156 */
157class OffsetEffect final : public GeometryEffect {
158public:
160 return child ? sk_sp<OffsetEffect>(new OffsetEffect(std::move(child))) : nullptr;
161 }
162
163 SG_ATTRIBUTE(Offset , SkScalar , fOffset )
164 SG_ATTRIBUTE(MiterLimit , SkScalar , fMiterLimit)
165 SG_ATTRIBUTE(Join , SkPaint::Join, fJoin )
166
167private:
168 explicit OffsetEffect(sk_sp<GeometryNode> child) : INHERITED(std::move(child)) {}
169
171
172 SkScalar fOffset = 0,
173 fMiterLimit = 4;
175
176 using INHERITED = GeometryEffect;
177};
178
179} // namespace sksg
180
181#endif // SkSGGeometryEffect_DEFINED
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition SkSGNode.h:100
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
SkPath onRevalidateEffect(const sk_sp< GeometryNode > &) override
static sk_sp< DashEffect > Make(sk_sp< GeometryNode > child)
void onDraw(SkCanvas *, const SkPaint &) const final
bool onContains(const SkPoint &) const final
virtual SkPath onRevalidateEffect(const sk_sp< GeometryNode > &)=0
void onClip(SkCanvas *, bool antiAlias) const final
SkRect onRevalidate(InvalidationController *, const SkMatrix &) final
SkPath onAsPath() const final
static sk_sp< GeometryTransform > Make(sk_sp< GeometryNode > child, sk_sp< Transform > transform)
SkPath onRevalidateEffect(const sk_sp< GeometryNode > &) override
const sk_sp< Transform > & getTransform() const
static sk_sp< OffsetEffect > Make(sk_sp< GeometryNode > child)
SkPath onRevalidateEffect(const sk_sp< GeometryNode > &) override
SkPath onRevalidateEffect(const sk_sp< GeometryNode > &) override
static sk_sp< RoundEffect > Make(sk_sp< GeometryNode > child)
static sk_sp< TrimEffect > Make(sk_sp< GeometryNode > child)
SkPath onRevalidateEffect(const sk_sp< GeometryNode > &) override
float SkScalar
Definition extension.cpp:12
Definition Skottie.h:32
Definition ref_ptr.h:256
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47