Merge "DALi Version 1.1.37" into 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) 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 struct Sampler;
63 class FrameBuffer;
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 TextureCacheDispatcher;
79 class PropertyBuffer;
80 class TextureSet;
81 class Camera;
82
83 /**
84  * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
85  * other scene graph property owning 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] textureCacheDispatcher Used for sending messages to texture cache.
106    */
107   UpdateManager( NotificationManager& notificationManager,
108                  CompleteNotificationInterface& animationFinishedNotifier,
109                  PropertyNotifier& propertyNotifier,
110                  ResourceManager& resourceManager,
111                  DiscardQueue& discardQueue,
112                  Integration::RenderController& controller,
113                  RenderManager& renderManager,
114                  RenderQueue& renderQueue,
115                  TextureCacheDispatcher& textureCacheDispatcher );
116
117   /**
118    * Destructor.
119    */
120   virtual ~UpdateManager();
121
122   // Node connection methods
123
124   /**
125    * Get the scene graph side list of RenderTasks.
126    * @param[in] systemLevel True if using the system-level overlay.
127    * @return The list of render tasks
128    */
129   RenderTaskList* GetRenderTaskList( bool systemLevel );
130
131   /**
132    * Installs a new layer as the root node.
133    * @pre The UpdateManager does not already have an installed root node.
134    * @pre The layer is of derived Node type Layer.
135    * @pre The layer does not have a parent.
136    * @param[in] layer The new root node.
137    * @param[in] systemLevel True if using the system-level overlay.
138    * @post The node is owned by UpdateManager.
139    */
140   void InstallRoot( Layer* layer, bool systemLevel );
141
142   /**
143    * Add a Node; UpdateManager takes ownership.
144    * @pre The node does not have a parent.
145    * @param[in] node The node to add.
146    */
147   void AddNode( Node* node );
148
149   /**
150    * Connect a Node to the scene-graph.
151    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
152    * @pre The node does not already have a parent.
153    * @param[in] parent The new parent node.
154    */
155   void ConnectNode( Node* parent, Node* node );
156
157   /**
158    * Disconnect a Node from the scene-graph.
159    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
160    * @pre The node has a parent.
161    * @param[in] node The node to disconnect.
162    */
163   void DisconnectNode( Node* node );
164
165   /**
166    * Destroy a Node owned by UpdateManager.
167    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
168    * In the following update, the previously queued Nodes may be deleted.
169    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
170    * @param[in] node The node to destroy.
171    */
172   void DestroyNode( Node* node );
173
174   /**
175    * Add a camera on scene
176    * @param[in] camera to add
177    */
178   void AddCamera( Camera* camera );
179
180   /**
181    * Remove a camera from scene
182    * @param[in] camera to remove
183    */
184   void RemoveCamera( const Camera* camera );
185
186   /**
187    * Add a newly created object.
188    * @param[in] object The object to add.
189    * @post The object is owned by UpdateManager.
190    */
191   void AddObject( PropertyOwner* object );
192
193   /**
194    * Remove an object.
195    * @param[in] object The object to remove.
196    */
197   void RemoveObject( PropertyOwner* object );
198
199   // Animations
200
201   /**
202    * Add a newly created animation.
203    * @param[in] animation The animation to add.
204    * @post The animation is owned by UpdateManager.
205    */
206   void AddAnimation( Animation* animation );
207
208   /**
209    * Stop an animation.
210    * @param[in] animation The animation to stop.
211    */
212   void StopAnimation( Animation* animation );
213
214   /**
215    * Remove an animation.
216    * @param[in] animation The animation to remove.
217    */
218   void RemoveAnimation( Animation* animation );
219
220   /**
221    * Query whether any animations are currently running.
222    * @return True if any animations are running.
223    */
224   bool IsAnimationRunning() const;
225
226   // Property Notification
227
228   /**
229    * Add a newly created property notification
230    * @param[in] propertyNotification The notification to add
231    * @post The propertyNotification is owned by UpdateManager.
232    */
233   void AddPropertyNotification( PropertyNotification* propertyNotification );
234
235   /**
236    * Remove a property notification
237    * @param[in] propertyNotification The notification to remove
238    */
239   void RemovePropertyNotification( PropertyNotification* propertyNotification );
240
241   /**
242    * Set Notify state for PropertyNotification
243    * @param[in] propertyNotification The notification to remove
244    * @param[in] notifyMode The notification mode.
245    */
246   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
247
248   /**
249    * @brief Get the renderer owner
250    *
251    * @return The renderer owner
252    */
253   ObjectOwnerContainer< Renderer >& GetRendererOwner();
254
255   /**
256    * @brief Get the property buffer owner
257    *
258    * @return The property buffer owner
259    */
260   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
261
262
263   // Shaders
264
265   /**
266    * Add a newly created shader.
267    * @param[in] shader The shader to add.
268    * @post The shader is owned by the UpdateManager.
269    */
270   void AddShader(Shader* shader);
271
272   /**
273    * Remove a shader.
274    * @pre The shader has been added to the UpdateManager.
275    * @param[in] shader The shader to remove.
276    * @post The shader is destroyed.
277    */
278   void RemoveShader(Shader* shader);
279
280   /**
281    * Add a newly created TextureSet.
282    * @param[in] textureSet The texture set to add.
283    * @post The TextureSet is owned by the UpdateManager.
284    */
285   void AddTextureSet(TextureSet* textureSet);
286
287   /**
288    * Remove a TextureSet.
289    * @pre The TextureSet has been added to the UpdateManager.
290    * @param[in] textureSet The TextureSet to remove.
291    * @post The TextureSet is destroyed.
292    */
293   void RemoveTextureSet(TextureSet* textureSet);
294
295   /**
296    * Set the shader program for a Shader object
297    * @param[in] shader        The shader to modify
298    * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
299    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
300    */
301   void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
302
303   /**
304    * @brief Accept compiled shaders passed back on render thread for saving.
305    * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
306    */
307   virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
308
309   /**
310    * @brief Set the destination for compiled shader binaries to be passed on to.
311    * The dispatcher passed in will be called from the update thread.
312    * @param[in] upstream A sink for ShaderDatas to be passed into.
313    */
314   void SetShaderSaver( ShaderSaver& upstream );
315
316   // Gestures
317
318   /**
319    * Add a newly created gesture.
320    * @param[in] gesture The gesture to add.
321    * @post The gesture is owned by the UpdateManager.
322    */
323   void AddGesture( PanGesture* gesture );
324
325   /**
326    * Remove a gesture.
327    * @pre The gesture has been added to the UpdateManager.
328    * @param[in] gesture The gesture to remove.
329    * @post The gesture is destroyed.
330    */
331   void RemoveGesture( PanGesture* gesture );
332
333 // Message queue handling
334
335   /**
336    * Reserve space for another message in the queue; this must then be initialized by the caller.
337    * The message will be read from the update-thread after the next FlushMessages is called.
338    * @post Calling this method may invalidate any previously returned slots.
339    * @param[in] size The message size with respect to the size of type "char".
340    * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
341    * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
342    * @return A pointer to the first char allocated for the message.
343    */
344   unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
345
346   /**
347    * @return the current event-buffer index.
348    */
349   BufferIndex GetEventBufferIndex() const
350   {
351     // inlined as its called often from event thread
352     return mSceneGraphBuffers.GetEventBufferIndex();
353   }
354
355   /**
356    * Called by the event-thread to signal that FlushQueue will be called
357    * e.g. when it has finished event processing.
358    */
359   void EventProcessingStarted();
360
361   /**
362    * Flush the set of messages, which were previously stored with QueueMessage().
363    * Calls to this thread-safe method should be minimized, to avoid thread blocking.
364    *
365    * @return True if there are messages to process.
366    */
367   bool FlushQueue();
368
369   /**
370    * Add a new sampler to RenderManager
371    * @param[in] sampler The sampler to add
372    * @post Sends a message to RenderManager to add the sampler.
373    * The sampler will be owned by RenderManager
374    */
375   void AddSampler( Render::Sampler* sampler );
376
377   /**
378    * Removes an existing sampler from RenderManager
379    * @param[in] sampler The sampler to remove
380    * @post The sampler will be destroyed in the render thread
381    */
382   void RemoveSampler( Render::Sampler* sampler );
383
384   /**
385    * Sets the filter modes for an existing sampler
386    * @param[in] sampler The sampler
387    * @param[in] minFilterMode The filter to use under minification
388    * @param[in] magFilterMode The filter to use under magnification
389    */
390   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
391
392   /**
393    * Sets the wrap mode for an existing sampler
394    * @param[in] sampler The sampler
395    * @param[in] rWrapMode Wrapping mode in z direction
396    * @param[in] sWrapMode Wrapping mode in x direction
397    * @param[in] tWrapMode Wrapping mode in y direction
398    */
399   void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
400
401   /**
402    * Add a new property buffer to RenderManager
403    * @param[in] propertryBuffer The property buffer to add
404    * @post Sends a message to RenderManager to add the property buffer.
405    * The property buffer will be owned by RenderManager
406    */
407   void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer );
408
409   /**
410    * Removes an existing PropertyBuffer from RenderManager
411    * @param[in] propertryBuffer The property buffer to remove
412    * @post The property buffer will be destroyed in the render thread
413    */
414   void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
415
416   /**
417    * Sets the format of an existing property buffer
418    * @param[in] propertyBuffer The property buffer.
419    * @param[in] format The new format of the buffer
420    * @post Sends a message to RenderManager to set the new format to the property buffer.
421    */
422   void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
423
424   /**
425    * Sets the data of an existing property buffer
426    * @param[in] propertyBuffer The property buffer.
427    * @param[in] data The new data of the buffer
428    * @param[in] size The new size of the buffer
429    * @post Sends a message to RenderManager to set the new data to the property buffer.
430    */
431   void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size);
432
433   /**
434    * Adds a geometry to the RenderManager
435    * @param[in] geometry The geometry to add
436    * @post Sends a message to RenderManager to add the Geometry
437    * The geometry will be owned by RenderManager
438    */
439   void AddGeometry( Render::Geometry* geometry );
440
441   /**
442    * Removes an existing Geometry from RenderManager
443    * @param[in] geometry The geometry to remove
444    * @post The geometry will be destroyed in the render thread
445    */
446   void RemoveGeometry( Render::Geometry* geometry );
447
448   /**
449    * Sets the geometry type of an existing Geometry
450    * @param[in] geometry The geometry
451    * @param[in] geometryType The type of the geometry
452    */
453   void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
454
455   /**
456    * Sets the index buffer to be used by a geometry
457    * @param[in] geometry The geometry
458    * @param[in] indices A vector containing the indices for the geometry
459    */
460   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
461
462   /**
463    * Adds a vertex buffer to a geomtry
464    * @param[in] geometry The geometry
465    * @param[in] propertyBuffer The property buffer
466    */
467   void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
468
469   /**
470    * Removes a vertex buffer from a geometry
471    * @param[in] geometry The geometry
472    * @param[in] propertyBuffer The property buffer
473    */
474   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
475
476   /**
477    * Adds a texture to the render manager
478    * @param[in] texture The texture to add
479    * The texture will be owned by RenderManager
480    */
481   void AddTexture( Render::NewTexture* texture );
482
483   /**
484    * Removes a texture from the render manager
485    * @param[in] texture The texture to remove
486    * @post The texture will be destroyed in the render thread
487    */
488   void RemoveTexture( Render::NewTexture* texture );
489
490   /**
491    * Uploads data to a texture owned by the RenderManager
492    * @param[in] texture The texture
493    * @param[in] buffer Vector with the data to be uploaded
494    * @param[in] params The parameters for the upload
495    */
496   void UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const TextureUploadParams& params );
497
498   /**
499    * Generates mipmaps for a texture owned by the RenderManager
500    * @param[in] texture The texture
501    */
502   void GenerateMipmaps( Render::NewTexture* texture );
503
504   /**
505    * Adds a framebuffer to the render manager
506    * @param[in] frameBuffer The framebuffer to add
507    * The framebuffer will be owned by RenderManager
508    */
509   void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
510
511   /**
512    * Removes a FrameBuffer from the render manager
513    * @param[in] frameBuffer The FrameBuffer to remove
514    * @post The FrameBuffer will be destroyed in the render thread
515    */
516   void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
517
518   /**
519    * Attach a texture as color output to an existing FrameBuffer
520    * @param[in] frameBuffer The FrameBuffer
521    * @param[in] texture The texture that will be used as output when rendering
522    * @param[in] mipmapLevel The mipmap of the texture to be attached
523    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
524    */
525   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int face );
526
527   /**
528    * Attach a texture as depth-stencil to an existing FrameBuffer
529    * @param[in] frameBuffer The FrameBuffer
530    * @param[in] texture The texture that will be used as depth-stencil buffer when rendering
531    */
532   void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture );
533
534 public:
535
536   /**
537    * Performs an Update traversal on the scene-graph.
538    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
539    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
540    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
541    * @return True if further updates are required e.g. during animations.
542    */
543   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
544
545   /**
546    * Set the background color i.e. the glClear color used at the beginning of each frame.
547    * @param[in] color The new background color.
548    */
549   void SetBackgroundColor(const Vector4& color);
550
551   /**
552    * Set the default surface rect.
553    * @param[in] rect The rect value representing the surface.
554    */
555   void SetDefaultSurfaceRect( const Rect<int>& rect );
556
557   /**
558    * @copydoc Dali::Stage::KeepRendering()
559    */
560   void KeepRendering( float durationSeconds );
561
562   /**
563    * Sets the depths of all layers.
564    * @param layers The layers in depth order.
565    * @param[in] systemLevel True if using the system-level overlay.
566    */
567   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
568
569 private:
570
571   // Undefined
572   UpdateManager(const UpdateManager&);
573
574   // Undefined
575   UpdateManager& operator=(const UpdateManager& rhs);
576
577   /**
578    * Helper to check whether the update-thread should keep going.
579    * @param[in] elapsedSeconds The time in seconds since the previous update.
580    * @return True if the update-thread should keep going.
581    */
582   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
583
584   /**
585    * Post process resources that have been updated by renderer
586    */
587   void PostProcessResources();
588
589   /**
590    * Helper to reset all Node properties
591    * @param[in] bufferIndex to use
592    */
593   void ResetProperties( BufferIndex bufferIndex );
594
595   /**
596    * Perform gesture updates.
597    * @param[in] bufferIndex to use
598    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
599    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
600    * @return true, if any properties were updated.
601    */
602   bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
603
604   /**
605    * Perform animation updates
606    * @param[in] bufferIndex to use
607    * @param[in] elapsedSeconds time since last frame
608    */
609   void Animate( BufferIndex bufferIndex, float elapsedSeconds );
610
611   /**
612    * Applies constraints to CustomObjects
613    * @param[in] bufferIndex to use
614    */
615   void ConstrainCustomObjects( BufferIndex bufferIndex );
616
617   /**
618    * Applies constraints to RenderTasks
619    * @param[in] bufferIndex to use
620    */
621   void ConstrainRenderTasks( BufferIndex bufferIndex );
622
623   /**
624    * Applies constraints to Shaders
625    * @param[in] bufferIndex to use
626    */
627   void ConstrainShaders( BufferIndex bufferIndex );
628
629   /**
630    * Perform property notification updates
631    * @param[in] bufferIndex to use
632    */
633   void ProcessPropertyNotifications( BufferIndex bufferIndex );
634
635   /**
636    * Prepare textures for rendering
637    */
638   void PrepareTextureSets( BufferIndex bufferIndex );
639
640   /**
641    * Pass shader binaries queued here on to event thread.
642    */
643   void ForwardCompiledShadersToEventThread();
644
645   /**
646    * Update node shaders, opacity, geometry etc.
647    * @param[in] bufferIndex to use
648    */
649   void UpdateNodes( BufferIndex bufferIndex );
650
651   /**
652    * Update Renderers
653    * @param[in] bufferIndex to use
654    */
655   void UpdateRenderers( BufferIndex bufferIndex );
656
657 private:
658
659   // needs to be direct member so that getter for event buffer can be inlined
660   SceneGraphBuffers mSceneGraphBuffers;
661
662   struct Impl;
663   Impl* mImpl;
664
665 };
666
667 // Messages for UpdateManager
668
669 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
670 {
671   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
672
673   // Reserve some memory inside the message queue
674   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
675
676   // Construct message in the message queue memory; note that delete should not be called on the return value
677   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
678 }
679
680 inline void AddNodeMessage( UpdateManager& manager, Node& node )
681 {
682   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
683
684   // Reserve some memory inside the message queue
685   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
686
687   // Construct message in the message queue memory; note that delete should not be called on the return value
688   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
689 }
690
691 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
692 {
693   // Update thread can edit the object
694   Node& parent = const_cast< Node& >( constParent );
695   Node& child = const_cast< Node& >( constChild );
696
697   typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
698
699   // Reserve some memory inside the message queue
700   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
701
702   // Construct message in the message queue memory; note that delete should not be called on the return value
703   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
704 }
705
706 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
707 {
708   // Scene graph thread can modify this object.
709   Node& node = const_cast< Node& >( constNode );
710
711   typedef MessageValue1< UpdateManager, Node* > 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::DisconnectNode, &node );
718 }
719
720 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
721 {
722   // Scene graph thread can destroy this object.
723   Node& node = const_cast< Node& >( constNode );
724
725   typedef MessageValue1< UpdateManager, Node* > LocalType;
726
727   // Reserve some memory inside the message queue
728   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
729
730   // Construct message in the message queue memory; note that delete should not be called on the return value
731   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
732 }
733
734 inline void AddCameraMessage( UpdateManager& manager, const Camera* constCamera )
735 {
736   typedef MessageValue1< UpdateManager, Camera* > LocalType;
737
738   Camera* camera = const_cast<Camera*>( constCamera );
739   // Reserve some memory inside the message queue
740   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
741
742   // Construct message in the message queue memory; note that delete should not be called on the return value
743   new (slot) LocalType( &manager, &UpdateManager::AddCamera, camera );
744 }
745
746 inline void RemoveCameraMessage( UpdateManager& manager, const Camera* camera )
747 {
748   typedef MessageValue1< UpdateManager, const Camera* > LocalType;
749
750   // Reserve some memory inside the message queue
751   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
752
753   // Construct message in the message queue memory; note that delete should not be called on the return value
754   new (slot) LocalType( &manager, &UpdateManager::RemoveCamera, camera );
755 }
756
757 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
758 {
759   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
760
761   // Reserve some memory inside the message queue
762   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
763
764   // Construct message in the message queue memory; note that delete should not be called on the return value
765   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
766 }
767
768 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
769 {
770   typedef MessageValue1< UpdateManager, PropertyOwner* > 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::RemoveObject, object );
777 }
778
779 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
780 {
781   typedef MessageValue1< UpdateManager, Animation* > LocalType;
782
783   // Reserve some memory inside the message queue
784   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
785
786   // Construct message in the message queue memory; note that delete should not be called on the return value
787   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
788 }
789
790 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
791 {
792   // The scene-graph thread owns this object so it can safely edit it.
793   Animation& animation = const_cast< Animation& >( constAnimation );
794
795   typedef MessageValue1< UpdateManager, Animation* > LocalType;
796
797   // Reserve some memory inside the message queue
798   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
799
800   // Construct message in the message queue memory; note that delete should not be called on the return value
801   new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
802 }
803
804 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
805 {
806   // The scene-graph thread owns this object so it can safely edit it.
807   Animation& animation = const_cast< Animation& >( constAnimation );
808
809   typedef MessageValue1< UpdateManager, Animation* > LocalType;
810
811   // Reserve some memory inside the message queue
812   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
813
814   // Construct message in the message queue memory; note that delete should not be called on the return value
815   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
816 }
817
818 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
819 {
820   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
821
822   // Reserve some memory inside the message queue
823   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
824
825   // Construct message in the message queue memory; note that delete should not be called on the return value
826   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
827 }
828
829 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
830 {
831   // The scene-graph thread owns this object so it can safely edit it.
832   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
833
834   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
835
836   // Reserve some memory inside the message queue
837   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
838
839   // Construct message in the message queue memory; note that delete should not be called on the return value
840   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
841 }
842
843 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
844                                                       const PropertyNotification* constPropertyNotification,
845                                                       PropertyNotification::NotifyMode notifyMode )
846 {
847   // The scene-graph thread owns this object so it can safely edit it.
848   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
849
850   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
851
852   // Reserve some memory inside the message queue
853   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
854
855   // Construct message in the message queue memory; note that delete should not be called on the return value
856   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
857 }
858
859 // The render thread can safely change the Shader
860 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
861 {
862   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > 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::AddShader, &shader );
869 }
870
871 // The render thread can safely change the Shader
872 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
873 {
874   typedef MessageValue1< UpdateManager, Shader* > LocalType;
875
876   // Reserve some memory inside the message queue
877   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
878
879   // Construct message in the message queue memory; note that delete should not be called on the return value
880   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
881 }
882
883 inline void SetShaderProgramMessage( UpdateManager& manager,
884                                      Shader& shader,
885                                      Internal::ShaderDataPtr shaderData,
886                                      bool modifiesGeometry )
887 {
888   typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
889
890   // Reserve some memory inside the message queue
891   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
892
893   // Construct message in the message queue memory; note that delete should not be called on the return value
894   new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
895 }
896
897 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
898 {
899   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
900
901   // Reserve some memory inside the message queue
902   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
903
904   // Construct message in the message queue memory; note that delete should not be called on the return value
905   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
906 }
907
908 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
909 {
910   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
911
912   // Reserve some memory inside the message queue
913   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
914
915   // Construct message in the message queue memory; note that delete should not be called on the return value
916   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
917 }
918
919 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
920 {
921   typedef MessageValue1< UpdateManager, float > LocalType;
922
923   // Reserve some memory inside the message queue
924   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
925
926   // Construct message in the message queue memory; note that delete should not be called on the return value
927   new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
928 }
929
930 /**
931  * Create a message for setting the depth of a layer
932  * @param[in] manager The update manager
933  * @param[in] layers list of layers
934  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
935  */
936 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
937 {
938   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
939
940   // Reserve some memory inside the message queue
941   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
942
943   // Construct message in the message queue memory; note that delete should not be called on the return value
944   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
945 }
946
947 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
948 {
949   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
950
951   // Reserve some memory inside the message queue
952   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
953
954   // Construct message in the message queue memory; note that delete should not be called on the return value
955   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
956 }
957
958 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
959 {
960   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
961
962   // Reserve some memory inside the message queue
963   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
964
965   // Construct message in the message queue memory; note that delete should not be called on the return value
966   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
967 }
968
969 template< typename T >
970 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
971 {
972   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
973
974   // Reserve some memory inside the message queue
975   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
976   // Construct message in the message queue memory; note that delete should not be called on the return value
977   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
978 }
979
980 template< typename T >
981 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
982 {
983   typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
984
985   // Reserve some memory inside the message queue
986   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
987   // Construct message in the message queue memory; note that delete should not be called on the return value
988   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
989 }
990
991 // The render thread can safely change the Shader
992 inline void AddTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
993 {
994   typedef MessageValue1< UpdateManager, OwnerPointer< TextureSet > > LocalType;
995
996   // Reserve some memory inside the message queue
997   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
998
999   // Construct message in the message queue memory; note that delete should not be called on the return value
1000   new (slot) LocalType( &manager, &UpdateManager::AddTextureSet, &textureSet );
1001 }
1002
1003 // The render thread can safely change the Shader
1004 inline void RemoveTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
1005 {
1006   typedef MessageValue1< UpdateManager, TextureSet* > LocalType;
1007
1008   // Reserve some memory inside the message queue
1009   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1010
1011   // Construct message in the message queue memory; note that delete should not be called on the return value
1012   new (slot) LocalType( &manager, &UpdateManager::RemoveTextureSet, &textureSet );
1013 }
1014
1015 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1016 {
1017   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
1018
1019   // Reserve some memory inside the message queue
1020   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1021
1022   // Construct message in the message queue memory; note that delete should not be called on the return value
1023   new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
1024 }
1025
1026 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1027 {
1028   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
1029
1030   // Reserve some memory inside the message queue
1031   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1032
1033   // Construct message in the message queue memory; note that delete should not be called on the return value
1034   new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
1035 }
1036
1037 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
1038 {
1039   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
1040
1041   // Reserve some memory inside the message queue
1042   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1043
1044   // Construct message in the message queue memory; note that delete should not be called on the return value
1045   new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
1046 }
1047
1048 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
1049 {
1050   typedef MessageValue4< UpdateManager, Render::Sampler*, unsigned int, unsigned int, unsigned int > LocalType;
1051
1052   // Reserve some memory inside the message queue
1053   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1054
1055   // Construct message in the message queue memory; note that delete should not be called on the return value
1056   new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, rWrapMode, sWrapMode, tWrapMode );
1057 }
1058
1059 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1060 {
1061   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
1062
1063   // Reserve some memory inside the message queue
1064   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1065
1066   // Construct message in the message queue memory; note that delete should not be called on the return value
1067   new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
1068 }
1069
1070 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1071 {
1072   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
1073
1074   // Reserve some memory inside the message queue
1075   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1076
1077   // Construct message in the message queue memory; note that delete should not be called on the return value
1078   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
1079 }
1080
1081 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
1082 {
1083   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format*  > LocalType;
1084
1085   // Reserve some memory inside the message queue
1086   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1087
1088   // Construct message in the message queue memory; note that delete should not be called on the return value
1089   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
1090 }
1091
1092 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data, size_t size )
1093 {
1094   typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, Vector<char>*, size_t  > LocalType;
1095
1096   // Reserve some memory inside the message queue
1097   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1098
1099   // Construct message in the message queue memory; note that delete should not be called on the return value
1100   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
1101 }
1102
1103 inline void AddGeometry( UpdateManager& manager, Render::Geometry& geometry )
1104 {
1105   typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
1106
1107   // Reserve some memory inside the message queue
1108   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1109
1110   // Construct message in the message queue memory; note that delete should not be called on the return value
1111   new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
1112 }
1113
1114 inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
1115 {
1116   typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
1117
1118   // Reserve some memory inside the message queue
1119   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1120
1121   // Construct message in the message queue memory; note that delete should not be called on the return value
1122   new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
1123 }
1124
1125 inline void AddVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1126 {
1127   typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1128
1129   // Reserve some memory inside the message queue
1130   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1131
1132   // Construct message in the message queue memory; note that delete should not be called on the return value
1133   new (slot) LocalType( &manager, &UpdateManager::AddVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1134 }
1135
1136 inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1137 {
1138   typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1139
1140   // Reserve some memory inside the message queue
1141   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1142
1143   // Construct message in the message queue memory; note that delete should not be called on the return value
1144   new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1145 }
1146
1147 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1148 template< typename T >
1149 class IndexBufferMessage : public MessageBase
1150 {
1151 public:
1152
1153   /**
1154    * Constructor which does a Vector::Swap()
1155    */
1156   IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
1157   : MessageBase(),
1158     mManager( manager ),
1159     mRenderGeometry( geometry )
1160   {
1161     mIndices.Swap( indices );
1162   }
1163
1164   /**
1165    * Virtual destructor
1166    */
1167   virtual ~IndexBufferMessage()
1168   {
1169   }
1170
1171   /**
1172    * @copydoc MessageBase::Process
1173    */
1174   virtual void Process( BufferIndex /*bufferIndex*/ )
1175   {
1176     DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1177     mManager->SetIndexBuffer( mRenderGeometry, mIndices );
1178   }
1179
1180 private:
1181
1182   T* mManager;
1183   Render::Geometry* mRenderGeometry;
1184   Dali::Vector<unsigned short> mIndices;
1185 };
1186
1187 inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
1188 {
1189   typedef IndexBufferMessage< UpdateManager > LocalType;
1190
1191   // Reserve some memory inside the message queue
1192   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1193
1194   // Construct message in the message queue memory; note that delete should not be called on the return value
1195   new (slot) LocalType( &manager, &geometry, indices );
1196 }
1197
1198 inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
1199 {
1200   typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
1201
1202   // Reserve some memory inside the message queue
1203   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1204
1205   // Construct message in the message queue memory; note that delete should not be called on the return value
1206   new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
1207 }
1208
1209 inline void AddTexture( UpdateManager& manager, Render::NewTexture& texture )
1210 {
1211   typedef MessageValue1< UpdateManager, Render::NewTexture*  > LocalType;
1212
1213   // Reserve some memory inside the message queue
1214   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1215
1216   // Construct message in the message queue memory; note that delete should not be called on the return value
1217   new (slot) LocalType( &manager, &UpdateManager::AddTexture, &texture );
1218 }
1219
1220 inline void RemoveTexture( UpdateManager& manager, Render::NewTexture& texture )
1221 {
1222   typedef MessageValue1< UpdateManager, Render::NewTexture*  > LocalType;
1223
1224   // Reserve some memory inside the message queue
1225   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1226
1227   // Construct message in the message queue memory; note that delete should not be called on the return value
1228   new (slot) LocalType( &manager, &UpdateManager::RemoveTexture, &texture );
1229 }
1230
1231 template< typename T >
1232 class UploadTextureDataMessage : public MessageBase
1233 {
1234 public:
1235
1236   /**
1237    * Constructor which does a Vector::Swap()
1238    */
1239   UploadTextureDataMessage( T* manager, Render::NewTexture* texture, Dali::Vector<unsigned char>& data, const Dali::TextureUploadParams& params )
1240   : MessageBase(),
1241     mManager( manager ),
1242     mRenderTexture( texture ),
1243     mParams( params )
1244   {
1245     mData.Swap( data );
1246   }
1247
1248   /**
1249    * Virtual destructor
1250    */
1251   virtual ~UploadTextureDataMessage()
1252   {
1253   }
1254
1255   /**
1256    * @copydoc MessageBase::Process
1257    */
1258   virtual void Process( BufferIndex /*bufferIndex*/ )
1259   {
1260     DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1261     mManager->UploadTexture( mRenderTexture, mData, mParams );
1262   }
1263
1264 private:
1265
1266   T* mManager;
1267   Render::NewTexture* mRenderTexture;
1268   Dali::Vector<unsigned char> mData;
1269   Dali::TextureUploadParams mParams;
1270 };
1271
1272 inline void UploadTextureMessage( UpdateManager& manager, Render::NewTexture& texture, Dali::Vector<unsigned char>& data, const Dali::TextureUploadParams& params )
1273 {
1274   typedef UploadTextureDataMessage< UpdateManager > LocalType;
1275
1276   // Reserve some memory inside the message queue
1277   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1278
1279   // Construct message in the message queue memory; note that delete should not be called on the return value
1280   new (slot) LocalType( &manager, &texture, data, params );
1281 }
1282
1283 inline void GenerateMipmapsMessage( UpdateManager& manager, Render::NewTexture& texture )
1284 {
1285   typedef MessageValue1< UpdateManager, Render::NewTexture*  > LocalType;
1286
1287   // Reserve some memory inside the message queue
1288   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1289
1290   // Construct message in the message queue memory; note that delete should not be called on the return value
1291   new (slot) LocalType( &manager, &UpdateManager::GenerateMipmaps, &texture );
1292 }
1293
1294
1295 inline void AddFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1296 {
1297   typedef MessageValue1< UpdateManager, Render::FrameBuffer*  > LocalType;
1298
1299   // Reserve some memory inside the message queue
1300   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1301
1302   // Construct message in the message queue memory; note that delete should not be called on the return value
1303   new (slot) LocalType( &manager, &UpdateManager::AddFrameBuffer, &frameBuffer );
1304 }
1305
1306 inline void RemoveFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1307 {
1308   typedef MessageValue1< UpdateManager, Render::FrameBuffer*  > LocalType;
1309
1310   // Reserve some memory inside the message queue
1311   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1312
1313   // Construct message in the message queue memory; note that delete should not be called on the return value
1314   new (slot) LocalType( &manager, &UpdateManager::RemoveFrameBuffer, &frameBuffer );
1315 }
1316
1317 inline void AttachColorTextureToFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer )
1318 {
1319   typedef MessageValue4< UpdateManager, Render::FrameBuffer*, Render::NewTexture*, unsigned int, unsigned int  > LocalType;
1320
1321   // Reserve some memory inside the message queue
1322   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1323
1324   // Construct message in the message queue memory; note that delete should not be called on the return value
1325   new (slot) LocalType( &manager, &UpdateManager::AttachColorTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel, layer );
1326 }
1327
1328 } // namespace SceneGraph
1329
1330 } // namespace Internal
1331
1332 } // namespace Dali
1333
1334 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__