Added ObjectOwnerContainer class for scene graph objects
[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
42 namespace Dali
43 {
44
45 namespace Integration
46 {
47 class GlSyncAbstraction;
48 class RenderController;
49 struct DynamicsWorldSettings;
50
51 } // namespace Integration
52
53 namespace Internal
54 {
55
56 class PropertyNotifier;
57 class EventToUpdate;
58 struct DynamicsWorldSettings;
59 class NotificationManager;
60 class CompleteNotificationInterface;
61 class ResourceManager;
62 class TouchResampler;
63
64 // value types used by messages
65 template <> struct ParameterType< PropertyNotification::NotifyMode >
66 : public BasicType< PropertyNotification::NotifyMode > {};
67
68 namespace SceneGraph
69 {
70
71 class Animation;
72 class DiscardQueue;
73 class PanGesture;
74 class RenderManager;
75 class RenderTaskList;
76 class RenderQueue;
77 class DynamicsWorld;
78 class TextureCache;
79 class Geometry;
80 class PropertyBuffer;
81 class Material;
82 class Sampler;
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    * Add a newly created object.
210    * @param[in] object The object to add.
211    * @post The object is owned by UpdateManager.
212    */
213   void AddObject( PropertyOwner* object );
214
215   /**
216    * Remove an object.
217    * @param[in] object The object to remove.
218    */
219   void RemoveObject( PropertyOwner* object );
220
221   // Animations
222
223   /**
224    * Add a newly created animation.
225    * @param[in] animation The animation to add.
226    * @post The animation is owned by UpdateManager.
227    */
228   void AddAnimation( Animation* animation );
229
230   /**
231    * Stop an animation.
232    * @param[in] animation The animation to stop.
233    */
234   void StopAnimation( Animation* animation );
235
236   /**
237    * Remove an animation.
238    * @param[in] animation The animation to remove.
239    */
240   void RemoveAnimation( Animation* animation );
241
242   /**
243    * Query whether any animations are currently running.
244    * @return True if any animations are running.
245    */
246   bool IsAnimationRunning() const;
247
248   // Property Notification
249
250   /**
251    * Add a newly created property notification
252    * @param[in] propertyNotification The notification to add
253    * @post The propertyNotification is owned by UpdateManager.
254    */
255   void AddPropertyNotification( PropertyNotification* propertyNotification );
256
257   /**
258    * Remove a property notification
259    * @param[in] propertyNotification The notification to remove
260    */
261   void RemovePropertyNotification( PropertyNotification* propertyNotification );
262
263   /**
264    * Set Notify state for PropertyNotification
265    * @param[in] propertyNotification The notification to remove
266    * @param[in] notifyMode The notification mode.
267    */
268   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
269
270   /**
271    * @brief Get the geometry owner
272    *
273    * @return The geometry owner
274    */
275   ObjectOwnerContainer<Geometry*>& GetGeometryOwner();
276
277   /**
278    * @brief Get the material owner
279    *
280    * @return The material owner
281    */
282   ObjectOwnerContainer<Material*>& GetMaterialOwner();
283
284   /**
285    * @brief Get the sampler owner
286    *
287    * @return The sampler owner
288    */
289   ObjectOwnerContainer<Sampler*>& GetSamplerOwner();
290
291   /**
292    * @brief Get the property buffer owner
293    *
294    * @return The property buffer owner
295    */
296   ObjectOwnerContainer<PropertyBuffer*>& GetPropertyBufferOwner();
297
298
299   // Shaders
300
301   /**
302    * Add a newly created shader.
303    * @param[in] shader The shader to add.
304    * @post The shader is owned by the UpdateManager.
305    */
306   void AddShader(Shader* shader);
307
308   /**
309    * Remove a shader.
310    * @pre The shader has been added to the UpdateManager.
311    * @param[in] shader The shader to remove.
312    * @post The shader is destroyed.
313    */
314   void RemoveShader(Shader* shader);
315
316   /**
317    * Set the shader program for a specified GeometryType to a Shader object
318    * @param[in] shader        The shader to modify
319    * @param[in] geometryType  The GeometryType to map to the program
320    * @param[in] subType       The program subtype
321    * @param[in] resourceId    A ResourceManager ticket ID for the program data (source and compiled binary)
322    * @param[in] shaderHash    hash key created with vertex and fragment shader code
323    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
324    */
325   void SetShaderProgram( Shader* shader, GeometryType geometryType, ShaderSubTypes subType, Integration::ResourceId resourceId, size_t shaderHash, bool modifiesGeometry );
326
327   /**
328    * Add a newly created gesture.
329    * @param[in] gesture The gesture to add.
330    * @post The gesture is owned by the UpdateManager.
331    */
332   void AddGesture( PanGesture* gesture );
333
334   /**
335    * Remove a gesture.
336    * @pre The gesture has been added to the UpdateManager.
337    * @param[in] gesture The gesture to remove.
338    * @post The gesture is destroyed.
339    */
340   void RemoveGesture( PanGesture* gesture );
341
342 public:
343
344   /**
345    * Performs an Update traversal on the scene-graph.
346    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
347    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
348    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
349    * @return True if further updates are required e.g. during animations.
350    */
351   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
352
353   /**
354    * Set the background color i.e. the glClear color used at the beginning of each frame.
355    * @param[in] color The new background color.
356    */
357   void SetBackgroundColor(const Vector4& color);
358
359   /**
360    * Set the default surface rect.
361    * @param[in] rect The rect value representing the surface.
362    */
363   void SetDefaultSurfaceRect( const Rect<int>& rect );
364
365   /**
366    * @copydoc Dali::Stage::KeepRendering()
367    */
368   void KeepRendering( float durationSeconds );
369
370   /**
371    * Sets the depths of all layers.
372    * @param layers The layers in depth order.
373    * @param[in] systemLevel True if using the system-level overlay.
374    */
375   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
376
377 #ifdef DYNAMICS_SUPPORT
378
379   /**
380    * Initialize the dynamics world
381    * @param[in] world The dynamics world
382    * @param[in] worldSettings The dynamics world settings
383    * @param[in] debugShader The shader used for rendering dynamics debug information
384    */
385   void InitializeDynamicsWorld( DynamicsWorld* world, Integration::DynamicsWorldSettings* worldSettings );
386
387   /**
388    * Terminate the dynamics world
389    */
390   void TerminateDynamicsWorld();
391
392 #endif // DYNAMICS_SUPPORT
393
394 private:
395
396   // Undefined
397   UpdateManager(const UpdateManager&);
398
399   // Undefined
400   UpdateManager& operator=(const UpdateManager& rhs);
401
402   /**
403    * Helper to check whether the update-thread should keep going.
404    * @param[in] elapsedSeconds The time in seconds since the previous update.
405    * @return True if the update-thread should keep going.
406    */
407   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
408
409   /**
410    * Helper to calculate new camera setup when root node resizes.
411    * @param[in] updateBuffer The buffer to read the root node size from.
412    */
413   void UpdateProjectionAndViewMatrices(int updateBuffer);
414
415   /**
416    * Post process resources that have been updated by renderer
417    */
418   void PostProcessResources();
419
420   /**
421    * Helper to reset a Node properties.
422    * @param[in] node The node.
423    */
424   void ResetNodeProperty( Node& node );
425
426   /**
427    * Helper to reset all Node properties
428    */
429   void ResetProperties();
430
431   /**
432    * Perform gesture updates.
433    * @param[in]  lastVSyncTime  The last VSync time in milliseconds.
434    * @param[in]  nextVSyncTime  The estimated time of the next VSync in milliseconds.
435    * @return true, if any properties were updated.
436    */
437   bool ProcessGestures( unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
438
439   /**
440    * Perform animation updates
441    * @param[in] elapsedSeconds time since last frame
442    */
443   void Animate( float elapsedSeconds );
444
445   /**
446    * Perform constraint updates.
447    * @note Applies constraints to nodes first (depth first search order).
448    * Then shader constraints second (construction order)
449    */
450   void ApplyConstraints();
451
452   /**
453    * Perform property notification updates
454    */
455   void ProcessPropertyNotifications();
456
457   /**
458    * Update the default camera.
459    * This must be altered to match the root Node for 2D layouting.
460    * @param[in] updateBuffer The buffer to read the root node size from.
461    */
462   void UpdateDefaultCamera( int updateBuffer );
463
464   /**
465    * Update node shaders, opacity, geometry etc.
466    */
467   void UpdateNodes();
468
469 private:
470
471   // needs to be direct member so that getter for event buffer can be inlined
472   SceneGraphBuffers mSceneGraphBuffers;
473
474   struct Impl;
475   Impl* mImpl;
476
477 };
478
479 // Messages for UpdateManager
480
481 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
482 {
483   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
484
485   // Reserve some memory inside the message queue
486   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
487
488   // Construct message in the message queue memory; note that delete should not be called on the return value
489   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
490 }
491
492 inline void AddNodeMessage( UpdateManager& manager, Node& node )
493 {
494   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
495
496   // Reserve some memory inside the message queue
497   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
498
499   // Construct message in the message queue memory; note that delete should not be called on the return value
500   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
501 }
502
503 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild, int index )
504 {
505   // Update thread can edit the object
506   Node& parent = const_cast< Node& >( constParent );
507   Node& child = const_cast< Node& >( constChild );
508
509   typedef MessageValue3< UpdateManager, Node*, Node*, int > LocalType;
510
511   // Reserve some memory inside the message queue
512   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
513
514   // Construct message in the message queue memory; note that delete should not be called on the return value
515   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child, index );
516 }
517
518 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
519 {
520   // Scene graph thread can modify this object.
521   Node& node = const_cast< Node& >( constNode );
522
523   typedef MessageValue1< UpdateManager, Node* > LocalType;
524
525   // Reserve some memory inside the message queue
526   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
527
528   // Construct message in the message queue memory; note that delete should not be called on the return value
529   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
530 }
531
532 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
533 {
534   // Scene graph thread can destroy this object.
535   Node& node = const_cast< Node& >( constNode );
536
537   typedef MessageValue1< UpdateManager, Node* > LocalType;
538
539   // Reserve some memory inside the message queue
540   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
541
542   // Construct message in the message queue memory; note that delete should not be called on the return value
543   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
544 }
545
546 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
547 {
548   // Scene graph thread can modify this object.
549   Node& parent = const_cast< Node& >( constParent );
550
551   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
552
553   // Reserve some memory inside the message queue
554   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
555
556   // Construct message in the message queue memory; note that delete should not be called on the return value
557   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
558 }
559
560 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
561 {
562   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
563
564   // Reserve some memory inside the message queue
565   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
566
567   // Construct message in the message queue memory; note that delete should not be called on the return value
568   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
569 }
570
571 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
572 {
573   typedef MessageValue1< UpdateManager, PropertyOwner* > 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::RemoveObject, object );
580 }
581
582 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
583 {
584   typedef MessageValue1< UpdateManager, Animation* > LocalType;
585
586   // Reserve some memory inside the message queue
587   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
588
589   // Construct message in the message queue memory; note that delete should not be called on the return value
590   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
591 }
592
593 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
594 {
595   // The scene-graph thread owns this object so it can safely edit it.
596   Animation& animation = const_cast< Animation& >( constAnimation );
597
598   typedef MessageValue1< UpdateManager, Animation* > 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::StopAnimation, &animation );
605 }
606
607 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
608 {
609   // The scene-graph thread owns this object so it can safely edit it.
610   Animation& animation = const_cast< Animation& >( constAnimation );
611
612   typedef MessageValue1< UpdateManager, Animation* > 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::RemoveAnimation, &animation );
619 }
620
621 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
622 {
623   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
624
625   // Reserve some memory inside the message queue
626   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
627
628   // Construct message in the message queue memory; note that delete should not be called on the return value
629   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
630 }
631
632 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
633 {
634   // The scene-graph thread owns this object so it can safely edit it.
635   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
636
637   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
638
639   // Reserve some memory inside the message queue
640   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
641
642   // Construct message in the message queue memory; note that delete should not be called on the return value
643   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
644 }
645
646 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
647                                                       const PropertyNotification* constPropertyNotification,
648                                                       PropertyNotification::NotifyMode notifyMode )
649 {
650   // The scene-graph thread owns this object so it can safely edit it.
651   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
652
653   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
654
655   // Reserve some memory inside the message queue
656   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
657
658   // Construct message in the message queue memory; note that delete should not be called on the return value
659   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
660 }
661
662
663
664 // The render thread can safely change the Shader
665 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
666 {
667   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
668
669   // Reserve some memory inside the message queue
670   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
671
672   // Construct message in the message queue memory; note that delete should not be called on the return value
673   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
674 }
675
676 // The render thread can safely change the Shader
677 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
678 {
679   typedef MessageValue1< UpdateManager, Shader* > LocalType;
680
681   // Reserve some memory inside the message queue
682   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
683
684   // Construct message in the message queue memory; note that delete should not be called on the return value
685   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
686 }
687
688 inline void SetShaderProgramMessage( UpdateManager& manager,
689                                      Shader& shader,
690                                      GeometryType geometryType,
691                                      ShaderSubTypes subType,
692                                      Integration::ResourceId resourceId,
693                                      size_t shaderHash,
694                                      bool modifiesGeometry )
695 {
696   typedef MessageValue6< UpdateManager, Shader*, GeometryType, ShaderSubTypes, Integration::ResourceId, size_t, bool > 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::SetShaderProgram, &shader, geometryType, subType, resourceId, shaderHash, modifiesGeometry );
703 }
704
705 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
706 {
707   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
708
709   // Reserve some memory inside the message queue
710   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
711
712   // Construct message in the message queue memory; note that delete should not be called on the return value
713   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
714 }
715
716 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
717 {
718   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
719
720   // Reserve some memory inside the message queue
721   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
722
723   // Construct message in the message queue memory; note that delete should not be called on the return value
724   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
725 }
726
727 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
728 {
729   typedef MessageValue1< UpdateManager, float > LocalType;
730
731   // Reserve some memory inside the message queue
732   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
733
734   // Construct message in the message queue memory; note that delete should not be called on the return value
735   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
736 }
737
738 /**
739  * Create a message for setting the depth of a layer
740  * @param[in] manager The update manager
741  * @param[in] layers list of layers
742  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
743  */
744 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
745 {
746   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > 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::SetLayerDepths, layers, systemLevel );
753 }
754
755 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
756 {
757   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
758
759   // Reserve some memory inside the message queue
760   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
761
762   // Construct message in the message queue memory; note that delete should not be called on the return value
763   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
764 }
765
766 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
767 {
768   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
769
770   // Reserve some memory inside the message queue
771   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
772
773   // Construct message in the message queue memory; note that delete should not be called on the return value
774   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
775 }
776
777 #ifdef DYNAMICS_SUPPORT
778
779 // Dynamics messages
780 inline void InitializeDynamicsWorldMessage( UpdateManager& manager, DynamicsWorld* dynamicsworld, Integration::DynamicsWorldSettings* worldSettings )
781 {
782   typedef MessageValue2< UpdateManager, DynamicsWorld*, Integration::DynamicsWorldSettings* > LocalType;
783
784   // Reserve some memory inside the message queue
785   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
786
787   // Construct message in the message queue memory; note that delete should not be called on the return value
788   new (slot) LocalType( &manager, &UpdateManager::InitializeDynamicsWorld, dynamicsworld, worldSettings );
789 }
790
791 inline void TerminateDynamicsWorldMessage(UpdateManager& manager)
792 {
793   typedef Message< UpdateManager > LocalType;
794
795   // Reserve some memory inside the message queue
796   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
797
798   // Construct message in the message queue memory; note that delete should not be called on the return value
799   new (slot) LocalType( &manager, &UpdateManager::TerminateDynamicsWorld );
800 }
801
802 #endif // DYNAMICS_SUPPORT
803
804
805 template< typename T >
806 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
807 {
808   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
809
810   // Reserve some memory inside the message queue
811   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
812   // Construct message in the message queue memory; note that delete should not be called on the return value
813   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
814 }
815
816 template< typename T >
817 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
818 {
819   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
820
821   // Reserve some memory inside the message queue
822   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
823   // Construct message in the message queue memory; note that delete should not be called on the return value
824   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
825 }
826
827 } // namespace SceneGraph
828
829 } // namespace Internal
830
831 } // namespace Dali
832
833 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__