[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-controller.h
index 81b93d2..6066f67 100644 (file)
@@ -2,7 +2,7 @@
 #define TEST_GRAPHICS_CONTROLLER_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -18,8 +18,8 @@
  */
 
 #include <dali/graphics-api/graphics-controller.h>
+#include <unordered_map>
 #include "test-gl-abstraction.h"
-#include "test-gl-context-helper-abstraction.h"
 #include "test-graphics-command-buffer.h"
 #include "test-graphics-program.h"
 #include "test-graphics-reflection.h"
@@ -103,14 +103,14 @@ public:
     mGl.Initialize();
   }
 
-  Integration::GlAbstraction& GetGlAbstraction() override
+  Integration::GlAbstraction& GetGlAbstraction()
   {
     return mGl;
   }
 
-  Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override
+  Integration::GraphicsConfig& GetGraphicsConfig()
   {
-    return mGlContextHelperAbstraction;
+    return mGl;
   }
 
   TestGraphicsSyncImplementation& GetGraphicsSyncImpl()
@@ -207,6 +207,8 @@ public:
    */
   Graphics::UniquePtr<Graphics::Buffer> CreateBuffer(const Graphics::BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer) override;
 
+  void DiscardBuffer(TestGraphicsBuffer* buffer);
+
   /**
    * @brief Creates new CommandBuffer object
    *
@@ -373,7 +375,63 @@ public:
    */
   bool PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const override;
 
+  /**
+   * @brief Retrieves program parameters
+   *
+   * This function can be used to retrieve data from internal implementation
+   *
+   * @param[in] program Valid program object
+   * @param[in] parameterId Integer parameter id
+   * @param[out] outData Pointer to output memory
+   * @return True on success
+   */
+  bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
+
+public: // ResourceId relative API.
+  /**
+   * @brief Create Graphics::Texture as resourceId.
+   * The ownership of Graphics::Texture will be hold on this controller.
+   * @note If some Graphics::Texture already created before, assert.
+   * @post DiscardTextureFromResourceId() or ReleaseTextureFromResourceId() should be called when we don't use resourceId texture anymore.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture, or nullptr if we fail to create.
+   */
+  Graphics::Texture* CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo) override;
+
+  /**
+   * @brief Discard Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   */
+  void DiscardTextureFromResourceId(uint32_t resourceId) override;
+
+  /**
+   * @brief Get the Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture, or nullptr if there is no valid objects.
+   */
+  Graphics::Texture* GetTextureFromResourceId(uint32_t resourceId) override;
+
+  /**
+   * @brief Get the ownership of Graphics::Texture as resourceId.
+   *
+   * @param[in] resourceId The unique id of resouces.
+   * @return Pointer of Graphics::Texture.
+   */
+  Graphics::UniquePtr<Graphics::Texture> ReleaseTextureFromResourceId(uint32_t resourceId) override;
+
 public: // Test Functions
+  void SetAutoAttrCreation(bool v)
+  {
+    mAutoAttrCreation = v;
+  }
+  bool AutoAttrCreation()
+  {
+    return mAutoAttrCreation;
+  }
+
   void SetVertexFormats(Property::Array& vfs)
   {
     mVertexFormats = vfs;
@@ -384,23 +442,16 @@ public: // Test Functions
     mCustomUniforms = customUniforms;
   }
 
+  void AddCustomUniformBlock(const TestGraphicsReflection::TestUniformBlockInfo& blockInfo)
+  {
+    mCustomUniformBlocks.push_back(blockInfo);
+  }
+
   void ClearSubmitStack()
   {
     mSubmitStack.clear();
   }
 
-  /**
-   * @brief Retrieves program parameters
-   *
-   * This function can be used to retrieve data from internal implementation
-   *
-   * @param[in] program Valid program object
-   * @param[in] parameterId Integer parameter id
-   * @param[out] outData Pointer to output memory
-   * @return True on success
-   */
-  bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
-
   void ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer);
 
   void BindPipeline(TestGraphicsPipeline* pipeline);
@@ -413,11 +464,10 @@ public:
 
   TestGlAbstraction              mGl;
   TestGraphicsSyncImplementation mGraphicsSyncImpl;
-  TestGlContextHelperAbstraction mGlContextHelperAbstraction;
-
-  bool isDiscardQueueEmptyResult{true};
-  bool isDrawOnResumeRequiredResult{true};
 
+  bool            isDiscardQueueEmptyResult{true};
+  bool            isDrawOnResumeRequiredResult{true};
+  bool            mAutoAttrCreation{true};
   Property::Array mVertexFormats;
 
   struct ProgramCache
@@ -427,11 +477,16 @@ public:
   };
   std::vector<ProgramCache> mProgramCache;
 
+  std::vector<TestGraphicsBuffer*> mAllocatedBuffers;
+
+  std::unordered_map<uint32_t, Graphics::UniquePtr<Graphics::Texture>> mTextureUploadBindMapper;
+
   struct PipelineCache
   {
   };
 
-  std::vector<UniformData> mCustomUniforms;
+  std::vector<UniformData>                                  mCustomUniforms;
+  std::vector<TestGraphicsReflection::TestUniformBlockInfo> mCustomUniformBlocks;
 };
 
 } // namespace Dali