2 * Copyright (c) 2022 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::GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) 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 const Matrix& worldMatrix = transformManager.GetWorldMatrix(node->GetTransformId());
166 Quaternion orientation;
167 worldMatrix.GetTransformComponents(position, orientation, scale);
169 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
175 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
177 bool success = false;
178 const SceneGraph::Node* node = GetNodeWithId(id);
181 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
182 scale = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE);
189 bool UpdateProxy::SetScale(uint32_t id, const Vector3& scale)
191 bool success = false;
192 SceneGraph::Node* node = GetNodeWithId(id);
195 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
201 bool UpdateProxy::BakeScale(uint32_t id, const Vector3& scale)
203 bool success = false;
204 SceneGraph::Node* node = GetNodeWithId(id);
207 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
213 bool UpdateProxy::GetColor(uint32_t id, Vector4& color) const
215 bool success = false;
216 const SceneGraph::Node* node = GetNodeWithId(id);
219 color = node->mColor.Get(mCurrentBufferIndex);
226 bool UpdateProxy::SetColor(uint32_t id, const Vector4& color)
228 bool success = false;
229 SceneGraph::Node* node = GetNodeWithId(id);
232 node->mColor.Set(mCurrentBufferIndex, color);
233 node->SetDirtyFlag(SceneGraph::NodePropertyFlags::COLOR);
234 mDirtyNodes.push_back(id);
235 AddResetter(*node, node->mColor);
241 bool UpdateProxy::BakeColor(uint32_t id, const Vector4& color)
243 bool success = false;
244 SceneGraph::Node* node = GetNodeWithId(id);
247 node->mColor.Bake(mCurrentBufferIndex, color);
253 void UpdateProxy::NodeHierarchyChanged()
255 mLastCachedIdNodePair = {0u, nullptr};
256 mNodeContainer.clear();
257 mPropertyModifier.reset();
260 SceneGraph::Node* UpdateProxy::GetNodeWithId(uint32_t id) const
262 SceneGraph::Node* node = nullptr;
264 // Cache the last accessed node so we don't have to traverse
265 if(mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id)
267 node = mLastCachedIdNodePair.node;
271 // Find node in vector
272 for(auto&& pair : mNodeContainer)
277 mLastCachedIdNodePair = pair;
284 // Node not in vector, find in scene-graph
285 node = FindNodeInSceneGraph(id, mRootNode);
288 mNodeContainer.push_back({id, node});
289 mLastCachedIdNodePair = *mNodeContainer.rbegin();
297 void UpdateProxy::AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase)
299 if(!mPropertyModifier)
301 mPropertyModifier = PropertyModifierPtr(new PropertyModifier(mUpdateManager));
303 mPropertyModifier->AddResetter(node, propertyBase);
306 void UpdateProxy::AddNodeResetters()
308 for(auto&& id : mDirtyNodes)
310 SceneGraph::Node* node = FindNodeInSceneGraph(id, mRootNode);
313 mUpdateManager.AddNodeResetter(*node);
318 } // namespace Internal