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}),
58 mCurrentBufferIndex(0u),
59 mUpdateManager(updateManager),
60 mTransformManager(transformManager),
62 mPropertyModifier(nullptr)
66 UpdateProxy::~UpdateProxy() = default;
68 bool UpdateProxy::GetPosition(uint32_t id, Vector3& position) const
71 const SceneGraph::Node* node = GetNodeWithId(id);
74 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
75 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
81 bool UpdateProxy::SetPosition(uint32_t id, const Vector3& position)
84 SceneGraph::Node* node = GetNodeWithId(id);
87 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION, position);
93 bool UpdateProxy::BakePosition(uint32_t id, const Vector3& position)
96 SceneGraph::Node* node = GetNodeWithId(id);
99 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION, position);
105 bool UpdateProxy::GetSize(uint32_t id, Vector3& size) const
107 bool success = false;
108 const SceneGraph::Node* node = GetNodeWithId(id);
111 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
112 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
118 bool UpdateProxy::SetSize(uint32_t id, const Vector3& size)
120 bool success = false;
121 SceneGraph::Node* node = GetNodeWithId(id);
124 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
130 bool UpdateProxy::BakeSize(uint32_t id, const Vector3& size)
132 bool success = false;
133 SceneGraph::Node* node = GetNodeWithId(id);
136 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
142 bool UpdateProxy::GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const
144 bool success = false;
145 const SceneGraph::Node* node = GetNodeWithId(id);
148 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
149 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
150 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
156 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
158 bool success = false;
159 const SceneGraph::Node* node = GetNodeWithId(id);
162 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
163 scale = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE);
170 bool UpdateProxy::SetScale(uint32_t id, const Vector3& scale)
172 bool success = false;
173 SceneGraph::Node* node = GetNodeWithId(id);
176 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
182 bool UpdateProxy::BakeScale(uint32_t id, const Vector3& scale)
184 bool success = false;
185 SceneGraph::Node* node = GetNodeWithId(id);
188 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
194 bool UpdateProxy::GetColor(uint32_t id, Vector4& color) const
196 bool success = false;
197 const SceneGraph::Node* node = GetNodeWithId(id);
200 color = node->mColor.Get(mCurrentBufferIndex);
207 bool UpdateProxy::SetColor(uint32_t id, const Vector4& color)
209 bool success = false;
210 SceneGraph::Node* node = GetNodeWithId(id);
213 node->mColor.Set(mCurrentBufferIndex, color);
214 node->SetDirtyFlag(SceneGraph::NodePropertyFlags::COLOR);
215 AddResetter(*node, node->mColor);
221 bool UpdateProxy::BakeColor(uint32_t id, const Vector4& color)
223 bool success = false;
224 SceneGraph::Node* node = GetNodeWithId(id);
227 node->mColor.Bake(mCurrentBufferIndex, color);
233 void UpdateProxy::NodeHierarchyChanged()
235 mLastCachedIdNodePair = {0u, nullptr};
236 mNodeContainer.clear();
237 mPropertyModifier.reset();
240 SceneGraph::Node* UpdateProxy::GetNodeWithId(uint32_t id) const
242 SceneGraph::Node* node = nullptr;
244 // Cache the last accessed node so we don't have to traverse
245 if(mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id)
247 node = mLastCachedIdNodePair.node;
251 // Find node in vector
252 for(auto&& pair : mNodeContainer)
257 mLastCachedIdNodePair = pair;
264 // Node not in vector, find in scene-graph
265 node = FindNodeInSceneGraph(id, mRootNode);
268 mNodeContainer.push_back({id, node});
269 mLastCachedIdNodePair = *mNodeContainer.rbegin();
277 void UpdateProxy::AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase)
279 if(!mPropertyModifier)
281 mPropertyModifier = PropertyModifierPtr(new PropertyModifier(mUpdateManager));
283 mPropertyModifier->AddResetter(node, propertyBase);
286 } // namespace Internal