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