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