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