2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/manager/update-proxy-impl.h>
22 #include <dali/internal/update/manager/update-proxy-property-modifier.h>
30 SceneGraph::Node* FindNodeInSceneGraph(uint32_t id, SceneGraph::Node& node)
32 SceneGraph::Node* matchingNode = nullptr;
40 for(auto&& i : node.GetChildren())
42 matchingNode = FindNodeInSceneGraph(id, *i);
53 } // unnamed namespace
55 UpdateProxy::UpdateProxy(SceneGraph::UpdateManager& updateManager, SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode)
57 mLastCachedIdNodePair({0u, nullptr}),
59 mCurrentBufferIndex(0u),
60 mUpdateManager(updateManager),
61 mTransformManager(transformManager),
63 mPropertyModifier(nullptr)
67 UpdateProxy::~UpdateProxy() = default;
69 bool UpdateProxy::GetPosition(uint32_t id, Vector3& position) const
72 const SceneGraph::Node* node = GetNodeWithId(id);
75 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
76 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
82 bool UpdateProxy::SetPosition(uint32_t id, const Vector3& position)
85 SceneGraph::Node* node = GetNodeWithId(id);
88 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION, position);
94 bool UpdateProxy::BakePosition(uint32_t id, const Vector3& position)
97 SceneGraph::Node* node = GetNodeWithId(id);
100 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION, position);
106 bool UpdateProxy::GetSize(uint32_t id, Vector3& size) const
108 bool success = false;
109 const SceneGraph::Node* node = GetNodeWithId(id);
112 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
113 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
119 bool UpdateProxy::SetSize(uint32_t id, const Vector3& size)
121 bool success = false;
122 SceneGraph::Node* node = GetNodeWithId(id);
125 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
131 bool UpdateProxy::BakeSize(uint32_t id, const Vector3& size)
133 bool success = false;
134 SceneGraph::Node* node = GetNodeWithId(id);
137 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
143 bool UpdateProxy::GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const
145 bool success = false;
146 const SceneGraph::Node* node = GetNodeWithId(id);
149 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
150 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
151 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
157 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
159 bool success = false;
160 const SceneGraph::Node* node = GetNodeWithId(id);
163 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
164 scale = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE);
171 bool UpdateProxy::SetScale(uint32_t id, const Vector3& scale)
173 bool success = false;
174 SceneGraph::Node* node = GetNodeWithId(id);
177 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
183 bool UpdateProxy::BakeScale(uint32_t id, const Vector3& scale)
185 bool success = false;
186 SceneGraph::Node* node = GetNodeWithId(id);
189 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
195 bool UpdateProxy::GetColor(uint32_t id, Vector4& color) const
197 bool success = false;
198 const SceneGraph::Node* node = GetNodeWithId(id);
201 color = node->mColor.Get(mCurrentBufferIndex);
208 bool UpdateProxy::SetColor(uint32_t id, const Vector4& color)
210 bool success = false;
211 SceneGraph::Node* node = GetNodeWithId(id);
214 node->mColor.Set(mCurrentBufferIndex, color);
215 node->SetDirtyFlag(SceneGraph::NodePropertyFlags::COLOR);
216 mDirtyNodes.push_back(id);
217 AddResetter(*node, node->mColor);
223 bool UpdateProxy::BakeColor(uint32_t id, const Vector4& color)
225 bool success = false;
226 SceneGraph::Node* node = GetNodeWithId(id);
229 node->mColor.Bake(mCurrentBufferIndex, color);
235 void UpdateProxy::NodeHierarchyChanged()
237 mLastCachedIdNodePair = {0u, nullptr};
238 mNodeContainer.clear();
239 mPropertyModifier.reset();
242 SceneGraph::Node* UpdateProxy::GetNodeWithId(uint32_t id) const
244 SceneGraph::Node* node = nullptr;
246 // Cache the last accessed node so we don't have to traverse
247 if(mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id)
249 node = mLastCachedIdNodePair.node;
253 // Find node in vector
254 for(auto&& pair : mNodeContainer)
259 mLastCachedIdNodePair = pair;
266 // Node not in vector, find in scene-graph
267 node = FindNodeInSceneGraph(id, mRootNode);
270 mNodeContainer.push_back({id, node});
271 mLastCachedIdNodePair = *mNodeContainer.rbegin();
279 void UpdateProxy::AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase)
281 if(!mPropertyModifier)
283 mPropertyModifier = PropertyModifierPtr(new PropertyModifier(mUpdateManager));
285 mPropertyModifier->AddResetter(node, propertyBase);
288 void UpdateProxy::AddNodeResetters()
290 for(auto&& id : mDirtyNodes)
292 SceneGraph::Node* node = FindNodeInSceneGraph(id, mRootNode);
295 mUpdateManager.AddNodeResetter(*node);
300 } // namespace Internal