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