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