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