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