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