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