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