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.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "test-graphics-controller.h"
18
19 #include "test-graphics-buffer.h"
20 #include "test-graphics-command-buffer.h"
21 #include "test-graphics-reflection.h"
22 #include "test-graphics-sampler.h"
23 #include "test-graphics-texture.h"
24
25 #include <dali/integration-api/gl-defines.h>
26 #include <cstdio>
27 #include <iostream>
28 #include <sstream>
29
30 namespace Dali
31 {
32 template<typename T>
33 T* Uncast(const Graphics::CommandBuffer* object)
34 {
35   return const_cast<T*>(static_cast<const T*>(object));
36 }
37
38 template<typename T>
39 T* Uncast(const Graphics::Texture* object)
40 {
41   return const_cast<T*>(static_cast<const T*>(object));
42 }
43
44 template<typename T>
45 T* Uncast(const Graphics::Sampler* object)
46 {
47   return const_cast<T*>(static_cast<const T*>(object));
48 }
49
50 template<typename T>
51 T* Uncast(const Graphics::Buffer* object)
52 {
53   return const_cast<T*>(static_cast<const T*>(object));
54 }
55
56 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
57 {
58   return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
59 }
60
61 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo)
62 {
63   return o << "level:" << (commandBufferCreateInfo.level == Graphics::CommandBufferLevel::PRIMARY ? "PRIMARY" : "SECONDARY")
64            << ", fixedCapacity:" << std::dec << commandBufferCreateInfo.fixedCapacity;
65 }
66
67 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType)
68 {
69   switch(textureType)
70   {
71     case Graphics::TextureType::TEXTURE_2D:
72       o << "TEXTURE_2D";
73       break;
74     case Graphics::TextureType::TEXTURE_3D:
75       o << "TEXTURE_3D";
76       break;
77     case Graphics::TextureType::TEXTURE_CUBEMAP:
78       o << "TEXTURE_CUBEMAP";
79       break;
80   }
81   return o;
82 }
83
84 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent)
85 {
86   o << "width:" << extent.width << ", height:" << extent.height;
87   return o;
88 }
89
90 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo)
91 {
92   o << "textureType:" << createInfo.textureType
93     << " size:" << createInfo.size
94     << " format:" << static_cast<uint32_t>(createInfo.format)
95     << " mipMapFlag:" << createInfo.mipMapFlag
96     << " layout:" << (createInfo.layout == Graphics::TextureLayout::LINEAR ? "LINEAR" : "OPTIMAL")
97     << " usageFlags:" << std::hex << createInfo.usageFlags
98     << " data:" << std::hex << createInfo.data
99     << " dataSize:" << std::dec << createInfo.dataSize
100     << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr;
101   return o;
102 }
103
104 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode)
105 {
106   switch(addressMode)
107   {
108     case Graphics::SamplerAddressMode::REPEAT:
109       o << "REPEAT";
110       break;
111     case Graphics::SamplerAddressMode::MIRRORED_REPEAT:
112       o << "MIRRORED_REPEAT";
113       break;
114     case Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
115       o << "CLAMP_TO_EDGE";
116       break;
117     case Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
118       o << "CLAMP_TO_BORDER";
119       break;
120     case Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
121       o << "MIRROR_CLAMP_TO_EDGE";
122       break;
123   }
124   return o;
125 }
126
127 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode)
128 {
129   switch(filterMode)
130   {
131     case Graphics::SamplerFilter::LINEAR:
132       o << "LINEAR";
133       break;
134     case Graphics::SamplerFilter::NEAREST:
135       o << "NEAREST";
136       break;
137   }
138   return o;
139 }
140
141 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode)
142 {
143   switch(mipmapMode)
144   {
145     case Graphics::SamplerMipmapMode::NONE:
146       o << "NONE";
147       break;
148     case Graphics::SamplerMipmapMode::LINEAR:
149       o << "LINEAR";
150       break;
151     case Graphics::SamplerMipmapMode::NEAREST:
152       o << "NEAREST";
153       break;
154   }
155   return o;
156 }
157
158 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo)
159 {
160   o << "minFilter:" << createInfo.minFilter
161     << " magFilter:" << createInfo.magFilter
162     << " wrapModeU:" << createInfo.addressModeU
163     << " wrapModeV:" << createInfo.addressModeV
164     << " wrapModeW:" << createInfo.addressModeW
165     << " mipMapMode:" << createInfo.mipMapMode;
166   return o;
167 }
168
169 class TestGraphicsMemory : public Graphics::Memory
170 {
171 public:
172   TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize)
173   : mCallStack(callStack),
174     mBuffer(buffer),
175     mMappedOffset(mappedOffset),
176     mMappedSize(mappedSize)
177   {
178   }
179
180   void* LockRegion(uint32_t offset, uint32_t size) override
181   {
182     std::ostringstream o;
183     o << offset << ", " << size;
184     mCallStack.PushCall("Memory::LockRegion", o.str());
185
186     if(offset > mMappedOffset + mMappedSize ||
187        size + offset > mMappedOffset + mMappedSize)
188     {
189       fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds");
190       mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing
191     }
192     mLockedOffset = offset;
193     mLockedSize   = size;
194     return &mBuffer.memory[mMappedOffset + offset];
195   }
196
197   void Unlock(bool flush) override
198   {
199     mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush"));
200     if(flush)
201     {
202       Flush();
203     }
204   }
205
206   void Flush() override
207   {
208     mCallStack.PushCall("Memory::Flush", "");
209     mBuffer.Bind();
210     mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize);
211     mBuffer.Unbind();
212   }
213
214   TraceCallStack&     mCallStack;
215   TestGraphicsBuffer& mBuffer;
216   uint32_t            mMappedOffset;
217   uint32_t            mMappedSize;
218   uint32_t            mLockedOffset;
219   uint32_t            mLockedSize;
220 };
221
222 TestGraphicsController::TestGraphicsController()
223 : mCallStack(true, "TestGraphicsController."),
224   mCommandBufferCallStack(true, "TestCommandBuffer.")
225 {
226   mCallStack.Enable(true);
227   mCommandBufferCallStack.Enable(true);
228   auto& trace = mGl.GetTextureTrace();
229   trace.Enable(true);
230   trace.EnableLogging(true);
231 }
232
233 int GetNumComponents(Graphics::VertexInputFormat vertexFormat)
234 {
235   switch(vertexFormat)
236   {
237     case Graphics::VertexInputFormat::UNDEFINED:
238     case Graphics::VertexInputFormat::FLOAT:
239     case Graphics::VertexInputFormat::INTEGER:
240       return 1;
241     case Graphics::VertexInputFormat::IVECTOR2:
242     case Graphics::VertexInputFormat::FVECTOR2:
243       return 2;
244     case Graphics::VertexInputFormat::IVECTOR3:
245     case Graphics::VertexInputFormat::FVECTOR3:
246       return 3;
247     case Graphics::VertexInputFormat::FVECTOR4:
248     case Graphics::VertexInputFormat::IVECTOR4:
249       return 4;
250   }
251   return 1;
252 }
253
254 GLint GetSize(Graphics::VertexInputFormat vertexFormat)
255 {
256   switch(vertexFormat)
257   {
258     case Graphics::VertexInputFormat::UNDEFINED:
259       return 1u;
260     case Graphics::VertexInputFormat::INTEGER:
261     case Graphics::VertexInputFormat::IVECTOR2:
262     case Graphics::VertexInputFormat::IVECTOR3:
263     case Graphics::VertexInputFormat::IVECTOR4:
264       return 2u;
265     case Graphics::VertexInputFormat::FLOAT:
266     case Graphics::VertexInputFormat::FVECTOR2:
267     case Graphics::VertexInputFormat::FVECTOR3:
268     case Graphics::VertexInputFormat::FVECTOR4:
269       return 4u;
270   }
271   return 1u;
272 }
273
274 GLint GetGlType(Graphics::VertexInputFormat vertexFormat)
275 {
276   switch(vertexFormat)
277   {
278     case Graphics::VertexInputFormat::UNDEFINED:
279       return GL_BYTE;
280     case Graphics::VertexInputFormat::INTEGER:
281     case Graphics::VertexInputFormat::IVECTOR2:
282     case Graphics::VertexInputFormat::IVECTOR3:
283     case Graphics::VertexInputFormat::IVECTOR4:
284       return GL_SHORT;
285     case Graphics::VertexInputFormat::FLOAT:
286     case Graphics::VertexInputFormat::FVECTOR2:
287     case Graphics::VertexInputFormat::FVECTOR3:
288     case Graphics::VertexInputFormat::FVECTOR4:
289       return GL_FLOAT;
290   }
291   return GL_BYTE;
292 }
293
294 GLenum GetTopology(Graphics::PrimitiveTopology topology)
295 {
296   switch(topology)
297   {
298     case Graphics::PrimitiveTopology::POINT_LIST:
299       return GL_POINTS;
300
301     case Graphics::PrimitiveTopology::LINE_LIST:
302       return GL_LINES;
303
304     case Graphics::PrimitiveTopology::LINE_LOOP:
305       return GL_LINE_LOOP;
306
307     case Graphics::PrimitiveTopology::LINE_STRIP:
308       return GL_LINE_STRIP;
309
310     case Graphics::PrimitiveTopology::TRIANGLE_LIST:
311       return GL_TRIANGLES;
312
313     case Graphics::PrimitiveTopology::TRIANGLE_STRIP:
314       return GL_TRIANGLE_STRIP;
315
316     case Graphics::PrimitiveTopology::TRIANGLE_FAN:
317       return GL_TRIANGLE_FAN;
318   }
319   return GL_TRIANGLES;
320 }
321
322 GLenum GetCullFace(Graphics::CullMode cullMode)
323 {
324   switch(cullMode)
325   {
326     case Graphics::CullMode::NONE:
327       return GL_NONE;
328     case Graphics::CullMode::FRONT:
329       return GL_FRONT;
330     case Graphics::CullMode::BACK:
331       return GL_BACK;
332     case Graphics::CullMode::FRONT_AND_BACK:
333       return GL_FRONT_AND_BACK;
334   }
335   return GL_NONE;
336 }
337
338 GLenum GetFrontFace(Graphics::FrontFace frontFace)
339 {
340   if(frontFace == Graphics::FrontFace::CLOCKWISE)
341   {
342     return GL_CW;
343   }
344   return GL_CCW;
345 }
346
347 GLenum GetBlendFactor(Graphics::BlendFactor blendFactor)
348 {
349   GLenum glFactor = GL_ZERO;
350
351   switch(blendFactor)
352   {
353     case Graphics::BlendFactor::ZERO:
354       glFactor = GL_ZERO;
355       break;
356     case Graphics::BlendFactor::ONE:
357       glFactor = GL_ONE;
358       break;
359     case Graphics::BlendFactor::SRC_COLOR:
360       glFactor = GL_SRC_COLOR;
361       break;
362     case Graphics::BlendFactor::ONE_MINUS_SRC_COLOR:
363       glFactor = GL_ONE_MINUS_SRC_COLOR;
364       break;
365     case Graphics::BlendFactor::DST_COLOR:
366       glFactor = GL_DST_COLOR;
367       break;
368     case Graphics::BlendFactor::ONE_MINUS_DST_COLOR:
369       glFactor = GL_ONE_MINUS_DST_COLOR;
370       break;
371     case Graphics::BlendFactor::SRC_ALPHA:
372       glFactor = GL_SRC_ALPHA;
373       break;
374     case Graphics::BlendFactor::ONE_MINUS_SRC_ALPHA:
375       glFactor = GL_ONE_MINUS_SRC_ALPHA;
376       break;
377     case Graphics::BlendFactor::DST_ALPHA:
378       glFactor = GL_DST_ALPHA;
379       break;
380     case Graphics::BlendFactor::ONE_MINUS_DST_ALPHA:
381       glFactor = GL_ONE_MINUS_DST_ALPHA;
382       break;
383     case Graphics::BlendFactor::CONSTANT_COLOR:
384       glFactor = GL_CONSTANT_COLOR;
385       break;
386     case Graphics::BlendFactor::ONE_MINUS_CONSTANT_COLOR:
387       glFactor = GL_ONE_MINUS_CONSTANT_COLOR;
388       break;
389     case Graphics::BlendFactor::CONSTANT_ALPHA:
390       glFactor = GL_CONSTANT_ALPHA;
391       break;
392     case Graphics::BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
393       glFactor = GL_ONE_MINUS_CONSTANT_ALPHA;
394       break;
395     case Graphics::BlendFactor::SRC_ALPHA_SATURATE:
396       glFactor = GL_SRC_ALPHA_SATURATE;
397       break;
398       // GLES doesn't appear to have dual source blending.
399     case Graphics::BlendFactor::SRC1_COLOR:
400       glFactor = GL_SRC_COLOR;
401       break;
402     case Graphics::BlendFactor::ONE_MINUS_SRC1_COLOR:
403       glFactor = GL_ONE_MINUS_SRC_COLOR;
404       break;
405     case Graphics::BlendFactor::SRC1_ALPHA:
406       glFactor = GL_SRC_ALPHA;
407       break;
408     case Graphics::BlendFactor::ONE_MINUS_SRC1_ALPHA:
409       glFactor = GL_ONE_MINUS_SRC_ALPHA;
410       break;
411   }
412   return glFactor;
413 }
414
415 GLenum GetBlendOp(Graphics::BlendOp blendOp)
416 {
417   GLenum op = GL_FUNC_ADD;
418   switch(blendOp)
419   {
420     case Graphics::BlendOp::ADD:
421       op = GL_FUNC_ADD;
422       break;
423     case Graphics::BlendOp::SUBTRACT:
424       op = GL_FUNC_SUBTRACT;
425       break;
426     case Graphics::BlendOp::REVERSE_SUBTRACT:
427       op = GL_FUNC_REVERSE_SUBTRACT;
428       break;
429     case Graphics::BlendOp::MIN:
430       op = GL_MIN;
431       break;
432     case Graphics::BlendOp::MAX:
433       op = GL_MAX;
434       break;
435
436       // @todo Add advanced blend equations
437   }
438   return op;
439 }
440
441 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
442 {
443   TraceCallStack::NamedParams namedParams;
444   namedParams["submitInfo"] << "cmdBuffer[" << submitInfo.cmdBuffer.size()
445                             << "], flags:" << std::hex << submitInfo.flags;
446
447   mCallStack.PushCall("Controller::SubmitCommandBuffers", "", namedParams);
448
449   for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer)
450   {
451     auto commandBuffer = Uncast<TestGraphicsCommandBuffer>(graphicsCommandBuffer);
452     for(auto& binding : commandBuffer->mTextureBindings)
453     {
454       if(binding.texture)
455       {
456         auto texture = Uncast<TestGraphicsTexture>(binding.texture);
457
458         texture->Bind(binding.binding);
459
460         if(binding.sampler)
461         {
462           auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
463           if(sampler)
464           {
465             sampler->Apply(texture->GetTarget());
466           }
467         }
468
469         texture->Prepare(); // Ensure native texture is ready
470       }
471     }
472
473     // IndexBuffer binding,
474     auto& indexBufferBinding = commandBuffer->mIndexBufferBinding;
475     if(indexBufferBinding.buffer)
476     {
477       auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
478       buffer->Bind();
479     }
480
481     // VertexBuffer binding,
482     for(auto graphicsBuffer : commandBuffer->mVertexBufferBindings.buffers)
483     {
484       auto vertexBuffer = Uncast<TestGraphicsBuffer>(graphicsBuffer);
485       vertexBuffer->Bind();
486     }
487
488     // Pipeline attribute setup
489     auto& vi = commandBuffer->mPipeline->vertexInputState;
490     for(auto& attribute : vi.attributes)
491     {
492       mGl.EnableVertexAttribArray(attribute.location);
493       uint32_t attributeOffset = attribute.offset;
494       GLsizei  stride          = vi.bufferBindings[attribute.binding].stride;
495
496       mGl.VertexAttribPointer(attribute.location,
497                               GetNumComponents(attribute.format),
498                               GetGlType(attribute.format),
499                               GL_FALSE, // Not normalized
500                               stride,
501                               reinterpret_cast<void*>(attributeOffset));
502     }
503
504     // Cull face setup
505     auto& rasterizationState = commandBuffer->mPipeline->rasterizationState;
506     if(rasterizationState.cullMode == Graphics::CullMode::NONE)
507     {
508       mGl.Disable(GL_CULL_FACE);
509     }
510     else
511     {
512       mGl.Enable(GL_CULL_FACE);
513       mGl.CullFace(GetCullFace(rasterizationState.cullMode));
514     }
515
516     mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
517     // We don't modify glPolygonMode in our context/abstraction from GL_FILL (the GL default),
518     // so it isn't present in the API (and won't have any tests!)
519
520     // Blending setup
521     auto& colorBlendState = commandBuffer->mPipeline->colorBlendState;
522     if(colorBlendState.blendEnable)
523     {
524       mGl.Enable(GL_BLEND);
525
526       mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
527                             GetBlendFactor(colorBlendState.dstColorBlendFactor),
528                             GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
529                             GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
530       if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
531       {
532         mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
533       }
534       else
535       {
536         mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
537       }
538       mGl.BlendColor(colorBlendState.blendConstants[0],
539                      colorBlendState.blendConstants[1],
540                      colorBlendState.blendConstants[2],
541                      colorBlendState.blendConstants[3]);
542     }
543     else
544     {
545       mGl.Disable(GL_BLEND);
546     }
547
548     // draw call
549     auto topology = commandBuffer->mPipeline->inputAssemblyState.topology;
550
551     if(commandBuffer->drawCommand.drawType == TestGraphicsCommandBuffer::Draw::DrawType::Indexed)
552     {
553       mGl.DrawElements(GetTopology(topology),
554                        static_cast<GLsizei>(commandBuffer->drawCommand.u.indexedDraw.indexCount),
555                        GL_UNSIGNED_SHORT,
556                        reinterpret_cast<void*>(commandBuffer->drawCommand.u.indexedDraw.firstIndex));
557     }
558     else
559     {
560       mGl.DrawArrays(GetTopology(topology), 0, commandBuffer->drawCommand.u.unindexedDraw.vertexCount);
561     }
562
563     // attribute clear
564     for(auto& attribute : vi.attributes)
565     {
566       mGl.DisableVertexAttribArray(attribute.location);
567     }
568   }
569 }
570
571 /**
572  * @brief Presents render target
573  * @param renderTarget render target to present
574  */
575 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
576 {
577   TraceCallStack::NamedParams namedParams;
578   namedParams["renderTarget"] << std::hex << renderTarget;
579   mCallStack.PushCall("Controller::PresentRenderTarget", "", namedParams);
580 }
581
582 /**
583  * @brief Waits until the GPU is idle
584  */
585 void TestGraphicsController::WaitIdle()
586 {
587   mCallStack.PushCall("Controller::WaitIdle", "");
588 }
589
590 /**
591  * @brief Lifecycle pause event
592  */
593 void TestGraphicsController::Pause()
594 {
595   mCallStack.PushCall("Controller::Pause", "");
596 }
597
598 /**
599  * @brief Lifecycle resume event
600  */
601 void TestGraphicsController::Resume()
602 {
603   mCallStack.PushCall("Controller::Resume", "");
604 }
605
606 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>&       updateInfoList,
607                                             const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
608 {
609   TraceCallStack::NamedParams namedParams;
610   namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:";
611   namedParams["sourceList"] << "[" << sourceList.size() << "]:";
612
613   mCallStack.PushCall("Controller::UpdateTextures", "", namedParams);
614
615   // Call either TexImage2D or TexSubImage2D
616   for(unsigned int i = 0; i < updateInfoList.size(); ++i)
617   {
618     auto& updateInfo = updateInfoList[i];
619     auto& source     = sourceList[i];
620
621     auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
622     texture->Bind(0); // Use first texture unit during resource update
623     texture->Update(updateInfo, source);
624   }
625 }
626
627 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
628 {
629   TraceCallStack::NamedParams namedParams;
630   namedParams["enableDepth"] << (enableDepth ? "T" : "F");
631   namedParams["enableStencil"] << (enableStencil ? "T" : "F");
632   mCallStack.PushCall("Controller::EnableDepthStencilBuffer", "", namedParams);
633   return false;
634 }
635
636 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
637 {
638   TraceCallStack::NamedParams namedParams;
639   namedParams["numberOfDiscardedRenderers"] << numberOfDiscardedRenderers;
640   mCallStack.PushCall("Controller::RunGarbageCollector", "", namedParams);
641 }
642
643 void TestGraphicsController::DiscardUnusedResources()
644 {
645   mCallStack.PushCall("Controller::DiscardUnusedResources", "");
646 }
647
648 bool TestGraphicsController::IsDiscardQueueEmpty()
649 {
650   mCallStack.PushCall("Controller::IsDiscardQueueEmpty", "");
651   return isDiscardQueueEmptyResult;
652 }
653
654 /**
655  * @brief Test if the graphics subsystem has resumed & should force a draw
656  *
657  * @return true if the graphics subsystem requires a re-draw
658  */
659 bool TestGraphicsController::IsDrawOnResumeRequired()
660 {
661   mCallStack.PushCall("Controller::IsDrawOnResumeRequired", "");
662   return isDrawOnResumeRequiredResult;
663 }
664
665 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
666 {
667   std::ostringstream oss;
668   oss << "bufferCreateInfo:" << createInfo;
669   mCallStack.PushCall("Controller::CreateBuffer", oss.str());
670   return Graphics::MakeUnique<TestGraphicsBuffer>(mCallStack, mGl, createInfo.size, createInfo.usage);
671 }
672
673 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
674 {
675   std::ostringstream oss;
676   oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
677   mCallStack.PushCall("Controller::CreateCommandBuffer", oss.str());
678   return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGl);
679 }
680
681 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
682 {
683   mCallStack.PushCall("Controller::CreateRenderPass", "");
684   return nullptr;
685 }
686
687 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
688 {
689   TraceCallStack::NamedParams namedParams;
690   namedParams["textureCreateInfo"] << textureCreateInfo;
691   mCallStack.PushCall("Controller::CreateTexture", namedParams.str(), namedParams);
692
693   return Graphics::MakeUnique<TestGraphicsTexture>(mGl, textureCreateInfo);
694 }
695
696 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
697 {
698   mCallStack.PushCall("Controller::CreateFramebuffer", "");
699   return nullptr;
700 }
701
702 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
703 {
704   mCallStack.PushCall("Controller::CreatePipeline", "");
705   return std::make_unique<TestGraphicsPipeline>(mGl, pipelineCreateInfo);
706 }
707
708 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
709 {
710   mCallStack.PushCall("Controller::CreateShader", "");
711   return nullptr;
712 }
713
714 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
715 {
716   TraceCallStack::NamedParams namedParams;
717   namedParams["samplerCreateInfo"] << samplerCreateInfo;
718   mCallStack.PushCall("Controller::CreateSampler", namedParams.str(), namedParams);
719
720   return Graphics::MakeUnique<TestGraphicsSampler>(mGl, samplerCreateInfo);
721 }
722
723 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
724 {
725   mCallStack.PushCall("Controller::CreateRenderTarget", "");
726   return nullptr;
727 }
728
729 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
730 {
731   mCallStack.PushCall("Controller::MapBufferRange", "");
732
733   auto buffer = static_cast<TestGraphicsBuffer*>(mapInfo.buffer);
734   buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity
735
736   return std::make_unique<TestGraphicsMemory>(mCallStack, *buffer, mapInfo.offset, mapInfo.size);
737 }
738
739 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
740 {
741   mCallStack.PushCall("Controller::MapTextureRange", "");
742   return nullptr;
743 }
744
745 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
746 {
747   mCallStack.PushCall("Controller::UnmapMemory", "");
748 }
749
750 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
751 {
752   mCallStack.PushCall("Controller::GetTextureMemoryRequirements", "");
753   return Graphics::MemoryRequirements{};
754 }
755
756 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
757 {
758   mCallStack.PushCall("Controller::GetBufferMemoryRequirements", "");
759   return Graphics::MemoryRequirements{};
760 }
761
762 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
763 {
764   static Graphics::TextureProperties textureProperties{};
765   mCallStack.PushCall("Controller::GetTextureProperties", "");
766
767   return textureProperties;
768 }
769
770 const Graphics::Reflection& TestGraphicsController::GetPipelineReflection(const Graphics::Pipeline& pipeline)
771 {
772   static TestGraphicsReflection reflection(mGl);
773   mCallStack.PushCall("Controller::GetPipelineReflection", "");
774
775   return reflection;
776 }
777
778 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
779 {
780   mCallStack.PushCall("Controller::PipelineEquals", "");
781   return false;
782 }
783
784 } // namespace Dali