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