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