2 * Copyright (c) 2024 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-manager.h>
23 #include <dali/internal/update/manager/update-proxy-property-modifier.h>
29 UpdateProxy::UpdateProxy(SceneGraph::UpdateManager& updateManager, SceneGraph::TransformManager& transformManager, SceneGraphTravelerInterfacePtr traveler)
30 : mLastCachedIdNodePair({0u, nullptr}),
32 mCurrentBufferIndex(0u),
33 mUpdateManager(updateManager),
34 mTransformManager(transformManager),
35 mSceneGraphTraveler(traveler),
36 mPropertyModifier(nullptr)
40 UpdateProxy::~UpdateProxy() = default;
42 bool UpdateProxy::GetPosition(uint32_t id, Vector3& position) const
45 const SceneGraph::Node* node = GetNodeWithId(id);
48 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
49 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
55 bool UpdateProxy::SetPosition(uint32_t id, const Vector3& position)
58 SceneGraph::Node* node = GetNodeWithId(id);
61 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION, position);
67 bool UpdateProxy::BakePosition(uint32_t id, const Vector3& position)
70 SceneGraph::Node* node = GetNodeWithId(id);
73 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION, position);
79 bool UpdateProxy::GetOrientation(uint32_t id, Quaternion& orientation) const
82 const SceneGraph::Node* node = GetNodeWithId(id);
85 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
87 orientation = transformManager.GetQuaternionPropertyValue(node->GetTransformId());
93 bool UpdateProxy::SetOrientation(uint32_t id, const Quaternion& orientation)
96 SceneGraph::Node* node = GetNodeWithId(id);
99 mTransformManager.SetQuaternionPropertyValue(node->GetTransformId(), orientation);
105 bool UpdateProxy::BakeOrientation(uint32_t id, const Quaternion& orientation)
107 bool success = false;
108 SceneGraph::Node* node = GetNodeWithId(id);
111 mTransformManager.BakeQuaternionPropertyValue(node->GetTransformId(), orientation);
117 bool UpdateProxy::GetSize(uint32_t id, Vector3& size) const
119 bool success = false;
120 const SceneGraph::Node* node = GetNodeWithId(id);
123 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
124 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
130 bool UpdateProxy::SetSize(uint32_t id, const Vector3& size)
132 bool success = false;
133 SceneGraph::Node* node = GetNodeWithId(id);
136 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
142 bool UpdateProxy::BakeSize(uint32_t id, const Vector3& size)
144 bool success = false;
145 SceneGraph::Node* node = GetNodeWithId(id);
148 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE, size);
154 bool UpdateProxy::GetPositionAndSize(uint32_t id, Vector3& position, Vector3& size) const
156 bool success = false;
157 const SceneGraph::Node* node = GetNodeWithId(id);
160 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
161 position = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_POSITION);
162 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
168 bool UpdateProxy::GetWorldPositionScaleAndSize(uint32_t id, Vector3& position, Vector3& scale, Vector3& size) const
170 bool success = false;
171 const SceneGraph::Node* node = GetNodeWithId(id);
174 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
175 const Matrix& worldMatrix = transformManager.GetWorldMatrix(node->GetTransformId());
177 Quaternion orientation;
178 worldMatrix.GetTransformComponents(position, orientation, scale);
180 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
186 bool UpdateProxy::GetWorldTransformAndSize(uint32_t id, Vector3& position, Vector3& scale, Quaternion& orientation, Vector3& size) const
188 bool success = false;
189 const SceneGraph::Node* node = GetNodeWithId(id);
192 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
193 const Matrix& worldMatrix = transformManager.GetWorldMatrix(node->GetTransformId());
195 worldMatrix.GetTransformComponents(position, orientation, scale);
196 size = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SIZE);
202 bool UpdateProxy::GetScale(uint32_t id, Vector3& scale) const
204 bool success = false;
205 const SceneGraph::Node* node = GetNodeWithId(id);
208 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
209 scale = transformManager.GetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE);
216 bool UpdateProxy::SetScale(uint32_t id, const Vector3& scale)
218 bool success = false;
219 SceneGraph::Node* node = GetNodeWithId(id);
222 mTransformManager.SetVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
228 bool UpdateProxy::BakeScale(uint32_t id, const Vector3& scale)
230 bool success = false;
231 SceneGraph::Node* node = GetNodeWithId(id);
234 mTransformManager.BakeVector3PropertyValue(node->GetTransformId(), SceneGraph::TRANSFORM_PROPERTY_SCALE, scale);
240 bool UpdateProxy::GetColor(uint32_t id, Vector4& color) const
242 bool success = false;
243 const SceneGraph::Node* node = GetNodeWithId(id);
246 color = node->mColor.Get(mCurrentBufferIndex);
253 bool UpdateProxy::SetColor(uint32_t id, const Vector4& color)
255 bool success = false;
256 SceneGraph::Node* node = GetNodeWithId(id);
259 node->mColor.Set(mCurrentBufferIndex, color);
260 node->SetDirtyFlag(SceneGraph::NodePropertyFlags::COLOR);
261 mDirtyNodes.push_back(id);
262 AddResetter(*node, node->mColor);
268 bool UpdateProxy::BakeColor(uint32_t id, const Vector4& color)
270 bool success = false;
271 SceneGraph::Node* node = GetNodeWithId(id);
274 node->mColor.Bake(mCurrentBufferIndex, color);
280 void UpdateProxy::NodeHierarchyChanged()
282 mLastCachedIdNodePair = {0u, nullptr};
283 mPropertyModifier.reset();
286 void UpdateProxy::Notify(Dali::UpdateProxy::NotifySyncPoint syncPoint)
288 mSyncPoints.push_back(syncPoint);
291 Dali::UpdateProxy::NotifySyncPoint UpdateProxy::PopSyncPoint()
293 if(!mSyncPoints.empty())
295 auto syncPoint = mSyncPoints.front();
296 mSyncPoints.pop_front();
300 return Dali::UpdateProxy::INVALID_SYNC;
303 SceneGraph::Node* UpdateProxy::GetNodeWithId(uint32_t id) const
305 SceneGraph::Node* node = nullptr;
307 // Cache the last accessed node so we don't have to traverse
308 if(mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id)
310 node = mLastCachedIdNodePair.node;
314 node = mSceneGraphTraveler->FindNode(id);
318 mLastCachedIdNodePair = {id, node};
325 void UpdateProxy::AddResetter(SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase)
327 if(!mPropertyModifier)
329 mPropertyModifier = PropertyModifierPtr(new PropertyModifier(mUpdateManager));
331 mPropertyModifier->AddResetter(node, propertyBase);
334 void UpdateProxy::AddNodeResetters()
336 for(auto&& id : mDirtyNodes)
338 SceneGraph::Node* node = GetNodeWithId(id);
341 mUpdateManager.AddNodeResetter(*node);
346 bool UpdateProxy::GetUpdateArea(uint32_t id, Vector4& updateArea) const
348 bool success = false;
349 SceneGraph::Node* node = GetNodeWithId(id);
352 updateArea = node->GetUpdateAreaHint();
358 bool UpdateProxy::SetUpdateArea(uint32_t id, const Vector4& updateArea)
360 bool success = false;
361 SceneGraph::Node* node = GetNodeWithId(id);
364 node->SetUpdateAreaHint(updateArea);
370 } // namespace Internal