1cad203303c6300707f573b2899e6b673d8334d2
[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 #include <dali/internal/update/rendering/scene-graph-renderer.h>
39 #include <dali/internal/render/shaders/scene-graph-shader.h>
40 #include <dali/internal/render/renderers/render-property-buffer.h>
41
42 namespace Dali
43 {
44
45 namespace Integration
46 {
47 class GlSyncAbstraction;
48 class RenderController;
49
50 } // namespace Integration
51
52 namespace Internal
53 {
54
55 class PropertyNotifier;
56 class NotificationManager;
57 class CompleteNotificationInterface;
58 class ResourceManager;
59 class TouchResampler;
60
61 namespace Render
62 {
63 class Sampler;
64 }
65 // value types used by messages
66 template <> struct ParameterType< PropertyNotification::NotifyMode >
67 : public BasicType< PropertyNotification::NotifyMode > {};
68
69 namespace SceneGraph
70 {
71
72 class Animation;
73 class DiscardQueue;
74 class PanGesture;
75 class RenderManager;
76 class RenderTaskList;
77 class RenderQueue;
78 class TextureCache;
79 class Geometry;
80 class PropertyBuffer;
81 class Material;
82
83 /**
84  * UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
85  * other property owner objects.
86  * It controls the Update traversal, in which nodes are repositioned/animated,
87  * and organizes the the culling and rendering of the scene.
88  * It also maintains the lifecycle of nodes and other property owners that are
89  * disconnected from the scene graph.
90  */
91 class UpdateManager : public ShaderSaver
92 {
93 public:
94
95   /**
96    * Construct a new UpdateManager.
97    * @param[in] notificationManager This should be notified when animations have finished.
98    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
99    * @param[in] propertyNotifier The PropertyNotifier
100    * @param[in] resourceManager The resource manager used to load textures etc.
101    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
102    * @param[in] controller After messages are flushed, we request a render from the RenderController.
103    * @param[in] renderManager This is responsible for rendering the results of each "update".
104    * @param[in] renderQueue Used to queue messages for the next render.
105    * @param[in] textureCache Used for caching textures.
106    * @param[in] touchResampler Used for re-sampling touch events.
107    */
108   UpdateManager( NotificationManager& notificationManager,
109                  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.
121    */
122   virtual ~UpdateManager();
123
124   // Node connection methods
125
126   /**
127    * Get the scene graph side list of RenderTasks.
128    * @param[in] systemLevel True if using the system-level overlay.
129    * @return The list of render tasks
130    */
131   RenderTaskList* GetRenderTaskList( bool systemLevel );
132
133   /**
134    * Installs a new layer as the root node.
135    * @pre The UpdateManager does not already have an installed root node.
136    * @pre The layer is of derived Node type Layer.
137    * @pre The layer does not have a parent.
138    * @param[in] layer The new root node.
139    * @param[in] systemLevel True if using the system-level overlay.
140    * @post The node is owned by UpdateManager.
141    */
142   void InstallRoot( Layer* layer, bool systemLevel );
143
144   /**
145    * Add a Node; UpdateManager takes ownership.
146    * @pre The node does not have a parent.
147    * @param[in] node The node to add.
148    */
149   void AddNode( Node* node );
150
151   /**
152    * Connect a Node to the scene-graph.
153    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
154    * @pre The node does not already have a parent.
155    * @param[in] parent The new parent node.
156    */
157   void ConnectNode( Node* parent, Node* node );
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    * Destroy a Node owned by UpdateManager.
169    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
170    * In the following update, the previously queued Nodes may be deleted.
171    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
172    * @param[in] node The node to destroy.
173    */
174   void DestroyNode( Node* node );
175
176   /**
177    * Attach an object to a Node.
178    * The UpdateManager is responsible for calling NodeAttachment::Initialize().
179    * @param[in] node The node which will own the attachment.
180    * @param[in] attachment The object to attach.
181    */
182   void AttachToNode( Node* node, NodeAttachment* attachment );
183
184   /**
185    * Add a newly created object.
186    * @param[in] object The object to add.
187    * @post The object is owned by UpdateManager.
188    */
189   void AddObject( PropertyOwner* object );
190
191   /**
192    * Remove an object.
193    * @param[in] object The object to remove.
194    */
195   void RemoveObject( PropertyOwner* object );
196
197   // Animations
198
199   /**
200    * Add a newly created animation.
201    * @param[in] animation The animation to add.
202    * @post The animation is owned by UpdateManager.
203    */
204   void AddAnimation( Animation* animation );
205
206   /**
207    * Stop an animation.
208    * @param[in] animation The animation to stop.
209    */
210   void StopAnimation( Animation* animation );
211
212   /**
213    * Remove an animation.
214    * @param[in] animation The animation to remove.
215    */
216   void RemoveAnimation( Animation* animation );
217
218   /**
219    * Query whether any animations are currently running.
220    * @return True if any animations are running.
221    */
222   bool IsAnimationRunning() const;
223
224   // Property Notification
225
226   /**
227    * Add a newly created property notification
228    * @param[in] propertyNotification The notification to add
229    * @post The propertyNotification is owned by UpdateManager.
230    */
231   void AddPropertyNotification( PropertyNotification* propertyNotification );
232
233   /**
234    * Remove a property notification
235    * @param[in] propertyNotification The notification to remove
236    */
237   void RemovePropertyNotification( PropertyNotification* propertyNotification );
238
239   /**
240    * Set Notify state for PropertyNotification
241    * @param[in] propertyNotification The notification to remove
242    * @param[in] notifyMode The notification mode.
243    */
244   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
245
246   /**
247    * @brief Get the geometry owner
248    *
249    * @return The geometry owner
250    */
251   ObjectOwnerContainer< Geometry >& GetGeometryOwner();
252
253   ObjectOwnerContainer< Renderer >& GetRendererOwner();
254   /**
255    * @brief Get the material owner
256    *
257    * @return The material owner
258    */
259   ObjectOwnerContainer< Material >& GetMaterialOwner();
260
261   /**
262    * @brief Get the property buffer owner
263    *
264    * @return The property buffer owner
265    */
266   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
267
268
269   // Shaders
270
271   /**
272    * Add a newly created shader.
273    * @param[in] shader The shader to add.
274    * @post The shader is owned by the UpdateManager.
275    */
276   void AddShader(Shader* shader);
277
278   /**
279    * Remove a shader.
280    * @pre The shader has been added to the UpdateManager.
281    * @param[in] shader The shader to remove.
282    * @post The shader is destroyed.
283    */
284   void RemoveShader(Shader* shader);
285
286   /**
287    * Set the shader program for a Shader object
288    * @param[in] shader        The shader to modify
289    * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
290    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
291    */
292   void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
293
294   /**
295    * @brief Accept compiled shaders passed back on render thread for saving.
296    * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
297    */
298   virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
299
300   /**
301    * @brief Set the destination for compiled shader binaries to be passed on to.
302    * The dispatcher passed in will be called from the update thread.
303    * @param[in] upstream A sink for ShaderDatas to be passed into.
304    */
305   void SetShaderSaver( ShaderSaver& upstream );
306
307   // Gestures
308
309   /**
310    * Add a newly created gesture.
311    * @param[in] gesture The gesture to add.
312    * @post The gesture is owned by the UpdateManager.
313    */
314   void AddGesture( PanGesture* gesture );
315
316   /**
317    * Remove a gesture.
318    * @pre The gesture has been added to the UpdateManager.
319    * @param[in] gesture The gesture to remove.
320    * @post The gesture is destroyed.
321    */
322   void RemoveGesture( PanGesture* gesture );
323
324 // Message queue handling
325
326   /**
327    * Reserve space for another message in the queue; this must then be initialized by the caller.
328    * The message will be read from the update-thread after the next FlushMessages is called.
329    * @post Calling this method may invalidate any previously returned slots.
330    * @param[in] size The message size with respect to the size of type "char".
331    * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
332    * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
333    * @return A pointer to the first char allocated for the message.
334    */
335   unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
336
337   /**
338    * @return the current event-buffer index.
339    */
340   BufferIndex GetEventBufferIndex() const
341   {
342     // inlined as its called often from event thread
343     return mSceneGraphBuffers.GetEventBufferIndex();
344   }
345
346   /**
347    * Called by the event-thread to signal that FlushQueue will be called
348    * e.g. when it has finished event processing.
349    */
350   void EventProcessingStarted();
351
352   /**
353    * Flush the set of messages, which were previously stored with QueueMessage().
354    * Calls to this thread-safe method should be minimized, to avoid thread blocking.
355    *
356    * @return True if there are messages to process.
357    */
358   bool FlushQueue();
359
360   /**
361    * Add a new sampler to RenderManager
362    * @param[in] sampler The sampler to add
363    * @post Sends a message to RenderManager to add the sampler.
364    * The sampler will be owned by RenderManager
365    */
366   void AddSampler( Render::Sampler* sampler );
367
368   /**
369    * Removes an existing sampler from RenderManager
370    * @param[in] sampler The sampler to remove
371    * @post The sampler will be destroyed in the render thread
372    */
373   void RemoveSampler( Render::Sampler* sampler );
374
375   /**
376    * Sets the filter modes for an existing sampler
377    * @param[in] sampler The sampler
378    * @param[in] minFilterMode The filter to use under minification
379    * @param[in] magFilterMode The filter to use under magnification
380    */
381   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
382
383   /**
384    * Sets the wrap mode for an existing sampler
385    * @param[in] sampler The sampler
386    * @param[in] uWrapMode Wrapping mode in x direction
387    * @param[in] vWrapMode Wrapping mode in y direction
388    */
389   void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
390
391   /**
392    * Add a new sampler to RenderManager
393    * @param[in] propertryBuffer The property buffer to add
394    * @post Sends a message to RenderManager to add the property buffer.
395    * The property buffer will be owned by RenderManager
396    */
397   void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer );
398
399   /**
400    * Removes an existing PropertyBuffer from RenderManager
401    * @param[in] propertryBuffer The property buffer to remove
402    * @post The property buffer will be destroyed in the render thread
403    */
404   void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
405
406   /**
407    * Sets the format of an existing property buffer
408    * @param[in] propertyBuffer The property buffer.
409    * @param[in] format The new format of the buffer
410    * @post Sends a message to RenderManager to set the new format to the property buffer.
411    */
412   void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
413
414   /**
415    * Sets the data of an existing property buffer
416    * @param[in] propertyBuffer The property buffer.
417    * @param[in] data The new data of the buffer
418    * @post Sends a message to RenderManager to set the new data to the property buffer.
419    */
420   void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
421
422   /**
423    * Sets the size of an existing property buffer
424    * @param[in] propertyBuffer The property buffer.
425    * @param[in] size The new size of the buffer
426    * @post Sends a message to RenderManager to set the new size to the property buffer.
427    */
428   void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
429
430 public:
431
432   /**
433    * Performs an Update traversal on the scene-graph.
434    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
435    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
436    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
437    * @return True if further updates are required e.g. during animations.
438    */
439   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
440
441   /**
442    * Set the background color i.e. the glClear color used at the beginning of each frame.
443    * @param[in] color The new background color.
444    */
445   void SetBackgroundColor(const Vector4& color);
446
447   /**
448    * Set the default surface rect.
449    * @param[in] rect The rect value representing the surface.
450    */
451   void SetDefaultSurfaceRect( const Rect<int>& rect );
452
453   /**
454    * @copydoc Dali::Stage::KeepRendering()
455    */
456   void KeepRendering( float durationSeconds );
457
458   /**
459    * Sets the depths of all layers.
460    * @param layers The layers in depth order.
461    * @param[in] systemLevel True if using the system-level overlay.
462    */
463   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
464
465 private:
466
467   // Undefined
468   UpdateManager(const UpdateManager&);
469
470   // Undefined
471   UpdateManager& operator=(const UpdateManager& rhs);
472
473   /**
474    * Helper to check whether the update-thread should keep going.
475    * @param[in] elapsedSeconds The time in seconds since the previous update.
476    * @return True if the update-thread should keep going.
477    */
478   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
479
480   /**
481    * Helper to calculate new camera setup when root node resizes.
482    * @param[in] updateBuffer The buffer to read the root node size from.
483    */
484   void UpdateProjectionAndViewMatrices(int updateBuffer);
485
486   /**
487    * Post process resources that have been updated by renderer
488    */
489   void PostProcessResources();
490
491   /**
492    * Helper to reset all Node properties
493    * @param[in] bufferIndex to use
494    */
495   void ResetProperties( BufferIndex bufferIndex );
496
497   /**
498    * Perform gesture updates.
499    * @param[in] bufferIndex to use
500    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
501    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
502    * @return true, if any properties were updated.
503    */
504   bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
505
506   /**
507    * Perform animation updates
508    * @param[in] bufferIndex to use
509    * @param[in] elapsedSeconds time since last frame
510    */
511   void Animate( BufferIndex bufferIndex, float elapsedSeconds );
512
513   /**
514    * Applies constraints to CustomObjects
515    * @param[in] bufferIndex to use
516    */
517   void ConstrainCustomObjects( BufferIndex bufferIndex );
518
519   /**
520    * Applies constraints to RenderTasks
521    * @param[in] bufferIndex to use
522    */
523   void ConstrainRenderTasks( BufferIndex bufferIndex );
524
525   /**
526    * Applies constraints to Shaders
527    * @param[in] bufferIndex to use
528    */
529   void ConstrainShaders( BufferIndex bufferIndex );
530
531   /**
532    * Perform property notification updates
533    * @param[in] bufferIndex to use
534    */
535   void ProcessPropertyNotifications( BufferIndex bufferIndex );
536
537   /**
538    * Prepare materials for rendering
539    */
540   void PrepareMaterials( BufferIndex bufferIndex );
541
542   /**
543    * Pass shader binaries queued here on to event thread.
544    */
545   void ForwardCompiledShadersToEventThread();
546
547   /**
548    * Update the default camera.
549    * This must be altered to match the root Node for 2D layouting.
550    * @param[in] updateBuffer The buffer to read the root node size from.
551    */
552   void UpdateDefaultCamera( int updateBuffer );
553
554   /**
555    * Update node shaders, opacity, geometry etc.
556    * @param[in] bufferIndex to use
557    */
558   void UpdateNodes( BufferIndex bufferIndex );
559
560   /**
561    * Update Renderers
562    * @param[in] bufferIndex to use
563    */
564   void UpdateRenderers( BufferIndex bufferIndex );
565
566 private:
567
568   // needs to be direct member so that getter for event buffer can be inlined
569   SceneGraphBuffers mSceneGraphBuffers;
570
571   struct Impl;
572   Impl* mImpl;
573
574 };
575
576 // Messages for UpdateManager
577
578 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
579 {
580   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
581
582   // Reserve some memory inside the message queue
583   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
584
585   // Construct message in the message queue memory; note that delete should not be called on the return value
586   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
587 }
588
589 inline void AddNodeMessage( UpdateManager& manager, Node& node )
590 {
591   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
592
593   // Reserve some memory inside the message queue
594   unsigned int* slot = manager.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::AddNode, &node );
598 }
599
600 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
601 {
602   // Update thread can edit the object
603   Node& parent = const_cast< Node& >( constParent );
604   Node& child = const_cast< Node& >( constChild );
605
606   typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
607
608   // Reserve some memory inside the message queue
609   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
610
611   // Construct message in the message queue memory; note that delete should not be called on the return value
612   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
613 }
614
615 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
616 {
617   // Scene graph thread can modify this object.
618   Node& node = const_cast< Node& >( constNode );
619
620   typedef MessageValue1< UpdateManager, Node* > LocalType;
621
622   // Reserve some memory inside the message queue
623   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
624
625   // Construct message in the message queue memory; note that delete should not be called on the return value
626   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
627 }
628
629 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
630 {
631   // Scene graph thread can destroy this object.
632   Node& node = const_cast< Node& >( constNode );
633
634   typedef MessageValue1< UpdateManager, Node* > LocalType;
635
636   // Reserve some memory inside the message queue
637   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
638
639   // Construct message in the message queue memory; note that delete should not be called on the return value
640   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
641 }
642
643 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
644 {
645   // Scene graph thread can modify this object.
646   Node& parent = const_cast< Node& >( constParent );
647
648   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
649
650   // Reserve some memory inside the message queue
651   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
652
653   // Construct message in the message queue memory; note that delete should not be called on the return value
654   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
655 }
656
657 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
658 {
659   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
660
661   // Reserve some memory inside the message queue
662   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
663
664   // Construct message in the message queue memory; note that delete should not be called on the return value
665   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
666 }
667
668 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
669 {
670   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
671
672   // Reserve some memory inside the message queue
673   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
674
675   // Construct message in the message queue memory; note that delete should not be called on the return value
676   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
677 }
678
679 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
680 {
681   typedef MessageValue1< UpdateManager, Animation* > LocalType;
682
683   // Reserve some memory inside the message queue
684   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
685
686   // Construct message in the message queue memory; note that delete should not be called on the return value
687   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
688 }
689
690 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
691 {
692   // The scene-graph thread owns this object so it can safely edit it.
693   Animation& animation = const_cast< Animation& >( constAnimation );
694
695   typedef MessageValue1< UpdateManager, Animation* > LocalType;
696
697   // Reserve some memory inside the message queue
698   unsigned int* slot = manager.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::StopAnimation, &animation );
702 }
703
704 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
705 {
706   // The scene-graph thread owns this object so it can safely edit it.
707   Animation& animation = const_cast< Animation& >( constAnimation );
708
709   typedef MessageValue1< UpdateManager, Animation* > LocalType;
710
711   // Reserve some memory inside the message queue
712   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
713
714   // Construct message in the message queue memory; note that delete should not be called on the return value
715   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
716 }
717
718 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
719 {
720   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
721
722   // Reserve some memory inside the message queue
723   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
724
725   // Construct message in the message queue memory; note that delete should not be called on the return value
726   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
727 }
728
729 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
730 {
731   // The scene-graph thread owns this object so it can safely edit it.
732   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
733
734   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
735
736   // Reserve some memory inside the message queue
737   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
738
739   // Construct message in the message queue memory; note that delete should not be called on the return value
740   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
741 }
742
743 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
744                                                       const PropertyNotification* constPropertyNotification,
745                                                       PropertyNotification::NotifyMode notifyMode )
746 {
747   // The scene-graph thread owns this object so it can safely edit it.
748   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
749
750   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
751
752   // Reserve some memory inside the message queue
753   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
754
755   // Construct message in the message queue memory; note that delete should not be called on the return value
756   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
757 }
758
759 // The render thread can safely change the Shader
760 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
761 {
762   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
763
764   // Reserve some memory inside the message queue
765   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
766
767   // Construct message in the message queue memory; note that delete should not be called on the return value
768   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
769 }
770
771 // The render thread can safely change the Shader
772 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
773 {
774   typedef MessageValue1< UpdateManager, Shader* > LocalType;
775
776   // Reserve some memory inside the message queue
777   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
778
779   // Construct message in the message queue memory; note that delete should not be called on the return value
780   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
781 }
782
783 inline void SetShaderProgramMessage( UpdateManager& manager,
784                                      Shader& shader,
785                                      Internal::ShaderDataPtr shaderData,
786                                      bool modifiesGeometry )
787 {
788   typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
789
790   // Reserve some memory inside the message queue
791   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
792
793   // Construct message in the message queue memory; note that delete should not be called on the return value
794   new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
795 }
796
797 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
798 {
799   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
800
801   // Reserve some memory inside the message queue
802   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
803
804   // Construct message in the message queue memory; note that delete should not be called on the return value
805   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
806 }
807
808 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
809 {
810   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
811
812   // Reserve some memory inside the message queue
813   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
814
815   // Construct message in the message queue memory; note that delete should not be called on the return value
816   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
817 }
818
819 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
820 {
821   typedef MessageValue1< UpdateManager, float > LocalType;
822
823   // Reserve some memory inside the message queue
824   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
825
826   // Construct message in the message queue memory; note that delete should not be called on the return value
827   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
828 }
829
830 /**
831  * Create a message for setting the depth of a layer
832  * @param[in] manager The update manager
833  * @param[in] layers list of layers
834  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
835  */
836 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
837 {
838   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
839
840   // Reserve some memory inside the message queue
841   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
842
843   // Construct message in the message queue memory; note that delete should not be called on the return value
844   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
845 }
846
847 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
848 {
849   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
850
851   // Reserve some memory inside the message queue
852   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
853
854   // Construct message in the message queue memory; note that delete should not be called on the return value
855   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
856 }
857
858 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
859 {
860   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
861
862   // Reserve some memory inside the message queue
863   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
864
865   // Construct message in the message queue memory; note that delete should not be called on the return value
866   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
867 }
868
869 template< typename T >
870 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
871 {
872   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
873
874   // Reserve some memory inside the message queue
875   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
876   // Construct message in the message queue memory; note that delete should not be called on the return value
877   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
878 }
879
880 template< typename T >
881 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
882 {
883   typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
884
885   // Reserve some memory inside the message queue
886   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
887   // Construct message in the message queue memory; note that delete should not be called on the return value
888   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
889 }
890
891 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
892 {
893   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
894
895   // Reserve some memory inside the message queue
896   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
897
898   // Construct message in the message queue memory; note that delete should not be called on the return value
899   new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
900 }
901
902 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
903 {
904   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
905
906   // Reserve some memory inside the message queue
907   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
908
909   // Construct message in the message queue memory; note that delete should not be called on the return value
910   new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
911 }
912
913 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
914 {
915   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
916
917   // Reserve some memory inside the message queue
918   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
919
920   // Construct message in the message queue memory; note that delete should not be called on the return value
921   new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
922 }
923
924 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int uWrapMode, unsigned int vWrapMode )
925 {
926   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int  > LocalType;
927
928   // Reserve some memory inside the message queue
929   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
930
931   // Construct message in the message queue memory; note that delete should not be called on the return value
932   new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, uWrapMode, vWrapMode );
933 }
934
935 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
936 {
937   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
938
939   // Reserve some memory inside the message queue
940   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
941
942   // Construct message in the message queue memory; note that delete should not be called on the return value
943   new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
944 }
945
946 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
947 {
948   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
949
950   // Reserve some memory inside the message queue
951   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
952
953   // Construct message in the message queue memory; note that delete should not be called on the return value
954   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
955 }
956
957 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
958 {
959   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format*  > LocalType;
960
961   // Reserve some memory inside the message queue
962   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
963
964   // Construct message in the message queue memory; note that delete should not be called on the return value
965   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
966 }
967
968 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data )
969 {
970   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Vector<char>*  > LocalType;
971
972   // Reserve some memory inside the message queue
973   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
974
975   // Construct message in the message queue memory; note that delete should not be called on the return value
976   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data );
977 }
978
979 inline void SetPropertyBufferSize( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, size_t size )
980 {
981   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, size_t  > LocalType;
982
983   // Reserve some memory inside the message queue
984   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
985
986   // Construct message in the message queue memory; note that delete should not be called on the return value
987   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferSize, &propertyBuffer, size );
988 }
989
990
991 } // namespace SceneGraph
992
993 } // namespace Internal
994
995 } // namespace Dali
996
997 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__