Updated test files to match dali-core Pipeline VtxFmt
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-controller.h
1 #ifndef TEST_GRAPHICS_CONTROLLER_H
2 #define TEST_GRAPHICS_CONTROLLER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali/graphics-api/graphics-controller.h>
21 #include "test-gl-abstraction.h"
22 #include "test-gl-context-helper-abstraction.h"
23 #include "test-gl-sync-abstraction.h"
24
25 namespace Dali
26 {
27 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo);
28 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo);
29 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType);
30 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent);
31 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo);
32 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode);
33 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode);
34 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode);
35 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo);
36
37 class TestGraphicsController : public Dali::Graphics::Controller
38 {
39 public:
40   TestGraphicsController();
41
42   virtual ~TestGraphicsController() = default;
43
44   void Initialize()
45   {
46     mGl.Initialize();
47   }
48
49   Integration::GlAbstraction& GetGlAbstraction() override
50   {
51     return mGl;
52   }
53
54   Integration::GlSyncAbstraction& GetGlSyncAbstraction() override
55   {
56     return mGlSyncAbstraction;
57   }
58
59   Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override
60   {
61     return mGlContextHelperAbstraction;
62   }
63
64   void SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo) override;
65
66   /**
67    * @brief Presents render target
68    * @param renderTarget render target to present
69    */
70   void PresentRenderTarget(Graphics::RenderTarget* renderTarget) override;
71
72   /**
73    * @brief Waits until the GPU is idle
74    */
75   void WaitIdle() override;
76
77   /**
78    * @brief Lifecycle pause event
79    */
80   void Pause() override;
81
82   /**
83    * @brief Lifecycle resume event
84    */
85   void Resume() override;
86
87   /**
88    * @brief Executes batch update of textures
89    *
90    * This function may perform full or partial update of many textures.
91    * The data source may come from:
92    * - CPU memory (client side)
93    * - GPU memory (another Texture or Buffer)
94    *
95    * UpdateTextures() is the only way to update unmappable Texture objects.
96    * It is recommended to batch updates as it may help with optimizing
97    * memory transfers based on dependencies.
98    *
99    */
100   void UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>&       updateInfoList,
101                       const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList) override;
102
103   /**
104    * TBD: do we need those functions in the new implementation?
105    */
106   bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) override;
107
108   void RunGarbageCollector(size_t numberOfDiscardedRenderers) override;
109
110   void DiscardUnusedResources() override;
111
112   bool IsDiscardQueueEmpty() override;
113
114   /**
115    * @brief Test if the graphics subsystem has resumed & should force a draw
116    *
117    * @return true if the graphics subsystem requires a re-draw
118    */
119   bool IsDrawOnResumeRequired() override;
120
121   /**
122    * @brief Creates new Buffer object
123    *
124    * The Buffer object is created with underlying memory. The Buffer
125    * specification is immutable. Based on the BufferCreateInfo::usage,
126    * the memory may be client-side mappable or not.
127    *
128    * The old buffer may be passed as BufferCreateInfo::oldbuffer, however,
129    * it's up to the implementation whether the object will be reused or
130    * discarded and replaced by the new one.
131    *
132    * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
133    * @return pointer to the Buffer object
134    */
135   Graphics::UniquePtr<Graphics::Buffer> CreateBuffer(const Graphics::BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer) override;
136
137   /**
138    * @brief Creates new CommandBuffer object
139    *
140    * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
141    * @return pointer to the CommandBuffer object
142    */
143   Graphics::UniquePtr<Graphics::CommandBuffer> CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer) override;
144
145   /**
146    * @brief Creates new RenderPass object
147    *
148    * @param[in] renderPassCreateInfo The valid RenderPassCreateInfo structure
149    * @return pointer to the RenderPass object
150    */
151   Graphics::UniquePtr<Graphics::RenderPass> CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass) override;
152
153   /**
154    * @brief Creates new Texture object
155    *
156    * @param[in] textureCreateInfo The valid TextureCreateInfo structure
157    * @return pointer to the TextureCreateInfo object
158    */
159   Graphics::UniquePtr<Graphics::Texture> CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture) override;
160
161   /**
162    * @brief Creates new Framebuffer object
163    *
164    * @param[in] framebufferCreateInfo The valid FramebufferCreateInfo structure
165    * @return pointer to the Framebuffer object
166    */
167   Graphics::UniquePtr<Graphics::Framebuffer> CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer) override;
168
169   /**
170    * @brief Creates new Pipeline object
171    *
172    * @param[in] pipelineCreateInfo The valid PipelineCreateInfo structure
173    * @return pointer to the Pipeline object
174    */
175   Graphics::UniquePtr<Graphics::Pipeline> CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline) override;
176
177   /**
178    * @brief Creates new Shader object
179    *
180    * @param[in] shaderCreateInfo The valid ShaderCreateInfo structure
181    * @return pointer to the Shader object
182    */
183   Graphics::UniquePtr<Graphics::Shader> CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader) override;
184
185   /**
186    * @brief Creates new Sampler object
187    *
188    * @param[in] samplerCreateInfo The valid SamplerCreateInfo structure
189    * @return pointer to the Sampler object
190    */
191   Graphics::UniquePtr<Graphics::Sampler> CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler) override;
192
193   /**
194    * @brief Creates new RenderTarget object
195    *
196    * @param[in] renderTargetCreateInfo The valid RenderTargetCreateInfo structure
197    * @return pointer to the RenderTarget object
198    */
199   Graphics::UniquePtr<Graphics::RenderTarget> CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget) override;
200
201   /**
202    * @brief Maps memory associated with Buffer object
203    *
204    * @param[in] mapInfo Filled details of mapped resource
205    *
206    * @return Returns pointer to Memory object or Graphicsnullptr on error
207    */
208   Graphics::UniquePtr<Graphics::Memory> MapBufferRange(const Graphics::MapBufferInfo& mapInfo) override;
209
210   /**
211    * @brief Maps memory associated with the texture.
212    *
213    * Only Texture objects that are backed with linear memory (staging memory) can be mapped.
214    * Example:
215    * 1) GLES implementation may create PBO object as staging memory and couple it
216    * with the texture. Texture can be mapped and the memory can be read/write on demand.
217    *
218    * 2) Vulkan implementation may allocate DeviceMemory and use linear layout.
219    *
220    * @param[in] mapInfo Filled details of mapped resource
221    *
222    * @return Valid Memory object or nullptr on error
223    */
224   Graphics::UniquePtr<Graphics::Memory> MapTextureRange(const Graphics::MapTextureInfo& mapInfo) override;
225
226   /**
227    * @brief Unmaps memory and discards Memory object
228    *
229    * This function automatically removes lock if Memory has been
230    * previously locked.
231    *
232    * @param[in] memory Valid and previously mapped Memory object
233    */
234   void UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory) override;
235
236   /**
237    * @brief Returns memory requirements of the Texture object.
238    *
239    * Call this function whenever it's necessary to know how much memory
240    * is needed to store all the texture data and what memory alignment
241    * the data should follow.
242    *
243    * @return Returns memory requirements of Texture
244    */
245   Graphics::MemoryRequirements GetTextureMemoryRequirements(Graphics::Texture& texture) const override;
246
247   /**
248    * @brief Returns memory requirements of the Buffer object.
249    *
250    * Call this function whenever it's necessary to know how much memory
251    * is needed to store all the buffer data and what memory alignment
252    * the data should follow.
253    *
254    * @return Returns memory requirements of Buffer
255    */
256   Graphics::MemoryRequirements GetBufferMemoryRequirements(Graphics::Buffer& buffer) const override;
257
258   /**
259    * @brief Returns specification of the Texture object
260    *
261    * Function obtains specification of the Texture object. It may retrieve
262    * implementation dependent details like ie. whether the texture is
263    * emulated (for example, RGB emulated on RGBA), compressed etc.
264    *
265    * @return Returns the TextureProperties object
266    */
267   const Graphics::TextureProperties& GetTextureProperties(const Graphics::Texture& texture) override;
268
269   /**
270    * @brief Tests whether two Pipelines are the same.
271    *
272    * On the higher level, this function may help wit creating pipeline cache.
273    *
274    * @return true if pipeline objects match
275    */
276   bool PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const override;
277
278 public:
279   mutable TraceCallStack mCallStack;
280   mutable TraceCallStack mCommandBufferCallStack;
281
282   TestGlAbstraction              mGl;
283   TestGlSyncAbstraction          mGlSyncAbstraction;
284   TestGlContextHelperAbstraction mGlContextHelperAbstraction;
285
286   bool isDiscardQueueEmptyResult{true};
287   bool isDrawOnResumeRequiredResult{true};
288 };
289
290 } // namespace Dali
291
292 #endif //TEST_GRAPHICS_CONTROLLER_H