1 #ifndef DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
5 * Copyright (c) 2017 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/internal/common/message.h>
26 #include <dali/internal/common/type-abstraction-enums.h>
27 #include <dali/internal/common/shader-saver.h>
28 #include <dali/internal/event/common/event-thread-services.h>
29 #include <dali/internal/update/animation/scene-graph-animation.h>
30 #include <dali/internal/update/common/scene-graph-buffers.h>
31 #include <dali/internal/update/common/scene-graph-property-notification.h>
32 #include <dali/internal/update/nodes/node.h>
33 #include <dali/internal/update/nodes/scene-graph-layer.h>
34 #include <dali/internal/update/rendering/scene-graph-renderer.h> // for OwnerPointer< Renderer >
35 #include <dali/internal/update/rendering/scene-graph-texture-set.h> // for OwnerPointer< TextureSet >
36 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
37 #include <dali/internal/update/render-tasks/scene-graph-camera.h>
38 #include <dali/internal/render/shaders/scene-graph-shader.h> // for OwnerPointer< Shader >
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;
65 // value types used by messages
66 template <> struct ParameterType< PropertyNotification::NotifyMode >
67 : public BasicType< PropertyNotification::NotifyMode > {};
76 class RenderTaskProcessor;
82 SceneGraph::Node* node;
84 NodeDepthPair( SceneGraph::Node* node, uint32_t sortedDepth )
86 sortedDepth(sortedDepth)
97 void Add( SceneGraph::Node* node, uint32_t sortedDepth )
99 nodeDepths.push_back( NodeDepthPair( node, sortedDepth ) );
102 std::vector<NodeDepthPair> nodeDepths;
107 * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
108 * other scene graph property owning objects.
109 * It controls the Update traversal, in which nodes are repositioned/animated,
110 * and organizes the the culling and rendering of the scene.
111 * It also maintains the lifecycle of nodes and other property owners that are
112 * disconnected from the scene graph.
114 class UpdateManager : public ShaderSaver
119 * Construct a new UpdateManager.
120 * @param[in] notificationManager This should be notified when animations have finished.
121 * @param[in] animationPlaylist The CompleteNotificationInterface that handles the animations
122 * @param[in] propertyNotifier The PropertyNotifier
123 * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
124 * @param[in] controller After messages are flushed, we request a render from the RenderController.
125 * @param[in] renderManager This is responsible for rendering the results of each "update".
126 * @param[in] renderQueue Used to queue messages for the next render.
127 * @param[in] renderTaskProcessor Handles RenderTasks and RenderInstrucitons.
129 UpdateManager( NotificationManager& notificationManager,
130 CompleteNotificationInterface& animationPlaylist,
131 PropertyNotifier& propertyNotifier,
132 DiscardQueue& discardQueue,
133 Integration::RenderController& controller,
134 RenderManager& renderManager,
135 RenderQueue& renderQueue,
136 RenderTaskProcessor& renderTaskProcessor );
141 virtual ~UpdateManager();
143 // Node connection methods
146 * Installs a new layer as the root node.
147 * @pre The UpdateManager does not already have an installed root node.
148 * @pre The layer is of derived Node type Layer.
149 * @pre The layer does not have a parent.
150 * @param[in] layer The new root node.
151 * @param[in] systemLevel True if using the system-level overlay.
152 * @post The node is owned by UpdateManager.
154 void InstallRoot( OwnerPointer<Layer>& layer, bool systemLevel );
157 * Add a Node; UpdateManager takes ownership.
158 * @pre The node does not have a parent.
159 * @note even though nodes are pool allocated, they also contain other heap allocated data, thus using OwnerPointer when transferring the data
160 * @param[in] node The node to add.
162 void AddNode( OwnerPointer<Node>& node );
165 * Connect a Node to the scene-graph.
166 * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
167 * @pre The node does not already have a parent.
168 * @param[in] parent The new parent node.
170 void ConnectNode( Node* parent, Node* node );
173 * Disconnect a Node from the scene-graph.
174 * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
175 * @pre The node has a parent.
176 * @param[in] node The node to disconnect.
178 void DisconnectNode( Node* node );
181 * Destroy a Node owned by UpdateManager.
182 * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
183 * In the following update, the previously queued Nodes may be deleted.
184 * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
185 * @param[in] node The node to destroy.
187 void DestroyNode( Node* node );
190 * Add a camera on scene
191 * @param[in] camera The camera to add
193 void AddCamera( OwnerPointer< Camera >& camera );
196 * Remove a camera from scene
197 * @param[in] camera to remove
199 void RemoveCamera( const Camera* camera );
202 * Add a newly created object.
203 * @param[in] object The object to add.
204 * @post The object is owned by UpdateManager.
206 void AddObject( OwnerPointer<PropertyOwner>& object );
210 * @param[in] object The object to remove.
212 void RemoveObject( PropertyOwner* object );
217 * Add a newly created animation.
218 * @param[in] animation The animation to add.
219 * @post The animation is owned by UpdateManager.
221 void AddAnimation( OwnerPointer< SceneGraph::Animation >& animation );
225 * @param[in] animation The animation to stop.
227 void StopAnimation( Animation* animation );
230 * Remove an animation.
231 * @param[in] animation The animation to remove.
233 void RemoveAnimation( Animation* animation );
236 * Query whether any animations are currently running.
237 * @return True if any animations are running.
239 bool IsAnimationRunning() const;
241 // Property Notification
244 * Add a newly created property notification
245 * @param[in] propertyNotification The notification to add
246 * @post The propertyNotification is owned by UpdateManager.
248 void AddPropertyNotification( OwnerPointer< PropertyNotification >& propertyNotification );
251 * Remove a property notification
252 * @param[in] propertyNotification The notification to remove
254 void RemovePropertyNotification( PropertyNotification* propertyNotification );
257 * Set Notify state for PropertyNotification
258 * @param[in] propertyNotification The notification to remove
259 * @param[in] notifyMode The notification mode.
261 void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
266 * Add a newly created shader.
267 * @param[in] shader The shader to add.
268 * @post The shader is owned by the UpdateManager.
270 void AddShader( OwnerPointer< Shader >& shader );
274 * @pre The shader has been added to the UpdateManager.
275 * @param[in] shader The shader to remove.
276 * @post The shader is destroyed.
278 void RemoveShader( Shader* shader );
281 * Set the shader program for a Shader object
282 * @param[in] shader The shader to modify
283 * @param[in] shaderData Source code, hash over source, and optional compiled binary for the shader program
284 * @param[in] modifiesGeometry True if the vertex shader modifies geometry
286 void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
289 * @brief Accept compiled shaders passed back on render thread for saving.
290 * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
292 virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
295 * @brief Set the destination for compiled shader binaries to be passed on to.
296 * The dispatcher passed in will be called from the update thread.
297 * @param[in] upstream A sink for ShaderDatas to be passed into.
299 void SetShaderSaver( ShaderSaver& upstream );
304 * Add a new renderer to scene
305 * @param renderer to add
307 void AddRenderer( OwnerPointer< Renderer >& renderer );
310 * Add a renderer from scene
311 * @param renderer to remove
313 void RemoveRenderer( Renderer* renderer );
318 * Set the pan gesture processor.
319 * Pan Gesture processor lives for the lifetime of UpdateManager
320 * @param[in] gesture The gesture processor.
321 * @post The gestureProcessor is owned by the UpdateManager.
323 void SetPanGestureProcessor( PanGesture* gestureProcessor );
328 * Add a newly created TextureSet.
329 * @param[in] textureSet The texture set to add.
330 * @post The TextureSet is owned by the UpdateManager.
332 void AddTextureSet( OwnerPointer< TextureSet >& textureSet );
335 * Remove a TextureSet.
336 * @pre The TextureSet has been added to the UpdateManager.
337 * @param[in] textureSet The TextureSet to remove.
338 * @post The TextureSet is destroyed.
340 void RemoveTextureSet( TextureSet* textureSet );
345 * Get the scene graph side list of RenderTasks.
346 * @param[in] systemLevel True if using the system-level overlay.
347 * @return The list of render tasks
349 RenderTaskList* GetRenderTaskList( bool systemLevel );
351 // Message queue handling
354 * Reserve space for another message in the queue; this must then be initialized by the caller.
355 * The message will be read from the update-thread after the next FlushMessages is called.
356 * @post Calling this method may invalidate any previously returned slots.
357 * @param[in] size The message size with respect to the size of type "char".
358 * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
359 * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
360 * @return A pointer to the first char allocated for the message.
362 unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
365 * @return the current event-buffer index.
367 BufferIndex GetEventBufferIndex() const
369 // inlined as its called often from event thread
370 return mSceneGraphBuffers.GetEventBufferIndex();
374 * Called by the event-thread to signal that FlushQueue will be called
375 * e.g. when it has finished event processing.
377 void EventProcessingStarted();
380 * Flush the set of messages, which were previously stored with QueueMessage().
381 * Calls to this thread-safe method should be minimized, to avoid thread blocking.
383 * @return True if there are messages to process.
388 * Add a new sampler to RenderManager
389 * @param[in] sampler The sampler to add
390 * @post Sends a message to RenderManager to add the sampler.
391 * The sampler will be owned by RenderManager
393 void AddSampler( OwnerPointer< Render::Sampler >& sampler );
396 * Removes an existing sampler from RenderManager
397 * @param[in] sampler The sampler to remove
398 * @post The sampler will be destroyed in the render thread
400 void RemoveSampler( Render::Sampler* sampler );
403 * Sets the filter modes for an existing sampler
404 * @param[in] sampler The sampler
405 * @param[in] minFilterMode The filter to use under minification
406 * @param[in] magFilterMode The filter to use under magnification
408 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
411 * Sets the wrap mode for an existing sampler
412 * @param[in] sampler The sampler
413 * @param[in] rWrapMode Wrapping mode in z direction
414 * @param[in] sWrapMode Wrapping mode in x direction
415 * @param[in] tWrapMode Wrapping mode in y direction
417 void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
420 * Add a new property buffer to RenderManager
421 * @param[in] propertryBuffer The property buffer to add
422 * @post Sends a message to RenderManager to add the property buffer.
423 * The property buffer will be owned by RenderManager
425 void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertryBuffer );
428 * Removes an existing PropertyBuffer from RenderManager
429 * @param[in] propertryBuffer The property buffer to remove
430 * @post The property buffer will be destroyed in the render thread
432 void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
435 * Sets the format of an existing property buffer
436 * @param[in] propertyBuffer The property buffer.
437 * @param[in] format The new format of the buffer
438 * @post Sends a message to RenderManager to set the new format to the property buffer.
440 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
443 * Sets the data of an existing property buffer
444 * @param[in] propertyBuffer The property buffer.
445 * @param[in] data The new data of the buffer
446 * @param[in] size The new size of the buffer
447 * @post Sends a message to RenderManager to set the new data to the property buffer.
449 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<char> >& data, size_t size );
452 * Adds a geometry to the RenderManager
453 * @param[in] geometry The geometry to add
454 * @post Sends a message to RenderManager to add the Geometry
455 * The geometry will be owned by RenderManager
457 void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
460 * Removes an existing Geometry from RenderManager
461 * @param[in] geometry The geometry to remove
462 * @post The geometry will be destroyed in the render thread
464 void RemoveGeometry( Render::Geometry* geometry );
467 * Sets the geometry type of an existing Geometry
468 * @param[in] geometry The geometry
469 * @param[in] geometryType The type of the geometry
471 void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
474 * Sets the index buffer to be used by a geometry
475 * @param[in] geometry The geometry
476 * @param[in] indices A vector containing the indices for the geometry
478 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
481 * Adds a vertex buffer to a geometry
482 * @param[in] geometry The geometry
483 * @param[in] propertyBuffer The property buffer
485 void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
488 * Removes a vertex buffer from a geometry
489 * @param[in] geometry The geometry
490 * @param[in] propertyBuffer The property buffer
492 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
495 * Adds a texture to the render manager
496 * @param[in] texture The texture to add
497 * The texture will be owned by RenderManager
499 void AddTexture( OwnerPointer< Render::Texture >& texture );
502 * Removes a texture from the render manager
503 * @param[in] texture The texture to remove
504 * @post The texture will be destroyed in the render thread
506 void RemoveTexture( Render::Texture* texture );
509 * Uploads data to a texture owned by the RenderManager
510 * @param[in] texture The texture
511 * @param[in] pixelData The pixel data object
512 * @param[in] params The parameters for the upload
514 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
517 * Generates mipmaps for a texture owned by the RenderManager
518 * @param[in] texture The texture
520 void GenerateMipmaps( Render::Texture* texture );
523 * Adds a framebuffer to the render manager
524 * @param[in] frameBuffer The framebuffer to add
525 * The framebuffer will be owned by RenderManager
527 void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
530 * Removes a FrameBuffer from the render manager
531 * @param[in] frameBuffer The FrameBuffer to remove
532 * @post The FrameBuffer will be destroyed in the render thread
534 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
537 * Attach a texture as color output to an existing FrameBuffer
538 * @param[in] frameBuffer The FrameBuffer
539 * @param[in] texture The texture that will be used as output when rendering
540 * @param[in] mipmapLevel The mipmap of the texture to be attached
541 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
543 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int face );
548 * Performs an Update traversal on the scene-graph.
549 * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
550 * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
551 * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
552 * @return True if further updates are required e.g. during animations.
554 unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
557 * Set the background color i.e. the glClear color used at the beginning of each frame.
558 * @param[in] color The new background color.
560 void SetBackgroundColor(const Vector4& color);
563 * Set the default surface rect.
564 * @param[in] rect The rect value representing the surface.
566 void SetDefaultSurfaceRect( const Rect<int>& rect );
569 * @copydoc Dali::Stage::KeepRendering()
571 void KeepRendering( float durationSeconds );
574 * Sets the depths of all layers.
575 * @param layers The layers in depth order.
576 * @param[in] systemLevel True if using the system-level overlay.
578 void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
581 * Set the depth indices of all nodes (in LayerUI's)
582 * @param[in] nodeDepths A vector of nodes and associated depth indices
584 void SetDepthIndices( OwnerPointer< NodeDepths >& nodeDepths );
589 UpdateManager(const UpdateManager&);
592 UpdateManager& operator=(const UpdateManager& rhs);
595 * Helper to check whether the update-thread should keep going.
596 * @param[in] elapsedSeconds The time in seconds since the previous update.
597 * @return True if the update-thread should keep going.
599 unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
602 * Helper to reset all Node properties
603 * @param[in] bufferIndex to use
605 void ResetProperties( BufferIndex bufferIndex );
608 * Perform gesture updates.
609 * @param[in] bufferIndex to use
610 * @param[in] lastVSyncTime The last VSync time in milliseconds.
611 * @param[in] nextVSyncTime The estimated time of the next VSync in milliseconds.
612 * @return true, if any properties were updated.
614 bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
617 * Perform animation updates
618 * @param[in] bufferIndex to use
619 * @param[in] elapsedSeconds time since last frame
621 void Animate( BufferIndex bufferIndex, float elapsedSeconds );
624 * Applies constraints to CustomObjects
625 * @param[in] bufferIndex to use
627 void ConstrainCustomObjects( BufferIndex bufferIndex );
630 * Applies constraints to RenderTasks
631 * @param[in] bufferIndex to use
633 void ConstrainRenderTasks( BufferIndex bufferIndex );
636 * Applies constraints to Shaders
637 * @param[in] bufferIndex to use
639 void ConstrainShaders( BufferIndex bufferIndex );
642 * Perform property notification updates
643 * @param[in] bufferIndex to use
645 void ProcessPropertyNotifications( BufferIndex bufferIndex );
648 * Pass shader binaries queued here on to event thread.
650 void ForwardCompiledShadersToEventThread();
653 * Update node shaders, opacity, geometry etc.
654 * @param[in] bufferIndex to use
656 void UpdateNodes( BufferIndex bufferIndex );
660 * @param[in] bufferIndex to use
662 void UpdateRenderers( BufferIndex bufferIndex );
666 // needs to be direct member so that getter for event buffer can be inlined
667 SceneGraphBuffers mSceneGraphBuffers;
674 // Messages for UpdateManager
676 inline void InstallRootMessage( UpdateManager& manager, OwnerPointer<Layer>& root, bool systemLevel )
678 // Message has ownership of Layer while in transit from event -> update
679 typedef MessageValue2< UpdateManager, OwnerPointer<Layer>, bool > 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::InstallRoot, root, systemLevel );
688 inline void AddNodeMessage( UpdateManager& manager, OwnerPointer<Node>& node )
690 // Message has ownership of Node while in transit from event -> update
691 typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
693 // Reserve some memory inside the message queue
694 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
696 // Construct message in the message queue memory; note that delete should not be called on the return value
697 new (slot) LocalType( &manager, &UpdateManager::AddNode, node );
700 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
702 // Update thread can edit the object
703 Node& parent = const_cast< Node& >( constParent );
704 Node& child = const_cast< Node& >( constChild );
706 typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
708 // Reserve some memory inside the message queue
709 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
711 // Construct message in the message queue memory; note that delete should not be called on the return value
712 new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
715 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
717 // Scene graph thread can modify this object.
718 Node& node = const_cast< Node& >( constNode );
720 typedef MessageValue1< UpdateManager, Node* > LocalType;
722 // Reserve some memory inside the message queue
723 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::DisconnectNode, &node );
729 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
731 // Scene graph thread can destroy this object.
732 Node& node = const_cast< Node& >( constNode );
734 typedef MessageValue1< UpdateManager, Node* > LocalType;
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::DestroyNode, &node );
743 inline void AddCameraMessage( UpdateManager& manager, OwnerPointer< Camera >& camera )
745 // Message has ownership of Camera while in transit from event -> update
746 typedef MessageValue1< UpdateManager, OwnerPointer< Camera > > LocalType;
748 // Reserve some memory inside the message queue
749 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
751 // Construct message in the message queue memory; note that delete should not be called on the return value
752 new (slot) LocalType( &manager, &UpdateManager::AddCamera, camera );
755 inline void RemoveCameraMessage( UpdateManager& manager, const Camera* camera )
757 typedef MessageValue1< UpdateManager, const Camera* > LocalType;
759 // Reserve some memory inside the message queue
760 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
762 // Construct message in the message queue memory; note that delete should not be called on the return value
763 new (slot) LocalType( &manager, &UpdateManager::RemoveCamera, camera );
766 inline void AddObjectMessage( UpdateManager& manager, OwnerPointer<PropertyOwner>& object )
768 // Message has ownership of object while in transit from event -> update
769 typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
771 // Reserve some memory inside the message queue
772 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
774 // Construct message in the message queue memory; note that delete should not be called on the return value
775 new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
778 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
780 typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
782 // Reserve some memory inside the message queue
783 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
785 // Construct message in the message queue memory; note that delete should not be called on the return value
786 new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
789 inline void AddAnimationMessage( UpdateManager& manager, OwnerPointer< SceneGraph::Animation >& animation )
791 typedef MessageValue1< UpdateManager, OwnerPointer< SceneGraph::Animation > > LocalType;
793 // Reserve some memory inside the message queue
794 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
796 // Construct message in the message queue memory; note that delete should not be called on the return value
797 new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
800 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
802 // The scene-graph thread owns this object so it can safely edit it.
803 Animation& animation = const_cast< Animation& >( constAnimation );
805 typedef MessageValue1< UpdateManager, Animation* > LocalType;
807 // Reserve some memory inside the message queue
808 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
810 // Construct message in the message queue memory; note that delete should not be called on the return value
811 new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
814 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
816 // The scene-graph thread owns this object so it can safely edit it.
817 Animation& animation = const_cast< Animation& >( constAnimation );
819 typedef MessageValue1< UpdateManager, Animation* > LocalType;
821 // Reserve some memory inside the message queue
822 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
824 // Construct message in the message queue memory; note that delete should not be called on the return value
825 new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
828 inline void AddPropertyNotificationMessage( UpdateManager& manager, OwnerPointer< PropertyNotification >& propertyNotification )
830 // Message has ownership of PropertyNotification while in transit from event -> update
831 typedef MessageValue1< UpdateManager, OwnerPointer< 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::AddPropertyNotification, propertyNotification );
840 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
842 // The scene-graph thread owns this object so it can safely edit it.
843 PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
845 typedef MessageValue1< UpdateManager, PropertyNotification* > LocalType;
847 // Reserve some memory inside the message queue
848 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
850 // Construct message in the message queue memory; note that delete should not be called on the return value
851 new (slot) LocalType( &manager, &UpdateManager::RemovePropertyNotification, &propertyNotification );
854 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
855 const PropertyNotification* constPropertyNotification,
856 PropertyNotification::NotifyMode notifyMode )
858 // The scene-graph thread owns this object so it can safely edit it.
859 PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
861 typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
863 // Reserve some memory inside the message queue
864 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
866 // Construct message in the message queue memory; note that delete should not be called on the return value
867 new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
870 // The render thread can safely change the Shader
871 inline void AddShaderMessage( UpdateManager& manager, OwnerPointer< Shader >& shader )
873 typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
875 // Reserve some memory inside the message queue
876 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
878 // Construct message in the message queue memory; note that delete should not be called on the return value
879 new (slot) LocalType( &manager, &UpdateManager::AddShader, shader );
882 // The render thread can safely change the Shader
883 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
885 typedef MessageValue1< UpdateManager, Shader* > 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::RemoveShader, &shader );
894 inline void SetShaderProgramMessage( UpdateManager& manager,
896 Internal::ShaderDataPtr shaderData,
897 bool modifiesGeometry )
899 typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
901 // Reserve some memory inside the message queue
902 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::SetShaderProgram, &shader, shaderData, modifiesGeometry );
908 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
910 typedef MessageValue1< UpdateManager, Vector4 > LocalType;
912 // Reserve some memory inside the message queue
913 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
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::SetBackgroundColor, color );
919 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect )
921 typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
923 // Reserve some memory inside the message queue
924 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( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
930 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
932 typedef MessageValue1< UpdateManager, float > LocalType;
934 // Reserve some memory inside the message queue
935 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( &manager, &UpdateManager::KeepRendering, durationSeconds );
942 * Create a message for setting the depth of a layer
943 * @param[in] manager The update manager
944 * @param[in] layers list of layers
945 * @param[in] systemLevel True if the layers are added via the SystemOverlay API
947 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
949 typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
951 // Reserve some memory inside the message queue
952 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
954 // Construct message in the message queue memory; note that delete should not be called on the return value
955 new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
958 inline void AddRendererMessage( UpdateManager& manager, OwnerPointer< Renderer >& object )
960 typedef MessageValue1< UpdateManager, OwnerPointer< Renderer > > LocalType;
962 // Reserve some memory inside the message queue
963 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
964 // Construct message in the message queue memory; note that delete should not be called on the return value
965 new (slot) LocalType( &manager, &UpdateManager::AddRenderer, object );
968 inline void RemoveRendererMessage( UpdateManager& manager, Renderer& object )
970 typedef MessageValue1< UpdateManager, Renderer* > LocalType;
972 // Reserve some memory inside the message queue
973 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
974 // Construct message in the message queue memory; note that delete should not be called on the return value
975 new (slot) LocalType( &manager, &UpdateManager::RemoveRenderer, &object );
978 // The render thread can safely change the Shader
979 inline void AddTextureSetMessage( UpdateManager& manager, OwnerPointer< TextureSet >& textureSet )
981 typedef MessageValue1< UpdateManager, OwnerPointer< TextureSet > > LocalType;
983 // Reserve some memory inside the message queue
984 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
986 // Construct message in the message queue memory; note that delete should not be called on the return value
987 new (slot) LocalType( &manager, &UpdateManager::AddTextureSet, textureSet );
990 // The render thread can safely change the Shader
991 inline void RemoveTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
993 typedef MessageValue1< UpdateManager, TextureSet* > LocalType;
995 // Reserve some memory inside the message queue
996 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
998 // Construct message in the message queue memory; note that delete should not be called on the return value
999 new (slot) LocalType( &manager, &UpdateManager::RemoveTextureSet, &textureSet );
1002 inline void AddSamplerMessage( UpdateManager& manager, OwnerPointer< Render::Sampler >& sampler )
1004 // Message has ownership of Sampler while in transit from event -> update
1005 typedef MessageValue1< UpdateManager, OwnerPointer< Render::Sampler > > LocalType;
1007 // Reserve some memory inside the message queue
1008 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1010 // Construct message in the message queue memory; note that delete should not be called on the return value
1011 new (slot) LocalType( &manager, &UpdateManager::AddSampler, sampler );
1014 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1016 typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
1018 // Reserve some memory inside the message queue
1019 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1021 // Construct message in the message queue memory; note that delete should not be called on the return value
1022 new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
1025 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
1027 typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
1029 // Reserve some memory inside the message queue
1030 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1032 // Construct message in the message queue memory; note that delete should not be called on the return value
1033 new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
1036 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
1038 typedef MessageValue4< UpdateManager, Render::Sampler*, unsigned int, unsigned int, unsigned int > LocalType;
1040 // Reserve some memory inside the message queue
1041 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1043 // Construct message in the message queue memory; note that delete should not be called on the return value
1044 new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, rWrapMode, sWrapMode, tWrapMode );
1047 inline void AddPropertyBuffer( UpdateManager& manager, OwnerPointer< Render::PropertyBuffer >& propertyBuffer )
1049 // Message has ownership of propertyBuffer while in transit from event -> update
1050 typedef MessageValue1< UpdateManager, OwnerPointer< Render::PropertyBuffer > > LocalType;
1052 // Reserve some memory inside the message queue
1053 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1055 // Construct message in the message queue memory; note that delete should not be called on the return value
1056 new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, propertyBuffer );
1059 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1061 typedef MessageValue1< UpdateManager, Render::PropertyBuffer* > LocalType;
1063 // Reserve some memory inside the message queue
1064 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1066 // Construct message in the message queue memory; note that delete should not be called on the return value
1067 new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
1070 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format )
1072 // Message has ownership of PropertyBuffer::Format while in transit from event -> update
1073 typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, OwnerPointer< Render::PropertyBuffer::Format> > LocalType;
1075 // Reserve some memory inside the message queue
1076 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1078 // Construct message in the message queue memory; note that delete should not be called on the return value
1079 new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
1082 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, OwnerPointer< Vector<char> >& data, size_t size )
1084 // Message has ownership of PropertyBuffer data while in transit from event -> update
1085 typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, OwnerPointer< Vector<char> >, size_t > LocalType;
1087 // Reserve some memory inside the message queue
1088 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1090 // Construct message in the message queue memory; note that delete should not be called on the return value
1091 new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
1094 inline void AddGeometry( UpdateManager& manager, OwnerPointer< Render::Geometry >& geometry )
1096 // Message has ownership of Geometry while in transit from event -> update
1097 typedef MessageValue1< UpdateManager, OwnerPointer< Render::Geometry > > LocalType;
1099 // Reserve some memory inside the message queue
1100 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1102 // Construct message in the message queue memory; note that delete should not be called on the return value
1103 new (slot) LocalType( &manager, &UpdateManager::AddGeometry, geometry );
1106 inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
1108 typedef MessageValue1< UpdateManager, Render::Geometry* > LocalType;
1110 // Reserve some memory inside the message queue
1111 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1113 // Construct message in the message queue memory; note that delete should not be called on the return value
1114 new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
1117 inline void AttachVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1119 typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1121 // Reserve some memory inside the message queue
1122 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1124 // Construct message in the message queue memory; note that delete should not be called on the return value
1125 new (slot) LocalType( &manager, &UpdateManager::AttachVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1128 inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1130 typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1132 // Reserve some memory inside the message queue
1133 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1135 // Construct message in the message queue memory; note that delete should not be called on the return value
1136 new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1139 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1140 template< typename T >
1141 class IndexBufferMessage : public MessageBase
1146 * Constructor which does a Vector::Swap()
1148 IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
1150 mManager( manager ),
1151 mRenderGeometry( geometry )
1153 mIndices.Swap( indices );
1157 * Virtual destructor
1159 virtual ~IndexBufferMessage()
1164 * @copydoc MessageBase::Process
1166 virtual void Process( BufferIndex /*bufferIndex*/ )
1168 DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1169 mManager->SetIndexBuffer( mRenderGeometry, mIndices );
1175 Render::Geometry* mRenderGeometry;
1176 Dali::Vector<unsigned short> mIndices;
1179 inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
1181 typedef IndexBufferMessage< UpdateManager > LocalType;
1183 // Reserve some memory inside the message queue
1184 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1186 // Construct message in the message queue memory; note that delete should not be called on the return value
1187 new (slot) LocalType( &manager, &geometry, indices );
1190 inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
1192 typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
1194 // Reserve some memory inside the message queue
1195 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1197 // Construct message in the message queue memory; note that delete should not be called on the return value
1198 new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
1201 inline void AddTexture( UpdateManager& manager, OwnerPointer< Render::Texture >& texture )
1203 // Message has ownership of Texture while in transit from event -> update
1204 typedef MessageValue1< UpdateManager, OwnerPointer< Render::Texture > > LocalType;
1206 // Reserve some memory inside the message queue
1207 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1209 // Construct message in the message queue memory; note that delete should not be called on the return value
1210 new (slot) LocalType( &manager, &UpdateManager::AddTexture, texture );
1213 inline void RemoveTexture( UpdateManager& manager, Render::Texture& texture )
1215 typedef MessageValue1< UpdateManager, Render::Texture* > LocalType;
1217 // Reserve some memory inside the message queue
1218 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1220 // Construct message in the message queue memory; note that delete should not be called on the return value
1221 new (slot) LocalType( &manager, &UpdateManager::RemoveTexture, &texture );
1224 inline void UploadTextureMessage( UpdateManager& manager, Render::Texture& texture, PixelDataPtr pixelData, const Texture::UploadParams& params )
1226 typedef MessageValue3< UpdateManager, Render::Texture*, PixelDataPtr, Texture::UploadParams > LocalType;
1228 // Reserve some memory inside the message queue
1229 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1231 // Construct message in the message queue memory; note that delete should not be called on the return value
1232 new (slot) LocalType( &manager, &UpdateManager::UploadTexture, &texture, pixelData, params );
1235 inline void GenerateMipmapsMessage( UpdateManager& manager, Render::Texture& texture )
1237 typedef MessageValue1< UpdateManager, Render::Texture* > LocalType;
1239 // Reserve some memory inside the message queue
1240 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1242 // Construct message in the message queue memory; note that delete should not be called on the return value
1243 new (slot) LocalType( &manager, &UpdateManager::GenerateMipmaps, &texture );
1247 inline void AddFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1249 typedef MessageValue1< UpdateManager, Render::FrameBuffer* > LocalType;
1251 // Reserve some memory inside the message queue
1252 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1254 // Construct message in the message queue memory; note that delete should not be called on the return value
1255 new (slot) LocalType( &manager, &UpdateManager::AddFrameBuffer, &frameBuffer );
1258 inline void RemoveFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1260 typedef MessageValue1< UpdateManager, Render::FrameBuffer* > LocalType;
1262 // Reserve some memory inside the message queue
1263 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1265 // Construct message in the message queue memory; note that delete should not be called on the return value
1266 new (slot) LocalType( &manager, &UpdateManager::RemoveFrameBuffer, &frameBuffer );
1269 inline void AttachColorTextureToFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int layer )
1271 typedef MessageValue4< UpdateManager, Render::FrameBuffer*, Render::Texture*, unsigned int, unsigned int > LocalType;
1273 // Reserve some memory inside the message queue
1274 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1276 // Construct message in the message queue memory; note that delete should not be called on the return value
1277 new (slot) LocalType( &manager, &UpdateManager::AttachColorTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel, layer );
1280 inline void SetDepthIndicesMessage( UpdateManager& manager, OwnerPointer< NodeDepths >& nodeDepths )
1282 typedef MessageValue1< UpdateManager, OwnerPointer< NodeDepths > > LocalType;
1284 // Reserve some memory inside the message queue
1285 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1287 // Construct message in the message queue memory; note that delete should not be called on the return value
1288 new (slot) LocalType( &manager, &UpdateManager::SetDepthIndices, nodeDepths );
1291 } // namespace SceneGraph
1293 } // namespace Internal
1297 #endif // DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H