Merge "Fix visual defect when BorderlineOffset = 1.0f" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-controller.cpp
1 /*
2  * Copyright (c) 2022 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-framebuffer.h"
22 #include "test-graphics-reflection.h"
23 #include "test-graphics-render-pass.h"
24 #include "test-graphics-render-target.h"
25 #include "test-graphics-sampler.h"
26 #include "test-graphics-shader.h"
27 #include "test-graphics-sync-object.h"
28 #include "test-graphics-texture.h"
29
30 #include <dali/integration-api/gl-defines.h>
31 #include <cstdio>
32 #include <iostream>
33 #include <sstream>
34
35 #include <any>
36
37 namespace Dali
38 {
39 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
40 {
41   return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
42 }
43
44 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo)
45 {
46   return o << "level:" << (commandBufferCreateInfo.level == Graphics::CommandBufferLevel::PRIMARY ? "PRIMARY" : "SECONDARY")
47            << ", fixedCapacity:" << std::dec << commandBufferCreateInfo.fixedCapacity;
48 }
49
50 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType)
51 {
52   switch(textureType)
53   {
54     case Graphics::TextureType::TEXTURE_2D:
55       o << "TEXTURE_2D";
56       break;
57     case Graphics::TextureType::TEXTURE_3D:
58       o << "TEXTURE_3D";
59       break;
60     case Graphics::TextureType::TEXTURE_CUBEMAP:
61       o << "TEXTURE_CUBEMAP";
62       break;
63   }
64   return o;
65 }
66
67 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent)
68 {
69   o << "width:" << extent.width << ", height:" << extent.height;
70   return o;
71 }
72
73 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo)
74 {
75   o << "textureType:" << createInfo.textureType
76     << " size:" << createInfo.size
77     << " format:" << static_cast<uint32_t>(createInfo.format)
78     << " mipMapFlag:" << createInfo.mipMapFlag
79     << " layout:" << (createInfo.layout == Graphics::TextureLayout::LINEAR ? "LINEAR" : "OPTIMAL")
80     << " usageFlags:" << std::hex << createInfo.usageFlags
81     << " data:" << std::hex << createInfo.data
82     << " dataSize:" << std::dec << createInfo.dataSize
83     << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr.Get();
84   return o;
85 }
86
87 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode)
88 {
89   switch(addressMode)
90   {
91     case Graphics::SamplerAddressMode::REPEAT:
92       o << "REPEAT";
93       break;
94     case Graphics::SamplerAddressMode::MIRRORED_REPEAT:
95       o << "MIRRORED_REPEAT";
96       break;
97     case Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
98       o << "CLAMP_TO_EDGE";
99       break;
100     case Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
101       o << "CLAMP_TO_BORDER";
102       break;
103     case Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
104       o << "MIRROR_CLAMP_TO_EDGE";
105       break;
106   }
107   return o;
108 }
109
110 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode)
111 {
112   switch(filterMode)
113   {
114     case Graphics::SamplerFilter::LINEAR:
115       o << "LINEAR";
116       break;
117     case Graphics::SamplerFilter::NEAREST:
118       o << "NEAREST";
119       break;
120   }
121   return o;
122 }
123
124 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode)
125 {
126   switch(mipmapMode)
127   {
128     case Graphics::SamplerMipmapMode::NONE:
129       o << "NONE";
130       break;
131     case Graphics::SamplerMipmapMode::LINEAR:
132       o << "LINEAR";
133       break;
134     case Graphics::SamplerMipmapMode::NEAREST:
135       o << "NEAREST";
136       break;
137   }
138   return o;
139 }
140
141 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo)
142 {
143   o << "minFilter:" << createInfo.minFilter
144     << " magFilter:" << createInfo.magFilter
145     << " wrapModeU:" << createInfo.addressModeU
146     << " wrapModeV:" << createInfo.addressModeV
147     << " wrapModeW:" << createInfo.addressModeW
148     << " mipMapMode:" << createInfo.mipMapMode;
149   return o;
150 }
151
152 std::ostream& operator<<(std::ostream& o, const Graphics::ColorAttachment& colorAttachment)
153 {
154   o << "attachmentId:" << colorAttachment.attachmentId
155     << " layerId:" << colorAttachment.layerId
156     << " levelId:" << colorAttachment.levelId
157     << " texture:" << colorAttachment.texture;
158   return o;
159 }
160
161 std::ostream& operator<<(std::ostream& o, const Graphics::DepthStencilAttachment& depthStencilAttachment)
162 {
163   o << "depthTexture:" << depthStencilAttachment.depthTexture
164     << "depthLevel:" << depthStencilAttachment.depthLevel
165     << "stencilTexture:" << depthStencilAttachment.stencilTexture
166     << "stencilLevel:" << depthStencilAttachment.stencilLevel;
167   return o;
168 }
169
170 std::ostream& operator<<(std::ostream& o, const Graphics::FramebufferCreateInfo& createInfo)
171 {
172   o << "colorAttachments:";
173   for(auto i = 0u; i < createInfo.colorAttachments.size(); ++i)
174   {
175     o << "[" << i << "]=" << createInfo.colorAttachments[i] << "  ";
176   }
177   o << "depthStencilAttachment:" << createInfo.depthStencilAttachment;
178   o << "size: " << createInfo.size;
179   return o;
180 }
181
182 int GetNumComponents(Graphics::VertexInputFormat vertexFormat)
183 {
184   switch(vertexFormat)
185   {
186     case Graphics::VertexInputFormat::UNDEFINED:
187     case Graphics::VertexInputFormat::FLOAT:
188     case Graphics::VertexInputFormat::INTEGER:
189       return 1;
190     case Graphics::VertexInputFormat::IVECTOR2:
191     case Graphics::VertexInputFormat::FVECTOR2:
192       return 2;
193     case Graphics::VertexInputFormat::IVECTOR3:
194     case Graphics::VertexInputFormat::FVECTOR3:
195       return 3;
196     case Graphics::VertexInputFormat::FVECTOR4:
197     case Graphics::VertexInputFormat::IVECTOR4:
198       return 4;
199   }
200   return 1;
201 }
202
203 GLint GetSize(Graphics::VertexInputFormat vertexFormat)
204 {
205   switch(vertexFormat)
206   {
207     case Graphics::VertexInputFormat::UNDEFINED:
208       return 1u;
209     case Graphics::VertexInputFormat::INTEGER:
210     case Graphics::VertexInputFormat::IVECTOR2:
211     case Graphics::VertexInputFormat::IVECTOR3:
212     case Graphics::VertexInputFormat::IVECTOR4:
213       return 2u;
214     case Graphics::VertexInputFormat::FLOAT:
215     case Graphics::VertexInputFormat::FVECTOR2:
216     case Graphics::VertexInputFormat::FVECTOR3:
217     case Graphics::VertexInputFormat::FVECTOR4:
218       return 4u;
219   }
220   return 1u;
221 }
222
223 GLint GetGlType(Graphics::VertexInputFormat vertexFormat)
224 {
225   switch(vertexFormat)
226   {
227     case Graphics::VertexInputFormat::UNDEFINED:
228       return GL_BYTE;
229     case Graphics::VertexInputFormat::INTEGER:
230     case Graphics::VertexInputFormat::IVECTOR2:
231     case Graphics::VertexInputFormat::IVECTOR3:
232     case Graphics::VertexInputFormat::IVECTOR4:
233       return GL_SHORT;
234     case Graphics::VertexInputFormat::FLOAT:
235     case Graphics::VertexInputFormat::FVECTOR2:
236     case Graphics::VertexInputFormat::FVECTOR3:
237     case Graphics::VertexInputFormat::FVECTOR4:
238       return GL_FLOAT;
239   }
240   return GL_BYTE;
241 }
242
243 GLenum GetTopology(Graphics::PrimitiveTopology topology)
244 {
245   switch(topology)
246   {
247     case Graphics::PrimitiveTopology::POINT_LIST:
248       return GL_POINTS;
249
250     case Graphics::PrimitiveTopology::LINE_LIST:
251       return GL_LINES;
252
253     case Graphics::PrimitiveTopology::LINE_LOOP:
254       return GL_LINE_LOOP;
255
256     case Graphics::PrimitiveTopology::LINE_STRIP:
257       return GL_LINE_STRIP;
258
259     case Graphics::PrimitiveTopology::TRIANGLE_LIST:
260       return GL_TRIANGLES;
261
262     case Graphics::PrimitiveTopology::TRIANGLE_STRIP:
263       return GL_TRIANGLE_STRIP;
264
265     case Graphics::PrimitiveTopology::TRIANGLE_FAN:
266       return GL_TRIANGLE_FAN;
267   }
268   return GL_TRIANGLES;
269 }
270
271 GLenum GetCullFace(Graphics::CullMode cullMode)
272 {
273   switch(cullMode)
274   {
275     case Graphics::CullMode::NONE:
276       return GL_NONE;
277     case Graphics::CullMode::FRONT:
278       return GL_FRONT;
279     case Graphics::CullMode::BACK:
280       return GL_BACK;
281     case Graphics::CullMode::FRONT_AND_BACK:
282       return GL_FRONT_AND_BACK;
283   }
284   return GL_NONE;
285 }
286
287 GLenum GetFrontFace(Graphics::FrontFace frontFace)
288 {
289   if(frontFace == Graphics::FrontFace::CLOCKWISE)
290   {
291     return GL_CW;
292   }
293   return GL_CCW;
294 }
295
296 GLenum GetBlendFactor(Graphics::BlendFactor blendFactor)
297 {
298   GLenum glFactor = GL_ZERO;
299
300   switch(blendFactor)
301   {
302     case Graphics::BlendFactor::ZERO:
303       glFactor = GL_ZERO;
304       break;
305     case Graphics::BlendFactor::ONE:
306       glFactor = GL_ONE;
307       break;
308     case Graphics::BlendFactor::SRC_COLOR:
309       glFactor = GL_SRC_COLOR;
310       break;
311     case Graphics::BlendFactor::ONE_MINUS_SRC_COLOR:
312       glFactor = GL_ONE_MINUS_SRC_COLOR;
313       break;
314     case Graphics::BlendFactor::DST_COLOR:
315       glFactor = GL_DST_COLOR;
316       break;
317     case Graphics::BlendFactor::ONE_MINUS_DST_COLOR:
318       glFactor = GL_ONE_MINUS_DST_COLOR;
319       break;
320     case Graphics::BlendFactor::SRC_ALPHA:
321       glFactor = GL_SRC_ALPHA;
322       break;
323     case Graphics::BlendFactor::ONE_MINUS_SRC_ALPHA:
324       glFactor = GL_ONE_MINUS_SRC_ALPHA;
325       break;
326     case Graphics::BlendFactor::DST_ALPHA:
327       glFactor = GL_DST_ALPHA;
328       break;
329     case Graphics::BlendFactor::ONE_MINUS_DST_ALPHA:
330       glFactor = GL_ONE_MINUS_DST_ALPHA;
331       break;
332     case Graphics::BlendFactor::CONSTANT_COLOR:
333       glFactor = GL_CONSTANT_COLOR;
334       break;
335     case Graphics::BlendFactor::ONE_MINUS_CONSTANT_COLOR:
336       glFactor = GL_ONE_MINUS_CONSTANT_COLOR;
337       break;
338     case Graphics::BlendFactor::CONSTANT_ALPHA:
339       glFactor = GL_CONSTANT_ALPHA;
340       break;
341     case Graphics::BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
342       glFactor = GL_ONE_MINUS_CONSTANT_ALPHA;
343       break;
344     case Graphics::BlendFactor::SRC_ALPHA_SATURATE:
345       glFactor = GL_SRC_ALPHA_SATURATE;
346       break;
347       // GLES doesn't appear to have dual source blending.
348     case Graphics::BlendFactor::SRC1_COLOR:
349       glFactor = GL_SRC_COLOR;
350       break;
351     case Graphics::BlendFactor::ONE_MINUS_SRC1_COLOR:
352       glFactor = GL_ONE_MINUS_SRC_COLOR;
353       break;
354     case Graphics::BlendFactor::SRC1_ALPHA:
355       glFactor = GL_SRC_ALPHA;
356       break;
357     case Graphics::BlendFactor::ONE_MINUS_SRC1_ALPHA:
358       glFactor = GL_ONE_MINUS_SRC_ALPHA;
359       break;
360   }
361   return glFactor;
362 }
363
364 GLenum GetBlendOp(Graphics::BlendOp blendOp)
365 {
366   GLenum op = GL_FUNC_ADD;
367   switch(blendOp)
368   {
369     case Graphics::BlendOp::ADD:
370       op = GL_FUNC_ADD;
371       break;
372     case Graphics::BlendOp::SUBTRACT:
373       op = GL_FUNC_SUBTRACT;
374       break;
375     case Graphics::BlendOp::REVERSE_SUBTRACT:
376       op = GL_FUNC_REVERSE_SUBTRACT;
377       break;
378     case Graphics::BlendOp::MIN:
379       op = GL_MIN;
380       break;
381     case Graphics::BlendOp::MAX:
382       op = GL_MAX;
383       break;
384     case Graphics::BlendOp::MULTIPLY:
385     {
386       op = GL_MULTIPLY;
387       break;
388     }
389     case Graphics::BlendOp::SCREEN:
390     {
391       op = GL_SCREEN;
392       break;
393     }
394     case Graphics::BlendOp::OVERLAY:
395     {
396       op = GL_OVERLAY;
397       break;
398     }
399     case Graphics::BlendOp::DARKEN:
400     {
401       op = GL_DARKEN;
402       break;
403     }
404     case Graphics::BlendOp::LIGHTEN:
405     {
406       op = GL_LIGHTEN;
407       break;
408     }
409     case Graphics::BlendOp::COLOR_DODGE:
410     {
411       op = GL_COLORDODGE;
412       break;
413     }
414     case Graphics::BlendOp::COLOR_BURN:
415     {
416       op = GL_COLORBURN;
417       break;
418     }
419     case Graphics::BlendOp::HARD_LIGHT:
420     {
421       op = GL_HARDLIGHT;
422       break;
423     }
424     case Graphics::BlendOp::SOFT_LIGHT:
425     {
426       op = GL_SOFTLIGHT;
427       break;
428     }
429     case Graphics::BlendOp::DIFFERENCE:
430     {
431       op = GL_DIFFERENCE;
432       break;
433     }
434     case Graphics::BlendOp::EXCLUSION:
435     {
436       op = GL_EXCLUSION;
437       break;
438     }
439     case Graphics::BlendOp::HUE:
440     {
441       op = GL_HSL_HUE;
442       break;
443     }
444     case Graphics::BlendOp::SATURATION:
445     {
446       op = GL_HSL_SATURATION;
447       break;
448     }
449     case Graphics::BlendOp::COLOR:
450     {
451       op = GL_HSL_COLOR;
452       break;
453     }
454     case Graphics::BlendOp::LUMINOSITY:
455     {
456       op = GL_HSL_LUMINOSITY;
457       break;
458     }
459   }
460   return op;
461 }
462
463 struct GLCompareOp
464 {
465   constexpr explicit GLCompareOp(Graphics::CompareOp compareOp)
466   {
467     switch(compareOp)
468     {
469       case Graphics::CompareOp::NEVER:
470         op = GL_NEVER;
471         break;
472       case Graphics::CompareOp::LESS:
473         op = GL_LESS;
474         break;
475       case Graphics::CompareOp::EQUAL:
476         op = GL_EQUAL;
477         break;
478       case Graphics::CompareOp::LESS_OR_EQUAL:
479         op = GL_LEQUAL;
480         break;
481       case Graphics::CompareOp::GREATER:
482         op = GL_GREATER;
483         break;
484       case Graphics::CompareOp::NOT_EQUAL:
485         op = GL_NOTEQUAL;
486         break;
487       case Graphics::CompareOp::GREATER_OR_EQUAL:
488         op = GL_GEQUAL;
489         break;
490       case Graphics::CompareOp::ALWAYS:
491         op = GL_ALWAYS;
492         break;
493     }
494   }
495   GLenum op{GL_LESS};
496 };
497
498 struct GLStencilOp
499 {
500   constexpr explicit GLStencilOp(Graphics::StencilOp stencilOp)
501   {
502     switch(stencilOp)
503     {
504       case Graphics::StencilOp::KEEP:
505         op = GL_KEEP;
506         break;
507       case Graphics::StencilOp::ZERO:
508         op = GL_ZERO;
509         break;
510       case Graphics::StencilOp::REPLACE:
511         op = GL_REPLACE;
512         break;
513       case Graphics::StencilOp::INCREMENT_AND_CLAMP:
514         op = GL_INCR;
515         break;
516       case Graphics::StencilOp::DECREMENT_AND_CLAMP:
517         op = GL_DECR;
518         break;
519       case Graphics::StencilOp::INVERT:
520         op = GL_INVERT;
521         break;
522       case Graphics::StencilOp::INCREMENT_AND_WRAP:
523         op = GL_INCR_WRAP;
524         break;
525       case Graphics::StencilOp::DECREMENT_AND_WRAP:
526         op = GL_DECR_WRAP;
527         break;
528     }
529   }
530   GLenum op{GL_KEEP};
531 };
532
533 class TestGraphicsMemory : public Graphics::Memory
534 {
535 public:
536   TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize)
537   : mCallStack(callStack),
538     mBuffer(buffer),
539     mMappedOffset(mappedOffset),
540     mMappedSize(mappedSize),
541     mLockedOffset(0u),
542     mLockedSize(0u)
543   {
544   }
545
546   void* LockRegion(uint32_t offset, uint32_t size) override
547   {
548     std::ostringstream o;
549     o << offset << ", " << size;
550     mCallStack.PushCall("Memory::LockRegion", o.str());
551
552     if(offset > mMappedOffset + mMappedSize ||
553        size + offset > mMappedOffset + mMappedSize)
554     {
555       fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds");
556       mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing
557     }
558     mLockedOffset = offset;
559     mLockedSize   = size;
560     return &mBuffer.memory[mMappedOffset + offset];
561   }
562
563   void Unlock(bool flush) override
564   {
565     mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush"));
566     if(flush)
567     {
568       Flush();
569     }
570   }
571
572   void Flush() override
573   {
574     mCallStack.PushCall("Memory::Flush", "");
575     mBuffer.Bind();
576     mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize);
577     mBuffer.Unbind();
578   }
579
580   TraceCallStack&     mCallStack;
581   TestGraphicsBuffer& mBuffer;
582   uint32_t            mMappedOffset;
583   uint32_t            mMappedSize;
584   uint32_t            mLockedOffset;
585   uint32_t            mLockedSize;
586 };
587
588 TestGraphicsController::TestGraphicsController()
589 : mCallStack(false, "TestGraphicsController."),
590   mCommandBufferCallStack(false, "TestCommandBuffer."),
591   mFrameBufferCallStack(false, "TestFrameBuffer.")
592 {
593   mCallStack.Enable(true);
594   mCommandBufferCallStack.Enable(true);
595   auto& trace = mGl.GetTextureTrace();
596   trace.Enable(true);
597   trace.EnableLogging(false);
598 }
599
600 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
601 {
602   TraceCallStack::NamedParams namedParams;
603   namedParams["submitInfo"] << "cmdBuffer[" << submitInfo.cmdBuffer.size()
604                             << "], flags:" << std::hex << submitInfo.flags;
605
606   mCallStack.PushCall("SubmitCommandBuffers", "", namedParams);
607
608   mSubmitStack.emplace_back(submitInfo);
609
610   for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer)
611   {
612     auto commandBuffer = Uncast<TestGraphicsCommandBuffer>(graphicsCommandBuffer);
613     ProcessCommandBuffer(*commandBuffer);
614   }
615 }
616
617 void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer)
618 {
619   bool                     scissorEnabled = false;
620   TestGraphicsFramebuffer* currentFramebuffer{nullptr};
621   TestGraphicsPipeline*    currentPipeline{nullptr};
622
623   for(auto& cmd : commandBuffer.GetCommands())
624   {
625     // process command
626     switch(cmd.type)
627     {
628       case CommandType::FLUSH:
629       {
630         // Nothing to do here
631         break;
632       }
633       case CommandType::BIND_TEXTURES:
634       {
635         for(auto& binding : cmd.data.bindTextures.textureBindings)
636         {
637           if(binding.texture)
638           {
639             auto texture = Uncast<TestGraphicsTexture>(binding.texture);
640             texture->Bind(binding.binding);
641
642             if(binding.sampler)
643             {
644               auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
645               if(sampler)
646               {
647                 sampler->Apply(texture->GetTarget());
648               }
649             }
650
651             texture->Prepare(); // Ensure native texture is ready
652           }
653         }
654         break;
655       }
656       case CommandType::BIND_VERTEX_BUFFERS:
657       {
658         for(auto& binding : cmd.data.bindVertexBuffers.vertexBufferBindings)
659         {
660           auto graphicsBuffer = binding.buffer;
661           auto vertexBuffer   = Uncast<TestGraphicsBuffer>(graphicsBuffer);
662           vertexBuffer->Bind();
663         }
664         break;
665       }
666       case CommandType::BIND_INDEX_BUFFER:
667       {
668         auto& indexBufferBinding = cmd.data.bindIndexBuffer;
669         if(indexBufferBinding.buffer)
670         {
671           auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
672           buffer->Bind();
673         }
674         break;
675       }
676       case CommandType::BIND_UNIFORM_BUFFER:
677       {
678         if(currentPipeline)
679         {
680           auto& bindings = cmd.data.bindUniformBuffers;
681           auto  buffer   = bindings.standaloneUniformsBufferBinding;
682
683           // based on reflection, issue gl calls
684           buffer.buffer->BindAsUniformBuffer(static_cast<const TestGraphicsProgram*>(currentPipeline->programState.program), bindings.standaloneUniformsBufferBinding);
685         }
686         break;
687       }
688       case CommandType::BIND_SAMPLERS:
689       {
690         break;
691       }
692       case CommandType::BIND_PIPELINE:
693       {
694         currentPipeline = Uncast<TestGraphicsPipeline>(cmd.data.bindPipeline.pipeline);
695         BindPipeline(currentPipeline);
696         break;
697       }
698       case CommandType::DRAW_NATIVE:
699       {
700         auto info = &cmd.data.draw.drawNative.drawNativeInfo;
701
702         if(info->glesNativeInfo.eglSharedContextStoragePointer)
703         {
704           auto* anyContext = reinterpret_cast<std::any*>(info->glesNativeInfo.eglSharedContextStoragePointer);
705           *anyContext      = reinterpret_cast<void*>(0x12345678u);
706         }
707
708         CallbackBase::ExecuteReturn<bool>(*info->callback, info->userData);
709         break;
710       }
711       case CommandType::DRAW:
712       {
713         if(currentPipeline)
714         {
715           mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
716                          0,
717                          cmd.data.draw.draw.vertexCount);
718         }
719         break;
720       }
721       case CommandType::DRAW_INDEXED:
722       {
723         if(currentPipeline)
724         {
725           mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
726                            static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
727                            GL_UNSIGNED_SHORT,
728                            reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
729         }
730         break;
731       }
732       case CommandType::DRAW_INDEXED_INDIRECT:
733       {
734         if(currentPipeline)
735         {
736           mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
737                            static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
738                            GL_UNSIGNED_SHORT,
739                            reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
740         }
741         break;
742       }
743       case CommandType::SET_SCISSOR:
744       {
745         if(scissorEnabled)
746         {
747           auto& rect = cmd.data.scissor.region;
748           mGl.Scissor(rect.x, rect.y, rect.width, rect.height);
749         }
750         break;
751       }
752       case CommandType::SET_SCISSOR_TEST:
753       {
754         if(cmd.data.scissorTest.enable)
755         {
756           mGl.Enable(GL_SCISSOR_TEST);
757           scissorEnabled = true;
758         }
759         else
760         {
761           mGl.Disable(GL_SCISSOR_TEST);
762           scissorEnabled = false;
763         }
764         break;
765       }
766       case CommandType::SET_VIEWPORT_TEST:
767       {
768         break;
769       }
770       case CommandType::SET_VIEWPORT: // @todo Consider correcting for orientation here?
771       {
772         auto& rect = cmd.data.viewport.region;
773         mGl.Viewport(rect.x, rect.y, rect.width, rect.height);
774         break;
775       }
776
777       case CommandType::SET_COLOR_MASK:
778       {
779         // Set all channels to the same mask
780         const bool mask = cmd.data.colorMask.enabled;
781         mGl.ColorMask(mask, mask, mask, mask);
782         break;
783       }
784       case CommandType::CLEAR_STENCIL_BUFFER:
785       {
786         mGl.Clear(GL_STENCIL_BUFFER_BIT);
787         break;
788       }
789       case CommandType::CLEAR_DEPTH_BUFFER:
790       {
791         mGl.Clear(GL_DEPTH_BUFFER_BIT);
792         break;
793       }
794
795       case CommandType::SET_STENCIL_TEST_ENABLE:
796       {
797         if(cmd.data.stencilTest.enabled)
798         {
799           mGl.Enable(GL_STENCIL_TEST);
800         }
801         else
802         {
803           mGl.Disable(GL_STENCIL_TEST);
804         }
805         break;
806       }
807
808       case CommandType::SET_STENCIL_FUNC:
809       {
810         mGl.StencilFunc(GLCompareOp(cmd.data.stencilFunc.compareOp).op,
811                         cmd.data.stencilFunc.reference,
812                         cmd.data.stencilFunc.compareMask);
813         break;
814       }
815
816       case CommandType::SET_STENCIL_WRITE_MASK:
817       {
818         mGl.StencilMask(cmd.data.stencilWriteMask.mask);
819         break;
820       }
821       case CommandType::SET_STENCIL_OP:
822       {
823         mGl.StencilOp(GLStencilOp(cmd.data.stencilOp.failOp).op,
824                       GLStencilOp(cmd.data.stencilOp.depthFailOp).op,
825                       GLStencilOp(cmd.data.stencilOp.passOp).op);
826         break;
827       }
828
829       case CommandType::SET_DEPTH_COMPARE_OP:
830       {
831         mGl.DepthFunc(GLCompareOp(cmd.data.depth.compareOp).op);
832         break;
833       }
834       case CommandType::SET_DEPTH_TEST_ENABLE:
835       {
836         if(cmd.data.depth.testEnabled)
837         {
838           mGl.Enable(GL_DEPTH_TEST);
839         }
840         else
841         {
842           mGl.Disable(GL_DEPTH_TEST);
843         }
844         break;
845       }
846       case CommandType::SET_DEPTH_WRITE_ENABLE:
847       {
848         mGl.DepthMask(cmd.data.depth.writeEnabled);
849         break;
850       }
851
852       case CommandType::EXECUTE_COMMAND_BUFFERS:
853       {
854         // Process secondary command buffers
855         for(auto& buf : cmd.data.executeCommandBuffers.buffers)
856         {
857           ProcessCommandBuffer(*Uncast<TestGraphicsCommandBuffer>(buf));
858         }
859         break;
860       }
861       case CommandType::BEGIN_RENDER_PASS:
862       {
863         auto renderTarget = Uncast<TestGraphicsRenderTarget>(cmd.data.beginRenderPass.renderTarget);
864
865         if(renderTarget)
866         {
867           auto fb = renderTarget->mCreateInfo.framebuffer;
868           if(fb)
869           {
870             if(currentFramebuffer != fb)
871             {
872               currentFramebuffer = Uncast<TestGraphicsFramebuffer>(fb);
873               currentFramebuffer->Bind();
874             }
875           }
876           else
877           {
878             mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
879           }
880         }
881         else
882         {
883           mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
884         }
885
886         auto& clearValues = cmd.data.beginRenderPass.clearValues;
887         if(clearValues.size() > 0)
888         {
889           const auto renderPass = static_cast<TestGraphicsRenderPass*>(cmd.data.beginRenderPass.renderPass);
890           if(renderPass)
891           {
892             const auto& color0 = renderPass->attachments[0];
893             GLuint      mask   = 0;
894             if(color0.loadOp == Graphics::AttachmentLoadOp::CLEAR)
895             {
896               mask |= GL_COLOR_BUFFER_BIT;
897
898               // Set clear color (todo: cache it!)
899               // Something goes wrong here if Alpha mask is GL_TRUE
900               mGl.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
901               mGl.ClearColor(clearValues[0].color.r,
902                              clearValues[0].color.g,
903                              clearValues[0].color.b,
904                              clearValues[0].color.a);
905             }
906
907             // check for depth stencil
908             if(renderPass->attachments.size() > 1)
909             {
910               const auto& depthStencil = renderPass->attachments.back();
911               if(depthStencil.loadOp == Graphics::AttachmentLoadOp::CLEAR)
912               {
913                 mGl.DepthMask(true);
914                 uint32_t depthClearColor = 0u;
915                 if(clearValues.size() == renderPass->attachments.size())
916                 {
917                   depthClearColor = clearValues.back().depthStencil.depth;
918                 }
919                 mGl.ClearDepthf(depthClearColor);
920                 mask |= GL_DEPTH_BUFFER_BIT;
921               }
922               if(depthStencil.stencilLoadOp == Graphics::AttachmentLoadOp::CLEAR)
923               {
924                 uint32_t stencilClearColor = 0u;
925                 if(clearValues.size() == renderPass->attachments.size())
926                 {
927                   stencilClearColor = clearValues.back().depthStencil.stencil;
928                 }
929                 mGl.ClearStencil(stencilClearColor);
930                 mGl.StencilMask(0xFF); // Clear all the bitplanes (assume 8)
931                 mask |= GL_STENCIL_BUFFER_BIT;
932               }
933             }
934
935             if(mask != 0)
936             {
937               // Test scissor area and RT size
938               const auto& area = cmd.data.beginRenderPass.renderArea;
939               if(area.x == 0 &&
940                  area.y == 0 &&
941                  renderTarget &&
942                  area.width == renderTarget->mCreateInfo.extent.width &&
943                  area.height == renderTarget->mCreateInfo.extent.height)
944               {
945                 mGl.Disable(GL_SCISSOR_TEST);
946                 mGl.Clear(mask);
947               }
948               else
949               {
950                 mGl.Enable(GL_SCISSOR_TEST);
951                 mGl.Scissor(cmd.data.beginRenderPass.renderArea.x, cmd.data.beginRenderPass.renderArea.y, cmd.data.beginRenderPass.renderArea.width, cmd.data.beginRenderPass.renderArea.height);
952                 mGl.Clear(mask);
953                 mGl.Disable(GL_SCISSOR_TEST);
954               }
955             }
956           }
957           else
958           {
959             DALI_ASSERT_DEBUG(0 && "BeginRenderPass has no render pass");
960           }
961         }
962         break;
963       }
964       case CommandType::END_RENDER_PASS:
965       {
966         if(cmd.data.endRenderPass.syncObject != nullptr)
967         {
968           auto syncObject = Uncast<TestGraphicsSyncObject>(cmd.data.endRenderPass.syncObject);
969           syncObject->InitializeResource(); // create the sync object.
970         }
971         break;
972       }
973     }
974   }
975 }
976
977 void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline)
978 {
979   auto& vi = pipeline->vertexInputState;
980   for(auto& attribute : vi.attributes)
981   {
982     mGl.EnableVertexAttribArray(attribute.location);
983     uint32_t attributeOffset = attribute.offset;
984     GLsizei  stride          = vi.bufferBindings[attribute.binding].stride;
985
986     mGl.VertexAttribPointer(attribute.location,
987                             GetNumComponents(attribute.format),
988                             GetGlType(attribute.format),
989                             GL_FALSE, // Not normalized
990                             stride,
991                             reinterpret_cast<void*>(attributeOffset));
992   }
993
994   // Cull face setup
995   auto& rasterizationState = pipeline->rasterizationState;
996   if(rasterizationState.cullMode == Graphics::CullMode::NONE)
997   {
998     mGl.Disable(GL_CULL_FACE);
999   }
1000   else
1001   {
1002     mGl.Enable(GL_CULL_FACE);
1003     mGl.CullFace(GetCullFace(rasterizationState.cullMode));
1004   }
1005
1006   mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
1007
1008   // Blending setup
1009   auto& colorBlendState = pipeline->colorBlendState;
1010   if(colorBlendState.blendEnable)
1011   {
1012     mGl.Enable(GL_BLEND);
1013
1014     mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
1015                           GetBlendFactor(colorBlendState.dstColorBlendFactor),
1016                           GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
1017                           GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
1018     if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
1019     {
1020       mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
1021     }
1022     else
1023     {
1024       mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
1025     }
1026     mGl.BlendColor(colorBlendState.blendConstants[0],
1027                    colorBlendState.blendConstants[1],
1028                    colorBlendState.blendConstants[2],
1029                    colorBlendState.blendConstants[3]);
1030   }
1031   else
1032   {
1033     mGl.Disable(GL_BLEND);
1034   }
1035
1036   auto* program = static_cast<const TestGraphicsProgram*>(pipeline->programState.program);
1037   mGl.UseProgram(program->mImpl->mId);
1038 }
1039
1040 /**
1041  * @brief Presents render target
1042  * @param renderTarget render target to present
1043  */
1044 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
1045 {
1046   auto*                       rt = static_cast<const TestGraphicsRenderTarget*>(renderTarget);
1047   TraceCallStack::NamedParams namedParams;
1048   namedParams["renderTarget"] << std::hex << renderTarget;
1049   namedParams["surface"] << std::hex << rt->mCreateInfo.surface;
1050   mCallStack.PushCall("PresentRenderTarget", namedParams.str(), namedParams);
1051 }
1052
1053 /**
1054  * @brief Waits until the GPU is idle
1055  */
1056 void TestGraphicsController::WaitIdle()
1057 {
1058   mCallStack.PushCall("WaitIdle", "");
1059 }
1060
1061 /**
1062  * @brief Lifecycle pause event
1063  */
1064 void TestGraphicsController::Pause()
1065 {
1066   mCallStack.PushCall("Pause", "");
1067 }
1068
1069 /**
1070  * @brief Lifecycle resume event
1071  */
1072 void TestGraphicsController::Resume()
1073 {
1074   mCallStack.PushCall("Resume", "");
1075 }
1076
1077 void TestGraphicsController::Shutdown()
1078 {
1079   mCallStack.PushCall("Shutdown", "");
1080 }
1081
1082 void TestGraphicsController::Destroy()
1083 {
1084   mCallStack.PushCall("Destroy", "");
1085 }
1086
1087 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>&       updateInfoList,
1088                                             const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
1089 {
1090   TraceCallStack::NamedParams namedParams;
1091   namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:";
1092   namedParams["sourceList"] << "[" << sourceList.size() << "]:";
1093
1094   mCallStack.PushCall("UpdateTextures", "", namedParams);
1095
1096   // Call either TexImage2D or TexSubImage2D
1097   for(unsigned int i = 0; i < updateInfoList.size(); ++i)
1098   {
1099     auto& updateInfo = updateInfoList[i];
1100     auto& source     = sourceList[i];
1101
1102     auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
1103     texture->Bind(0); // Use first texture unit during resource update
1104     texture->Update(updateInfo, source);
1105   }
1106 }
1107
1108 void TestGraphicsController::GenerateTextureMipmaps(const Graphics::Texture& texture)
1109 {
1110   mCallStack.PushCall("GenerateTextureMipmaps", "");
1111
1112   auto gfxTexture = Uncast<TestGraphicsTexture>(&texture);
1113   mGl.BindTexture(gfxTexture->GetTarget(), 0);
1114   mGl.GenerateMipmap(gfxTexture->GetTarget());
1115 }
1116
1117 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
1118 {
1119   TraceCallStack::NamedParams namedParams;
1120   namedParams["enableDepth"] << (enableDepth ? "T" : "F");
1121   namedParams["enableStencil"] << (enableStencil ? "T" : "F");
1122   mCallStack.PushCall("EnableDepthStencilBuffer", "", namedParams);
1123   return false;
1124 }
1125
1126 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
1127 {
1128   TraceCallStack::NamedParams namedParams;
1129   namedParams["numberOfDiscardedRenderers"] << numberOfDiscardedRenderers;
1130   mCallStack.PushCall("RunGarbageCollector", "", namedParams);
1131 }
1132
1133 void TestGraphicsController::DiscardUnusedResources()
1134 {
1135   mCallStack.PushCall("DiscardUnusedResources", "");
1136 }
1137
1138 bool TestGraphicsController::IsDiscardQueueEmpty()
1139 {
1140   mCallStack.PushCall("IsDiscardQueueEmpty", "");
1141   return isDiscardQueueEmptyResult;
1142 }
1143
1144 /**
1145  * @brief Test if the graphics subsystem has resumed & should force a draw
1146  *
1147  * @return true if the graphics subsystem requires a re-draw
1148  */
1149 bool TestGraphicsController::IsDrawOnResumeRequired()
1150 {
1151   mCallStack.PushCall("IsDrawOnResumeRequired", "");
1152   return isDrawOnResumeRequiredResult;
1153 }
1154
1155 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
1156 {
1157   std::ostringstream oss;
1158   oss << "bufferCreateInfo:" << createInfo;
1159   mCallStack.PushCall("CreateBuffer", oss.str());
1160   return Graphics::MakeUnique<TestGraphicsBuffer>(mCallStack, mGl, createInfo.size, createInfo.usage);
1161 }
1162
1163 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
1164 {
1165   std::ostringstream oss;
1166   oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
1167   mCallStack.PushCall("CreateCommandBuffer", oss.str());
1168   return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGl);
1169 }
1170
1171 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
1172 {
1173   mCallStack.PushCall("CreateRenderPass", "");
1174   return Graphics::MakeUnique<TestGraphicsRenderPass>(mGl, renderPassCreateInfo);
1175 }
1176
1177 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
1178 {
1179   TraceCallStack::NamedParams namedParams;
1180   namedParams["textureCreateInfo"] << textureCreateInfo;
1181   mCallStack.PushCall("CreateTexture", namedParams.str(), namedParams);
1182
1183   return Graphics::MakeUnique<TestGraphicsTexture>(mGl, textureCreateInfo);
1184 }
1185
1186 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(
1187   const Graphics::FramebufferCreateInfo&       createInfo,
1188   Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
1189 {
1190   TraceCallStack::NamedParams namedParams;
1191   namedParams["framebufferCreateInfo"] << createInfo;
1192   mCallStack.PushCall("Controller::CreateFramebuffer", namedParams.str(), namedParams);
1193
1194   return Graphics::MakeUnique<TestGraphicsFramebuffer>(mFrameBufferCallStack, mGl, createInfo);
1195 }
1196
1197 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
1198 {
1199   mCallStack.PushCall("CreatePipeline", "");
1200   return std::make_unique<TestGraphicsPipeline>(mGl, pipelineCreateInfo);
1201 }
1202
1203 Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
1204 {
1205   mCallStack.PushCall("CreateProgram", "");
1206
1207   for(auto cacheEntry : mProgramCache)
1208   {
1209     bool found = true;
1210     for(auto& shader : *(programCreateInfo.shaderState))
1211     {
1212       auto                 graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
1213       std::vector<uint8_t> source;
1214       source.resize(graphicsShader->mCreateInfo.sourceSize);
1215       memcpy(&source[0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
1216
1217       if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin()))
1218       {
1219         found = false;
1220         break;
1221       }
1222     }
1223     if(found)
1224     {
1225       return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
1226     }
1227   }
1228
1229   mProgramCache.emplace_back();
1230   mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms);
1231   for(auto& shader : *(programCreateInfo.shaderState))
1232   {
1233     auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
1234     mProgramCache.back().shaders[shader.pipelineStage].resize(graphicsShader->mCreateInfo.sourceSize);
1235     memcpy(&mProgramCache.back().shaders[shader.pipelineStage][0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
1236   }
1237   return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
1238 }
1239
1240 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
1241 {
1242   mCallStack.PushCall("CreateShader", "");
1243   return Graphics::MakeUnique<TestGraphicsShader>(mGl, shaderCreateInfo);
1244 }
1245
1246 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
1247 {
1248   TraceCallStack::NamedParams namedParams;
1249   namedParams["samplerCreateInfo"] << samplerCreateInfo;
1250   mCallStack.PushCall("CreateSampler", namedParams.str(), namedParams);
1251
1252   return Graphics::MakeUnique<TestGraphicsSampler>(mGl, samplerCreateInfo);
1253 }
1254
1255 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
1256 {
1257   TraceCallStack::NamedParams namedParams;
1258   namedParams["surface"] << std::hex << renderTargetCreateInfo.surface;
1259   mCallStack.PushCall("CreateRenderTarget", namedParams.str(), namedParams);
1260
1261   return Graphics::MakeUnique<TestGraphicsRenderTarget>(mGl, renderTargetCreateInfo);
1262 }
1263
1264 Graphics::UniquePtr<Graphics::SyncObject> TestGraphicsController::CreateSyncObject(
1265   const Graphics::SyncObjectCreateInfo&       syncObjectCreateInfo,
1266   Graphics::UniquePtr<Graphics::SyncObject>&& oldSyncObject)
1267 {
1268   mCallStack.PushCall("CreateSyncObject", "");
1269   return Graphics::MakeUnique<TestGraphicsSyncObject>(mGraphicsSyncImpl, syncObjectCreateInfo);
1270 }
1271
1272 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
1273 {
1274   mCallStack.PushCall("MapBufferRange", "");
1275
1276   auto buffer = static_cast<TestGraphicsBuffer*>(mapInfo.buffer);
1277   buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity
1278
1279   return std::make_unique<TestGraphicsMemory>(mCallStack, *buffer, mapInfo.offset, mapInfo.size);
1280 }
1281
1282 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
1283 {
1284   mCallStack.PushCall("MapTextureRange", "");
1285   return nullptr;
1286 }
1287
1288 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
1289 {
1290   mCallStack.PushCall("UnmapMemory", "");
1291 }
1292
1293 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
1294 {
1295   mCallStack.PushCall("GetTextureMemoryRequirements", "");
1296   return Graphics::MemoryRequirements{};
1297 }
1298
1299 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
1300 {
1301   mCallStack.PushCall("GetBufferMemoryRequirements", "");
1302   return Graphics::MemoryRequirements{};
1303 }
1304
1305 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
1306 {
1307   static Graphics::TextureProperties textureProperties{};
1308   mCallStack.PushCall("GetTextureProperties", "");
1309
1310   return textureProperties;
1311 }
1312
1313 const Graphics::Reflection& TestGraphicsController::GetProgramReflection(const Graphics::Program& program)
1314 {
1315   mCallStack.PushCall("GetProgramReflection", "");
1316
1317   return static_cast<const TestGraphicsProgram*>(&program)->GetReflection();
1318 }
1319
1320 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
1321 {
1322   mCallStack.PushCall("PipelineEquals", "");
1323   return false;
1324 }
1325
1326 bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
1327 {
1328   mCallStack.PushCall("GetProgramParameter", "");
1329   auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
1330   return graphicsProgram->GetParameter(parameterId, outData);
1331 }
1332
1333 } // namespace Dali