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