8499642c9622bf213667066a53fc2552ff58ff77
[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) 2023 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    * Sets the depths of all layers.
687    * @param layers The layers in depth order.
688    * @param[in] rootLayer The root layer of the sorted layers.
689    */
690   void SetLayerDepths(const std::vector<Layer*>& layers, const Layer* rootLayer);
691
692   /**
693    * Set the depth indices of all nodes (in LayerUI's)
694    * @param[in] nodeDepths A vector of nodes and associated depth indices
695    */
696   void SetDepthIndices(OwnerPointer<NodeDepths>& nodeDepths);
697
698   /**
699    * Adds an implementation of the FrameCallbackInterface.
700    * @param[in] frameCallback An OwnerPointer to the SceneGraph FrameCallback object
701    * @param[in] rootNode A pointer to the root node to apply the FrameCallback to
702    */
703   void AddFrameCallback(OwnerPointer<FrameCallback>& frameCallback, const Node* rootNode);
704
705   /**
706    * Removes the specified implementation of FrameCallbackInterface.
707    * @param[in] frameCallback A pointer to the implementation of the FrameCallbackInterface to remove.
708    */
709   void RemoveFrameCallback(FrameCallbackInterface* frameCallback);
710
711   /**
712    * Notify the specified implementation of FrameCallbackInterface with the given sync point.
713    * @param[in] frameCallback A pointer to the implementation of the FrameCallbackInterface to notify.
714    * @param[in] syncPoint The unique sync point to notify with.
715    */
716   void NotifyFrameCallback(FrameCallbackInterface* frameCallback, Dali::UpdateProxy::NotifySyncPoint syncPoint);
717
718   /**
719    * Get the update message queue capacity (mutex locked)
720    */
721   std::size_t GetUpdateMessageQueueCapacity() const;
722
723   /**
724    * Get the render message queue capacity
725    */
726   std::size_t GetRenderMessageQueueCapacity() const;
727
728   /**
729    * Get the render instruction capacity
730    */
731   std::size_t GetRenderInstructionCapacity() const;
732
733 private:
734   // Undefined
735   UpdateManager(const UpdateManager&);
736
737   // Undefined
738   UpdateManager& operator=(const UpdateManager& rhs);
739
740   /**
741    * Add a camera on scene
742    * @param[in] camera The camera to add
743    */
744   void AddCamera(Camera* camera);
745
746   /**
747    * Remove a camera from scene
748    * @param[in] camera to remove
749    */
750   void RemoveCamera(Camera* camera);
751
752   /**
753    * Helper to check whether the update-thread should keep going.
754    * @param[in] elapsedSeconds The time in seconds since the previous update.
755    * @return True if the update-thread should keep going.
756    */
757   uint32_t KeepUpdatingCheck(float elapsedSeconds) const;
758
759   /**
760    * Helper to reset all Node properties
761    * @param[in] bufferIndex to use
762    */
763   void ResetProperties(BufferIndex bufferIndex);
764
765   /**
766    * Perform gesture updates.
767    * @param[in] bufferIndex to use
768    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
769    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
770    * @return true, if any properties were updated.
771    */
772   bool ProcessGestures(BufferIndex bufferIndex, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds);
773
774   /**
775    * Perform animation updates
776    * @param[in] bufferIndex to use
777    * @param[in] elapsedSeconds time since last frame
778    * @return true if at least one animations is currently active or false otherwise
779    */
780   bool Animate(BufferIndex bufferIndex, float elapsedSeconds);
781
782   /**
783    * Applies constraints to CustomObjects
784    * @param[out] postPropertyOwner property owners those have post constraint.
785    * @param[in] bufferIndex to use
786    */
787   void ConstrainCustomObjects(PropertyOwnerContainer& postPropertyOwners, BufferIndex bufferIndex);
788
789   /**
790    * Applies constraints to RenderTasks
791    * @param[out] postPropertyOwner property owners those have post constraint.
792    * @param[in] bufferIndex to use
793    */
794   void ConstrainRenderTasks(PropertyOwnerContainer& postPropertyOwners, BufferIndex bufferIndex);
795
796   /**
797    * Applies constraints to Shaders
798    * @param[out] postPropertyOwner property owners those have post constraint.
799    * @param[in] bufferIndex to use
800    */
801   void ConstrainShaders(PropertyOwnerContainer& postPropertyOwners, BufferIndex bufferIndex);
802
803   /**
804    * Perform property notification updates
805    * @param[in] bufferIndex to use
806    */
807   void ProcessPropertyNotifications(BufferIndex bufferIndex);
808
809   /**
810    * Pass shader binaries queued here on to event thread.
811    */
812   void ForwardCompiledShadersToEventThread();
813
814   /**
815    * Update node shaders, opacity, geometry etc.
816    * @param[out] postPropertyOwner property owners those have post constraint.
817    * @param[in] bufferIndex to use
818    */
819   void UpdateNodes(PropertyOwnerContainer& postPropertyOwners, BufferIndex bufferIndex);
820
821   /**
822    * initialize layer renderables
823    * @param[in] bufferIndex
824    */
825   void UpdateLayers(BufferIndex bufferIndex);
826
827   /**
828    * Update Renderers
829    * @param[out] postPropertyOwner property owners those have post constraint.
830    * @param[in] bufferIndex to use
831    */
832   void UpdateRenderers(PropertyOwnerContainer& postPropertyOwners, BufferIndex bufferIndex);
833
834 private:
835   // needs to be direct member so that getter for event buffer can be inlined
836   SceneGraphBuffers mSceneGraphBuffers;
837
838   struct Impl;
839   Impl* mImpl;
840 };
841
842 // Messages for UpdateManager
843
844 inline void InstallRootMessage(UpdateManager& manager, OwnerPointer<Layer>& root)
845 {
846   // Message has ownership of Layer while in transit from event -> update
847   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Layer>>;
848
849   // Reserve some memory inside the message queue
850   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
851
852   // Construct message in the message queue memory; note that delete should not be called on the return value
853   new(slot) LocalType(&manager, &UpdateManager::InstallRoot, root);
854 }
855
856 inline void UninstallRootMessage(UpdateManager& manager, const Layer* constRoot)
857 {
858   // Scene graph thread can destroy this object.
859   Layer* root = const_cast<Layer*>(constRoot);
860
861   using LocalType = MessageValue1<UpdateManager, Layer*>;
862
863   // Reserve some memory inside the message queue
864   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
865
866   // Construct message in the message queue memory; note that delete should not be called on the return value
867   new(slot) LocalType(&manager, &UpdateManager::UninstallRoot, root);
868 }
869
870 inline void AddNodeMessage(UpdateManager& manager, OwnerPointer<Node>& node)
871 {
872   // Message has ownership of Node while in transit from event -> update
873   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Node>>;
874
875   // Reserve some memory inside the message queue
876   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
877
878   // Construct message in the message queue memory; note that delete should not be called on the return value
879   new(slot) LocalType(&manager, &UpdateManager::AddNode, node);
880 }
881
882 inline void ConnectNodeMessage(UpdateManager& manager, const Node& constParent, const Node& constChild)
883 {
884   // Update thread can edit the object
885   Node& parent = const_cast<Node&>(constParent);
886   Node& child  = const_cast<Node&>(constChild);
887
888   using LocalType = MessageValue2<UpdateManager, Node*, Node*>;
889
890   // Reserve some memory inside the message queue
891   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
892
893   // Construct message in the message queue memory; note that delete should not be called on the return value
894   new(slot) LocalType(&manager, &UpdateManager::ConnectNode, &parent, &child);
895 }
896
897 inline void DisconnectNodeMessage(UpdateManager& manager, const Node& constNode)
898 {
899   // Scene graph thread can modify this object.
900   Node& node = const_cast<Node&>(constNode);
901
902   using LocalType = MessageValue1<UpdateManager, Node*>;
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::DisconnectNode, &node);
909 }
910
911 inline void DestroyNodeMessage(UpdateManager& manager, const Node& constNode)
912 {
913   // Scene graph thread can destroy this object.
914   Node& node = const_cast<Node&>(constNode);
915
916   using LocalType = MessageValue1<UpdateManager, Node*>;
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::DestroyNode, &node);
923 }
924
925 inline void AddObjectMessage(UpdateManager& manager, OwnerPointer<PropertyOwner>& object)
926 {
927   // Message has ownership of object while in transit from event -> update
928   using LocalType = MessageValue1<UpdateManager, OwnerPointer<PropertyOwner>>;
929
930   // Reserve some memory inside the message queue
931   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
932
933   // Construct message in the message queue memory; note that delete should not be called on the return value
934   new(slot) LocalType(&manager, &UpdateManager::AddObject, object);
935 }
936
937 inline void RemoveObjectMessage(UpdateManager& manager, const PropertyOwner* object)
938 {
939   using LocalType = MessageValue1<UpdateManager, PropertyOwner*>;
940
941   // Reserve some memory inside the message queue
942   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
943
944   // Construct message in the message queue memory; note that delete should not be called on the return value
945   new(slot) LocalType(&manager, &UpdateManager::RemoveObject, const_cast<PropertyOwner*>(object));
946 }
947
948 inline void AddAnimationMessage(UpdateManager& manager, OwnerPointer<SceneGraph::Animation>& animation)
949 {
950   using LocalType = MessageValue1<UpdateManager, OwnerPointer<SceneGraph::Animation>>;
951
952   // Reserve some memory inside the message queue
953   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
954
955   // Construct message in the message queue memory; note that delete should not be called on the return value
956   new(slot) LocalType(&manager, &UpdateManager::AddAnimation, animation);
957 }
958
959 inline void StopAnimationMessage(UpdateManager& manager, const Animation& constAnimation)
960 {
961   // The scene-graph thread owns this object so it can safely edit it.
962   Animation& animation = const_cast<Animation&>(constAnimation);
963
964   using LocalType = MessageValue1<UpdateManager, Animation*>;
965
966   // Reserve some memory inside the message queue
967   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
968
969   // Construct message in the message queue memory; note that delete should not be called on the return value
970   new(slot) LocalType(&manager, &UpdateManager::StopAnimation, &animation);
971 }
972
973 inline void RemoveAnimationMessage(UpdateManager& manager, const Animation& constAnimation)
974 {
975   // The scene-graph thread owns this object so it can safely edit it.
976   Animation& animation = const_cast<Animation&>(constAnimation);
977
978   using LocalType = MessageValue1<UpdateManager, Animation*>;
979
980   // Reserve some memory inside the message queue
981   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
982
983   // Construct message in the message queue memory; note that delete should not be called on the return value
984   new(slot) LocalType(&manager, &UpdateManager::RemoveAnimation, &animation);
985 }
986
987 inline void AddRenderTaskListMessage(UpdateManager& manager, OwnerPointer<SceneGraph::RenderTaskList>& taskList)
988 {
989   using LocalType = MessageValue1<UpdateManager, OwnerPointer<SceneGraph::RenderTaskList>>;
990
991   // Reserve some memory inside the message queue
992   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
993
994   // Construct message in the message queue memory; note that delete should not be called on the return value
995   new(slot) LocalType(&manager, &UpdateManager::AddRenderTaskList, taskList);
996 }
997
998 inline void RemoveRenderTaskListMessage(UpdateManager& manager, const RenderTaskList& constTaskList)
999 {
1000   // The scene-graph thread owns this object so it can safely edit it.
1001   RenderTaskList& taskList = const_cast<RenderTaskList&>(constTaskList);
1002
1003   using LocalType = MessageValue1<UpdateManager, RenderTaskList*>;
1004
1005   // Reserve some memory inside the message queue
1006   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1007
1008   // Construct message in the message queue memory; note that delete should not be called on the return value
1009   new(slot) LocalType(&manager, &UpdateManager::RemoveRenderTaskList, &taskList);
1010 }
1011
1012 inline void AddSceneMessage(UpdateManager& manager, OwnerPointer<SceneGraph::Scene>& scene)
1013 {
1014   using LocalType = MessageValue1<UpdateManager, OwnerPointer<SceneGraph::Scene>>;
1015
1016   // Reserve some memory inside the message queue
1017   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1018
1019   // Construct message in the message queue memory; note that delete should not be called on the return value
1020   new(slot) LocalType(&manager, &UpdateManager::AddScene, scene);
1021 }
1022
1023 inline void RemoveSceneMessage(UpdateManager& manager, const SceneGraph::Scene& constScene)
1024 {
1025   // The scene-graph thread owns this object so it can safely edit it.
1026   Scene& scene = const_cast<Scene&>(constScene);
1027
1028   using LocalType = MessageValue1<UpdateManager, Scene*>;
1029
1030   // Reserve some memory inside the message queue
1031   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1032
1033   // Construct message in the message queue memory; note that delete should not be called on the return value
1034   new(slot) LocalType(&manager, &UpdateManager::RemoveScene, &scene);
1035 }
1036
1037 inline void AddPropertyNotificationMessage(UpdateManager& manager, OwnerPointer<PropertyNotification>& propertyNotification)
1038 {
1039   // Message has ownership of PropertyNotification while in transit from event -> update
1040   using LocalType = MessageValue1<UpdateManager, OwnerPointer<PropertyNotification>>;
1041
1042   // Reserve some memory inside the message queue
1043   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1044
1045   // Construct message in the message queue memory; note that delete should not be called on the return value
1046   new(slot) LocalType(&manager, &UpdateManager::AddPropertyNotification, propertyNotification);
1047 }
1048
1049 inline void RemovePropertyNotificationMessage(UpdateManager& manager, const PropertyNotification& constPropertyNotification)
1050 {
1051   // The scene-graph thread owns this object so it can safely edit it.
1052   PropertyNotification& propertyNotification = const_cast<PropertyNotification&>(constPropertyNotification);
1053
1054   using LocalType = MessageValue1<UpdateManager, PropertyNotification*>;
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::RemovePropertyNotification, &propertyNotification);
1061 }
1062
1063 inline void PropertyNotificationSetNotifyModeMessage(UpdateManager&                   manager,
1064                                                      const PropertyNotification*      constPropertyNotification,
1065                                                      PropertyNotification::NotifyMode notifyMode)
1066 {
1067   // The scene-graph thread owns this object so it can safely edit it.
1068   PropertyNotification* propertyNotification = const_cast<PropertyNotification*>(constPropertyNotification);
1069
1070   using LocalType = MessageValue2<UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode>;
1071
1072   // Reserve some memory inside the message queue
1073   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1074
1075   // Construct message in the message queue memory; note that delete should not be called on the return value
1076   new(slot) LocalType(&manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode);
1077 }
1078
1079 // The render thread can safely change the Shader
1080 inline void AddShaderMessage(UpdateManager& manager, OwnerPointer<Shader>& shader)
1081 {
1082   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Shader>>;
1083
1084   // Reserve some memory inside the message queue
1085   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1086
1087   // Construct message in the message queue memory; note that delete should not be called on the return value
1088   new(slot) LocalType(&manager, &UpdateManager::AddShader, shader);
1089 }
1090
1091 // The render thread can safely change the Shader
1092 inline void RemoveShaderMessage(UpdateManager& manager, const Shader* shader)
1093 {
1094   using LocalType = MessageValue1<UpdateManager, Shader*>;
1095
1096   // Reserve some memory inside the message queue
1097   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1098
1099   // Construct message in the message queue memory; note that delete should not be called on the return value
1100   new(slot) LocalType(&manager, &UpdateManager::RemoveShader, const_cast<Shader*>(shader));
1101 }
1102
1103 inline void SurfaceReplacedMessage(UpdateManager& manager, const SceneGraph::Scene& constScene)
1104 {
1105   // The scene-graph thread owns this object so it can safely edit it.
1106   Scene& scene = const_cast<Scene&>(constScene);
1107
1108   using LocalType = MessageValue1<UpdateManager, Scene*>;
1109
1110   // Reserve some memory inside the message queue
1111   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1112
1113   // Construct message in the message queue memory; note that delete should not be called on the return value
1114   new(slot) LocalType(&manager, &UpdateManager::SurfaceReplaced, &scene);
1115 }
1116
1117 inline void KeepRenderingMessage(UpdateManager& manager, float durationSeconds)
1118 {
1119   using LocalType = MessageValue1<UpdateManager, float>;
1120
1121   // Reserve some memory inside the message queue
1122   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1123
1124   // Construct message in the message queue memory; note that delete should not be called on the return value
1125   new(slot) LocalType(&manager, &UpdateManager::KeepRendering, durationSeconds);
1126 }
1127
1128 inline void SetRenderingBehaviorMessage(UpdateManager& manager, DevelStage::Rendering renderingBehavior)
1129 {
1130   using LocalType = MessageValue1<UpdateManager, DevelStage::Rendering>;
1131
1132   // Reserve some memory inside the message queue
1133   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1134
1135   // Construct message in the message queue memory; note that delete should not be called on the return value
1136   new(slot) LocalType(&manager, &UpdateManager::SetRenderingBehavior, renderingBehavior);
1137 }
1138
1139 inline void RequestRenderingMessage(UpdateManager& manager)
1140 {
1141   using LocalType = Message<UpdateManager>;
1142
1143   // Reserve some memory inside the message queue
1144   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1145
1146   // Construct message in the message queue memory; note that delete should not be called on the return value
1147   new(slot) LocalType(&manager, &UpdateManager::RequestRendering);
1148 }
1149
1150 /**
1151  * Create a message for setting the depth of a layer
1152  * @param[in] manager The update manager
1153  * @param[in] layers list of layers
1154  * @param[in] rootLayer The rool layer
1155  */
1156 inline void SetLayerDepthsMessage(UpdateManager& manager, const std::vector<Layer*>& layers, const Layer* rootLayer)
1157 {
1158   using LocalType = MessageValue2<UpdateManager, std::vector<Layer*>, const Layer*>;
1159
1160   // Reserve some memory inside the message queue
1161   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1162
1163   // Construct message in the message queue memory; note that delete should not be called on the return value
1164   new(slot) LocalType(&manager, &UpdateManager::SetLayerDepths, layers, rootLayer);
1165 }
1166
1167 inline void AddRendererMessage(UpdateManager& manager, const RendererKey& rendererKey)
1168 {
1169   using LocalType = MessageValue1<UpdateManager, RendererKey>;
1170
1171   // Reserve some memory inside the message queue
1172   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1173   // Construct message in the message queue memory; note that delete should not be called on the return value
1174   new(slot) LocalType(&manager, &UpdateManager::AddRenderer, rendererKey);
1175 }
1176
1177 inline void RemoveRendererMessage(UpdateManager& manager, const RendererKey& rendererKey)
1178 {
1179   using LocalType = MessageValue1<UpdateManager, RendererKey>;
1180
1181   // Reserve some memory inside the message queue
1182   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1183   // Construct message in the message queue memory; note that delete should not be called on the return value
1184   new(slot) LocalType(&manager, &UpdateManager::RemoveRenderer, rendererKey);
1185 }
1186
1187 inline void AttachRendererMessage(UpdateManager& manager, const Node& node, const Renderer& renderer)
1188 {
1189   using LocalType = MessageValue2<UpdateManager, Node*, Renderer*>;
1190
1191   // Reserve some memory inside the message queue
1192   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1193   // Construct message in the message queue memory; note that delete should not be called on the return value
1194   new(slot) LocalType(&manager, &UpdateManager::AttachRenderer, const_cast<Node*>(&node), const_cast<Renderer*>(&renderer));
1195 }
1196
1197 // The render thread can safely change the Shader
1198 inline void AddTextureSetMessage(UpdateManager& manager, OwnerPointer<TextureSet>& textureSet)
1199 {
1200   using LocalType = MessageValue1<UpdateManager, OwnerPointer<TextureSet>>;
1201
1202   // Reserve some memory inside the message queue
1203   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1204
1205   // Construct message in the message queue memory; note that delete should not be called on the return value
1206   new(slot) LocalType(&manager, &UpdateManager::AddTextureSet, textureSet);
1207 }
1208
1209 // The render thread can safely change the Shader
1210 inline void RemoveTextureSetMessage(UpdateManager& manager, TextureSet& textureSet)
1211 {
1212   using LocalType = MessageValue1<UpdateManager, TextureSet*>;
1213
1214   // Reserve some memory inside the message queue
1215   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1216
1217   // Construct message in the message queue memory; note that delete should not be called on the return value
1218   new(slot) LocalType(&manager, &UpdateManager::RemoveTextureSet, &textureSet);
1219 }
1220
1221 inline void AddSamplerMessage(UpdateManager& manager, OwnerPointer<Render::Sampler>& sampler)
1222 {
1223   // Message has ownership of Sampler while in transit from event -> update
1224   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Render::Sampler>>;
1225
1226   // Reserve some memory inside the message queue
1227   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1228
1229   // Construct message in the message queue memory; note that delete should not be called on the return value
1230   new(slot) LocalType(&manager, &UpdateManager::AddSampler, sampler);
1231 }
1232
1233 inline void RemoveSamplerMessage(UpdateManager& manager, Render::Sampler& sampler)
1234 {
1235   using LocalType = MessageValue1<UpdateManager, Render::Sampler*>;
1236
1237   // Reserve some memory inside the message queue
1238   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1239
1240   // Construct message in the message queue memory; note that delete should not be called on the return value
1241   new(slot) LocalType(&manager, &UpdateManager::RemoveSampler, &sampler);
1242 }
1243
1244 inline void SetFilterModeMessage(UpdateManager& manager, Render::Sampler& sampler, uint32_t minFilterMode, uint32_t magFilterMode)
1245 {
1246   using LocalType = MessageValue3<UpdateManager, Render::Sampler*, uint32_t, uint32_t>;
1247
1248   // Reserve some memory inside the message queue
1249   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1250
1251   // Construct message in the message queue memory; note that delete should not be called on the return value
1252   new(slot) LocalType(&manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode);
1253 }
1254
1255 inline void SetWrapModeMessage(UpdateManager& manager, Render::Sampler& sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode)
1256 {
1257   using LocalType = MessageValue4<UpdateManager, Render::Sampler*, uint32_t, uint32_t, uint32_t>;
1258
1259   // Reserve some memory inside the message queue
1260   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1261
1262   // Construct message in the message queue memory; note that delete should not be called on the return value
1263   new(slot) LocalType(&manager, &UpdateManager::SetWrapMode, &sampler, rWrapMode, sWrapMode, tWrapMode);
1264 }
1265
1266 inline void AddVertexBuffer(UpdateManager& manager, OwnerPointer<Render::VertexBuffer>& vertexBuffer)
1267 {
1268   // Message has ownership of vertexBuffer while in transit from event -> update
1269   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Render::VertexBuffer>>;
1270
1271   // Reserve some memory inside the message queue
1272   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1273
1274   // Construct message in the message queue memory; note that delete should not be called on the return value
1275   new(slot) LocalType(&manager, &UpdateManager::AddVertexBuffer, vertexBuffer);
1276 }
1277
1278 inline void RemoveVertexBuffer(UpdateManager& manager, Render::VertexBuffer& vertexBuffer)
1279 {
1280   using LocalType = MessageValue1<UpdateManager, Render::VertexBuffer*>;
1281
1282   // Reserve some memory inside the message queue
1283   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1284
1285   // Construct message in the message queue memory; note that delete should not be called on the return value
1286   new(slot) LocalType(&manager, &UpdateManager::RemoveVertexBuffer, &vertexBuffer);
1287 }
1288
1289 inline void SetVertexBufferFormat(UpdateManager& manager, Render::VertexBuffer& vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format)
1290 {
1291   // Message has ownership of VertexBuffer::Format while in transit from event -> update
1292   using LocalType = MessageValue2<UpdateManager, Render::VertexBuffer*, OwnerPointer<Render::VertexBuffer::Format>>;
1293
1294   // Reserve some memory inside the message queue
1295   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1296
1297   // Construct message in the message queue memory; note that delete should not be called on the return value
1298   new(slot) LocalType(&manager, &UpdateManager::SetVertexBufferFormat, &vertexBuffer, format);
1299 }
1300
1301 inline void SetVertexBufferData(UpdateManager& manager, Render::VertexBuffer& vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size)
1302 {
1303   // Message has ownership of VertexBuffer data while in transit from event -> update
1304   using LocalType = MessageValue3<UpdateManager, Render::VertexBuffer*, OwnerPointer<Vector<uint8_t>>, uint32_t>;
1305
1306   // Reserve some memory inside the message queue
1307   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1308
1309   // Construct message in the message queue memory; note that delete should not be called on the return value
1310   new(slot) LocalType(&manager, &UpdateManager::SetVertexBufferData, &vertexBuffer, data, size);
1311 }
1312
1313 inline void SetVertexBufferDivisorMessage(UpdateManager& manager, Render::VertexBuffer& vertexBuffer, uint32_t divisor)
1314 {
1315   using LocalType = MessageValue2<UpdateManager, Render::VertexBuffer*, uint32_t>;
1316   uint32_t* slot  = manager.ReserveMessageSlot(sizeof(LocalType));
1317   new(slot) LocalType(&manager, &UpdateManager::SetVertexBufferDivisor, &vertexBuffer, divisor);
1318 }
1319
1320 inline void SetVertexBufferUpdateCallbackMessage(UpdateManager& manager, Render::VertexBuffer& vertexBuffer, Dali::VertexBufferUpdateCallback* callback)
1321 {
1322   // Message has ownership of VertexBuffer data while in transit from event -> update
1323   using LocalType = MessageValue2<UpdateManager, Render::VertexBuffer*, Dali::VertexBufferUpdateCallback*>;
1324
1325   // Reserve some memory inside the message queue
1326   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1327
1328   // Construct message in the message queue memory; note that delete should not be called on the return value
1329   new(slot) LocalType(&manager, &UpdateManager::SetVertexBufferUpdateCallback, &vertexBuffer, callback);
1330 }
1331
1332 inline void AddGeometry(UpdateManager& manager, OwnerPointer<Render::Geometry>& geometry)
1333 {
1334   // Message has ownership of Geometry while in transit from event -> update
1335   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Render::Geometry>>;
1336
1337   // Reserve some memory inside the message queue
1338   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1339
1340   // Construct message in the message queue memory; note that delete should not be called on the return value
1341   new(slot) LocalType(&manager, &UpdateManager::AddGeometry, geometry);
1342 }
1343
1344 inline void RemoveGeometry(UpdateManager& manager, Render::Geometry& geometry)
1345 {
1346   using LocalType = MessageValue1<UpdateManager, Render::Geometry*>;
1347
1348   // Reserve some memory inside the message queue
1349   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1350
1351   // Construct message in the message queue memory; note that delete should not be called on the return value
1352   new(slot) LocalType(&manager, &UpdateManager::RemoveGeometry, &geometry);
1353 }
1354
1355 inline void AttachVertexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, const Render::VertexBuffer& vertexBuffer)
1356 {
1357   using LocalType = MessageValue2<UpdateManager, Render::Geometry*, Render::VertexBuffer*>;
1358
1359   // Reserve some memory inside the message queue
1360   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1361
1362   // Construct message in the message queue memory; note that delete should not be called on the return value
1363   new(slot) LocalType(&manager, &UpdateManager::AttachVertexBuffer, &geometry, const_cast<Render::VertexBuffer*>(&vertexBuffer));
1364 }
1365
1366 inline void RemoveVertexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, const Render::VertexBuffer& vertexBuffer)
1367 {
1368   using LocalType = MessageValue2<UpdateManager, Render::Geometry*, Render::VertexBuffer*>;
1369
1370   // Reserve some memory inside the message queue
1371   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1372
1373   // Construct message in the message queue memory; note that delete should not be called on the return value
1374   new(slot) LocalType(&manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::VertexBuffer*>(&vertexBuffer));
1375 }
1376
1377 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1378 template<typename T, typename IndexContainerType>
1379 class IndexBufferMessage : public MessageBase
1380 {
1381 public:
1382   /**
1383    * Constructor which does a Vector::Swap()
1384    */
1385   IndexBufferMessage(T* manager, Render::Geometry* geometry, IndexContainerType& indices)
1386   : MessageBase(),
1387     mManager(manager),
1388     mRenderGeometry(geometry)
1389   {
1390     mIndices.Swap(indices);
1391   }
1392
1393   /**
1394    * Virtual destructor
1395    */
1396   ~IndexBufferMessage() override = default;
1397
1398   /**
1399    * @copydoc MessageBase::Process
1400    */
1401   void Process(BufferIndex /*bufferIndex*/) override
1402   {
1403     DALI_ASSERT_DEBUG(mManager && "Message does not have an object");
1404     mManager->SetIndexBuffer(mRenderGeometry, mIndices);
1405   }
1406
1407 private:
1408   T*                 mManager;
1409   Render::Geometry*  mRenderGeometry;
1410   IndexContainerType mIndices;
1411 };
1412
1413 inline void SetIndexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, Render::Geometry::Uint16ContainerType& indices)
1414 {
1415   using LocalType = IndexBufferMessage<UpdateManager, Render::Geometry::Uint16ContainerType>;
1416
1417   // Reserve some memory inside the message queue
1418   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1419
1420   // Construct message in the message queue memory; note that delete should not be called on the return value
1421   new(slot) LocalType(&manager, &geometry, indices);
1422 }
1423
1424 inline void SetIndexBufferMessage(UpdateManager& manager, Render::Geometry& geometry, Render::Geometry::Uint32ContainerType& indices)
1425 {
1426   using LocalType = IndexBufferMessage<UpdateManager, Render::Geometry::Uint32ContainerType>;
1427
1428   // Reserve some memory inside the message queue
1429   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1430
1431   // Construct message in the message queue memory; note that delete should not be called on the return value
1432   new(slot) LocalType(&manager, &geometry, indices);
1433 }
1434
1435 inline void SetGeometryTypeMessage(UpdateManager& manager, Render::Geometry& geometry, uint32_t geometryType)
1436 {
1437   using LocalType = MessageValue2<UpdateManager, Render::Geometry*, uint32_t>;
1438
1439   // Reserve some memory inside the message queue
1440   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1441
1442   // Construct message in the message queue memory; note that delete should not be called on the return value
1443   new(slot) LocalType(&manager, &UpdateManager::SetGeometryType, &geometry, geometryType);
1444 }
1445
1446 inline void AddTextureMessage(UpdateManager& manager, const Render::TextureKey& texture)
1447 {
1448   using LocalType = MessageValue1<UpdateManager, Render::TextureKey>;
1449
1450   // Reserve some memory inside the message queue
1451   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1452
1453   // Construct message in the message queue memory; note that delete should not be called on the return value
1454   new(slot) LocalType(&manager, &UpdateManager::AddTexture, texture);
1455 }
1456
1457 inline void RemoveTextureMessage(UpdateManager& manager, const Render::TextureKey& texture)
1458 {
1459   using LocalType = MessageValue1<UpdateManager, Render::TextureKey>;
1460
1461   // Reserve some memory inside the message queue
1462   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1463
1464   // Construct message in the message queue memory; note that delete should not be called on the return value
1465   new(slot) LocalType(&manager, &UpdateManager::RemoveTexture, texture);
1466 }
1467
1468 inline void UploadTextureMessage(UpdateManager& manager, Render::TextureKey texture, PixelDataPtr pixelData, const Graphics::UploadParams& params)
1469 {
1470   using LocalType = MessageValue3<UpdateManager, Render::TextureKey, PixelDataPtr, Graphics::UploadParams>;
1471
1472   // Reserve some memory inside the message queue
1473   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1474
1475   // Construct message in the message queue memory; note that delete should not be called on the return value
1476   new(slot) LocalType(&manager, &UpdateManager::UploadTexture, texture, pixelData, params);
1477 }
1478
1479 inline void GenerateMipmapsMessage(UpdateManager& manager, Render::TextureKey texture)
1480 {
1481   using LocalType = MessageValue1<UpdateManager, Render::TextureKey>;
1482
1483   // Reserve some memory inside the message queue
1484   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1485
1486   // Construct message in the message queue memory; note that delete should not be called on the return value
1487   new(slot) LocalType(&manager, &UpdateManager::GenerateMipmaps, texture);
1488 }
1489
1490 inline void SetTextureSizeMessage(UpdateManager& manager, Render::TextureKey texture, const Dali::ImageDimensions& size)
1491 {
1492   using LocalType = MessageValue2<UpdateManager, Render::TextureKey, Dali::ImageDimensions>;
1493
1494   // Reserve some memory inside the message queue
1495   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1496
1497   // Construct message in the message queue memory; note that delete should not be called on the return value
1498   new(slot) LocalType(&manager, &UpdateManager::SetTextureSize, texture, size);
1499 }
1500
1501 inline void SetTextureFormatMessage(UpdateManager& manager, Render::TextureKey texture, Dali::Pixel::Format pixelFormat)
1502 {
1503   using LocalType = MessageValue2<UpdateManager, Render::TextureKey, Dali::Pixel::Format>;
1504
1505   // Reserve some memory inside the message queue
1506   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1507
1508   // Construct message in the message queue memory; note that delete should not be called on the return value
1509   new(slot) LocalType(&manager, &UpdateManager::SetTextureFormat, texture, pixelFormat);
1510 }
1511
1512 inline void AddFrameBuffer(UpdateManager& manager, OwnerPointer<Render::FrameBuffer>& frameBuffer)
1513 {
1514   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Render::FrameBuffer>>;
1515
1516   // Reserve some memory inside the message queue
1517   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1518
1519   // Construct message in the message queue memory; note that delete should not be called on the return value
1520   new(slot) LocalType(&manager, &UpdateManager::AddFrameBuffer, frameBuffer);
1521 }
1522
1523 inline void RemoveFrameBuffer(UpdateManager& manager, Render::FrameBuffer& frameBuffer)
1524 {
1525   using LocalType = MessageValue1<UpdateManager, Render::FrameBuffer*>;
1526
1527   // Reserve some memory inside the message queue
1528   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1529
1530   // Construct message in the message queue memory; note that delete should not be called on the return value
1531   new(slot) LocalType(&manager, &UpdateManager::RemoveFrameBuffer, &frameBuffer);
1532 }
1533
1534 inline void AttachColorTextureToFrameBuffer(UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer)
1535 {
1536   using LocalType = MessageValue4<UpdateManager, Render::FrameBuffer*, Render::Texture*, uint32_t, uint32_t>;
1537
1538   // Reserve some memory inside the message queue
1539   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1540
1541   // Construct message in the message queue memory; note that delete should not be called on the return value
1542   new(slot) LocalType(&manager, &UpdateManager::AttachColorTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel, layer);
1543 }
1544
1545 inline void AttachDepthTextureToFrameBuffer(UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, uint32_t mipmapLevel)
1546 {
1547   using LocalType = MessageValue3<UpdateManager, Render::FrameBuffer*, Render::Texture*, uint32_t>;
1548
1549   // Reserve some memory inside the message queue
1550   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1551
1552   // Construct message in the message queue memory; note that delete should not be called on the return value
1553   new(slot) LocalType(&manager, &UpdateManager::AttachDepthTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel);
1554 }
1555
1556 inline void AttachDepthStencilTextureToFrameBuffer(UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, uint32_t mipmapLevel)
1557 {
1558   using LocalType = MessageValue3<UpdateManager, Render::FrameBuffer*, Render::Texture*, uint32_t>;
1559
1560   // Reserve some memory inside the message queue
1561   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1562
1563   // Construct message in the message queue memory; note that delete should not be called on the return value
1564   new(slot) LocalType(&manager, &UpdateManager::AttachDepthStencilTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel);
1565 }
1566
1567 inline void SetMultiSamplingLevelToFrameBuffer(UpdateManager& manager, Render::FrameBuffer& frameBuffer, uint8_t multiSamplingLevel)
1568 {
1569   using LocalType = MessageValue2<UpdateManager, Render::FrameBuffer*, uint8_t>;
1570
1571   // Reserve some memory inside the message queue
1572   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1573
1574   // Construct message in the message queue memory; note that delete should not be called on the return value
1575   new(slot) LocalType(&manager, &UpdateManager::SetMultiSamplingLevelToFrameBuffer, &frameBuffer, multiSamplingLevel);
1576 }
1577
1578 inline void SetDepthIndicesMessage(UpdateManager& manager, OwnerPointer<NodeDepths>& nodeDepths)
1579 {
1580   using LocalType = MessageValue1<UpdateManager, OwnerPointer<NodeDepths>>;
1581
1582   // Reserve some memory inside the message queue
1583   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1584
1585   // Construct message in the message queue memory; note that delete should not be called on the return value
1586   new(slot) LocalType(&manager, &UpdateManager::SetDepthIndices, nodeDepths);
1587 }
1588
1589 inline void AddResetterMessage(UpdateManager& manager, OwnerPointer<PropertyResetterBase> resetter)
1590 {
1591   using LocalType = MessageValue1<UpdateManager, OwnerPointer<PropertyResetterBase>>;
1592
1593   // Reserve some memory inside the message queue
1594   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1595
1596   // Construct message in the message queue memory; note that delete should not be called on the return value
1597   new(slot) LocalType(&manager, &UpdateManager::AddPropertyResetter, resetter);
1598 }
1599
1600 inline void AddFrameCallbackMessage(UpdateManager& manager, OwnerPointer<FrameCallback>& frameCallback, const Node& rootNode)
1601 {
1602   using LocalType = MessageValue2<UpdateManager, OwnerPointer<FrameCallback>, const Node*>;
1603
1604   // Reserve some memory inside the message queue
1605   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1606
1607   // Construct message in the message queue memory; note that delete should not be called on the return value
1608   new(slot) LocalType(&manager, &UpdateManager::AddFrameCallback, frameCallback, &rootNode);
1609 }
1610
1611 inline void RemoveFrameCallbackMessage(UpdateManager& manager, FrameCallbackInterface& frameCallback)
1612 {
1613   using LocalType = MessageValue1<UpdateManager, FrameCallbackInterface*>;
1614
1615   // Reserve some memory inside the message queue
1616   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1617
1618   // Construct message in the message queue memory; note that delete should not be called on the return value
1619   new(slot) LocalType(&manager, &UpdateManager::RemoveFrameCallback, &frameCallback);
1620 }
1621
1622 inline void NotifyFrameCallbackMessage(UpdateManager& manager, FrameCallbackInterface* frameCallback, Dali::UpdateProxy::NotifySyncPoint syncPoint)
1623 {
1624   using LocalType = MessageValue2<UpdateManager, FrameCallbackInterface*, Dali::UpdateProxy::NotifySyncPoint>;
1625   uint32_t* slot  = manager.ReserveMessageSlot(sizeof(LocalType));
1626   new(slot) LocalType(&manager, &UpdateManager::NotifyFrameCallback, frameCallback, syncPoint);
1627 }
1628
1629 } // namespace SceneGraph
1630
1631 } // namespace Internal
1632
1633 } // namespace Dali
1634
1635 #endif // DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H