/* * Copyright 2019 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SkottieEffects_DEFINED #define SkottieEffects_DEFINED #include "modules/skottie/src/Composition.h" #include "modules/skottie/src/SkottiePriv.h" #include "modules/skottie/src/animator/Animator.h" class SkMaskFilter; namespace sksg { class MaskShaderEffect; } // namespace sksg namespace skottie { namespace internal { class EffectBuilder final : public SkNoncopyable { public: EffectBuilder(const AnimationBuilder*, const SkSize&, CompositionBuilder*); sk_sp attachEffects(const skjson::ArrayValue&, sk_sp) const; sk_sp attachStyles(const skjson::ArrayValue&, sk_sp) const; static const skjson::Value& GetPropValue(const skjson::ArrayValue& jprops, size_t prop_index); LayerBuilder* getLayerBuilder(int layer_index) const { return fCompBuilder->layerBuilder(layer_index); } private: using EffectBuilderT = sk_sp(EffectBuilder::*)(const skjson::ArrayValue&, sk_sp) const; sk_sp attachBlackAndWhiteEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachBrightnessContrastEffect(const skjson::ArrayValue&, sk_sp) const; sk_sp attachBulgeEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachCornerPinEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachCCTonerEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachDirectionalBlurEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachDisplacementMapEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachDropShadowEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachFillEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachFractalNoiseEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachGaussianBlurEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachGradientEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachHueSaturationEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachInvertEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachEasyLevelsEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachLinearWipeEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachMotionTileEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachProLevelsEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachRadialWipeEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachSharpenEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachShiftChannelsEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachSkSLColorFilter (const skjson::ArrayValue&, sk_sp) const; sk_sp attachSkSLShader (const skjson::ArrayValue&, sk_sp) const; sk_sp attachSphereEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachThresholdEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachTintEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachTransformEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachTritoneEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachVenetianBlindsEffect (const skjson::ArrayValue&, sk_sp) const; sk_sp attachDropShadowStyle(const skjson::ObjectValue&, sk_sp) const; sk_sp attachInnerShadowStyle(const skjson::ObjectValue&, sk_sp) const; sk_sp attachInnerGlowStyle(const skjson::ObjectValue&, sk_sp) const; sk_sp attachOuterGlowStyle(const skjson::ObjectValue&, sk_sp) const; EffectBuilderT findBuilder(const skjson::ObjectValue&) const; const AnimationBuilder* fBuilder; CompositionBuilder* fCompBuilder; const SkSize fLayerSize; }; // Syntactic sugar/helper. class EffectBinder { public: EffectBinder(const skjson::ArrayValue& jprops, const AnimationBuilder& abuilder, AnimatablePropertyContainer* acontainer) : fProps(jprops) , fBuilder(abuilder) , fContainer(acontainer) {} template const EffectBinder& bind(size_t prop_index, T& value) const { fContainer->bind(fBuilder, EffectBuilder::GetPropValue(fProps, prop_index), value); return *this; } private: const skjson::ArrayValue& fProps; const AnimationBuilder& fBuilder; AnimatablePropertyContainer* fContainer; }; /** * Base class for mask-shader-related effects. */ class MaskShaderEffectBase : public AnimatablePropertyContainer { public: const sk_sp& node() const { return fMaskEffectNode; } protected: MaskShaderEffectBase(sk_sp, const SkSize&); const SkSize& layerSize() const { return fLayerSize; } struct MaskInfo { sk_sp fMaskShader; bool fVisible; }; virtual MaskInfo onMakeMask() const = 0; private: void onSync() final; const sk_sp fMaskEffectNode; const SkSize fLayerSize; }; } // namespace internal } // namespace skottie #endif // SkottieEffects_DEFINED