Flutter Engine
The Flutter Engine
Effects.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 SkottieEffects_DEFINED
9#define SkottieEffects_DEFINED
10
13#include "include/core/SkSize.h"
18#include "src/utils/SkJSON.h" // IWYU pragma: keep
19
20#include <cstddef>
21
22namespace sksg {
23class RenderNode;
24} // namespace sksg
25
26namespace skottie {
27namespace internal {
28class AnimationBuilder;
29class LayerBuilder;
30
31class EffectBuilder final : public SkNoncopyable {
32public:
34
37
40
41 static const skjson::Value& GetPropValue(const skjson::ArrayValue& jprops, size_t prop_index);
42
43 LayerBuilder* getLayerBuilder(int layer_index) const {
44 return fCompBuilder->layerBuilder(layer_index);
45 }
46
47private:
48 using EffectBuilderT = sk_sp<sksg::RenderNode>(EffectBuilder::*)(const skjson::ArrayValue&,
50
51 sk_sp<sksg::RenderNode> attachBlackAndWhiteEffect (const skjson::ArrayValue&,
53 sk_sp<sksg::RenderNode> attachBrightnessContrastEffect(const skjson::ArrayValue&,
55 sk_sp<sksg::RenderNode> attachBulgeEffect (const skjson::ArrayValue&,
57 sk_sp<sksg::RenderNode> attachCornerPinEffect (const skjson::ArrayValue&,
59 sk_sp<sksg::RenderNode> attachCCTonerEffect (const skjson::ArrayValue&,
61 sk_sp<sksg::RenderNode> attachDirectionalBlurEffect (const skjson::ArrayValue&,
63 sk_sp<sksg::RenderNode> attachDisplacementMapEffect (const skjson::ArrayValue&,
65 sk_sp<sksg::RenderNode> attachDropShadowEffect (const skjson::ArrayValue&,
67 sk_sp<sksg::RenderNode> attachFillEffect (const skjson::ArrayValue&,
69 sk_sp<sksg::RenderNode> attachFractalNoiseEffect (const skjson::ArrayValue&,
71 sk_sp<sksg::RenderNode> attachGaussianBlurEffect (const skjson::ArrayValue&,
73 sk_sp<sksg::RenderNode> attachGradientEffect (const skjson::ArrayValue&,
75 sk_sp<sksg::RenderNode> attachHueSaturationEffect (const skjson::ArrayValue&,
77 sk_sp<sksg::RenderNode> attachInvertEffect (const skjson::ArrayValue&,
79 sk_sp<sksg::RenderNode> attachEasyLevelsEffect (const skjson::ArrayValue&,
81 sk_sp<sksg::RenderNode> attachLinearWipeEffect (const skjson::ArrayValue&,
83 sk_sp<sksg::RenderNode> attachMotionTileEffect (const skjson::ArrayValue&,
85 sk_sp<sksg::RenderNode> attachProLevelsEffect (const skjson::ArrayValue&,
87 sk_sp<sksg::RenderNode> attachRadialWipeEffect (const skjson::ArrayValue&,
89 sk_sp<sksg::RenderNode> attachSharpenEffect (const skjson::ArrayValue&,
91 sk_sp<sksg::RenderNode> attachShiftChannelsEffect (const skjson::ArrayValue&,
93 sk_sp<sksg::RenderNode> attachSkSLColorFilter (const skjson::ArrayValue&,
95 sk_sp<sksg::RenderNode> attachSkSLShader (const skjson::ArrayValue&,
97 sk_sp<sksg::RenderNode> attachSphereEffect (const skjson::ArrayValue&,
99 sk_sp<sksg::RenderNode> attachThresholdEffect (const skjson::ArrayValue&,
101 sk_sp<sksg::RenderNode> attachTintEffect (const skjson::ArrayValue&,
103 sk_sp<sksg::RenderNode> attachTransformEffect (const skjson::ArrayValue&,
105 sk_sp<sksg::RenderNode> attachTritoneEffect (const skjson::ArrayValue&,
107 sk_sp<sksg::RenderNode> attachVenetianBlindsEffect (const skjson::ArrayValue&,
109
110 sk_sp<sksg::RenderNode> attachDropShadowStyle(const skjson::ObjectValue&,
112 sk_sp<sksg::RenderNode> attachInnerShadowStyle(const skjson::ObjectValue&,
114 sk_sp<sksg::RenderNode> attachInnerGlowStyle(const skjson::ObjectValue&,
116 sk_sp<sksg::RenderNode> attachOuterGlowStyle(const skjson::ObjectValue&,
118
119 EffectBuilderT findBuilder(const skjson::ObjectValue&) const;
120
121 const AnimationBuilder* fBuilder;
122 CompositionBuilder* fCompBuilder;
123 const SkSize fLayerSize;
124};
125
126// Syntactic sugar/helper.
128public:
130 const AnimationBuilder& abuilder,
131 AnimatablePropertyContainer* acontainer)
132 : fProps(jprops)
133 , fBuilder(abuilder)
134 , fContainer(acontainer) {}
135
136 template <typename T>
137 const EffectBinder& bind(size_t prop_index, T& value) const {
138 fContainer->bind(fBuilder, EffectBuilder::GetPropValue(fProps, prop_index), value);
139
140 return *this;
141 }
142
143private:
144 const skjson::ArrayValue& fProps;
145 const AnimationBuilder& fBuilder;
146 AnimatablePropertyContainer* fContainer;
147};
148
149/**
150 * Base class for mask-shader-related effects.
151 */
153public:
154 const sk_sp<sksg::MaskShaderEffect>& node() const { return fMaskEffectNode; }
155
156protected:
158
159 const SkSize& layerSize() const { return fLayerSize; }
160
161 struct MaskInfo {
164 };
165 virtual MaskInfo onMakeMask() const = 0;
166
167private:
168 void onSync() final;
169
170 const sk_sp<sksg::MaskShaderEffect> fMaskEffectNode;
171 const SkSize fLayerSize;
172};
173
174} // namespace internal
175} // namespace skottie
176
177#endif // SkottieEffects_DEFINED
bool bind(const AnimationBuilder &, const skjson::ObjectValue *, T *)
LayerBuilder * layerBuilder(int layer_index)
EffectBinder(const skjson::ArrayValue &jprops, const AnimationBuilder &abuilder, AnimatablePropertyContainer *acontainer)
Definition: Effects.h:129
const EffectBinder & bind(size_t prop_index, T &value) const
Definition: Effects.h:137
sk_sp< sksg::RenderNode > attachEffects(const skjson::ArrayValue &, sk_sp< sksg::RenderNode >) const
Definition: Effects.cpp:112
EffectBuilder(const AnimationBuilder *, const SkSize &, CompositionBuilder *)
Definition: Effects.cpp:27
static const skjson::Value & GetPropValue(const skjson::ArrayValue &jprops, size_t prop_index)
Definition: Effects.cpp:181
LayerBuilder * getLayerBuilder(int layer_index) const
Definition: Effects.h:43
sk_sp< sksg::RenderNode > attachStyles(const skjson::ArrayValue &, sk_sp< sksg::RenderNode >) const
Definition: Effects.cpp:141
MaskShaderEffectBase(sk_sp< sksg::RenderNode >, const SkSize &)
Definition: Effects.cpp:194
virtual MaskInfo onMakeMask() const =0
const sk_sp< sksg::MaskShaderEffect > & node() const
Definition: Effects.h:154
const SkSize & layerSize() const
Definition: Effects.h:159
uint8_t value
Definition: Skottie.h:32
#define T
Definition: precompiler.cc:65
Definition: SkSize.h:52