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 SkottieLayer_DEFINED 9 #define SkottieLayer_DEFINED 10 11 #include <cstddef> 12 #include <cstdint> 13 #include "include/core/SkRefCnt.h" 14 #include "modules/skottie/src/SkottiePriv.h" 15 16 struct SkSize; 17 18 namespace skjson { 19 class ObjectValue; 20 } 21 namespace sksg { 22 class RenderNode; 23 class Transform; 24 } // namespace sksg 25 26 namespace skottie { 27 namespace internal { 28 29 class CompositionBuilder; 30 31 class LayerBuilder final { 32 public: 33 LayerBuilder(const skjson::ObjectValue& jlayer, const SkSize& comp_size); 34 LayerBuilder(const LayerBuilder&) = default; 35 ~LayerBuilder(); 36 index()37 int index() const { return fIndex; } 38 39 bool isCamera() const; 40 41 // Attaches the local and ancestor transform chain for the layer "native" type. 42 sk_sp<sksg::Transform> buildTransform(const AnimationBuilder&, CompositionBuilder*); 43 44 // Attaches the actual layer content and finalizes its render tree. Called once per layer. 45 sk_sp<sksg::RenderNode> buildRenderTree(const AnimationBuilder&, CompositionBuilder*, 46 const LayerBuilder* prev_layer); 47 contentTree()48 const sk_sp<sksg::RenderNode>& contentTree() const { return fContentTree; } 49 size()50 const SkSize& size() const { return fInfo.fSize; } 51 52 private: 53 enum TransformType : uint8_t { 54 k2D = 0, 55 k3D = 1, 56 }; 57 58 enum Flags { 59 // k2DTransformValid = 0x01, // reserved for cache tracking 60 // k3DTransformValie = 0x02, // reserved for cache tracking 61 kIs3D = 0x04, // 3D layer ("ddd": 1) or camera layer 62 }; 63 is3D()64 bool is3D() const { return fFlags & Flags::kIs3D; } 65 66 bool hasMotionBlur(const CompositionBuilder*) const; 67 68 // Attaches (if needed) and caches the transform chain for a given layer, 69 // as either a 2D or 3D chain type. 70 // Called transitively (and possibly repeatedly) to resolve layer parenting. 71 sk_sp<sksg::Transform> getTransform(const AnimationBuilder&, CompositionBuilder*, 72 TransformType); 73 74 sk_sp<sksg::Transform> getParentTransform(const AnimationBuilder&, CompositionBuilder*, 75 TransformType); 76 77 sk_sp<sksg::Transform> doAttachTransform(const AnimationBuilder&, CompositionBuilder*, 78 TransformType); 79 80 const skjson::ObjectValue& fJlayer; 81 const int fIndex; 82 const int fParentIndex; 83 const int fType; 84 const bool fAutoOrient; 85 86 AnimationBuilder::LayerInfo fInfo; 87 sk_sp<sksg::Transform> fLayerTransform; // this layer's transform node. 88 sk_sp<sksg::Transform> fTransformCache[2]; // cached 2D/3D chain for the local node 89 sk_sp<sksg::RenderNode> fContentTree; // render tree for layer content, 90 // excluding mask/matte and blending 91 92 AnimatorScope fLayerScope; // layer-scoped animators 93 size_t fTransformAnimatorCount = 0; // transform-related animator count 94 uint32_t fFlags = 0; 95 }; 96 97 } // namespace internal 98 } // namespace skottie 99 100 #endif // SkottieLayer_DEFINED 101