364390ea20d9f2072d22620af4759ac981497f17
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 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/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 #include <dali/integration-api/resource-declarations.h>
26
27 #include <dali/internal/common/message.h>
28 #include <dali/internal/common/event-to-update.h>
29 #include <dali/internal/common/type-abstraction-enums.h>
30
31 #include <dali/internal/update/animation/scene-graph-animation.h>
32 #include <dali/internal/update/common/scene-graph-buffers.h>
33 #include <dali/internal/update/common/scene-graph-property-notification.h>
34 #include <dali/internal/update/manager/object-owner-container.h>
35 #include <dali/internal/update/node-attachments/node-attachment.h>
36 #include <dali/internal/update/nodes/node.h>
37 #include <dali/internal/update/nodes/scene-graph-layer.h>
38
39 #include <dali/internal/render/shaders/scene-graph-shader.h>
40
41 namespace Dali
42 {
43
44 namespace Integration
45 {
46 class GlSyncAbstraction;
47 class RenderController;
48 struct DynamicsWorldSettings;
49
50 } // namespace Integration
51
52 namespace Internal
53 {
54
55 class PropertyNotifier;
56 class EventToUpdate;
57 struct DynamicsWorldSettings;
58 class NotificationManager;
59 class CompleteNotificationInterface;
60 class ResourceManager;
61 class TouchResampler;
62
63 // value types used by messages
64 template <> struct ParameterType< PropertyNotification::NotifyMode >
65 : public BasicType< PropertyNotification::NotifyMode > {};
66
67 namespace SceneGraph
68 {
69
70 class Animation;
71 class DiscardQueue;
72 class PanGesture;
73 class RenderManager;
74 class RenderTaskList;
75 class RenderQueue;
76 class DynamicsWorld;
77 class TextureCache;
78 class Geometry;
79 class PropertyBuffer;
80 class Material;
81 class Sampler;
82 class RendererAttachment;
83
84 /**
85  * UpdateManager holds a scene graph i.e. a tree of nodes.
86  * It controls the Update traversal, in which nodes are repositioned/animated,
87  * and organizes the the culling and rendering of the scene.
88  */
89 class UpdateManager
90 {
91 public:
92
93   /**
94    * Construct a new UpdateManager.
95    * @param[in] notificationManager This should be notified when animations have finished.
96    * @param[in] glSyncAbstraction Used to determine when framebuffers are ready
97    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
98    * @param[in] propertyNotifier The PropertyNotifier
99    * @param[in] resourceManager The resource manager used to load textures etc.
100    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
101    * @param[in] controller After messages are flushed, we request a render from the RenderController.
102    * @param[in] renderManager This is responsible for rendering the results of each "update".
103    * @param[in] renderQueue Used to queue messages for the next render.
104    * @param[in] textureCache Used for caching textures.
105    * @param[in] touchResampler Used for re-sampling touch events.
106    */
107   UpdateManager( NotificationManager& notificationManager,
108                  Integration::GlSyncAbstraction& glSyncAbstraction,
109                  CompleteNotificationInterface& animationFinishedNotifier,
110                  PropertyNotifier& propertyNotifier,
111                  ResourceManager& resourceManager,
112                  DiscardQueue& discardQueue,
113                  Integration::RenderController& controller,
114                  RenderManager& renderManager,
115                  RenderQueue& renderQueue,
116                  TextureCache& textureCache,
117                  TouchResampler& touchResampler );
118
119   /**
120    * Destructor. Not virtual as this is not a base class
121    */
122   ~UpdateManager();
123
124   /**
125    * The event-thread uses this interface to queue messages for the next update.
126    * @return The event-to-update interface.
127    */
128   EventToUpdate& GetEventToUpdate();
129
130   /**
131    * @return the event buffer index
132    */
133   BufferIndex GetEventBufferIndex() const
134   {
135     // inlined as its called often
136     return mSceneGraphBuffers.GetEventBufferIndex();
137   }
138
139   // Node connection methods
140
141   /**
142    * Get the scene graph side list of RenderTasks.
143    * @param[in] systemLevel True if using the system-level overlay.
144    * @return The list of render tasks
145    */
146   RenderTaskList* GetRenderTaskList( bool systemLevel );
147
148   /**
149    * Installs a new layer as the root node.
150    * @pre The UpdateManager does not already have an installed root node.
151    * @pre The layer is of derived Node type Layer.
152    * @pre The layer does not have a parent.
153    * @param[in] layer The new root node.
154    * @param[in] systemLevel True if using the system-level overlay.
155    * @post The node is owned by UpdateManager.
156    */
157   void InstallRoot( Layer* layer, bool systemLevel );
158
159   /**
160    * Add a Node; UpdateManager takes ownership.
161    * @pre The node does not have a parent.
162    * @param[in] node The node to add.
163    */
164   void AddNode( Node* node );
165
166   /**
167    * Connect a Node to the scene-graph.
168    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
169    * @pre The node does not already have a parent.
170    * @param[in] node The new parent node.
171    * @param[in] node The node to connect.
172    */
173   void ConnectNode( Node* parent, Node* node, int index );
174
175   /**
176    * Disconnect a Node from the scene-graph.
177    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
178    * @pre The node has a parent.
179    * @param[in] node The node to disconnect.
180    */
181   void DisconnectNode( Node* node );
182
183   /**
184    * Called when a property is set on a disconnected Node (via public API)
185    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
186    * @pre The node does not have a parent.
187    * @param[in] node The node to set as "active".
188    */
189   void SetNodeActive( Node* node );
190
191   /**
192    * Destroy a Node owned by UpdateManager.
193    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
194    * In the following update, the previously queued Nodes may be deleted.
195    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
196    * @param[in] node The node to destroy.
197    */
198   void DestroyNode( Node* node );
199
200   /**
201    * Attach an object to a Node.
202    * The UpdateManager is responsible for calling NodeAttachment::Initialize().
203    * @param[in] node The node which will own the attachment.
204    * @param[in] attachment The object to attach.
205    */
206   void AttachToNode( Node* node, NodeAttachment* attachment );
207
208   /**
209    * Attach a renderer to the scene graph
210    */
211   void AttachToSceneGraph( RendererAttachment* renderer );
212
213
214   /**
215    * Add a newly created object.
216    * @param[in] object The object to add.
217    * @post The object is owned by UpdateManager.
218    */
219   void AddObject( PropertyOwner* object );
220
221   /**
222    * Remove an object.
223    * @param[in] object The object to remove.
224    */
225   void RemoveObject( PropertyOwner* object );
226
227   // Animations
228
229   /**
230    * Add a newly created animation.
231    * @param[in] animation The animation to add.
232    * @post The animation is owned by UpdateManager.
233    */
234   void AddAnimation( Animation* animation );
235
236   /**
237    * Stop an animation.
238    * @param[in] animation The animation to stop.
239    */
240   void StopAnimation( Animation* animation );
241
242   /**
243    * Remove an animation.
244    * @param[in] animation The animation to remove.
245    */
246   void RemoveAnimation( Animation* animation );
247
248   /**
249    * Query whether any animations are currently running.
250    * @return True if any animations are running.
251    */
252   bool IsAnimationRunning() const;
253
254   // Property Notification
255
256   /**
257    * Add a newly created property notification
258    * @param[in] propertyNotification The notification to add
259    * @post The propertyNotification is owned by UpdateManager.
260    */
261   void AddPropertyNotification( PropertyNotification* propertyNotification );
262
263   /**
264    * Remove a property notification
265    * @param[in] propertyNotification The notification to remove
266    */
267   void RemovePropertyNotification( PropertyNotification* propertyNotification );
268
269   /**
270    * Set Notify state for PropertyNotification
271    * @param[in] propertyNotification The notification to remove
272    * @param[in] notifyMode The notification mode.
273    */
274   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
275
276   /**
277    * @brief Get the geometry owner
278    *
279    * @return The geometry owner
280    */
281   ObjectOwnerContainer< Geometry >& GetGeometryOwner();
282
283   /**
284    * @brief Get the material owner
285    *
286    * @return The material owner
287    */
288   ObjectOwnerContainer< Material >& GetMaterialOwner();
289
290   /**
291    * @brief Get the sampler owner
292    *
293    * @return The sampler owner
294    */
295   ObjectOwnerContainer< Sampler >& GetSamplerOwner();
296
297   /**
298    * @brief Get the property buffer owner
299    *
300    * @return The property buffer owner
301    */
302   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
303
304
305   // Shaders
306
307   /**
308    * Add a newly created shader.
309    * @param[in] shader The shader to add.
310    * @post The shader is owned by the UpdateManager.
311    */
312   void AddShader(Shader* shader);
313
314   /**
315    * Remove a shader.
316    * @pre The shader has been added to the UpdateManager.
317    * @param[in] shader The shader to remove.
318    * @post The shader is destroyed.
319    */
320   void RemoveShader(Shader* shader);
321
322   /**
323    * Set the shader program for a specified GeometryType to a Shader object
324    * @param[in] shader        The shader to modify
325    * @param[in] geometryType  The GeometryType to map to the program
326    * @param[in] subType       The program subtype
327    * @param[in] resourceId    A ResourceManager ticket ID for the program data (source and compiled binary)
328    * @param[in] shaderHash    hash key created with vertex and fragment shader code
329    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
330    */
331   void SetShaderProgram( Shader* shader, GeometryType geometryType, ShaderSubTypes subType, Integration::ResourceId resourceId, size_t shaderHash, bool modifiesGeometry );
332
333   /**
334    * Add a newly created gesture.
335    * @param[in] gesture The gesture to add.
336    * @post The gesture is owned by the UpdateManager.
337    */
338   void AddGesture( PanGesture* gesture );
339
340   /**
341    * Remove a gesture.
342    * @pre The gesture has been added to the UpdateManager.
343    * @param[in] gesture The gesture to remove.
344    * @post The gesture is destroyed.
345    */
346   void RemoveGesture( PanGesture* gesture );
347
348 public:
349
350   /**
351    * Performs an Update traversal on the scene-graph.
352    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
353    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
354    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
355    * @return True if further updates are required e.g. during animations.
356    */
357   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
358
359   /**
360    * Set the background color i.e. the glClear color used at the beginning of each frame.
361    * @param[in] color The new background color.
362    */
363   void SetBackgroundColor(const Vector4& color);
364
365   /**
366    * Set the default surface rect.
367    * @param[in] rect The rect value representing the surface.
368    */
369   void SetDefaultSurfaceRect( const Rect<int>& rect );
370
371   /**
372    * @copydoc Dali::Stage::KeepRendering()
373    */
374   void KeepRendering( float durationSeconds );
375
376   /**
377    * Sets the depths of all layers.
378    * @param layers The layers in depth order.
379    * @param[in] systemLevel True if using the system-level overlay.
380    */
381   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
382
383 #ifdef DYNAMICS_SUPPORT
384
385   /**
386    * Initialize the dynamics world
387    * @param[in] world The dynamics world
388    * @param[in] worldSettings The dynamics world settings
389    * @param[in] debugShader The shader used for rendering dynamics debug information
390    */
391   void InitializeDynamicsWorld( DynamicsWorld* world, Integration::DynamicsWorldSettings* worldSettings );
392
393   /**
394    * Terminate the dynamics world
395    */
396   void TerminateDynamicsWorld();
397
398 #endif // DYNAMICS_SUPPORT
399
400 private:
401
402   // Undefined
403   UpdateManager(const UpdateManager&);
404
405   // Undefined
406   UpdateManager& operator=(const UpdateManager& rhs);
407
408   /**
409    * Helper to check whether the update-thread should keep going.
410    * @param[in] elapsedSeconds The time in seconds since the previous update.
411    * @return True if the update-thread should keep going.
412    */
413   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
414
415   /**
416    * Helper to calculate new camera setup when root node resizes.
417    * @param[in] updateBuffer The buffer to read the root node size from.
418    */
419   void UpdateProjectionAndViewMatrices(int updateBuffer);
420
421   /**
422    * Post process resources that have been updated by renderer
423    */
424   void PostProcessResources();
425
426   /**
427    * Helper to reset a Node properties.
428    * @param[in] node The node.
429    */
430   void ResetNodeProperty( Node& node );
431
432   /**
433    * Helper to reset all Node properties
434    */
435   void ResetProperties();
436
437   /**
438    * Perform gesture updates.
439    * @param[in]  lastVSyncTime  The last VSync time in milliseconds.
440    * @param[in]  nextVSyncTime  The estimated time of the next VSync in milliseconds.
441    * @return true, if any properties were updated.
442    */
443   bool ProcessGestures( unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
444
445   /**
446    * Perform animation updates
447    * @param[in] elapsedSeconds time since last frame
448    */
449   void Animate( float elapsedSeconds );
450
451   /**
452    * Perform constraint updates.
453    * @note Applies constraints to nodes first (depth first search order).
454    * Then shader constraints second (construction order)
455    */
456   void ApplyConstraints();
457
458   /**
459    * Perform property notification updates
460    */
461   void ProcessPropertyNotifications();
462
463   /**
464    * Update the default camera.
465    * This must be altered to match the root Node for 2D layouting.
466    * @param[in] updateBuffer The buffer to read the root node size from.
467    */
468   void UpdateDefaultCamera( int updateBuffer );
469
470   /**
471    * Update node shaders, opacity, geometry etc.
472    */
473   void UpdateNodes();
474
475 private:
476
477   // needs to be direct member so that getter for event buffer can be inlined
478   SceneGraphBuffers mSceneGraphBuffers;
479
480   struct Impl;
481   Impl* mImpl;
482
483 };
484
485 // Messages for UpdateManager
486
487 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
488 {
489   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
490
491   // Reserve some memory inside the message queue
492   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
493
494   // Construct message in the message queue memory; note that delete should not be called on the return value
495   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
496 }
497
498 inline void AddNodeMessage( UpdateManager& manager, Node& node )
499 {
500   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
501
502   // Reserve some memory inside the message queue
503   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
504
505   // Construct message in the message queue memory; note that delete should not be called on the return value
506   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
507 }
508
509 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild, int index )
510 {
511   // Update thread can edit the object
512   Node& parent = const_cast< Node& >( constParent );
513   Node& child = const_cast< Node& >( constChild );
514
515   typedef MessageValue3< UpdateManager, Node*, Node*, int > LocalType;
516
517   // Reserve some memory inside the message queue
518   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
519
520   // Construct message in the message queue memory; note that delete should not be called on the return value
521   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child, index );
522 }
523
524 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
525 {
526   // Scene graph thread can modify this object.
527   Node& node = const_cast< Node& >( constNode );
528
529   typedef MessageValue1< UpdateManager, Node* > LocalType;
530
531   // Reserve some memory inside the message queue
532   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
533
534   // Construct message in the message queue memory; note that delete should not be called on the return value
535   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
536 }
537
538 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
539 {
540   // Scene graph thread can destroy this object.
541   Node& node = const_cast< Node& >( constNode );
542
543   typedef MessageValue1< UpdateManager, Node* > LocalType;
544
545   // Reserve some memory inside the message queue
546   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
547
548   // Construct message in the message queue memory; note that delete should not be called on the return value
549   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
550 }
551
552 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
553 {
554   // Scene graph thread can modify this object.
555   Node& parent = const_cast< Node& >( constParent );
556
557   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
558
559   // Reserve some memory inside the message queue
560   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
561
562   // Construct message in the message queue memory; note that delete should not be called on the return value
563   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
564 }
565
566 inline void AttachToSceneGraphMessage( UpdateManager& manager, RendererAttachment* renderer )
567 {
568   typedef MessageValue1< UpdateManager, RendererAttachment* > LocalType;
569
570   // Reserve some memory inside the message queue
571   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
572
573   // Construct message in the message queue memory; note that delete should not be called on the return value
574   new (slot) LocalType( &manager, &UpdateManager::AttachToSceneGraph, renderer );
575 }
576
577 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
578 {
579   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
580
581   // Reserve some memory inside the message queue
582   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
583
584   // Construct message in the message queue memory; note that delete should not be called on the return value
585   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
586 }
587
588 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
589 {
590   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
591
592   // Reserve some memory inside the message queue
593   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
594
595   // Construct message in the message queue memory; note that delete should not be called on the return value
596   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
597 }
598
599 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
600 {
601   typedef MessageValue1< UpdateManager, Animation* > LocalType;
602
603   // Reserve some memory inside the message queue
604   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
605
606   // Construct message in the message queue memory; note that delete should not be called on the return value
607   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
608 }
609
610 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
611 {
612   // The scene-graph thread owns this object so it can safely edit it.
613   Animation& animation = const_cast< Animation& >( constAnimation );
614
615   typedef MessageValue1< UpdateManager, Animation* > LocalType;
616
617   // Reserve some memory inside the message queue
618   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
619
620   // Construct message in the message queue memory; note that delete should not be called on the return value
621   new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
622 }
623
624 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
625 {
626   // The scene-graph thread owns this object so it can safely edit it.
627   Animation& animation = const_cast< Animation& >( constAnimation );
628
629   typedef MessageValue1< UpdateManager, Animation* > LocalType;
630
631   // Reserve some memory inside the message queue
632   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
633
634   // Construct message in the message queue memory; note that delete should not be called on the return value
635   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
636 }
637
638 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
639 {
640   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
641
642   // Reserve some memory inside the message queue
643   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
644
645   // Construct message in the message queue memory; note that delete should not be called on the return value
646   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
647 }
648
649 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
650 {
651   // The scene-graph thread owns this object so it can safely edit it.
652   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
653
654   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
655
656   // Reserve some memory inside the message queue
657   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
658
659   // Construct message in the message queue memory; note that delete should not be called on the return value
660   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
661 }
662
663 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
664                                                       const PropertyNotification* constPropertyNotification,
665                                                       PropertyNotification::NotifyMode notifyMode )
666 {
667   // The scene-graph thread owns this object so it can safely edit it.
668   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
669
670   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
671
672   // Reserve some memory inside the message queue
673   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
674
675   // Construct message in the message queue memory; note that delete should not be called on the return value
676   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
677 }
678
679
680
681 // The render thread can safely change the Shader
682 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
683 {
684   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
685
686   // Reserve some memory inside the message queue
687   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
688
689   // Construct message in the message queue memory; note that delete should not be called on the return value
690   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
691 }
692
693 // The render thread can safely change the Shader
694 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
695 {
696   typedef MessageValue1< UpdateManager, Shader* > LocalType;
697
698   // Reserve some memory inside the message queue
699   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
700
701   // Construct message in the message queue memory; note that delete should not be called on the return value
702   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
703 }
704
705 inline void SetShaderProgramMessage( UpdateManager& manager,
706                                      Shader& shader,
707                                      GeometryType geometryType,
708                                      ShaderSubTypes subType,
709                                      Integration::ResourceId resourceId,
710                                      size_t shaderHash,
711                                      bool modifiesGeometry )
712 {
713   typedef MessageValue6< UpdateManager, Shader*, GeometryType, ShaderSubTypes, Integration::ResourceId, size_t, bool > LocalType;
714
715   // Reserve some memory inside the message queue
716   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
717
718   // Construct message in the message queue memory; note that delete should not be called on the return value
719   new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, geometryType, subType, resourceId, shaderHash, modifiesGeometry );
720 }
721
722 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
723 {
724   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
725
726   // Reserve some memory inside the message queue
727   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
728
729   // Construct message in the message queue memory; note that delete should not be called on the return value
730   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
731 }
732
733 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
734 {
735   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
736
737   // Reserve some memory inside the message queue
738   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
739
740   // Construct message in the message queue memory; note that delete should not be called on the return value
741   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
742 }
743
744 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
745 {
746   typedef MessageValue1< UpdateManager, float > LocalType;
747
748   // Reserve some memory inside the message queue
749   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
750
751   // Construct message in the message queue memory; note that delete should not be called on the return value
752   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
753 }
754
755 /**
756  * Create a message for setting the depth of a layer
757  * @param[in] manager The update manager
758  * @param[in] layers list of layers
759  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
760  */
761 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
762 {
763   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
764
765   // Reserve some memory inside the message queue
766   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
767
768   // Construct message in the message queue memory; note that delete should not be called on the return value
769   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
770 }
771
772 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
773 {
774   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
775
776   // Reserve some memory inside the message queue
777   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
778
779   // Construct message in the message queue memory; note that delete should not be called on the return value
780   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
781 }
782
783 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
784 {
785   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
786
787   // Reserve some memory inside the message queue
788   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
789
790   // Construct message in the message queue memory; note that delete should not be called on the return value
791   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
792 }
793
794 #ifdef DYNAMICS_SUPPORT
795
796 // Dynamics messages
797 inline void InitializeDynamicsWorldMessage( UpdateManager& manager, DynamicsWorld* dynamicsworld, Integration::DynamicsWorldSettings* worldSettings )
798 {
799   typedef MessageValue2< UpdateManager, DynamicsWorld*, Integration::DynamicsWorldSettings* > LocalType;
800
801   // Reserve some memory inside the message queue
802   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
803
804   // Construct message in the message queue memory; note that delete should not be called on the return value
805   new (slot) LocalType( &manager, &UpdateManager::InitializeDynamicsWorld, dynamicsworld, worldSettings );
806 }
807
808 inline void TerminateDynamicsWorldMessage(UpdateManager& manager)
809 {
810   typedef Message< UpdateManager > LocalType;
811
812   // Reserve some memory inside the message queue
813   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
814
815   // Construct message in the message queue memory; note that delete should not be called on the return value
816   new (slot) LocalType( &manager, &UpdateManager::TerminateDynamicsWorld );
817 }
818
819 #endif // DYNAMICS_SUPPORT
820
821
822 template< typename T >
823 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
824 {
825   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
826
827   // Reserve some memory inside the message queue
828   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
829   // Construct message in the message queue memory; note that delete should not be called on the return value
830   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
831 }
832
833 template< typename T >
834 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
835 {
836   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
837
838   // Reserve some memory inside the message queue
839   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
840   // Construct message in the message queue memory; note that delete should not be called on the return value
841   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
842 }
843
844 } // namespace SceneGraph
845
846 } // namespace Internal
847
848 } // namespace Dali
849
850 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__