Flutter Engine
The Flutter Engine
SkSGRenderEffect.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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 SkSGRenderEffect_DEFINED
9#define SkSGRenderEffect_DEFINED
10
15#include "include/core/SkRect.h"
24
25#include <optional>
26
27class SkCanvas;
28class SkMatrix;
29
30// TODO: merge EffectNode.h with this header
31
32namespace sksg {
33class InvalidationController;
34class RenderNode;
35
36/**
37 * Shader base class.
38 */
39class Shader : public Node {
40public:
41 ~Shader() override;
42
43 const sk_sp<SkShader>& getShader() const {
44 SkASSERT(!this->hasInval());
45 return fShader;
46 }
47
48protected:
49 Shader();
50
52
54
55private:
56 sk_sp<SkShader> fShader;
57
58 using INHERITED = Node;
59};
60
61/**
62 * Attaches a shader to the render DAG.
63 */
64class ShaderEffect final : public EffectNode {
65public:
66 ~ShaderEffect() override;
67
68 static sk_sp<ShaderEffect> Make(sk_sp<RenderNode> child, sk_sp<Shader> shader = nullptr);
69
71
72protected:
73 void onRender(SkCanvas*, const RenderContext*) const override;
74
76
77private:
79
80 sk_sp<Shader> fShader;
81
82 using INHERITED = EffectNode;
83};
84
85/**
86 * Attaches a mask shader to the render DAG.
87 */
88class MaskShaderEffect final : public EffectNode {
89public:
91
93
94protected:
95 void onRender(SkCanvas*, const RenderContext*) const override;
96
97private:
99
100 sk_sp<SkShader> fShader;
101
102 using INHERITED = EffectNode;
103};
104
105/**
106 * ImageFilter base class.
107 */
108class ImageFilter : public Node {
109public:
110 ~ImageFilter() override;
111
113 SkASSERT(!this->hasInval());
114 return fFilter;
115 }
116
117 SG_ATTRIBUTE(CropRect, SkImageFilters::CropRect, fCropRect)
118
119protected:
120 ImageFilter();
121
123
125
126private:
127 sk_sp<SkImageFilter> fFilter;
128 SkImageFilters::CropRect fCropRect = std::nullopt;
129
130 using INHERITED = Node;
131};
132
133/**
134 * Attaches an ImageFilter (chain) to the render DAG.
135 */
136class ImageFilterEffect final : public EffectNode {
137public:
138 ~ImageFilterEffect() override;
139
141
142 enum class Cropping {
143 kNone, // Doesn't use a crop rect.
144 kContent, // Uses the content bounding box as a crop rect.
145 };
146
147 SG_ATTRIBUTE(Cropping, Cropping, fCropping)
148
149protected:
150 void onRender(SkCanvas*, const RenderContext*) const override;
151 const RenderNode* onNodeAt(const SkPoint&) const override;
152
154
155private:
157
158 sk_sp<ImageFilter> fImageFilter;
159 Cropping fCropping = Cropping::kNone;
160
161 using INHERITED = EffectNode;
162};
163
164/**
165 * Wrapper for externally-managed SkImageFilters.
166 */
167class ExternalImageFilter final : public ImageFilter {
168public:
170
173 }
174
176
177private:
179
180 sk_sp<SkImageFilter> onRevalidateFilter() override { return fImageFilter; }
181
182 sk_sp<SkImageFilter> fImageFilter;
183};
184
185/**
186 * SkDropShadowImageFilter node.
187 */
188class DropShadowImageFilter final : public ImageFilter {
189public:
191
193
194 enum class Mode { kShadowAndForeground, kShadowOnly };
195
196 SG_ATTRIBUTE(Offset, SkVector, fOffset)
197 SG_ATTRIBUTE(Sigma , SkVector, fSigma )
198 SG_ATTRIBUTE(Color , SkColor , fColor )
199 SG_ATTRIBUTE(Mode , Mode , fMode )
200
201protected:
203
204private:
205 explicit DropShadowImageFilter();
206
207 SkVector fOffset = { 0, 0 },
208 fSigma = { 0, 0 };
209 SkColor fColor = SK_ColorBLACK;
211
212 using INHERITED = ImageFilter;
213};
214
215/**
216 * SkBlurImageFilter node.
217 */
218class BlurImageFilter final : public ImageFilter {
219public:
221
223
224 SG_ATTRIBUTE(Sigma , SkVector , fSigma )
225 SG_ATTRIBUTE(TileMode, SkTileMode, fTileMode)
226
227protected:
229
230private:
231 explicit BlurImageFilter();
232
233 SkVector fSigma = { 0, 0 };
234 SkTileMode fTileMode = SkTileMode::kDecal;
235
236 using INHERITED = ImageFilter;
237};
238
239/**
240 * Applies an SkBlender to descendant render nodes.
241 */
242class BlenderEffect final : public EffectNode {
243public:
244 ~BlenderEffect() override;
245
247
248 SG_ATTRIBUTE(Blender, sk_sp<SkBlender>, fBlender)
249
250protected:
251 void onRender(SkCanvas*, const RenderContext*) const override;
252 const RenderNode* onNodeAt(const SkPoint&) const override;
253
254private:
256
257 sk_sp<SkBlender> fBlender;
258
259 using INHERITED = EffectNode;
260};
261
262class LayerEffect final : public EffectNode {
263public:
264 ~LayerEffect() override;
265
268
270
271private:
273
274 void onRender(SkCanvas*, const RenderContext*) const override;
275
276 SkBlendMode fMode;
277
278 using INHERITED = EffectNode;
279};
280
281} // namespace sksg
282
283#endif // SkSGRenderEffect_DEFINED
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOver
r = s + (1-sa)*d
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:100
SkTileMode
Definition: SkTileMode.h:13
void onRender(SkCanvas *, const RenderContext *) const override
const RenderNode * onNodeAt(const SkPoint &) const override
static sk_sp< BlenderEffect > Make(sk_sp< RenderNode > child, sk_sp< SkBlender >=nullptr)
~BlenderEffect() override
~BlurImageFilter() override
static sk_sp< BlurImageFilter > Make()
sk_sp< SkImageFilter > onRevalidateFilter() override
static sk_sp< DropShadowImageFilter > Make()
sk_sp< SkImageFilter > onRevalidateFilter() override
EffectNode(sk_sp< RenderNode >, uint32_t inval_traits=0)
static sk_sp< ExternalImageFilter > Make()
const RenderNode * onNodeAt(const SkPoint &) const override
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
static sk_sp< RenderNode > Make(sk_sp< RenderNode > child, sk_sp< ImageFilter > filter)
void onRender(SkCanvas *, const RenderContext *) const override
~ImageFilter() override
const sk_sp< SkImageFilter > & getFilter() const
SkRect onRevalidate(InvalidationController *, const SkMatrix &) final
virtual sk_sp< SkImageFilter > onRevalidateFilter()=0
static sk_sp< LayerEffect > Make(sk_sp< RenderNode > child, SkBlendMode mode=SkBlendMode::kSrcOver)
~LayerEffect() override
static sk_sp< MaskShaderEffect > Make(sk_sp< RenderNode >, sk_sp< SkShader >=nullptr)
void onRender(SkCanvas *, const RenderContext *) const override
bool hasInval() const
Definition: SkSGNode.h:60
Node(uint32_t invalTraits)
Definition: SkSGNode.cpp:45
friend class ImageFilterEffect
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
void setShader(sk_sp< Shader >)
static sk_sp< ShaderEffect > Make(sk_sp< RenderNode > child, sk_sp< Shader > shader=nullptr)
void onRender(SkCanvas *, const RenderContext *) const override
const sk_sp< SkShader > & getShader() const
SkRect onRevalidate(InvalidationController *, const SkMatrix &) final
~Shader() override
virtual sk_sp< SkShader > onRevalidateShader()=0
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
SkTileMode TileMode(jint tm)
Definition: Utils.cpp:26
Definition: Skottie.h:32