Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SlotManager.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 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 SlotManager_DEFINED
9#define SlotManager_DEFINED
10
18#include "src/core/SkTHash.h"
19
20#include <optional>
21
22struct SkV2;
23
24namespace skresources {
25class ImageAsset;
26}
27
28namespace skottie {
29
30struct TextPropertyValue;
31
32namespace internal {
33class AnimationBuilder;
34class SceneGraphRevalidator;
35class AnimatablePropertyContainer;
36} // namespace internal
37
38using namespace skia_private;
39
40class SK_API SlotManager final : public SkRefCnt {
41
42public:
44
46 ~SlotManager() override;
47
48 bool setColorSlot(const SlotID&, SkColor);
49 bool setImageSlot(const SlotID&, const sk_sp<skresources::ImageAsset>&);
50 bool setScalarSlot(const SlotID&, float);
51 bool setVec2Slot(const SlotID&, SkV2);
52 bool setTextSlot(const SlotID&, const TextPropertyValue&);
53
54 std::optional<SkColor> getColorSlot(const SlotID&) const;
55 sk_sp<const skresources::ImageAsset> getImageSlot(const SlotID&) const;
56 std::optional<float> getScalarSlot(const SlotID&) const;
57 std::optional<SkV2> getVec2Slot(const SlotID&) const;
58 std::optional<TextPropertyValue> getTextSlot(const SlotID&) const;
59
67
68 // Helper function to get all slot IDs and their value types
69 SlotInfo getSlotInfo() const;
70
71private:
72
73 // pass value to the SlotManager for manipulation and node for invalidation
74 void trackColorValue(const SlotID&, ColorValue*,
77 void trackScalarValue(const SlotID&, ScalarValue*,
79 void trackVec2Value(const SlotID&, Vec2Value*,
81 void trackTextValue(const SlotID&, sk_sp<skottie::internal::TextAdapter>);
82
83 // ValuePair tracks a pointer to a value to change, and a means to invalidate the render tree.
84 // For the latter, we can take either a node in the scene graph that directly the scene graph,
85 // or an adapter which takes the value passed and interprets it before pushing to the scene
86 // (clamping, normalizing, etc.)
87 // Only one should be set, it is UB to create a ValuePair with both a node and an adapter.
88 template <typename T>
89 struct ValuePair
90 {
91 T value;
93 };
94
95 class ImageAssetProxy;
96 template <typename T>
97 using SlotMap = THashMap<SlotID, TArray<T>>;
98
99 SlotMap<ValuePair<ColorValue*>> fColorMap;
100 SlotMap<ValuePair<ScalarValue*>> fScalarMap;
101 SlotMap<ValuePair<Vec2Value*>> fVec2Map;
102 SlotMap<sk_sp<ImageAssetProxy>> fImageMap;
103 SlotMap<sk_sp<skottie::internal::TextAdapter>> fTextMap;
104
106
109};
110
111} // namespace skottie
112
113#endif // SlotManager_DEFINED
#define SK_API
Definition SkAPI.h:35
uint32_t SkColor
Definition SkColor.h:37
~SlotManager() override
uint8_t value
SkScalar ScalarValue
#define T
Definition SkM44.h:19
TArray< SlotID > fTextSlotIDs
Definition SlotManager.h:65
TArray< SlotID > fColorSlotIDs
Definition SlotManager.h:61
TArray< SlotID > fVec2SlotIDs
Definition SlotManager.h:63
TArray< SlotID > fImageSlotIDs
Definition SlotManager.h:64
TArray< SlotID > fScalarSlotIDs
Definition SlotManager.h:62