1 #ifndef DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/common/dali-common.h>
25 #include <dali/integration-api/resource-declarations.h>
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 #include <dali/internal/event/rendering/texture-impl.h>
47 class GlSyncAbstraction;
48 class RenderController;
50 } // namespace Integration
55 class PropertyNotifier;
56 class NotificationManager;
57 class CompleteNotificationInterface;
58 class ResourceManager;
66 // value types used by messages
67 template <> struct ParameterType< PropertyNotification::NotifyMode >
68 : public BasicType< PropertyNotification::NotifyMode > {};
78 class RenderTaskProcessor;
80 class TextureCacheDispatcher;
86 * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
87 * other scene graph property owning objects.
88 * It controls the Update traversal, in which nodes are repositioned/animated,
89 * and organizes the the culling and rendering of the scene.
90 * It also maintains the lifecycle of nodes and other property owners that are
91 * disconnected from the scene graph.
93 class UpdateManager : public ShaderSaver
98 * Construct a new UpdateManager.
99 * @param[in] notificationManager This should be notified when animations have finished.
100 * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
101 * @param[in] propertyNotifier The PropertyNotifier
102 * @param[in] resourceManager The resource manager used to load textures etc.
103 * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
104 * @param[in] controller After messages are flushed, we request a render from the RenderController.
105 * @param[in] renderManager This is responsible for rendering the results of each "update".
106 * @param[in] renderQueue Used to queue messages for the next render.
107 * @param[in] textureCacheDispatcher Used for sending messages to texture cache.
108 * @param[in] renderTaskProcessor Handles RenderTasks and RenderInstrucitons.
110 UpdateManager( NotificationManager& notificationManager,
111 CompleteNotificationInterface& animationFinishedNotifier,
112 PropertyNotifier& propertyNotifier,
113 ResourceManager& resourceManager,
114 DiscardQueue& discardQueue,
115 Integration::RenderController& controller,
116 RenderManager& renderManager,
117 RenderQueue& renderQueue,
118 TextureCacheDispatcher& textureCacheDispatcher,
119 RenderTaskProcessor& renderTaskProcessor );
124 virtual ~UpdateManager();
126 // Node connection methods
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
133 RenderTaskList* GetRenderTaskList( bool systemLevel );
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.
144 void InstallRoot( Layer* layer, bool systemLevel );
147 * Add a Node; UpdateManager takes ownership.
148 * @pre The node does not have a parent.
149 * @param[in] node The node to add.
151 void AddNode( Node* node );
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.
159 void ConnectNode( Node* parent, Node* node );
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.
167 void DisconnectNode( Node* node );
170 * Destroy a Node owned by UpdateManager.
171 * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
172 * In the following update, the previously queued Nodes may be deleted.
173 * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
174 * @param[in] node The node to destroy.
176 void DestroyNode( Node* node );
179 * Add a camera on scene
180 * @param[in] camera to add
182 void AddCamera( Camera* camera );
185 * Remove a camera from scene
186 * @param[in] camera to remove
188 void RemoveCamera( const Camera* camera );
191 * Add a newly created object.
192 * @param[in] object The object to add.
193 * @post The object is owned by UpdateManager.
195 void AddObject( PropertyOwner* object );
199 * @param[in] object The object to remove.
201 void RemoveObject( PropertyOwner* object );
206 * Add a newly created animation.
207 * @param[in] animation The animation to add.
208 * @post The animation is owned by UpdateManager.
210 void AddAnimation( Animation* animation );
214 * @param[in] animation The animation to stop.
216 void StopAnimation( Animation* animation );
219 * Remove an animation.
220 * @param[in] animation The animation to remove.
222 void RemoveAnimation( Animation* animation );
225 * Query whether any animations are currently running.
226 * @return True if any animations are running.
228 bool IsAnimationRunning() const;
230 // Property Notification
233 * Add a newly created property notification
234 * @param[in] propertyNotification The notification to add
235 * @post The propertyNotification is owned by UpdateManager.
237 void AddPropertyNotification( PropertyNotification* propertyNotification );
240 * Remove a property notification
241 * @param[in] propertyNotification The notification to remove
243 void RemovePropertyNotification( PropertyNotification* propertyNotification );
246 * Set Notify state for PropertyNotification
247 * @param[in] propertyNotification The notification to remove
248 * @param[in] notifyMode The notification mode.
250 void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
253 * @brief Get the renderer owner
255 * @return The renderer owner
257 ObjectOwnerContainer< Renderer >& GetRendererOwner();
260 * @brief Get the property buffer owner
262 * @return The property buffer owner
264 ObjectOwnerContainer< PropertyBuffer >& GetPropertyBufferOwner();
270 * Add a newly created shader.
271 * @param[in] shader The shader to add.
272 * @post The shader is owned by the UpdateManager.
274 void AddShader(Shader* shader);
278 * @pre The shader has been added to the UpdateManager.
279 * @param[in] shader The shader to remove.
280 * @post The shader is destroyed.
282 void RemoveShader(Shader* shader);
285 * Add a newly created TextureSet.
286 * @param[in] textureSet The texture set to add.
287 * @post The TextureSet is owned by the UpdateManager.
289 void AddTextureSet(TextureSet* textureSet);
292 * Remove a TextureSet.
293 * @pre The TextureSet has been added to the UpdateManager.
294 * @param[in] textureSet The TextureSet to remove.
295 * @post The TextureSet is destroyed.
297 void RemoveTextureSet(TextureSet* textureSet);
300 * Set the shader program for a Shader object
301 * @param[in] shader The shader to modify
302 * @param[in] shaderData Source code, hash over source, and optional compiled binary for the shader program
303 * @param[in] modifiesGeometry True if the vertex shader modifies geometry
305 void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
308 * @brief Accept compiled shaders passed back on render thread for saving.
309 * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
311 virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
314 * @brief Set the destination for compiled shader binaries to be passed on to.
315 * The dispatcher passed in will be called from the update thread.
316 * @param[in] upstream A sink for ShaderDatas to be passed into.
318 void SetShaderSaver( ShaderSaver& upstream );
323 * Add a newly created gesture.
324 * @param[in] gesture The gesture to add.
325 * @post The gesture is owned by the UpdateManager.
327 void AddGesture( PanGesture* gesture );
331 * @pre The gesture has been added to the UpdateManager.
332 * @param[in] gesture The gesture to remove.
333 * @post The gesture is destroyed.
335 void RemoveGesture( PanGesture* gesture );
337 // Message queue handling
340 * Reserve space for another message in the queue; this must then be initialized by the caller.
341 * The message will be read from the update-thread after the next FlushMessages is called.
342 * @post Calling this method may invalidate any previously returned slots.
343 * @param[in] size The message size with respect to the size of type "char".
344 * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
345 * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
346 * @return A pointer to the first char allocated for the message.
348 unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
351 * @return the current event-buffer index.
353 BufferIndex GetEventBufferIndex() const
355 // inlined as its called often from event thread
356 return mSceneGraphBuffers.GetEventBufferIndex();
360 * Called by the event-thread to signal that FlushQueue will be called
361 * e.g. when it has finished event processing.
363 void EventProcessingStarted();
366 * Flush the set of messages, which were previously stored with QueueMessage().
367 * Calls to this thread-safe method should be minimized, to avoid thread blocking.
369 * @return True if there are messages to process.
374 * Add a new sampler to RenderManager
375 * @param[in] sampler The sampler to add
376 * @post Sends a message to RenderManager to add the sampler.
377 * The sampler will be owned by RenderManager
379 void AddSampler( Render::Sampler* sampler );
382 * Removes an existing sampler from RenderManager
383 * @param[in] sampler The sampler to remove
384 * @post The sampler will be destroyed in the render thread
386 void RemoveSampler( Render::Sampler* sampler );
389 * Sets the filter modes for an existing sampler
390 * @param[in] sampler The sampler
391 * @param[in] minFilterMode The filter to use under minification
392 * @param[in] magFilterMode The filter to use under magnification
394 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
397 * Sets the wrap mode for an existing sampler
398 * @param[in] sampler The sampler
399 * @param[in] rWrapMode Wrapping mode in z direction
400 * @param[in] sWrapMode Wrapping mode in x direction
401 * @param[in] tWrapMode Wrapping mode in y direction
403 void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
406 * Add a new property buffer to RenderManager
407 * @param[in] propertryBuffer The property buffer to add
408 * @post Sends a message to RenderManager to add the property buffer.
409 * The property buffer will be owned by RenderManager
411 void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer );
414 * Removes an existing PropertyBuffer from RenderManager
415 * @param[in] propertryBuffer The property buffer to remove
416 * @post The property buffer will be destroyed in the render thread
418 void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
421 * Sets the format of an existing property buffer
422 * @param[in] propertyBuffer The property buffer.
423 * @param[in] format The new format of the buffer
424 * @post Sends a message to RenderManager to set the new format to the property buffer.
426 void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
429 * Sets the data of an existing property buffer
430 * @param[in] propertyBuffer The property buffer.
431 * @param[in] data The new data of the buffer
432 * @param[in] size The new size of the buffer
433 * @post Sends a message to RenderManager to set the new data to the property buffer.
435 void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size);
438 * Adds a geometry to the RenderManager
439 * @param[in] geometry The geometry to add
440 * @post Sends a message to RenderManager to add the Geometry
441 * The geometry will be owned by RenderManager
443 void AddGeometry( Render::Geometry* geometry );
446 * Removes an existing Geometry from RenderManager
447 * @param[in] geometry The geometry to remove
448 * @post The geometry will be destroyed in the render thread
450 void RemoveGeometry( Render::Geometry* geometry );
453 * Sets the geometry type of an existing Geometry
454 * @param[in] geometry The geometry
455 * @param[in] geometryType The type of the geometry
457 void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
460 * Sets the index buffer to be used by a geometry
461 * @param[in] geometry The geometry
462 * @param[in] indices A vector containing the indices for the geometry
464 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
467 * Adds a vertex buffer to a geomtry
468 * @param[in] geometry The geometry
469 * @param[in] propertyBuffer The property buffer
471 void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
474 * Removes a vertex buffer from a geometry
475 * @param[in] geometry The geometry
476 * @param[in] propertyBuffer The property buffer
478 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
481 * Adds a texture to the render manager
482 * @param[in] texture The texture to add
483 * The texture will be owned by RenderManager
485 void AddTexture( Render::NewTexture* texture );
488 * Removes a texture from the render manager
489 * @param[in] texture The texture to remove
490 * @post The texture will be destroyed in the render thread
492 void RemoveTexture( Render::NewTexture* texture );
495 * Uploads data to a texture owned by the RenderManager
496 * @param[in] texture The texture
497 * @param[in] pixelData The pixel data object
498 * @param[in] params The parameters for the upload
500 void UploadTexture( Render::NewTexture* texture, PixelDataPtr pixelData, const NewTexture::UploadParams& params );
503 * Generates mipmaps for a texture owned by the RenderManager
504 * @param[in] texture The texture
506 void GenerateMipmaps( Render::NewTexture* texture );
509 * Adds a framebuffer to the render manager
510 * @param[in] frameBuffer The framebuffer to add
511 * The framebuffer will be owned by RenderManager
513 void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
516 * Removes a FrameBuffer from the render manager
517 * @param[in] frameBuffer The FrameBuffer to remove
518 * @post The FrameBuffer will be destroyed in the render thread
520 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
523 * Attach a texture as color output to an existing FrameBuffer
524 * @param[in] frameBuffer The FrameBuffer
525 * @param[in] texture The texture that will be used as output when rendering
526 * @param[in] mipmapLevel The mipmap of the texture to be attached
527 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
529 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int face );
534 * Performs an Update traversal on the scene-graph.
535 * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
536 * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
537 * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
538 * @return True if further updates are required e.g. during animations.
540 unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
543 * Set the background color i.e. the glClear color used at the beginning of each frame.
544 * @param[in] color The new background color.
546 void SetBackgroundColor(const Vector4& color);
549 * Set the default surface rect.
550 * @param[in] rect The rect value representing the surface.
552 void SetDefaultSurfaceRect( const Rect<int>& rect );
555 * @copydoc Dali::Stage::KeepRendering()
557 void KeepRendering( float durationSeconds );
560 * Sets the depths of all layers.
561 * @param layers The layers in depth order.
562 * @param[in] systemLevel True if using the system-level overlay.
564 void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
569 UpdateManager(const UpdateManager&);
572 UpdateManager& operator=(const UpdateManager& rhs);
575 * Helper to check whether the update-thread should keep going.
576 * @param[in] elapsedSeconds The time in seconds since the previous update.
577 * @return True if the update-thread should keep going.
579 unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
582 * Post process resources that have been updated by renderer
584 void PostProcessResources();
587 * Helper to reset all Node properties
588 * @param[in] bufferIndex to use
590 void ResetProperties( BufferIndex bufferIndex );
593 * Perform gesture updates.
594 * @param[in] bufferIndex to use
595 * @param[in] lastVSyncTime The last VSync time in milliseconds.
596 * @param[in] nextVSyncTime The estimated time of the next VSync in milliseconds.
597 * @return true, if any properties were updated.
599 bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
602 * Perform animation updates
603 * @param[in] bufferIndex to use
604 * @param[in] elapsedSeconds time since last frame
606 void Animate( BufferIndex bufferIndex, float elapsedSeconds );
609 * Applies constraints to CustomObjects
610 * @param[in] bufferIndex to use
612 void ConstrainCustomObjects( BufferIndex bufferIndex );
615 * Applies constraints to RenderTasks
616 * @param[in] bufferIndex to use
618 void ConstrainRenderTasks( BufferIndex bufferIndex );
621 * Applies constraints to Shaders
622 * @param[in] bufferIndex to use
624 void ConstrainShaders( BufferIndex bufferIndex );
627 * Perform property notification updates
628 * @param[in] bufferIndex to use
630 void ProcessPropertyNotifications( BufferIndex bufferIndex );
633 * Prepare textures for rendering
635 void PrepareTextureSets( BufferIndex bufferIndex );
638 * Pass shader binaries queued here on to event thread.
640 void ForwardCompiledShadersToEventThread();
643 * Update node shaders, opacity, geometry etc.
644 * @param[in] bufferIndex to use
646 void UpdateNodes( BufferIndex bufferIndex );
650 * @param[in] bufferIndex to use
652 void UpdateRenderers( BufferIndex bufferIndex );
656 // needs to be direct member so that getter for event buffer can be inlined
657 SceneGraphBuffers mSceneGraphBuffers;
664 // Messages for UpdateManager
666 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
668 typedef MessageValue2< UpdateManager, Layer*, bool > LocalType;
670 // Reserve some memory inside the message queue
671 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::InstallRoot, &root, systemLevel );
677 inline void AddNodeMessage( UpdateManager& manager, Node& node )
679 typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
681 // Reserve some memory inside the message queue
682 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
684 // Construct message in the message queue memory; note that delete should not be called on the return value
685 new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
688 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
690 // Update thread can edit the object
691 Node& parent = const_cast< Node& >( constParent );
692 Node& child = const_cast< Node& >( constChild );
694 typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
696 // Reserve some memory inside the message queue
697 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
699 // Construct message in the message queue memory; note that delete should not be called on the return value
700 new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
703 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
705 // Scene graph thread can modify this object.
706 Node& node = const_cast< Node& >( constNode );
708 typedef MessageValue1< UpdateManager, Node* > LocalType;
710 // Reserve some memory inside the message queue
711 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
713 // Construct message in the message queue memory; note that delete should not be called on the return value
714 new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
717 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
719 // Scene graph thread can destroy this object.
720 Node& node = const_cast< Node& >( constNode );
722 typedef MessageValue1< UpdateManager, Node* > LocalType;
724 // Reserve some memory inside the message queue
725 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
727 // Construct message in the message queue memory; note that delete should not be called on the return value
728 new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
731 inline void AddCameraMessage( UpdateManager& manager, const Camera* constCamera )
733 typedef MessageValue1< UpdateManager, Camera* > LocalType;
735 Camera* camera = const_cast<Camera*>( constCamera );
736 // Reserve some memory inside the message queue
737 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
739 // Construct message in the message queue memory; note that delete should not be called on the return value
740 new (slot) LocalType( &manager, &UpdateManager::AddCamera, camera );
743 inline void RemoveCameraMessage( UpdateManager& manager, const Camera* camera )
745 typedef MessageValue1< UpdateManager, const Camera* > LocalType;
747 // Reserve some memory inside the message queue
748 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::RemoveCamera, camera );
754 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
756 typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
758 // Reserve some memory inside the message queue
759 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
761 // Construct message in the message queue memory; note that delete should not be called on the return value
762 new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
765 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
767 typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
769 // Reserve some memory inside the message queue
770 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
772 // Construct message in the message queue memory; note that delete should not be called on the return value
773 new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
776 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
778 typedef MessageValue1< UpdateManager, Animation* > LocalType;
780 // Reserve some memory inside the message queue
781 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
783 // Construct message in the message queue memory; note that delete should not be called on the return value
784 new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
787 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
789 // The scene-graph thread owns this object so it can safely edit it.
790 Animation& animation = const_cast< Animation& >( constAnimation );
792 typedef MessageValue1< UpdateManager, Animation* > LocalType;
794 // Reserve some memory inside the message queue
795 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
797 // Construct message in the message queue memory; note that delete should not be called on the return value
798 new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
801 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
803 // The scene-graph thread owns this object so it can safely edit it.
804 Animation& animation = const_cast< Animation& >( constAnimation );
806 typedef MessageValue1< UpdateManager, Animation* > LocalType;
808 // Reserve some memory inside the message queue
809 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::RemoveAnimation, &animation );
815 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
817 typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
819 // Reserve some memory inside the message queue
820 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::AddPropertyNotification, propertyNotification );
826 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
828 // The scene-graph thread owns this object so it can safely edit it.
829 PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
831 typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
833 // Reserve some memory inside the message queue
834 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::RemovePropertyNotification, &propertyNotification );
840 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
841 const PropertyNotification* constPropertyNotification,
842 PropertyNotification::NotifyMode notifyMode )
844 // The scene-graph thread owns this object so it can safely edit it.
845 PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
847 typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
849 // Reserve some memory inside the message queue
850 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
852 // Construct message in the message queue memory; note that delete should not be called on the return value
853 new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
856 // The render thread can safely change the Shader
857 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
859 typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
861 // Reserve some memory inside the message queue
862 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
864 // Construct message in the message queue memory; note that delete should not be called on the return value
865 new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
868 // The render thread can safely change the Shader
869 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
871 typedef MessageValue1< UpdateManager, Shader* > LocalType;
873 // Reserve some memory inside the message queue
874 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::RemoveShader, &shader );
880 inline void SetShaderProgramMessage( UpdateManager& manager,
882 Internal::ShaderDataPtr shaderData,
883 bool modifiesGeometry )
885 typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
887 // Reserve some memory inside the message queue
888 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
890 // Construct message in the message queue memory; note that delete should not be called on the return value
891 new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
894 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
896 typedef MessageValue1< UpdateManager, Vector4 > LocalType;
898 // Reserve some memory inside the message queue
899 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
901 // Construct message in the message queue memory; note that delete should not be called on the return value
902 new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
905 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect )
907 typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
909 // Reserve some memory inside the message queue
910 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
912 // Construct message in the message queue memory; note that delete should not be called on the return value
913 new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
916 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
918 typedef MessageValue1< UpdateManager, float > LocalType;
920 // Reserve some memory inside the message queue
921 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
923 // Construct message in the message queue memory; note that delete should not be called on the return value
924 new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
928 * Create a message for setting the depth of a layer
929 * @param[in] manager The update manager
930 * @param[in] layers list of layers
931 * @param[in] systemLevel True if the layers are added via the SystemOverlay API
933 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
935 typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
937 // Reserve some memory inside the message queue
938 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
940 // Construct message in the message queue memory; note that delete should not be called on the return value
941 new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
944 inline void AddGestureMessage( UpdateManager& manager, PanGesture* gesture )
946 typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
948 // Reserve some memory inside the message queue
949 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
951 // Construct message in the message queue memory; note that delete should not be called on the return value
952 new (slot) LocalType( &manager, &UpdateManager::AddGesture, gesture );
955 inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
957 typedef MessageValue1< UpdateManager, PanGesture* > LocalType;
959 // Reserve some memory inside the message queue
960 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
962 // Construct message in the message queue memory; note that delete should not be called on the return value
963 new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
966 template< typename T >
967 inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
969 typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
971 // Reserve some memory inside the message queue
972 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
973 // Construct message in the message queue memory; note that delete should not be called on the return value
974 new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
977 template< typename T >
978 inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
980 typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
982 // Reserve some memory inside the message queue
983 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
984 // Construct message in the message queue memory; note that delete should not be called on the return value
985 new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
988 // The render thread can safely change the Shader
989 inline void AddTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
991 typedef MessageValue1< UpdateManager, OwnerPointer< TextureSet > > LocalType;
993 // Reserve some memory inside the message queue
994 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
996 // Construct message in the message queue memory; note that delete should not be called on the return value
997 new (slot) LocalType( &manager, &UpdateManager::AddTextureSet, &textureSet );
1000 // The render thread can safely change the Shader
1001 inline void RemoveTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
1003 typedef MessageValue1< UpdateManager, TextureSet* > LocalType;
1005 // Reserve some memory inside the message queue
1006 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1008 // Construct message in the message queue memory; note that delete should not be called on the return value
1009 new (slot) LocalType( &manager, &UpdateManager::RemoveTextureSet, &textureSet );
1012 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1014 typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
1016 // Reserve some memory inside the message queue
1017 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1019 // Construct message in the message queue memory; note that delete should not be called on the return value
1020 new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
1023 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1025 typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
1027 // Reserve some memory inside the message queue
1028 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1030 // Construct message in the message queue memory; note that delete should not be called on the return value
1031 new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
1034 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
1036 typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
1038 // Reserve some memory inside the message queue
1039 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1041 // Construct message in the message queue memory; note that delete should not be called on the return value
1042 new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
1045 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
1047 typedef MessageValue4< UpdateManager, Render::Sampler*, unsigned int, unsigned int, unsigned int > LocalType;
1049 // Reserve some memory inside the message queue
1050 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1052 // Construct message in the message queue memory; note that delete should not be called on the return value
1053 new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, rWrapMode, sWrapMode, tWrapMode );
1056 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1058 typedef MessageValue1< UpdateManager, Render::PropertyBuffer* > LocalType;
1060 // Reserve some memory inside the message queue
1061 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1063 // Construct message in the message queue memory; note that delete should not be called on the return value
1064 new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
1067 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1069 typedef MessageValue1< UpdateManager, Render::PropertyBuffer* > LocalType;
1071 // Reserve some memory inside the message queue
1072 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1074 // Construct message in the message queue memory; note that delete should not be called on the return value
1075 new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
1078 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
1080 typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format* > LocalType;
1082 // Reserve some memory inside the message queue
1083 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1085 // Construct message in the message queue memory; note that delete should not be called on the return value
1086 new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
1089 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data, size_t size )
1091 typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, Vector<char>*, size_t > LocalType;
1093 // Reserve some memory inside the message queue
1094 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1096 // Construct message in the message queue memory; note that delete should not be called on the return value
1097 new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
1100 inline void AddGeometry( UpdateManager& manager, Render::Geometry& geometry )
1102 typedef MessageValue1< UpdateManager, Render::Geometry* > LocalType;
1104 // Reserve some memory inside the message queue
1105 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1107 // Construct message in the message queue memory; note that delete should not be called on the return value
1108 new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
1111 inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
1113 typedef MessageValue1< UpdateManager, Render::Geometry* > LocalType;
1115 // Reserve some memory inside the message queue
1116 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1118 // Construct message in the message queue memory; note that delete should not be called on the return value
1119 new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
1122 inline void AddVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1124 typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1126 // Reserve some memory inside the message queue
1127 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1129 // Construct message in the message queue memory; note that delete should not be called on the return value
1130 new (slot) LocalType( &manager, &UpdateManager::AddVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1133 inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1135 typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1137 // Reserve some memory inside the message queue
1138 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1140 // Construct message in the message queue memory; note that delete should not be called on the return value
1141 new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1144 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1145 template< typename T >
1146 class IndexBufferMessage : public MessageBase
1151 * Constructor which does a Vector::Swap()
1153 IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
1155 mManager( manager ),
1156 mRenderGeometry( geometry )
1158 mIndices.Swap( indices );
1162 * Virtual destructor
1164 virtual ~IndexBufferMessage()
1169 * @copydoc MessageBase::Process
1171 virtual void Process( BufferIndex /*bufferIndex*/ )
1173 DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1174 mManager->SetIndexBuffer( mRenderGeometry, mIndices );
1180 Render::Geometry* mRenderGeometry;
1181 Dali::Vector<unsigned short> mIndices;
1184 inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
1186 typedef IndexBufferMessage< UpdateManager > LocalType;
1188 // Reserve some memory inside the message queue
1189 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1191 // Construct message in the message queue memory; note that delete should not be called on the return value
1192 new (slot) LocalType( &manager, &geometry, indices );
1195 inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
1197 typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
1199 // Reserve some memory inside the message queue
1200 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1202 // Construct message in the message queue memory; note that delete should not be called on the return value
1203 new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
1206 inline void AddTexture( UpdateManager& manager, Render::NewTexture& texture )
1208 typedef MessageValue1< UpdateManager, Render::NewTexture* > LocalType;
1210 // Reserve some memory inside the message queue
1211 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1213 // Construct message in the message queue memory; note that delete should not be called on the return value
1214 new (slot) LocalType( &manager, &UpdateManager::AddTexture, &texture );
1217 inline void RemoveTexture( UpdateManager& manager, Render::NewTexture& texture )
1219 typedef MessageValue1< UpdateManager, Render::NewTexture* > LocalType;
1221 // Reserve some memory inside the message queue
1222 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1224 // Construct message in the message queue memory; note that delete should not be called on the return value
1225 new (slot) LocalType( &manager, &UpdateManager::RemoveTexture, &texture );
1228 inline void UploadTextureMessage( UpdateManager& manager, Render::NewTexture& texture, PixelDataPtr pixelData, const NewTexture::UploadParams& params )
1230 typedef MessageValue3< UpdateManager, Render::NewTexture*, PixelDataPtr, NewTexture::UploadParams > LocalType;
1232 // Reserve some memory inside the message queue
1233 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1235 // Construct message in the message queue memory; note that delete should not be called on the return value
1236 new (slot) LocalType( &manager, &UpdateManager::UploadTexture, &texture, pixelData, params );
1239 inline void GenerateMipmapsMessage( UpdateManager& manager, Render::NewTexture& texture )
1241 typedef MessageValue1< UpdateManager, Render::NewTexture* > LocalType;
1243 // Reserve some memory inside the message queue
1244 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1246 // Construct message in the message queue memory; note that delete should not be called on the return value
1247 new (slot) LocalType( &manager, &UpdateManager::GenerateMipmaps, &texture );
1251 inline void AddFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1253 typedef MessageValue1< UpdateManager, Render::FrameBuffer* > LocalType;
1255 // Reserve some memory inside the message queue
1256 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1258 // Construct message in the message queue memory; note that delete should not be called on the return value
1259 new (slot) LocalType( &manager, &UpdateManager::AddFrameBuffer, &frameBuffer );
1262 inline void RemoveFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1264 typedef MessageValue1< UpdateManager, Render::FrameBuffer* > LocalType;
1266 // Reserve some memory inside the message queue
1267 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1269 // Construct message in the message queue memory; note that delete should not be called on the return value
1270 new (slot) LocalType( &manager, &UpdateManager::RemoveFrameBuffer, &frameBuffer );
1273 inline void AttachColorTextureToFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer )
1275 typedef MessageValue4< UpdateManager, Render::FrameBuffer*, Render::NewTexture*, unsigned int, unsigned int > LocalType;
1277 // Reserve some memory inside the message queue
1278 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1280 // Construct message in the message queue memory; note that delete should not be called on the return value
1281 new (slot) LocalType( &manager, &UpdateManager::AttachColorTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel, layer );
1285 } // namespace SceneGraph
1287 } // namespace Internal
1291 #endif // DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H