License conversion from Flora to Apache 2.0
[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    */
308   void SetShaderProgram( Shader* shader, GeometryType geometryType, ShaderSubTypes subType, Integration::ResourceId resourceId, size_t shaderHash );
309
310   /**
311    * Add an animatable mesh
312    * @param[in] animatableMesh The animatable mesh to add.
313    * @post the animatableMesh is owned by the UpdateManager.
314    */
315   void AddAnimatableMesh( AnimatableMesh* animatableMesh );
316
317   /**
318    * Remove an animatable mesh
319    * @pre The animatable mesh has been added to the update manager
320    * @param[in] animatableMesh The animatable mesh to add.
321    */
322   void RemoveAnimatableMesh( AnimatableMesh* animatableMesh );
323
324   /**
325    * Add a material
326    * @param[in] material The material to add
327    * @post the material remains owned by its event object
328    */
329   void AddMaterial(Material* material);
330
331   /**
332    * Remove a material
333    * @pre The material has been added to the UpdateManager
334    * @param[in] material The material to remove
335    */
336   void RemoveMaterial(Material* material);
337
338   /**
339    * Add a newly created gesture.
340    * @param[in] gesture The gesture to add.
341    * @post The gesture is owned by the UpdateManager.
342    */
343   void AddGesture( PanGesture* gesture );
344
345   /**
346    * Remove a gesture.
347    * @pre The gesture has been added to the UpdateManager.
348    * @param[in] gesture The gesture to remove.
349    * @post The gesture is destroyed.
350    */
351   void RemoveGesture( PanGesture* gesture );
352
353 public:
354
355   /**
356    * Performs an Update traversal on the scene-graph.
357    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
358    * @param[in] lastVSyncTime The last time, in milliseconds, that we had a VSync.
359    * @param[in] nextVSyncTime The estimated time, in milliseconds, of the next VSync.
360    * @return True if further updates are required e.g. during animations.
361    */
362   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTime, unsigned int nextVSyncTime );
363
364   /**
365    * Set the background color i.e. the glClear color used at the beginning of each frame.
366    * @param[in] color The new background color.
367    */
368   void SetBackgroundColor(const Vector4& color);
369
370   /**
371    * Set the default surface rect.
372    * @param[in] rect The rect value representing the surface.
373    */
374   void SetDefaultSurfaceRect( const Rect<int>& rect );
375
376   /**
377    * @copydoc Dali::Stage::KeepRendering()
378    */
379   void KeepRendering( float durationSeconds );
380
381   /**
382    * Sets the depths of all layers.
383    * @param layers The layers in depth order.
384    * @param[in] systemLevel True if using the system-level overlay.
385    */
386   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
387
388 #ifdef DYNAMICS_SUPPORT
389
390   /**
391    * Initialize the dynamics world
392    * @param[in] world The dynamics world
393    * @param[in] worldSettings The dynamics world settings
394    * @param[in] debugShader The shader used for rendering dynamics debug information
395    */
396   void InitializeDynamicsWorld( DynamicsWorld* world, Integration::DynamicsWorldSettings* worldSettings, Shader* debugShader );
397
398   /**
399    * Terminate the dynamics world
400    */
401   void TerminateDynamicsWorld();
402
403 #endif // DYNAMICS_SUPPORT
404
405 private:
406
407   // Undefined
408   UpdateManager(const UpdateManager&);
409
410   // Undefined
411   UpdateManager& operator=(const UpdateManager& rhs);
412
413   /**
414    * Helper to check whether the update-thread should keep going.
415    * @param[in] elapsedSeconds The time in seconds since the previous update.
416    * @return True if the update-thread should keep going.
417    */
418   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
419
420   /**
421    * Helper to calculate new camera setup when root node resizes.
422    * @param[in] updateBuffer The buffer to read the root node size from.
423    */
424   void UpdateProjectionAndViewMatrices(int updateBuffer);
425
426   /**
427    * Post process resources that have been updated by renderer
428    */
429   void PostProcessResources();
430
431   /**
432    * Helper to reset a Node properties.
433    * @param[in] node The node.
434    */
435   void ResetNodeProperty( Node& node );
436
437   /**
438    * Helper to reset all Node properties
439    */
440   void ResetProperties();
441
442   /**
443    * Perform gesture updates.
444    * @param[in]  lastVSyncTime  The last VSync time.
445    * @param[in]  nextVSyncTime  The estimated time of the next VSync.
446    * @return true, if any properties were updated.
447    */
448   bool ProcessGestures( unsigned int lastVSyncTime, unsigned int nextVSyncTime );
449
450   /**
451    * Perform animation updates
452    * @param[in] elapsedSeconds time since last frame
453    */
454   void Animate( float elapsedSeconds );
455
456   /**
457    * Perform constraint updates.
458    * @note Applies constraints to nodes first (depth first search order).
459    * Then shader constraints second (construction order)
460    */
461   void ApplyConstraints();
462
463   /**
464    * Perform property notification updates
465    */
466   void ProcessPropertyNotifications();
467
468   /**
469    * Update the default camera.
470    * This must be altered to match the root Node for 2D layouting.
471    * @param[in] updateBuffer The buffer to read the root node size from.
472    */
473   void UpdateDefaultCamera( int updateBuffer );
474
475   /**
476    * Update node shaders, opacity, geometry etc.
477    */
478   void UpdateNodes();
479
480   /**
481    * Update animatable meshes
482    */
483   void UpdateMeshes( BufferIndex updateBufferIndex, AnimatableMeshContainer& meshes );
484
485   /**
486    * Update materials - Ensure all render materials are updated with texture pointers
487    * when ready.
488    */
489   void UpdateMaterials( BufferIndex updateBufferIndex, MaterialContainer& materials );
490
491   /**
492    * PrepareMaterials - Ensure updated material properties are sent to render materials
493    */
494   void PrepareMaterials( BufferIndex updateBufferIndex, MaterialContainer& materials );
495
496 private:
497
498   // needs to be direct member so that getter for event buffer can be inlined
499   SceneGraphBuffers mSceneGraphBuffers;
500
501   struct Impl;
502   Impl* mImpl;
503
504 };
505
506 // Messages for UpdateManager
507
508 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
509 {
510   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
511
512   // Reserve some memory inside the message queue
513   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
514
515   // Construct message in the message queue memory; note that delete should not be called on the return value
516   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
517 }
518
519 inline void AddNodeMessage( UpdateManager& manager, Node& node )
520 {
521   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
522
523   // Reserve some memory inside the message queue
524   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
525
526   // Construct message in the message queue memory; note that delete should not be called on the return value
527   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
528 }
529
530 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
531 {
532   // Update thread can edit the object
533   Node& parent = const_cast< Node& >( constParent );
534   Node& child = const_cast< Node& >( constChild );
535
536   typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
537
538   // Reserve some memory inside the message queue
539   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
540
541   // Construct message in the message queue memory; note that delete should not be called on the return value
542   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
543 }
544
545 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
546 {
547   // Scene graph thread can modify this object.
548   Node& node = const_cast< Node& >( constNode );
549
550   typedef MessageValue1< UpdateManager, Node* > LocalType;
551
552   // Reserve some memory inside the message queue
553   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
554
555   // Construct message in the message queue memory; note that delete should not be called on the return value
556   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
557 }
558
559 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
560 {
561   // Scene graph thread can destroy this object.
562   Node& node = const_cast< Node& >( constNode );
563
564   typedef MessageValue1< UpdateManager, Node* > LocalType;
565
566   // Reserve some memory inside the message queue
567   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
568
569   // Construct message in the message queue memory; note that delete should not be called on the return value
570   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
571 }
572
573 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
574 {
575   // Scene graph thread can modify this object.
576   Node& parent = const_cast< Node& >( constParent );
577
578   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
579
580   // Reserve some memory inside the message queue
581   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
582
583   // Construct message in the message queue memory; note that delete should not be called on the return value
584   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
585 }
586
587 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
588 {
589   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
590
591   // Reserve some memory inside the message queue
592   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
593
594   // Construct message in the message queue memory; note that delete should not be called on the return value
595   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
596 }
597
598 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
599 {
600   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
601
602   // Reserve some memory inside the message queue
603   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
604
605   // Construct message in the message queue memory; note that delete should not be called on the return value
606   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
607 }
608
609 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
610 {
611   typedef MessageValue1< UpdateManager, Animation* > LocalType;
612
613   // Reserve some memory inside the message queue
614   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
615
616   // Construct message in the message queue memory; note that delete should not be called on the return value
617   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
618 }
619
620 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
621 {
622   // The scene-graph thread owns this object so it can safely edit it.
623   Animation& animation = const_cast< Animation& >( constAnimation );
624
625   typedef MessageValue1< UpdateManager, Animation* > LocalType;
626
627   // Reserve some memory inside the message queue
628   unsigned int* slot = manager.GetEventToUpdate().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::StopAnimation, &animation );
632 }
633
634 inline void RemoveAnimationMessage( 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.GetEventToUpdate().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::RemoveAnimation, &animation );
646 }
647
648 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
649 {
650   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
651
652   // Reserve some memory inside the message queue
653   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
654
655   // Construct message in the message queue memory; note that delete should not be called on the return value
656   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
657 }
658
659 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
660 {
661   // The scene-graph thread owns this object so it can safely edit it.
662   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
663
664   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
665
666   // Reserve some memory inside the message queue
667   unsigned int* slot = manager.GetEventToUpdate().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::RemovePropertyNotification, &propertyNotification );
671 }
672
673 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
674                                                       const PropertyNotification* constPropertyNotification,
675                                                       PropertyNotification::NotifyMode notifyMode )
676 {
677   // The scene-graph thread owns this object so it can safely edit it.
678   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
679
680   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
681
682   // Reserve some memory inside the message queue
683   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
684
685   // Construct message in the message queue memory; note that delete should not be called on the return value
686   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
687 }
688
689 // The render thread can safely change the Shader
690 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
691 {
692   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
693
694   // Reserve some memory inside the message queue
695   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
696
697   // Construct message in the message queue memory; note that delete should not be called on the return value
698   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
699 }
700
701 // The render thread can safely change the Shader
702 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
703 {
704   typedef MessageValue1< UpdateManager, Shader* > LocalType;
705
706   // Reserve some memory inside the message queue
707   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
708
709   // Construct message in the message queue memory; note that delete should not be called on the return value
710   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
711 }
712
713 inline void SetShaderProgramMessage( UpdateManager& manager,
714                                      Shader& shader,
715                                      GeometryType geometryType,
716                                      ShaderSubTypes subType,
717                                      Integration::ResourceId resourceId,
718                                      size_t shaderHash )
719 {
720   typedef MessageValue5< UpdateManager, Shader*, GeometryType, ShaderSubTypes, Integration::ResourceId, size_t > LocalType;
721
722   // Reserve some memory inside the message queue
723   unsigned int* slot = manager.GetEventToUpdate().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::SetShaderProgram, &shader, geometryType, subType, resourceId, shaderHash );
727 }
728
729 // The render thread can safely change the AnimatableMesh
730 inline void AddAnimatableMeshMessage( UpdateManager& manager, AnimatableMesh& animatableMesh )
731 {
732   typedef MessageValue1< UpdateManager, AnimatableMesh* > LocalType;
733
734   // Reserve some memory inside the message queue
735   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
736
737   // Construct message in the message queue memory; note that delete should not be called on the return value
738   new (slot) LocalType( &manager, &UpdateManager::AddAnimatableMesh, &animatableMesh );
739 }
740
741 // The render thread can safely change the AnimatableMesh
742 inline void RemoveAnimatableMeshMessage( UpdateManager& manager, AnimatableMesh& animatableMesh )
743 {
744   typedef MessageValue1< UpdateManager, AnimatableMesh* > LocalType;
745
746   // Reserve some memory inside the message queue
747   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
748
749   // Construct message in the message queue memory; note that delete should not be called on the return value
750   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimatableMesh, &animatableMesh );
751 }
752
753
754 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
755 {
756   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
757
758   // Reserve some memory inside the message queue
759   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
760
761   // Construct message in the message queue memory; note that delete should not be called on the return value
762   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
763 }
764
765 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
766 {
767   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
768
769   // Reserve some memory inside the message queue
770   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
771
772   // Construct message in the message queue memory; note that delete should not be called on the return value
773   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
774 }
775
776 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
777 {
778   typedef MessageValue1< UpdateManager, float > LocalType;
779
780   // Reserve some memory inside the message queue
781   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
782
783   // Construct message in the message queue memory; note that delete should not be called on the return value
784   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
785 }
786
787 /**
788  * Create a message for setting the depth of a layer
789  * @param[in] manager The update manager
790  * @param[in] layers list of layers
791  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
792  */
793 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
794 {
795   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
796
797   // Reserve some memory inside the message queue
798   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
799
800   // Construct message in the message queue memory; note that delete should not be called on the return value
801   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
802 }
803
804 inline void AddMaterialMessage( UpdateManager& manager, Material* material )
805 {
806   typedef MessageValue1< UpdateManager, Material* > LocalType;
807
808   // Reserve some memory inside the message queue
809   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
810
811   // Construct message in the message queue memory; note that delete should not be called on the return value
812   new (slot) LocalType( &manager, &UpdateManager::AddMaterial, material );
813 }
814
815 inline void RemoveMaterialMessage( UpdateManager& manager, Material* material )
816 {
817   typedef MessageValue1< UpdateManager, Material* > LocalType;
818
819   // Reserve some memory inside the message queue
820   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
821
822   // Construct message in the message queue memory; note that delete should not be called on the return value
823   new (slot) LocalType( &manager, &UpdateManager::RemoveMaterial, material );
824 }
825
826 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
827 {
828   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
829
830   // Reserve some memory inside the message queue
831   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
832
833   // Construct message in the message queue memory; note that delete should not be called on the return value
834   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
835 }
836
837 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
838 {
839   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
840
841   // Reserve some memory inside the message queue
842   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
843
844   // Construct message in the message queue memory; note that delete should not be called on the return value
845   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
846 }
847
848 #ifdef DYNAMICS_SUPPORT
849
850 // Dynamics messages
851 inline void InitializeDynamicsWorldMessage(UpdateManager& manager, DynamicsWorld* dynamicsworld, Integration::DynamicsWorldSettings* worldSettings, const Shader* debugShader)
852 {
853   typedef MessageValue3< UpdateManager, DynamicsWorld*, Integration::DynamicsWorldSettings*, Shader*> LocalType;
854
855   // Reserve some memory inside the message queue
856   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
857
858   // Construct message in the message queue memory; note that delete should not be called on the return value
859   new (slot) LocalType( &manager, &UpdateManager::InitializeDynamicsWorld, dynamicsworld, worldSettings, const_cast<Shader*>(debugShader) );
860 }
861
862 inline void TerminateDynamicsWorldMessage(UpdateManager& manager)
863 {
864   typedef Message< UpdateManager > LocalType;
865
866   // Reserve some memory inside the message queue
867   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
868
869   // Construct message in the message queue memory; note that delete should not be called on the return value
870   new (slot) LocalType( &manager, &UpdateManager::TerminateDynamicsWorld );
871 }
872
873 #endif // DYNAMICS_SUPPORT
874
875 } // namespace SceneGraph
876
877 } // namespace Internal
878
879 } // namespace Dali
880
881 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__