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