Removal of renderable attachment
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager.h
index 1f181a1..a2bed89 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <dali/internal/common/message.h>
 #include <dali/internal/common/type-abstraction-enums.h>
+#include <dali/internal/common/shader-saver.h>
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/update/animation/scene-graph-animation.h>
 #include <dali/internal/update/common/scene-graph-buffers.h>
@@ -34,8 +35,9 @@
 #include <dali/internal/update/node-attachments/node-attachment.h>
 #include <dali/internal/update/nodes/node.h>
 #include <dali/internal/update/nodes/scene-graph-layer.h>
-
+#include <dali/internal/update/rendering/scene-graph-renderer.h>
 #include <dali/internal/render/shaders/scene-graph-shader.h>
+#include <dali/internal/render/renderers/render-property-buffer.h>
 
 namespace Dali
 {
@@ -44,7 +46,6 @@ namespace Integration
 {
 class GlSyncAbstraction;
 class RenderController;
-struct DynamicsWorldSettings;
 
 } // namespace Integration
 
@@ -52,12 +53,15 @@ namespace Internal
 {
 
 class PropertyNotifier;
-struct DynamicsWorldSettings;
 class NotificationManager;
 class CompleteNotificationInterface;
 class ResourceManager;
 class TouchResampler;
 
+namespace Render
+{
+class Sampler;
+}
 // value types used by messages
 template <> struct ParameterType< PropertyNotification::NotifyMode >
 : public BasicType< PropertyNotification::NotifyMode > {};
@@ -71,13 +75,10 @@ class PanGesture;
 class RenderManager;
 class RenderTaskList;
 class RenderQueue;
-class DynamicsWorld;
 class TextureCache;
 class Geometry;
 class PropertyBuffer;
 class Material;
-class Sampler;
-class RendererAttachment;
 
 /**
  * UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
@@ -87,7 +88,7 @@ class RendererAttachment;
  * It also maintains the lifecycle of nodes and other property owners that are
  * disconnected from the scene graph.
  */
-class UpdateManager
+class UpdateManager : public ShaderSaver
 {
 public:
 
@@ -118,9 +119,9 @@ public:
                  TouchResampler& touchResampler );
 
   /**
-   * Destructor. Not virtual as this is not a base class
+   * Destructor.
    */
-  ~UpdateManager();
+  virtual ~UpdateManager();
 
   // Node connection methods
 
@@ -153,10 +154,9 @@ public:
    * Connect a Node to the scene-graph.
    * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
    * @pre The node does not already have a parent.
-   * @param[in] node The new parent node.
-   * @param[in] node The node to connect.
+   * @param[in] parent The new parent node.
    */
-  void ConnectNode( Node* parent, Node* node, int index );
+  void ConnectNode( Node* parent, Node* node );
 
   /**
    * Disconnect a Node from the scene-graph.
@@ -192,12 +192,6 @@ public:
   void AttachToNode( Node* node, NodeAttachment* attachment );
 
   /**
-   * Attach a renderer to the scene graph
-   */
-  void AttachToSceneGraph( RendererAttachment* renderer );
-
-
-  /**
    * Add a newly created object.
    * @param[in] object The object to add.
    * @post The object is owned by UpdateManager.
@@ -266,6 +260,7 @@ public:
    */
   ObjectOwnerContainer< Geometry >& GetGeometryOwner();
 
+  ObjectOwnerContainer< Renderer >& GetRendererOwner();
   /**
    * @brief Get the material owner
    *
@@ -274,13 +269,6 @@ public:
   ObjectOwnerContainer< Material >& GetMaterialOwner();
 
   /**
-   * @brief Get the sampler owner
-   *
-   * @return The sampler owner
-   */
-  ObjectOwnerContainer< Sampler >& GetSamplerOwner();
-
-  /**
    * @brief Get the property buffer owner
    *
    * @return The property buffer owner
@@ -308,11 +296,25 @@ public:
   /**
    * Set the shader program for a Shader object
    * @param[in] shader        The shader to modify
-   * @param[in] resourceId    A ResourceManager ticket ID for the program data (source and compiled binary)
-   * @param[in] shaderHash    hash key created with vertex and fragment shader code
+   * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
    * @param[in] modifiesGeometry True if the vertex shader modifies geometry
    */
-  void SetShaderProgram( Shader* shader, Integration::ResourceId resourceId, size_t shaderHash, bool modifiesGeometry );
+  void SetShaderProgram( Shader* shader, Internal::ShaderDataPtr shaderData, bool modifiesGeometry );
+
+  /**
+   * @brief Accept compiled shaders passed back on render thread for saving.
+   * @param[in] shaderData Source code, hash over source, and corresponding compiled binary to be saved.
+   */
+  virtual void SaveBinary( Internal::ShaderDataPtr shaderData );
+
+  /**
+   * @brief Set the destination for compiled shader binaries to be passed on to.
+   * The dispatcher passed in will be called from the update thread.
+   * @param[in] upstream A sink for ShaderDatas to be passed into.
+   */
+  void SetShaderSaver( ShaderSaver& upstream );
+
+  // Gestures
 
   /**
    * Add a newly created gesture.
@@ -365,6 +367,76 @@ public:
    */
   bool FlushQueue();
 
+  /**
+   * Add a new sampler to RenderManager
+   * @param[in] sampler The sampler to add
+   * @post Sends a message to RenderManager to add the sampler.
+   * The sampler will be owned by RenderManager
+   */
+  void AddSampler( Render::Sampler* sampler );
+
+  /**
+   * Removes an existing sampler from RenderManager
+   * @param[in] sampler The sampler to remove
+   * @post The sampler will be destroyed in the render thread
+   */
+  void RemoveSampler( Render::Sampler* sampler );
+
+  /**
+   * Sets the filter modes for an existing sampler
+   * @param[in] sampler The sampler
+   * @param[in] minFilterMode The filter to use under minification
+   * @param[in] magFilterMode The filter to use under magnification
+   */
+  void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
+
+  /**
+   * Sets the wrap mode for an existing sampler
+   * @param[in] sampler The sampler
+   * @param[in] uWrapMode Wrapping mode in x direction
+   * @param[in] vWrapMode Wrapping mode in y direction
+   */
+  void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
+
+  /**
+   * Add a new sampler to RenderManager
+   * @param[in] propertryBuffer The property buffer to add
+   * @post Sends a message to RenderManager to add the property buffer.
+   * The property buffer will be owned by RenderManager
+   */
+  void AddPropertyBuffer( Render::PropertyBuffer* propertryBuffer );
+
+  /**
+   * Removes an existing PropertyBuffer from RenderManager
+   * @param[in] propertryBuffer The property buffer to remove
+   * @post The property buffer will be destroyed in the render thread
+   */
+  void RemovePropertyBuffer( Render::PropertyBuffer* propertryBuffer );
+
+  /**
+   * Sets the format of an existing property buffer
+   * @param[in] propertyBuffer The property buffer.
+   * @param[in] format The new format of the buffer
+   * @post Sends a message to RenderManager to set the new format to the property buffer.
+   */
+  void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
+
+  /**
+   * Sets the data of an existing property buffer
+   * @param[in] propertyBuffer The property buffer.
+   * @param[in] data The new data of the buffer
+   * @post Sends a message to RenderManager to set the new data to the property buffer.
+   */
+  void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
+
+  /**
+   * Sets the size of an existing property buffer
+   * @param[in] propertyBuffer The property buffer.
+   * @param[in] size The new size of the buffer
+   * @post Sends a message to RenderManager to set the new size to the property buffer.
+   */
+  void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
+
 public:
 
   /**
@@ -400,23 +472,6 @@ public:
    */
   void SetLayerDepths( const std::vector< Layer* >& layers, bool systemLevel );
 
-#ifdef DALI_DYNAMICS_SUPPORT
-
-  /**
-   * Initialize the dynamics world
-   * @param[in] world The dynamics world
-   * @param[in] worldSettings The dynamics world settings
-   * @param[in] debugShader The shader used for rendering dynamics debug information
-   */
-  void InitializeDynamicsWorld( DynamicsWorld* world, Integration::DynamicsWorldSettings* worldSettings );
-
-  /**
-   * Terminate the dynamics world
-   */
-  void TerminateDynamicsWorld();
-
-#endif // DALI_DYNAMICS_SUPPORT
-
 private:
 
   // Undefined
@@ -444,41 +499,45 @@ private:
   void PostProcessResources();
 
   /**
-   * Helper to reset a Node properties.
-   * @param[in] node The node.
-   */
-  void ResetNodeProperty( Node& node );
-
-  /**
    * Helper to reset all Node properties
+   * @param[in] bufferIndex to use
    */
-  void ResetProperties();
+  void ResetProperties( BufferIndex bufferIndex );
 
   /**
    * Perform gesture updates.
-   * @param[in]  lastVSyncTime  The last VSync time in milliseconds.
-   * @param[in]  nextVSyncTime  The estimated time of the next VSync in milliseconds.
+   * @param[in] bufferIndex to use
+   * @param[in] lastVSyncTime  The last VSync time in milliseconds.
+   * @param[in] nextVSyncTime  The estimated time of the next VSync in milliseconds.
    * @return true, if any properties were updated.
    */
-  bool ProcessGestures( unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
+  bool ProcessGestures( BufferIndex bufferIndex, unsigned int lastVSyncTimeMilliseconds, unsigned int nextVSyncTimeMilliseconds );
 
   /**
    * Perform animation updates
+   * @param[in] bufferIndex to use
    * @param[in] elapsedSeconds time since last frame
    */
-  void Animate( float elapsedSeconds );
+  void Animate( BufferIndex bufferIndex, float elapsedSeconds );
 
   /**
    * Perform constraint updates.
    * @note Applies constraints to nodes first (depth first search order).
    * Then shader constraints second (construction order)
+   * @param[in] bufferIndex to use
    */
-  void ApplyConstraints();
+  void ApplyConstraints( BufferIndex bufferIndex );
 
   /**
    * Perform property notification updates
+   * @param[in] bufferIndex to use
    */
-  void ProcessPropertyNotifications();
+  void ProcessPropertyNotifications( BufferIndex bufferIndex );
+
+  /**
+   * Pass shader binaries queued here on to event thread.
+   */
+  void ForwardCompiledShadersToEventThread();
 
   /**
    * Update the default camera.
@@ -489,8 +548,15 @@ private:
 
   /**
    * Update node shaders, opacity, geometry etc.
+   * @param[in] bufferIndex to use
+   */
+  void UpdateNodes( BufferIndex bufferIndex );
+
+  /**
+   * Update Renderers
+   * @param[in] bufferIndex to use
    */
-  void UpdateNodes();
+  void UpdateRenderers( BufferIndex bufferIndex );
 
 private:
 
@@ -526,19 +592,19 @@ inline void AddNodeMessage( UpdateManager& manager, Node& node )
   new (slot) LocalType( &manager, &UpdateManager::AddNode, &node );
 }
 
-inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild, int index )
+inline void ConnectNodeMessage( UpdateManager& manager, const Node& constParent, const Node& constChild )
 {
   // Update thread can edit the object
   Node& parent = const_cast< Node& >( constParent );
   Node& child = const_cast< Node& >( constChild );
 
-  typedef MessageValue3< UpdateManager, Node*, Node*, int > LocalType;
+  typedef MessageValue2< UpdateManager, Node*, Node* > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child, index );
+  new (slot) LocalType( &manager, &UpdateManager::ConnectNode, &parent, &child );
 }
 
 inline void DisconnectNodeMessage( UpdateManager& manager, const Node& constNode )
@@ -574,7 +640,6 @@ inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent
   // Scene graph thread can modify this object.
   Node& parent = const_cast< Node& >( constParent );
 
-  // @todo MESH_REWORK Don't pass by owner pointer after merge with SceneGraph::RenderableAttachment ? (not needed if we split RendererAttachment to 2 objects)
   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
 
   // Reserve some memory inside the message queue
@@ -584,18 +649,6 @@ inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent
   new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
 }
 
-inline void AttachToSceneGraphMessage( UpdateManager& manager, RendererAttachment* renderer )
-{
-  // @todo MESH_REWORK Pass by owner pointer after merge with SceneGraph::RenderableAttachment
-  typedef MessageValue1< UpdateManager, RendererAttachment* > LocalType;
-
-  // Reserve some memory inside the message queue
-  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
-
-  // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::AttachToSceneGraph, renderer );
-}
-
 inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
 {
   typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
@@ -698,8 +751,6 @@ inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
 }
 
-
-
 // The render thread can safely change the Shader
 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
 {
@@ -726,17 +777,16 @@ inline void RemoveShaderMessage( UpdateManager& manager, Shader& shader )
 
 inline void SetShaderProgramMessage( UpdateManager& manager,
                                      Shader& shader,
-                                     Integration::ResourceId resourceId,
-                                     size_t shaderHash,
+                                     Internal::ShaderDataPtr shaderData,
                                      bool modifiesGeometry )
 {
-  typedef MessageValue4< UpdateManager, Shader*, Integration::ResourceId, size_t, bool > LocalType;
+  typedef MessageValue3< UpdateManager, Shader*, Internal::ShaderDataPtr, bool > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, resourceId, shaderHash, modifiesGeometry );
+  new (slot) LocalType( &manager, &UpdateManager::SetShaderProgram, &shader, shaderData, modifiesGeometry );
 }
 
 inline void SetBackgroundColorMessage( UpdateManager& manager, const Vector4& color )
@@ -811,56 +861,128 @@ inline void RemoveGestureMessage( UpdateManager& manager, PanGesture* gesture )
   new (slot) LocalType( &manager, &UpdateManager::RemoveGesture, gesture );
 }
 
-#ifdef DALI_DYNAMICS_SUPPORT
+template< typename T >
+inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
+{
+  typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
+}
+
+template< typename T >
+inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
+{
+  typedef MessageValue1< ObjectOwnerContainer<T>, T* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
+}
 
-// Dynamics messages
-inline void InitializeDynamicsWorldMessage( UpdateManager& manager, DynamicsWorld* dynamicsworld, Integration::DynamicsWorldSettings* worldSettings )
+inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
 {
-  typedef MessageValue2< UpdateManager, DynamicsWorld*, Integration::DynamicsWorldSettings* > LocalType;
+  typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::InitializeDynamicsWorld, dynamicsworld, worldSettings );
+  new (slot) LocalType( &manager, &UpdateManager::AddSampler, &sampler );
 }
 
-inline void TerminateDynamicsWorldMessage(UpdateManager& manager)
+inline void RemoveSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
 {
-  typedef Message< UpdateManager > LocalType;
+  typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::TerminateDynamicsWorld );
+  new (slot) LocalType( &manager, &UpdateManager::RemoveSampler, &sampler );
 }
 
-#endif // DALI_DYNAMICS_SUPPORT
+inline void SetFilterModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
+{
+  typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int > LocalType;
 
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
-template< typename T >
-inline void AddMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::SetFilterMode, &sampler, minFilterMode, magFilterMode );
+}
+
+inline void SetWrapModeMessage( UpdateManager& manager, Render::Sampler& sampler, unsigned int uWrapMode, unsigned int vWrapMode )
 {
-  typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
+  typedef MessageValue3< UpdateManager, Render::Sampler*, unsigned int, unsigned int  > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Add, &object );
+  new (slot) LocalType( &manager, &UpdateManager::SetWrapMode, &sampler, uWrapMode, vWrapMode );
 }
 
-template< typename T >
-inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owner, T& object )
+inline void AddPropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
 {
-  typedef MessageValue1< ObjectOwnerContainer<T>, OwnerPointer< T > > LocalType;
+  typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
+  new (slot) LocalType( &manager, &UpdateManager::AddPropertyBuffer, &propertyBuffer );
+}
+
+inline void RemovePropertyBuffer( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer )
+{
+  typedef MessageValue1< UpdateManager, Render::PropertyBuffer*  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::RemovePropertyBuffer, &propertyBuffer );
+}
+
+inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Render::PropertyBuffer::Format* format )
+{
+  typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Render::PropertyBuffer::Format*  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
 }
 
+inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data )
+{
+  typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Vector<char>*  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data );
+}
+
+inline void SetPropertyBufferSize( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, size_t size )
+{
+  typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, size_t  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferSize, &propertyBuffer, size );
+}
+
+
 } // namespace SceneGraph
 
 } // namespace Internal