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