Debian Codegraph @

modules/skottie/src/Layer.h

raw
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
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 int prev_layer_index);
47
48 const sk_sp<sksg::RenderNode>& getContentTree(const AnimationBuilder&, CompositionBuilder*);
49
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 // k3DTransformValid = 0x02, // reserved for cache tracking
61 kIs3D = 0x04, // 3D layer ("ddd": 1) or camera layer
62 kBuiltContent = 0x08, // the content tree has been built
63 };
64
65 bool is3D() const { return fFlags & Flags::kIs3D; }
66
67 // Attaches the layer content (excluding motion blur, layer controller, and mattes).
68 // Can be called transitively, but only once per layer (via getContentTree, which caches
69 // the result).
70 sk_sp<sksg::RenderNode> buildContentTree(const AnimationBuilder&, CompositionBuilder*);
71
72 // Attaches (if needed) and caches the transform chain for a given layer,
73 // as either a 2D or 3D chain type.
74 // Called transitively (and possibly repeatedly) to resolve layer parenting.
75 sk_sp<sksg::Transform> getTransform(const AnimationBuilder&, CompositionBuilder*,
76 TransformType);
77
78 sk_sp<sksg::Transform> getParentTransform(const AnimationBuilder&, CompositionBuilder*,
79 TransformType);
80
81 sk_sp<sksg::Transform> doAttachTransform(const AnimationBuilder&, CompositionBuilder*,
82 TransformType);
83
84 using LayerBuilderFunc =
85 sk_sp<sksg::RenderNode> (AnimationBuilder::*)(const skjson::ObjectValue&,
86 LayerInfo*) const;
87 struct BuilderInfo {
88 LayerBuilderFunc fBuilder = nullptr;
89 uint32_t fFlags = 0;
90 };
91
92 const skjson::ObjectValue& fJlayer;
93 const int fIndex;
94 const int fParentIndex;
95 const int fType;
96 const bool fAutoOrient;
97
98 LayerInfo fInfo;
99 BuilderInfo fBuilderInfo;
100 sk_sp<sksg::Transform> fLayerTransform; // this layer's transform node.
101 sk_sp<sksg::Transform> fTransformCache[2]; // cached 2D/3D chain for the local node
102 sk_sp<sksg::RenderNode> fContentTree; // render tree for layer content,
103 // excluding mask/matte and blending
104
105 AnimatorScope fLayerScope; // layer-scoped animators
106 size_t fTransformAnimatorCount = 0; // transform-related animator count
107 uint32_t fFlags = 0;
108 };
109
110 } // namespace internal
111 } // namespace skottie
112
113 #endif // SkottieLayer_DEFINED