Merge "Reduce Render::Renderer size" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.cpp
index 80dbc6f..db30a4e 100644 (file)
@@ -22,6 +22,7 @@
 #include <dali/graphics-api/graphics-types.h>
 #include <dali/integration-api/debug.h>
 #include <dali/internal/common/image-sampler.h>
+#include <dali/internal/common/matrix-utils.h>
 #include <dali/internal/event/rendering/texture-impl.h>
 #include <dali/internal/render/common/render-instruction.h>
 #include <dali/internal/render/data-providers/node-data-provider.h>
@@ -185,8 +186,7 @@ Renderer::Renderer(SceneGraph::RenderDataProvider* dataProvider,
   mDepthWriteMode(depthWriteMode),
   mDepthTestMode(depthTestMode),
   mPremultipliedAlphaEnabled(preMultipliedAlphaEnabled),
-  mShaderChanged(false),
-  mUpdated(true)
+  mShaderChanged(false)
 {
   if(blendingBitmask != 0u)
   {
@@ -210,7 +210,6 @@ Renderer::~Renderer() = default;
 void Renderer::SetGeometry(Render::Geometry* geometry)
 {
   mGeometry = geometry;
-  mUpdated  = true;
 }
 void Renderer::SetDrawCommands(Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size)
 {
@@ -263,49 +262,41 @@ void Renderer::BindTextures(Graphics::CommandBuffer& commandBuffer, Vector<Graph
 void Renderer::SetFaceCullingMode(FaceCullingMode::Type mode)
 {
   mFaceCullingMode = mode;
-  mUpdated         = true;
 }
 
 void Renderer::SetBlendingBitMask(uint32_t bitmask)
 {
   mBlendingOptions.SetBitmask(bitmask);
-  mUpdated = true;
 }
 
 void Renderer::SetBlendColor(const Vector4& color)
 {
   mBlendingOptions.SetBlendColor(color);
-  mUpdated = true;
 }
 
 void Renderer::SetIndexedDrawFirstElement(uint32_t firstElement)
 {
   mIndexedDrawFirstElement = firstElement;
-  mUpdated                 = true;
 }
 
 void Renderer::SetIndexedDrawElementsCount(uint32_t elementsCount)
 {
   mIndexedDrawElementsCount = elementsCount;
-  mUpdated                  = true;
 }
 
 void Renderer::EnablePreMultipliedAlpha(bool enable)
 {
   mPremultipliedAlphaEnabled = enable;
-  mUpdated                   = true;
 }
 
 void Renderer::SetDepthWriteMode(DepthWriteMode::Type depthWriteMode)
 {
   mDepthWriteMode = depthWriteMode;
-  mUpdated        = true;
 }
 
 void Renderer::SetDepthTestMode(DepthTestMode::Type depthTestMode)
 {
   mDepthTestMode = depthTestMode;
-  mUpdated       = true;
 }
 
 DepthWriteMode::Type Renderer::GetDepthWriteMode() const
@@ -321,7 +312,6 @@ DepthTestMode::Type Renderer::GetDepthTestMode() const
 void Renderer::SetDepthFunction(DepthFunction::Type depthFunction)
 {
   mDepthFunction = depthFunction;
-  mUpdated       = true;
 }
 
 DepthFunction::Type Renderer::GetDepthFunction() const
@@ -332,7 +322,6 @@ DepthFunction::Type Renderer::GetDepthFunction() const
 void Renderer::SetRenderMode(RenderMode::Type renderMode)
 {
   mStencilParameters.renderMode = renderMode;
-  mUpdated                      = true;
 }
 
 RenderMode::Type Renderer::GetRenderMode() const
@@ -343,7 +332,6 @@ RenderMode::Type Renderer::GetRenderMode() const
 void Renderer::SetStencilFunction(StencilFunction::Type stencilFunction)
 {
   mStencilParameters.stencilFunction = stencilFunction;
-  mUpdated                           = true;
 }
 
 StencilFunction::Type Renderer::GetStencilFunction() const
@@ -354,7 +342,6 @@ StencilFunction::Type Renderer::GetStencilFunction() const
 void Renderer::SetStencilFunctionMask(int stencilFunctionMask)
 {
   mStencilParameters.stencilFunctionMask = stencilFunctionMask;
-  mUpdated                               = true;
 }
 
 int Renderer::GetStencilFunctionMask() const
@@ -365,7 +352,6 @@ int Renderer::GetStencilFunctionMask() const
 void Renderer::SetStencilFunctionReference(int stencilFunctionReference)
 {
   mStencilParameters.stencilFunctionReference = stencilFunctionReference;
-  mUpdated                                    = true;
 }
 
 int Renderer::GetStencilFunctionReference() const
@@ -376,7 +362,6 @@ int Renderer::GetStencilFunctionReference() const
 void Renderer::SetStencilMask(int stencilMask)
 {
   mStencilParameters.stencilMask = stencilMask;
-  mUpdated                       = true;
 }
 
 int Renderer::GetStencilMask() const
@@ -387,7 +372,6 @@ int Renderer::GetStencilMask() const
 void Renderer::SetStencilOperationOnFail(StencilOperation::Type stencilOperationOnFail)
 {
   mStencilParameters.stencilOperationOnFail = stencilOperationOnFail;
-  mUpdated                                  = true;
 }
 
 StencilOperation::Type Renderer::GetStencilOperationOnFail() const
@@ -398,7 +382,6 @@ StencilOperation::Type Renderer::GetStencilOperationOnFail() const
 void Renderer::SetStencilOperationOnZFail(StencilOperation::Type stencilOperationOnZFail)
 {
   mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail;
-  mUpdated                                   = true;
 }
 
 StencilOperation::Type Renderer::GetStencilOperationOnZFail() const
@@ -409,7 +392,6 @@ StencilOperation::Type Renderer::GetStencilOperationOnZFail() const
 void Renderer::SetStencilOperationOnZPass(StencilOperation::Type stencilOperationOnZPass)
 {
   mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass;
-  mUpdated                                   = true;
 }
 
 StencilOperation::Type Renderer::GetStencilOperationOnZPass() const
@@ -444,13 +426,18 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
   // Check if there is render callback
   if(mRenderCallback)
   {
+    if(!mRenderCallbackInput)
+    {
+      mRenderCallbackInput = std::unique_ptr<RenderCallbackInput>(new RenderCallbackInput);
+    }
+
     Graphics::DrawNativeInfo info{};
     info.api      = Graphics::DrawNativeAPI::GLES;
     info.callback = &static_cast<Dali::CallbackBase&>(*mRenderCallback);
-    info.userData = &mRenderCallbackInput;
+    info.userData = mRenderCallbackInput.get();
 
     // Set storage for the context to be used
-    info.glesNativeInfo.eglSharedContextStoragePointer = &mRenderCallbackInput.eglContext;
+    info.glesNativeInfo.eglSharedContextStoragePointer = &mRenderCallbackInput->eglContext;
     info.reserved                                      = nullptr;
 
     auto& textureResources = mRenderCallback->GetTextureResources();
@@ -458,27 +445,27 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
     if(!textureResources.empty())
     {
       mRenderCallbackTextureBindings.clear();
-      mRenderCallbackInput.textureBindings.resize(textureResources.size());
+      mRenderCallbackInput->textureBindings.resize(textureResources.size());
       auto i = 0u;
       for(auto& texture : textureResources)
       {
         auto& textureImpl     = GetImplementation(texture);
         auto  graphicsTexture = textureImpl.GetRenderObject()->GetGraphicsObject();
 
-        const auto& properties = mGraphicsController->GetTextureProperties(*graphicsTexture);
+        auto properties = mGraphicsController->GetTextureProperties(*graphicsTexture);
 
         mRenderCallbackTextureBindings.emplace_back(graphicsTexture);
-        mRenderCallbackInput.textureBindings[i] = properties.nativeHandle;
+        mRenderCallbackInput->textureBindings[i++] = properties.nativeHandle;
       }
       info.textureCount = mRenderCallbackTextureBindings.size();
       info.textureList  = mRenderCallbackTextureBindings.data();
     }
 
     // pass render callback input
-    mRenderCallbackInput.size       = size;
-    mRenderCallbackInput.projection = projectionMatrix;
+    mRenderCallbackInput->size       = size;
+    mRenderCallbackInput->projection = projectionMatrix;
 
-    Matrix::Multiply(mRenderCallbackInput.mvp, modelViewMatrix, projectionMatrix);
+    MatrixUtils::Multiply(mRenderCallbackInput->mvp, modelViewMatrix, projectionMatrix);
 
     // submit draw
     commandBuffer.DrawNative(&info);
@@ -555,7 +542,7 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
 
   BindTextures(commandBuffer, boundTextures);
 
-  int nodeIndex = BuildUniformIndexMap(bufferIndex, node, size, *program);
+  std::size_t nodeIndex = BuildUniformIndexMap(bufferIndex, node, size, *program);
 
   WriteUniformBuffer(bufferIndex, commandBuffer, program, instruction, node, modelMatrix, modelViewMatrix, viewMatrix, projectionMatrix, size, nodeIndex);
 
@@ -574,11 +561,10 @@ bool Renderer::Render(Graphics::CommandBuffer&                             comma
     }
   }
 
-  mUpdated = false;
   return drawn;
 }
 
-int Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program)
+std::size_t Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program)
 {
   // Check if the map has changed
   DALI_ASSERT_DEBUG(mRenderDataProvider && "No Uniform map data provider available");
@@ -601,7 +587,7 @@ int Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::No
 
   auto iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [nodePtr](RenderItemLookup& element) { return element.node == nodePtr; });
 
-  int renderItemMapIndex;
+  std::size_t renderItemMapIndex;
   if(iter == mNodeIndexMap.end())
   {
     renderItemMapIndex = mUniformIndexMaps.size();
@@ -692,7 +678,7 @@ void Renderer::WriteUniformBuffer(
   const Matrix&                        viewMatrix,
   const Matrix&                        projectionMatrix,
   const Vector3&                       size,
-  int                                  nodeIndex)
+  std::size_t                          nodeIndex)
 {
   // Create the UBO
   uint32_t uboOffset{0u};
@@ -731,7 +717,7 @@ void Renderer::WriteUniformBuffer(
     if(mvpUniformInfo && !mvpUniformInfo->name.empty())
     {
       Matrix modelViewProjectionMatrix(false);
-      Matrix::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix);
+      MatrixUtils::Multiply(modelViewProjectionMatrix, modelViewMatrix, projectionMatrix);
       WriteDefaultUniform(mvpUniformInfo, *uboView, modelViewProjectionMatrix);
     }
 
@@ -796,7 +782,7 @@ void Renderer::FillUniformBuffer(Program&                                      p
                                  std::vector<Graphics::UniformBufferBinding>*& outBindings,
                                  uint32_t&                                     offset,
                                  BufferIndex                                   updateBufferIndex,
-                                 int                                           nodeIndex)
+                                 std::size_t                                   nodeIndex)
 {
   auto& reflection = mGraphicsController->GetProgramReflection(program.GetGraphicsProgram());
   auto  uboCount   = reflection.GetUniformBlockCount();
@@ -876,15 +862,9 @@ void Renderer::SetShaderChanged(bool value)
   mShaderChanged = value;
 }
 
-bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node)
+bool Renderer::Updated(BufferIndex bufferIndex)
 {
-  if(mUpdated)
-  {
-    mUpdated = false;
-    return true;
-  }
-
-  if(mRenderCallback || mShaderChanged || mGeometry->AttributesChanged())
+  if(mRenderCallback || mShaderChanged || mGeometry->AttributesChanged() || mRenderDataProvider->IsUpdated())
   {
     return true;
   }
@@ -895,48 +875,26 @@ bool Renderer::Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvid
     for(auto iter = textures->Begin(), end = textures->End(); iter < end; ++iter)
     {
       auto texture = *iter;
-      if(texture && texture->IsNativeImage())
+      if(texture && texture->Updated())
       {
         return true;
       }
     }
   }
-
-  // Hash the property values. If the values are different, then rendering is required.
-  uint64_t                      hash           = 0xc70f6907UL;
-  const SceneGraph::UniformMap& uniformMapNode = node->GetNodeUniformMap();
-  for(uint32_t i = 0u, count = uniformMapNode.Count(); i < count; ++i)
-  {
-    hash = uniformMapNode[i].propertyPtr->Hash(bufferIndex, hash);
-  }
-
-  const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMapDataProvider();
-  const SceneGraph::CollectedUniformMap&    collectedUniformMap    = uniformMapDataProvider.GetCollectedUniformMap();
-  for(uint32_t i = 0u, count = collectedUniformMap.Count(); i < count; ++i)
-  {
-    hash = collectedUniformMap.mUniformMap[i].propertyPtr->Hash(bufferIndex, hash);
-  }
-
-  if(mUniformsHash != hash)
-  {
-    mUniformsHash = hash;
-    return true;
-  }
-
   return false;
 }
 
+Vector4 Renderer::GetVisualTransformedUpdateArea(BufferIndex bufferIndex, const Vector4& originalUpdateArea) const noexcept
+{
+  return mRenderDataProvider->GetVisualTransformedUpdateArea(bufferIndex, originalUpdateArea);
+}
+
 Graphics::Pipeline& Renderer::PrepareGraphicsPipeline(
   Program&                                             program,
   const Dali::Internal::SceneGraph::RenderInstruction& instruction,
   const SceneGraph::NodeDataProvider&                  node,
   bool                                                 blend)
 {
-  if(mGeometry->AttributesChanged())
-  {
-    mUpdated = true;
-  }
-
   // Prepare query info
   PipelineCacheQueryInfo queryInfo{};
   queryInfo.program               = &program;