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