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