1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/internal/update/manager/update-manager.h>
38 class NodePropertyMessageBase : public MessageBase
45 NodePropertyMessageBase(UpdateManager& updateManager);
50 virtual ~NodePropertyMessageBase();
55 * Inform UpdateManager that the Node is now active
57 void NotifyUpdateManager( Node* node );
62 NodePropertyMessageBase(const NodePropertyMessageBase&);
63 NodePropertyMessageBase& operator=(const NodePropertyMessageBase& rhs);
67 UpdateManager& mUpdateManager;
71 * Templated message which bakes a Node property.
73 template< typename P >
74 class NodePropertyMessage : public NodePropertyMessageBase
78 typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, typename ParameterType< P >::PassingType );
82 * @note The node is expected to be const in the thread which sends this message.
83 * However it can be modified when Process() is called in a different thread.
84 * @param[in] updateManager The update-manager.
85 * @param[in] node The node.
86 * @param[in] property The property to bake.
87 * @param[in] member The member function of the object.
88 * @param[in] value The new value of the property.
90 static void Send( UpdateManager& updateManager,
92 const AnimatableProperty<P>* property,
93 MemberFunction member,
94 typename ParameterType< P >::PassingType value )
96 // Reserve some memory inside the message queue
97 unsigned int* slot = updateManager.GetEventToUpdate().ReserveMessageSlot( sizeof( NodePropertyMessage ) );
99 // Construct message in the message queue memory; note that delete should not be called on the return value
100 new (slot) NodePropertyMessage( updateManager, node, property, member, value );
106 virtual ~NodePropertyMessage()
111 * @copydoc MessageBase::Process
113 virtual void Process( BufferIndex updateBufferIndex )
115 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
117 if( ! mNode->IsActive() )
119 // Inform UpdateManager that the Node is now active
120 NotifyUpdateManager( mNode );
128 * @note The node is expected to be const in the thread which sends this message.
129 * However it can be modified when Process() is called in a different thread.
130 * @param[in] updateManager The update-manager.
131 * @param[in] node The node.
132 * @param[in] property The property to bake.
133 * @param[in] member The member function of the object.
134 * @param[in] value The new value of the property.
136 NodePropertyMessage( UpdateManager& updateManager,
138 const AnimatableProperty<P>* property,
139 MemberFunction member,
140 typename ParameterType< P >::PassingType value )
141 : NodePropertyMessageBase( updateManager ),
142 mNode( const_cast< Node* >( node ) ),
143 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
144 mMemberFunction( member ),
152 AnimatableProperty<P>* mProperty;
153 MemberFunction mMemberFunction;
154 typename ParameterType< P >::HolderType mParam;
158 * Templated message which bakes a Node property.
160 template< typename P >
161 class NodePropertyComponentMessage : public NodePropertyMessageBase
165 typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
169 * @note The node is expected to be const in the thread which sends this message.
170 * However it can be modified when Process() is called in a different thread.
171 * @param[in] updateManager The update-manager.
172 * @param[in] node The node.
173 * @param[in] property The property to bake.
174 * @param[in] member The member function of the object.
175 * @param[in] value The new value of the X,Y,Z or W component.
177 static void Send( UpdateManager& updateManager,
179 const AnimatableProperty<P>* property,
180 MemberFunction member,
183 // Reserve some memory inside the message queue
184 unsigned int* slot = updateManager.GetEventToUpdate().ReserveMessageSlot( sizeof( NodePropertyComponentMessage ) );
186 // Construct message in the message queue memory; note that delete should not be called on the return value
187 new (slot) NodePropertyComponentMessage( updateManager, node, property, member, value );
193 virtual ~NodePropertyComponentMessage()
198 * @copydoc MessageBase::Process
200 virtual void Process( BufferIndex updateBufferIndex )
202 (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
204 if( ! mNode->IsActive() )
206 // Inform UpdateManager that the Node is now active
207 NotifyUpdateManager( mNode );
215 * @note The node is expected to be const in the thread which sends this message.
216 * However it can be modified when Process() is called in a different thread.
217 * @param[in] updateManager The update-manager.
218 * @param[in] node The node.
219 * @param[in] property The property to bake.
220 * @param[in] member The member function of the object.
221 * @param[in] value The new value of the X,Y,Z or W component.
223 NodePropertyComponentMessage( UpdateManager& updateManager,
225 const AnimatableProperty<P>* property,
226 MemberFunction member,
228 : NodePropertyMessageBase( updateManager ),
229 mNode( const_cast< Node* >( node ) ),
230 mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
231 mMemberFunction( member ),
239 AnimatableProperty<P>* mProperty;
240 MemberFunction mMemberFunction;
244 } // namespace SceneGraph
246 } // namespace Internal
250 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H__