Fixed SVACE errors in Test Graphics
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-command-buffer.cpp
index a0dee4a..9f86b99 100644 (file)
 
 namespace Dali
 {
-TestGraphicsCommandBuffer::TestGraphicsCommandBuffer(TraceCallStack& callstack, TestGlAbstraction& glAbstraction)
-: mCallStack(callstack),
-  mGlAbstraction(glAbstraction)
-{
-}
-
-void TestGraphicsCommandBuffer::BindVertexBuffers(uint32_t                             firstBinding,
-                                                  std::vector<const Graphics::Buffer*> buffers,
-                                                  std::vector<uint32_t>                offsets)
-{
-  mVertexBufferBindings.firstBinding = firstBinding;
-  mVertexBufferBindings.buffers      = buffers; // Copy
-  mVertexBufferBindings.offsets      = offsets; // Copy
-  mCallStack.PushCall("BindVertexBuffers", "");
-}
-
-void TestGraphicsCommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings)
-{
-  mCallStack.PushCall("BindUniformBuffers", "");
-}
-
-void TestGraphicsCommandBuffer::BindPipeline(const Graphics::Pipeline& pipeline)
-{
-  mPipeline = static_cast<TestGraphicsPipeline*>(const_cast<Graphics::Pipeline*>(&pipeline));
-  mCallStack.PushCall("BindPipeline", "");
-}
-
-void TestGraphicsCommandBuffer::BindTextures(std::vector<Graphics::TextureBinding>& textureBindings)
+std::ostream& operator<<(std::ostream& os, Graphics::StencilOp op)
 {
-  mCallStack.PushCall("BindTextures", "");
-  for(auto& binding : textureBindings)
+  switch(op)
   {
-    mTextureBindings.push_back(binding);
+    case Graphics::StencilOp::KEEP:
+      os << "KEEP";
+      return os;
+    case Graphics::StencilOp::ZERO:
+      os << "ZERO";
+      return os;
+    case Graphics::StencilOp::REPLACE:
+      os << "REPLACE";
+      return os;
+    case Graphics::StencilOp::INCREMENT_AND_CLAMP:
+      os << "INCREMENT_AND_CLAMP";
+      return os;
+    case Graphics::StencilOp::DECREMENT_AND_CLAMP:
+      os << "DECREMENT_AND_CLAMP";
+      return os;
+    case Graphics::StencilOp::INVERT:
+      os << "INVERT";
+      return os;
+    case Graphics::StencilOp::INCREMENT_AND_WRAP:
+      os << "INCREMENT_AND_WRAP";
+      return os;
+    case Graphics::StencilOp::DECREMENT_AND_WRAP:
+      os << "DECREMENT_AND_WRAP";
+      return os;
   }
-}
+  return os;
+};
 
-void TestGraphicsCommandBuffer::BindSamplers(std::vector<Graphics::SamplerBinding>& samplerBindings)
+std::ostream& operator<<(std::ostream& os, Graphics::CompareOp op)
 {
-  mCallStack.PushCall("BindSamplers", "");
-}
-
-void TestGraphicsCommandBuffer::BindPushConstants(void*    data,
-                                                  uint32_t size,
-                                                  uint32_t binding)
-{
-  mCallStack.PushCall("BindPushConstants", "");
-}
-
-void TestGraphicsCommandBuffer::BindIndexBuffer(const Graphics::Buffer& buffer,
-                                                uint32_t                offset,
-                                                Graphics::Format        format)
-{
-  mIndexBufferBinding.buffer = &buffer;
-  mIndexBufferBinding.offset = offset;
-  mIndexBufferBinding.format = format;
-  mCallStack.PushCall("BindIndexBuffer", "");
-}
-
-void TestGraphicsCommandBuffer::BeginRenderPass(
-  Graphics::RenderPass&             renderPass,
-  Graphics::RenderTarget&           renderTarget,
-  Graphics::Extent2D                renderArea,
-  std::vector<Graphics::ClearValue> clearValues)
-{
-  mCallStack.PushCall("BeginRenderPass", "");
-}
-
-void TestGraphicsCommandBuffer::EndRenderPass()
-{
-  mCallStack.PushCall("EndRenderPass", "");
-}
-
-void TestGraphicsCommandBuffer::Draw(
-  uint32_t vertexCount,
-  uint32_t instanceCount,
-  uint32_t firstVertex,
-  uint32_t firstInstance)
-{
-  drawCommand.drawType                      = Draw::DrawType::Unindexed;
-  drawCommand.u.unindexedDraw.vertexCount   = vertexCount;
-  drawCommand.u.unindexedDraw.instanceCount = instanceCount;
-  drawCommand.u.unindexedDraw.firstVertex   = firstVertex;
-  drawCommand.u.unindexedDraw.firstInstance = firstInstance;
-  mCallStack.PushCall("Draw", "");
-}
-
-void TestGraphicsCommandBuffer::DrawIndexed(
-  uint32_t indexCount,
-  uint32_t instanceCount,
-  uint32_t firstIndex,
-  int32_t  vertexOffset,
-  uint32_t firstInstance)
-{
-  drawCommand.drawType                    = TestGraphicsCommandBuffer::Draw::DrawType::Indexed;
-  drawCommand.u.indexedDraw.indexCount    = indexCount;
-  drawCommand.u.indexedDraw.instanceCount = instanceCount;
-  drawCommand.u.indexedDraw.firstIndex    = firstIndex;
-  drawCommand.u.indexedDraw.vertexOffset  = vertexOffset;
-  drawCommand.u.indexedDraw.firstInstance = firstInstance;
-  mCallStack.PushCall("DrawIndexed", "");
-}
-
-void TestGraphicsCommandBuffer::DrawIndexedIndirect(
-  Graphics::Buffer& buffer,
-  uint32_t          offset,
-  uint32_t          drawCount,
-  uint32_t          stride)
-{
-  mCallStack.PushCall("DrawIndexedIndirect", "");
-}
+  switch(op)
+  {
+    case Graphics::CompareOp::NEVER:
+      os << "NEVER";
+      return os;
+    case Graphics::CompareOp::LESS:
+      os << "LESS";
+      return os;
+    case Graphics::CompareOp::EQUAL:
+      os << "EQUAL";
+      return os;
+    case Graphics::CompareOp::LESS_OR_EQUAL:
+      os << "LESS_OR_EQUAL";
+      return os;
+    case Graphics::CompareOp::GREATER:
+      os << "GREATER";
+      return os;
+    case Graphics::CompareOp::NOT_EQUAL:
+      os << "NOT_EQUAL";
+      return os;
+    case Graphics::CompareOp::GREATER_OR_EQUAL:
+      os << "GREATER_OR_EQUAL";
+      return os;
+    case Graphics::CompareOp::ALWAYS:
+      os << "ALWAYS";
+      return os;
+  }
+  return os;
+};
 
-void TestGraphicsCommandBuffer::Reset(Graphics::CommandBuffer& commandBuffer)
+TestGraphicsCommandBuffer::TestGraphicsCommandBuffer(TraceCallStack& callstack, TestGlAbstraction& glAbstraction)
+: mCallStack(callstack),
+  mGlAbstraction(glAbstraction)
 {
-  mCallStack.PushCall("Reset", "");
 }
 
-void TestGraphicsCommandBuffer::SetScissor(Graphics::Extent2D value)
+int TestGraphicsCommandBuffer::GetDrawCallsCount()
 {
-  mCallStack.PushCall("SetScissor", "");
+  int count = 0;
+  for(auto& cmd : mCommands)
+  {
+    if(cmd.type == CommandType::DRAW ||
+       cmd.type == CommandType::DRAW_INDEXED ||
+       cmd.type == CommandType::DRAW_INDEXED_INDIRECT)
+    {
+      ++count;
+    }
+  }
+  return count;
 }
 
-void TestGraphicsCommandBuffer::SetScissorTestEnable(bool value)
+void TestGraphicsCommandBuffer::GetStateForDrawCall(int drawCallIndex)
 {
-  mCallStack.PushCall("SetScissorTestEnable", "");
+  int                  index = 0;
+  std::vector<Command> mCommandStack{};
+  for(auto& cmd : mCommands)
+  {
+    mCommandStack.push_back(cmd);
+    if(cmd.type == CommandType::DRAW ||
+       cmd.type == CommandType::DRAW_INDEXED ||
+       cmd.type == CommandType::DRAW_INDEXED_INDIRECT)
+    {
+      if(index == drawCallIndex)
+      {
+        break;
+      }
+      mCommandStack.clear();
+      ++index;
+    }
+  }
 }
 
-void TestGraphicsCommandBuffer::SetViewport(Graphics::Viewport value)
+std::vector<const Command*> TestGraphicsCommandBuffer::GetCommandsByType(CommandTypeMask mask) const
 {
-  mCallStack.PushCall("SetViewport", "");
+  std::vector<const Command*> mCommandStack{};
+  for(auto& cmd : mCommands)
+  {
+    if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)))
+    {
+      mCommandStack.emplace_back(&cmd);
+    }
+  }
+  return mCommandStack;
 }
 
-void TestGraphicsCommandBuffer::SetViewportEnable(bool value)
+std::vector<const Command*> TestGraphicsCommandBuffer::GetChildCommandsByType(CommandTypeMask mask) const
 {
-  mCallStack.PushCall("SetViewportEnable", "");
+  std::vector<const Command*> mCommandStack{};
+  for(auto& cmd : mCommands)
+  {
+    if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)))
+    {
+      mCommandStack.emplace_back(&cmd);
+    }
+    if(cmd.type == CommandType::EXECUTE_COMMAND_BUFFERS)
+    {
+      for(auto secondaryCB : cmd.data.executeCommandBuffers.buffers)
+      {
+        for(auto command : secondaryCB->GetChildCommandsByType(mask))
+        {
+          mCommandStack.push_back(command);
+        }
+      }
+    }
+  }
+  return mCommandStack;
 }
 
 } // namespace Dali