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 = NULL;
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, NULL } ),
61 mCurrentBufferIndex( 0u ),
62 mUpdateManager( updateManager ),
63 mTransformManager( transformManager ),
64 mRootNode( rootNode ),
65 mPropertyModifier( nullptr )
69 UpdateProxy::~UpdateProxy()
73 bool UpdateProxy::GetPosition( uint32_t id, Vector3& position ) const
76 const SceneGraph::Node* node = GetNodeWithId( id );
79 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
85 bool UpdateProxy::SetPosition( uint32_t id, const Vector3& position )
88 SceneGraph::Node* node = GetNodeWithId( id );
91 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
97 bool UpdateProxy::BakePosition( uint32_t id, const Vector3& position )
100 SceneGraph::Node* node = GetNodeWithId( id );
103 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION, position );
109 bool UpdateProxy::GetSize( uint32_t id, Vector3& size ) const
111 bool success = false;
112 const SceneGraph::Node* node = GetNodeWithId( id );
115 size = mTransformManager.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 position = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_POSITION );
152 size = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SIZE );
158 bool UpdateProxy::GetScale( uint32_t id, Vector3& scale ) const
160 bool success = false;
161 const SceneGraph::Node* node = GetNodeWithId( id );
164 scale = mTransformManager.GetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE );
171 bool UpdateProxy::SetScale( uint32_t id, const Vector3& scale )
173 bool success = false;
174 SceneGraph::Node* node = GetNodeWithId( id );
177 mTransformManager.SetVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
183 bool UpdateProxy::BakeScale( uint32_t id, const Vector3& scale )
185 bool success = false;
186 SceneGraph::Node* node = GetNodeWithId( id );
189 mTransformManager.BakeVector3PropertyValue( node->mTransformId, SceneGraph::TRANSFORM_PROPERTY_SCALE, scale );
195 bool UpdateProxy::GetColor( uint32_t id, Vector4& color ) const
197 bool success = false;
198 SceneGraph::Node* node = GetNodeWithId( id );
201 color = node->mColor.Get( mCurrentBufferIndex );
208 bool UpdateProxy::SetColor( uint32_t id, const Vector4& color )
210 bool success = false;
211 SceneGraph::Node* node = GetNodeWithId( id );
214 node->mColor.Set( mCurrentBufferIndex, color );
215 node->SetDirtyFlag( SceneGraph::NodePropertyFlags::COLOR );
216 AddResetter( *node, node->mColor );
222 bool UpdateProxy::BakeColor( uint32_t id, const Vector4& color )
224 bool success = false;
225 SceneGraph::Node* node = GetNodeWithId( id );
228 node->mColor.Bake( mCurrentBufferIndex, color );
234 void UpdateProxy::NodeHierarchyChanged()
236 mLastCachedIdNodePair = { 0u, NULL };
237 mNodeContainer.clear();
238 mPropertyModifier.reset();
241 SceneGraph::Node* UpdateProxy::GetNodeWithId( uint32_t id ) const
243 SceneGraph::Node* node = NULL;
245 // Cache the last accessed node so we don't have to traverse
246 if( mLastCachedIdNodePair.node && mLastCachedIdNodePair.id == id )
248 node = mLastCachedIdNodePair.node;
252 // Find node in vector
253 for( auto&& pair : mNodeContainer )
258 mLastCachedIdNodePair = pair;
265 // Node not in vector, find in scene-graph
266 node = FindNodeInSceneGraph( id, mRootNode );
269 mNodeContainer.push_back( { id, node } );
270 mLastCachedIdNodePair = *mNodeContainer.rbegin();
278 void UpdateProxy::AddResetter( SceneGraph::Node& node, SceneGraph::PropertyBase& propertyBase )
280 if( ! mPropertyModifier )
282 mPropertyModifier = PropertyModifierPtr( new PropertyModifier( mUpdateManager ) );
284 mPropertyModifier->AddResetter( node, propertyBase );
287 } // namespace Internal