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