Merge "Fix the synchronization issue when window is resized or rotated" into devel...
[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/scene-graph-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 GlSyncAbstraction;
56 class RenderController;
57
58 } // namespace Integration
59
60 namespace Internal
61 {
62 class PropertyNotifier;
63 class NotificationManager;
64 class CompleteNotificationInterface;
65 class TouchResampler;
66
67 namespace Render
68 {
69 struct Sampler;
70 class FrameBuffer;
71 } // namespace Render
72 // value types used by messages
73 template<>
74 struct ParameterType<PropertyNotification::NotifyMode>
75 : public BasicType<PropertyNotification::NotifyMode>
76 {
77 };
78
79 namespace SceneGraph
80 {
81 class Animation;
82 class DiscardQueue;
83 class RenderManager;
84 class RenderTaskList;
85 class RenderTaskProcessor;
86 class RenderQueue;
87 class VertexBuffer;
88
89 /**
90  * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
91  * other scene graph property owning objects.
92  * It controls the Update traversal, in which nodes are repositioned/animated,
93  * and organizes the the culling and rendering of the scene.
94  * It also maintains the lifecycle of nodes and other property owners that are
95  * disconnected from the scene graph.
96  */
97 class UpdateManager : public ShaderSaver
98 {
99 public:
100   /**
101    * Construct a new UpdateManager.
102    * @param[in] notificationManager This should be notified when animations have finished.
103    * @param[in] animationPlaylist The CompleteNotificationInterface that handles the animations
104    * @param[in] propertyNotifier The PropertyNotifier
105    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
106    * @param[in] controller After messages are flushed, we request a render from the RenderController.
107    * @param[in] renderManager This is responsible for rendering the results of each "update".
108    * @param[in] renderQueue Used to queue messages for the next render.
109    * @param[in] renderTaskProcessor Handles RenderTasks and RenderInstrucitons.
110    */
111   UpdateManager(NotificationManager&           notificationManager,
112                 CompleteNotificationInterface& animationPlaylist,
113                 PropertyNotifier&              propertyNotifier,
114                 DiscardQueue&                  discardQueue,
115                 Integration::RenderController& controller,
116                 RenderManager&                 renderManager,
117                 RenderQueue&                   renderQueue,
118                 RenderTaskProcessor&           renderTaskProcessor);
119
120   /**
121    * Destructor.
122    */
123   ~UpdateManager() override;
124
125   // Node connection methods
126
127   /**
128    * Installs a new layer as the root node.
129    * @pre The layer is of derived Node type Layer.
130    * @pre The layer does not have a parent.
131    * @param[in] layer The new root node.
132    * @post The node is owned by UpdateManager.
133    */
134   void InstallRoot(OwnerPointer<Layer>& layer);
135
136   /**
137    * Uninstalls the root node.
138    * @pre The layer is of derived Node type Layer.
139    * @pre The layer does not have a parent.
140    * @param[in] layer The root node.
141    * @post The node is owned by UpdateManager.
142    */
143   void UninstallRoot(Layer* layer);
144
145   /**
146    * Add a Node; UpdateManager takes ownership.
147    * @pre The node does not have a parent.
148    * @note even though nodes are pool allocated, they also contain other heap allocated data, thus using OwnerPointer when transferring the data
149    * @param[in] node The node to add.
150    */
151   void AddNode(OwnerPointer<Node>& node);
152
153   /**
154    * Connect a Node to the scene-graph.
155    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
156    * @pre The node does not already have a parent.
157    * @param[in] parent The new parent node.
158    */
159   void ConnectNode(Node* parent, Node* node);
160
161   /**
162    * Disconnect a Node from the scene-graph.
163    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
164    * @pre The node has a parent.
165    * @param[in] node The node to disconnect.
166    */
167   void DisconnectNode(Node* node);
168
169   /**
170    * Destroy a Node owned by UpdateManager.
171    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
172    * In the following update, the previously queued Nodes may be deleted.
173    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
174    * @param[in] node The node to destroy.
175    */
176   void DestroyNode(Node* node);
177
178   /**
179    * Add a camera on scene
180    * @param[in] camera The camera to add
181    */
182   void AddCamera(OwnerPointer<Camera>& camera);
183
184   /**
185    * Remove a camera from scene
186    * @param[in] camera to remove
187    */
188   void RemoveCamera(Camera* camera);
189
190   /**
191    * Add a newly created object.
192    * @param[in] object The object to add.
193    * @post The object is owned by UpdateManager.
194    */
195   void AddObject(OwnerPointer<PropertyOwner>& object);
196
197   /**
198    * Remove an object.
199    * @param[in] object The object to remove.
200    */
201   void RemoveObject(PropertyOwner* object);
202
203   /**
204    * Add a newly created render task list.
205    * @param[in] taskList The render task list to add.
206    * @post The render task list is owned by UpdateManager.
207    */
208   void AddRenderTaskList(OwnerPointer<RenderTaskList>& taskList);
209
210   /**
211    * Remove a render task list.
212    * @param[in] taskList The render task list to remove.
213    */
214   void RemoveRenderTaskList(RenderTaskList* taskList);
215
216   /**
217    * Add a newly created scene.
218    * @param[in] scene The scene to add.
219    * @post The scene is owned by UpdateManager.
220    */
221   void AddScene(OwnerPointer<Scene>& scene);
222
223   /**
224    * Remove a scene.
225    * @param[in] scene The scene to remove.
226    */
227   void RemoveScene(Scene* scene);
228
229   // Animations
230
231   /**
232    * Add a newly created animation.
233    * @param[in] animation The animation to add.
234    * @post The animation is owned by UpdateManager.
235    */
236   void AddAnimation(OwnerPointer<SceneGraph::Animation>& animation);
237
238   /**
239    * Stop an animation.
240    * @param[in] animation The animation to stop.
241    */
242   void StopAnimation(Animation* animation);
243
244   /**
245    * Remove an animation.
246    * @param[in] animation The animation to remove.
247    */
248   void RemoveAnimation(Animation* animation);
249
250   /**
251    * Query whether any animations are currently running.
252    * @return True if any animations are running.
253    */
254   bool IsAnimationRunning() const;
255
256   /**
257    * Add a property resetter. UpdateManager takes ownership of the object.
258    * It will be killed by UpdateManager when the associated animator or
259    * constraint has finished; or the property owner of the property is destroyed.
260    */
261   void AddPropertyResetter(OwnerPointer<PropertyResetterBase>& propertyResetter);
262
263   // Property Notification
264
265   /**
266    * Add a newly created property notification
267    * @param[in] propertyNotification The notification to add
268    * @post The propertyNotification is owned by UpdateManager.
269    */
270   void AddPropertyNotification(OwnerPointer<PropertyNotification>& propertyNotification);
271
272   /**
273    * Remove a property notification
274    * @param[in] propertyNotification The notification to remove
275    */
276   void RemovePropertyNotification(PropertyNotification* propertyNotification);
277
278   /**
279    * Set Notify state for PropertyNotification
280    * @param[in] propertyNotification The notification to remove
281    * @param[in] notifyMode The notification mode.
282    */
283   void PropertyNotificationSetNotify(PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode);
284
285   // Shaders
286
287   /**
288    * Add a newly created shader.
289    * @param[in] shader The shader to add.
290    * @post The shader is owned by the UpdateManager.
291    */
292   void AddShader(OwnerPointer<Shader>& shader);
293
294   /**
295    * Remove a shader.
296    * @pre The shader has been added to the UpdateManager.
297    * @param[in] shader The shader to remove.
298    * @post The shader is destroyed.
299    */
300   void RemoveShader(Shader* shader);
301
302   /**
303    * Set the shader program for a Shader object
304    * @param[in] shader        The shader to modify
305    * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
306    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
307    */
308   void SetShaderProgram(Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry);
309
310   /**
311    * @brief Accept compiled shaders passed back on render thread for saving.
312    * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
313    */
314   void SaveBinary(Internal::ShaderDataPtr shaderData) override;
315
316   /**
317    * @brief Set the destination for compiled shader binaries to be passed on to.
318    * The dispatcher passed in will be called from the update thread.
319    * @param[in] upstream A sink for ShaderDatas to be passed into.
320    */
321   void SetShaderSaver(ShaderSaver& upstream);
322
323   // Renderers
324
325   /**
326    * Add a new renderer to scene
327    * @param renderer to add
328    */
329   void AddRenderer(OwnerPointer<Renderer>& renderer);
330
331   /**
332    * Add a renderer from scene
333    * @param renderer to remove
334    */
335   void RemoveRenderer(Renderer* renderer);
336
337   // Gestures
338
339   /**
340    * Set the pan gesture processor.
341    * Pan Gesture processor lives for the lifetime of UpdateManager
342    * @param[in] gesture The gesture processor.
343    * @post The gestureProcessor is owned by the UpdateManager.
344    */
345   void SetPanGestureProcessor(PanGesture* gestureProcessor);
346
347   // Textures
348
349   /**
350    * Add a newly created TextureSet.
351    * @param[in] textureSet The texture set to add.
352    * @post The TextureSet is owned by the UpdateManager.
353    */
354   void AddTextureSet(OwnerPointer<TextureSet>& textureSet);
355
356   /**
357    * Remove a TextureSet.
358    * @pre The TextureSet has been added to the UpdateManager.
359    * @param[in] textureSet The TextureSet to remove.
360    * @post The TextureSet is destroyed.
361    */
362   void RemoveTextureSet(TextureSet* textureSet);
363
364   // Render tasks
365
366   /**
367    * Get the scene graph side list of RenderTasks.
368    * @param[in] systemLevel True if using the system-level overlay.
369    * @return The list of render tasks
370    */
371   RenderTaskList* GetRenderTaskList(bool systemLevel);
372
373   // Message queue handling
374
375   /**
376    * Reserve space for another message in the queue; this must then be initialized by the caller.
377    * The message will be read from the update-thread after the next FlushMessages is called.
378    * @post Calling this method may invalidate any previously returned slots.
379    * @param[in] size The message size with respect to the size of type "char".
380    * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
381    * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
382    * @return A pointer to the first char allocated for the message.
383    */
384   uint32_t* ReserveMessageSlot(uint32_t size, bool updateScene = true);
385
386   /**
387    * @return the current event-buffer index.
388    */
389   BufferIndex GetEventBufferIndex() const
390   {
391     // inlined as its called often from event thread
392     return mSceneGraphBuffers.GetEventBufferIndex();
393   }
394
395   /**
396    * Called by the event-thread to signal that FlushQueue will be called
397    * e.g. when it has finished event processing.
398    */
399   void EventProcessingStarted();
400
401   /**
402    * Flush the set of messages, which were previously stored with QueueMessage().
403    * Calls to this thread-safe method should be minimized, to avoid thread blocking.
404    *
405    * @return True if there are messages to process.
406    */
407   bool FlushQueue();
408
409   /**
410    * Add a new sampler to RenderManager
411    * @param[in] sampler The sampler to add
412    * @post Sends a message to RenderManager to add the sampler.
413    * The sampler will be owned by RenderManager
414    */
415   void AddSampler(OwnerPointer<Render::Sampler>& sampler);
416
417   /**
418    * Removes an existing sampler from RenderManager
419    * @param[in] sampler The sampler to remove
420    * @post The sampler will be destroyed in the render thread
421    */
422   void RemoveSampler(Render::Sampler* sampler);
423
424   /**
425    * Sets the filter modes for an existing sampler
426    * @param[in] sampler The sampler
427    * @param[in] minFilterMode The filter to use under minification
428    * @param[in] magFilterMode The filter to use under magnification
429    */
430   void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
431
432   /**
433    * Sets the wrap mode for an existing sampler
434    * @param[in] sampler The sampler
435    * @param[in] rWrapMode Wrapping mode in z direction
436    * @param[in] sWrapMode Wrapping mode in x direction
437    * @param[in] tWrapMode Wrapping mode in y direction
438    */
439   void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
440
441   /**
442    * Add a new property buffer to RenderManager
443    * @param[in] propertryBuffer The property buffer to add
444    * @post Sends a message to RenderManager to add the property buffer.
445    * The property buffer will be owned by RenderManager
446    */
447   void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& propertryBuffer);
448
449   /**
450    * Removes an existing VertexBuffer from RenderManager
451    * @param[in] propertryBuffer The property buffer to remove
452    * @post The property buffer will be destroyed in the render thread
453    */
454   void RemoveVertexBuffer(Render::VertexBuffer* propertryBuffer);
455
456   /**
457    * Sets the format of an existing property buffer
458    * @param[in] vertexBuffer The property buffer.
459    * @param[in] format The new format of the buffer
460    * @post Sends a message to RenderManager to set the new format to the property buffer.
461    */
462   void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
463
464   /**
465    * Sets the data of an existing property buffer
466    * @param[in] vertexBuffer The property buffer.
467    * @param[in] data The new data of the buffer
468    * @param[in] size The new size of the buffer
469    * @post Sends a message to RenderManager to set the new data to the property buffer.
470    */
471   void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t> >& data, uint32_t size);
472
473   /**
474    * Adds a geometry to the RenderManager
475    * @param[in] geometry The geometry to add
476    * @post Sends a message to RenderManager to add the Geometry
477    * The geometry will be owned by RenderManager
478    */
479   void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
480
481   /**
482    * Removes an existing Geometry from RenderManager
483    * @param[in] geometry The geometry to remove
484    * @post The geometry will be destroyed in the render thread
485    */
486   void RemoveGeometry(Render::Geometry* geometry);
487
488   /**
489    * Sets the geometry type of an existing Geometry
490    * @param[in] geometry The geometry
491    * @param[in] geometryType The type of the geometry
492    */
493   void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
494
495   /**
496    * Sets the index buffer to be used by a geometry
497    * @param[in] geometry The geometry
498    * @param[in] indices A vector containing the indices for the geometry
499    */
500   void SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& indices);
501
502   /**
503    * Adds a vertex buffer to a geometry
504    * @param[in] geometry The geometry
505    * @param[in] vertexBuffer The property buffer
506    */
507   void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
508
509   /**
510    * Removes a vertex buffer from a geometry
511    * @param[in] geometry The geometry
512    * @param[in] vertexBuffer The property buffer
513    */
514   void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
515
516   /**
517    * Adds a texture to the render manager
518    * @param[in] texture The texture to add
519    * The texture will be owned by RenderManager
520    */
521   void AddTexture(OwnerPointer<Render::Texture>& texture);
522
523   /**
524    * Removes a texture from the render manager
525    * @param[in] texture The texture to remove
526    * @post The texture will be destroyed in the render thread
527    */
528   void RemoveTexture(Render::Texture* texture);
529
530   /**
531    * Uploads data to a texture owned by the RenderManager
532    * @param[in] texture The texture
533    * @param[in] pixelData The pixel data object
534    * @param[in] params The parameters for the upload
535    */
536   void UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
537
538   /**
539    * Generates mipmaps for a texture owned by the RenderManager
540    * @param[in] texture The texture
541    */
542   void GenerateMipmaps(Render::Texture* texture);
543
544   /**
545    * Adds a framebuffer to the render manager
546    * @param[in] frameBuffer The framebuffer to add
547    * The framebuffer will be owned by RenderManager
548    */
549   void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
550
551   /**
552    * Removes a FrameBuffer from the render manager
553    * @param[in] frameBuffer The FrameBuffer to remove
554    * @post The FrameBuffer will be destroyed in the render thread
555    */
556   void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
557
558   /**
559    * Attach a texture as color output to an existing FrameBuffer
560    * @param[in] frameBuffer The FrameBuffer
561    * @param[in] texture The texture that will be used as output when rendering
562    * @param[in] mipmapLevel The mipmap of the texture to be attached
563    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
564    */
565   void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t face);
566
567   /**
568    * Attach a texture as depth output to an existing FrameBuffer
569    * @param[in] frameBuffer The FrameBuffer
570    * @param[in] texture The texture that will be used as output when rendering
571    * @param[in] mipmapLevel The mipmap of the texture to be attached
572    */
573   void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
574
575   /**
576    * Attach a texture as depth/stencil output to an existing FrameBuffer
577    * @param[in] frameBuffer The FrameBuffer
578    * @param[in] texture The texture that will be used as output when rendering
579    * @param[in] mipmapLevel The mipmap of the texture to be attached
580    */
581   void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
582
583   /**
584    * This is called when the surface of the scene has been replaced.
585    * @param[in] scene The scene.
586    */
587   void SurfaceReplaced(Scene* scene);
588
589 public:
590   /**
591    * Performs an Update traversal on the scene-graph.
592    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
593    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
594    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
595    * @param[in] renderToFboEnabled Whether rendering into the Frame Buffer Object is enabled.
596    * @param[in] isRenderingToFbo   Whether this frame is being rendered into the Frame Buffer Object.
597    * @return True if further updates are required e.g. during animations.
598    */
599   uint32_t Update(float    elapsedSeconds,
600                   uint32_t lastVSyncTimeMilliseconds,
601                   uint32_t nextVSyncTimeMilliseconds,
602                   bool     renderToFboEnabled,
603                   bool     isRenderingToFbo);
604
605   /**
606    * @copydoc Dali::Stage::KeepRendering()
607    */
608   void KeepRendering(float durationSeconds);
609
610   /**
611    * @copydoc Dali::DevelStage::SetRenderingBehavior()
612    */
613   void SetRenderingBehavior(DevelStage::Rendering renderingBehavior);
614
615   /**
616    * Request to render the current frame
617    * @note This is a temporary workaround (to be removed in the future) to request the rendering of
618    *       the current frame if the color or visibility of any actor is updated. It MUST NOT be used
619    *       for any other purposes.
620    */
621   void RequestRendering();
622
623   /**
624    * Sets the depths of all layers.
625    * @param layers The layers in depth order.
626    * @param[in] rootLayer The root layer of the sorted layers.
627    */
628   void SetLayerDepths(const std::vector<Layer*>& layers, const Layer* rootLayer);
629
630   /**
631    * Set the depth indices of all nodes (in LayerUI's)
632    * @param[in] nodeDepths A vector of nodes and associated depth indices
633    */
634   void SetDepthIndices(OwnerPointer<NodeDepths>& nodeDepths);
635
636   /**
637    * Adds an implementation of the FrameCallbackInterface.
638    * @param[in] frameCallback An OwnerPointer to the SceneGraph FrameCallback object
639    * @param[in] rootNode A pointer to the root node to apply the FrameCallback to
640    */
641   void AddFrameCallback(OwnerPointer<FrameCallback>& frameCallback, const Node* rootNode);
642
643   /**
644    * Removes the specified implementation of FrameCallbackInterface.
645    * @param[in] frameCallback A pointer to the implementation of the FrameCallbackInterface to remove.
646    */
647   void RemoveFrameCallback(FrameCallbackInterface* frameCallback);
648
649 private:
650   // Undefined
651   UpdateManager(const UpdateManager&);
652
653   // Undefined
654   UpdateManager& operator=(const UpdateManager& rhs);
655
656   /**
657    * Helper to check whether the update-thread should keep going.
658    * @param[in] elapsedSeconds The time in seconds since the previous update.
659    * @return True if the update-thread should keep going.
660    */
661   uint32_t KeepUpdatingCheck(float elapsedSeconds) const;
662
663   /**
664    * Helper to reset all Node properties
665    * @param[in] bufferIndex to use
666    */
667   void ResetProperties(BufferIndex bufferIndex);
668
669   /**
670    * Perform gesture updates.
671    * @param[in] bufferIndex to use
672    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
673    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
674    * @return true, if any properties were updated.
675    */
676   bool ProcessGestures(BufferIndex bufferIndex, uint32_t lastVSyncTimeMilliseconds, uint32_t nextVSyncTimeMilliseconds);
677
678   /**
679    * Perform animation updates
680    * @param[in] bufferIndex to use
681    * @param[in] elapsedSeconds time since last frame
682    * @return true if at least one animations is currently active or false otherwise
683    */
684   bool Animate(BufferIndex bufferIndex, float elapsedSeconds);
685
686   /**
687    * Applies constraints to CustomObjects
688    * @param[in] bufferIndex to use
689    */
690   void ConstrainCustomObjects(BufferIndex bufferIndex);
691
692   /**
693    * Applies constraints to RenderTasks
694    * @param[in] bufferIndex to use
695    */
696   void ConstrainRenderTasks(BufferIndex bufferIndex);
697
698   /**
699    * Applies constraints to Shaders
700    * @param[in] bufferIndex to use
701    */
702   void ConstrainShaders(BufferIndex bufferIndex);
703
704   /**
705    * Perform property notification updates
706    * @param[in] bufferIndex to use
707    */
708   void ProcessPropertyNotifications(BufferIndex bufferIndex);
709
710   /**
711    * Pass shader binaries queued here on to event thread.
712    */
713   void ForwardCompiledShadersToEventThread();
714
715   /**
716    * Update node shaders, opacity, geometry etc.
717    * @param[in] bufferIndex to use
718    */
719   void UpdateNodes(BufferIndex bufferIndex);
720
721   /**
722    * Update Renderers
723    * @param[in] bufferIndex to use
724    */
725   void UpdateRenderers(BufferIndex bufferIndex);
726
727 private:
728   // needs to be direct member so that getter for event buffer can be inlined
729   SceneGraphBuffers mSceneGraphBuffers;
730
731   struct Impl;
732   Impl* mImpl;
733 };
734
735 // Messages for UpdateManager
736
737 inline void InstallRootMessage(UpdateManager& manager, OwnerPointer<Layer>& root)
738 {
739   // Message has ownership of Layer while in transit from event -> update
740   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Layer> >;
741
742   // Reserve some memory inside the message queue
743   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
744
745   // Construct message in the message queue memory; note that delete should not be called on the return value
746   new(slot) LocalType(&manager, &UpdateManager::InstallRoot, root);
747 }
748
749 inline void UninstallRootMessage(UpdateManager& manager, const Layer* constRoot)
750 {
751   // Scene graph thread can destroy this object.
752   Layer* root = const_cast<Layer*>(constRoot);
753
754   using LocalType = MessageValue1<UpdateManager, Layer*>;
755
756   // Reserve some memory inside the message queue
757   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
758
759   // Construct message in the message queue memory; note that delete should not be called on the return value
760   new(slot) LocalType(&manager, &UpdateManager::UninstallRoot, root);
761 }
762
763 inline void AddNodeMessage(UpdateManager& manager, OwnerPointer<Node>& node)
764 {
765   // Message has ownership of Node while in transit from event -> update
766   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Node> >;
767
768   // Reserve some memory inside the message queue
769   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
770
771   // Construct message in the message queue memory; note that delete should not be called on the return value
772   new(slot) LocalType(&manager, &UpdateManager::AddNode, node);
773 }
774
775 inline void ConnectNodeMessage(UpdateManager& manager, const Node& constParent, const Node& constChild)
776 {
777   // Update thread can edit the object
778   Node& parent = const_cast<Node&>(constParent);
779   Node& child  = const_cast<Node&>(constChild);
780
781   using LocalType = MessageValue2<UpdateManager, Node*, Node*>;
782
783   // Reserve some memory inside the message queue
784   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
785
786   // Construct message in the message queue memory; note that delete should not be called on the return value
787   new(slot) LocalType(&manager, &UpdateManager::ConnectNode, &parent, &child);
788 }
789
790 inline void DisconnectNodeMessage(UpdateManager& manager, const Node& constNode)
791 {
792   // Scene graph thread can modify this object.
793   Node& node = const_cast<Node&>(constNode);
794
795   using LocalType = MessageValue1<UpdateManager, Node*>;
796
797   // Reserve some memory inside the message queue
798   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
799
800   // Construct message in the message queue memory; note that delete should not be called on the return value
801   new(slot) LocalType(&manager, &UpdateManager::DisconnectNode, &node);
802 }
803
804 inline void DestroyNodeMessage(UpdateManager& manager, const Node& constNode)
805 {
806   // Scene graph thread can destroy this object.
807   Node& node = const_cast<Node&>(constNode);
808
809   using LocalType = MessageValue1<UpdateManager, Node*>;
810
811   // Reserve some memory inside the message queue
812   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
813
814   // Construct message in the message queue memory; note that delete should not be called on the return value
815   new(slot) LocalType(&manager, &UpdateManager::DestroyNode, &node);
816 }
817
818 inline void AddCameraMessage(UpdateManager& manager, OwnerPointer<Camera>& camera)
819 {
820   // Message has ownership of Camera while in transit from event -> update
821   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Camera> >;
822
823   // Reserve some memory inside the message queue
824   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
825
826   // Construct message in the message queue memory; note that delete should not be called on the return value
827   new(slot) LocalType(&manager, &UpdateManager::AddCamera, camera);
828 }
829
830 inline void RemoveCameraMessage(UpdateManager& manager, const Camera* camera)
831 {
832   using LocalType = MessageValue1<UpdateManager, Camera*>;
833
834   // Reserve some memory inside the message queue
835   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
836
837   // Construct message in the message queue memory; note that delete should not be called on the return value
838   new(slot) LocalType(&manager, &UpdateManager::RemoveCamera, const_cast<Camera*>(camera));
839 }
840
841 inline void AddObjectMessage(UpdateManager& manager, OwnerPointer<PropertyOwner>& object)
842 {
843   // Message has ownership of object while in transit from event -> update
844   using LocalType = MessageValue1<UpdateManager, OwnerPointer<PropertyOwner> >;
845
846   // Reserve some memory inside the message queue
847   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
848
849   // Construct message in the message queue memory; note that delete should not be called on the return value
850   new(slot) LocalType(&manager, &UpdateManager::AddObject, object);
851 }
852
853 inline void RemoveObjectMessage(UpdateManager& manager, const PropertyOwner* object)
854 {
855   using LocalType = MessageValue1<UpdateManager, PropertyOwner*>;
856
857   // Reserve some memory inside the message queue
858   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
859
860   // Construct message in the message queue memory; note that delete should not be called on the return value
861   new(slot) LocalType(&manager, &UpdateManager::RemoveObject, const_cast<PropertyOwner*>(object));
862 }
863
864 inline void AddAnimationMessage(UpdateManager& manager, OwnerPointer<SceneGraph::Animation>& animation)
865 {
866   using LocalType = MessageValue1<UpdateManager, OwnerPointer<SceneGraph::Animation> >;
867
868   // Reserve some memory inside the message queue
869   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
870
871   // Construct message in the message queue memory; note that delete should not be called on the return value
872   new(slot) LocalType(&manager, &UpdateManager::AddAnimation, animation);
873 }
874
875 inline void StopAnimationMessage(UpdateManager& manager, const Animation& constAnimation)
876 {
877   // The scene-graph thread owns this object so it can safely edit it.
878   Animation& animation = const_cast<Animation&>(constAnimation);
879
880   using LocalType = MessageValue1<UpdateManager, Animation*>;
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::StopAnimation, &animation);
887 }
888
889 inline void RemoveAnimationMessage(UpdateManager& manager, const Animation& constAnimation)
890 {
891   // The scene-graph thread owns this object so it can safely edit it.
892   Animation& animation = const_cast<Animation&>(constAnimation);
893
894   using LocalType = MessageValue1<UpdateManager, Animation*>;
895
896   // Reserve some memory inside the message queue
897   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
898
899   // Construct message in the message queue memory; note that delete should not be called on the return value
900   new(slot) LocalType(&manager, &UpdateManager::RemoveAnimation, &animation);
901 }
902
903 inline void AddRenderTaskListMessage(UpdateManager& manager, OwnerPointer<SceneGraph::RenderTaskList>& taskList)
904 {
905   using LocalType = MessageValue1<UpdateManager, OwnerPointer<SceneGraph::RenderTaskList> >;
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::AddRenderTaskList, taskList);
912 }
913
914 inline void RemoveRenderTaskListMessage(UpdateManager& manager, const RenderTaskList& constTaskList)
915 {
916   // The scene-graph thread owns this object so it can safely edit it.
917   RenderTaskList& taskList = const_cast<RenderTaskList&>(constTaskList);
918
919   using LocalType = MessageValue1<UpdateManager, RenderTaskList*>;
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::RemoveRenderTaskList, &taskList);
926 }
927
928 inline void AddSceneMessage(UpdateManager& manager, OwnerPointer<SceneGraph::Scene>& scene)
929 {
930   using LocalType = MessageValue1<UpdateManager, OwnerPointer<SceneGraph::Scene> >;
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::AddScene, scene);
937 }
938
939 inline void RemoveSceneMessage(UpdateManager& manager, const SceneGraph::Scene& constScene)
940 {
941   // The scene-graph thread owns this object so it can safely edit it.
942   Scene& scene = const_cast<Scene&>(constScene);
943
944   using LocalType = MessageValue1<UpdateManager, Scene*>;
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::RemoveScene, &scene);
951 }
952
953 inline void AddPropertyNotificationMessage(UpdateManager& manager, OwnerPointer<PropertyNotification>& propertyNotification)
954 {
955   // Message has ownership of PropertyNotification while in transit from event -> update
956   using LocalType = MessageValue1<UpdateManager, OwnerPointer<PropertyNotification> >;
957
958   // Reserve some memory inside the message queue
959   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
960
961   // Construct message in the message queue memory; note that delete should not be called on the return value
962   new(slot) LocalType(&manager, &UpdateManager::AddPropertyNotification, propertyNotification);
963 }
964
965 inline void RemovePropertyNotificationMessage(UpdateManager& manager, const PropertyNotification& constPropertyNotification)
966 {
967   // The scene-graph thread owns this object so it can safely edit it.
968   PropertyNotification& propertyNotification = const_cast<PropertyNotification&>(constPropertyNotification);
969
970   using LocalType = MessageValue1<UpdateManager, PropertyNotification*>;
971
972   // Reserve some memory inside the message queue
973   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
974
975   // Construct message in the message queue memory; note that delete should not be called on the return value
976   new(slot) LocalType(&manager, &UpdateManager::RemovePropertyNotification, &propertyNotification);
977 }
978
979 inline void PropertyNotificationSetNotifyModeMessage(UpdateManager&                   manager,
980                                                      const PropertyNotification*      constPropertyNotification,
981                                                      PropertyNotification::NotifyMode notifyMode)
982 {
983   // The scene-graph thread owns this object so it can safely edit it.
984   PropertyNotification* propertyNotification = const_cast<PropertyNotification*>(constPropertyNotification);
985
986   using LocalType = MessageValue2<UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode>;
987
988   // Reserve some memory inside the message queue
989   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
990
991   // Construct message in the message queue memory; note that delete should not be called on the return value
992   new(slot) LocalType(&manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode);
993 }
994
995 // The render thread can safely change the Shader
996 inline void AddShaderMessage(UpdateManager& manager, OwnerPointer<Shader>& shader)
997 {
998   using LocalType = MessageValue1<UpdateManager, OwnerPointer<Shader> >;
999
1000   // Reserve some memory inside the message queue
1001   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1002
1003   // Construct message in the message queue memory; note that delete should not be called on the return value
1004   new(slot) LocalType(&manager, &UpdateManager::AddShader, shader);
1005 }
1006
1007 // The render thread can safely change the Shader
1008 inline void RemoveShaderMessage(UpdateManager& manager, const Shader* shader)
1009 {
1010   using LocalType = MessageValue1<UpdateManager, Shader*>;
1011
1012   // Reserve some memory inside the message queue
1013   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1014
1015   // Construct message in the message queue memory; note that delete should not be called on the return value
1016   new(slot) LocalType(&manager, &UpdateManager::RemoveShader, const_cast<Shader*>(shader));
1017 }
1018
1019 inline void SetShaderProgramMessage(UpdateManager&          manager,
1020                                     const Shader&           shader,
1021                                     Internal::ShaderDataPtr shaderData,
1022                                     bool                    modifiesGeometry)
1023 {
1024   using LocalType = MessageValue3<UpdateManager, Shader*, Internal::ShaderDataPtr, bool>;
1025
1026   // Reserve some memory inside the message queue
1027   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1028
1029   // Construct message in the message queue memory; note that delete should not be called on the return value
1030   new(slot) LocalType(&manager, &UpdateManager::SetShaderProgram, const_cast<Shader*>(&shader), shaderData, modifiesGeometry);
1031 }
1032
1033 inline void SurfaceReplacedMessage( UpdateManager& manager, const SceneGraph::Scene& constScene )
1034 {
1035   // The scene-graph thread owns this object so it can safely edit it.
1036   Scene& scene = const_cast<Scene&>(constScene);
1037
1038   using LocalType = MessageValue1<UpdateManager, Scene*>;
1039
1040   // Reserve some memory inside the message queue
1041   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1042
1043   // Construct message in the message queue memory; note that delete should not be called on the return value
1044   new(slot) LocalType(&manager, &UpdateManager::SurfaceReplaced, &scene);
1045 }
1046
1047 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
1048 {
1049   using LocalType = MessageValue1<UpdateManager, float>;
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::KeepRendering, durationSeconds);
1056 }
1057
1058 inline void SetRenderingBehaviorMessage(UpdateManager& manager, DevelStage::Rendering renderingBehavior)
1059 {
1060   using LocalType = MessageValue1<UpdateManager, DevelStage::Rendering>;
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::SetRenderingBehavior, renderingBehavior);
1067 }
1068
1069 inline void RequestRenderingMessage(UpdateManager& manager)
1070 {
1071   using LocalType = Message<UpdateManager>;
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::RequestRendering);
1078 }
1079
1080 /**
1081  * Create a message for setting the depth of a layer
1082  * @param[in] manager The update manager
1083  * @param[in] layers list of layers
1084  * @param[in] rootLayer The rool layer
1085  */
1086 inline void SetLayerDepthsMessage(UpdateManager& manager, const std::vector<Layer*>& layers, const Layer* rootLayer)
1087 {
1088   using LocalType = MessageValue2<UpdateManager, std::vector<Layer*>, const Layer*>;
1089
1090   // Reserve some memory inside the message queue
1091   uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType));
1092
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::SetLayerDepths, layers, rootLayer);
1095 }
1096
1097 inline void AddRendererMessage(UpdateManager& manager, OwnerPointer<Renderer>& object)
1098 {
1099   using LocalType = MessageValue1<UpdateManager, OwnerPointer<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::AddRenderer, object);
1105 }
1106
1107 inline void RemoveRendererMessage(UpdateManager& manager, const Renderer& object)
1108 {
1109   using LocalType = MessageValue1<UpdateManager, 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::RemoveRenderer, const_cast<Renderer*>(&object));
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