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