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