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