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