Revert "[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     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
109   }
110
111 private:
112
113   /**
114    * Create a message.
115    * @note The node is expected to be const in the thread which sends this message.
116    * However it can be modified when Process() is called in a different thread.
117    * @param[in] updateManager The update-manager.
118    * @param[in] node The node.
119    * @param[in] property The property to bake.
120    * @param[in] member The member function of the object.
121    * @param[in] value The new value of the property.
122    */
123   NodePropertyMessage( UpdateManager& updateManager,
124                        const Node* node,
125                        const AnimatableProperty<P>* property,
126                        MemberFunction member,
127                        typename ParameterType< P >::PassingType value )
128   : NodePropertyMessageBase( updateManager ),
129     mNode( const_cast< Node* >( node ) ),
130     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
131     mMemberFunction( member ),
132     mParam( value )
133   {
134   }
135
136 private:
137
138   Node* mNode;
139   AnimatableProperty<P>* mProperty;
140   MemberFunction mMemberFunction;
141   typename ParameterType< P >::HolderType mParam;
142 };
143
144 /**
145  * Templated message which bakes a Node property.
146  */
147 template< typename P >
148 class NodePropertyComponentMessage : public NodePropertyMessageBase
149 {
150 public:
151
152   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
153
154   /**
155    * Send a message.
156    * @note The node is expected to be const in the thread which sends this message.
157    * However it can be modified when Process() is called in a different thread.
158    * @param[in] eventThreadServices The object used to send messages to the scene graph
159    * @param[in] node The node.
160    * @param[in] property The property to bake.
161    * @param[in] member The member function of the object.
162    * @param[in] value The new value of the X,Y,Z or W component.
163    */
164   static void Send( EventThreadServices& eventThreadServices,
165                     const Node* node,
166                     const AnimatableProperty<P>* property,
167                     MemberFunction member,
168                     float value )
169   {
170     // Reserve some memory inside the message queue
171     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodePropertyComponentMessage ) );
172
173     // Construct message in the message queue memory; note that delete should not be called on the return value
174     new (slot) NodePropertyComponentMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
175   }
176
177   /**
178    * Virtual destructor
179    */
180   virtual ~NodePropertyComponentMessage()
181   {
182   }
183
184   /**
185    * @copydoc MessageBase::Process
186    */
187   virtual void Process( BufferIndex updateBufferIndex )
188   {
189     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
190   }
191
192 private:
193
194   /**
195    * Create a message.
196    * @note The node is expected to be const in the thread which sends this message.
197    * However it can be modified when Process() is called in a different thread.
198    * @param[in] updateManager The update-manager.
199    * @param[in] node The node.
200    * @param[in] property The property to bake.
201    * @param[in] member The member function of the object.
202    * @param[in] value The new value of the X,Y,Z or W component.
203   */
204   NodePropertyComponentMessage( UpdateManager& updateManager,
205                                 const Node* node,
206                                 const AnimatableProperty<P>* property,
207                                 MemberFunction member,
208                                 float value )
209   : NodePropertyMessageBase( updateManager ),
210     mNode( const_cast< Node* >( node ) ),
211     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
212     mMemberFunction( member ),
213     mParam( value )
214   {
215   }
216
217 private:
218
219   Node* mNode;
220   AnimatableProperty<P>* mProperty;
221   MemberFunction mMemberFunction;
222   float mParam;
223 };
224
225
226 template <typename P>
227 class NodeTransformPropertyMessage : public NodePropertyMessageBase
228 {
229 public:
230
231   typedef void(TransformManagerPropertyHandler<P>::*MemberFunction)( BufferIndex, const P& );
232
233   /**
234    * Create a message.
235    * @note The node is expected to be const in the thread which sends this message.
236    * However it can be modified when Process() is called in a different thread.
237    * @param[in] eventThreadServices The object used to send messages to the scene graph
238    * @param[in] node The node.
239    * @param[in] property The property to bake.
240    * @param[in] member The member function of the object.
241    * @param[in] value The new value of the property.
242    */
243   static void Send( EventThreadServices& eventThreadServices,
244                     const Node* node,
245                     const TransformManagerPropertyHandler<P>* property,
246                     MemberFunction member,
247                     const P& value )
248   {
249     // Reserve some memory inside the message queue
250     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodeTransformPropertyMessage ) );
251
252     // Construct message in the message queue memory; note that delete should not be called on the return value
253     new (slot) NodeTransformPropertyMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
254   }
255
256   /**
257    * Virtual destructor
258    */
259   virtual ~NodeTransformPropertyMessage()
260   {
261   }
262
263   /**
264    * @copydoc MessageBase::Process
265    */
266   virtual void Process( BufferIndex updateBufferIndex )
267   {
268     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
269   }
270
271 private:
272
273   /**
274    * Create a message.
275    * @note The node is expected to be const in the thread which sends this message.
276    * However it can be modified when Process() is called in a different thread.
277    * @param[in] updateManager The update-manager.
278    * @param[in] node The node.
279    * @param[in] property The property to bake.
280    * @param[in] member The member function of the object.
281    * @param[in] value The new value of the property.
282    */
283   NodeTransformPropertyMessage( UpdateManager& updateManager,
284                        const Node* node,
285                        const TransformManagerPropertyHandler<P>* property,
286                        MemberFunction member,
287                        const P& value )
288   : NodePropertyMessageBase( updateManager ),
289     mNode( const_cast< Node* >( node ) ),
290     mProperty( const_cast< TransformManagerPropertyHandler<P>* >( property ) ),
291     mMemberFunction( member ),
292     mParam( value )
293   {
294   }
295
296 private:
297
298   Node* mNode;
299   TransformManagerPropertyHandler<P>* mProperty;
300   MemberFunction mMemberFunction;
301   P mParam;
302 };
303
304
305 template <typename P>
306 class NodeTransformComponentMessage : public NodePropertyMessageBase
307 {
308 public:
309
310   typedef void(TransformManagerPropertyHandler<P>::*MemberFunction)( BufferIndex, float );
311
312   /**
313    * Send a message.
314    * @note The node is expected to be const in the thread which sends this message.
315    * However it can be modified when Process() is called in a different thread.
316    * @param[in] eventThreadServices The object used to send messages to the scene graph
317    * @param[in] node The node.
318    * @param[in] property The property to bake.
319    * @param[in] member The member function of the object.
320    * @param[in] value The new value of the X,Y,Z or W component.
321    */
322   static void Send( EventThreadServices& eventThreadServices,
323                     const Node* node,
324                     const TransformManagerPropertyHandler<P>* property,
325                     MemberFunction member,
326                     float value )
327   {
328     // Reserve some memory inside the message queue
329     uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( NodeTransformComponentMessage ) );
330
331     // Construct message in the message queue memory; note that delete should not be called on the return value
332     new (slot) NodeTransformComponentMessage( eventThreadServices.GetUpdateManager(), node, property, member, value );
333   }
334
335   /**
336    * Virtual destructor
337    */
338   virtual ~NodeTransformComponentMessage()
339   {
340   }
341
342   /**
343    * @copydoc MessageBase::Process
344    */
345   virtual void Process( BufferIndex updateBufferIndex )
346   {
347     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
348   }
349
350 private:
351
352   /**
353    * Create a message.
354    * @note The node is expected to be const in the thread which sends this message.
355    * However it can be modified when Process() is called in a different thread.
356    * @param[in] updateManager The update-manager.
357    * @param[in] node The node.
358    * @param[in] property The property to bake.
359    * @param[in] member The member function of the object.
360    * @param[in] value The new value of the X,Y,Z or W component.
361   */
362   NodeTransformComponentMessage( UpdateManager& updateManager,
363                                 const Node* node,
364                                 const TransformManagerPropertyHandler<P>* property,
365                                 MemberFunction member,
366                                 float value )
367   : NodePropertyMessageBase( updateManager ),
368     mNode( const_cast< Node* >( node ) ),
369     mProperty( const_cast< TransformManagerPropertyHandler<P>* >( property ) ),
370     mMemberFunction( member ),
371     mParam( value )
372   {
373   }
374
375 private:
376
377   Node* mNode;
378   TransformManagerPropertyHandler<P>* mProperty;
379   MemberFunction mMemberFunction;
380   float mParam;
381 };
382
383 } // namespace SceneGraph
384
385 } // namespace Internal
386
387 } // namespace Dali
388
389 #endif // DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H