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