2 * Copyright 2019 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkottieEffects_DEFINED
9 #define SkottieEffects_DEFINED
11 #include "modules/skottie/src/Composition.h"
12 #include "modules/skottie/src/SkottiePriv.h"
13 #include "modules/skottie/src/animator/Animator.h"
18 class MaskShaderEffect;
24 class EffectBuilder final : public SkNoncopyable {
26 EffectBuilder(const AnimationBuilder*, const SkSize&, CompositionBuilder*);
28 sk_sp<sksg::RenderNode> attachEffects(const skjson::ArrayValue&,
29 sk_sp<sksg::RenderNode>) const;
31 sk_sp<sksg::RenderNode> attachStyles(const skjson::ArrayValue&,
32 sk_sp<sksg::RenderNode>) const;
34 static const skjson::Value& GetPropValue(const skjson::ArrayValue& jprops, size_t prop_index);
36 LayerBuilder* getLayerBuilder(int layer_index) const {
37 return fCompBuilder->layerBuilder(layer_index);
41 using EffectBuilderT = sk_sp<sksg::RenderNode>(EffectBuilder::*)(const skjson::ArrayValue&,
42 sk_sp<sksg::RenderNode>) const;
44 sk_sp<sksg::RenderNode> attachBlackAndWhiteEffect (const skjson::ArrayValue&,
45 sk_sp<sksg::RenderNode>) const;
46 sk_sp<sksg::RenderNode> attachBrightnessContrastEffect(const skjson::ArrayValue&,
47 sk_sp<sksg::RenderNode>) const;
48 sk_sp<sksg::RenderNode> attachBulgeEffect (const skjson::ArrayValue&,
49 sk_sp<sksg::RenderNode>) const;
50 sk_sp<sksg::RenderNode> attachCornerPinEffect (const skjson::ArrayValue&,
51 sk_sp<sksg::RenderNode>) const;
52 sk_sp<sksg::RenderNode> attachCCTonerEffect (const skjson::ArrayValue&,
53 sk_sp<sksg::RenderNode>) const;
54 sk_sp<sksg::RenderNode> attachDirectionalBlurEffect (const skjson::ArrayValue&,
55 sk_sp<sksg::RenderNode>) const;
56 sk_sp<sksg::RenderNode> attachDisplacementMapEffect (const skjson::ArrayValue&,
57 sk_sp<sksg::RenderNode>) const;
58 sk_sp<sksg::RenderNode> attachDropShadowEffect (const skjson::ArrayValue&,
59 sk_sp<sksg::RenderNode>) const;
60 sk_sp<sksg::RenderNode> attachFillEffect (const skjson::ArrayValue&,
61 sk_sp<sksg::RenderNode>) const;
62 sk_sp<sksg::RenderNode> attachFractalNoiseEffect (const skjson::ArrayValue&,
63 sk_sp<sksg::RenderNode>) const;
64 sk_sp<sksg::RenderNode> attachGaussianBlurEffect (const skjson::ArrayValue&,
65 sk_sp<sksg::RenderNode>) const;
66 sk_sp<sksg::RenderNode> attachGradientEffect (const skjson::ArrayValue&,
67 sk_sp<sksg::RenderNode>) const;
68 sk_sp<sksg::RenderNode> attachHueSaturationEffect (const skjson::ArrayValue&,
69 sk_sp<sksg::RenderNode>) const;
70 sk_sp<sksg::RenderNode> attachInvertEffect (const skjson::ArrayValue&,
71 sk_sp<sksg::RenderNode>) const;
72 sk_sp<sksg::RenderNode> attachEasyLevelsEffect (const skjson::ArrayValue&,
73 sk_sp<sksg::RenderNode>) const;
74 sk_sp<sksg::RenderNode> attachLinearWipeEffect (const skjson::ArrayValue&,
75 sk_sp<sksg::RenderNode>) const;
76 sk_sp<sksg::RenderNode> attachMotionTileEffect (const skjson::ArrayValue&,
77 sk_sp<sksg::RenderNode>) const;
78 sk_sp<sksg::RenderNode> attachProLevelsEffect (const skjson::ArrayValue&,
79 sk_sp<sksg::RenderNode>) const;
80 sk_sp<sksg::RenderNode> attachRadialWipeEffect (const skjson::ArrayValue&,
81 sk_sp<sksg::RenderNode>) const;
82 sk_sp<sksg::RenderNode> attachSharpenEffect (const skjson::ArrayValue&,
83 sk_sp<sksg::RenderNode>) const;
84 sk_sp<sksg::RenderNode> attachShiftChannelsEffect (const skjson::ArrayValue&,
85 sk_sp<sksg::RenderNode>) const;
86 sk_sp<sksg::RenderNode> attachSkSLColorFilter (const skjson::ArrayValue&,
87 sk_sp<sksg::RenderNode>) const;
88 sk_sp<sksg::RenderNode> attachSkSLShader (const skjson::ArrayValue&,
89 sk_sp<sksg::RenderNode>) const;
90 sk_sp<sksg::RenderNode> attachSphereEffect (const skjson::ArrayValue&,
91 sk_sp<sksg::RenderNode>) const;
92 sk_sp<sksg::RenderNode> attachThresholdEffect (const skjson::ArrayValue&,
93 sk_sp<sksg::RenderNode>) const;
94 sk_sp<sksg::RenderNode> attachTintEffect (const skjson::ArrayValue&,
95 sk_sp<sksg::RenderNode>) const;
96 sk_sp<sksg::RenderNode> attachTransformEffect (const skjson::ArrayValue&,
97 sk_sp<sksg::RenderNode>) const;
98 sk_sp<sksg::RenderNode> attachTritoneEffect (const skjson::ArrayValue&,
99 sk_sp<sksg::RenderNode>) const;
100 sk_sp<sksg::RenderNode> attachVenetianBlindsEffect (const skjson::ArrayValue&,
101 sk_sp<sksg::RenderNode>) const;
103 sk_sp<sksg::RenderNode> attachDropShadowStyle(const skjson::ObjectValue&,
104 sk_sp<sksg::RenderNode>) const;
105 sk_sp<sksg::RenderNode> attachInnerShadowStyle(const skjson::ObjectValue&,
106 sk_sp<sksg::RenderNode>) const;
107 sk_sp<sksg::RenderNode> attachInnerGlowStyle(const skjson::ObjectValue&,
108 sk_sp<sksg::RenderNode>) const;
109 sk_sp<sksg::RenderNode> attachOuterGlowStyle(const skjson::ObjectValue&,
110 sk_sp<sksg::RenderNode>) const;
112 EffectBuilderT findBuilder(const skjson::ObjectValue&) const;
114 const AnimationBuilder* fBuilder;
115 CompositionBuilder* fCompBuilder;
116 const SkSize fLayerSize;
119 // Syntactic sugar/helper.
122 EffectBinder(const skjson::ArrayValue& jprops,
123 const AnimationBuilder& abuilder,
124 AnimatablePropertyContainer* acontainer)
127 , fContainer(acontainer) {}
129 template <typename T>
130 const EffectBinder& bind(size_t prop_index, T& value) const {
131 fContainer->bind(fBuilder, EffectBuilder::GetPropValue(fProps, prop_index), value);
137 const skjson::ArrayValue& fProps;
138 const AnimationBuilder& fBuilder;
139 AnimatablePropertyContainer* fContainer;
143 * Base class for mask-shader-related effects.
145 class MaskShaderEffectBase : public AnimatablePropertyContainer {
147 const sk_sp<sksg::MaskShaderEffect>& node() const { return fMaskEffectNode; }
150 MaskShaderEffectBase(sk_sp<sksg::RenderNode>, const SkSize&);
152 const SkSize& layerSize() const { return fLayerSize; }
155 sk_sp<SkShader> fMaskShader;
158 virtual MaskInfo onMakeMask() const = 0;
163 const sk_sp<sksg::MaskShaderEffect> fMaskEffectNode;
164 const SkSize fLayerSize;
167 } // namespace internal
168 } // namespace skottie
170 #endif // SkottieEffects_DEFINED