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/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/nodes/node.h>
35 #include <dali/internal/update/nodes/scene-graph-layer.h>
36 #include <dali/internal/update/rendering/scene-graph-renderer.h> // for OwnerPointer< Renderer >
37 #include <dali/internal/update/rendering/scene-graph-texture-set.h> // for OwnerPointer< TextureSet >
38 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
39 #include <dali/internal/update/render-tasks/scene-graph-camera.h>
40 #include <dali/internal/render/shaders/scene-graph-shader.h> // for OwnerPointer< Shader >
41 #include <dali/internal/render/renderers/render-property-buffer.h>
42 #include <dali/internal/event/rendering/texture-impl.h>
49 class GlSyncAbstraction;
50 class RenderController;
52 } // namespace Integration
57 class PropertyNotifier;
58 class NotificationManager;
59 class CompleteNotificationInterface;
67 // value types used by messages
68 template <> struct ParameterType< PropertyNotification::NotifyMode >
69 : public BasicType< PropertyNotification::NotifyMode > {};
78 class RenderTaskProcessor;
84 SceneGraph::Node* node;
86 NodeDepthPair( SceneGraph::Node* node, uint32_t sortedDepth )
88 sortedDepth(sortedDepth)
95 std::vector<NodeDepthPair> nodeDepths;
96 NodeDepths( int reserveSize )
98 nodeDepths.reserve(reserveSize);
101 void Add( SceneGraph::Node* node, uint32_t sortedDepth )
103 nodeDepths.push_back( NodeDepthPair( node, sortedDepth ) );
109 * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
110 * other scene graph property owning objects.
111 * It controls the Update traversal, in which nodes are repositioned/animated,
112 * and organizes the the culling and rendering of the scene.
113 * It also maintains the lifecycle of nodes and other property owners that are
114 * disconnected from the scene graph.
116 class UpdateManager : public ShaderSaver
121 * Construct a new UpdateManager.
122 * @param[in] notificationManager This should be notified when animations have finished.
123 * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
124 * @param[in] propertyNotifier The PropertyNotifier
125 * @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
126 * @param[in] controller After messages are flushed, we request a render from the RenderController.
127 * @param[in] renderManager This is responsible for rendering the results of each "update".
128 * @param[in] renderQueue Used to queue messages for the next render.
129 * @param[in] renderTaskProcessor Handles RenderTasks and RenderInstrucitons.
131 UpdateManager( NotificationManager& notificationManager,
132 CompleteNotificationInterface& animationFinishedNotifier,
133 PropertyNotifier& propertyNotifier,
134 DiscardQueue& discardQueue,
135 Integration::RenderController& controller,
136 RenderManager& renderManager,
137 RenderQueue& renderQueue,
138 RenderTaskProcessor& renderTaskProcessor );
143 virtual ~UpdateManager();
145 // Node connection methods
148 * Installs a new layer as the root node.
149 * @pre The UpdateManager does not already have an installed root node.
150 * @pre The layer is of derived Node type Layer.
151 * @pre The layer does not have a parent.
152 * @param[in] layer The new root node.
153 * @param[in] systemLevel True if using the system-level overlay.
154 * @post The node is owned by UpdateManager.
156 void InstallRoot( Layer* layer, bool systemLevel );
159 * Add a Node; UpdateManager takes ownership.
160 * @pre The node does not have a parent.
161 * @param[in] node The node to add.
163 void AddNode( Node* node );
166 * Connect a Node to the scene-graph.
167 * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
168 * @pre The node does not already have a parent.
169 * @param[in] parent The new parent node.
171 void ConnectNode( Node* parent, Node* node );
174 * Disconnect a Node from the scene-graph.
175 * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
176 * @pre The node has a parent.
177 * @param[in] node The node to disconnect.
179 void DisconnectNode( Node* node );
182 * Destroy a Node owned by UpdateManager.
183 * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
184 * In the following update, the previously queued Nodes may be deleted.
185 * @pre The node has been disconnected from the scene-graph i.e. has no parent or children.
186 * @param[in] node The node to destroy.
188 void DestroyNode( Node* node );
191 * Add a camera on scene
192 * @param[in] camera to add
194 void AddCamera( Camera* camera );
197 * Remove a camera from scene
198 * @param[in] camera to remove
200 void RemoveCamera( const Camera* camera );
203 * Add a newly created object.
204 * @param[in] object The object to add.
205 * @post The object is owned by UpdateManager.
207 void AddObject( PropertyOwner* object );
211 * @param[in] object The object to remove.
213 void RemoveObject( PropertyOwner* object );
218 * Add a newly created animation.
219 * @param[in] animation The animation to add.
220 * @post The animation is owned by UpdateManager.
222 void AddAnimation( Animation* animation );
226 * @param[in] animation The animation to stop.
228 void StopAnimation( Animation* animation );
231 * Remove an animation.
232 * @param[in] animation The animation to remove.
234 void RemoveAnimation( Animation* animation );
237 * Query whether any animations are currently running.
238 * @return True if any animations are running.
240 bool IsAnimationRunning() const;
242 // Property Notification
245 * Add a newly created property notification
246 * @param[in] propertyNotification The notification to add
247 * @post The propertyNotification is owned by UpdateManager.
249 void AddPropertyNotification( PropertyNotification* propertyNotification );
252 * Remove a property notification
253 * @param[in] propertyNotification The notification to remove
255 void RemovePropertyNotification( PropertyNotification* propertyNotification );
258 * Set Notify state for PropertyNotification
259 * @param[in] propertyNotification The notification to remove
260 * @param[in] notifyMode The notification mode.
262 void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
267 * Add a newly created shader.
268 * @param[in] shader The shader to add.
269 * @post The shader is owned by the UpdateManager.
271 void AddShader(Shader* shader);
275 * @pre The shader has been added to the UpdateManager.
276 * @param[in] shader The shader to remove.
277 * @post The shader is destroyed.
279 void RemoveShader(Shader* shader);
282 * Set the shader program for a Shader object
283 * @param[in] shader The shader to modify
284 * @param[in] shaderData Source code, hash over source, and optional compiled binary for the shader program
285 * @param[in] modifiesGeometry True if the vertex shader modifies geometry
287 void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
290 * @brief Accept compiled shaders passed back on render thread for saving.
291 * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
293 virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
296 * @brief Set the destination for compiled shader binaries to be passed on to.
297 * The dispatcher passed in will be called from the update thread.
298 * @param[in] upstream A sink for ShaderDatas to be passed into.
300 void SetShaderSaver( ShaderSaver& upstream );
305 * Add a new renderer to scene
306 * @param renderer to add
308 void AddRenderer( Renderer* renderer );
311 * Add a renderer from scene
312 * @param renderer to remove
314 void RemoveRenderer( Renderer* renderer );
319 * Set the pan gesture processor.
320 * Pan Gesture processor lives for the lifetime of UpdateManager
321 * @param[in] gesture The gesture processor.
322 * @post The gestureProcessor is owned by the UpdateManager.
324 void SetPanGestureProcessor( PanGesture* gestureProcessor );
329 * Add a newly created TextureSet.
330 * @param[in] textureSet The texture set to add.
331 * @post The TextureSet is owned by the UpdateManager.
333 void AddTextureSet( TextureSet* textureSet );
336 * Remove a TextureSet.
337 * @pre The TextureSet has been added to the UpdateManager.
338 * @param[in] textureSet The TextureSet to remove.
339 * @post The TextureSet is destroyed.
341 void RemoveTextureSet( TextureSet* textureSet );
346 * Get the scene graph side list of RenderTasks.
347 * @param[in] systemLevel True if using the system-level overlay.
348 * @return The list of render tasks
350 RenderTaskList* GetRenderTaskList( bool systemLevel );
352 // Message queue handling
355 * Reserve space for another message in the queue; this must then be initialized by the caller.
356 * The message will be read from the update-thread after the next FlushMessages is called.
357 * @post Calling this method may invalidate any previously returned slots.
358 * @param[in] size The message size with respect to the size of type "char".
359 * @param[in] updateScene A flag, when true denotes that the message will cause the scene-graph node tree to require an update.
360 * @note the default value of updateScene should match that in EventThreadServices::ReserveMessageSlot.
361 * @return A pointer to the first char allocated for the message.
363 unsigned int* ReserveMessageSlot( std::size_t size, bool updateScene = true );
366 * @return the current event-buffer index.
368 BufferIndex GetEventBufferIndex() const
370 // inlined as its called often from event thread
371 return mSceneGraphBuffers.GetEventBufferIndex();
375 * Called by the event-thread to signal that FlushQueue will be called
376 * e.g. when it has finished event processing.
378 void EventProcessingStarted();
381 * Flush the set of messages, which were previously stored with QueueMessage().
382 * Calls to this thread-safe method should be minimized, to avoid thread blocking.
384 * @return True if there are messages to process.
389 * Add a new sampler to RenderManager
390 * @param[in] sampler The sampler to add
391 * @post Sends a message to RenderManager to add the sampler.
392 * The sampler will be owned by RenderManager
394 void AddSampler( Render::Sampler* sampler );
397 * Removes an existing sampler from RenderManager
398 * @param[in] sampler The sampler to remove
399 * @post The sampler will be destroyed in the render thread
401 void RemoveSampler( Render::Sampler* sampler );
404 * Sets the filter modes for an existing sampler
405 * @param[in] sampler The sampler
406 * @param[in] minFilterMode The filter to use under minification
407 * @param[in] magFilterMode The filter to use under magnification
409 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
412 * Sets the wrap mode for an existing sampler
413 * @param[in] sampler The sampler
414 * @param[in] rWrapMode Wrapping mode in z direction
415 * @param[in] sWrapMode Wrapping mode in x direction
416 * @param[in] tWrapMode Wrapping mode in y direction
418 void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
421 * Add a new property buffer to RenderManager
422 * @param[in] propertryBuffer The property buffer to add
423 * @post Sends a message to RenderManager to add the property buffer.
424 * The property buffer will be owned by RenderManager
426 void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer );
429 * Removes an existing PropertyBuffer from RenderManager
430 * @param[in] propertryBuffer The property buffer to remove
431 * @post The property buffer will be destroyed in the render thread
433 void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
436 * Sets the format of an existing property buffer
437 * @param[in] propertyBuffer The property buffer.
438 * @param[in] format The new format of the buffer
439 * @post Sends a message to RenderManager to set the new format to the property buffer.
441 void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
444 * Sets the data of an existing property buffer
445 * @param[in] propertyBuffer The property buffer.
446 * @param[in] data The new data of the buffer
447 * @param[in] size The new size of the buffer
448 * @post Sends a message to RenderManager to set the new data to the property buffer.
450 void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size);
453 * Adds a geometry to the RenderManager
454 * @param[in] geometry The geometry to add
455 * @post Sends a message to RenderManager to add the Geometry
456 * The geometry will be owned by RenderManager
458 void AddGeometry( Render::Geometry* geometry );
461 * Removes an existing Geometry from RenderManager
462 * @param[in] geometry The geometry to remove
463 * @post The geometry will be destroyed in the render thread
465 void RemoveGeometry( Render::Geometry* geometry );
468 * Sets the geometry type of an existing Geometry
469 * @param[in] geometry The geometry
470 * @param[in] geometryType The type of the geometry
472 void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
475 * Sets the index buffer to be used by a geometry
476 * @param[in] geometry The geometry
477 * @param[in] indices A vector containing the indices for the geometry
479 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
482 * Adds a vertex buffer to a geomtry
483 * @param[in] geometry The geometry
484 * @param[in] propertyBuffer The property buffer
486 void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
489 * Removes a vertex buffer from a geometry
490 * @param[in] geometry The geometry
491 * @param[in] propertyBuffer The property buffer
493 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
496 * Adds a texture to the render manager
497 * @param[in] texture The texture to add
498 * The texture will be owned by RenderManager
500 void AddTexture( Render::Texture* texture );
503 * Removes a texture from the render manager
504 * @param[in] texture The texture to remove
505 * @post The texture will be destroyed in the render thread
507 void RemoveTexture( Render::Texture* texture );
510 * Uploads data to a texture owned by the RenderManager
511 * @param[in] texture The texture
512 * @param[in] pixelData The pixel data object
513 * @param[in] params The parameters for the upload
515 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
518 * Generates mipmaps for a texture owned by the RenderManager
519 * @param[in] texture The texture
521 void GenerateMipmaps( Render::Texture* texture );
524 * Adds a framebuffer to the render manager
525 * @param[in] frameBuffer The framebuffer to add
526 * The framebuffer will be owned by RenderManager
528 void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
531 * Removes a FrameBuffer from the render manager
532 * @param[in] frameBuffer The FrameBuffer to remove
533 * @post The FrameBuffer will be destroyed in the render thread
535 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
538 * Attach a texture as color output to an existing FrameBuffer
539 * @param[in] frameBuffer The FrameBuffer
540 * @param[in] texture The texture that will be used as output when rendering
541 * @param[in] mipmapLevel The mipmap of the texture to be attached
542 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
544 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int face );
549 * Performs an Update traversal on the scene-graph.
550 * @param[in] elapsedSeconds The elapsed time that should be applied to animations.
551 * @param[in] lastVSyncTimeMilliseconds The last time, in milliseconds, that we had a VSync.
552 * @param[in] nextVSyncTimeMilliseconds The estimated time, in milliseconds, of the next VSync.
553 * @return True if further updates are required e.g. during animations.
555 unsigned int Update( float elapsedSeconds, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
558 * Set the background color i.e. the glClear color used at the beginning of each frame.
559 * @param[in] color The new background color.
561 void SetBackgroundColor(const Vector4& color);
564 * Set the default surface rect.
565 * @param[in] rect The rect value representing the surface.
567 void SetDefaultSurfaceRect( const Rect<int>& rect );
570 * @copydoc Dali::Stage::KeepRendering()
572 void KeepRendering( float durationSeconds );
575 * Sets the depths of all layers.
576 * @param layers The layers in depth order.
577 * @param[in] systemLevel True if using the system-level overlay.
579 void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
582 * Set the depth indices of all nodes (in LayerUI's)
583 * @param[in] nodeDepths A vector of nodes and associated depth indices
585 void SetDepthIndices( NodeDepths* nodeDepths );
590 UpdateManager(const UpdateManager&);
593 UpdateManager& operator=(const UpdateManager& rhs);
596 * Helper to check whether the update-thread should keep going.
597 * @param[in] elapsedSeconds The time in seconds since the previous update.
598 * @return True if the update-thread should keep going.
600 unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
603 * Helper to reset all Node properties
604 * @param[in] bufferIndex to use
606 void ResetProperties( BufferIndex bufferIndex );
609 * Perform gesture updates.
610 * @param[in] bufferIndex to use
611 * @param[in] lastVSyncTime The last VSync time in milliseconds.
612 * @param[in] nextVSyncTime The estimated time of the next VSync in milliseconds.
613 * @return true, if any properties were updated.
615 bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
618 * Perform animation updates
619 * @param[in] bufferIndex to use
620 * @param[in] elapsedSeconds time since last frame
622 void Animate( BufferIndex bufferIndex, float elapsedSeconds );
625 * Applies constraints to CustomObjects
626 * @param[in] bufferIndex to use
628 void ConstrainCustomObjects( BufferIndex bufferIndex );
631 * Applies constraints to RenderTasks
632 * @param[in] bufferIndex to use
634 void ConstrainRenderTasks( BufferIndex bufferIndex );
637 * Applies constraints to Shaders
638 * @param[in] bufferIndex to use
640 void ConstrainShaders( BufferIndex bufferIndex );
643 * Perform property notification updates
644 * @param[in] bufferIndex to use
646 void ProcessPropertyNotifications( BufferIndex bufferIndex );
649 * Pass shader binaries queued here on to event thread.
651 void ForwardCompiledShadersToEventThread();
654 * Update node shaders, opacity, geometry etc.
655 * @param[in] bufferIndex to use
657 void UpdateNodes( BufferIndex bufferIndex );
661 * @param[in] bufferIndex to use
663 void UpdateRenderers( BufferIndex bufferIndex );
667 // needs to be direct member so that getter for event buffer can be inlined
668 SceneGraphBuffers mSceneGraphBuffers;
675 // Messages for UpdateManager
677 inline void InstallRootMessage( UpdateManager& manager, Layer& root, bool systemLevel )
679 // Message has ownership of Layer while in transit from event -> update
680 typedef MessageValue2< UpdateManager, OwnerPointer<Layer>, bool > LocalType;
682 // Reserve some memory inside the message queue
683 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
685 // Construct message in the message queue memory; note that delete should not be called on the return value
686 new (slot) LocalType( &manager, &UpdateManager::InstallRoot, &root, systemLevel );
689 inline void AddNodeMessage( UpdateManager& manager, Node& node )
691 // Message has ownership of Node while in transit from event -> update
692 typedef MessageValue1< UpdateManager, OwnerPointer<Node> > LocalType;
694 // Reserve some memory inside the message queue
695 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
697 // Construct message in the message queue memory; note that delete should not be called on the return value
698 new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
701 inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
703 // Update thread can edit the object
704 Node& parent = const_cast< Node& >( constParent );
705 Node& child = const_cast< Node& >( constChild );
707 typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
709 // Reserve some memory inside the message queue
710 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
712 // Construct message in the message queue memory; note that delete should not be called on the return value
713 new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
716 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
718 // Scene graph thread can modify this object.
719 Node& node = const_cast< Node& >( constNode );
721 typedef MessageValue1< UpdateManager, Node* > LocalType;
723 // Reserve some memory inside the message queue
724 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
726 // Construct message in the message queue memory; note that delete should not be called on the return value
727 new (slot) LocalType( &manager, &UpdateManager::DisconnectNode, &node );
730 inline void DestroyNodeMessage( UpdateManager& manager, const Node& constNode )
732 // Scene graph thread can destroy this object.
733 Node& node = const_cast< Node& >( constNode );
735 typedef MessageValue1< UpdateManager, Node* > LocalType;
737 // Reserve some memory inside the message queue
738 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
740 // Construct message in the message queue memory; note that delete should not be called on the return value
741 new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
744 inline void AddCameraMessage( UpdateManager& manager, const Camera* constCamera )
746 // Message has ownership of Camera while in transit from event -> update
747 typedef MessageValue1< UpdateManager, OwnerPointer< Camera > > LocalType;
749 Camera* camera = const_cast<Camera*>( constCamera );
750 // Reserve some memory inside the message queue
751 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
753 // Construct message in the message queue memory; note that delete should not be called on the return value
754 new (slot) LocalType( &manager, &UpdateManager::AddCamera, camera );
757 inline void RemoveCameraMessage( UpdateManager& manager, const Camera* camera )
759 typedef MessageValue1< UpdateManager, const Camera* > LocalType;
761 // Reserve some memory inside the message queue
762 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
764 // Construct message in the message queue memory; note that delete should not be called on the return value
765 new (slot) LocalType( &manager, &UpdateManager::RemoveCamera, camera );
768 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
770 // Message has ownership of object while in transit from event -> update
771 typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
773 // Reserve some memory inside the message queue
774 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
776 // Construct message in the message queue memory; note that delete should not be called on the return value
777 new (slot) LocalType( &manager, &UpdateManager::AddObject, object );
780 inline void RemoveObjectMessage( UpdateManager& manager, PropertyOwner* object )
782 typedef MessageValue1< UpdateManager, PropertyOwner* > LocalType;
784 // Reserve some memory inside the message queue
785 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
787 // Construct message in the message queue memory; note that delete should not be called on the return value
788 new (slot) LocalType( &manager, &UpdateManager::RemoveObject, object );
791 inline void AddAnimationMessage( UpdateManager& manager, Animation* animation )
793 typedef MessageValue1< UpdateManager, Animation* > LocalType;
795 // Reserve some memory inside the message queue
796 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
798 // Construct message in the message queue memory; note that delete should not be called on the return value
799 new (slot) LocalType( &manager, &UpdateManager::AddAnimation, animation );
802 inline void StopAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
804 // The scene-graph thread owns this object so it can safely edit it.
805 Animation& animation = const_cast< Animation& >( constAnimation );
807 typedef MessageValue1< UpdateManager, Animation* > LocalType;
809 // Reserve some memory inside the message queue
810 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
812 // Construct message in the message queue memory; note that delete should not be called on the return value
813 new (slot) LocalType( &manager, &UpdateManager::StopAnimation, &animation );
816 inline void RemoveAnimationMessage( UpdateManager& manager, const Animation& constAnimation )
818 // The scene-graph thread owns this object so it can safely edit it.
819 Animation& animation = const_cast< Animation& >( constAnimation );
821 typedef MessageValue1< UpdateManager, Animation* > LocalType;
823 // Reserve some memory inside the message queue
824 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
826 // Construct message in the message queue memory; note that delete should not be called on the return value
827 new (slot) LocalType( &manager, &UpdateManager::RemoveAnimation, &animation );
830 inline void AddPropertyNotificationMessage( UpdateManager& manager, PropertyNotification* propertyNotification )
832 // Message has ownership of PropertyNotification while in transit from event -> update
833 typedef MessageValue1< UpdateManager, OwnerPointer< PropertyNotification > > LocalType;
835 // Reserve some memory inside the message queue
836 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
838 // Construct message in the message queue memory; note that delete should not be called on the return value
839 new (slot) LocalType( &manager, &UpdateManager::AddPropertyNotification, propertyNotification );
842 inline void RemovePropertyNotificationMessage( UpdateManager& manager, const PropertyNotification& constPropertyNotification )
844 // The scene-graph thread owns this object so it can safely edit it.
845 PropertyNotification& propertyNotification = const_cast< PropertyNotification& >( constPropertyNotification );
847 typedef MessageValue1< UpdateManager, PropertyNotification* > 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::RemovePropertyNotification, &propertyNotification );
856 inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
857 const PropertyNotification* constPropertyNotification,
858 PropertyNotification::NotifyMode notifyMode )
860 // The scene-graph thread owns this object so it can safely edit it.
861 PropertyNotification* propertyNotification = const_cast< PropertyNotification* >( constPropertyNotification );
863 typedef MessageValue2< UpdateManager, PropertyNotification*, PropertyNotification::NotifyMode > LocalType;
865 // Reserve some memory inside the message queue
866 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
868 // Construct message in the message queue memory; note that delete should not be called on the return value
869 new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
872 // The render thread can safely change the Shader
873 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
875 typedef MessageValue1< UpdateManager, OwnerPointer< Shader > > LocalType;
877 // Reserve some memory inside the message queue
878 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
880 // Construct message in the message queue memory; note that delete should not be called on the return value
881 new (slot) LocalType( &manager, &UpdateManager::AddShader, &shader );
884 // The render thread can safely change the Shader
885 inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
887 typedef MessageValue1< UpdateManager, Shader* > LocalType;
889 // Reserve some memory inside the message queue
890 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
892 // Construct message in the message queue memory; note that delete should not be called on the return value
893 new (slot) LocalType( &manager, &UpdateManager::RemoveShader, &shader );
896 inline void SetShaderProgramMessage( UpdateManager& manager,
898 Internal::ShaderDataPtr shaderData,
899 bool modifiesGeometry )
901 typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
903 // Reserve some memory inside the message queue
904 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
906 // Construct message in the message queue memory; note that delete should not be called on the return value
907 new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
910 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
912 typedef MessageValue1< UpdateManager, Vector4 > LocalType;
914 // Reserve some memory inside the message queue
915 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
917 // Construct message in the message queue memory; note that delete should not be called on the return value
918 new (slot) LocalType( &manager, &UpdateManager::SetBackgroundColor, color );
921 inline void SetDefaultSurfaceRectMessage( UpdateManager& manager, const Rect<int>& rect )
923 typedef MessageValue1< UpdateManager, Rect<int> > LocalType;
925 // Reserve some memory inside the message queue
926 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
928 // Construct message in the message queue memory; note that delete should not be called on the return value
929 new (slot) LocalType( &manager, &UpdateManager::SetDefaultSurfaceRect, rect );
932 inline void KeepRenderingMessage( UpdateManager& manager, float durationSeconds )
934 typedef MessageValue1< UpdateManager, float > LocalType;
936 // Reserve some memory inside the message queue
937 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
939 // Construct message in the message queue memory; note that delete should not be called on the return value
940 new (slot) LocalType( &manager, &UpdateManager::KeepRendering, durationSeconds );
944 * Create a message for setting the depth of a layer
945 * @param[in] manager The update manager
946 * @param[in] layers list of layers
947 * @param[in] systemLevel True if the layers are added via the SystemOverlay API
949 inline void SetLayerDepthsMessage( UpdateManager& manager, const std::vector< Layer* >& layers, bool systemLevel )
951 typedef MessageValue2< UpdateManager, std::vector< Layer* >, bool > LocalType;
953 // Reserve some memory inside the message queue
954 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
956 // Construct message in the message queue memory; note that delete should not be called on the return value
957 new (slot) LocalType( &manager, &UpdateManager::SetLayerDepths, layers, systemLevel );
960 inline void AddRendererMessage( UpdateManager& manager, Renderer& object )
962 typedef MessageValue1< UpdateManager, OwnerPointer< Renderer > > LocalType;
964 // Reserve some memory inside the message queue
965 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
966 // Construct message in the message queue memory; note that delete should not be called on the return value
967 new (slot) LocalType( &manager, &UpdateManager::AddRenderer, &object );
970 inline void RemoveRendererMessage( UpdateManager& manager, Renderer& object )
972 typedef MessageValue1< UpdateManager, Renderer* > LocalType;
974 // Reserve some memory inside the message queue
975 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
976 // Construct message in the message queue memory; note that delete should not be called on the return value
977 new (slot) LocalType( &manager, &UpdateManager::RemoveRenderer, &object );
980 // The render thread can safely change the Shader
981 inline void AddTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
983 typedef MessageValue1< UpdateManager, OwnerPointer< TextureSet > > LocalType;
985 // Reserve some memory inside the message queue
986 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
988 // Construct message in the message queue memory; note that delete should not be called on the return value
989 new (slot) LocalType( &manager, &UpdateManager::AddTextureSet, &textureSet );
992 // The render thread can safely change the Shader
993 inline void RemoveTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
995 typedef MessageValue1< UpdateManager, TextureSet* > LocalType;
997 // Reserve some memory inside the message queue
998 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1000 // Construct message in the message queue memory; note that delete should not be called on the return value
1001 new (slot) LocalType( &manager, &UpdateManager::RemoveTextureSet, &textureSet );
1004 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1006 // Message has ownership of Sampler while in transit from event -> update
1007 typedef MessageValue1< UpdateManager, OwnerPointer< Render::Sampler > > LocalType;
1009 // Reserve some memory inside the message queue
1010 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1012 // Construct message in the message queue memory; note that delete should not be called on the return value
1013 new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
1016 inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
1018 typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
1020 // Reserve some memory inside the message queue
1021 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1023 // Construct message in the message queue memory; note that delete should not be called on the return value
1024 new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
1027 inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
1029 typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
1031 // Reserve some memory inside the message queue
1032 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1034 // Construct message in the message queue memory; note that delete should not be called on the return value
1035 new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
1038 inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
1040 typedef MessageValue4< UpdateManager, Render::Sampler*, unsigned int, unsigned int, unsigned int > LocalType;
1042 // Reserve some memory inside the message queue
1043 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1045 // Construct message in the message queue memory; note that delete should not be called on the return value
1046 new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, rWrapMode, sWrapMode, tWrapMode );
1049 inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1051 // Message has ownership of propertyBuffer while in transit from event -> update
1052 typedef MessageValue1< UpdateManager, OwnerPointer< Render::PropertyBuffer > > LocalType;
1054 // Reserve some memory inside the message queue
1055 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1057 // Construct message in the message queue memory; note that delete should not be called on the return value
1058 new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
1061 inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
1063 typedef MessageValue1< UpdateManager, Render::PropertyBuffer* > LocalType;
1065 // Reserve some memory inside the message queue
1066 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1068 // Construct message in the message queue memory; note that delete should not be called on the return value
1069 new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
1072 inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
1074 // Message has ownership of PropertyBuffer::Format while in transit from event -> update
1075 typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, OwnerPointer< Render::PropertyBuffer::Format> > LocalType;
1077 // Reserve some memory inside the message queue
1078 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1080 // Construct message in the message queue memory; note that delete should not be called on the return value
1081 new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
1084 inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data, size_t size )
1086 // Message has ownership of PropertyBuffer data while in transit from event -> update
1087 typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, OwnerPointer< Vector<char> >, size_t > LocalType;
1089 // Reserve some memory inside the message queue
1090 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1092 // Construct message in the message queue memory; note that delete should not be called on the return value
1093 new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
1096 inline void AddGeometry( UpdateManager& manager, Render::Geometry& geometry )
1098 // Message has ownership of Geometry while in transit from event -> update
1099 typedef MessageValue1< UpdateManager, OwnerPointer< Render::Geometry > > LocalType;
1101 // Reserve some memory inside the message queue
1102 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1104 // Construct message in the message queue memory; note that delete should not be called on the return value
1105 new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
1108 inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
1110 typedef MessageValue1< UpdateManager, Render::Geometry* > LocalType;
1112 // Reserve some memory inside the message queue
1113 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1115 // Construct message in the message queue memory; note that delete should not be called on the return value
1116 new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
1119 inline void AddVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1121 typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1123 // Reserve some memory inside the message queue
1124 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1126 // Construct message in the message queue memory; note that delete should not be called on the return value
1127 new (slot) LocalType( &manager, &UpdateManager::AddVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1130 inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
1132 typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
1134 // Reserve some memory inside the message queue
1135 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1137 // Construct message in the message queue memory; note that delete should not be called on the return value
1138 new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
1141 // Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
1142 template< typename T >
1143 class IndexBufferMessage : public MessageBase
1148 * Constructor which does a Vector::Swap()
1150 IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
1152 mManager( manager ),
1153 mRenderGeometry( geometry )
1155 mIndices.Swap( indices );
1159 * Virtual destructor
1161 virtual ~IndexBufferMessage()
1166 * @copydoc MessageBase::Process
1168 virtual void Process( BufferIndex /*bufferIndex*/ )
1170 DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
1171 mManager->SetIndexBuffer( mRenderGeometry, mIndices );
1177 Render::Geometry* mRenderGeometry;
1178 Dali::Vector<unsigned short> mIndices;
1181 inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
1183 typedef IndexBufferMessage< UpdateManager > LocalType;
1185 // Reserve some memory inside the message queue
1186 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1188 // Construct message in the message queue memory; note that delete should not be called on the return value
1189 new (slot) LocalType( &manager, &geometry, indices );
1192 inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
1194 typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
1196 // Reserve some memory inside the message queue
1197 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1199 // Construct message in the message queue memory; note that delete should not be called on the return value
1200 new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
1203 inline void AddTexture( UpdateManager& manager, Render::Texture& texture )
1205 // Message has ownership of Texture while in transit from event -> update
1206 typedef MessageValue1< UpdateManager, OwnerPointer< Render::Texture > > LocalType;
1208 // Reserve some memory inside the message queue
1209 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1211 // Construct message in the message queue memory; note that delete should not be called on the return value
1212 new (slot) LocalType( &manager, &UpdateManager::AddTexture, &texture );
1215 inline void RemoveTexture( UpdateManager& manager, Render::Texture& texture )
1217 typedef MessageValue1< UpdateManager, Render::Texture* > LocalType;
1219 // Reserve some memory inside the message queue
1220 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1222 // Construct message in the message queue memory; note that delete should not be called on the return value
1223 new (slot) LocalType( &manager, &UpdateManager::RemoveTexture, &texture );
1226 inline void UploadTextureMessage( UpdateManager& manager, Render::Texture& texture, PixelDataPtr pixelData, const Texture::UploadParams& params )
1228 typedef MessageValue3< UpdateManager, Render::Texture*, PixelDataPtr, Texture::UploadParams > LocalType;
1230 // Reserve some memory inside the message queue
1231 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1233 // Construct message in the message queue memory; note that delete should not be called on the return value
1234 new (slot) LocalType( &manager, &UpdateManager::UploadTexture, &texture, pixelData, params );
1237 inline void GenerateMipmapsMessage( UpdateManager& manager, Render::Texture& texture )
1239 typedef MessageValue1< UpdateManager, Render::Texture* > LocalType;
1241 // Reserve some memory inside the message queue
1242 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1244 // Construct message in the message queue memory; note that delete should not be called on the return value
1245 new (slot) LocalType( &manager, &UpdateManager::GenerateMipmaps, &texture );
1249 inline void AddFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1251 typedef MessageValue1< UpdateManager, Render::FrameBuffer* > LocalType;
1253 // Reserve some memory inside the message queue
1254 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1256 // Construct message in the message queue memory; note that delete should not be called on the return value
1257 new (slot) LocalType( &manager, &UpdateManager::AddFrameBuffer, &frameBuffer );
1260 inline void RemoveFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer )
1262 typedef MessageValue1< UpdateManager, Render::FrameBuffer* > LocalType;
1264 // Reserve some memory inside the message queue
1265 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1267 // Construct message in the message queue memory; note that delete should not be called on the return value
1268 new (slot) LocalType( &manager, &UpdateManager::RemoveFrameBuffer, &frameBuffer );
1271 inline void AttachColorTextureToFrameBuffer( UpdateManager& manager, Render::FrameBuffer& frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int layer )
1273 typedef MessageValue4< UpdateManager, Render::FrameBuffer*, Render::Texture*, unsigned int, unsigned int > LocalType;
1275 // Reserve some memory inside the message queue
1276 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1278 // Construct message in the message queue memory; note that delete should not be called on the return value
1279 new (slot) LocalType( &manager, &UpdateManager::AttachColorTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel, layer );
1282 inline void SetDepthIndicesMessage( UpdateManager& manager, NodeDepths* nodeDepths )
1284 typedef MessageValue1< UpdateManager, OwnerPointer< NodeDepths > > LocalType;
1286 // Reserve some memory inside the message queue
1287 unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
1289 // Construct message in the message queue memory; note that delete should not be called on the return value
1290 new (slot) LocalType( &manager, &UpdateManager::SetDepthIndices, nodeDepths );
1294 } // namespace SceneGraph
1296 } // namespace Internal
1300 #endif // DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H