[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node-messages.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
2 #define DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35
36 // Messages for Node
37
38 class NodePropertyMessageBase : public MessageBase
39 {
40 public:
41
42   /**
43    * Create a message.
44    */
45   NodePropertyMessageBase(UpdateManager& updateManager);
46
47   /**
48    * Virtual destructor
49    */
50   virtual ~NodePropertyMessageBase();
51
52 private:
53
54   // Undefined
55   NodePropertyMessageBase(const NodePropertyMessageBase&);
56   NodePropertyMessageBase& operator=(const NodePropertyMessageBase& rhs);
57
58 protected:
59
60   UpdateManager& mUpdateManager;
61 };
62
63 /**
64  * Templated message which bakes a Node property.
65  */
66 template< typename P >
67 class NodePropertyMessage : public NodePropertyMessageBase
68 {
69 public:
70
71   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, typename ParameterType< P >::PassingType );
72
73   /**
74    * Create a message.
75    * @note The node is expected to be const in the thread which sends this message.
76    * However it can be modified when Process() is called in a different thread.
77    * @param[in] eventThreadServices The object used to send messages to the scene graph
78    * @param[in] node The node.
79    * @param[in] property The property to bake.
80    * @param[in] member The member function of the object.
81    * @param[in] value The new value of the property.
82    */
83   static void Send( EventThreadServices& eventThreadServices,
84                     const Node* node,
85                     const AnimatableProperty<P>* property,
86                     MemberFunction member,
87                     typename ParameterType< P >::PassingType value )
88   {
89     // Reserve some memory inside the message queue
90     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodePropertyMessage ) );
91
92     // Construct message in the message queue memory; note that delete should not be called on the return value
93     new (slot) NodePropertyMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
94   }
95
96   /**
97    * Virtual destructor
98    */
99   virtual ~NodePropertyMessage()
100   {
101   }
102
103   /**
104    * @copydoc MessageBase::Process
105    */
106   virtual void Process( BufferIndex updateBufferIndex )
107   {
108     mNode->SetPropertyDirty( true );
109     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
110   }
111
112 private:
113
114   /**
115    * Create a message.
116    * @note The node is expected to be const in the thread which sends this message.
117    * However it can be modified when Process() is called in a different thread.
118    * @param[in] updateManager The update-manager.
119    * @param[in] node The node.
120    * @param[in] property The property to bake.
121    * @param[in] member The member function of the object.
122    * @param[in] value The new value of the property.
123    */
124   NodePropertyMessage( UpdateManager& updateManager,
125                        const Node* node,
126                        const AnimatableProperty<P>* property,
127                        MemberFunction member,
128                        typename ParameterType< P >::PassingType value )
129   : NodePropertyMessageBase( updateManager ),
130     mNode( const_cast< Node* >( node ) ),
131     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
132     mMemberFunction( member ),
133     mParam( value )
134   {
135   }
136
137 private:
138
139   Node* mNode;
140   AnimatableProperty<P>* mProperty;
141   MemberFunction mMemberFunction;
142   typename ParameterType< P >::HolderType mParam;
143 };
144
145 /**
146  * Templated message which bakes a Node property.
147  */
148 template< typename P >
149 class NodePropertyComponentMessage : public NodePropertyMessageBase
150 {
151 public:
152
153   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
154
155   /**
156    * Send a message.
157    * @note The node is expected to be const in the thread which sends this message.
158    * However it can be modified when Process() is called in a different thread.
159    * @param[in] eventThreadServices The object used to send messages to the scene graph
160    * @param[in] node The node.
161    * @param[in] property The property to bake.
162    * @param[in] member The member function of the object.
163    * @param[in] value The new value of the X,Y,Z or W component.
164    */
165   static void Send( EventThreadServices& eventThreadServices,
166                     const Node* node,
167                     const AnimatableProperty<P>* property,
168                     MemberFunction member,
169                     float value )
170   {
171     // Reserve some memory inside the message queue
172     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodePropertyComponentMessage ) );
173
174     // Construct message in the message queue memory; note that delete should not be called on the return value
175     new (slot) NodePropertyComponentMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
176   }
177
178   /**
179    * Virtual destructor
180    */
181   virtual ~NodePropertyComponentMessage()
182   {
183   }
184
185   /**
186    * @copydoc MessageBase::Process
187    */
188   virtual void Process( BufferIndex updateBufferIndex )
189   {
190     mNode->SetPropertyDirty( true );
191     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
192   }
193
194 private:
195
196   /**
197    * Create a message.
198    * @note The node is expected to be const in the thread which sends this message.
199    * However it can be modified when Process() is called in a different thread.
200    * @param[in] updateManager The update-manager.
201    * @param[in] node The node.
202    * @param[in] property The property to bake.
203    * @param[in] member The member function of the object.
204    * @param[in] value The new value of the X,Y,Z or W component.
205   */
206   NodePropertyComponentMessage( UpdateManager& updateManager,
207                                 const Node* node,
208                                 const AnimatableProperty<P>* property,
209                                 MemberFunction member,
210                                 float value )
211   : NodePropertyMessageBase( updateManager ),
212     mNode( const_cast< Node* >( node ) ),
213     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
214     mMemberFunction( member ),
215     mParam( value )
216   {
217   }
218
219 private:
220
221   Node* mNode;
222   AnimatableProperty<P>* mProperty;
223   MemberFunction mMemberFunction;
224   float mParam;
225 };
226
227
228 template <typename P>
229 class NodeTransformPropertyMessage : public NodePropertyMessageBase
230 {
231 public:
232
233   typedef void(TransformManagerPropertyHandler<P>::*MemberFunction)( BufferIndex, const P& );
234
235   /**
236    * Create a message.
237    * @note The node is expected to be const in the thread which sends this message.
238    * However it can be modified when Process() is called in a different thread.
239    * @param[in] eventThreadServices The object used to send messages to the scene graph
240    * @param[in] node The node.
241    * @param[in] property The property to bake.
242    * @param[in] member The member function of the object.
243    * @param[in] value The new value of the property.
244    */
245   static void Send( EventThreadServices& eventThreadServices,
246                     const Node* node,
247                     const TransformManagerPropertyHandler<P>* property,
248                     MemberFunction member,
249                     const P& value )
250   {
251     // Reserve some memory inside the message queue
252     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodeTransformPropertyMessage ) );
253
254     // Construct message in the message queue memory; note that delete should not be called on the return value
255     new (slot) NodeTransformPropertyMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
256   }
257
258   /**
259    * Virtual destructor
260    */
261   virtual ~NodeTransformPropertyMessage()
262   {
263   }
264
265   /**
266    * @copydoc MessageBase::Process
267    */
268   virtual void Process( BufferIndex updateBufferIndex )
269   {
270     mNode->SetPropertyDirty( true );
271     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
272   }
273
274 private:
275
276   /**
277    * Create a message.
278    * @note The node is expected to be const in the thread which sends this message.
279    * However it can be modified when Process() is called in a different thread.
280    * @param[in] updateManager The update-manager.
281    * @param[in] node The node.
282    * @param[in] property The property to bake.
283    * @param[in] member The member function of the object.
284    * @param[in] value The new value of the property.
285    */
286   NodeTransformPropertyMessage( UpdateManager& updateManager,
287                        const Node* node,
288                        const TransformManagerPropertyHandler<P>* property,
289                        MemberFunction member,
290                        const P& value )
291   : NodePropertyMessageBase( updateManager ),
292     mNode( const_cast< Node* >( node ) ),
293     mProperty( const_cast< TransformManagerPropertyHandler<P>* >( property ) ),
294     mMemberFunction( member ),
295     mParam( value )
296   {
297   }
298
299 private:
300
301   Node* mNode;
302   TransformManagerPropertyHandler<P>* mProperty;
303   MemberFunction mMemberFunction;
304   P mParam;
305 };
306
307
308 template <typename P>
309 class NodeTransformComponentMessage : public NodePropertyMessageBase
310 {
311 public:
312
313   typedef void(TransformManagerPropertyHandler<P>::*MemberFunction)( BufferIndex, float );
314
315   /**
316    * Send a message.
317    * @note The node is expected to be const in the thread which sends this message.
318    * However it can be modified when Process() is called in a different thread.
319    * @param[in] eventThreadServices The object used to send messages to the scene graph
320    * @param[in] node The node.
321    * @param[in] property The property to bake.
322    * @param[in] member The member function of the object.
323    * @param[in] value The new value of the X,Y,Z or W component.
324    */
325   static void Send( EventThreadServices& eventThreadServices,
326                     const Node* node,
327                     const TransformManagerPropertyHandler<P>* property,
328                     MemberFunction member,
329                     float value )
330   {
331     // Reserve some memory inside the message queue
332     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodeTransformComponentMessage ) );
333
334     // Construct message in the message queue memory; note that delete should not be called on the return value
335     new (slot) NodeTransformComponentMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
336   }
337
338   /**
339    * Virtual destructor
340    */
341   virtual ~NodeTransformComponentMessage()
342   {
343   }
344
345   /**
346    * @copydoc MessageBase::Process
347    */
348   virtual void Process( BufferIndex updateBufferIndex )
349   {
350     mNode->SetPropertyDirty( true );
351     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
352   }
353
354 private:
355
356   /**
357    * Create a message.
358    * @note The node is expected to be const in the thread which sends this message.
359    * However it can be modified when Process() is called in a different thread.
360    * @param[in] updateManager The update-manager.
361    * @param[in] node The node.
362    * @param[in] property The property to bake.
363    * @param[in] member The member function of the object.
364    * @param[in] value The new value of the X,Y,Z or W component.
365   */
366   NodeTransformComponentMessage( UpdateManager& updateManager,
367                                 const Node* node,
368                                 const TransformManagerPropertyHandler<P>* property,
369                                 MemberFunction member,
370                                 float value )
371   : NodePropertyMessageBase( updateManager ),
372     mNode( const_cast< Node* >( node ) ),
373     mProperty( const_cast< TransformManagerPropertyHandler<P>* >( property ) ),
374     mMemberFunction( member ),
375     mParam( value )
376   {
377   }
378
379 private:
380
381   Node* mNode;
382   TransformManagerPropertyHandler<P>* mProperty;
383   MemberFunction mMemberFunction;
384   float mParam;
385 };
386
387 } // namespace SceneGraph
388
389 } // namespace Internal
390
391 } // namespace Dali
392
393 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H