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