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