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