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