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