Merge branch 'devel/master (1.1.2 ~ 1.1.7)' into tizen
[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 Material;
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] glSyncAbstraction Used to determine when framebuffers are ready
99    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
100    * @param[in] propertyNotifier The PropertyNotifier
101    * @param[in] resourceManager The resource manager used to load textures etc.
102    * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
103    * @param[in] controller After messages are flushed, we request a render from the RenderController.
104    * @param[in] renderManager This is responsible for rendering the results of each "update".
105    * @param[in] renderQueue Used to queue messages for the next render.
106    * @param[in] textureCache Used for caching textures.
107    * @param[in] touchResampler Used for re-sampling touch events.
108    */
109   UpdateManager( NotificationManager& notificationManager,
110                  Integration::GlSyncAbstraction& glSyncAbstraction,
111                  CompleteNotificationInterface& animationFinishedNotifier,
112                  PropertyNotifier& propertyNotifier,
113                  ResourceManager& resourceManager,
114                  DiscardQueue& discardQueue,
115                  Integration::RenderController& controller,
116                  RenderManager& renderManager,
117                  RenderQueue& renderQueue,
118                  TextureCache& textureCache,
119                  TouchResampler& touchResampler );
120
121   /**
122    * Destructor.
123    */
124   virtual ~UpdateManager();
125
126   // Node connection methods
127
128   /**
129    * Get the scene graph side list of RenderTasks.
130    * @param[in] systemLevel True if using the system-level overlay.
131    * @return The list of render tasks
132    */
133   RenderTaskList* GetRenderTaskList( bool systemLevel );
134
135   /**
136    * Installs a new layer as the root node.
137    * @pre The UpdateManager does not already have an installed root node.
138    * @pre The layer is of derived Node type Layer.
139    * @pre The layer does not have a parent.
140    * @param[in] layer The new root node.
141    * @param[in] systemLevel True if using the system-level overlay.
142    * @post The node is owned by UpdateManager.
143    */
144   void InstallRoot( Layer* layer, bool systemLevel );
145
146   /**
147    * Add a Node; UpdateManager takes ownership.
148    * @pre The node does not have a parent.
149    * @param[in] node The node to add.
150    */
151   void AddNode( Node* node );
152
153   /**
154    * Connect a Node to the scene-graph.
155    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
156    * @pre The node does not already have a parent.
157    * @param[in] parent The new parent node.
158    */
159   void ConnectNode( Node* parent, Node* node );
160
161   /**
162    * Disconnect a Node from the scene-graph.
163    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
164    * @pre The node has a parent.
165    * @param[in] node The node to disconnect.
166    */
167   void DisconnectNode( Node* node );
168
169   /**
170    * Called when a property is set on a disconnected Node (via public API)
171    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
172    * @pre The node does not have a parent.
173    * @param[in] node The node to set as "active".
174    */
175   void SetNodeActive( Node* node );
176
177   /**
178    * Destroy a Node owned by UpdateManager.
179    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
180    * In the following update, the previously queued Nodes may be deleted.
181    * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
182    * @param[in] node The node to destroy.
183    */
184   void DestroyNode( Node* node );
185
186   /**
187    * Attach an object to a Node.
188    * The UpdateManager is responsible for calling NodeAttachment::Initialize().
189    * @param[in] node The node which will own the attachment.
190    * @param[in] attachment The object to attach.
191    */
192   void AttachToNode( Node* node, NodeAttachment* attachment );
193
194   /**
195    * Add a newly created object.
196    * @param[in] object The object to add.
197    * @post The object is owned by UpdateManager.
198    */
199   void AddObject( PropertyOwner* object );
200
201   /**
202    * Remove an object.
203    * @param[in] object The object to remove.
204    */
205   void RemoveObject( PropertyOwner* object );
206
207   // Animations
208
209   /**
210    * Add a newly created animation.
211    * @param[in] animation The animation to add.
212    * @post The animation is owned by UpdateManager.
213    */
214   void AddAnimation( Animation* animation );
215
216   /**
217    * Stop an animation.
218    * @param[in] animation The animation to stop.
219    */
220   void StopAnimation( Animation* animation );
221
222   /**
223    * Remove an animation.
224    * @param[in] animation The animation to remove.
225    */
226   void RemoveAnimation( Animation* animation );
227
228   /**
229    * Query whether any animations are currently running.
230    * @return True if any animations are running.
231    */
232   bool IsAnimationRunning() const;
233
234   // Property Notification
235
236   /**
237    * Add a newly created property notification
238    * @param[in] propertyNotification The notification to add
239    * @post The propertyNotification is owned by UpdateManager.
240    */
241   void AddPropertyNotification( PropertyNotification* propertyNotification );
242
243   /**
244    * Remove a property notification
245    * @param[in] propertyNotification The notification to remove
246    */
247   void RemovePropertyNotification( PropertyNotification* propertyNotification );
248
249   /**
250    * Set Notify state for PropertyNotification
251    * @param[in] propertyNotification The notification to remove
252    * @param[in] notifyMode The notification mode.
253    */
254   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
255
256   /**
257    * @brief Get the geometry owner
258    *
259    * @return The geometry owner
260    */
261   ObjectOwnerContainer< Geometry >& GetGeometryOwner();
262
263   ObjectOwnerContainer< Renderer >& GetRendererOwner();
264   /**
265    * @brief Get the material owner
266    *
267    * @return The material owner
268    */
269   ObjectOwnerContainer< Material >& GetMaterialOwner();
270
271   /**
272    * @brief Get the property buffer owner
273    *
274    * @return The property buffer owner
275    */
276   ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
277
278
279   // Shaders
280
281   /**
282    * Add a newly created shader.
283    * @param[in] shader The shader to add.
284    * @post The shader is owned by the UpdateManager.
285    */
286   void AddShader(Shader* shader);
287
288   /**
289    * Remove a shader.
290    * @pre The shader has been added to the UpdateManager.
291    * @param[in] shader The shader to remove.
292    * @post The shader is destroyed.
293    */
294   void RemoveShader(Shader* shader);
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 sampler 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    * @post Sends a message to RenderManager to set the new data to the property buffer.
429    */
430   void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
431
432   /**
433    * Sets the size of an existing property buffer
434    * @param[in] propertyBuffer The property buffer.
435    * @param[in] size The new size of the buffer
436    * @post Sends a message to RenderManager to set the new size to the property buffer.
437    */
438   void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
439
440 public:
441
442   /**
443    * Performs an Update traversal on the scene-graph.
444    * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
445    * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
446    * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
447    * @return True if further updates are required e.g. during animations.
448    */
449   unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
450
451   /**
452    * Set the background color i.e. the glClear color used at the beginning of each frame.
453    * @param[in] color The new background color.
454    */
455   void SetBackgroundColor(const Vector4& color);
456
457   /**
458    * Set the default surface rect.
459    * @param[in] rect The rect value representing the surface.
460    */
461   void SetDefaultSurfaceRect( const Rect<int>& rect );
462
463   /**
464    * @copydoc Dali::Stage::KeepRendering()
465    */
466   void KeepRendering( float durationSeconds );
467
468   /**
469    * Sets the depths of all layers.
470    * @param layers The layers in depth order.
471    * @param[in] systemLevel True if using the system-level overlay.
472    */
473   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
474
475 private:
476
477   // Undefined
478   UpdateManager(const UpdateManager&);
479
480   // Undefined
481   UpdateManager& operator=(const UpdateManager& rhs);
482
483   /**
484    * Helper to check whether the update-thread should keep going.
485    * @param[in] elapsedSeconds The time in seconds since the previous update.
486    * @return True if the update-thread should keep going.
487    */
488   unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
489
490   /**
491    * Helper to calculate new camera setup when root node resizes.
492    * @param[in] updateBuffer The buffer to read the root node size from.
493    */
494   void UpdateProjectionAndViewMatrices(int updateBuffer);
495
496   /**
497    * Post process resources that have been updated by renderer
498    */
499   void PostProcessResources();
500
501   /**
502    * Helper to reset all Node properties
503    * @param[in] bufferIndex to use
504    */
505   void ResetProperties( BufferIndex bufferIndex );
506
507   /**
508    * Perform gesture updates.
509    * @param[in] bufferIndex to use
510    * @param[in] lastVSyncTime  The last VSync time in milliseconds.
511    * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
512    * @return true, if any properties were updated.
513    */
514   bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
515
516   /**
517    * Perform animation updates
518    * @param[in] bufferIndex to use
519    * @param[in] elapsedSeconds time since last frame
520    */
521   void Animate( BufferIndex bufferIndex, float elapsedSeconds );
522
523   /**
524    * Perform constraint updates.
525    * @note Applies constraints to nodes first (depth first search order).
526    * Then shader constraints second (construction order)
527    * @param[in] bufferIndex to use
528    */
529   void ApplyConstraints( BufferIndex bufferIndex );
530
531   /**
532    * Perform property notification updates
533    * @param[in] bufferIndex to use
534    */
535   void ProcessPropertyNotifications( BufferIndex bufferIndex );
536
537   /**
538    * Pass shader binaries queued here on to event thread.
539    */
540   void ForwardCompiledShadersToEventThread();
541
542   /**
543    * Update the default camera.
544    * This must be altered to match the root Node for 2D layouting.
545    * @param[in] updateBuffer The buffer to read the root node size from.
546    */
547   void UpdateDefaultCamera( int updateBuffer );
548
549   /**
550    * Update node shaders, opacity, geometry etc.
551    * @param[in] bufferIndex to use
552    */
553   void UpdateNodes( BufferIndex bufferIndex );
554
555   /**
556    * Update Renderers
557    * @param[in] bufferIndex to use
558    */
559   void UpdateRenderers( BufferIndex bufferIndex );
560
561 private:
562
563   // needs to be direct member so that getter for event buffer can be inlined
564   SceneGraphBuffers mSceneGraphBuffers;
565
566   struct Impl;
567   Impl* mImpl;
568
569 };
570
571 // Messages for UpdateManager
572
573 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
574 {
575   typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
576
577   // Reserve some memory inside the message queue
578   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
579
580   // Construct message in the message queue memory; note that delete should not be called on the return value
581   new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
582 }
583
584 inline void AddNodeMessage( UpdateManager& manager, Node& node )
585 {
586   typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
587
588   // Reserve some memory inside the message queue
589   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
590
591   // Construct message in the message queue memory; note that delete should not be called on the return value
592   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
593 }
594
595 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
596 {
597   // Update thread can edit the object
598   Node& parent = const_cast< Node& >( constParent );
599   Node& child = const_cast< Node& >( constChild );
600
601   typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
602
603   // Reserve some memory inside the message queue
604   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
605
606   // Construct message in the message queue memory; note that delete should not be called on the return value
607   new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
608 }
609
610 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
611 {
612   // Scene graph thread can modify this object.
613   Node& node = const_cast< Node& >( constNode );
614
615   typedef MessageValue1< UpdateManager, Node* > LocalType;
616
617   // Reserve some memory inside the message queue
618   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
619
620   // Construct message in the message queue memory; note that delete should not be called on the return value
621   new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
622 }
623
624 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
625 {
626   // Scene graph thread can destroy this object.
627   Node& node = const_cast< Node& >( constNode );
628
629   typedef MessageValue1< UpdateManager, Node* > LocalType;
630
631   // Reserve some memory inside the message queue
632   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
633
634   // Construct message in the message queue memory; note that delete should not be called on the return value
635   new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
636 }
637
638 inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
639 {
640   // Scene graph thread can modify this object.
641   Node& parent = const_cast< Node& >( constParent );
642
643   // @todo MESH_REWORK Don't pass by owner pointer after merge with SceneGraph::RenderableAttachment ? (not needed if we split RendererAttachment to 2 objects)
644   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
645
646   // Reserve some memory inside the message queue
647   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
648
649   // Construct message in the message queue memory; note that delete should not be called on the return value
650   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
651 }
652
653 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
654 {
655   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
656
657   // Reserve some memory inside the message queue
658   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
659
660   // Construct message in the message queue memory; note that delete should not be called on the return value
661   new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
662 }
663
664 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
665 {
666   typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
667
668   // Reserve some memory inside the message queue
669   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
670
671   // Construct message in the message queue memory; note that delete should not be called on the return value
672   new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
673 }
674
675 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
676 {
677   typedef MessageValue1< UpdateManager, Animation* > LocalType;
678
679   // Reserve some memory inside the message queue
680   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
681
682   // Construct message in the message queue memory; note that delete should not be called on the return value
683   new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
684 }
685
686 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
687 {
688   // The scene-graph thread owns this object so it can safely edit it.
689   Animation& animation = const_cast< Animation& >( constAnimation );
690
691   typedef MessageValue1< UpdateManager, Animation* > 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::StopAnimation, &animation );
698 }
699
700 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
701 {
702   // The scene-graph thread owns this object so it can safely edit it.
703   Animation& animation = const_cast< Animation& >( constAnimation );
704
705   typedef MessageValue1< UpdateManager, Animation* > LocalType;
706
707   // Reserve some memory inside the message queue
708   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
709
710   // Construct message in the message queue memory; note that delete should not be called on the return value
711   new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
712 }
713
714 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
715 {
716   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
717
718   // Reserve some memory inside the message queue
719   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
720
721   // Construct message in the message queue memory; note that delete should not be called on the return value
722   new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
723 }
724
725 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
726 {
727   // The scene-graph thread owns this object so it can safely edit it.
728   PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
729
730   typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
731
732   // Reserve some memory inside the message queue
733   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
734
735   // Construct message in the message queue memory; note that delete should not be called on the return value
736   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
737 }
738
739 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
740                                                       const PropertyNotification* constPropertyNotification,
741                                                       PropertyNotification::NotifyMode notifyMode )
742 {
743   // The scene-graph thread owns this object so it can safely edit it.
744   PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
745
746   typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
747
748   // Reserve some memory inside the message queue
749   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
750
751   // Construct message in the message queue memory; note that delete should not be called on the return value
752   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
753 }
754
755 // The render thread can safely change the Shader
756 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
757 {
758   typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
759
760   // Reserve some memory inside the message queue
761   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
762
763   // Construct message in the message queue memory; note that delete should not be called on the return value
764   new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
765 }
766
767 // The render thread can safely change the Shader
768 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
769 {
770   typedef MessageValue1< UpdateManager, Shader* > LocalType;
771
772   // Reserve some memory inside the message queue
773   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
774
775   // Construct message in the message queue memory; note that delete should not be called on the return value
776   new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
777 }
778
779 inline void SetShaderProgramMessage( UpdateManager& manager,
780                                      Shader& shader,
781                                      Internal::ShaderDataPtr shaderData,
782                                      bool modifiesGeometry )
783 {
784   typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
785
786   // Reserve some memory inside the message queue
787   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
788
789   // Construct message in the message queue memory; note that delete should not be called on the return value
790   new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
791 }
792
793 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
794 {
795   typedef MessageValue1< UpdateManager, Vector4 > LocalType;
796
797   // Reserve some memory inside the message queue
798   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
799
800   // Construct message in the message queue memory; note that delete should not be called on the return value
801   new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
802 }
803
804 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect  )
805 {
806   typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
807
808   // Reserve some memory inside the message queue
809   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
810
811   // Construct message in the message queue memory; note that delete should not be called on the return value
812   new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
813 }
814
815 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
816 {
817   typedef MessageValue1< UpdateManager, float > 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::KeepRendering, durationSeconds );
824 }
825
826 /**
827  * Create a message for setting the depth of a layer
828  * @param[in] manager The update manager
829  * @param[in] layers list of layers
830  * @param[in] systemLevel True if the layers are added via the SystemOverlay API
831  */
832 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
833 {
834   typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
835
836   // Reserve some memory inside the message queue
837   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
838
839   // Construct message in the message queue memory; note that delete should not be called on the return value
840   new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
841 }
842
843 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
844 {
845   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
846
847   // Reserve some memory inside the message queue
848   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
849
850   // Construct message in the message queue memory; note that delete should not be called on the return value
851   new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
852 }
853
854 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
855 {
856   typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
857
858   // Reserve some memory inside the message queue
859   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
860
861   // Construct message in the message queue memory; note that delete should not be called on the return value
862   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
863 }
864
865 template< typename T >
866 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
867 {
868   typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
869
870   // Reserve some memory inside the message queue
871   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
872   // Construct message in the message queue memory; note that delete should not be called on the return value
873   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
874 }
875
876 template< typename T >
877 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
878 {
879   typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
880
881   // Reserve some memory inside the message queue
882   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
883   // Construct message in the message queue memory; note that delete should not be called on the return value
884   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
885 }
886
887 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
888 {
889   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
890
891   // Reserve some memory inside the message queue
892   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
893
894   // Construct message in the message queue memory; note that delete should not be called on the return value
895   new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
896 }
897
898 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
899 {
900   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
901
902   // Reserve some memory inside the message queue
903   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
904
905   // Construct message in the message queue memory; note that delete should not be called on the return value
906   new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
907 }
908
909 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
910 {
911   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
912
913   // Reserve some memory inside the message queue
914   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
915
916   // Construct message in the message queue memory; note that delete should not be called on the return value
917   new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
918 }
919
920 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int uWrapMode, unsigned int vWrapMode )
921 {
922   typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int  > LocalType;
923
924   // Reserve some memory inside the message queue
925   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
926
927   // Construct message in the message queue memory; note that delete should not be called on the return value
928   new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, uWrapMode, vWrapMode );
929 }
930
931 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
932 {
933   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
934
935   // Reserve some memory inside the message queue
936   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
937
938   // Construct message in the message queue memory; note that delete should not be called on the return value
939   new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
940 }
941
942 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
943 {
944   typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
945
946   // Reserve some memory inside the message queue
947   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
948
949   // Construct message in the message queue memory; note that delete should not be called on the return value
950   new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
951 }
952
953 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
954 {
955   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format*  > LocalType;
956
957   // Reserve some memory inside the message queue
958   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
959
960   // Construct message in the message queue memory; note that delete should not be called on the return value
961   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
962 }
963
964 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data )
965 {
966   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Vector<char>*  > LocalType;
967
968   // Reserve some memory inside the message queue
969   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
970
971   // Construct message in the message queue memory; note that delete should not be called on the return value
972   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data );
973 }
974
975 inline void SetPropertyBufferSize( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, size_t size )
976 {
977   typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, size_t  > LocalType;
978
979   // Reserve some memory inside the message queue
980   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
981
982   // Construct message in the message queue memory; note that delete should not be called on the return value
983   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferSize, &propertyBuffer, size );
984 }
985
986
987 } // namespace SceneGraph
988
989 } // namespace Internal
990
991 } // namespace Dali
992
993 #endif // __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__