Created renderer objects.
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 #include <dali/integration-api/resource-declarations.h>
26
27 #include <dali/internal/common/message.h>
28 #include <dali/internal/common/event-to-update.h>
29 #include <dali/internal/common/type-abstraction-enums.h>
30
31 #include <dali/internal/update/animation/scene-graph-animation.h>
32 #include <dali/internal/update/common/scene-graph-buffers.h>
33 #include <dali/internal/update/common/scene-graph-property-notification.h>
34 #include <dali/internal/update/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 //@todo MESH_REWORK Move messages to a separate file to avoid having dependent headers
41 // pollute core & slow the build down.
42 #include <dali/internal/update/geometry/scene-graph-geometry.h>
43 #include <dali/internal/update/effects/scene-graph-material.h>
44
45
46 namespace Dali
47 {
48
49 namespace Integration
50 {
51 class GlSyncAbstraction;
52 class RenderController;
53 struct DynamicsWorldSettings;
54
55 } // namespace Integration
56
57 namespace Internal
58 {
59
60 class PropertyNotifier;
61 class EventToUpdate;
62 struct DynamicsWorldSettings;
63 class NotificationManager;
64 class CompleteNotificationInterface;
65 class ResourceManager;
66 class TouchResampler;
67
68 // value types used by messages
69 template <> struct ParameterType< PropertyNotification::NotifyMode >
70 : public BasicType< PropertyNotification::NotifyMode > {};
71
72 namespace SceneGraph
73 {
74
75 class Animation;
76 class DiscardQueue;
77 class PanGesture;
78 class RenderManager;
79 class RenderTaskList;
80 class RenderQueue;
81 class DynamicsWorld;
82 class TextureCache;
83
84 /**
85  * UpdateManager holds a scene graph i.e. a tree of nodes.
86  * It controls the Update traversal, in which nodes are repositioned/animated,
87  * and organizes the the culling and rendering of the scene.
88  */
89 class UpdateManager
90 {
91 public:
92
93   /**
94    * Construct a new UpdateManager.
95    * @param[in] notificationManager This should be notified when animations have finished.
96    * @param[in] glSyncAbstraction Used to determine when framebuffers are ready
97    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
98    * @param[in] propertyNotifier The PropertyNotifier
99    * @param[in] resourceManager The resource manager used to load textures etc.
100    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
101    * @param[in] controller After messages are flushed, we request a render from the RenderController.
102    * @param[in] renderManager This is responsible for rendering the results of each "update".
103    * @param[in] renderQueue Used to queue messages for the next render.
104    * @param[in] textureCache Used for caching textures.
105    * @param[in] touchResampler Used for re-sampling touch events.
106    */
107   UpdateManager( NotificationManager& notificationManager,
108                  Integration::GlSyncAbstraction& glSyncAbstraction,
109                  CompleteNotificationInterface& animationFinishedNotifier,
110                  PropertyNotifier& propertyNotifier,
111                  ResourceManager& resourceManager,
112                  DiscardQueue& discardQueue,
113                  Integration::RenderController& controller,
114                  RenderManager& renderManager,
115                  RenderQueue& renderQueue,
116                  TextureCache& textureCache,
117                  TouchResampler& touchResampler );
118
119   /**
120    * Destructor. Not virtual as this is not a base class
121    */
122   ~UpdateManager();
123
124   /**
125    * The event-thread uses this interface to queue messages for the next update.
126    * @return The event-to-update interface.
127    */
128   EventToUpdate& GetEventToUpdate();
129
130   /**
131    * @return the event buffer index
132    */
133   BufferIndex GetEventBufferIndex() const
134   {
135     // inlined as its called often
136     return mSceneGraphBuffers.GetEventBufferIndex();
137   }
138
139   // Node connection methods
140
141   /**
142    * Get the scene graph side list of RenderTasks.
143    * @param[in] systemLevel True if using the system-level overlay.
144    * @return The list of render tasks
145    */
146   RenderTaskList* GetRenderTaskList( bool systemLevel );
147
148   /**
149    * Installs a new layer as the root node.
150    * @pre The UpdateManager does not already have an installed root node.
151    * @pre The layer is of derived Node type Layer.
152    * @pre The layer does not have a parent.
153    * @param[in] layer The new root node.
154    * @param[in] systemLevel True if using the system-level overlay.
155    * @post The node is owned by UpdateManager.
156    */
157   void InstallRoot( Layer* layer, bool systemLevel );
158
159   /**
160    * Add a Node; UpdateManager takes ownership.
161    * @pre The node does not have a parent.
162    * @param[in] node The node to add.
163    */
164   void AddNode( Node* node );
165
166   /**
167    * Connect a Node to the scene-graph.
168    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
169    * @pre The node does not already have a parent.
170    * @param[in] node The new parent node.
171    * @param[in] node The node to connect.
172    */
173   void ConnectNode( Node* parent, Node* node, int index );
174
175   /**
176    * Disconnect a Node from the scene-graph.
177    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
178    * @pre The node has a parent.
179    * @param[in] node The node to disconnect.
180    */
181   void DisconnectNode( Node* node );
182
183   /**
184    * Called when a property is set on a disconnected Node (via public API)
185    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
186    * @pre The node does not have a parent.
187    * @param[in] node The node to set as "active".
188    */
189   void SetNodeActive( Node* node );
190
191   /**
192    * Destroy a Node owned by UpdateManager.
193    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
194    * In the following update, the previously queued Nodes may be deleted.
195    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
196    * @param[in] node The node to destroy.
197    */
198   void DestroyNode( Node* node );
199
200   /**
201    * Attach an object to a Node.
202    * The UpdateManager is responsible for calling NodeAttachment::Initialize().
203    * @param[in] node The node which will own the attachment.
204    * @param[in] attachment The object to attach.
205    */
206   void AttachToNode( Node* node, NodeAttachment* attachment );
207
208   /**
209    * Add a newly created object.
210    * @param[in] object The object to add.
211    * @post The object is owned by UpdateManager.
212    */
213   void AddObject( PropertyOwner* object );
214
215   /**
216    * Remove an object.
217    * @param[in] object The object to remove.
218    */
219   void RemoveObject( PropertyOwner* object );
220
221   // Animations
222
223   /**
224    * Add a newly created animation.
225    * @param[in] animation The animation to add.
226    * @post The animation is owned by UpdateManager.
227    */
228   void AddAnimation( Animation* animation );
229
230   /**
231    * Stop an animation.
232    * @param[in] animation The animation to stop.
233    */
234   void StopAnimation( Animation* animation );
235
236   /**
237    * Remove an animation.
238    * @param[in] animation The animation to remove.
239    */
240   void RemoveAnimation( Animation* animation );
241
242   /**
243    * Query whether any animations are currently running.
244    * @return True if any animations are running.
245    */
246   bool IsAnimationRunning() const;
247
248   // Property Notification
249
250   /**
251    * Add a newly created property notification
252    * @param[in] propertyNotification The notification to add
253    * @post The propertyNotification is owned by UpdateManager.
254    */
255   void AddPropertyNotification( PropertyNotification* propertyNotification );
256
257   /**
258    * Remove a property notification
259    * @param[in] propertyNotification The notification to remove
260    */
261   void RemovePropertyNotification( PropertyNotification* propertyNotification );
262
263   /**
264    * Set Notify state for PropertyNotification
265    * @param[in] propertyNotification The notification to remove
266    * @param[in] notifyMode The notification mode.
267    */
268   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
269
270
271   /**
272    * Add a geometry to the scene graph
273    * @param[in] geometry The geometry to add
274    */
275   void AddGeometry( Geometry* geometry );
276
277   /**
278    * Remove a geometry from the scene graph
279    * @param[in] geometry The geometry to remove
280    */
281   void RemoveGeometry( Geometry* geometry );
282
283   /**
284    * Add a material to the scene graph
285    * @param[in] material The material to add
286    */
287   void AddMaterial( Material* material );
288
289   /**
290    * Remove a material from the scene graph
291    * @param[in] material The material to remove
292    */
293   void RemoveMaterial( Material* material );
294
295   // Shaders
296
297   /**
298    * Add a newly created shader.
299    * @param[in] shader The shader to add.
300    * @post The shader is owned by the UpdateManager.
301    */
302   void AddShader(Shader* shader);
303
304   /**
305    * Remove a shader.
306    * @pre The shader has been added to the UpdateManager.
307    * @param[in] shader The shader to remove.
308    * @post The shader is destroyed.
309    */
310   void RemoveShader(Shader* shader);
311
312   /**
313    * Set the shader program for a specified GeometryType to a Shader object
314    * @param[in] shader        The shader to modify
315    * @param[in] geometryType  The GeometryType to map to the program
316    * @param[in] subType       The program subtype
317    * @param[in] resourceId    A ResourceManager ticket ID for the program data (source and compiled binary)
318    * @param[in] shaderHash    hash key created with vertex and fragment shader code
319    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
320    */
321   void SetShaderProgram( Shader* shader, GeometryType geometryType, ShaderSubTypes subType, Integration::ResourceId resourceId, size_t shaderHash, bool modifiesGeometry );
322
323   /**
324    * Add a newly created gesture.
325    * @param[in] gesture The gesture to add.
326    * @post The gesture is owned by the UpdateManager.
327    */
328   void AddGesture( PanGesture* gesture );
329
330   /**
331    * Remove a gesture.
332    * @pre The gesture has been added to the UpdateManager.
333    * @param[in] gesture The gesture to remove.
334    * @post The gesture is destroyed.
335    */
336   void RemoveGesture( PanGesture* gesture );
337
338 public:
339
340   /**
341    * Performs an Update traversal on the scene-graph.
342    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
343    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
344    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
345    * @return True if further updates are required e.g. during animations.
346    */
347   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
348
349   /**
350    * Set the background color i.e. the glClear color used at the beginning of each frame.
351    * @param[in] color The new background color.
352    */
353   void SetBackgroundColor(const Vector4& color);
354
355   /**
356    * Set the default surface rect.
357    * @param[in] rect The rect value representing the surface.
358    */
359   void SetDefaultSurfaceRect( const Rect<int>& rect );
360
361   /**
362    * @copydoc Dali::Stage::KeepRendering()
363    */
364   void KeepRendering( float durationSeconds );
365
366   /**
367    * Sets the depths of all layers.
368    * @param layers The layers in depth order.
369    * @param[in] systemLevel True if using the system-level overlay.
370    */
371   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
372
373 #ifdef DYNAMICS_SUPPORT
374
375   /**
376    * Initialize the dynamics world
377    * @param[in] world The dynamics world
378    * @param[in] worldSettings The dynamics world settings
379    * @param[in] debugShader The shader used for rendering dynamics debug information
380    */
381   void InitializeDynamicsWorld( DynamicsWorld* world, Integration::DynamicsWorldSettings* worldSettings );
382
383   /**
384    * Terminate the dynamics world
385    */
386   void TerminateDynamicsWorld();
387
388 #endif // DYNAMICS_SUPPORT
389
390 private:
391
392   // Undefined
393   UpdateManager(const UpdateManager&);
394
395   // Undefined
396   UpdateManager& operator=(const UpdateManager& rhs);
397
398   /**
399    * Helper to check whether the update-thread should keep going.
400    * @param[in] elapsedSeconds The time in seconds since the previous update.
401    * @return True if the update-thread should keep going.
402    */
403   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
404
405   /**
406    * Helper to calculate new camera setup when root node resizes.
407    * @param[in] updateBuffer The buffer to read the root node size from.
408    */
409   void UpdateProjectionAndViewMatrices(int updateBuffer);
410
411   /**
412    * Post process resources that have been updated by renderer
413    */
414   void PostProcessResources();
415
416   /**
417    * Helper to reset a Node properties.
418    * @param[in] node The node.
419    */
420   void ResetNodeProperty( Node& node );
421
422   /**
423    * Helper to reset all Node properties
424    */
425   void ResetProperties();
426
427   /**
428    * Perform gesture updates.
429    * @param[in]  lastVSyncTime  The last VSync time in milliseconds.
430    * @param[in]  nextVSyncTime  The estimated time of the next VSync in milliseconds.
431    * @return true, if any properties were updated.
432    */
433   bool ProcessGestures( unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
434
435   /**
436    * Perform animation updates
437    * @param[in] elapsedSeconds time since last frame
438    */
439   void Animate( float elapsedSeconds );
440
441   /**
442    * Perform constraint updates.
443    * @note Applies constraints to nodes first (depth first search order).
444    * Then shader constraints second (construction order)
445    */
446   void ApplyConstraints();
447
448   /**
449    * Perform property notification updates
450    */
451   void ProcessPropertyNotifications();
452
453   /**
454    * Update the default camera.
455    * This must be altered to match the root Node for 2D layouting.
456    * @param[in] updateBuffer The buffer to read the root node size from.
457    */
458   void UpdateDefaultCamera( int updateBuffer );
459
460   /**
461    * Update node shaders, opacity, geometry etc.
462    */
463   void UpdateNodes();
464
465 private:
466
467   // needs to be direct member so that getter for event buffer can be inlined
468   SceneGraphBuffers mSceneGraphBuffers;
469
470   struct Impl;
471   Impl* mImpl;
472
473 };
474
475 // Messages for UpdateManager
476
477 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
478 {
479   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
480
481   // Reserve some memory inside the message queue
482   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
483
484   // Construct message in the message queue memory; note that delete should not be called on the return value
485   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
486 }
487
488 inline void AddNodeMessage( UpdateManager& manager, Node& node )
489 {
490   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
491
492   // Reserve some memory inside the message queue
493   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
494
495   // Construct message in the message queue memory; note that delete should not be called on the return value
496   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
497 }
498
499 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild, int index )
500 {
501   // Update thread can edit the object
502   Node& parent = const_cast< Node& >( constParent );
503   Node& child = const_cast< Node& >( constChild );
504
505   typedef MessageValue3< UpdateManager, Node*, Node*, int > LocalType;
506
507   // Reserve some memory inside the message queue
508   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
509
510   // Construct message in the message queue memory; note that delete should not be called on the return value
511   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child, index );
512 }
513
514 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
515 {
516   // Scene graph thread can modify this object.
517   Node& node = const_cast< Node& >( constNode );
518
519   typedef MessageValue1< UpdateManager, Node* > LocalType;
520
521   // Reserve some memory inside the message queue
522   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
523
524   // Construct message in the message queue memory; note that delete should not be called on the return value
525   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
526 }
527
528 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
529 {
530   // Scene graph thread can destroy this object.
531   Node& node = const_cast< Node& >( constNode );
532
533   typedef MessageValue1< UpdateManager, Node* > LocalType;
534
535   // Reserve some memory inside the message queue
536   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
537
538   // Construct message in the message queue memory; note that delete should not be called on the return value
539   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
540 }
541
542 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
543 {
544   // Scene graph thread can modify this object.
545   Node& parent = const_cast< Node& >( constParent );
546
547   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
548
549   // Reserve some memory inside the message queue
550   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
551
552   // Construct message in the message queue memory; note that delete should not be called on the return value
553   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
554 }
555
556 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
557 {
558   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
559
560   // Reserve some memory inside the message queue
561   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
562
563   // Construct message in the message queue memory; note that delete should not be called on the return value
564   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
565 }
566
567 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
568 {
569   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
570
571   // Reserve some memory inside the message queue
572   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
573
574   // Construct message in the message queue memory; note that delete should not be called on the return value
575   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
576 }
577
578 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
579 {
580   typedef MessageValue1< UpdateManager, Animation* > LocalType;
581
582   // Reserve some memory inside the message queue
583   unsigned int* slot = manager.GetEventToUpdate().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::AddAnimation, animation );
587 }
588
589 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
590 {
591   // The scene-graph thread owns this object so it can safely edit it.
592   Animation& animation = const_cast< Animation& >( constAnimation );
593
594   typedef MessageValue1< UpdateManager, Animation* > LocalType;
595
596   // Reserve some memory inside the message queue
597   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
598
599   // Construct message in the message queue memory; note that delete should not be called on the return value
600   new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
601 }
602
603 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
604 {
605   // The scene-graph thread owns this object so it can safely edit it.
606   Animation& animation = const_cast< Animation& >( constAnimation );
607
608   typedef MessageValue1< UpdateManager, Animation* > LocalType;
609
610   // Reserve some memory inside the message queue
611   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
612
613   // Construct message in the message queue memory; note that delete should not be called on the return value
614   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
615 }
616
617 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
618 {
619   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
620
621   // Reserve some memory inside the message queue
622   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
623
624   // Construct message in the message queue memory; note that delete should not be called on the return value
625   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
626 }
627
628 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
629 {
630   // The scene-graph thread owns this object so it can safely edit it.
631   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
632
633   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
634
635   // Reserve some memory inside the message queue
636   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
637
638   // Construct message in the message queue memory; note that delete should not be called on the return value
639   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
640 }
641
642 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
643                                                       const PropertyNotification* constPropertyNotification,
644                                                       PropertyNotification::NotifyMode notifyMode )
645 {
646   // The scene-graph thread owns this object so it can safely edit it.
647   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
648
649   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
650
651   // Reserve some memory inside the message queue
652   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
653
654   // Construct message in the message queue memory; note that delete should not be called on the return value
655   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
656 }
657
658 inline void AddGeometryMessage( UpdateManager& manager, Geometry& geometry )
659 {
660   typedef MessageValue1< UpdateManager, OwnerPointer< Geometry > > LocalType;
661
662   // Reserve some memory inside the message queue
663   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
664
665   // Construct message in the message queue memory; note that delete should not be called on the return value
666   new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
667 }
668
669 // The render thread can safely change the Geometry
670 inline void RemoveGeometryMessage( UpdateManager& manager, Geometry& geometry )
671 {
672   typedef MessageValue1< UpdateManager, Geometry* > LocalType;
673
674   // Reserve some memory inside the message queue
675   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
676
677   // Construct message in the message queue memory; note that delete should not be called on the return value
678   new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
679 }
680
681 inline void AddMaterialMessage( UpdateManager& manager, Material& material )
682 {
683   typedef MessageValue1< UpdateManager, OwnerPointer< Material > > LocalType;
684
685   // Reserve some memory inside the message queue
686   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
687
688   // Construct message in the message queue memory; note that delete should not be called on the return value
689   new (slot) LocalType( &manager, &UpdateManager::AddMaterial, &material );
690 }
691
692 // The render thread can safely change the Material
693 inline void RemoveMaterialMessage( UpdateManager& manager, Material& material )
694 {
695   typedef MessageValue1< UpdateManager, Material* > LocalType;
696
697   // Reserve some memory inside the message queue
698   unsigned int* slot = manager.GetEventToUpdate().ReserveMessageSlot( sizeof( LocalType ) );
699
700   // Construct message in the message queue memory; note that delete should not be called on the return value
701   new (slot) LocalType( &manager, &UpdateManager::RemoveMaterial, &material );
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.GetEventToUpdate().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.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::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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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.GetEventToUpdate().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 } // namespace SceneGraph
846
847 } // namespace Internal
848
849 } // namespace Dali
850
851 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__