2 * Copyright (c) 2020 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>
33 SceneGraph::Node* FindNodeInSceneGraph( uint32_t id, SceneGraph::Node& node )
35 SceneGraph::Node* matchingNode = nullptr;
43 for( auto&& i : node.GetChildren() )
45 matchingNode = FindNodeInSceneGraph( id, *i );
56 } // unnamed namespace
58 UpdateProxy::UpdateProxy( SceneGraph::UpdateManager& updateManager, SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode )
60 mLastCachedIdNodePair( { 0u, nullptr } ),
61 mCurrentBufferIndex( 0u ),
62 mUpdateManager( updateManager ),
63 mTransformManager( transformManager ),
64 mRootNode( rootNode ),
65 mPropertyModifier( nullptr )
69 UpdateProxy::~UpdateProxy() = default;
71 bool UpdateProxy::GetPosition( uint32_t id, Vector3& position ) const
74 const SceneGraph::Node* node = GetNodeWithId( id );
77 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
78 position = transformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
84 bool UpdateProxy::SetPosition( uint32_t id, const Vector3& position )
87 SceneGraph::Node* node = GetNodeWithId( id );
90 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
96 bool UpdateProxy::BakePosition( uint32_t id, const Vector3& position )
99 SceneGraph::Node* node = GetNodeWithId( id );
102 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
108 bool UpdateProxy::GetSize( uint32_t id, Vector3& size ) const
110 bool success = false;
111 const SceneGraph::Node* node = GetNodeWithId( id );
114 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
115 size = transformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
121 bool UpdateProxy::SetSize( uint32_t id, const Vector3& size )
123 bool success = false;
124 SceneGraph::Node* node = GetNodeWithId( id );
127 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
133 bool UpdateProxy::BakeSize( uint32_t id, const Vector3& size )
135 bool success = false;
136 SceneGraph::Node* node = GetNodeWithId( id );
139 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
145 bool UpdateProxy::GetPositionAndSize( uint32_t id, Vector3& position, Vector3& size ) const
147 bool success = false;
148 const SceneGraph::Node* node = GetNodeWithId( id );
151 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
152 position = transformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
153 size = transformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
159 bool UpdateProxy::GetScale( uint32_t id, Vector3& scale ) const
161 bool success = false;
162 const SceneGraph::Node* node = GetNodeWithId( id );
165 const SceneGraph::TransformManager& transformManager = mTransformManager; // To ensure we call the const getter
166 scale = transformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE );
173 bool UpdateProxy::SetScale( uint32_t id, const Vector3& scale )
175 bool success = false;
176 SceneGraph::Node* node = GetNodeWithId( id );
179 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
185 bool UpdateProxy::BakeScale( uint32_t id, const Vector3& scale )
187 bool success = false;
188 SceneGraph::Node* node = GetNodeWithId( id );
191 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
197 bool UpdateProxy::GetColor( uint32_t id, Vector4& color ) const
199 bool success = false;
200 const SceneGraph::Node* node = GetNodeWithId( id );
203 color = node->mColor.Get( mCurrentBufferIndex );
210 bool UpdateProxy::SetColor( uint32_t id, const Vector4& color )
212 bool success = false;
213 SceneGraph::Node* node = GetNodeWithId( id );
216 node->mColor.Set( mCurrentBufferIndex, color );
217 node->SetDirtyFlag( SceneGraph::NodePropertyFlags::COLOR );
218 AddResetter( *node, node->mColor );
224 bool UpdateProxy::BakeColor( uint32_t id, const Vector4& color )
226 bool success = false;
227 SceneGraph::Node* node = GetNodeWithId( id );
230 node->mColor.Bake( mCurrentBufferIndex, color );
236 void UpdateProxy::NodeHierarchyChanged()
238 mLastCachedIdNodePair = { 0u, nullptr };
239 mNodeContainer.clear();
240 mPropertyModifier.reset();
243 SceneGraph::Node* UpdateProxy::GetNodeWithId( uint32_t id ) const
245 SceneGraph::Node* node = nullptr;
247 // Cache the last accessed node so we don't have to traverse
248 if( mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id )
250 node = mLastCachedIdNodePair.node;
254 // Find node in vector
255 for( auto&& pair : mNodeContainer )
260 mLastCachedIdNodePair = pair;
267 // Node not in vector, find in scene-graph
268 node = FindNodeInSceneGraph( id, mRootNode );
271 mNodeContainer.push_back( { id, node } );
272 mLastCachedIdNodePair = *mNodeContainer.rbegin();
280 void UpdateProxy::AddResetter( SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase )
282 if( ! mPropertyModifier )
284 mPropertyModifier = PropertyModifierPtr( new PropertyModifier( mUpdateManager ) );
286 mPropertyModifier->AddResetter( node, propertyBase );
289 } // namespace Internal