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