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