Merge branch 'devel/master' 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) 2016 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/nodes/node.h>
36 #include <dali/internal/update/nodes/scene-graph-layer.h>
37 #include <dali/internal/update/rendering/scene-graph-renderer.h>
38 #include <dali/internal/render/shaders/scene-graph-shader.h>
39 #include <dali/internal/render/renderers/render-property-buffer.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 namespace Render
61 {
62 class Sampler;
63 }
64 // value types used by messages
65 template <> struct ParameterType< PropertyNotification::NotifyMode >
66 : public BasicType< PropertyNotification::NotifyMode > {};
67
68 namespace SceneGraph
69 {
70
71 class Animation;
72 class DiscardQueue;
73 class PanGesture;
74 class RenderManager;
75 class RenderTaskList;
76 class RenderQueue;
77 class TextureCacheDispatcher;
78 class PropertyBuffer;
79 class TextureSet;
80 class Camera;
81
82 /**
83  * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
84  * other scene graph property owning objects.
85  * It controls the Update traversal, in which nodes are repositioned/animated,
86  * and organizes the the culling and rendering of the scene.
87  * It also maintains the lifecycle of nodes and other property owners that are
88  * disconnected from the scene graph.
89  */
90 class UpdateManager : public ShaderSaver
91 {
92 public:
93
94   /**
95    * Construct a new UpdateManager.
96    * @param[in] notificationManager This should be notified when animations have finished.
97    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
98    * @param[in] propertyNotifier The PropertyNotifier
99    * @param[in] resourceManager The resource manager used to load textures etc.
100    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
101    * @param[in] controller After messages are flushed, we request a render from the RenderController.
102    * @param[in] renderManager This is responsible for rendering the results of each "update".
103    * @param[in] renderQueue Used to queue messages for the next render.
104    * @param[in] textureCacheDispatcher Used for sending messages to texture cache.
105    */
106   UpdateManager( NotificationManager& notificationManager,
107                  CompleteNotificationInterface& animationFinishedNotifier,
108                  PropertyNotifier& propertyNotifier,
109                  ResourceManager& resourceManager,
110                  DiscardQueue& discardQueue,
111                  Integration::RenderController& controller,
112                  RenderManager& renderManager,
113                  RenderQueue& renderQueue,
114                  TextureCacheDispatcher& textureCacheDispatcher );
115
116   /**
117    * Destructor.
118    */
119   virtual ~UpdateManager();
120
121   // Node connection methods
122
123   /**
124    * Get the scene graph side list of RenderTasks.
125    * @param[in] systemLevel True if using the system-level overlay.
126    * @return The list of render tasks
127    */
128   RenderTaskList* GetRenderTaskList( bool systemLevel );
129
130   /**
131    * Installs a new layer as the root node.
132    * @pre The UpdateManager does not already have an installed root node.
133    * @pre The layer is of derived Node type Layer.
134    * @pre The layer does not have a parent.
135    * @param[in] layer The new root node.
136    * @param[in] systemLevel True if using the system-level overlay.
137    * @post The node is owned by UpdateManager.
138    */
139   void InstallRoot( Layer* layer, bool systemLevel );
140
141   /**
142    * Add a Node; UpdateManager takes ownership.
143    * @pre The node does not have a parent.
144    * @param[in] node The node to add.
145    */
146   void AddNode( Node* node );
147
148   /**
149    * Connect a Node to the scene-graph.
150    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
151    * @pre The node does not already have a parent.
152    * @param[in] parent The new parent node.
153    */
154   void ConnectNode( Node* parent, Node* node );
155
156   /**
157    * Disconnect a Node from the scene-graph.
158    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
159    * @pre The node has a parent.
160    * @param[in] node The node to disconnect.
161    */
162   void DisconnectNode( Node* node );
163
164   /**
165    * Destroy a Node owned by UpdateManager.
166    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
167    * In the following update, the previously queued Nodes may be deleted.
168    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
169    * @param[in] node The node to destroy.
170    */
171   void DestroyNode( Node* node );
172
173   /**
174    * Add a camera on scene
175    * @param[in] camera to add
176    */
177   void AddCamera( Camera* camera );
178
179   /**
180    * Remove a camera from scene
181    * @param[in] camera to remove
182    */
183   void RemoveCamera( const Camera* camera );
184
185   /**
186    * Add a newly created object.
187    * @param[in] object The object to add.
188    * @post The object is owned by UpdateManager.
189    */
190   void AddObject( PropertyOwner* object );
191
192   /**
193    * Remove an object.
194    * @param[in] object The object to remove.
195    */
196   void RemoveObject( PropertyOwner* object );
197
198   // Animations
199
200   /**
201    * Add a newly created animation.
202    * @param[in] animation The animation to add.
203    * @post The animation is owned by UpdateManager.
204    */
205   void AddAnimation( Animation* animation );
206
207   /**
208    * Stop an animation.
209    * @param[in] animation The animation to stop.
210    */
211   void StopAnimation( Animation* animation );
212
213   /**
214    * Remove an animation.
215    * @param[in] animation The animation to remove.
216    */
217   void RemoveAnimation( Animation* animation );
218
219   /**
220    * Query whether any animations are currently running.
221    * @return True if any animations are running.
222    */
223   bool IsAnimationRunning() const;
224
225   // Property Notification
226
227   /**
228    * Add a newly created property notification
229    * @param[in] propertyNotification The notification to add
230    * @post The propertyNotification is owned by UpdateManager.
231    */
232   void AddPropertyNotification( PropertyNotification* propertyNotification );
233
234   /**
235    * Remove a property notification
236    * @param[in] propertyNotification The notification to remove
237    */
238   void RemovePropertyNotification( PropertyNotification* propertyNotification );
239
240   /**
241    * Set Notify state for PropertyNotification
242    * @param[in] propertyNotification The notification to remove
243    * @param[in] notifyMode The notification mode.
244    */
245   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
246
247   /**
248    * @brief Get the renderer owner
249    *
250    * @return The renderer owner
251    */
252   ObjectOwnerContainer< Renderer >& GetRendererOwner();
253
254   /**
255    * @brief Get the property buffer owner
256    *
257    * @return The property buffer owner
258    */
259   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
260
261
262   // Shaders
263
264   /**
265    * Add a newly created shader.
266    * @param[in] shader The shader to add.
267    * @post The shader is owned by the UpdateManager.
268    */
269   void AddShader(Shader* shader);
270
271   /**
272    * Remove a shader.
273    * @pre The shader has been added to the UpdateManager.
274    * @param[in] shader The shader to remove.
275    * @post The shader is destroyed.
276    */
277   void RemoveShader(Shader* shader);
278
279   /**
280    * Add a newly created TextureSet.
281    * @param[in] textureSet The texture set to add.
282    * @post The TextureSet is owned by the UpdateManager.
283    */
284   void AddTextureSet(TextureSet* textureSet);
285
286   /**
287    * Remove a TextureSet.
288    * @pre The TextureSet has been added to the UpdateManager.
289    * @param[in] textureSet The TextureSet to remove.
290    * @post The TextureSet is destroyed.
291    */
292   void RemoveTextureSet(TextureSet* textureSet);
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 property buffer 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    * @param[in] size The new size of the buffer
427    * @post Sends a message to RenderManager to set the new data to the property buffer.
428    */
429   void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size);
430
431   /**
432    * Adds a geometry to the RenderManager
433    * @param[in] geometry The geometry to add
434    * @post Sends a message to RenderManager to add the Geometry
435    * The geometry will be owned by RenderManager
436    */
437   void AddGeometry( Render::Geometry* geometry );
438
439   /**
440    * Removes an existing Geometry from RenderManager
441    * @param[in] geometry The geometry to remove
442    * @post The geometry will be destroyed in the render thread
443    */
444   void RemoveGeometry( Render::Geometry* geometry );
445
446   /**
447    * Sets the geometry type of an existing Geometry
448    * @param[in] geometry The geometry
449    * @param[in] geometryType The type of the geometry
450    */
451   void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
452
453   /**
454    * Sets the index buffer to be used by a geometry
455    * @param[in] geometry The geometry
456    * @param[in] indices A vector containing the indices for the geometry
457    */
458   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
459
460   /**
461    * Adds a vertex buffer to a geomtry
462    * @param[in] geometry The geometry
463    * @param[in] propertyBuffer The property buffer
464    */
465   void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
466
467   /**
468    * Removes a vertex buffer from a geometry
469    * @param[in] geometry The geometry
470    * @param[in] propertyBuffer The property buffer
471    */
472   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
473
474
475 public:
476
477   /**
478    * Performs an Update traversal on the scene-graph.
479    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
480    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
481    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
482    * @return True if further updates are required e.g. during animations.
483    */
484   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
485
486   /**
487    * Set the background color i.e. the glClear color used at the beginning of each frame.
488    * @param[in] color The new background color.
489    */
490   void SetBackgroundColor(const Vector4& color);
491
492   /**
493    * Set the default surface rect.
494    * @param[in] rect The rect value representing the surface.
495    */
496   void SetDefaultSurfaceRect( const Rect<int>& rect );
497
498   /**
499    * @copydoc Dali::Stage::KeepRendering()
500    */
501   void KeepRendering( float durationSeconds );
502
503   /**
504    * Sets the depths of all layers.
505    * @param layers The layers in depth order.
506    * @param[in] systemLevel True if using the system-level overlay.
507    */
508   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
509
510 private:
511
512   // Undefined
513   UpdateManager(const UpdateManager&);
514
515   // Undefined
516   UpdateManager& operator=(const UpdateManager& rhs);
517
518   /**
519    * Helper to check whether the update-thread should keep going.
520    * @param[in] elapsedSeconds The time in seconds since the previous update.
521    * @return True if the update-thread should keep going.
522    */
523   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
524
525   /**
526    * Post process resources that have been updated by renderer
527    */
528   void PostProcessResources();
529
530   /**
531    * Helper to reset all Node properties
532    * @param[in] bufferIndex to use
533    */
534   void ResetProperties( BufferIndex bufferIndex );
535
536   /**
537    * Perform gesture updates.
538    * @param[in] bufferIndex to use
539    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
540    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
541    * @return true, if any properties were updated.
542    */
543   bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
544
545   /**
546    * Perform animation updates
547    * @param[in] bufferIndex to use
548    * @param[in] elapsedSeconds time since last frame
549    */
550   void Animate( BufferIndex bufferIndex, float elapsedSeconds );
551
552   /**
553    * Applies constraints to CustomObjects
554    * @param[in] bufferIndex to use
555    */
556   void ConstrainCustomObjects( BufferIndex bufferIndex );
557
558   /**
559    * Applies constraints to RenderTasks
560    * @param[in] bufferIndex to use
561    */
562   void ConstrainRenderTasks( BufferIndex bufferIndex );
563
564   /**
565    * Applies constraints to Shaders
566    * @param[in] bufferIndex to use
567    */
568   void ConstrainShaders( BufferIndex bufferIndex );
569
570   /**
571    * Perform property notification updates
572    * @param[in] bufferIndex to use
573    */
574   void ProcessPropertyNotifications( BufferIndex bufferIndex );
575
576   /**
577    * Prepare textures for rendering
578    */
579   void PrepareTextureSets( BufferIndex bufferIndex );
580
581   /**
582    * Pass shader binaries queued here on to event thread.
583    */
584   void ForwardCompiledShadersToEventThread();
585
586   /**
587    * Update node shaders, opacity, geometry etc.
588    * @param[in] bufferIndex to use
589    */
590   void UpdateNodes( BufferIndex bufferIndex );
591
592   /**
593    * Update Renderers
594    * @param[in] bufferIndex to use
595    */
596   void UpdateRenderers( BufferIndex bufferIndex );
597
598 private:
599
600   // needs to be direct member so that getter for event buffer can be inlined
601   SceneGraphBuffers mSceneGraphBuffers;
602
603   struct Impl;
604   Impl* mImpl;
605
606 };
607
608 // Messages for UpdateManager
609
610 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
611 {
612   typedef MessageValue2< UpdateManager, Layer*, bool > 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::InstallRoot, &root, systemLevel );
619 }
620
621 inline void AddNodeMessage( UpdateManager& manager, Node& node )
622 {
623   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > 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::AddNode, &node );
630 }
631
632 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
633 {
634   // Update thread can edit the object
635   Node& parent = const_cast< Node& >( constParent );
636   Node& child = const_cast< Node& >( constChild );
637
638   typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
639
640   // Reserve some memory inside the message queue
641   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
642
643   // Construct message in the message queue memory; note that delete should not be called on the return value
644   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
645 }
646
647 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
648 {
649   // Scene graph thread can modify this object.
650   Node& node = const_cast< Node& >( constNode );
651
652   typedef MessageValue1< UpdateManager, Node* > LocalType;
653
654   // Reserve some memory inside the message queue
655   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
656
657   // Construct message in the message queue memory; note that delete should not be called on the return value
658   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
659 }
660
661 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
662 {
663   // Scene graph thread can destroy this object.
664   Node& node = const_cast< Node& >( constNode );
665
666   typedef MessageValue1< UpdateManager, Node* > LocalType;
667
668   // Reserve some memory inside the message queue
669   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
670
671   // Construct message in the message queue memory; note that delete should not be called on the return value
672   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
673 }
674
675 inline void AddCameraMessage( UpdateManager& manager, const Camera* constCamera )
676 {
677   typedef MessageValue1< UpdateManager, Camera* > LocalType;
678
679   Camera* camera = const_cast<Camera*>( constCamera );
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::AddCamera, camera );
685 }
686
687 inline void RemoveCameraMessage( UpdateManager& manager, const Camera* camera )
688 {
689   typedef MessageValue1< UpdateManager, const Camera* > 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::RemoveCamera, camera );
696 }
697
698 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
699 {
700   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
701
702   // Reserve some memory inside the message queue
703   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
704
705   // Construct message in the message queue memory; note that delete should not be called on the return value
706   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
707 }
708
709 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
710 {
711   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
712
713   // Reserve some memory inside the message queue
714   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
715
716   // Construct message in the message queue memory; note that delete should not be called on the return value
717   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
718 }
719
720 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
721 {
722   typedef MessageValue1< UpdateManager, Animation* > LocalType;
723
724   // Reserve some memory inside the message queue
725   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
726
727   // Construct message in the message queue memory; note that delete should not be called on the return value
728   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
729 }
730
731 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
732 {
733   // The scene-graph thread owns this object so it can safely edit it.
734   Animation& animation = const_cast< Animation& >( constAnimation );
735
736   typedef MessageValue1< UpdateManager, Animation* > LocalType;
737
738   // Reserve some memory inside the message queue
739   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
740
741   // Construct message in the message queue memory; note that delete should not be called on the return value
742   new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
743 }
744
745 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
746 {
747   // The scene-graph thread owns this object so it can safely edit it.
748   Animation& animation = const_cast< Animation& >( constAnimation );
749
750   typedef MessageValue1< UpdateManager, Animation* > 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::RemoveAnimation, &animation );
757 }
758
759 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
760 {
761   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
762
763   // Reserve some memory inside the message queue
764   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
765
766   // Construct message in the message queue memory; note that delete should not be called on the return value
767   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
768 }
769
770 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
771 {
772   // The scene-graph thread owns this object so it can safely edit it.
773   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
774
775   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
776
777   // Reserve some memory inside the message queue
778   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
779
780   // Construct message in the message queue memory; note that delete should not be called on the return value
781   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
782 }
783
784 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
785                                                       const PropertyNotification* constPropertyNotification,
786                                                       PropertyNotification::NotifyMode notifyMode )
787 {
788   // The scene-graph thread owns this object so it can safely edit it.
789   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
790
791   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > 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::PropertyNotificationSetNotify, propertyNotification, notifyMode );
798 }
799
800 // The render thread can safely change the Shader
801 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
802 {
803   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
804
805   // Reserve some memory inside the message queue
806   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
807
808   // Construct message in the message queue memory; note that delete should not be called on the return value
809   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
810 }
811
812 // The render thread can safely change the Shader
813 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
814 {
815   typedef MessageValue1< UpdateManager, Shader* > LocalType;
816
817   // Reserve some memory inside the message queue
818   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
819
820   // Construct message in the message queue memory; note that delete should not be called on the return value
821   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
822 }
823
824 inline void SetShaderProgramMessage( UpdateManager& manager,
825                                      Shader& shader,
826                                      Internal::ShaderDataPtr shaderData,
827                                      bool modifiesGeometry )
828 {
829   typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > 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::SetShaderProgram, &shader, shaderData, modifiesGeometry );
836 }
837
838 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
839 {
840   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
841
842   // Reserve some memory inside the message queue
843   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
844
845   // Construct message in the message queue memory; note that delete should not be called on the return value
846   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
847 }
848
849 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
850 {
851   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
852
853   // Reserve some memory inside the message queue
854   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
855
856   // Construct message in the message queue memory; note that delete should not be called on the return value
857   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
858 }
859
860 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
861 {
862   typedef MessageValue1< UpdateManager, float > LocalType;
863
864   // Reserve some memory inside the message queue
865   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
866
867   // Construct message in the message queue memory; note that delete should not be called on the return value
868   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
869 }
870
871 /**
872  * Create a message for setting the depth of a layer
873  * @param[in] manager The update manager
874  * @param[in] layers list of layers
875  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
876  */
877 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
878 {
879   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
880
881   // Reserve some memory inside the message queue
882   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
883
884   // Construct message in the message queue memory; note that delete should not be called on the return value
885   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
886 }
887
888 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
889 {
890   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
891
892   // Reserve some memory inside the message queue
893   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
894
895   // Construct message in the message queue memory; note that delete should not be called on the return value
896   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
897 }
898
899 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
900 {
901   typedef MessageValue1< UpdateManager, PanGesture* > 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::RemoveGesture, gesture );
908 }
909
910 template< typename T >
911 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
912 {
913   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
914
915   // Reserve some memory inside the message queue
916   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
917   // Construct message in the message queue memory; note that delete should not be called on the return value
918   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
919 }
920
921 template< typename T >
922 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
923 {
924   typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
925
926   // Reserve some memory inside the message queue
927   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
928   // Construct message in the message queue memory; note that delete should not be called on the return value
929   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
930 }
931
932 // The render thread can safely change the Shader
933 inline void AddTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
934 {
935   typedef MessageValue1< UpdateManager, OwnerPointer< TextureSet > > LocalType;
936
937   // Reserve some memory inside the message queue
938   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
939
940   // Construct message in the message queue memory; note that delete should not be called on the return value
941   new (slot) LocalType( &manager, &UpdateManager::AddTextureSet, &textureSet );
942 }
943
944 // The render thread can safely change the Shader
945 inline void RemoveTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
946 {
947   typedef MessageValue1< UpdateManager, TextureSet* > LocalType;
948
949   // Reserve some memory inside the message queue
950   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
951
952   // Construct message in the message queue memory; note that delete should not be called on the return value
953   new (slot) LocalType( &manager, &UpdateManager::RemoveTextureSet, &textureSet );
954 }
955
956 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
957 {
958   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
959
960   // Reserve some memory inside the message queue
961   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
962
963   // Construct message in the message queue memory; note that delete should not be called on the return value
964   new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
965 }
966
967 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
968 {
969   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
970
971   // Reserve some memory inside the message queue
972   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
973
974   // Construct message in the message queue memory; note that delete should not be called on the return value
975   new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
976 }
977
978 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
979 {
980   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
981
982   // Reserve some memory inside the message queue
983   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
984
985   // Construct message in the message queue memory; note that delete should not be called on the return value
986   new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
987 }
988
989 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int uWrapMode, unsigned int vWrapMode )
990 {
991   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int  > LocalType;
992
993   // Reserve some memory inside the message queue
994   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
995
996   // Construct message in the message queue memory; note that delete should not be called on the return value
997   new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, uWrapMode, vWrapMode );
998 }
999
1000 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1001 {
1002   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
1003
1004   // Reserve some memory inside the message queue
1005   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1006
1007   // Construct message in the message queue memory; note that delete should not be called on the return value
1008   new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
1009 }
1010
1011 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1012 {
1013   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
1014
1015   // Reserve some memory inside the message queue
1016   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1017
1018   // Construct message in the message queue memory; note that delete should not be called on the return value
1019   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
1020 }
1021
1022 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
1023 {
1024   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format*  > LocalType;
1025
1026   // Reserve some memory inside the message queue
1027   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1028
1029   // Construct message in the message queue memory; note that delete should not be called on the return value
1030   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
1031 }
1032
1033 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data, size_t size )
1034 {
1035   typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, Vector<char>*, size_t  > LocalType;
1036
1037   // Reserve some memory inside the message queue
1038   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1039
1040   // Construct message in the message queue memory; note that delete should not be called on the return value
1041   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
1042 }
1043
1044 inline void AddGeometry( UpdateManager& manager, Render::Geometry& geometry )
1045 {
1046   typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
1047
1048   // Reserve some memory inside the message queue
1049   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1050
1051   // Construct message in the message queue memory; note that delete should not be called on the return value
1052   new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
1053 }
1054
1055 inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
1056 {
1057   typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
1058
1059   // Reserve some memory inside the message queue
1060   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1061
1062   // Construct message in the message queue memory; note that delete should not be called on the return value
1063   new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
1064 }
1065
1066 inline void AddVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1067 {
1068   typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1069
1070   // Reserve some memory inside the message queue
1071   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1072
1073   // Construct message in the message queue memory; note that delete should not be called on the return value
1074   new (slot) LocalType( &manager, &UpdateManager::AddVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1075 }
1076
1077 inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1078 {
1079   typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1080
1081   // Reserve some memory inside the message queue
1082   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1083
1084   // Construct message in the message queue memory; note that delete should not be called on the return value
1085   new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1086 }
1087
1088 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1089 template< typename T >
1090 class IndexBufferMessage : public MessageBase
1091 {
1092 public:
1093
1094   /**
1095    * Constructor which does a Vector::Swap()
1096    */
1097   IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
1098   : MessageBase(),
1099     mManager( manager ),
1100     mRenderGeometry( geometry )
1101   {
1102     mIndices.Swap( indices );
1103   }
1104
1105   /**
1106    * Virtual destructor
1107    */
1108   virtual ~IndexBufferMessage()
1109   {
1110   }
1111
1112   /**
1113    * @copydoc MessageBase::Process
1114    */
1115   virtual void Process( BufferIndex /*bufferIndex*/ )
1116   {
1117     DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1118     mManager->SetIndexBuffer( mRenderGeometry, mIndices );
1119   }
1120
1121 private:
1122
1123   T* mManager;
1124   Render::Geometry* mRenderGeometry;
1125   Dali::Vector<unsigned short> mIndices;
1126 };
1127
1128 inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
1129 {
1130   typedef IndexBufferMessage< UpdateManager > LocalType;
1131
1132   // Reserve some memory inside the message queue
1133   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1134
1135   // Construct message in the message queue memory; note that delete should not be called on the return value
1136   new (slot) LocalType( &manager, &geometry, indices );
1137 }
1138
1139 inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
1140 {
1141   typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
1142
1143   // Reserve some memory inside the message queue
1144   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1145
1146   // Construct message in the message queue memory; note that delete should not be called on the return value
1147   new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
1148 }
1149
1150 } // namespace SceneGraph
1151
1152 } // namespace Internal
1153
1154 } // namespace Dali
1155
1156 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__