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