Merge branch devel/master (1.0.49) into tizen
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/common/dali-common.h>
24
25 #include <dali/integration-api/resource-declarations.h>
26
27 #include <dali/internal/common/message.h>
28 #include <dali/internal/common/type-abstraction-enums.h>
29 #include <dali/internal/common/shader-saver.h>
30 #include <dali/internal/event/common/event-thread-services.h>
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/manager/object-owner-container.h>
35 #include <dali/internal/update/node-attachments/node-attachment.h>
36 #include <dali/internal/update/nodes/node.h>
37 #include <dali/internal/update/nodes/scene-graph-layer.h>
38
39 #include <dali/internal/render/shaders/scene-graph-shader.h>
40
41 namespace Dali
42 {
43
44 namespace Integration
45 {
46 class GlSyncAbstraction;
47 class RenderController;
48
49 } // namespace Integration
50
51 namespace Internal
52 {
53
54 class PropertyNotifier;
55 class NotificationManager;
56 class CompleteNotificationInterface;
57 class ResourceManager;
58 class TouchResampler;
59
60 // value types used by messages
61 template <> struct ParameterType< PropertyNotification::NotifyMode >
62 : public BasicType< PropertyNotification::NotifyMode > {};
63
64 namespace SceneGraph
65 {
66
67 class Animation;
68 class DiscardQueue;
69 class PanGesture;
70 class RenderManager;
71 class RenderTaskList;
72 class RenderQueue;
73 class TextureCache;
74 class Geometry;
75 class PropertyBuffer;
76 class Material;
77 class Sampler;
78 class RendererAttachment;
79
80 /**
81  * UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
82  * other property owner objects.
83  * It controls the Update traversal, in which nodes are repositioned/animated,
84  * and organizes the the culling and rendering of the scene.
85  * It also maintains the lifecycle of nodes and other property owners that are
86  * disconnected from the scene graph.
87  */
88 class UpdateManager : public ShaderSaver
89 {
90 public:
91
92   /**
93    * Construct a new UpdateManager.
94    * @param[in] notificationManager This should be notified when animations have finished.
95    * @param[in] glSyncAbstraction Used to determine when framebuffers are ready
96    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
97    * @param[in] propertyNotifier The PropertyNotifier
98    * @param[in] resourceManager The resource manager used to load textures etc.
99    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
100    * @param[in] controller After messages are flushed, we request a render from the RenderController.
101    * @param[in] renderManager This is responsible for rendering the results of each "update".
102    * @param[in] renderQueue Used to queue messages for the next render.
103    * @param[in] textureCache Used for caching textures.
104    * @param[in] touchResampler Used for re-sampling touch events.
105    */
106   UpdateManager( NotificationManager& notificationManager,
107                  Integration::GlSyncAbstraction& glSyncAbstraction,
108                  CompleteNotificationInterface& animationFinishedNotifier,
109                  PropertyNotifier& propertyNotifier,
110                  ResourceManager& resourceManager,
111                  DiscardQueue& discardQueue,
112                  Integration::RenderController& controller,
113                  RenderManager& renderManager,
114                  RenderQueue& renderQueue,
115                  TextureCache& textureCache,
116                  TouchResampler& touchResampler );
117
118   /**
119    * Destructor.
120    */
121   virtual ~UpdateManager();
122
123   // Node connection methods
124
125   /**
126    * Get the scene graph side list of RenderTasks.
127    * @param[in] systemLevel True if using the system-level overlay.
128    * @return The list of render tasks
129    */
130   RenderTaskList* GetRenderTaskList( bool systemLevel );
131
132   /**
133    * Installs a new layer as the root node.
134    * @pre The UpdateManager does not already have an installed root node.
135    * @pre The layer is of derived Node type Layer.
136    * @pre The layer does not have a parent.
137    * @param[in] layer The new root node.
138    * @param[in] systemLevel True if using the system-level overlay.
139    * @post The node is owned by UpdateManager.
140    */
141   void InstallRoot( Layer* layer, bool systemLevel );
142
143   /**
144    * Add a Node; UpdateManager takes ownership.
145    * @pre The node does not have a parent.
146    * @param[in] node The node to add.
147    */
148   void AddNode( Node* node );
149
150   /**
151    * Connect a Node to the scene-graph.
152    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
153    * @pre The node does not already have a parent.
154    * @param[in] node The new parent node.
155    * @param[in] node The node to connect.
156    */
157   void ConnectNode( Node* parent, Node* node, int index );
158
159   /**
160    * Disconnect a Node from the scene-graph.
161    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
162    * @pre The node has a parent.
163    * @param[in] node The node to disconnect.
164    */
165   void DisconnectNode( Node* node );
166
167   /**
168    * Called when a property is set on a disconnected Node (via public API)
169    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
170    * @pre The node does not have a parent.
171    * @param[in] node The node to set as "active".
172    */
173   void SetNodeActive( Node* node );
174
175   /**
176    * Destroy a Node owned by UpdateManager.
177    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
178    * In the following update, the previously queued Nodes may be deleted.
179    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
180    * @param[in] node The node to destroy.
181    */
182   void DestroyNode( Node* node );
183
184   /**
185    * Attach an object to a Node.
186    * The UpdateManager is responsible for calling NodeAttachment::Initialize().
187    * @param[in] node The node which will own the attachment.
188    * @param[in] attachment The object to attach.
189    */
190   void AttachToNode( Node* node, NodeAttachment* attachment );
191
192   /**
193    * Attach a renderer to the scene graph
194    */
195   void AttachToSceneGraph( RendererAttachment* renderer );
196
197
198   /**
199    * Add a newly created object.
200    * @param[in] object The object to add.
201    * @post The object is owned by UpdateManager.
202    */
203   void AddObject( PropertyOwner* object );
204
205   /**
206    * Remove an object.
207    * @param[in] object The object to remove.
208    */
209   void RemoveObject( PropertyOwner* object );
210
211   // Animations
212
213   /**
214    * Add a newly created animation.
215    * @param[in] animation The animation to add.
216    * @post The animation is owned by UpdateManager.
217    */
218   void AddAnimation( Animation* animation );
219
220   /**
221    * Stop an animation.
222    * @param[in] animation The animation to stop.
223    */
224   void StopAnimation( Animation* animation );
225
226   /**
227    * Remove an animation.
228    * @param[in] animation The animation to remove.
229    */
230   void RemoveAnimation( Animation* animation );
231
232   /**
233    * Query whether any animations are currently running.
234    * @return True if any animations are running.
235    */
236   bool IsAnimationRunning() const;
237
238   // Property Notification
239
240   /**
241    * Add a newly created property notification
242    * @param[in] propertyNotification The notification to add
243    * @post The propertyNotification is owned by UpdateManager.
244    */
245   void AddPropertyNotification( PropertyNotification* propertyNotification );
246
247   /**
248    * Remove a property notification
249    * @param[in] propertyNotification The notification to remove
250    */
251   void RemovePropertyNotification( PropertyNotification* propertyNotification );
252
253   /**
254    * Set Notify state for PropertyNotification
255    * @param[in] propertyNotification The notification to remove
256    * @param[in] notifyMode The notification mode.
257    */
258   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
259
260   /**
261    * @brief Get the geometry owner
262    *
263    * @return The geometry owner
264    */
265   ObjectOwnerContainer< Geometry >& GetGeometryOwner();
266
267   /**
268    * @brief Get the material owner
269    *
270    * @return The material owner
271    */
272   ObjectOwnerContainer< Material >& GetMaterialOwner();
273
274   /**
275    * @brief Get the sampler owner
276    *
277    * @return The sampler owner
278    */
279   ObjectOwnerContainer< Sampler >& GetSamplerOwner();
280
281   /**
282    * @brief Get the property buffer owner
283    *
284    * @return The property buffer owner
285    */
286   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
287
288
289   // Shaders
290
291   /**
292    * Add a newly created shader.
293    * @param[in] shader The shader to add.
294    * @post The shader is owned by the UpdateManager.
295    */
296   void AddShader(Shader* shader);
297
298   /**
299    * Remove a shader.
300    * @pre The shader has been added to the UpdateManager.
301    * @param[in] shader The shader to remove.
302    * @post The shader is destroyed.
303    */
304   void RemoveShader(Shader* shader);
305
306   /**
307    * Set the shader program for a Shader object
308    * @param[in] shader        The shader to modify
309    * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
310    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
311    */
312   void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
313
314   /**
315    * @brief Accept compiled shaders passed back on render thread for saving.
316    * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
317    */
318   virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
319
320   /**
321    * @brief Set the destination for compiled shader binaries to be passed on to.
322    * The dispatcher passed in will be called from the update thread.
323    * @param[in] upstream A sink for ShaderDatas to be passed into.
324    */
325   void SetShaderSaver( ShaderSaver& upstream );
326
327   // Gestures
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 // Message queue handling
345
346   /**
347    * Reserve space for another message in the queue; this must then be initialized by the caller.
348    * The message will be read from the update-thread after the next FlushMessages is called.
349    * @post Calling this method may invalidate any previously returned slots.
350    * @param[in] size The message size with respect to the size of type "char".
351    * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
352    * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
353    * @return A pointer to the first char allocated for the message.
354    */
355   unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
356
357   /**
358    * @return the current event-buffer index.
359    */
360   BufferIndex GetEventBufferIndex() const
361   {
362     // inlined as its called often from event thread
363     return mSceneGraphBuffers.GetEventBufferIndex();
364   }
365
366   /**
367    * Called by the event-thread to signal that FlushQueue will be called
368    * e.g. when it has finished event processing.
369    */
370   void EventProcessingStarted();
371
372   /**
373    * Flush the set of messages, which were previously stored with QueueMessage().
374    * Calls to this thread-safe method should be minimized, to avoid thread blocking.
375    *
376    * @return True if there are messages to process.
377    */
378   bool FlushQueue();
379
380 public:
381
382   /**
383    * Performs an Update traversal on the scene-graph.
384    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
385    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
386    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
387    * @return True if further updates are required e.g. during animations.
388    */
389   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
390
391   /**
392    * Set the background color i.e. the glClear color used at the beginning of each frame.
393    * @param[in] color The new background color.
394    */
395   void SetBackgroundColor(const Vector4& color);
396
397   /**
398    * Set the default surface rect.
399    * @param[in] rect The rect value representing the surface.
400    */
401   void SetDefaultSurfaceRect( const Rect<int>& rect );
402
403   /**
404    * @copydoc Dali::Stage::KeepRendering()
405    */
406   void KeepRendering( float durationSeconds );
407
408   /**
409    * Sets the depths of all layers.
410    * @param layers The layers in depth order.
411    * @param[in] systemLevel True if using the system-level overlay.
412    */
413   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
414
415 private:
416
417   // Undefined
418   UpdateManager(const UpdateManager&);
419
420   // Undefined
421   UpdateManager& operator=(const UpdateManager& rhs);
422
423   /**
424    * Helper to check whether the update-thread should keep going.
425    * @param[in] elapsedSeconds The time in seconds since the previous update.
426    * @return True if the update-thread should keep going.
427    */
428   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
429
430   /**
431    * Helper to calculate new camera setup when root node resizes.
432    * @param[in] updateBuffer The buffer to read the root node size from.
433    */
434   void UpdateProjectionAndViewMatrices(int updateBuffer);
435
436   /**
437    * Post process resources that have been updated by renderer
438    */
439   void PostProcessResources();
440
441   /**
442    * Helper to reset a Node properties.
443    * @param[in] node The node.
444    */
445   void ResetNodeProperty( Node& node );
446
447   /**
448    * Helper to reset all Node properties
449    */
450   void ResetProperties();
451
452   /**
453    * Perform gesture updates.
454    * @param[in]  lastVSyncTime  The last VSync time in milliseconds.
455    * @param[in]  nextVSyncTime  The estimated time of the next VSync in milliseconds.
456    * @return true, if any properties were updated.
457    */
458   bool ProcessGestures( unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
459
460   /**
461    * Perform animation updates
462    * @param[in] elapsedSeconds time since last frame
463    */
464   void Animate( float elapsedSeconds );
465
466   /**
467    * Perform constraint updates.
468    * @note Applies constraints to nodes first (depth first search order).
469    * Then shader constraints second (construction order)
470    */
471   void ApplyConstraints();
472
473   /**
474    * Perform property notification updates
475    */
476   void ProcessPropertyNotifications();
477
478   /**
479    * Pass shader binaries queued here on to event thread.
480    */
481   void ForwardCompiledShadersToEventThread();
482
483   /**
484    * Update the default camera.
485    * This must be altered to match the root Node for 2D layouting.
486    * @param[in] updateBuffer The buffer to read the root node size from.
487    */
488   void UpdateDefaultCamera( int updateBuffer );
489
490   /**
491    * Update node shaders, opacity, geometry etc.
492    */
493   void UpdateNodes();
494
495 private:
496
497   // needs to be direct member so that getter for event buffer can be inlined
498   SceneGraphBuffers mSceneGraphBuffers;
499
500   struct Impl;
501   Impl* mImpl;
502
503 };
504
505 // Messages for UpdateManager
506
507 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
508 {
509   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
510
511   // Reserve some memory inside the message queue
512   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
513
514   // Construct message in the message queue memory; note that delete should not be called on the return value
515   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
516 }
517
518 inline void AddNodeMessage( UpdateManager& manager, Node& node )
519 {
520   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
521
522   // Reserve some memory inside the message queue
523   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
524
525   // Construct message in the message queue memory; note that delete should not be called on the return value
526   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
527 }
528
529 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild, int index )
530 {
531   // Update thread can edit the object
532   Node& parent = const_cast< Node& >( constParent );
533   Node& child = const_cast< Node& >( constChild );
534
535   typedef MessageValue3< UpdateManager, Node*, Node*, int > LocalType;
536
537   // Reserve some memory inside the message queue
538   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
539
540   // Construct message in the message queue memory; note that delete should not be called on the return value
541   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child, index );
542 }
543
544 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
545 {
546   // Scene graph thread can modify this object.
547   Node& node = const_cast< Node& >( constNode );
548
549   typedef MessageValue1< UpdateManager, Node* > LocalType;
550
551   // Reserve some memory inside the message queue
552   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
553
554   // Construct message in the message queue memory; note that delete should not be called on the return value
555   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
556 }
557
558 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
559 {
560   // Scene graph thread can destroy this object.
561   Node& node = const_cast< Node& >( constNode );
562
563   typedef MessageValue1< UpdateManager, Node* > LocalType;
564
565   // Reserve some memory inside the message queue
566   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
567
568   // Construct message in the message queue memory; note that delete should not be called on the return value
569   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
570 }
571
572 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
573 {
574   // Scene graph thread can modify this object.
575   Node& parent = const_cast< Node& >( constParent );
576
577   // @todo MESH_REWORK Don't pass by owner pointer after merge with SceneGraph::RenderableAttachment ? (not needed if we split RendererAttachment to 2 objects)
578   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
579
580   // Reserve some memory inside the message queue
581   unsigned int* slot = manager.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 AttachToSceneGraphMessage( UpdateManager& manager, RendererAttachment* renderer )
588 {
589   // @todo MESH_REWORK Pass by owner pointer after merge with SceneGraph::RenderableAttachment
590   typedef MessageValue1< UpdateManager, RendererAttachment* > LocalType;
591
592   // Reserve some memory inside the message queue
593   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
594
595   // Construct message in the message queue memory; note that delete should not be called on the return value
596   new (slot) LocalType( &manager, &UpdateManager::AttachToSceneGraph, renderer );
597 }
598
599 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
600 {
601   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
602
603   // Reserve some memory inside the message queue
604   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
605
606   // Construct message in the message queue memory; note that delete should not be called on the return value
607   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
608 }
609
610 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
611 {
612   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
613
614   // Reserve some memory inside the message queue
615   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
616
617   // Construct message in the message queue memory; note that delete should not be called on the return value
618   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
619 }
620
621 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
622 {
623   typedef MessageValue1< UpdateManager, Animation* > LocalType;
624
625   // Reserve some memory inside the message queue
626   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
627
628   // Construct message in the message queue memory; note that delete should not be called on the return value
629   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
630 }
631
632 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
633 {
634   // The scene-graph thread owns this object so it can safely edit it.
635   Animation& animation = const_cast< Animation& >( constAnimation );
636
637   typedef MessageValue1< UpdateManager, Animation* > LocalType;
638
639   // Reserve some memory inside the message queue
640   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
641
642   // Construct message in the message queue memory; note that delete should not be called on the return value
643   new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
644 }
645
646 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
647 {
648   // The scene-graph thread owns this object so it can safely edit it.
649   Animation& animation = const_cast< Animation& >( constAnimation );
650
651   typedef MessageValue1< UpdateManager, Animation* > LocalType;
652
653   // Reserve some memory inside the message queue
654   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
655
656   // Construct message in the message queue memory; note that delete should not be called on the return value
657   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
658 }
659
660 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
661 {
662   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
663
664   // Reserve some memory inside the message queue
665   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
666
667   // Construct message in the message queue memory; note that delete should not be called on the return value
668   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
669 }
670
671 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
672 {
673   // The scene-graph thread owns this object so it can safely edit it.
674   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
675
676   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
677
678   // Reserve some memory inside the message queue
679   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
680
681   // Construct message in the message queue memory; note that delete should not be called on the return value
682   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
683 }
684
685 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
686                                                       const PropertyNotification* constPropertyNotification,
687                                                       PropertyNotification::NotifyMode notifyMode )
688 {
689   // The scene-graph thread owns this object so it can safely edit it.
690   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
691
692   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
693
694   // Reserve some memory inside the message queue
695   unsigned int* slot = manager.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::PropertyNotificationSetNotify, propertyNotification, notifyMode );
699 }
700
701 // The render thread can safely change the Shader
702 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
703 {
704   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
705
706   // Reserve some memory inside the message queue
707   unsigned int* slot = manager.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::AddShader, &shader );
711 }
712
713 // The render thread can safely change the Shader
714 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
715 {
716   typedef MessageValue1< UpdateManager, Shader* > LocalType;
717
718   // Reserve some memory inside the message queue
719   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
720
721   // Construct message in the message queue memory; note that delete should not be called on the return value
722   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
723 }
724
725 inline void SetShaderProgramMessage( UpdateManager& manager,
726                                      Shader& shader,
727                                      Internal::ShaderDataPtr shaderData,
728                                      bool modifiesGeometry )
729 {
730   typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
731
732   // Reserve some memory inside the message queue
733   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
734
735   // Construct message in the message queue memory; note that delete should not be called on the return value
736   new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
737 }
738
739 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
740 {
741   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
742
743   // Reserve some memory inside the message queue
744   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
745
746   // Construct message in the message queue memory; note that delete should not be called on the return value
747   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
748 }
749
750 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
751 {
752   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
753
754   // Reserve some memory inside the message queue
755   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
756
757   // Construct message in the message queue memory; note that delete should not be called on the return value
758   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
759 }
760
761 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
762 {
763   typedef MessageValue1< UpdateManager, float > LocalType;
764
765   // Reserve some memory inside the message queue
766   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
767
768   // Construct message in the message queue memory; note that delete should not be called on the return value
769   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
770 }
771
772 /**
773  * Create a message for setting the depth of a layer
774  * @param[in] manager The update manager
775  * @param[in] layers list of layers
776  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
777  */
778 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
779 {
780   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
781
782   // Reserve some memory inside the message queue
783   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
784
785   // Construct message in the message queue memory; note that delete should not be called on the return value
786   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
787 }
788
789 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
790 {
791   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
792
793   // Reserve some memory inside the message queue
794   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
795
796   // Construct message in the message queue memory; note that delete should not be called on the return value
797   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
798 }
799
800 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
801 {
802   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
803
804   // Reserve some memory inside the message queue
805   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
806
807   // Construct message in the message queue memory; note that delete should not be called on the return value
808   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
809 }
810
811 template< typename T >
812 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
813 {
814   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
815
816   // Reserve some memory inside the message queue
817   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
818   // Construct message in the message queue memory; note that delete should not be called on the return value
819   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
820 }
821
822 template< typename T >
823 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
824 {
825   typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
826
827   // Reserve some memory inside the message queue
828   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
829   // Construct message in the message queue memory; note that delete should not be called on the return value
830   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
831 }
832
833 } // namespace SceneGraph
834
835 } // namespace Internal
836
837 } // namespace Dali
838
839 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__