DirectRendering:
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.cpp
index 6677d91..3a84873 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -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/public-api/signals/render-callback.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)
@@ -88,176 +90,47 @@ 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);}
-    default:
-    {
-      return 0;
-    }
-  };
-}
-
-// Helper to get the vertex input format
-Dali::Graphics::VertexInputFormat GetPropertyVertexFormat(Property::Type propertyType)
-{
-  Dali::Graphics::VertexInputFormat type{};
-
-  switch(propertyType)
-  {
-    case Property::NONE:
-    case Property::STRING:
-    case Property::ARRAY:
-    case Property::MAP:
-    case Property::EXTENTS:   // i4?
-    case Property::RECTANGLE: // i4/f4?
-    case Property::ROTATION:
-    {
-      type = Dali::Graphics::VertexInputFormat::UNDEFINED;
-      break;
-    }
-    case Property::BOOLEAN:
-    {
-      type = Dali::Graphics::VertexInputFormat::UNDEFINED; // type = GL_BYTE; @todo new type for this?
-      break;
-    }
-    case Property::INTEGER:
-    {
-      type = Dali::Graphics::VertexInputFormat::INTEGER; // (short)
-      break;
-    }
-    case Property::FLOAT:
+    case Property::Type::BOOLEAN:
     {
-      type = Dali::Graphics::VertexInputFormat::FLOAT;
-      break;
+      return sizeof(bool);
     }
-    case Property::VECTOR2:
+    case Property::Type::FLOAT:
     {
-      type = Dali::Graphics::VertexInputFormat::FVECTOR2;
-      break;
+      return sizeof(float);
     }
-    case Property::VECTOR3:
+    case Property::Type::INTEGER:
     {
-      type = Dali::Graphics::VertexInputFormat::FVECTOR3;
-      break;
+      return sizeof(int);
     }
-    case Property::VECTOR4:
+    case Property::Type::VECTOR2:
     {
-      type = Dali::Graphics::VertexInputFormat::FVECTOR4;
-      break;
+      return sizeof(Vector2);
     }
-    case Property::MATRIX3:
-    case Property::MATRIX:
+    case Property::Type::VECTOR3:
     {
-      type = Dali::Graphics::VertexInputFormat::FLOAT;
-      break;
+      return sizeof(Vector3);
     }
-  }
-
-  return type;
-}
-
-constexpr Graphics::CullMode ConvertCullFace(Dali::FaceCullingMode::Type mode)
-{
-  switch(mode)
-  {
-    case Dali::FaceCullingMode::NONE:
+    case Property::Type::VECTOR4:
     {
-      return Graphics::CullMode::NONE;
+      return sizeof(Vector4);
     }
-    case Dali::FaceCullingMode::FRONT:
+    case Property::Type::MATRIX3:
     {
-      return Graphics::CullMode::FRONT;
+      return sizeof(Matrix3);
     }
-    case Dali::FaceCullingMode::BACK:
+    case Property::Type::MATRIX:
     {
-      return Graphics::CullMode::BACK;
+      return sizeof(Matrix);
     }
-    case Dali::FaceCullingMode::FRONT_AND_BACK:
+    default:
     {
-      return Graphics::CullMode::FRONT_AND_BACK;
+      return 0;
     }
-  }
-  return Graphics::CullMode::NONE;
-}
-
-constexpr Graphics::BlendFactor ConvertBlendFactor(BlendFactor::Type blendFactor)
-{
-  switch(blendFactor)
-  {
-    case BlendFactor::ZERO:
-      return Graphics::BlendFactor::ZERO;
-    case BlendFactor::ONE:
-      return Graphics::BlendFactor::ONE;
-    case BlendFactor::SRC_COLOR:
-      return Graphics::BlendFactor::SRC_COLOR;
-    case BlendFactor::ONE_MINUS_SRC_COLOR:
-      return Graphics::BlendFactor::ONE_MINUS_SRC_COLOR;
-    case BlendFactor::SRC_ALPHA:
-      return Graphics::BlendFactor::SRC_ALPHA;
-    case BlendFactor::ONE_MINUS_SRC_ALPHA:
-      return Graphics::BlendFactor::ONE_MINUS_SRC_ALPHA;
-    case BlendFactor::DST_ALPHA:
-      return Graphics::BlendFactor::DST_ALPHA;
-    case BlendFactor::ONE_MINUS_DST_ALPHA:
-      return Graphics::BlendFactor::ONE_MINUS_DST_ALPHA;
-    case BlendFactor::DST_COLOR:
-      return Graphics::BlendFactor::DST_COLOR;
-    case BlendFactor::ONE_MINUS_DST_COLOR:
-      return Graphics::BlendFactor::ONE_MINUS_DST_COLOR;
-    case BlendFactor::SRC_ALPHA_SATURATE:
-      return Graphics::BlendFactor::SRC_ALPHA_SATURATE;
-    case BlendFactor::CONSTANT_COLOR:
-      return Graphics::BlendFactor::CONSTANT_COLOR;
-    case BlendFactor::ONE_MINUS_CONSTANT_COLOR:
-      return Graphics::BlendFactor::ONE_MINUS_CONSTANT_COLOR;
-    case BlendFactor::CONSTANT_ALPHA:
-      return Graphics::BlendFactor::CONSTANT_ALPHA;
-    case BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
-      return Graphics::BlendFactor::ONE_MINUS_CONSTANT_ALPHA;
-  }
-  return Graphics::BlendFactor{};
-}
-
-constexpr Graphics::BlendOp ConvertBlendEquation(DevelBlendEquation::Type blendEquation)
-{
-  switch(blendEquation)
-  {
-    case DevelBlendEquation::ADD:
-      return Graphics::BlendOp::ADD;
-    case DevelBlendEquation::SUBTRACT:
-      return Graphics::BlendOp::SUBTRACT;
-    case DevelBlendEquation::REVERSE_SUBTRACT:
-      return Graphics::BlendOp::REVERSE_SUBTRACT;
-    case DevelBlendEquation::COLOR:
-    case DevelBlendEquation::COLOR_BURN:
-    case DevelBlendEquation::COLOR_DODGE:
-    case DevelBlendEquation::DARKEN:
-    case DevelBlendEquation::DIFFERENCE:
-    case DevelBlendEquation::EXCLUSION:
-    case DevelBlendEquation::HARD_LIGHT:
-    case DevelBlendEquation::HUE:
-    case DevelBlendEquation::LIGHTEN:
-    case DevelBlendEquation::LUMINOSITY:
-    case DevelBlendEquation::MAX:
-    case DevelBlendEquation::MIN:
-    case DevelBlendEquation::MULTIPLY:
-    case DevelBlendEquation::OVERLAY:
-    case DevelBlendEquation::SATURATION:
-    case DevelBlendEquation::SCREEN:
-    case DevelBlendEquation::SOFT_LIGHT:
-      return Graphics::BlendOp{};
-  }
-  return Graphics::BlendOp{};
+  };
 }
 
 /**
@@ -303,7 +176,6 @@ Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
   mGeometry(geometry),
   mProgramCache(nullptr),
   mUniformIndexMap(),
-  mAttributeLocations(),
   mUniformsHash(),
   mStencilParameters(stencilParameters),
   mBlendingOptions(),
@@ -313,7 +185,6 @@ Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
   mFaceCullingMode(faceCullingMode),
   mDepthWriteMode(depthWriteMode),
   mDepthTestMode(depthTestMode),
-  mUpdateAttributeLocations(true),
   mPremultipliedAlphaEnabled(preMultipliedAlphaEnabled),
   mShaderChanged(false),
   mUpdated(true)
@@ -326,20 +197,21 @@ Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
   mBlendingOptions.SetBlendColor(blendColor);
 }
 
-void Renderer::Initialize(Graphics::Controller& graphicsController, ProgramCache& programCache, Render::ShaderCache& shaderCache, Render::UniformBufferManager& uniformBufferManager)
+void Renderer::Initialize(Graphics::Controller& graphicsController, ProgramCache& programCache, Render::ShaderCache& shaderCache, Render::UniformBufferManager& uniformBufferManager, Render::PipelineCache& pipelineCache)
 {
   mGraphicsController   = &graphicsController;
   mProgramCache         = &programCache;
   mShaderCache          = &shaderCache;
   mUniformBufferManager = &uniformBufferManager;
+  mPipelineCache        = &pipelineCache;
 }
 
 Renderer::~Renderer() = default;
 
 void Renderer::SetGeometry(Render::Geometry* geometry)
 {
-  mGeometry                 = geometry;
-  mUpdateAttributeLocations = true;
+  mGeometry = geometry;
+  mUpdate = true;
 }
 void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)
 {
@@ -351,26 +223,35 @@ 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())
+    const std::uint32_t texturesCount(static_cast<std::uint32_t>(textures->Count()));
+    textureBindings.reserve(texturesCount);
+
+    for(uint32_t i = 0; i < texturesCount; ++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())
+      {
+        Graphics::Texture* graphicsTexture = (*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(graphicsTexture);
+        const Graphics::TextureBinding textureBinding{graphicsTexture, graphicsSampler, textureUnit};
+        textureBindings.push_back(textureBinding);
 
-      ++textureUnit;
+        ++textureUnit;
+      }
     }
   }
 
@@ -561,6 +442,25 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
     return false;
   }
 
+  // Check if there is render callback
+  if(mRenderCallback)
+  {
+    Graphics::DrawNativeInfo info{};
+    info.api      = Graphics::DrawNativeAPI::GLES;
+    info.callback = &static_cast<Dali::CallbackBase&>(*mRenderCallback);
+    info.userData = &mRenderCallbackInput;
+    info.reserved = nullptr;
+
+    // pass render callback input
+    mRenderCallbackInput.size       = size;
+    mRenderCallbackInput.projection = projectionMatrix;
+    Matrix::Multiply(mRenderCallbackInput.mvp, modelViewMatrix, projectionMatrix);
+
+    // submit draw
+    commandBuffer.DrawNative(&info);
+    return true;
+  }
+
   // Prepare commands
   std::vector<DevelRenderer::DrawCommand*> commands;
   for(auto& cmd : mDrawCommands)
@@ -584,42 +484,46 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
   }
 
   // Create Program
-  ShaderDataPtr            shaderData   = mRenderDataProvider->GetShader().GetShaderData();
-  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(
-    fragShader,
-    Graphics::PipelineStage::FRAGMENT_SHADER,
-    shaderData->GetSourceMode());
-
-  std::vector<Graphics::ShaderState> shaderStates{
-    Graphics::ShaderState()
-      .SetShader(vertexShader)
-      .SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER),
-    Graphics::ShaderState()
-      .SetShader(fragmentShader)
-      .SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER)};
-
-  auto createInfo = Graphics::ProgramCreateInfo();
-  createInfo.SetShaderState(shaderStates);
-
-  auto     graphicsProgram = mGraphicsController->CreateProgram(createInfo, nullptr);
-  Program* program         = Program::New(*mProgramCache,
-                                  shaderData,
-                                  *mGraphicsController,
-                                  std::move(graphicsProgram));
+  ShaderDataPtr shaderData = mRenderDataProvider->GetShader().GetShaderData();
 
+  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(
+      vertShader,
+      Graphics::PipelineStage::VERTEX_SHADER,
+      shaderData->GetSourceMode());
+
+    Dali::Graphics::Shader& fragmentShader = mShaderCache->GetShader(
+      fragShader,
+      Graphics::PipelineStage::FRAGMENT_SHADER,
+      shaderData->GetSourceMode());
+
+    std::vector<Graphics::ShaderState> shaderStates{
+      Graphics::ShaderState()
+        .SetShader(vertexShader)
+        .SetPipelineStage(Graphics::PipelineStage::VERTEX_SHADER),
+      Graphics::ShaderState()
+        .SetShader(fragmentShader)
+        .SetPipelineStage(Graphics::PipelineStage::FRAGMENT_SHADER)};
+
+    auto createInfo = Graphics::ProgramCreateInfo();
+    createInfo.SetShaderState(shaderStates);
+    auto graphicsProgram = mGraphicsController->CreateProgram(createInfo, nullptr);
+    program->SetGraphicsProgram(std::move(graphicsProgram));
+  }
+
   // Prepare the graphics pipeline. This may either re-use an existing pipeline or create a new one.
   auto& pipeline = PrepareGraphicsPipeline(*program, instruction, node, blend);
 
@@ -655,7 +559,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) ||
@@ -712,10 +616,6 @@ void Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::N
 
     mUniformIndexMap.Resize(mapIndex);
   }
-
-  // @todo Temporary workaround to reduce workload each frame. Find a better way.
-  auto& sceneGraphRenderer = const_cast<SceneGraph::Renderer&>(static_cast<const SceneGraph::Renderer&>(uniformMapDataProvider));
-  sceneGraphRenderer.AgeUniformMap();
 }
 
 void Renderer::WriteUniformBuffer(
@@ -733,7 +633,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;
 
@@ -781,18 +681,19 @@ void Renderer::WriteUniformBuffer(
       WriteDefaultUniform(normalUniformInfo, *uboView, normalMatrix);
     }
 
-    Vector4        finalColor;
-    const Vector4& color = node.GetRenderColor(bufferIndex);
+    Vector4        finalColor;                               ///< Applied renderer's opacity color
+    const Vector4& color = node.GetRenderColor(bufferIndex); ///< Actor's original color
     if(mPremultipliedAlphaEnabled)
     {
-      float alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
-      finalColor  = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
+      const float& alpha = color.a * mRenderDataProvider->GetOpacity(bufferIndex);
+      finalColor         = Vector4(color.r * alpha, color.g * alpha, color.b * alpha, alpha);
     }
     else
     {
       finalColor = Vector4(color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity(bufferIndex));
     }
     WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::COLOR), *uboView, finalColor);
+    WriteDefaultUniform(program->GetDefaultUniform(Program::DefaultUniformIndex::ACTOR_COLOR), *uboView, color);
 
     // Write uniforms from the uniform map
     FillUniformBuffer(*program, instruction, *uboView, bindings, uboOffset, bufferIndex);
@@ -851,21 +752,42 @@ void Renderer::FillUniformBuffer(Program&                                      p
         iter != end;
         ++iter)
     {
-      // @todo This means parsing the uniform string every frame. Instead, store the array index if present.
-      int arrayIndex = (*iter).arrayIndex;
+      auto& uniform    = *iter;
+      int   arrayIndex = uniform.arrayIndex;
+
+      if(!uniform.uniformFunc)
+      {
+        auto uniformInfo  = Graphics::UniformInfo{};
+        auto uniformFound = program.GetUniform(uniform.uniformName.GetCString(),
+                                               uniform.uniformNameHashNoArray ? uniform.uniformNameHashNoArray
+                                                                              : uniform.uniformNameHash,
+                                               uniformInfo);
+
+        uniform.uniformOffset   = uniformInfo.offset;
+        uniform.uniformLocation = uniformInfo.location;
+
+        if(uniformFound)
+        {
+          auto       dst      = ubo.GetOffset() + uniformInfo.offset;
+          const auto typeSize = GetPropertyValueSizeForUniform((*iter).propertyValue->GetType());
+          const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
+          const auto func     = GetPropertyValueGetter((*iter).propertyValue->GetType());
 
-      auto uniformInfo  = Graphics::UniformInfo{};
-      auto uniformFound = program.GetUniform((*iter).uniformName.GetCString(),
-                                             (*iter).uniformNameHashNoArray ? (*iter).uniformNameHashNoArray
-                                                                            : (*iter).uniformNameHash,
-                                             uniformInfo);
+          ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
+                    typeSize,
+                    dest);
 
-      if(uniformFound)
+          uniform.uniformSize = typeSize;
+          uniform.uniformFunc = func;
+        }
+      }
+      else
       {
-        auto dst = ubo.GetOffset() + uniformInfo.offset;
-        const auto typeSize = GetPropertyValueSizeForUniform( (*iter).propertyValue->GetType() );
-        const auto dest = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
-        const auto func = GetPropertyValueGetter((*iter).propertyValue->GetType());
+        auto       dst      = ubo.GetOffset() + uniform.uniformOffset;
+        const auto typeSize = uniform.uniformSize;
+        const auto dest     = dst + static_cast<uint32_t>(typeSize) * arrayIndex;
+        const auto func     = uniform.uniformFunc;
+
         ubo.Write(&((*iter).propertyValue->*func)(updateBufferIndex),
                   typeSize,
                   dest);
@@ -898,16 +820,21 @@ bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvid
     return true;
   }
 
-  if(mShaderChanged || mUpdateAttributeLocations || mGeometry->AttributesChanged())
+  if(mRenderCallback || mShaderChanged || mGeometry->AttributesChanged())
   {
     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;
+      }
     }
   }
 
@@ -918,7 +845,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)
   {
@@ -940,193 +867,30 @@ Graphics::Pipeline& Renderer::PrepareGraphicsPipeline(
   const SceneGraph::NodeDataProvider&                  node,
   bool                                                 blend)
 {
-  Graphics::InputAssemblyState inputAssemblyState{};
-  Graphics::VertexInputState   vertexInputState{};
-  Graphics::ProgramState       programState{};
-  uint32_t                     bindingIndex{0u};
-
-  if(mUpdateAttributeLocations || mGeometry->AttributesChanged())
+  if(mGeometry->AttributesChanged())
   {
-    mAttributeLocations.Clear();
-    mUpdateAttributeLocations = true;
-  }
-
-  auto& reflection = mGraphicsController->GetProgramReflection(program.GetGraphicsProgram());
-
-  /**
-   * Bind Attributes
-   */
-  uint32_t base = 0;
-  for(auto&& vertexBuffer : mGeometry->GetVertexBuffers())
-  {
-    const VertexBuffer::Format& vertexFormat = *vertexBuffer->GetFormat();
-
-    vertexInputState.bufferBindings.emplace_back(vertexFormat.size, // stride
-                                                 Graphics::VertexInputRate::PER_VERTEX);
-
-    const uint32_t attributeCount = vertexBuffer->GetAttributeCount();
-    for(uint32_t i = 0; i < attributeCount; ++i)
-    {
-      if(mUpdateAttributeLocations)
-      {
-        auto    attributeName = vertexBuffer->GetAttributeName(i);
-        int32_t pLocation     = reflection.GetVertexAttributeLocation(std::string(attributeName.GetStringView()));
-        if(-1 == pLocation)
-        {
-          DALI_LOG_WARNING("Attribute not found in the shader: %s\n", attributeName.GetCString());
-        }
-        mAttributeLocations.PushBack(pLocation);
-      }
-
-      auto location = static_cast<uint32_t>(mAttributeLocations[base + i]);
-
-      vertexInputState.attributes.emplace_back(location,
-                                               bindingIndex,
-                                               vertexFormat.components[i].offset,
-                                               GetPropertyVertexFormat(vertexFormat.components[i].type));
-    }
-    base += attributeCount;
-    ++bindingIndex;
+    mUpdated = true;
   }
-  mUpdateAttributeLocations = false;
 
-  // Get the topology
-  inputAssemblyState.SetTopology(mGeometry->GetTopology());
+  // Prepare query info
+  PipelineCacheQueryInfo queryInfo{};
+  queryInfo.program               = &program;
+  queryInfo.renderer              = this;
+  queryInfo.geometry              = mGeometry;
+  queryInfo.blendingEnabled       = blend;
+  queryInfo.blendingOptions       = &mBlendingOptions;
+  queryInfo.alphaPremultiplied    = mPremultipliedAlphaEnabled;
+  queryInfo.cameraUsingReflection = instruction.GetCamera()->GetReflectionUsed();
 
-  // Get the program
-  programState.SetProgram(program.GetGraphicsProgram());
+  auto pipelineResult = mPipelineCache->GetPipeline(queryInfo, true);
 
-  Graphics::RasterizationState rasterizationState{};
-
-  //Set cull face  mode
-  const Dali::Internal::SceneGraph::Camera* cam = instruction.GetCamera();
-  if(cam->GetReflectionUsed())
-  {
-    auto adjFaceCullingMode = mFaceCullingMode;
-    switch(mFaceCullingMode)
-    {
-      case FaceCullingMode::Type::FRONT:
-      {
-        adjFaceCullingMode = FaceCullingMode::Type::BACK;
-        break;
-      }
-      case FaceCullingMode::Type::BACK:
-      {
-        adjFaceCullingMode = FaceCullingMode::Type::FRONT;
-        break;
-      }
-      default:
-      {
-        // nothing to do, leave culling as it is
-      }
-    }
-    rasterizationState.SetCullMode(ConvertCullFace(adjFaceCullingMode));
-  }
-  else
-  {
-    rasterizationState.SetCullMode(ConvertCullFace(mFaceCullingMode));
-  }
-
-  rasterizationState.SetFrontFace(Graphics::FrontFace::COUNTER_CLOCKWISE);
-
-  /**
-   * Set Polygon mode
-   */
-  switch(mGeometry->GetTopology())
-  {
-    case Graphics::PrimitiveTopology::TRIANGLE_LIST:
-    case Graphics::PrimitiveTopology::TRIANGLE_STRIP:
-    case Graphics::PrimitiveTopology::TRIANGLE_FAN:
-      rasterizationState.SetPolygonMode(Graphics::PolygonMode::FILL);
-      break;
-    case Graphics::PrimitiveTopology::LINE_LIST:
-    case Graphics::PrimitiveTopology::LINE_LOOP:
-    case Graphics::PrimitiveTopology::LINE_STRIP:
-      rasterizationState.SetPolygonMode(Graphics::PolygonMode::LINE);
-      break;
-    case Graphics::PrimitiveTopology::POINT_LIST:
-      rasterizationState.SetPolygonMode(Graphics::PolygonMode::POINT);
-      break;
-  }
-
-  // @todo Add blend barrier to the Graphics API if we are using advanced
-  // blending options. Command?
-
-  Graphics::ColorBlendState colorBlendState{};
-  colorBlendState.SetBlendEnable(false);
-
-  if(blend)
-  {
-    colorBlendState.SetBlendEnable(true);
-
-    Graphics::BlendOp rgbOp   = ConvertBlendEquation(mBlendingOptions.GetBlendEquationRgb());
-    Graphics::BlendOp alphaOp = ConvertBlendEquation(mBlendingOptions.GetBlendEquationRgb());
-    if(mBlendingOptions.IsAdvancedBlendEquationApplied() && mPremultipliedAlphaEnabled)
-    {
-      if(rgbOp != alphaOp)
-      {
-        DALI_LOG_ERROR("Advanced Blend Equation MUST be applied by using BlendEquation.\n");
-        alphaOp = rgbOp;
-      }
-    }
-
-    colorBlendState
-      .SetSrcColorBlendFactor(ConvertBlendFactor(mBlendingOptions.GetBlendSrcFactorRgb()))
-      .SetSrcAlphaBlendFactor(ConvertBlendFactor(mBlendingOptions.GetBlendSrcFactorAlpha()))
-      .SetDstColorBlendFactor(ConvertBlendFactor(mBlendingOptions.GetBlendDestFactorRgb()))
-      .SetDstAlphaBlendFactor(ConvertBlendFactor(mBlendingOptions.GetBlendDestFactorAlpha()))
-      .SetColorBlendOp(rgbOp)
-      .SetAlphaBlendOp(alphaOp);
-
-    // Blend color is optional and rarely used
-    auto* blendColor = const_cast<Vector4*>(mBlendingOptions.GetBlendColor());
-    if(blendColor)
-    {
-      colorBlendState.SetBlendConstants(blendColor->AsFloat());
-    }
-  }
-
-  mUpdated = true;
-
-  // Create the pipeline
-  Graphics::PipelineCreateInfo createInfo;
-  createInfo
-    .SetInputAssemblyState(&inputAssemblyState)
-    .SetVertexInputState(&vertexInputState)
-    .SetRasterizationState(&rasterizationState)
-    .SetColorBlendState(&colorBlendState)
-    .SetProgramState(&programState);
-
-  // Store a pipeline per renderer per render (renderer can be owned by multiple nodes,
-  // and re-drawn in multiple instructions).
-  // @todo This is only needed because ColorBlend state can change. Fixme!
-  // This is ameliorated by the fact that implementation caches pipelines, and we're only storing
-  // handles.
-  auto            hash           = HashedPipeline::GetHash(&node, &instruction, blend);
-  HashedPipeline* hashedPipeline = nullptr;
-  for(auto& element : mGraphicsPipelines)
-  {
-    if(element.mHash == hash)
-    {
-      hashedPipeline = &element;
-      break;
-    }
-  }
+  // should be never null?
+  return *pipelineResult.pipeline;
+}
 
-  if(hashedPipeline != nullptr)
-  {
-    hashedPipeline->mGraphicsPipeline = mGraphicsController->CreatePipeline(
-      createInfo,
-      std::move(hashedPipeline->mGraphicsPipeline));
-  }
-  else
-  {
-    mGraphicsPipelines.emplace_back();
-    mGraphicsPipelines.back().mHash             = hash;
-    mGraphicsPipelines.back().mGraphicsPipeline = mGraphicsController->CreatePipeline(createInfo, nullptr);
-    hashedPipeline                              = &mGraphicsPipelines.back();
-  }
-  return *hashedPipeline->mGraphicsPipeline.get();
+void Renderer::SetRenderCallback(RenderCallback* callback)
+{
+  mRenderCallback = callback;
 }
 
 } // namespace Render