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