Flutter Engine
The Flutter Engine
Layer.h
Go to the documentation of this file.
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>
15
16struct SkSize;
17
18namespace skjson {
19class ObjectValue;
20}
21namespace sksg {
22class RenderNode;
23class Transform;
24} // namespace sksg
25
26namespace skottie {
27namespace internal {
28
29class CompositionBuilder;
30
31class LayerBuilder final {
32public:
33 LayerBuilder(const skjson::ObjectValue& jlayer, const SkSize& comp_size);
34 LayerBuilder(const LayerBuilder&) = default;
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.
43
44 // Attaches the actual layer content and finalizes its render tree. Called once per layer.
46 const LayerBuilder* prev_layer);
47
48 const sk_sp<sksg::RenderNode>& contentTree() const { return fContentTree; }
49
50 const SkSize& size() const { return fInfo.fSize; }
51
52private:
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
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
LayerBuilder(const skjson::ObjectValue &jlayer, const SkSize &comp_size)
Definition: Layer.cpp:329
const SkSize & size() const
Definition: Layer.h:50
sk_sp< sksg::RenderNode > buildRenderTree(const AnimationBuilder &, CompositionBuilder *, const LayerBuilder *prev_layer)
Definition: Layer.cpp:431
sk_sp< sksg::Transform > buildTransform(const AnimationBuilder &, CompositionBuilder *)
Definition: Layer.cpp:353
LayerBuilder(const LayerBuilder &)=default
const sk_sp< sksg::RenderNode > & contentTree() const
Definition: Layer.h:48
std::vector< sk_sp< Animator > > AnimatorScope
Definition: SkottiePriv.h:55
Definition: Skottie.h:32
skgpu::graphite::Transform Transform
Definition: SkSize.h:52