2 * Copyright (c) 2018 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 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
83 bool UpdateProxy::SetPosition( uint32_t id, const Vector3& position )
86 SceneGraph::Node* node = GetNodeWithId( id );
89 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
95 bool UpdateProxy::BakePosition( uint32_t id, const Vector3& position )
98 SceneGraph::Node* node = GetNodeWithId( id );
101 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
107 bool UpdateProxy::GetSize( uint32_t id, Vector3& size ) const
109 bool success = false;
110 const SceneGraph::Node* node = GetNodeWithId( id );
113 size = mTransformManager.GetVector3PropertyValue( node->mTransformId, 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->mTransformId, 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->mTransformId, 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 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
150 size = mTransformManager.GetVector3PropertyValue( node->mTransformId, 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 scale = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE );
169 bool UpdateProxy::SetScale( uint32_t id, const Vector3& scale )
171 bool success = false;
172 SceneGraph::Node* node = GetNodeWithId( id );
175 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
181 bool UpdateProxy::BakeScale( uint32_t id, const Vector3& scale )
183 bool success = false;
184 SceneGraph::Node* node = GetNodeWithId( id );
187 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
193 bool UpdateProxy::GetColor( uint32_t id, Vector4& color ) const
195 bool success = false;
196 SceneGraph::Node* node = GetNodeWithId( id );
199 color = node->mColor.Get( mCurrentBufferIndex );
206 bool UpdateProxy::SetColor( uint32_t id, const Vector4& color )
208 bool success = false;
209 SceneGraph::Node* node = GetNodeWithId( id );
212 node->mColor.Set( mCurrentBufferIndex, color );
213 node->SetDirtyFlag( SceneGraph::NodePropertyFlags::COLOR );
214 AddResetter( *node, node->mColor );
220 bool UpdateProxy::BakeColor( uint32_t id, const Vector4& color )
222 bool success = false;
223 SceneGraph::Node* node = GetNodeWithId( id );
226 node->mColor.Bake( mCurrentBufferIndex, color );
232 void UpdateProxy::NodeHierarchyChanged()
234 mLastCachedIdNodePair = { 0u, nullptr };
235 mNodeContainer.clear();
236 mPropertyModifier.reset();
239 SceneGraph::Node* UpdateProxy::GetNodeWithId( uint32_t id ) const
241 SceneGraph::Node* node = nullptr;
243 // Cache the last accessed node so we don't have to traverse
244 if( mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id )
246 node = mLastCachedIdNodePair.node;
250 // Find node in vector
251 for( auto&& pair : mNodeContainer )
256 mLastCachedIdNodePair = pair;
263 // Node not in vector, find in scene-graph
264 node = FindNodeInSceneGraph( id, mRootNode );
267 mNodeContainer.push_back( { id, node } );
268 mLastCachedIdNodePair = *mNodeContainer.rbegin();
276 void UpdateProxy::AddResetter( SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase )
278 if( ! mPropertyModifier )
280 mPropertyModifier = PropertyModifierPtr( new PropertyModifier( mUpdateManager ) );
282 mPropertyModifier->AddResetter( node, propertyBase );
285 } // namespace Internal