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