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 11 #include "modules/skottie/src/SkottiePriv.h" 12 13 class SkMaskFilter; 14 15 namespace sksg { 16 class MaskFilter; 17 class MaskFilterEffect; 18 } // namespace sksg 19 20 namespace skottie { 21 namespace internal { 22 23 class EffectBuilder final : public SkNoncopyable { 24 public: 25 EffectBuilder(const AnimationBuilder*, const SkSize&); 26 27 sk_sp<sksg::RenderNode> attachEffects(const skjson::ArrayValue&, 28 sk_sp<sksg::RenderNode>) const; 29 30 static const skjson::Value& GetPropValue(const skjson::ArrayValue& jprops, size_t prop_index); 31 32 private: 33 using EffectBuilderT = sk_sp<sksg::RenderNode>(EffectBuilder::*)(const skjson::ArrayValue&, 34 sk_sp<sksg::RenderNode>) const; 35 36 sk_sp<sksg::RenderNode> attachDropShadowEffect (const skjson::ArrayValue&, 37 sk_sp<sksg::RenderNode>) const; 38 sk_sp<sksg::RenderNode> attachFillEffect (const skjson::ArrayValue&, 39 sk_sp<sksg::RenderNode>) const; 40 sk_sp<sksg::RenderNode> attachGaussianBlurEffect (const skjson::ArrayValue&, 41 sk_sp<sksg::RenderNode>) const; 42 sk_sp<sksg::RenderNode> attachGradientEffect (const skjson::ArrayValue&, 43 sk_sp<sksg::RenderNode>) const; 44 sk_sp<sksg::RenderNode> attachHueSaturationEffect (const skjson::ArrayValue&, 45 sk_sp<sksg::RenderNode>) const; 46 sk_sp<sksg::RenderNode> attachLevelsEffect (const skjson::ArrayValue&, 47 sk_sp<sksg::RenderNode>) const; 48 sk_sp<sksg::RenderNode> attachLinearWipeEffect (const skjson::ArrayValue&, 49 sk_sp<sksg::RenderNode>) const; 50 sk_sp<sksg::RenderNode> attachMotionTileEffect (const skjson::ArrayValue&, 51 sk_sp<sksg::RenderNode>) const; 52 sk_sp<sksg::RenderNode> attachRadialWipeEffect (const skjson::ArrayValue&, 53 sk_sp<sksg::RenderNode>) const; 54 sk_sp<sksg::RenderNode> attachTintEffect (const skjson::ArrayValue&, 55 sk_sp<sksg::RenderNode>) const; 56 sk_sp<sksg::RenderNode> attachTransformEffect (const skjson::ArrayValue&, 57 sk_sp<sksg::RenderNode>) const; 58 sk_sp<sksg::RenderNode> attachTritoneEffect (const skjson::ArrayValue&, 59 sk_sp<sksg::RenderNode>) const; 60 sk_sp<sksg::RenderNode> attachVenetianBlindsEffect(const skjson::ArrayValue&, 61 sk_sp<sksg::RenderNode>) const; 62 63 EffectBuilderT findBuilder(const skjson::ObjectValue&) const; 64 65 const AnimationBuilder* fBuilder; 66 const SkSize fLayerSize; 67 }; 68 69 70 /** 71 * Base class for mask-filter-related effects. 72 */ 73 class MaskFilterEffectBase : public SkRefCnt { 74 public: 75 ~MaskFilterEffectBase() override; 76 root()77 const sk_sp<sksg::MaskFilterEffect>& root() const { return fMaskEffectNode; } 78 79 protected: 80 MaskFilterEffectBase(sk_sp<sksg::RenderNode>, const SkSize&); 81 layerSize()82 const SkSize& layerSize() const { return fLayerSize; } 83 84 void apply() const; 85 86 struct MaskInfo { 87 sk_sp<SkMaskFilter> fMask; 88 bool fVisible; 89 }; 90 virtual MaskInfo onMakeMask() const = 0; 91 92 private: 93 const sk_sp<sksg::MaskFilter> fMaskNode; 94 const sk_sp<sksg::MaskFilterEffect> fMaskEffectNode; 95 const SkSize fLayerSize; 96 }; 97 98 } // namespace internal 99 } // namespace skottie 100 101 #endif // SkottieEffects_DEFINED 102