Messages and ownership of update objects 93/36393/4
authorDavid Steele <david.steele@partner.samsung.com>
Thu, 5 Mar 2015 19:05:22 +0000 (19:05 +0000)
committerDavid Steele <david.steele@partner.samsung.com>
Wed, 11 Mar 2015 19:48:27 +0000 (19:48 +0000)
Change-Id: Iaf66aedb9e6133cf9a0542165462e20ab444b494

16 files changed:
dali/internal/file.list
dali/internal/update/common/discard-queue.cpp
dali/internal/update/common/discard-queue.h
dali/internal/update/common/scene-graph-property-buffer.cpp [moved from dali/internal/update/common/property-buffer.cpp with 95% similarity]
dali/internal/update/common/scene-graph-property-buffer.h [moved from dali/internal/update/common/property-buffer.h with 82% similarity]
dali/internal/update/common/uniform-map.h
dali/internal/update/effects/scene-graph-material.cpp
dali/internal/update/effects/scene-graph-material.h
dali/internal/update/effects/scene-graph-sampler.cpp
dali/internal/update/effects/scene-graph-sampler.h
dali/internal/update/geometry/scene-graph-geometry.cpp
dali/internal/update/geometry/scene-graph-geometry.h
dali/internal/update/manager/update-manager.cpp
dali/internal/update/manager/update-manager.h
dali/internal/update/node-attachments/scene-graph-renderer-attachment.cpp
dali/internal/update/node-attachments/scene-graph-renderer-attachment.h

index 05283a1..6483c94 100644 (file)
@@ -147,7 +147,7 @@ internal_src_files = \
   $(internal_src_dir)/update/animation/scene-graph-constraint-base.cpp \
   $(internal_src_dir)/update/common/discard-queue.cpp \
   $(internal_src_dir)/update/common/property-base.cpp \
-  $(internal_src_dir)/update/common/property-buffer.cpp \
+  $(internal_src_dir)/update/common/scene-graph-property-buffer.cpp \
   $(internal_src_dir)/update/common/property-condition-functions.cpp \
   $(internal_src_dir)/update/common/property-condition-step-functions.cpp \
   $(internal_src_dir)/update/common/property-condition-variable-step-functions.cpp \
index 164035b..0e68aca 100644 (file)
@@ -79,6 +79,41 @@ void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachmen
   }
 }
 
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Geometry* geometry )
+{
+  DALI_ASSERT_DEBUG( NULL != geometry );
+
+  // The GL resources will now be freed in frame N
+  // The Update for frame N+1 may occur in parallel with the rendering of frame N
+  // Queue the node for destruction in frame N+2
+  if ( 0u == updateBufferIndex )
+  {
+    mGeometryQueue0.PushBack( geometry );
+  }
+  else
+  {
+    mGeometryQueue1.PushBack( geometry );
+  }
+}
+
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Material* material )
+{
+  DALI_ASSERT_DEBUG( NULL != material );
+
+  // The GL resources will now be freed in frame N
+  // The Update for frame N+1 may occur in parallel with the rendering of frame N
+  // Queue the node for destruction in frame N+2
+  if ( 0u == updateBufferIndex )
+  {
+    mMaterialQueue0.PushBack( material );
+  }
+  else
+  {
+    mMaterialQueue1.PushBack( material );
+  }
+}
+
+
 void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
 {
   DALI_ASSERT_DEBUG( NULL != shader );
@@ -107,12 +142,16 @@ void DiscardQueue::Clear( BufferIndex updateBufferIndex )
     mNodeQueue0.Clear();
     mAttachmentQueue0.Clear();
     mShaderQueue0.Clear();
+    mGeometryQueue0.Clear();
+    mMaterialQueue0.Clear();
   }
   else
   {
     mNodeQueue1.Clear();
     mAttachmentQueue1.Clear();
     mShaderQueue1.Clear();
+    mGeometryQueue1.Clear();
+    mMaterialQueue1.Clear();
   }
 }
 
index 879cc5b..56bd2db 100644 (file)
@@ -24,6 +24,8 @@
 #include <dali/internal/common/owner-container.h>
 #include <dali/internal/update/nodes/node-declarations.h>
 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
+#include <dali/internal/update/geometry/scene-graph-geometry.h>
+#include <dali/internal/update/effects/scene-graph-material.h>
 
 namespace Dali
 {
@@ -52,6 +54,8 @@ class DiscardQueue
 public:
 
   typedef OwnerContainer< Shader* > ShaderQueue;
+  typedef OwnerContainer< Geometry* > GeometryQueue;
+  typedef OwnerContainer< Material* > MaterialQueue;
 
   /**
    * Create a new DiscardQueue.
@@ -83,6 +87,18 @@ public:
   void Add( BufferIndex updateBufferIndex, NodeAttachment* attachment );
 
   /**
+   * Adds an unwanted geometry to the discard queue.
+   * A message will be sent to clean up GL resources in the next Render
+   */
+  void Add( BufferIndex updateBufferIndex, Geometry* geometry );
+
+  /**
+   * Adds an unwanted material to the discard queue.
+   * A message will be sent to clean up GL resources in the next Render.
+   */
+  void Add( BufferIndex updateBufferIndex, Material* material );
+
+  /**
    * Adds an unwanted shader to the discard queue.
    * A message will be sent to clean-up GL resources in the next Render.
    * @pre This method is not thread-safe, and should only be called from the update-thread.
@@ -114,11 +130,15 @@ private:
   NodeOwnerContainer           mNodeQueue0;
   NodeAttachmentOwnerContainer mAttachmentQueue0;
   ShaderQueue                  mShaderQueue0;
+  GeometryQueue                mGeometryQueue0;
+  MaterialQueue                mMaterialQueue0;
 
   // Messages are queued here when the update buffer index == 1
   NodeOwnerContainer           mNodeQueue1;
   NodeAttachmentOwnerContainer mAttachmentQueue1;
   ShaderQueue                  mShaderQueue1;
+  GeometryQueue                mGeometryQueue1;
+  MaterialQueue                mMaterialQueue1;
 };
 
 } // namespace SceneGraph
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "property-buffer.h"
+#include "scene-graph-property-buffer.h"
 
 namespace Dali
 {
@@ -27,6 +27,12 @@ namespace SceneGraph
 class PropertyBuffer
 {
 public:
+  //@todo MESH_REWORK Remove when we have working property buffers
+  static PropertyBuffer* NewQuadVertices();
+
+  //@todo MESH_REWORK Remove when we have working property buffers
+  static PropertyBuffer* NewQuadIndices();
+
   /**
    * Constructor
    */
index 16f54a9..1fb6e43 100644 (file)
@@ -38,7 +38,12 @@ public:
   /**
    * Constructor
    */
-  UniformMap;
+  UniformMap();
+
+  /**
+   * Destructor
+   */
+  ~UniformMap();
 
 private:
   // data
index 575c4cb..146e20e 100644 (file)
@@ -28,9 +28,7 @@ namespace SceneGraph
 {
 
 Material::Material()
-: mShader(NULL),
-  mCullFaceMode( CullNone ),
-  mBlendingOptions()
+: mShader(NULL)
 {
 }
 
@@ -47,12 +45,12 @@ Shader* Material::GetShader()
   return mShader;
 }
 
-void Material::AddSampler( Sampler* sampler )
+void Material::AddSampler( const Sampler* sampler )
 {
   // @todo MESH_REWORK
 }
 
-void Material::RemoveSampler( Sampler* sampler )
+void Material::RemoveSampler( const Sampler* sampler )
 {
   // @todo MESH_REWORK
 }
@@ -63,26 +61,6 @@ const Material::Samplers& Material::GetSamplers() const
   return mSamplers;
 }
 
-void Material::SetFaceCulling( BufferIndex updateBufferIndex, Dali::CullFaceMode mode )
-{
-  // @todo MESH_REWORK
-}
-
-CullFaceMode Material::GetFaceCulling() const
-{
-  // @todo MESH_REWORK
-  return mCullFaceMode;
-}
-
-void Material::SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options )
-{
-  // @todo MESH_REWORK
-}
-
-void Material::SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color )
-{
-  // @todo MESH_REWORK
-}
 
 
 } // namespace SceneGraph
index c1675c1..fa5cce7 100644 (file)
@@ -20,6 +20,7 @@
 #include <dali/public-api/actors/renderable-actor.h> // For CullFaceMode
 #include <dali/internal/common/buffer-index.h>
 #include <dali/internal/common/blending-options.h>
+#include <dali/internal/common/event-to-update.h>
 #include <dali/internal/update/common/double-buffered.h>
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/render/renderers/material-data-provider.h>
@@ -64,13 +65,13 @@ public:
    * Add a sampler (image + sampler modes) to the material
    * @param[in] sampler A sampler to add
    */
-  void AddSampler( Sampler* sampler );
+  void AddSampler( const Sampler* sampler );
 
   /**
    * Remove a sampler (image + sampler modes) from the material
    * @param[in] sampler A sampler to remove
    */
-  void RemoveSampler( Sampler* sampler );
+  void RemoveSampler( const Sampler* sampler );
 
   /**
    * Get the samplers this material uses.
@@ -78,40 +79,46 @@ public:
    */
   const Samplers& GetSamplers() const;
 
-  /**
-   * Set the face culling mode for geometry used by this material
-   * @param[in] mode The face culling mode to use
-   */
-  void SetFaceCulling( BufferIndex updateBufferIndex, Dali::CullFaceMode mode );
+private:
+  Shader* mShader;
+  Samplers mSamplers; // Not owned (though who does?)
 
-  /**
-   * Get the face culling mode
-   * @return the face culling mdoe
-   */
-  CullFaceMode GetFaceCulling() const ;
+  // @todo MESH_REWORK add property values for cull face mode, blending options, blend color
+  // Add getters/setters?
+};
 
-  // @note Blending mode is per actor, not per material (requires actor color)
+inline void SetShaderMessage( EventToUpdate& eventToUpdate, const Material& material, Shader& shader )
+{
+  typedef MessageValue1< Material, Shader* > LocalType;
 
-  /**
-   * Set the blending options. This should only be called from the update-thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] options A bitmask of blending options.
-   */
-  void SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options );
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
 
-  /**
-   * Set the blend-color. This should only be called from the update-thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] color The new blend-color.
-   */
-  void SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color );
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &material, &Material::SetShader, &shader );
+}
 
-private:
-  Shader* mShader;
-  Samplers mSamplers; // Not owned (though who does?)
-  Dali::CullFaceMode mCullFaceMode:3;
-  BlendingOptions mBlendingOptions;
-};
+inline void AddSamplerMessage( EventToUpdate& eventToUpdate, const Material& material, const Sampler& sampler )
+{
+  typedef MessageValue1< Material, const Sampler* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &material, &Material::AddSampler, &sampler );
+}
+
+inline void RemoveSamplerMessage( EventToUpdate& eventToUpdate, const Material& material, const Sampler& sampler )
+{
+  typedef MessageValue1< Material, const Sampler* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &material, &Material::RemoveSampler, &sampler );
+}
 
 } // namespace SceneGraph
 } // namespace Internal
index 92472db..4014226 100644 (file)
@@ -47,10 +47,13 @@ void Sampler::SetUniformName( const std::string& samplerName )
 
 void Sampler::SetTextureId( ResourceId textureId )
 {
+  mTextureId = textureId;
 }
 
 void Sampler::SetFilterMode( BufferIndex bufferIndex, FilterMode minFilter, FilterMode magFilter )
 {
+  mMinFilter[bufferIndex] = minFilter;
+  mMagFilter[bufferIndex] = magFilter;
 }
 
 void Sampler::SetWrapMode( BufferIndex bufferIndex, WrapMode uWrap, WrapMode vWrap )
index 632170a..950b5f9 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <dali/public-api/shader-effects/sampler.h>
+#include <dali/internal/common/event-to-update.h>
 #include <dali/internal/update/common/double-buffered.h>
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/render/renderers/sampler-data-provider.h>
@@ -128,6 +129,56 @@ private:
   DoubleBuffered<WrapMode> mVWrapMode;      ///< The vertical wrap mode
 };
 
+inline void SetUniformNameMessage( EventToUpdate& eventToUpdate, const Sampler& sampler, const std::string& name )
+{
+  typedef MessageValue1< Sampler, std::string > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &sampler, &Sampler::SetUniformName, name );
+}
+
+} // namespace SceneGraph
+
+// Declare enum as a message parameter type outside the SceneGraph namespace
+template <> struct ParameterType< SceneGraph::Sampler::FilterMode > : public BasicType< SceneGraph::Sampler::FilterMode > {};
+
+namespace SceneGraph
+{
+
+inline void SetFilterModeMessage( EventToUpdate& eventToUpdate, const Sampler& sampler, Sampler::FilterMode minFilter, Sampler::FilterMode magFilter )
+{
+  typedef MessageDoubleBuffered2< Sampler, Sampler::FilterMode, Sampler::FilterMode > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &sampler, &Sampler::SetFilterMode, minFilter, magFilter );
+}
+
+} // namespace SceneGraph
+
+// Declare enum as a message parameter type
+template <> struct ParameterType< SceneGraph::Sampler::WrapMode > : public BasicType< SceneGraph::Sampler::WrapMode > {};
+
+namespace SceneGraph
+{
+
+inline void SetWrapModeMessage( EventToUpdate& eventToUpdate, const SceneGraph::Sampler& sampler, SceneGraph::Sampler::WrapMode horizontalWrap, SceneGraph::Sampler::WrapMode verticalWrap )
+{
+  typedef MessageDoubleBuffered2< Sampler, Sampler::WrapMode, Sampler::WrapMode > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &sampler, &Sampler::SetWrapMode, horizontalWrap, verticalWrap );
+}
+
+
 } // namespace SceneGraph
 } // namespace Internal
 } // namespace Dali
index 136a771..6a07a39 100644 (file)
@@ -26,26 +26,56 @@ namespace SceneGraph
 Geometry::Geometry()
 : mGeometryType(Dali::Geometry::TRIANGLES)
 {
+  // @todo MESH_REWORK Remove this code when we have working property buffers
+  // @todo It's also the wrong place to do this temporary work
+  PropertyBuffer* vertexPropertyBuffer = PropertyBuffer::NewQuadVertices();
+  mVertexBuffers.PushBack( vertexPropertyBuffer );
+
+  mIndexBuffer = PropertyBuffer::NewQuadIndices();
 }
 
 Geometry::~Geometry()
 {
+  // @todo Inform renderers of deletion of buffers?
+}
+
+void Geometry::AddVertexBuffer( PropertyBuffer* vertexBuffer )
+{
+  mVertexBuffers.PushBack( vertexBuffer );
 }
 
-void Geometry::AddVertexBuffer( PropertyBuffer vertexBuffer )
+void Geometry::RemoveVertexBuffer( PropertyBuffer* vertexBuffer )
 {
+  DALI_ASSERT_DEBUG( NULL != vertexBuffer );
+
+  // Find the object and destroy it
+  for ( OwnerContainer< PropertyBuffer* >::Iterator iter = mVertexBuffers.Begin(); iter != mVertexBuffers.End(); ++iter )
+  {
+    PropertyBuffer* current = *iter;
+    if ( current == vertexBuffer )
+    {
+      mVertexBuffers.Erase( iter );
+      return;
+    }
+  }
+
+  DALI_ASSERT_DEBUG(false);
 }
 
-void Geometry::RemoveVertexBuffer( PropertyBuffer vertexBuffer )
+void Geometry::SetIndexBuffer( PropertyBuffer* indexBuffer )
 {
+  mIndexBuffer = indexBuffer;
 }
 
-void Geometry::SetIndexBuffer( PropertyBuffer indexBuffer )
+void Geometry::ClearIndexBuffer()
 {
+  // @todo Actually delete, or put on Discard Queue and tell Renderer in render thread?
+  mIndexBuffer.Reset();
 }
 
 void Geometry::SetGeometryType( Geometry::GeometryType geometryType )
 {
+  mGeometryType = geometryType;
 }
 
 const Geometry::VertexBuffers& Geometry::GetVertexBuffers()
@@ -55,7 +85,7 @@ const Geometry::VertexBuffers& Geometry::GetVertexBuffers()
 
 const PropertyBuffer& Geometry::GetIndexBuffer()
 {
-  return mIndexBuffer;
+  return *mIndexBuffer.Get();
 }
 
 Geometry::GeometryType Geometry::GetGeometryType( )
index 93ce584..86da67d 100644 (file)
  */
 
 #include <dali/public-api/geometry/geometry.h>
+#include <dali/internal/common/event-to-update.h>
 #include <dali/internal/update/common/double-buffered.h>
 #include <dali/internal/update/common/property-owner.h>
-#include <dali/internal/update/common/property-buffer.h>
+#include <dali/internal/update/common/scene-graph-property-buffer.h>
 
 namespace Dali
 {
@@ -53,19 +54,25 @@ public:
   /**
    * Add a property buffer to be used as a vertex buffer
    */
-  void AddVertexBuffer( PropertyBuffer vertexBuffer );
+  void AddVertexBuffer( PropertyBuffer* vertexBuffer );
 
   /**
    * Remove a property buffer to be used as a vertex buffer
    * @param[in] vertexBuffer the associated vertex buffer to remove
    */
-  void RemoveVertexBuffer( PropertyBuffer vertexBuffer );
+  void RemoveVertexBuffer( PropertyBuffer* vertexBuffer );
 
   /**
    * Set the buffer to be used as a source of indices for the geometry
    * @param[in] indexBuffer the Property buffer describing the indexes for Line, Triangle tyes.
    */
-  void SetIndexBuffer( PropertyBuffer indexBuffer );
+  void SetIndexBuffer( PropertyBuffer* indexBuffer );
+
+  /**
+   * Clear the index buffer if it is no longer required, e.g. if changing geometry type
+   * to POINTS.
+   */
+  void ClearIndexBuffer();
 
   /**
    * Set the type of geometry to draw (Points, Lines, Triangles, etc)
@@ -93,10 +100,73 @@ public: // GeometryDataProvider
 
 private:
   VertexBuffers mVertexBuffers; ///< The vertex buffers
-  PropertyBuffer mIndexBuffer;  ///< The index buffer if required
+  OwnerPointer<PropertyBuffer> mIndexBuffer;  ///< The index buffer if required
   GeometryType mGeometryType;   ///< The type of geometry (tris/lines etc)
 };
 
+inline void AddVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer )
+{
+  typedef MessageValue1< Geometry, OwnerPointer<PropertyBuffer> > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &geometry, &Geometry::AddVertexBuffer, &vertexBuffer );
+}
+
+inline void RemoveVertexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& vertexBuffer )
+{
+  typedef MessageValue1< Geometry, PropertyBuffer* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &geometry, &Geometry::RemoveVertexBuffer, &vertexBuffer );
+}
+
+inline void SetIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, PropertyBuffer& indexBuffer )
+{
+  typedef MessageValue1< Geometry, OwnerPointer< PropertyBuffer > > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &geometry, &Geometry::SetIndexBuffer, &indexBuffer );
+}
+
+inline void ClearIndexBufferMessage( EventToUpdate& eventToUpdate, const Geometry& geometry )
+{
+  typedef Message< Geometry > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &geometry, &Geometry::ClearIndexBuffer );
+}
+
+} // namespace SceneGraph
+
+// Declare enum as a message parameter type
+template <> struct ParameterType< SceneGraph::Geometry::GeometryType > : public BasicType< SceneGraph::Geometry::GeometryType > {};
+
+namespace SceneGraph
+{
+
+inline void SetGeometryTypeMessage( EventToUpdate& eventToUpdate, const Geometry& geometry, SceneGraph::Geometry::GeometryType geometryType )
+{
+  typedef MessageValue1< Geometry, SceneGraph::Geometry::GeometryType > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &geometry, &Geometry::SetGeometryType, geometryType );
+}
+
 } // namespace SceneGraph
 } // namespace Internal
 } // namespace Dali
index 33ebb76..3b0f651 100644 (file)
 #include <dali/internal/update/animation/scene-graph-animator.h>
 #include <dali/internal/update/animation/scene-graph-animation.h>
 #include <dali/internal/update/common/discard-queue.h>
+#include <dali/internal/update/common/scene-graph-buffers.h>
+#include <dali/internal/update/controllers/render-message-dispatcher.h>
+#include <dali/internal/update/controllers/scene-controller-impl.h>
+#include <dali/internal/update/effects/scene-graph-material.h>
+#include <dali/internal/update/geometry/scene-graph-geometry.h>
+#include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
 #include <dali/internal/update/manager/prepare-render-algorithms.h>
 #include <dali/internal/update/manager/process-render-tasks.h>
-#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/internal/update/resources/complete-status-manager.h>
-#include <dali/internal/update/common/scene-graph-buffers.h>
-#include <dali/internal/update/render-tasks/scene-graph-render-task.h>
-#include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
 #include <dali/internal/update/manager/sorted-layers.h>
 #include <dali/internal/update/manager/update-algorithms.h>
-#include <dali/internal/update/queue/update-message-queue.h>
 #include <dali/internal/update/manager/update-manager-debug.h>
-#include <dali/internal/update/controllers/render-message-dispatcher.h>
-#include <dali/internal/update/controllers/scene-controller-impl.h>
-#include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
 #include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
 #include <dali/internal/update/nodes/node.h>
 #include <dali/internal/update/nodes/scene-graph-layer.h>
+#include <dali/internal/update/queue/update-message-queue.h>
+#include <dali/internal/update/render-tasks/scene-graph-render-task.h>
+#include <dali/internal/update/render-tasks/scene-graph-render-task-list.h>
+#include <dali/internal/update/resources/resource-manager.h>
+#include <dali/internal/update/resources/complete-status-manager.h>
 #include <dali/internal/update/touch/touch-resampler.h>
 
 #include <dali/internal/render/common/render-instruction-container.h>
@@ -124,6 +126,14 @@ void DestroyNodeSet( std::set<Node*>& nodeSet )
 
 } //namespace
 
+typedef OwnerContainer< Geometry* >            GeometryContainer;
+typedef GeometryContainer::Iterator            GeometryIter;
+typedef GeometryContainer::ConstIterator       GeometryConstIter;
+
+typedef OwnerContainer< Material* >            MaterialContainer;
+typedef MaterialContainer::Iterator            MaterialIter;
+typedef MaterialContainer::ConstIterator       MaterialConstIter;
+
 typedef OwnerContainer< Shader* >              ShaderContainer;
 typedef ShaderContainer::Iterator              ShaderIter;
 typedef ShaderContainer::ConstIterator         ShaderConstIter;
@@ -258,6 +268,9 @@ struct UpdateManager::Impl
   AnimationContainer                  animations;                    ///< A container of owned animations
   PropertyNotificationContainer       propertyNotifications;         ///< A container of owner property notifications.
 
+  GeometryContainer                   geometries;                    ///< A container of geometries
+  MaterialContainer                   materials;                     ///< A container of materials
+
   ShaderContainer                     shaders;                       ///< A container of owned shaders
 
   MessageQueue                        messageQueue;                  ///< The messages queued from the event-thread
@@ -519,6 +532,67 @@ void UpdateManager::PropertyNotificationSetNotify( PropertyNotification* propert
   propertyNotification->SetNotifyMode( notifyMode );
 }
 
+
+void UpdateManager::AddGeometry( Geometry* geometry )
+{
+  DALI_ASSERT_DEBUG( NULL != geometry );
+  mImpl->geometries.PushBack( geometry );
+}
+
+void UpdateManager::RemoveGeometry( Geometry* geometry )
+{
+  DALI_ASSERT_DEBUG(geometry != NULL);
+
+  GeometryContainer& geometries = mImpl->geometries;
+
+  // Find the geometry and destroy it
+  for ( GeometryIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+  {
+    Geometry& current = **iter;
+    if ( &current == geometry )
+    {
+      // Transfer ownership to the discard queue
+      // This keeps the geometry alive, until the render-thread has finished with it
+      mImpl->discardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), geometries.Release( iter ) );
+
+      return;
+    }
+  }
+
+  // Should not reach here
+  DALI_ASSERT_DEBUG(false);
+}
+
+void UpdateManager::AddMaterial( Material* material )
+{
+  DALI_ASSERT_DEBUG( NULL != material );
+
+  mImpl->materials.PushBack( material );
+}
+
+void UpdateManager::RemoveMaterial( Material* material )
+{
+  DALI_ASSERT_DEBUG(material != NULL);
+
+  MaterialContainer& materials = mImpl->materials;
+
+  // Find the material and destroy it
+  for ( MaterialIter iter = materials.Begin(); iter != materials.End(); ++iter )
+  {
+    Material& current = **iter;
+    if ( &current == material )
+    {
+      // Transfer ownership to the discard queue
+      // This keeps the material alive, until the render-thread has finished with it
+      mImpl->discardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), materials.Release( iter ) );
+
+      return;
+    }
+  }
+  // Should not reach here
+  DALI_ASSERT_DEBUG(false);
+}
+
 void UpdateManager::AddShader( Shader* shader )
 {
   DALI_ASSERT_DEBUG( NULL != shader );
@@ -542,7 +616,7 @@ void UpdateManager::AddShader( Shader* shader )
   shader->Initialize( mImpl->renderQueue, mImpl->sceneController->GetTextureCache() );
 }
 
-void UpdateManager::RemoveShader(Shader* shader)
+void UpdateManager::RemoveShader( Shader* shader )
 {
   DALI_ASSERT_DEBUG(shader != NULL);
 
@@ -694,6 +768,18 @@ void UpdateManager::ResetProperties()
     (*iter)->ResetToBaseValues( mSceneGraphBuffers.GetUpdateBufferIndex() );
   }
 
+  // Reset animatable material properties to base values
+  for (MaterialIter iter = mImpl->materials.Begin(); iter != mImpl->materials.End(); ++iter)
+  {
+    (*iter)->ResetToBaseValues( mSceneGraphBuffers.GetUpdateBufferIndex() );
+  }
+
+  // Reset animatable geometry properties to base values
+  for (GeometryIter iter = mImpl->geometries.Begin(); iter != mImpl->geometries.End(); ++iter)
+  {
+    (*iter)->ResetToBaseValues( mSceneGraphBuffers.GetUpdateBufferIndex() );
+  }
+
   // Reset animatable shader properties to base values
   for (ShaderIter iter = mImpl->shaders.Begin(); iter != mImpl->shaders.End(); ++iter)
   {
@@ -807,6 +893,21 @@ void UpdateManager::ApplyConstraints()
     mImpl->activeConstraints += ConstrainPropertyOwner( task, mSceneGraphBuffers.GetUpdateBufferIndex() );
   }
 
+  // Constrain Materials and geometries
+  MaterialContainer& materials = mImpl->materials;
+  for ( MaterialIter iter = materials.Begin(); iter != materials.End(); ++iter )
+  {
+    Material& material = **iter;
+    mImpl->activeConstraints += ConstrainPropertyOwner( material, mSceneGraphBuffers.GetUpdateBufferIndex() );
+  }
+
+  GeometryContainer& geometries = mImpl->geometries;
+  for ( GeometryIter iter = geometries.Begin(); iter != geometries.End(); ++iter )
+  {
+    Geometry& geometry = **iter;
+    mImpl->activeConstraints += ConstrainPropertyOwner( geometry, mSceneGraphBuffers.GetUpdateBufferIndex() );
+  }
+
   // constrain shaders... (in construction order)
   ShaderContainer& shaders = mImpl->shaders;
 
index 47c047a..d174bdf 100644 (file)
 // INTERNAL INCLUDES
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/common/dali-common.h>
+
 #include <dali/integration-api/resource-declarations.h>
+
 #include <dali/internal/common/message.h>
 #include <dali/internal/common/event-to-update.h>
-#include <dali/internal/render/shaders/scene-graph-shader.h>
-#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
-#include <dali/internal/update/common/scene-graph-buffers.h>
+#include <dali/internal/common/type-abstraction-enums.h>
+
 #include <dali/internal/update/animation/scene-graph-animation.h>
+#include <dali/internal/update/common/scene-graph-buffers.h>
 #include <dali/internal/update/common/scene-graph-property-notification.h>
+#include <dali/internal/update/geometry/scene-graph-geometry.h>
+#include <dali/internal/update/effects/scene-graph-material.h>
+#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/common/type-abstraction-enums.h>
+
+#include <dali/internal/render/shaders/scene-graph-shader.h>
 
 namespace Dali
 {
@@ -257,6 +263,31 @@ public:
    */
   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
 
+
+  /**
+   * Add a geometry to the scene graph
+   * @param[in] geometry The geometry to add
+   */
+  void AddGeometry( Geometry* geometry );
+
+  /**
+   * Remove a geometry from the scene graph
+   * @param[in] geometry The geometry to remove
+   */
+  void RemoveGeometry( Geometry* geometry );
+
+  /**
+   * Add a material to the scene graph
+   * @param[in] material The material to add
+   */
+  void AddMaterial( Material* material );
+
+  /**
+   * Remove a material from the scene graph
+   * @param[in] material The material to remove
+   */
+  void RemoveMaterial( Material* material );
+
   // Shaders
 
   /**
@@ -620,6 +651,53 @@ inline void PropertyNotificationSetNotifyModeMessage( UpdateManager& manager,
   new (slot) LocalType( &manager, &UpdateManager::PropertyNotificationSetNotify, propertyNotification, notifyMode );
 }
 
+inline void AddGeometryMessage( UpdateManager& manager, Geometry& geometry )
+{
+  typedef MessageValue1< UpdateManager, OwnerPointer< Geometry > > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.GetEventToUpdate().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::AddGeometry, &geometry );
+}
+
+// The render thread can safely change the Geometry
+inline void RemoveGeometryMessage( UpdateManager& manager, Geometry& geometry )
+{
+  typedef MessageValue1< UpdateManager, Geometry* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.GetEventToUpdate().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::RemoveGeometry, &geometry );
+}
+
+inline void AddMaterialMessage( UpdateManager& manager, Material& material )
+{
+  typedef MessageValue1< UpdateManager, OwnerPointer< Material > > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.GetEventToUpdate().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::AddMaterial, &material );
+}
+
+// The render thread can safely change the Material
+inline void RemoveMaterialMessage( UpdateManager& manager, Material& material )
+{
+  typedef MessageValue1< UpdateManager, Material* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.GetEventToUpdate().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::RemoveMaterial, &material );
+}
+
+
 // The render thread can safely change the Shader
 inline void AddShaderMessage( UpdateManager& manager, Shader& shader )
 {
index 63ba684..377a812 100644 (file)
@@ -37,10 +37,10 @@ RendererAttachment::~RendererAttachment()
   mGeometry=NULL;
 }
 
-void RendererAttachment::SetMaterial(const Material& material)
+void RendererAttachment::SetMaterial(const Material* material)
 {
   // @todo MESH_REWORK
-  mMaterial = &material;
+  mMaterial = material;
 }
 
 const Material& RendererAttachment::GetMaterial() const
@@ -48,10 +48,10 @@ const Material& RendererAttachment::GetMaterial() const
   return *mMaterial;
 }
 
-void RendererAttachment::SetGeometry(const Geometry& geometry)
+void RendererAttachment::SetGeometry(const Geometry* geometry)
 {
   // @todo MESH_REWORK
-  mGeometry = &geometry;
+  mGeometry = geometry;
 }
 
 const Geometry& RendererAttachment::GetGeometry() const
index 27194ce..b4eda54 100644 (file)
@@ -48,7 +48,7 @@ public:
    * Set the material for the renderer
    * @param[in] material The material this renderer will use
    */
-  void SetMaterial(const Material& material);
+  void SetMaterial(const Material* material);
 
   /**
    * Get the material of this renderer
@@ -60,7 +60,7 @@ public:
    * Set the geometry for the renderer
    * @param[in] geometry The geometry this renderer will use
    */
-  void SetGeometry(const Geometry& geometry);
+  void SetGeometry(const Geometry* geometry);
 
   /**
    * Get the geometry of this renderer
@@ -86,6 +86,41 @@ private:
   int mDepthIndex;     ///< Used only in PrepareRenderInstructions
 };
 
+// Messages for RendererAttachment
+
+inline void SetMaterialMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, const Material& material )
+{
+  typedef MessageValue1< RendererAttachment, const Material* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &attachment, &RendererAttachment::SetMaterial, &material );
+}
+
+inline void SetGeometryMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, const Geometry& geometry )
+{
+  typedef MessageValue1< RendererAttachment, const Geometry* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &attachment, &RendererAttachment::SetGeometry, &geometry );
+}
+
+inline void SetDepthIndexMessage( EventToUpdate& eventToUpdate, const RendererAttachment& attachment, int depthIndex )
+{
+  typedef MessageValue1< RendererAttachment, int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &attachment, &RendererAttachment::SetDepthIndex, depthIndex );
+}
+
 } // namespace SceneGraph
 } // namespace Internal
 } // namespace Dali