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>
30 SceneGraph::Node* FindNodeInSceneGraph( unsigned int id, SceneGraph::Node& node )
32 SceneGraph::Node* matchingNode = NULL;
40 for( auto&& i : node.GetChildren() )
42 matchingNode = FindNodeInSceneGraph( id, *i );
53 } // unnamed namespace
55 UpdateProxy::UpdateProxy( SceneGraph::TransformManager& transformManager, SceneGraph::Node& rootNode )
57 mLastCachedIdNodePair( { 0u, NULL } ),
58 mCurrentBufferIndex( 0u ),
59 mTransformManager( transformManager ),
64 UpdateProxy::~UpdateProxy()
68 bool UpdateProxy::GetPosition( unsigned int id, Vector3& position ) const
71 const SceneGraph::Node* node = GetNodeWithId( id );
74 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
80 bool UpdateProxy::SetPosition( unsigned int id, const Vector3& position )
83 SceneGraph::Node* node = GetNodeWithId( id );
86 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
92 bool UpdateProxy::BakePosition( unsigned int id, const Vector3& position )
95 SceneGraph::Node* node = GetNodeWithId( id );
98 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
104 bool UpdateProxy::GetSize( unsigned int id, Vector3& size ) const
106 bool success = false;
107 const SceneGraph::Node* node = GetNodeWithId( id );
110 size = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
116 bool UpdateProxy::SetSize( unsigned int id, const Vector3& size )
118 bool success = false;
119 SceneGraph::Node* node = GetNodeWithId( id );
122 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
128 bool UpdateProxy::BakeSize( unsigned int id, const Vector3& size )
130 bool success = false;
131 SceneGraph::Node* node = GetNodeWithId( id );
134 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE, size );
140 bool UpdateProxy::GetPositionAndSize( unsigned int id, Vector3& position, Vector3& size ) const
142 bool success = false;
143 const SceneGraph::Node* node = GetNodeWithId( id );
146 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
147 size = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
153 bool UpdateProxy::GetScale( unsigned int id, Vector3& scale ) const
155 bool success = false;
156 const SceneGraph::Node* node = GetNodeWithId( id );
159 scale = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE );
166 bool UpdateProxy::SetScale( unsigned int id, const Vector3& scale )
168 bool success = false;
169 SceneGraph::Node* node = GetNodeWithId( id );
172 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
178 bool UpdateProxy::BakeScale( unsigned int id, const Vector3& scale )
180 bool success = false;
181 SceneGraph::Node* node = GetNodeWithId( id );
184 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
190 bool UpdateProxy::GetColor( unsigned int id, Vector4& color ) const
192 bool success = false;
193 SceneGraph::Node* node = GetNodeWithId( id );
196 color = node->mColor.Get( mCurrentBufferIndex );
203 bool UpdateProxy::SetColor( unsigned int id, const Vector4& color ) const
205 bool success = false;
206 SceneGraph::Node* node = GetNodeWithId( id );
209 node->mColor.Set( mCurrentBufferIndex, color );
215 bool UpdateProxy::BakeColor( unsigned int id, const Vector4& color ) const
217 bool success = false;
218 SceneGraph::Node* node = GetNodeWithId( id );
221 node->mColor.Bake( mCurrentBufferIndex, color );
227 void UpdateProxy::NodeHierarchyChanged()
229 mLastCachedIdNodePair = { 0u, NULL };
230 mNodeContainer.clear();
233 SceneGraph::Node* UpdateProxy::GetNodeWithId( unsigned int id ) const
235 SceneGraph::Node* node = NULL;
237 // Cache the last accessed node so we don't have to traverse
238 if( mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id )
240 node = mLastCachedIdNodePair.node;
244 // Find node in vector
245 for( auto&& pair : mNodeContainer )
250 mLastCachedIdNodePair = pair;
257 // Node not in vector, find in scene-graph
258 node = FindNodeInSceneGraph( id, mRootNode );
261 mNodeContainer.push_back( { id, node } );
262 mLastCachedIdNodePair = *mNodeContainer.rbegin();
270 } // namespace Internal