Flutter Engine
The Flutter Engine
SlotManager.cpp
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
9
11#include "include/core/SkM44.h"
19
20#include <utility>
21
23public:
25 : fImageAsset(std::move(asset)) {}
26
27 // always returns true to force the FootageLayer to always redraw in case asset is swapped
28 bool isMultiFrame() override { return true; }
29
30 FrameData getFrameData(float t) override {
31 if (fImageAsset) {
32 return fImageAsset->getFrameData(t);
33 }
36 }
37
39 fImageAsset = std::move(asset);
40 }
41
43 return fImageAsset;
44 }
45private:
47};
48
50 : fRevalidator(std::move(revalidator)) {}
51
53
55 auto c4f = SkColor4f::FromColor(c);
56 ColorValue v{c4f.fR, c4f.fG, c4f.fB, c4f.fA};
57 const auto valueGroup = fColorMap.find(slotID);
58 if (valueGroup) {
59 for (auto& cPair : *valueGroup) {
60 *(cPair.value) = v;
61 cPair.adapter->onSync();
62 }
63 fRevalidator->revalidate();
64 return true;
65 }
66 return false;
67}
68
71 const auto imageGroup = fImageMap.find(slotID);
72 if (imageGroup) {
73 for (auto& imageAsset : *imageGroup) {
74 imageAsset->setImageAsset(i);
75 }
76 fRevalidator->revalidate();
77 return true;
78 }
79 return false;
80}
81
82bool skottie::SlotManager::setScalarSlot(const SlotID& slotID, float s) {
83 const auto valueGroup = fScalarMap.find(slotID);
84 if (valueGroup) {
85 for (auto& sPair : *valueGroup) {
86 *(sPair.value) = s;
87 sPair.adapter->onSync();
88 }
89 fRevalidator->revalidate();
90 return true;
91 }
92 return false;
93}
94
96 const auto valueGroup = fVec2Map.find(slotID);
97 if (valueGroup) {
98 for (auto& vPair : *valueGroup) {
99 *(vPair.value) = v;
100 vPair.adapter->onSync();
101 }
102 fRevalidator->revalidate();
103 return true;
104 }
105 return false;
106}
107
109 const auto adapterGroup = fTextMap.find(slotID);
110 if (adapterGroup) {
111 for (auto& textAdapter : *adapterGroup) {
112 textAdapter->setText(t);
113 }
114 fRevalidator->revalidate();
115 return true;
116 }
117 return false;
118}
119
120std::optional<SkColor> skottie::SlotManager::getColorSlot(const SlotID& slotID) const {
121 const auto valueGroup = fColorMap.find(slotID);
122 return valueGroup && !valueGroup->empty() ? std::optional<SkColor>(*(valueGroup->at(0).value))
123 : std::nullopt;
124}
125
127 const SlotID& slotID) const {
128 const auto imageGroup = fImageMap.find(slotID);
129 return imageGroup && !imageGroup->empty() ? imageGroup->at(0)->getImageAsset() : nullptr;
130}
131
132std::optional<float> skottie::SlotManager::getScalarSlot(const SlotID& slotID) const {
133 const auto valueGroup = fScalarMap.find(slotID);
134 return valueGroup && !valueGroup->empty() ? std::optional<float>(*(valueGroup->at(0).value))
135 : std::nullopt;
136}
137
138std::optional<SkV2> skottie::SlotManager::getVec2Slot(const SlotID& slotID) const {
139 const auto valueGroup = fVec2Map.find(slotID);
140 return valueGroup && !valueGroup->empty() ? std::optional<SkV2>(*(valueGroup->at(0).value))
141 : std::nullopt;
142}
143
144std::optional<skottie::TextPropertyValue> skottie::SlotManager::getTextSlot(
145 const SlotID& slotID) const {
146 const auto adapterGroup = fTextMap.find(slotID);
147 return adapterGroup && !adapterGroup->empty() ?
148 std::optional<TextPropertyValue>(adapterGroup->at(0)->getText()) :
149 std::nullopt;
150}
151
152void skottie::SlotManager::trackColorValue(const SlotID& slotID, ColorValue* colorValue,
154 fColorMap[slotID].push_back({colorValue, std::move(adapter)});
155}
156
157sk_sp<skresources::ImageAsset> skottie::SlotManager::trackImageValue(const SlotID& slotID,
159 imageAsset) {
160 auto proxy = sk_make_sp<ImageAssetProxy>(std::move(imageAsset));
161 fImageMap[slotID].push_back(proxy);
162 return proxy;
163}
164
165void skottie::SlotManager::trackScalarValue(const SlotID& slotID, ScalarValue* scalarValue,
167 fScalarMap[slotID].push_back({scalarValue, std::move(adapter)});
168}
169
170void skottie::SlotManager::trackVec2Value(const SlotID& slotID, Vec2Value* vec2Value,
172 fVec2Map[slotID].push_back({vec2Value, std::move(adapter)});
173}
174
175void skottie::SlotManager::trackTextValue(const SlotID& slotID,
177 fTextMap[slotID].push_back(std::move(adapter));
178}
179
181 SlotInfo sInfo;
182 for (const auto& c : fColorMap) {
183 sInfo.fColorSlotIDs.push_back(c.first);
184 }
185 for (const auto& s : fScalarMap) {
186 sInfo.fScalarSlotIDs.push_back(s.first);
187 }
188 for (const auto& v : fVec2Map) {
189 sInfo.fVec2SlotIDs.push_back(v.first);
190 }
191 for (const auto& i : fImageMap) {
192 sInfo.fImageSlotIDs.push_back(i.first);
193 }
194 for (const auto& t : fTextMap) {
195 sInfo.fTextSlotIDs.push_back(t.first);
196 }
197 return sInfo;
198}
uint32_t SkColor
Definition: SkColor.h:37
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
ImageAssetProxy(sk_sp< skresources::ImageAsset > asset)
Definition: SlotManager.cpp:24
void setImageAsset(sk_sp< skresources::ImageAsset > asset)
Definition: SlotManager.cpp:38
sk_sp< const skresources::ImageAsset > getImageAsset() const
Definition: SlotManager.cpp:42
FrameData getFrameData(float t) override
Definition: SlotManager.cpp:30
std::optional< SkV2 > getVec2Slot(const SlotID &) const
bool setColorSlot(const SlotID &, SkColor)
Definition: SlotManager.cpp:54
std::optional< TextPropertyValue > getTextSlot(const SlotID &) const
SlotInfo getSlotInfo() const
SlotManager(sk_sp< skottie::internal::SceneGraphRevalidator >)
Definition: SlotManager.cpp:49
bool setScalarSlot(const SlotID &, float)
Definition: SlotManager.cpp:82
sk_sp< const skresources::ImageAsset > getImageSlot(const SlotID &) const
std::optional< float > getScalarSlot(const SlotID &) const
~SlotManager() override
bool setImageSlot(const SlotID &, const sk_sp< skresources::ImageAsset > &)
Definition: SlotManager.cpp:69
bool setVec2Slot(const SlotID &, SkV2)
Definition: SlotManager.cpp:95
bool setTextSlot(const SlotID &, const TextPropertyValue &)
std::optional< SkColor > getColorSlot(const SlotID &) const
virtual FrameData getFrameData(float t)
struct MyStruct s
SkSamplingOptions(SkFilterMode::kLinear))
SkScalar ScalarValue
Definition: SkottieValue.h:22
SkV2 Vec2Value
Definition: SkottieValue.h:23
Definition: ref_ptr.h:256
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