745e0425b5dfc5dd4a5d3cc452ef516594078aa5
[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) 2014 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/integration-api/resource-declarations.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/scene-graph-buffers.h>
33 #include <dali/internal/update/common/scene-graph-property-notification.h>
34 #include <dali/internal/update/manager/object-owner-container.h>
35 #include <dali/internal/update/node-attachments/node-attachment.h>
36 #include <dali/internal/update/nodes/node.h>
37 #include <dali/internal/update/nodes/scene-graph-layer.h>
38 #include <dali/internal/update/rendering/scene-graph-renderer.h>
39 #include <dali/internal/render/shaders/scene-graph-shader.h>
40 #include <dali/internal/render/renderers/render-property-buffer.h>
41
42 namespace Dali
43 {
44
45 namespace Integration
46 {
47 class GlSyncAbstraction;
48 class RenderController;
49
50 } // namespace Integration
51
52 namespace Internal
53 {
54
55 class PropertyNotifier;
56 class NotificationManager;
57 class CompleteNotificationInterface;
58 class ResourceManager;
59 class TouchResampler;
60
61 namespace Render
62 {
63 class Sampler;
64 }
65 // value types used by messages
66 template <> struct ParameterType< PropertyNotification::NotifyMode >
67 : public BasicType< PropertyNotification::NotifyMode > {};
68
69 namespace SceneGraph
70 {
71
72 class Animation;
73 class DiscardQueue;
74 class PanGesture;
75 class RenderManager;
76 class RenderTaskList;
77 class RenderQueue;
78 class TextureCache;
79 class PropertyBuffer;
80 class TextureSet;
81
82 /**
83  * UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
84  * other property owner objects.
85  * It controls the Update traversal, in which nodes are repositioned/animated,
86  * and organizes the the culling and rendering of the scene.
87  * It also maintains the lifecycle of nodes and other property owners that are
88  * disconnected from the scene graph.
89  */
90 class UpdateManager : public ShaderSaver
91 {
92 public:
93
94   /**
95    * Construct a new UpdateManager.
96    * @param[in] notificationManager This should be notified when animations have finished.
97    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
98    * @param[in] propertyNotifier The PropertyNotifier
99    * @param[in] resourceManager The resource manager used to load textures etc.
100    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
101    * @param[in] controller After messages are flushed, we request a render from the RenderController.
102    * @param[in] renderManager This is responsible for rendering the results of each "update".
103    * @param[in] renderQueue Used to queue messages for the next render.
104    * @param[in] textureCache Used for caching textures.
105    * @param[in] touchResampler Used for re-sampling touch events.
106    */
107   UpdateManager( NotificationManager& notificationManager,
108                  CompleteNotificationInterface& animationFinishedNotifier,
109                  PropertyNotifier& propertyNotifier,
110                  ResourceManager& resourceManager,
111                  DiscardQueue& discardQueue,
112                  Integration::RenderController& controller,
113                  RenderManager& renderManager,
114                  RenderQueue& renderQueue,
115                  TextureCache& textureCache,
116                  TouchResampler& touchResampler );
117
118   /**
119    * Destructor.
120    */
121   virtual ~UpdateManager();
122
123   // Node connection methods
124
125   /**
126    * Get the scene graph side list of RenderTasks.
127    * @param[in] systemLevel True if using the system-level overlay.
128    * @return The list of render tasks
129    */
130   RenderTaskList* GetRenderTaskList( bool systemLevel );
131
132   /**
133    * Installs a new layer as the root node.
134    * @pre The UpdateManager does not already have an installed root node.
135    * @pre The layer is of derived Node type Layer.
136    * @pre The layer does not have a parent.
137    * @param[in] layer The new root node.
138    * @param[in] systemLevel True if using the system-level overlay.
139    * @post The node is owned by UpdateManager.
140    */
141   void InstallRoot( Layer* layer, bool systemLevel );
142
143   /**
144    * Add a Node; UpdateManager takes ownership.
145    * @pre The node does not have a parent.
146    * @param[in] node The node to add.
147    */
148   void AddNode( Node* node );
149
150   /**
151    * Connect a Node to the scene-graph.
152    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
153    * @pre The node does not already have a parent.
154    * @param[in] parent The new parent node.
155    */
156   void ConnectNode( Node* parent, Node* node );
157
158   /**
159    * Disconnect a Node from the scene-graph.
160    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
161    * @pre The node has a parent.
162    * @param[in] node The node to disconnect.
163    */
164   void DisconnectNode( Node* node );
165
166   /**
167    * Destroy a Node owned by UpdateManager.
168    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
169    * In the following update, the previously queued Nodes may be deleted.
170    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
171    * @param[in] node The node to destroy.
172    */
173   void DestroyNode( Node* node );
174
175   /**
176    * Attach an object to a Node.
177    * The UpdateManager is responsible for calling NodeAttachment::Initialize().
178    * @param[in] node The node which will own the attachment.
179    * @param[in] attachment The object to attach.
180    */
181   void AttachToNode( Node* node, NodeAttachment* attachment );
182
183   /**
184    * Add a newly created object.
185    * @param[in] object The object to add.
186    * @post The object is owned by UpdateManager.
187    */
188   void AddObject( PropertyOwner* object );
189
190   /**
191    * Remove an object.
192    * @param[in] object The object to remove.
193    */
194   void RemoveObject( PropertyOwner* object );
195
196   // Animations
197
198   /**
199    * Add a newly created animation.
200    * @param[in] animation The animation to add.
201    * @post The animation is owned by UpdateManager.
202    */
203   void AddAnimation( Animation* animation );
204
205   /**
206    * Stop an animation.
207    * @param[in] animation The animation to stop.
208    */
209   void StopAnimation( Animation* animation );
210
211   /**
212    * Remove an animation.
213    * @param[in] animation The animation to remove.
214    */
215   void RemoveAnimation( Animation* animation );
216
217   /**
218    * Query whether any animations are currently running.
219    * @return True if any animations are running.
220    */
221   bool IsAnimationRunning() const;
222
223   // Property Notification
224
225   /**
226    * Add a newly created property notification
227    * @param[in] propertyNotification The notification to add
228    * @post The propertyNotification is owned by UpdateManager.
229    */
230   void AddPropertyNotification( PropertyNotification* propertyNotification );
231
232   /**
233    * Remove a property notification
234    * @param[in] propertyNotification The notification to remove
235    */
236   void RemovePropertyNotification( PropertyNotification* propertyNotification );
237
238   /**
239    * Set Notify state for PropertyNotification
240    * @param[in] propertyNotification The notification to remove
241    * @param[in] notifyMode The notification mode.
242    */
243   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
244
245   /**
246    * @brief Get the renderer owner
247    *
248    * @return The renderer owner
249    */
250   ObjectOwnerContainer< Renderer >& GetRendererOwner();
251
252   /**
253    * @brief Get the texture set owner
254    *
255    * @return The texture set owner
256    */
257   ObjectOwnerContainer< TextureSet >& GetTexturesOwner();
258
259   /**
260    * @brief Get the property buffer owner
261    *
262    * @return The property buffer owner
263    */
264   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
265
266
267   // Shaders
268
269   /**
270    * Add a newly created shader.
271    * @param[in] shader The shader to add.
272    * @post The shader is owned by the UpdateManager.
273    */
274   void AddShader(Shader* shader);
275
276   /**
277    * Remove a shader.
278    * @pre The shader has been added to the UpdateManager.
279    * @param[in] shader The shader to remove.
280    * @post The shader is destroyed.
281    */
282   void RemoveShader(Shader* shader);
283
284   /**
285    * Set the shader program for a Shader object
286    * @param[in] shader        The shader to modify
287    * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
288    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
289    */
290   void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
291
292   /**
293    * @brief Accept compiled shaders passed back on render thread for saving.
294    * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
295    */
296   virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
297
298   /**
299    * @brief Set the destination for compiled shader binaries to be passed on to.
300    * The dispatcher passed in will be called from the update thread.
301    * @param[in] upstream A sink for ShaderDatas to be passed into.
302    */
303   void SetShaderSaver( ShaderSaver& upstream );
304
305   // Gestures
306
307   /**
308    * Add a newly created gesture.
309    * @param[in] gesture The gesture to add.
310    * @post The gesture is owned by the UpdateManager.
311    */
312   void AddGesture( PanGesture* gesture );
313
314   /**
315    * Remove a gesture.
316    * @pre The gesture has been added to the UpdateManager.
317    * @param[in] gesture The gesture to remove.
318    * @post The gesture is destroyed.
319    */
320   void RemoveGesture( PanGesture* gesture );
321
322 // Message queue handling
323
324   /**
325    * Reserve space for another message in the queue; this must then be initialized by the caller.
326    * The message will be read from the update-thread after the next FlushMessages is called.
327    * @post Calling this method may invalidate any previously returned slots.
328    * @param[in] size The message size with respect to the size of type "char".
329    * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
330    * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
331    * @return A pointer to the first char allocated for the message.
332    */
333   unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
334
335   /**
336    * @return the current event-buffer index.
337    */
338   BufferIndex GetEventBufferIndex() const
339   {
340     // inlined as its called often from event thread
341     return mSceneGraphBuffers.GetEventBufferIndex();
342   }
343
344   /**
345    * Called by the event-thread to signal that FlushQueue will be called
346    * e.g. when it has finished event processing.
347    */
348   void EventProcessingStarted();
349
350   /**
351    * Flush the set of messages, which were previously stored with QueueMessage().
352    * Calls to this thread-safe method should be minimized, to avoid thread blocking.
353    *
354    * @return True if there are messages to process.
355    */
356   bool FlushQueue();
357
358   /**
359    * Add a new sampler to RenderManager
360    * @param[in] sampler The sampler to add
361    * @post Sends a message to RenderManager to add the sampler.
362    * The sampler will be owned by RenderManager
363    */
364   void AddSampler( Render::Sampler* sampler );
365
366   /**
367    * Removes an existing sampler from RenderManager
368    * @param[in] sampler The sampler to remove
369    * @post The sampler will be destroyed in the render thread
370    */
371   void RemoveSampler( Render::Sampler* sampler );
372
373   /**
374    * Sets the filter modes for an existing sampler
375    * @param[in] sampler The sampler
376    * @param[in] minFilterMode The filter to use under minification
377    * @param[in] magFilterMode The filter to use under magnification
378    */
379   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
380
381   /**
382    * Sets the wrap mode for an existing sampler
383    * @param[in] sampler The sampler
384    * @param[in] uWrapMode Wrapping mode in x direction
385    * @param[in] vWrapMode Wrapping mode in y direction
386    */
387   void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
388
389   /**
390    * Add a new property buffer to RenderManager
391    * @param[in] propertryBuffer The property buffer to add
392    * @post Sends a message to RenderManager to add the property buffer.
393    * The property buffer will be owned by RenderManager
394    */
395   void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer );
396
397   /**
398    * Removes an existing PropertyBuffer from RenderManager
399    * @param[in] propertryBuffer The property buffer to remove
400    * @post The property buffer will be destroyed in the render thread
401    */
402   void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
403
404   /**
405    * Sets the format of an existing property buffer
406    * @param[in] propertyBuffer The property buffer.
407    * @param[in] format The new format of the buffer
408    * @post Sends a message to RenderManager to set the new format to the property buffer.
409    */
410   void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
411
412   /**
413    * Sets the data of an existing property buffer
414    * @param[in] propertyBuffer The property buffer.
415    * @param[in] data The new data of the buffer
416    * @param[in] size The new size of the buffer
417    * @post Sends a message to RenderManager to set the new data to the property buffer.
418    */
419   void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size);
420
421   /**
422    * Adds a geometry to the RenderManager
423    * @param[in] geometry The geometry to add
424    * @post Sends a message to RenderManager to add the Geometry
425    * The geometry will be owned by RenderManager
426    */
427   void AddGeometry( Render::Geometry* geometry );
428
429   /**
430    * Removes an existing Geometry from RenderManager
431    * @param[in] geometry The geometry to remove
432    * @post The geometry will be destroyed in the render thread
433    */
434   void RemoveGeometry( Render::Geometry* geometry );
435
436   /**
437    * Sets if a Geometry requieres depth testing
438    * @param[in] geometry The geometry
439    * @param[in] requiresDepthTest True if the geometry requires depth testing, false otherwise
440    */
441   void SetGeometryRequiresDepthTest( Render::Geometry* geometry, bool requiresDepthTest );
442
443   /**
444    * Sets the geometry type of an existing Geometry
445    * @param[in] geometry The geometry
446    * @param[in] geometryType The type of the geometry
447    */
448   void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
449
450   /**
451    * Sets the index buffer to be used by a geometry
452    * @param[in] geometry The geometry
453    * @param[in] indices A vector containing the indices for the geometry
454    */
455   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
456
457   /**
458    * Adds a vertex buffer to a geomtry
459    * @param[in] geometry The geometry
460    * @param[in] propertyBuffer The property buffer
461    */
462   void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
463
464   /**
465    * Removes a vertex buffer from a geometry
466    * @param[in] geometry The geometry
467    * @param[in] propertyBuffer The property buffer
468    */
469   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
470
471
472 public:
473
474   /**
475    * Performs an Update traversal on the scene-graph.
476    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
477    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
478    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
479    * @return True if further updates are required e.g. during animations.
480    */
481   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
482
483   /**
484    * Set the background color i.e. the glClear color used at the beginning of each frame.
485    * @param[in] color The new background color.
486    */
487   void SetBackgroundColor(const Vector4& color);
488
489   /**
490    * Set the default surface rect.
491    * @param[in] rect The rect value representing the surface.
492    */
493   void SetDefaultSurfaceRect( const Rect<int>& rect );
494
495   /**
496    * @copydoc Dali::Stage::KeepRendering()
497    */
498   void KeepRendering( float durationSeconds );
499
500   /**
501    * Sets the depths of all layers.
502    * @param layers The layers in depth order.
503    * @param[in] systemLevel True if using the system-level overlay.
504    */
505   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
506
507 private:
508
509   // Undefined
510   UpdateManager(const UpdateManager&);
511
512   // Undefined
513   UpdateManager& operator=(const UpdateManager& rhs);
514
515   /**
516    * Helper to check whether the update-thread should keep going.
517    * @param[in] elapsedSeconds The time in seconds since the previous update.
518    * @return True if the update-thread should keep going.
519    */
520   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
521
522   /**
523    * Helper to calculate new camera setup when root node resizes.
524    * @param[in] updateBuffer The buffer to read the root node size from.
525    */
526   void UpdateProjectionAndViewMatrices(int updateBuffer);
527
528   /**
529    * Post process resources that have been updated by renderer
530    */
531   void PostProcessResources();
532
533   /**
534    * Helper to reset all Node properties
535    * @param[in] bufferIndex to use
536    */
537   void ResetProperties( BufferIndex bufferIndex );
538
539   /**
540    * Perform gesture updates.
541    * @param[in] bufferIndex to use
542    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
543    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
544    * @return true, if any properties were updated.
545    */
546   bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
547
548   /**
549    * Perform animation updates
550    * @param[in] bufferIndex to use
551    * @param[in] elapsedSeconds time since last frame
552    */
553   void Animate( BufferIndex bufferIndex, float elapsedSeconds );
554
555   /**
556    * Applies constraints to CustomObjects
557    * @param[in] bufferIndex to use
558    */
559   void ConstrainCustomObjects( BufferIndex bufferIndex );
560
561   /**
562    * Applies constraints to RenderTasks
563    * @param[in] bufferIndex to use
564    */
565   void ConstrainRenderTasks( BufferIndex bufferIndex );
566
567   /**
568    * Applies constraints to Shaders
569    * @param[in] bufferIndex to use
570    */
571   void ConstrainShaders( BufferIndex bufferIndex );
572
573   /**
574    * Perform property notification updates
575    * @param[in] bufferIndex to use
576    */
577   void ProcessPropertyNotifications( BufferIndex bufferIndex );
578
579   /**
580    * Prepare textures for rendering
581    */
582   void PrepareTextureSets( BufferIndex bufferIndex );
583
584   /**
585    * Pass shader binaries queued here on to event thread.
586    */
587   void ForwardCompiledShadersToEventThread();
588
589   /**
590    * Update the default camera.
591    * This must be altered to match the root Node for 2D layouting.
592    * @param[in] updateBuffer The buffer to read the root node size from.
593    */
594   void UpdateDefaultCamera( int updateBuffer );
595
596   /**
597    * Update node shaders, opacity, geometry etc.
598    * @param[in] bufferIndex to use
599    */
600   void UpdateNodes( BufferIndex bufferIndex );
601
602   /**
603    * Update Renderers
604    * @param[in] bufferIndex to use
605    */
606   void UpdateRenderers( BufferIndex bufferIndex );
607
608 private:
609
610   // needs to be direct member so that getter for event buffer can be inlined
611   SceneGraphBuffers mSceneGraphBuffers;
612
613   struct Impl;
614   Impl* mImpl;
615
616 };
617
618 // Messages for UpdateManager
619
620 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
621 {
622   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
623
624   // Reserve some memory inside the message queue
625   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
626
627   // Construct message in the message queue memory; note that delete should not be called on the return value
628   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
629 }
630
631 inline void AddNodeMessage( UpdateManager& manager, Node& node )
632 {
633   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
634
635   // Reserve some memory inside the message queue
636   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
637
638   // Construct message in the message queue memory; note that delete should not be called on the return value
639   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
640 }
641
642 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
643 {
644   // Update thread can edit the object
645   Node& parent = const_cast< Node& >( constParent );
646   Node& child = const_cast< Node& >( constChild );
647
648   typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
649
650   // Reserve some memory inside the message queue
651   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
652
653   // Construct message in the message queue memory; note that delete should not be called on the return value
654   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
655 }
656
657 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
658 {
659   // Scene graph thread can modify this object.
660   Node& node = const_cast< Node& >( constNode );
661
662   typedef MessageValue1< UpdateManager, Node* > LocalType;
663
664   // Reserve some memory inside the message queue
665   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
666
667   // Construct message in the message queue memory; note that delete should not be called on the return value
668   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
669 }
670
671 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
672 {
673   // Scene graph thread can destroy this object.
674   Node& node = const_cast< Node& >( constNode );
675
676   typedef MessageValue1< UpdateManager, Node* > LocalType;
677
678   // Reserve some memory inside the message queue
679   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
680
681   // Construct message in the message queue memory; note that delete should not be called on the return value
682   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
683 }
684
685 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
686 {
687   // Scene graph thread can modify this object.
688   Node& parent = const_cast< Node& >( constParent );
689
690   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
691
692   // Reserve some memory inside the message queue
693   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
694
695   // Construct message in the message queue memory; note that delete should not be called on the return value
696   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
697 }
698
699 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
700 {
701   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
702
703   // Reserve some memory inside the message queue
704   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
705
706   // Construct message in the message queue memory; note that delete should not be called on the return value
707   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
708 }
709
710 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
711 {
712   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
713
714   // Reserve some memory inside the message queue
715   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
716
717   // Construct message in the message queue memory; note that delete should not be called on the return value
718   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
719 }
720
721 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
722 {
723   typedef MessageValue1< UpdateManager, Animation* > LocalType;
724
725   // Reserve some memory inside the message queue
726   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
727
728   // Construct message in the message queue memory; note that delete should not be called on the return value
729   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
730 }
731
732 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
733 {
734   // The scene-graph thread owns this object so it can safely edit it.
735   Animation& animation = const_cast< Animation& >( constAnimation );
736
737   typedef MessageValue1< UpdateManager, Animation* > LocalType;
738
739   // Reserve some memory inside the message queue
740   unsigned int* 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::StopAnimation, &animation );
744 }
745
746 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
747 {
748   // The scene-graph thread owns this object so it can safely edit it.
749   Animation& animation = const_cast< Animation& >( constAnimation );
750
751   typedef MessageValue1< UpdateManager, Animation* > LocalType;
752
753   // Reserve some memory inside the message queue
754   unsigned int* 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::RemoveAnimation, &animation );
758 }
759
760 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
761 {
762   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
763
764   // Reserve some memory inside the message queue
765   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
766
767   // Construct message in the message queue memory; note that delete should not be called on the return value
768   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
769 }
770
771 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
772 {
773   // The scene-graph thread owns this object so it can safely edit it.
774   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
775
776   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
777
778   // Reserve some memory inside the message queue
779   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
780
781   // Construct message in the message queue memory; note that delete should not be called on the return value
782   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
783 }
784
785 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
786                                                       const PropertyNotification* constPropertyNotification,
787                                                       PropertyNotification::NotifyMode notifyMode )
788 {
789   // The scene-graph thread owns this object so it can safely edit it.
790   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
791
792   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
793
794   // Reserve some memory inside the message queue
795   unsigned int* 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::PropertyNotificationSetNotify, propertyNotification, notifyMode );
799 }
800
801 // The render thread can safely change the Shader
802 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
803 {
804   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
805
806   // Reserve some memory inside the message queue
807   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
808
809   // Construct message in the message queue memory; note that delete should not be called on the return value
810   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
811 }
812
813 // The render thread can safely change the Shader
814 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
815 {
816   typedef MessageValue1< UpdateManager, Shader* > LocalType;
817
818   // Reserve some memory inside the message queue
819   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
820
821   // Construct message in the message queue memory; note that delete should not be called on the return value
822   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
823 }
824
825 inline void SetShaderProgramMessage( UpdateManager& manager,
826                                      Shader& shader,
827                                      Internal::ShaderDataPtr shaderData,
828                                      bool modifiesGeometry )
829 {
830   typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
831
832   // Reserve some memory inside the message queue
833   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
834
835   // Construct message in the message queue memory; note that delete should not be called on the return value
836   new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
837 }
838
839 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
840 {
841   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
842
843   // Reserve some memory inside the message queue
844   unsigned int* 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::SetBackgroundColor, color );
848 }
849
850 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
851 {
852   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
853
854   // Reserve some memory inside the message queue
855   unsigned int* 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::SetDefaultSurfaceRect, rect );
859 }
860
861 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
862 {
863   typedef MessageValue1< UpdateManager, float > LocalType;
864
865   // Reserve some memory inside the message queue
866   unsigned int* 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::KeepRendering, durationSeconds );
870 }
871
872 /**
873  * Create a message for setting the depth of a layer
874  * @param[in] manager The update manager
875  * @param[in] layers list of layers
876  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
877  */
878 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
879 {
880   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
881
882   // Reserve some memory inside the message queue
883   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
884
885   // Construct message in the message queue memory; note that delete should not be called on the return value
886   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
887 }
888
889 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
890 {
891   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
892
893   // Reserve some memory inside the message queue
894   unsigned int* 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::AddGesture, gesture );
898 }
899
900 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
901 {
902   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
903
904   // Reserve some memory inside the message queue
905   unsigned int* 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::RemoveGesture, gesture );
909 }
910
911 template< typename T >
912 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
913 {
914   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
915
916   // Reserve some memory inside the message queue
917   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
918   // Construct message in the message queue memory; note that delete should not be called on the return value
919   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
920 }
921
922 template< typename T >
923 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
924 {
925   typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
926
927   // Reserve some memory inside the message queue
928   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
929   // Construct message in the message queue memory; note that delete should not be called on the return value
930   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
931 }
932
933 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
934 {
935   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
936
937   // Reserve some memory inside the message queue
938   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
939
940   // Construct message in the message queue memory; note that delete should not be called on the return value
941   new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
942 }
943
944 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
945 {
946   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
947
948   // Reserve some memory inside the message queue
949   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
950
951   // Construct message in the message queue memory; note that delete should not be called on the return value
952   new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
953 }
954
955 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
956 {
957   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
958
959   // Reserve some memory inside the message queue
960   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
961
962   // Construct message in the message queue memory; note that delete should not be called on the return value
963   new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
964 }
965
966 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int uWrapMode, unsigned int vWrapMode )
967 {
968   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int  > LocalType;
969
970   // Reserve some memory inside the message queue
971   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
972
973   // Construct message in the message queue memory; note that delete should not be called on the return value
974   new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, uWrapMode, vWrapMode );
975 }
976
977 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
978 {
979   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
980
981   // Reserve some memory inside the message queue
982   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
983
984   // Construct message in the message queue memory; note that delete should not be called on the return value
985   new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
986 }
987
988 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
989 {
990   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
991
992   // Reserve some memory inside the message queue
993   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
994
995   // Construct message in the message queue memory; note that delete should not be called on the return value
996   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
997 }
998
999 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
1000 {
1001   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format*  > LocalType;
1002
1003   // Reserve some memory inside the message queue
1004   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1005
1006   // Construct message in the message queue memory; note that delete should not be called on the return value
1007   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
1008 }
1009
1010 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data, size_t size )
1011 {
1012   typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, Vector<char>*, size_t  > LocalType;
1013
1014   // Reserve some memory inside the message queue
1015   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1016
1017   // Construct message in the message queue memory; note that delete should not be called on the return value
1018   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
1019 }
1020
1021 inline void AddGeometry( UpdateManager& manager, Render::Geometry& geometry )
1022 {
1023   typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
1024
1025   // Reserve some memory inside the message queue
1026   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1027
1028   // Construct message in the message queue memory; note that delete should not be called on the return value
1029   new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
1030 }
1031
1032 inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
1033 {
1034   typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
1035
1036   // Reserve some memory inside the message queue
1037   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1038
1039   // Construct message in the message queue memory; note that delete should not be called on the return value
1040   new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
1041 }
1042
1043 inline void AddVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1044 {
1045   typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1046
1047   // Reserve some memory inside the message queue
1048   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1049
1050   // Construct message in the message queue memory; note that delete should not be called on the return value
1051   new (slot) LocalType( &manager, &UpdateManager::AddVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1052 }
1053
1054 inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1055 {
1056   typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1057
1058   // Reserve some memory inside the message queue
1059   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1060
1061   // Construct message in the message queue memory; note that delete should not be called on the return value
1062   new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1063 }
1064
1065 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1066 template< typename T >
1067 class IndexBufferMessage : public MessageBase
1068 {
1069 public:
1070
1071   /**
1072    * Constructor which does a Vector::Swap()
1073    */
1074   IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
1075   : MessageBase(),
1076     mManager( manager ),
1077     mRenderGeometry( geometry )
1078   {
1079     mIndices.Swap( indices );
1080   }
1081
1082   /**
1083    * Virtual destructor
1084    */
1085   virtual ~IndexBufferMessage()
1086   {
1087   }
1088
1089   /**
1090    * @copydoc MessageBase::Process
1091    */
1092   virtual void Process( BufferIndex /*bufferIndex*/ )
1093   {
1094     DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1095     mManager->SetIndexBuffer( mRenderGeometry, mIndices );
1096   }
1097
1098 private:
1099
1100   T* mManager;
1101   Render::Geometry* mRenderGeometry;
1102   Dali::Vector<unsigned short> mIndices;
1103 };
1104
1105 inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
1106 {
1107   typedef IndexBufferMessage< UpdateManager > LocalType;
1108
1109   // Reserve some memory inside the message queue
1110   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1111
1112   // Construct message in the message queue memory; note that delete should not be called on the return value
1113   new (slot) LocalType( &manager, &geometry, indices );
1114 }
1115
1116 inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
1117 {
1118   typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
1119
1120   // Reserve some memory inside the message queue
1121   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1122
1123   // Construct message in the message queue memory; note that delete should not be called on the return value
1124   new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
1125 }
1126
1127 inline void SetGeometryRequiresDepthTestMessage( UpdateManager& manager, Render::Geometry& geometry, bool requiresDepthTest )
1128 {
1129   typedef MessageValue2< UpdateManager, Render::Geometry*, bool > LocalType;
1130
1131   // Reserve some memory inside the message queue
1132   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1133
1134   // Construct message in the message queue memory; note that delete should not be called on the return value
1135   new (slot) LocalType( &manager, &UpdateManager::SetGeometryRequiresDepthTest, &geometry, requiresDepthTest );
1136 }
1137
1138 } // namespace SceneGraph
1139
1140 } // namespace Internal
1141
1142 } // namespace Dali
1143
1144 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__