Changed RenderDataProvider to remove copy 29/261529/1
authorDavid Steele <david.steele@samsung.com>
Tue, 20 Jul 2021 17:21:05 +0000 (18:21 +0100)
committerDavid Steele <david.steele@samsung.com>
Tue, 20 Jul 2021 17:21:05 +0000 (18:21 +0100)
Previously, RenderDataProvider had it's own data, and
we copied in texture & sampler ptrs whenever texture changed.
Changed RenderDataProvider to a pure interface with no data.

Changed to make SceneGraph::Renderer a RenderDataProvider,
and removed copies & TextureSet observers.

Change-Id: I6f19fc667f0abafd07b29c664dec316f86e88ebb
Signed-off-by: David Steele <david.steele@samsung.com>
dali/internal/file.list
dali/internal/render/data-providers/render-data-provider.cpp [deleted file]
dali/internal/render/data-providers/render-data-provider.h
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/update/manager/render-instruction-processor.cpp
dali/internal/update/rendering/scene-graph-renderer.cpp
dali/internal/update/rendering/scene-graph-renderer.h
dali/internal/update/rendering/scene-graph-texture-set.cpp
dali/internal/update/rendering/scene-graph-texture-set.h

index 613c672..a833158 100644 (file)
@@ -106,7 +106,6 @@ SET( internal_src_files
   ${internal_src_dir}/render/common/render-item.cpp
   ${internal_src_dir}/render/common/render-tracker.cpp
   ${internal_src_dir}/render/common/render-manager.cpp
-  ${internal_src_dir}/render/data-providers/render-data-provider.cpp
   ${internal_src_dir}/render/queue/render-queue.cpp
   ${internal_src_dir}/render/renderers/gpu-buffer.cpp
   ${internal_src_dir}/render/renderers/pipeline-cache.cpp
diff --git a/dali/internal/render/data-providers/render-data-provider.cpp b/dali/internal/render/data-providers/render-data-provider.cpp
deleted file mode 100644 (file)
index b769864..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "render-data-provider.h"
-
-namespace Dali
-{
-namespace Internal
-{
-namespace SceneGraph
-{
-RenderDataProvider::RenderDataProvider(AnimatableProperty<float>& opacity)
-: mUniformMapDataProvider(nullptr),
-  mShader(nullptr),
-  mOpacity(opacity)
-{
-}
-
-RenderDataProvider::~RenderDataProvider() = default;
-
-void RenderDataProvider::SetUniformMap(const UniformMapDataProvider& uniformMapDataProvider)
-{
-  mUniformMapDataProvider = &uniformMapDataProvider;
-}
-
-const UniformMapDataProvider& RenderDataProvider::GetUniformMap() const
-{
-  return *mUniformMapDataProvider;
-}
-
-void RenderDataProvider::SetShader(Shader& shader)
-{
-  mShader = &shader;
-}
-
-Shader& RenderDataProvider::GetShader() const
-{
-  return *mShader;
-}
-
-RenderDataProvider::Samplers& RenderDataProvider::GetSamplers()
-{
-  return mSamplers;
-}
-
-std::vector<Render::Texture*>& RenderDataProvider::GetTextures()
-{
-  return mTextures;
-}
-
-float RenderDataProvider::GetOpacity(BufferIndex bufferIndex)
-{
-  return mOpacity[bufferIndex];
-}
-
-} // namespace SceneGraph
-} // namespace Internal
-} // namespace Dali
index 3568666..f33822d 100644 (file)
@@ -50,72 +50,41 @@ class Renderer;
  */
 class RenderDataProvider
 {
-public:
-  using Samplers = std::vector<Render::Sampler*>;
-
-  /**
-   * Constructor.
-   * The RendererAttachment that creates this object will initialize the members
-   * directly.
-   */
-  explicit RenderDataProvider(AnimatableProperty<float>& opacity);
-
+protected:
   /**
    * Destructor
    */
-  ~RenderDataProvider();
+  virtual ~RenderDataProvider() = default;
 
 public:
   /**
-   * Set the uniform map data provider
-   * @param[in] uniformMapDataProvider The uniform map data provider
-   */
-  void SetUniformMap(const UniformMapDataProvider& uniformMapDataProvider);
-
-  /**
    * Get the uniform map data provider
    */
-  [[nodiscard]] const UniformMapDataProvider& GetUniformMap() const;
-
-  /**
-   * Set the shader data provider
-   * @param[in] shader The shader data provider
-   */
-  void SetShader(Shader& shader);
+  virtual const UniformMapDataProvider& GetUniformMapDataProvider() const = 0;
 
   /**
    * Returns the shader
    * @return The shader
    */
-  [[nodiscard]] Shader& GetShader() const;
+  virtual const Shader& GetShader() const = 0;
 
   /**
    * Returns the list of samplers
    * @return The list of samplers
    */
-  Samplers& GetSamplers();
+  virtual const Dali::Vector<Render::Sampler*>* GetSamplers() const = 0;
 
   /**
    * Returns the list of Textures
    * @return The list of Textures
    */
-  std::vector<Render::Texture*>& GetTextures();
+  virtual const Dali::Vector<Render::Texture*>* GetTextures() const = 0;
 
   /**
    * Get the opacity
    * @return The opacity
    */
-  float GetOpacity(BufferIndex bufferIndex);
-
-private:
-  const UniformMapDataProvider* mUniformMapDataProvider;
-  Shader*                       mShader;
-  std::vector<Render::Texture*> mTextures;
-  Samplers                      mSamplers;
-  AnimatableProperty<float>&    mOpacity;
-
-  // Give Renderer access to our private data to reduce copying vectors on construction.
-  friend class Renderer;
+  virtual float GetOpacity(BufferIndex bufferIndex) const = 0;
 };
 
 } // namespace SceneGraph
index 6681a54..3150bf4 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali/internal/render/common/render-instruction.h>
 #include <dali/internal/render/data-providers/node-data-provider.h>
 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
+#include <dali/internal/render/renderers/pipeline-cache.h>
 #include <dali/internal/render/renderers/render-sampler.h>
 #include <dali/internal/render/renderers/render-texture.h>
 #include <dali/internal/render/renderers/render-vertex-buffer.h>
 #include <dali/internal/render/shaders/program.h>
 #include <dali/internal/render/shaders/render-shader.h>
 #include <dali/internal/update/common/uniform-map.h>
-#include <dali/internal/render/renderers/pipeline-cache.h>
 
 namespace Dali::Internal
 {
 namespace
 {
 // Helper to get the property value getter by type
-typedef const float&(PropertyInputImpl::*FuncGetter )(BufferIndex) const;
+typedef const float& (PropertyInputImpl::*FuncGetter)(BufferIndex) const;
 constexpr FuncGetter GetPropertyValueGetter(Property::Type type)
 {
   switch(type)
@@ -89,18 +89,42 @@ constexpr FuncGetter GetPropertyValueGetter(Property::Type type)
  * Helper function that returns size of uniform datatypes based
  * on property type.
  */
-constexpr int GetPropertyValueSizeForUniform( Property::Type type )
+constexpr int GetPropertyValueSizeForUniform(Property::Type type)
 {
   switch(type)
   {
-    case Property::Type::BOOLEAN:{ return sizeof(bool);}
-    case Property::Type::FLOAT:{ return sizeof(float);}
-    case Property::Type::INTEGER:{ return sizeof(int);}
-    case Property::Type::VECTOR2:{ return sizeof(Vector2);}
-    case Property::Type::VECTOR3:{ return sizeof(Vector3);}
-    case Property::Type::VECTOR4:{ return sizeof(Vector4);}
-    case Property::Type::MATRIX3:{ return sizeof(Matrix3);}
-    case Property::Type::MATRIX:{ return sizeof(Matrix);}
+    case Property::Type::BOOLEAN:
+    {
+      return sizeof(bool);
+    }
+    case Property::Type::FLOAT:
+    {
+      return sizeof(float);
+    }
+    case Property::Type::INTEGER:
+    {
+      return sizeof(int);
+    }
+    case Property::Type::VECTOR2:
+    {
+      return sizeof(Vector2);
+    }
+    case Property::Type::VECTOR3:
+    {
+      return sizeof(Vector3);
+    }
+    case Property::Type::VECTOR4:
+    {
+      return sizeof(Vector4);
+    }
+    case Property::Type::MATRIX3:
+    {
+      return sizeof(Matrix3);
+    }
+    case Property::Type::MATRIX:
+    {
+      return sizeof(Matrix);
+    }
     default:
     {
       return 0;
@@ -185,8 +209,8 @@ Renderer::~Renderer() = default;
 
 void Renderer::SetGeometry(Render::Geometry* geometry)
 {
-  mGeometry  = geometry;
-  mUpdated   = true;
+  mGeometry = geometry;
+  mUpdated  = true;
 }
 void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)
 {
@@ -198,26 +222,31 @@ void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graph
 {
   uint32_t textureUnit = 0;
 
-  std::vector<Render::Sampler*>& samplers(mRenderDataProvider->GetSamplers());
-  std::vector<Render::Texture*>& textures(mRenderDataProvider->GetTextures());
+  const Dali::Vector<Render::Texture*>* textures(mRenderDataProvider->GetTextures());
+  const Dali::Vector<Render::Sampler*>* samplers(mRenderDataProvider->GetSamplers());
 
   std::vector<Graphics::TextureBinding> textureBindings;
-  for(uint32_t i = 0; i < static_cast<uint32_t>(textures.size()); ++i) // not expecting more than uint32_t of textures
+
+  if(textures != nullptr)
   {
-    if(textures[i] && textures[i]->GetGraphicsObject())
+    for(uint32_t i = 0; i < static_cast<uint32_t>(textures->Count()); ++i) // not expecting more than uint32_t of textures
     {
-      // if the sampler exists,
-      //   if it's default, delete the graphics object
-      //   otherwise re-initialize it if dirty
+      if((*textures)[i] && (*textures)[i]->GetGraphicsObject())
+      {
+        // if the sampler exists,
+        //   if it's default, delete the graphics object
+        //   otherwise re-initialize it if dirty
 
-      const Graphics::Sampler* graphicsSampler = (samplers[i] ? samplers[i]->GetGraphicsObject()
-                                                              : nullptr);
+        const Graphics::Sampler* graphicsSampler = samplers ? ((*samplers)[i] ? (*samplers)[i]->GetGraphicsObject()
+                                                                              : nullptr)
+                                                            : nullptr;
 
-      boundTextures.PushBack(textures[i]->GetGraphicsObject());
-      const Graphics::TextureBinding textureBinding{textures[i]->GetGraphicsObject(), graphicsSampler, textureUnit};
-      textureBindings.push_back(textureBinding);
+        boundTextures.PushBack((*textures)[i]->GetGraphicsObject());
+        const Graphics::TextureBinding textureBinding{(*textures)[i]->GetGraphicsObject(), graphicsSampler, textureUnit};
+        textureBindings.push_back(textureBinding);
 
-      ++textureUnit;
+        ++textureUnit;
+      }
     }
   }
 
@@ -431,28 +460,28 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
   }
 
   // Create Program
-  ShaderDataPtr            shaderData   = mRenderDataProvider->GetShader().GetShaderData();
+  ShaderDataPtr shaderData = mRenderDataProvider->GetShader().GetShaderData();
 
-  Program* program         = Program::New(*mProgramCache,
+  Program* program = Program::New(*mProgramCache,
                                   shaderData,
                                   *mGraphicsController);
   if(!program)
   {
-    DALI_LOG_ERROR("Failed to get program for shader at address %p.\n", reinterpret_cast<void*>(&mRenderDataProvider->GetShader()));
+    DALI_LOG_ERROR("Failed to get program for shader at address %p.\n", reinterpret_cast<const void*>(&mRenderDataProvider->GetShader()));
     return false;
   }
 
   // If program doesn't have Gfx program object assigned yet, prepare it.
   if(!program->GetGraphicsProgramPtr())
   {
-    const std::vector<char> &vertShader   = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::VERTEX_SHADER);
-    const std::vector<char> &fragShader   = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER);
-    Dali::Graphics::Shader  &vertexShader = mShaderCache->GetShader(
+    const std::vector<char>vertShader   = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::VERTEX_SHADER);
+    const std::vector<char>fragShader   = shaderData->GetShaderForPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER);
+    Dali::Graphics::Shader&  vertexShader = mShaderCache->GetShader(
       vertShader,
       Graphics::PipelineStage::VERTEX_SHADER,
       shaderData->GetSourceMode());
 
-    Dali::Graphics::Shader &fragmentShader = mShaderCache->GetShader(
+    Dali::Graphics::ShaderfragmentShader = mShaderCache->GetShader(
       fragShader,
       Graphics::PipelineStage::FRAGMENT_SHADER,
       shaderData->GetSourceMode());
@@ -506,7 +535,7 @@ void Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::N
   // Check if the map has changed
   DALI_ASSERT_DEBUG(mRenderDataProvider && "No Uniform map data provider available");
 
-  const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
+  const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
 
   if(uniformMapDataProvider.GetUniformMapChanged(bufferIndex) ||
      node.GetUniformMapChanged(bufferIndex) ||
@@ -580,7 +609,7 @@ void Renderer::WriteUniformBuffer(
   // Create the UBO
   uint32_t uboOffset{0u};
 
-  auto &reflection = mGraphicsController->GetProgramReflection(program->GetGraphicsProgram());
+  autoreflection = mGraphicsController->GetProgramReflection(program->GetGraphicsProgram());
 
   uint32_t uniformBlockAllocationBytes = program->GetUniformBlocksMemoryRequirements().totalSizeRequired;
 
@@ -698,8 +727,8 @@ void Renderer::FillUniformBuffer(Program&                                      p
         iter != end;
         ++iter)
     {
-      auto& uniform = *iter;
-      int arrayIndex = uniform.arrayIndex;
+      auto& uniform    = *iter;
+      int   arrayIndex = uniform.arrayIndex;
 
       if(!uniform.uniformFunc)
       {
@@ -712,7 +741,7 @@ void Renderer::FillUniformBuffer(Program&                                      p
         uniform.uniformOffset   = uniformInfo.offset;
         uniform.uniformLocation = uniformInfo.location;
 
-        if (uniformFound)
+        if(uniformFound)
         {
           auto       dst      = ubo.GetOffset() + uniformInfo.offset;
           const auto typeSize = GetPropertyValueSizeForUniform((*iter).propertyValue->GetType());
@@ -734,7 +763,6 @@ void Renderer::FillUniformBuffer(Program&                                      p
         const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
         const auto func     = uniform.uniformFunc;
 
-
         ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
                   typeSize,
                   dest);
@@ -772,11 +800,16 @@ bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvid
     return true;
   }
 
-  for(const auto& texture : mRenderDataProvider->GetTextures())
+  auto* textures = mRenderDataProvider->GetTextures();
+  if(textures)
   {
-    if(texture && texture->IsNativeImage())
+    for(auto iter = textures->Begin(), end = textures->End(); iter < end; ++iter)
     {
-      return true;
+      auto texture = *iter;
+      if(texture && texture->IsNativeImage())
+      {
+        return true;
+      }
     }
   }
 
@@ -787,7 +820,7 @@ bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvid
     hash = uniformProperty.propertyPtr->Hash(bufferIndex, hash);
   }
 
-  const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
+  const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
   const SceneGraph::CollectedUniformMap&    uniformMap             = uniformMapDataProvider.GetUniformMap(bufferIndex);
   for(const auto& uniformProperty : uniformMap)
   {
@@ -816,15 +849,15 @@ Graphics::Pipeline& Renderer::PrepareGraphicsPipeline(
 
   // Prepare query info
   PipelineCacheQueryInfo queryInfo{};
-  queryInfo.program = &program;
-  queryInfo.renderer = this;
-  queryInfo.geometry = mGeometry;
-  queryInfo.blendingEnabled = blend;
-  queryInfo.blendingOptions = &mBlendingOptions;
-  queryInfo.alphaPremultiplied = mPremultipliedAlphaEnabled;
+  queryInfo.program               = &program;
+  queryInfo.renderer              = this;
+  queryInfo.geometry              = mGeometry;
+  queryInfo.blendingEnabled       = blend;
+  queryInfo.blendingOptions       = &mBlendingOptions;
+  queryInfo.alphaPremultiplied    = mPremultipliedAlphaEnabled;
   queryInfo.cameraUsingReflection = instruction.GetCamera()->GetReflectionUsed();
 
-  auto pipelineResult = mPipelineCache->GetPipeline( queryInfo, true );
+  auto pipelineResult = mPipelineCache->GetPipeline(queryInfo, true);
 
   // should be never null?
   return *pipelineResult.pipeline;
index 5583fe0..fe0e07e 100644 (file)
@@ -403,19 +403,19 @@ public:
   bool Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node);
 
   template<class T>
-  bool WriteDefaultUniform(const Graphics::UniformInfo*                       uniformInfo,
-                           Render::UniformBufferView&                         ubo,
-                           const T&                                           data);
+  bool WriteDefaultUniform(const Graphics::UniformInfo* uniformInfo,
+                           Render::UniformBufferView&   ubo,
+                           const T&                     data);
 
   template<class T>
-  void WriteUniform(Render::UniformBufferView&                             ubo,
-                    const Graphics::UniformInfo&                       uniformInfo,
-                    const T&                                           data);
+  void WriteUniform(Render::UniformBufferView&   ubo,
+                    const Graphics::UniformInfo& uniformInfo,
+                    const T&                     data);
 
-  void WriteUniform(Render::UniformBufferView&                             ubo,
-                    const Graphics::UniformInfo&                       uniformInfo,
-                    const void*                                        data,
-                    uint32_t                                           size);
+  void WriteUniform(Render::UniformBufferView&   ubo,
+                    const Graphics::UniformInfo& uniformInfo,
+                    const void*                  data,
+                    uint32_t                     size);
 
   [[nodiscard]] FaceCullingMode::Type GetFaceCullMode() const
   {
@@ -502,8 +502,8 @@ private:
                          BufferIndex                                   updateBufferIndex);
 
 private:
-  Graphics::Controller*                        mGraphicsController;
-  OwnerPointer<SceneGraph::RenderDataProvider> mRenderDataProvider;
+  Graphics::Controller*           mGraphicsController;
+  SceneGraph::RenderDataProvider* mRenderDataProvider;
 
   Render::Geometry* mGeometry;
 
@@ -517,7 +517,7 @@ private:
 
   using Hash = unsigned long;
 
-  typedef const float&(PropertyInputImpl::*FuncGetter )(BufferIndex) const;
+  typedef const float& (PropertyInputImpl::*FuncGetter)(BufferIndex) const;
 
   struct UniformIndexMap
   {
@@ -527,10 +527,10 @@ private:
     Hash                     uniformNameHashNoArray{0u};
     int32_t                  arrayIndex{-1}; ///< The array index
 
-    int16_t                  uniformLocation{0u};
-    uint16_t                 uniformOffset{0u};
-    uint16_t                 uniformSize{0u};
-    FuncGetter               uniformFunc{0};
+    int16_t    uniformLocation{0u};
+    uint16_t   uniformOffset{0u};
+    uint16_t   uniformSize{0u};
+    FuncGetter uniformFunc{0};
   };
 
   using UniformIndexMappings = Dali::Vector<UniformIndexMap>;
index 08d768a..64ba230 100644 (file)
@@ -185,7 +185,7 @@ inline void AddRendererToRenderList(BufferIndex         updateBufferIndex,
 
       if(renderable.mRenderer)
       {
-        partialRenderingCacheInfo.textureSet = renderable.mRenderer->GetTextures();
+        partialRenderingCacheInfo.textureSet = renderable.mRenderer->GetTextureSet();
       }
 
       item.mNode     = renderable.mNode;
@@ -201,7 +201,7 @@ inline void AddRendererToRenderList(BufferIndex         updateBufferIndex,
       if(DALI_LIKELY(renderable.mRenderer))
       {
         item.mRenderer   = &renderable.mRenderer->GetRenderer();
-        item.mTextureSet = renderable.mRenderer->GetTextures();
+        item.mTextureSet = renderable.mRenderer->GetTextureSet();
         item.mDepthIndex += renderable.mRenderer->GetDepthIndex();
       }
       else
index dd765b8..55d4ec1 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/internal/common/internal-constants.h>
 #include <dali/internal/common/memory-pool-object-allocator.h>
 #include <dali/internal/render/data-providers/node-data-provider.h>
+#include <dali/internal/render/data-providers/render-data-provider.h>
 #include <dali/internal/render/queue/render-queue.h>
 #include <dali/internal/render/renderers/render-geometry.h>
 #include <dali/internal/render/shaders/program.h>
@@ -131,7 +132,6 @@ Renderer::Renderer()
   mTextureSet(nullptr),
   mGeometry(nullptr),
   mShader(nullptr),
-  mRenderDataProvider(nullptr),
   mBlendColor(nullptr),
   mStencilParameters(RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP),
   mIndexedDrawFirstElement(0u),
@@ -160,7 +160,6 @@ Renderer::~Renderer()
 {
   if(mTextureSet)
   {
-    mTextureSet->RemoveObserver(this);
     mTextureSet = nullptr;
   }
   if(mShader)
@@ -378,16 +377,18 @@ void Renderer::SetTextures(TextureSet* textureSet)
 {
   DALI_ASSERT_DEBUG(textureSet != NULL && "Texture set pointer is NULL");
 
-  if(mTextureSet)
-  {
-    mTextureSet->RemoveObserver(this);
-  }
-
-  mTextureSet = textureSet;
-  mTextureSet->AddObserver(this);
+  mTextureSet           = textureSet;
   mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
+}
 
-  UpdateTextureSet();
+const Vector<Render::Texture*>* Renderer::GetTextures() const
+{
+  return mTextureSet ? &(mTextureSet->GetTextures()) : nullptr;
+}
+
+const Vector<Render::Sampler*>* Renderer::GetSamplers() const
+{
+  return mTextureSet ? &(mTextureSet->GetSamplers()) : nullptr;
 }
 
 void Renderer::SetShader(Shader* shader)
@@ -403,11 +404,6 @@ void Renderer::SetShader(Shader* shader)
   mShader->AddConnectionObserver(*this);
   mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
   mResendFlag |= RESEND_GEOMETRY | RESEND_SHADER;
-
-  if(mRenderDataProvider)
-  {
-    mRenderDataProvider->mShader = mShader;
-  }
 }
 
 void Renderer::SetGeometry(Render::Geometry* geometry)
@@ -636,10 +632,7 @@ void Renderer::ConnectToSceneGraph(SceneController& sceneController, BufferIndex
   mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
   mSceneController      = &sceneController;
 
-  mRenderDataProvider                          = new RenderDataProvider(mOpacity);
-  mRenderDataProvider->mUniformMapDataProvider = this;
-
-  mRenderer = Render::Renderer::New(mRenderDataProvider, mGeometry, mBlendBitmask, GetBlendColor(), static_cast<FaceCullingMode::Type>(mFaceCullingMode), mPremultipledAlphaEnabled, mDepthWriteMode, mDepthTestMode, mDepthFunction, mStencilParameters);
+  mRenderer = Render::Renderer::New(this, mGeometry, mBlendBitmask, GetBlendColor(), static_cast<FaceCullingMode::Type>(mFaceCullingMode), mPremultipledAlphaEnabled, mDepthWriteMode, mDepthTestMode, mDepthFunction, mStencilParameters);
 
   OwnerPointer<Render::Renderer> transferOwnership(mRenderer);
   mSceneController->GetRenderMessageDispatcher().AddRenderer(transferOwnership);
@@ -654,31 +647,7 @@ void Renderer::DisconnectFromSceneGraph(SceneController& sceneController, Buffer
     mSceneController->GetRenderMessageDispatcher().RemoveRenderer(*mRenderer);
     mRenderer = nullptr;
   }
-  mSceneController    = nullptr;
-  mRenderDataProvider = nullptr;
-}
-
-void Renderer::UpdateTextureSet()
-{
-  if(mRenderDataProvider)
-  {
-    if(mTextureSet)
-    {
-      uint32_t textureCount = mTextureSet->GetTextureCount();
-      mRenderDataProvider->mTextures.resize(textureCount);
-      mRenderDataProvider->mSamplers.resize(textureCount);
-      for(uint32_t i = 0; i < textureCount; ++i)
-      {
-        mRenderDataProvider->mTextures[i] = mTextureSet->GetTexture(i);
-        mRenderDataProvider->mSamplers[i] = mTextureSet->GetTextureSampler(i);
-      }
-    }
-    else
-    {
-      mRenderDataProvider->mTextures.clear();
-      mRenderDataProvider->mSamplers.clear();
-    }
-  }
+  mSceneController = nullptr;
 }
 
 Render::Renderer& Renderer::GetRenderer()
@@ -753,22 +722,6 @@ Renderer::OpacityType Renderer::GetOpacityType(BufferIndex updateBufferIndex, co
   return opacityType;
 }
 
-void Renderer::TextureSetChanged()
-{
-  mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
-
-  UpdateTextureSet();
-}
-
-void Renderer::TextureSetDeleted()
-{
-  mTextureSet = nullptr;
-
-  mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
-
-  UpdateTextureSet();
-}
-
 void Renderer::ConnectionsChanged(PropertyOwner& object)
 {
   // One of our child objects has changed it's connections. Ensure the uniform
index 335e125..7fc994f 100644 (file)
@@ -54,6 +54,7 @@ class Geometry;
 
 class Renderer : public PropertyOwner,
                  public UniformMapDataProvider,
+                 public RenderDataProvider,
                  public UniformMap::Observer,
                  public ConnectionChangePropagator::Observer
 {
@@ -87,26 +88,31 @@ public:
    */
   void SetTextures(TextureSet* textureSet);
 
-  /**
-   * Returns current texture set object
-   * @return Pointer to the texture set
-   */
-  const TextureSet* GetTextures() const
+  const SceneGraph::TextureSet* GetTextureSet() const
   {
     return mTextureSet;
   }
 
   /**
+   * @copydoc RenderDataProvider::GetTextures()
+   */
+  const Vector<Render::Texture*>* GetTextures() const override;
+
+  /**
+   * @copydoc RenderDataProvider::GetSamplers()
+   */
+  const Vector<Render::Sampler*>* GetSamplers() const override;
+
+  /**
    * Set the shader for the renderer
    * @param[in] shader The shader this renderer will use
    */
   void SetShader(Shader* shader);
 
   /**
-   * Get the shader used by this renderer
-   * @return the shader this renderer uses
+   * @copydoc RenderDataProvider::GetShader()
    */
-  const Shader& GetShader() const
+  const Shader& GetShader() const override
   {
     return *mShader;
   }
@@ -314,11 +320,9 @@ public:
   void BakeOpacity(BufferIndex updateBufferIndex, float opacity);
 
   /**
-   * Gets the opacity
-   * @param[in] bufferIndex The buffer to read from.
-   * @return The opacity
+   * @copydoc RenderDataProvider::GetOpacity()
    */
-  float GetOpacity(BufferIndex updateBufferIndex) const;
+  float GetOpacity(BufferIndex updateBufferIndex) const override;
 
   /**
    * Sets the rendering behavior
@@ -354,16 +358,6 @@ public:
   OpacityType GetOpacityType(BufferIndex updateBufferIndex, const Node& node) const;
 
   /**
-   * Called by the TextureSet to notify to the renderer that it has changed
-   */
-  void TextureSetChanged();
-
-  /**
-   * Called by the TextureSet to notify to the renderer that it is about to be deleted
-   */
-  void TextureSetDeleted();
-
-  /**
    * Connect the object to the scene graph
    *
    * @param[in] sceneController The scene controller - used for sending messages to render thread
@@ -378,6 +372,14 @@ public:
    */
   void DisconnectFromSceneGraph(SceneController& sceneController, BufferIndex bufferIndex);
 
+  /**
+   * @copydoc RenderDataProvider::GetUniformMapDataProvider()
+   */
+  const UniformMapDataProvider& GetUniformMapDataProvider() const override
+  {
+    return *this;
+  };
+
 public: // Implementation of ConnectionChangePropagator
   /**
    * @copydoc ConnectionChangePropagator::AddObserver
@@ -439,21 +441,15 @@ private:
    */
   Renderer();
 
-  /**
-   * Update texture set to the render data provider
-   */
-  void UpdateTextureSet();
-
 private:
   CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
 
-  SceneController*      mSceneController;    ///< Used for initializing renderers
-  Render::Renderer*     mRenderer;           ///< Raw pointer to the renderer (that's owned by RenderManager)
-  TextureSet*           mTextureSet;         ///< The texture set this renderer uses. (Not owned)
-  Render::Geometry*     mGeometry;           ///< The geometry this renderer uses. (Not owned)
-  Shader*               mShader;             ///< The shader this renderer uses. (Not owned)
-  RenderDataProvider*   mRenderDataProvider; ///< The render data provider
-  OwnerPointer<Vector4> mBlendColor;         ///< The blend color for blending operation
+  SceneController*      mSceneController; ///< Used for initializing renderers
+  Render::Renderer*     mRenderer;        ///< Raw pointer to the renderer (that's owned by RenderManager)
+  TextureSet*           mTextureSet;      ///< The texture set this renderer uses. (Not owned)
+  Render::Geometry*     mGeometry;        ///< The geometry this renderer uses. (Not owned)
+  Shader*               mShader;          ///< The shader this renderer uses. (Not owned)
+  OwnerPointer<Vector4> mBlendColor;      ///< The blend color for blending operation
 
   Dali::Internal::Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options
 
index 876b1da..0fa96f0 100644 (file)
@@ -42,17 +42,12 @@ TextureSet* TextureSet::New()
 
 TextureSet::TextureSet()
 : mSamplers(),
-  mRenderers(),
   mHasAlpha(false)
 {
 }
 
 TextureSet::~TextureSet()
 {
-  for(auto&& renderer : mRenderers)
-  {
-    renderer->TextureSetDeleted();
-  }
 }
 
 void TextureSet::operator delete(void* ptr)
@@ -73,7 +68,6 @@ void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
   }
 
   mSamplers[index] = sampler;
-  NotifyChangeToRenderers();
 }
 
 void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
@@ -106,8 +100,6 @@ void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
   {
     mHasAlpha |= texture->HasAlphaChannel();
   }
-
-  NotifyChangeToRenderers();
 }
 
 bool TextureSet::HasAlpha() const
@@ -115,40 +107,6 @@ bool TextureSet::HasAlpha() const
   return mHasAlpha;
 }
 
-void TextureSet::AddObserver(Renderer* renderer)
-{
-  for(auto&& element : mRenderers)
-  {
-    if(element == renderer)
-    {
-      //Renderer already in the list
-      return;
-    }
-  }
-
-  mRenderers.PushBack(renderer);
-}
-
-void TextureSet::RemoveObserver(Renderer* renderer)
-{
-  for(auto &&iter = mRenderers.Begin(), end = mRenderers.End(); iter != end; ++iter)
-  {
-    if(*iter == renderer)
-    {
-      mRenderers.Remove(iter);
-      return;
-    }
-  }
-}
-
-void TextureSet::NotifyChangeToRenderers()
-{
-  for(auto&& element : mRenderers)
-  {
-    element->TextureSetChanged();
-  }
-}
-
 } // namespace SceneGraph
 
 } // namespace Internal
index 38ff4bb..683296a 100644 (file)
@@ -76,47 +76,19 @@ public:
   bool HasAlpha() const;
 
   /**
-   * Adds a renderer to the Renderers list of the texture set.
-   * Renderers using the TextureSet get a notification when the texture set changes
-   *
-   * @param[in] renderer The renderer using the TextureSet
+   * Accessor for textures (used by RenderDataProvider impl)
    */
-  void AddObserver(Renderer* renderer);
-
-  /**
-   * Removes a renderer from the TextureSet renderers list
-   *
-   * @param[in] renderer The renderer no longer using the TextureSet
-   */
-  void RemoveObserver(Renderer* renderer);
-
-  /**
-   * Get the sampler of a texture in the TextureSet
-   * @param[in] index The index of the texture in the textures array
-   * @return the sampler used by the texture
-   */
-  Render::Sampler* GetTextureSampler(uint32_t index)
-  {
-    return mSamplers[index];
-  }
-
-  /**
-   * Get the number of Textures in the texture set
-   * @return The number of Textures
-   */
-  uint32_t GetTextureCount()
+  const Vector<Render::Texture*>& GetTextures()
   {
-    return static_cast<uint32_t>(mTextures.Size());
+    return mTextures;
   }
 
   /**
-   * Get the pointer to  a Texture in the TextureSet
-   * @param[in] index The index of the texture in the textures array
-   * @return the pointer to the Texture in that position
+   * Accessor for samplers (used by RenderDataProvider impl)
    */
-  Render::Texture* GetTexture(uint32_t index)
+  const Vector<Render::Sampler*>& GetSamplers()
   {
-    return mTextures[index];
+    return mSamplers;
   }
 
 private:
@@ -125,17 +97,10 @@ private:
    */
   TextureSet();
 
-  /**
-   * Helper method to notify the renderers observing the TextureSet
-   * that the TextureSet has changed
-   */
-  void NotifyChangeToRenderers();
-
-private:                               // Data
-  Vector<Render::Sampler*> mSamplers;  ///< List of samplers used by each texture. Not owned
-  Vector<Render::Texture*> mTextures;  ///< List of Textures. Not owned
-  Vector<Renderer*>        mRenderers; ///< List of renderers using the TextureSet
-  bool                     mHasAlpha;  ///< if any of the textures has an alpha channel
+private:                              // Data
+  Vector<Render::Sampler*> mSamplers; ///< List of samplers used by each texture. Not owned
+  Vector<Render::Texture*> mTextures; ///< List of Textures. Not owned
+  bool                     mHasAlpha; ///< if any of the textures has an alpha channel
 };
 
 inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Texture* texture)