2 * Copyright (c) 2023 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::GetOrientation(uint32_t id, Quaternion& orientation) 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
114 orientation = transformManager.GetQuaternionPropertyValue(node->GetTransformId());
120 bool UpdateProxy::SetOrientation(uint32_t id, const Quaternion& orientation)
122 bool success = false;
123 SceneGraph::Node* node = GetNodeWithId(id);
126 mTransformManager.SetQuaternionPropertyValue(node->GetTransformId(), orientation);
132 bool UpdateProxy::BakeOrientation(uint32_t id, const Quaternion& orientation)
134 bool success = false;
135 SceneGraph::Node* node = GetNodeWithId(id);
138 mTransformManager.BakeQuaternionPropertyValue(node->GetTransformId(), orientation);
144 bool UpdateProxy::GetSize(uint32_t id, Vector3& size) const
146 bool success = false;
147 const SceneGraph::Node* node = GetNodeWithId(id);
150 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
151 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
157 bool UpdateProxy::SetSize(uint32_t id, const Vector3& size)
159 bool success = false;
160 SceneGraph::Node* node = GetNodeWithId(id);
163 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
169 bool UpdateProxy::BakeSize(uint32_t id, const Vector3& size)
171 bool success = false;
172 SceneGraph::Node* node = GetNodeWithId(id);
175 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
181 bool UpdateProxy::GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const
183 bool success = false;
184 const SceneGraph::Node* node = GetNodeWithId(id);
187 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
188 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
189 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
195 bool UpdateProxy::GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const
197 bool success = false;
198 const SceneGraph::Node* node = GetNodeWithId(id);
201 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
202 const Matrix& worldMatrix = transformManager.GetWorldMatrix(node->GetTransformId());
204 Quaternion orientation;
205 worldMatrix.GetTransformComponents(position, orientation, scale);
207 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
213 bool UpdateProxy::GetWorldTransformAndSize(uint32_t id, Vector3& position, Vector3& scale, Quaternion& orientation, Vector3& size) const
215 bool success = false;
216 const SceneGraph::Node* node = GetNodeWithId(id);
219 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
220 const Matrix& worldMatrix = transformManager.GetWorldMatrix(node->GetTransformId());
222 worldMatrix.GetTransformComponents(position, orientation, scale);
223 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
229 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
231 bool success = false;
232 const SceneGraph::Node* node = GetNodeWithId(id);
235 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
236 scale = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE);
243 bool UpdateProxy::SetScale(uint32_t id, const Vector3& scale)
245 bool success = false;
246 SceneGraph::Node* node = GetNodeWithId(id);
249 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
255 bool UpdateProxy::BakeScale(uint32_t id, const Vector3& scale)
257 bool success = false;
258 SceneGraph::Node* node = GetNodeWithId(id);
261 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
267 bool UpdateProxy::GetColor(uint32_t id, Vector4& color) const
269 bool success = false;
270 const SceneGraph::Node* node = GetNodeWithId(id);
273 color = node->mColor.Get(mCurrentBufferIndex);
280 bool UpdateProxy::SetColor(uint32_t id, const Vector4& color)
282 bool success = false;
283 SceneGraph::Node* node = GetNodeWithId(id);
286 node->mColor.Set(mCurrentBufferIndex, color);
287 node->SetDirtyFlag(SceneGraph::NodePropertyFlags::COLOR);
288 mDirtyNodes.push_back(id);
289 AddResetter(*node, node->mColor);
295 bool UpdateProxy::BakeColor(uint32_t id, const Vector4& color)
297 bool success = false;
298 SceneGraph::Node* node = GetNodeWithId(id);
301 node->mColor.Bake(mCurrentBufferIndex, color);
307 void UpdateProxy::NodeHierarchyChanged()
309 mLastCachedIdNodePair = {0u, nullptr};
310 mNodeContainer.clear();
311 mPropertyModifier.reset();
314 SceneGraph::Node* UpdateProxy::GetNodeWithId(uint32_t id) const
316 SceneGraph::Node* node = nullptr;
318 // Cache the last accessed node so we don't have to traverse
319 if(mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id)
321 node = mLastCachedIdNodePair.node;
325 // Find node in vector
326 for(auto&& pair : mNodeContainer)
331 mLastCachedIdNodePair = pair;
338 // Node not in vector, find in scene-graph
339 node = FindNodeInSceneGraph(id, mRootNode);
342 mNodeContainer.push_back({id, node});
343 mLastCachedIdNodePair = *mNodeContainer.rbegin();
351 void UpdateProxy::AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase)
353 if(!mPropertyModifier)
355 mPropertyModifier = PropertyModifierPtr(new PropertyModifier(mUpdateManager));
357 mPropertyModifier->AddResetter(node, propertyBase);
360 void UpdateProxy::AddNodeResetters()
362 for(auto&& id : mDirtyNodes)
364 SceneGraph::Node* node = FindNodeInSceneGraph(id, mRootNode);
367 mUpdateManager.AddNodeResetter(*node);
372 } // namespace Internal