Multiply only for Transform Matrix + NEON comment clean up
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-types.h
1 #ifndef DALI_GRAPHICS_API_TYPES
2 #define DALI_GRAPHICS_API_TYPES
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <memory>
23 #include <string>
24 #include <utility>
25 #include <vector>
26
27 #include <dali/public-api/signals/callback.h>
28
29 namespace Dali
30 {
31 namespace Graphics
32 {
33 class Buffer;
34 class CommandBuffer;
35 class Framebuffer;
36 class Program;
37 class Shader;
38 class Texture;
39
40 /**
41  * @brief Structure describes 2D offset
42  */
43 struct Offset2D
44 {
45   int32_t x = 0;
46   int32_t y = 0;
47 };
48
49 /**
50  * @brief Structure describes 2D dimensions
51  */
52 struct Extent2D
53 {
54   uint32_t width;
55   uint32_t height;
56 };
57
58 /**
59  * @brief Structure describes 2D rectangle (offset, extent)
60  */
61 struct Rect2D
62 {
63   int32_t  x      = 0;
64   int32_t  y      = 0;
65   uint32_t width  = 0;
66   uint32_t height = 0;
67 };
68
69 /**
70  * @brief Structure represents area of viewport
71  */
72 struct Viewport
73 {
74   float x        = 0.0f;
75   float y        = 0.0f;
76   float width    = 0.0f;
77   float height   = 0.0f;
78   float minDepth = 0.0f;
79   float maxDepth = 0.0f;
80 };
81
82 /**
83  * @brief Describes vertex attribute input rate
84  */
85 enum class VertexInputRate
86 {
87   PER_VERTEX,  ///< Attribute read per vertex
88   PER_INSTANCE ///< Attribute read per instance
89 };
90
91 /**
92  * @brief Vertex input format
93  *
94  * When UNDEFINED, the reflection is used to determine what
95  * the actual format is.
96  */
97 enum class VertexInputFormat
98 {
99   UNDEFINED,
100   FVECTOR2,
101   FVECTOR3,
102   FVECTOR4,
103   IVECTOR2,
104   IVECTOR3,
105   IVECTOR4,
106   FLOAT,
107   INTEGER,
108 };
109
110 /**
111  * @brief Logic operators used by color blending state
112  * when logicOpEnable is set.
113  */
114 enum class LogicOp
115 {
116   CLEAR         = 0,
117   AND           = 1,
118   AND_REVERSE   = 2,
119   COPY          = 3,
120   AND_INVERTED  = 4,
121   NO_OP         = 5,
122   XOR           = 6,
123   OR            = 7,
124   NOR           = 8,
125   EQUIVALENT    = 9,
126   INVERT        = 10,
127   OR_REVERSE    = 11,
128   COPY_INVERTED = 12,
129   OR_INVERTED   = 13,
130   NAND          = 14,
131   SET           = 15,
132 };
133
134 /**
135  * @brief Blend factors
136  */
137 enum class BlendFactor
138 {
139   ZERO                     = 0,
140   ONE                      = 1,
141   SRC_COLOR                = 2,
142   ONE_MINUS_SRC_COLOR      = 3,
143   DST_COLOR                = 4,
144   ONE_MINUS_DST_COLOR      = 5,
145   SRC_ALPHA                = 6,
146   ONE_MINUS_SRC_ALPHA      = 7,
147   DST_ALPHA                = 8,
148   ONE_MINUS_DST_ALPHA      = 9,
149   CONSTANT_COLOR           = 10,
150   ONE_MINUS_CONSTANT_COLOR = 11,
151   CONSTANT_ALPHA           = 12,
152   ONE_MINUS_CONSTANT_ALPHA = 13,
153   SRC_ALPHA_SATURATE       = 14,
154   SRC1_COLOR               = 15,
155   ONE_MINUS_SRC1_COLOR     = 16,
156   SRC1_ALPHA               = 17,
157   ONE_MINUS_SRC1_ALPHA     = 18,
158 };
159
160 /**
161  * @brief Blend operators
162  */
163 enum class BlendOp
164 {
165   ADD              = 0,
166   SUBTRACT         = 1,
167   REVERSE_SUBTRACT = 2,
168   MIN              = 3,
169   MAX              = 4,
170   MULTIPLY         = 5,
171   SCREEN           = 6,
172   OVERLAY          = 7,
173   DARKEN           = 8,
174   LIGHTEN          = 9,
175   COLOR_DODGE      = 10,
176   COLOR_BURN       = 11,
177   HARD_LIGHT       = 12,
178   SOFT_LIGHT       = 13,
179   DIFFERENCE       = 14,
180   EXCLUSION        = 15,
181   HUE              = 16,
182   SATURATION       = 17,
183   COLOR            = 18,
184   LUMINOSITY       = 19,
185 };
186
187 const BlendOp ADVANCED_BLEND_OPTIONS_START(BlendOp::MULTIPLY);
188
189 /**
190  * @brief Compare operators
191  */
192 enum class CompareOp
193 {
194   NEVER,
195   LESS,
196   EQUAL,
197   LESS_OR_EQUAL,
198   GREATER,
199   NOT_EQUAL,
200   GREATER_OR_EQUAL,
201   ALWAYS
202 };
203
204 /**
205  * @brief Stencil operators
206  */
207 enum class StencilOp
208 {
209   KEEP,
210   ZERO,
211   REPLACE,
212   INCREMENT_AND_CLAMP,
213   DECREMENT_AND_CLAMP,
214   INVERT,
215   INCREMENT_AND_WRAP,
216   DECREMENT_AND_WRAP
217 };
218
219 /**
220  * @brief Backface culling modes
221  */
222 enum class CullMode
223 {
224   NONE,
225   FRONT,
226   BACK,
227   FRONT_AND_BACK
228 };
229
230 /**
231  * @brief Polygon drawing modes
232  */
233 enum class PolygonMode
234 {
235   FILL,
236   LINE,
237   POINT
238 };
239
240 /**
241  * @brief Front face direction
242  */
243 enum class FrontFace
244 {
245   COUNTER_CLOCKWISE,
246   CLOCKWISE
247 };
248
249 /**
250  * @brief Primitive geometry topology
251  */
252 enum class PrimitiveTopology
253 {
254   POINT_LIST,
255   LINE_LIST,
256   LINE_LOOP,
257   LINE_STRIP,
258   TRIANGLE_LIST,
259   TRIANGLE_STRIP,
260   TRIANGLE_FAN
261 };
262
263 /**
264  * @brief Sampler address ( wrapping ) mode
265  */
266 enum class SamplerAddressMode
267 {
268   REPEAT,
269   MIRRORED_REPEAT,
270   CLAMP_TO_EDGE,
271   CLAMP_TO_BORDER,
272   MIRROR_CLAMP_TO_EDGE
273 };
274
275 /**
276  * @brief Filtering mode
277  */
278 enum class SamplerFilter
279 {
280   NEAREST,
281   LINEAR
282 };
283
284 /**
285  * @brief Mipmap mode
286  */
287 enum class SamplerMipmapMode
288 {
289   NONE,
290   NEAREST,
291   LINEAR
292 };
293
294 /**
295  * @brief Describes pipeline's color blend state
296  */
297 struct ColorBlendState
298 {
299   bool        logicOpEnable           = false;
300   LogicOp     logicOp                 = {};
301   float       blendConstants[4]       = {0.0f, 0.0f, 0.0f, 0.0f};
302   bool        blendEnable             = false;
303   BlendFactor srcColorBlendFactor     = BlendFactor::ZERO;
304   BlendFactor dstColorBlendFactor     = BlendFactor::ZERO;
305   BlendOp     colorBlendOp            = {};
306   BlendFactor srcAlphaBlendFactor     = BlendFactor::ZERO;
307   BlendFactor dstAlphaBlendFactor     = BlendFactor::ZERO;
308   BlendOp     alphaBlendOp            = {};
309   uint32_t    colorComponentWriteBits = {0u};
310
311   auto& SetLogicOpEnable(bool value)
312   {
313     logicOpEnable = value;
314     return *this;
315   }
316
317   auto& SetLogicOp(LogicOp value)
318   {
319     logicOp = value;
320     return *this;
321   }
322
323   auto& SetBlendConstants(float value[4])
324   {
325     std::copy(value, value + 4, blendConstants);
326     return *this;
327   }
328
329   auto& SetBlendEnable(bool value)
330   {
331     blendEnable = value;
332     return *this;
333   }
334
335   auto& SetSrcColorBlendFactor(BlendFactor value)
336   {
337     srcColorBlendFactor = value;
338     return *this;
339   }
340
341   auto& SetDstColorBlendFactor(BlendFactor value)
342   {
343     dstColorBlendFactor = value;
344     return *this;
345   }
346
347   auto& SetColorBlendOp(BlendOp value)
348   {
349     colorBlendOp = value;
350     return *this;
351   }
352
353   auto& SetSrcAlphaBlendFactor(BlendFactor value)
354   {
355     srcAlphaBlendFactor = value;
356     return *this;
357   }
358
359   auto& SetDstAlphaBlendFactor(BlendFactor value)
360   {
361     dstAlphaBlendFactor = value;
362     return *this;
363   }
364
365   auto& SetAlphaBlendOp(BlendOp value)
366   {
367     alphaBlendOp = value;
368     return *this;
369   }
370
371   auto& SetColorComponentsWriteBits(uint32_t value)
372   {
373     colorComponentWriteBits = value;
374     return *this;
375   }
376 };
377
378 /**
379  * @brief Program State
380  */
381 struct ProgramState
382 {
383   const Program* program{nullptr};
384
385   auto& SetProgram(const Program& value)
386   {
387     program = &value;
388     return *this;
389   }
390 };
391
392 /**
393  * @brief  Framebuffer state.
394  */
395 struct FramebufferState
396 {
397   const Framebuffer* framebuffer{nullptr};
398
399   auto& SetFramebuffer(const Framebuffer& value)
400   {
401     framebuffer = &value;
402     return *this;
403   }
404 };
405
406 /**
407  * @brief Describes pipeline's viewport and scissor state
408  */
409 struct ViewportState
410 {
411   Viewport viewport{0.0, 0.0, 0.0, 0.0};
412   Rect2D   scissor{0, 0, 0, 0};
413   bool     scissorTestEnable{false};
414
415   auto& SetViewport(const Viewport& value)
416   {
417     viewport = value;
418     return *this;
419   }
420
421   auto& SetScissor(const Rect2D& value)
422   {
423     scissor = value;
424     return *this;
425   }
426
427   auto& SetScissorTestEnable(bool value)
428   {
429     scissorTestEnable = value;
430     return *this;
431   }
432 };
433
434 /**
435  * @brief Describes stencil operation state
436  */
437 struct StencilOpState
438 {
439   StencilOp failOp{};
440   StencilOp passOp{};
441   StencilOp depthFailOp{};
442   CompareOp compareOp{};
443   uint32_t  compareMask{0u};
444   uint32_t  writeMask{0u};
445   uint32_t  reference{0u};
446
447   auto& SetFailOp(StencilOp value)
448   {
449     failOp = value;
450     return *this;
451   }
452
453   auto& SetPassOp(StencilOp value)
454   {
455     failOp = value;
456     return *this;
457   }
458
459   auto& SetDepthFailOp(StencilOp value)
460   {
461     failOp = value;
462     return *this;
463   }
464
465   auto& SetCompareOp(CompareOp value)
466   {
467     compareOp = value;
468     return *this;
469   }
470
471   auto& SetCompareMask(uint32_t value)
472   {
473     compareMask = value;
474     return *this;
475   }
476
477   auto& SetWriteMask(uint32_t value)
478   {
479     writeMask = value;
480     return *this;
481   }
482
483   auto& SetReference(uint32_t value)
484   {
485     reference = value;
486     return *this;
487   }
488 };
489
490 /**
491  * @brief Describes pipeline's viewport and scissor state
492  */
493 struct DepthStencilState
494 {
495   bool      depthTestEnable{false};
496   bool      depthWriteEnable{false};
497   CompareOp depthCompareOp{};
498
499   bool           stencilTestEnable{false};
500   StencilOpState front{};
501   StencilOpState back{};
502
503   auto& SetDepthTestEnable(bool value)
504   {
505     depthTestEnable = value;
506     return *this;
507   }
508
509   auto& SetDepthWriteEnable(bool value)
510   {
511     depthWriteEnable = value;
512     return *this;
513   }
514
515   auto& SetDepthCompareOp(CompareOp value)
516   {
517     depthCompareOp = value;
518     return *this;
519   }
520
521   auto& SetFront(StencilOpState value)
522   {
523     front = value;
524     return *this;
525   }
526
527   auto& SetBack(StencilOpState value)
528   {
529     back = value;
530     return *this;
531   }
532
533   auto& SetStencilTestEnable(bool value)
534   {
535     stencilTestEnable = value;
536     return *this;
537   }
538 };
539
540 /**
541  * @brief Rasterization state descriptor
542  */
543 struct RasterizationState
544 {
545   CullMode    cullMode{};
546   PolygonMode polygonMode{};
547   FrontFace   frontFace{};
548
549   auto& SetCullMode(CullMode value)
550   {
551     cullMode = value;
552     return *this;
553   }
554
555   auto& SetPolygonMode(PolygonMode value)
556   {
557     polygonMode = value;
558     return *this;
559   }
560
561   auto& SetFrontFace(FrontFace value)
562   {
563     frontFace = value;
564     return *this;
565   }
566 };
567
568 /**
569  * @brief Input assembly state descriptor.
570  *
571  * Structure describes the topology for submitted
572  * geometry.
573  */
574 struct InputAssemblyState
575 {
576   PrimitiveTopology topology{};
577   bool              primitiveRestartEnable{true};
578
579   auto& SetTopology(PrimitiveTopology value)
580   {
581     topology = value;
582     return *this;
583   }
584
585   auto& SetPrimitiveRestartEnable(bool value)
586   {
587     primitiveRestartEnable = true;
588     return *this;
589   }
590 };
591
592 /**
593  * @brief Pipeline dynamic state bits
594  */
595 namespace PipelineDynamicStateBits
596 {
597 const uint32_t VIEWPORT_BIT             = 1 << 0;
598 const uint32_t SCISSOR_BIT              = 1 << 1;
599 const uint32_t LINE_WIDTH_BIT           = 1 << 2;
600 const uint32_t DEPTH_BIAS_BIT           = 1 << 3;
601 const uint32_t BLEND_CONSTANTS_BIT      = 1 << 4;
602 const uint32_t DEPTH_BOUNDS_BIT         = 1 << 5;
603 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
604 const uint32_t STENCIL_WRITE_MASK_BIT   = 1 << 7;
605 const uint32_t STENCIL_REFERENCE_BIT    = 1 << 8;
606 } // namespace PipelineDynamicStateBits
607
608 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
609
610 using PipelineDynamicStateMask = uint32_t;
611
612 /**
613  * @brief Structure describes vertex input state of the pipeline.
614  * It specifies buffer binding and attribute format to be used.
615  */
616 struct VertexInputState
617 {
618   VertexInputState() = default;
619
620   /**
621    * @brief Vertex buffer binding
622    */
623   struct Binding
624   {
625     Binding(uint32_t _stride, VertexInputRate _inputRate)
626     : stride(_stride),
627       inputRate(_inputRate)
628     {
629     }
630     uint32_t        stride;
631     VertexInputRate inputRate;
632   };
633
634   /**
635    * @brief Attribute description
636    */
637   struct Attribute
638   {
639     Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
640     : location(_location),
641       binding(_binding),
642       offset(_offset),
643       format(_format)
644     {
645     }
646
647     uint32_t          location;
648     uint32_t          binding;
649     uint32_t          offset;
650     VertexInputFormat format;
651   };
652
653   VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
654   : bufferBindings(std::move(_bufferBindings)),
655     attributes(std::move(_attributes))
656   {
657   }
658
659   std::vector<Binding>   bufferBindings{};
660   std::vector<Attribute> attributes{};
661 };
662
663 /**
664  * @brief List of all possible formats
665  * Not all formats may be supported
666  */
667 enum class Format
668 {
669   UNDEFINED,
670   // GLES compatible, luminance doesn't exist in Vulkan
671   L8,
672   L8A8,
673
674   // Vulkan compatible
675   R4G4_UNORM_PACK8,
676   R4G4B4A4_UNORM_PACK16,
677   B4G4R4A4_UNORM_PACK16,
678   R5G6B5_UNORM_PACK16,
679   B5G6R5_UNORM_PACK16,
680   R5G5B5A1_UNORM_PACK16,
681   B5G5R5A1_UNORM_PACK16,
682   A1R5G5B5_UNORM_PACK16,
683   R8_UNORM,
684   R8_SNORM,
685   R8_USCALED,
686   R8_SSCALED,
687   R8_UINT,
688   R8_SINT,
689   R8_SRGB,
690   R8G8_UNORM,
691   R8G8_SNORM,
692   R8G8_USCALED,
693   R8G8_SSCALED,
694   R8G8_UINT,
695   R8G8_SINT,
696   R8G8_SRGB,
697   R8G8B8_UNORM,
698   R8G8B8_SNORM,
699   R8G8B8_USCALED,
700   R8G8B8_SSCALED,
701   R8G8B8_UINT,
702   R8G8B8_SINT,
703   R8G8B8_SRGB,
704   B8G8R8_UNORM,
705   B8G8R8_SNORM,
706   B8G8R8_USCALED,
707   B8G8R8_SSCALED,
708   B8G8R8_UINT,
709   B8G8R8_SINT,
710   B8G8R8_SRGB,
711   R8G8B8A8_UNORM,
712   R8G8B8A8_SNORM,
713   R8G8B8A8_USCALED,
714   R8G8B8A8_SSCALED,
715   R8G8B8A8_UINT,
716   R8G8B8A8_SINT,
717   R8G8B8A8_SRGB,
718   B8G8R8A8_UNORM,
719   B8G8R8A8_SNORM,
720   B8G8R8A8_USCALED,
721   B8G8R8A8_SSCALED,
722   B8G8R8A8_UINT,
723   B8G8R8A8_SINT,
724   B8G8R8A8_SRGB,
725   A8B8G8R8_UNORM_PACK32,
726   A8B8G8R8_SNORM_PACK32,
727   A8B8G8R8_USCALED_PACK32,
728   A8B8G8R8_SSCALED_PACK32,
729   A8B8G8R8_UINT_PACK32,
730   A8B8G8R8_SINT_PACK32,
731   A8B8G8R8_SRGB_PACK32,
732   A2R10G10B10_UNORM_PACK32,
733   A2R10G10B10_SNORM_PACK32,
734   A2R10G10B10_USCALED_PACK32,
735   A2R10G10B10_SSCALED_PACK32,
736   A2R10G10B10_UINT_PACK32,
737   A2R10G10B10_SINT_PACK32,
738   A2B10G10R10_UNORM_PACK32,
739   A2B10G10R10_SNORM_PACK32,
740   A2B10G10R10_USCALED_PACK32,
741   A2B10G10R10_SSCALED_PACK32,
742   A2B10G10R10_UINT_PACK32,
743   A2B10G10R10_SINT_PACK32,
744   R16_UNORM,
745   R16_SNORM,
746   R16_USCALED,
747   R16_SSCALED,
748   R16_UINT,
749   R16_SINT,
750   R16_SFLOAT,
751   R16G16_UNORM,
752   R16G16_SNORM,
753   R16G16_USCALED,
754   R16G16_SSCALED,
755   R16G16_UINT,
756   R16G16_SINT,
757   R16G16_SFLOAT,
758   R16G16B16_UNORM,
759   R16G16B16_SNORM,
760   R16G16B16_USCALED,
761   R16G16B16_SSCALED,
762   R16G16B16_UINT,
763   R16G16B16_SINT,
764   R16G16B16_SFLOAT,
765   R16G16B16A16_UNORM,
766   R16G16B16A16_SNORM,
767   R16G16B16A16_USCALED,
768   R16G16B16A16_SSCALED,
769   R16G16B16A16_UINT,
770   R16G16B16A16_SINT,
771   R16G16B16A16_SFLOAT,
772   R32_UINT,
773   R32_SINT,
774   R32_SFLOAT,
775   R32G32_UINT,
776   R32G32_SINT,
777   R32G32_SFLOAT,
778   R32G32B32_UINT,
779   R32G32B32_SINT,
780   R32G32B32_SFLOAT,
781   R32G32B32A32_UINT,
782   R32G32B32A32_SINT,
783   R32G32B32A32_SFLOAT,
784   R64_UINT,
785   R64_SINT,
786   R64_SFLOAT,
787   R64G64_UINT,
788   R64G64_SINT,
789   R64G64_SFLOAT,
790   R64G64B64_UINT,
791   R64G64B64_SINT,
792   R64G64B64_SFLOAT,
793   R64G64B64A64_UINT,
794   R64G64B64A64_SINT,
795   R64G64B64A64_SFLOAT,
796   R11G11B10_UFLOAT_PACK32,
797   B10G11R11_UFLOAT_PACK32,
798   E5B9G9R9_UFLOAT_PACK32,
799   D16_UNORM,
800   X8_D24_UNORM_PACK32,
801   D32_SFLOAT,
802   S8_UINT,
803   D16_UNORM_S8_UINT,
804   D24_UNORM_S8_UINT,
805   D32_SFLOAT_S8_UINT,
806   BC1_RGB_UNORM_BLOCK,
807   BC1_RGB_SRGB_BLOCK,
808   BC1_RGBA_UNORM_BLOCK,
809   BC1_RGBA_SRGB_BLOCK,
810   BC2_UNORM_BLOCK,
811   BC2_SRGB_BLOCK,
812   BC3_UNORM_BLOCK,
813   BC3_SRGB_BLOCK,
814   BC4_UNORM_BLOCK,
815   BC4_SNORM_BLOCK,
816   BC5_UNORM_BLOCK,
817   BC5_SNORM_BLOCK,
818   BC6H_UFLOAT_BLOCK,
819   BC6H_SFLOAT_BLOCK,
820   BC7_UNORM_BLOCK,
821   BC7_SRGB_BLOCK,
822   ETC2_R8G8B8_UNORM_BLOCK,
823   ETC2_R8G8B8_SRGB_BLOCK,
824   ETC2_R8G8B8A1_UNORM_BLOCK,
825   ETC2_R8G8B8A1_SRGB_BLOCK,
826   ETC2_R8G8B8A8_UNORM_BLOCK,
827   ETC2_R8G8B8A8_SRGB_BLOCK,
828   EAC_R11_UNORM_BLOCK,
829   EAC_R11_SNORM_BLOCK,
830   EAC_R11G11_UNORM_BLOCK,
831   EAC_R11G11_SNORM_BLOCK,
832   ASTC_4x4_UNORM_BLOCK,
833   ASTC_4x4_SRGB_BLOCK,
834   ASTC_5x4_UNORM_BLOCK,
835   ASTC_5x4_SRGB_BLOCK,
836   ASTC_5x5_UNORM_BLOCK,
837   ASTC_5x5_SRGB_BLOCK,
838   ASTC_6x5_UNORM_BLOCK,
839   ASTC_6x5_SRGB_BLOCK,
840   ASTC_6x6_UNORM_BLOCK,
841   ASTC_6x6_SRGB_BLOCK,
842   ASTC_8x5_UNORM_BLOCK,
843   ASTC_8x5_SRGB_BLOCK,
844   ASTC_8x6_UNORM_BLOCK,
845   ASTC_8x6_SRGB_BLOCK,
846   ASTC_8x8_UNORM_BLOCK,
847   ASTC_8x8_SRGB_BLOCK,
848   ASTC_10x5_UNORM_BLOCK,
849   ASTC_10x5_SRGB_BLOCK,
850   ASTC_10x6_UNORM_BLOCK,
851   ASTC_10x6_SRGB_BLOCK,
852   ASTC_10x8_UNORM_BLOCK,
853   ASTC_10x8_SRGB_BLOCK,
854   ASTC_10x10_UNORM_BLOCK,
855   ASTC_10x10_SRGB_BLOCK,
856   ASTC_12x10_UNORM_BLOCK,
857   ASTC_12x10_SRGB_BLOCK,
858   ASTC_12x12_UNORM_BLOCK,
859   ASTC_12x12_SRGB_BLOCK,
860   PVRTC1_2BPP_UNORM_BLOCK_IMG,
861   PVRTC1_4BPP_UNORM_BLOCK_IMG,
862   PVRTC2_2BPP_UNORM_BLOCK_IMG,
863   PVRTC2_4BPP_UNORM_BLOCK_IMG,
864   PVRTC1_2BPP_SRGB_BLOCK_IMG,
865   PVRTC1_4BPP_SRGB_BLOCK_IMG,
866   PVRTC2_2BPP_SRGB_BLOCK_IMG,
867   PVRTC2_4BPP_SRGB_BLOCK_IMG,
868 };
869
870 /**
871  * @brief Flags specifying a buffer usage
872  */
873 enum class BufferUsage
874 {
875   TRANSFER_SRC         = 1 << 0,
876   TRANSFER_DST         = 1 << 1,
877   UNIFORM_TEXEL_BUFFER = 1 << 2,
878   STORAGE_TEXEL_BUFFER = 1 << 3,
879   UNIFORM_BUFFER       = 1 << 4,
880   STORAGE_BUFFER       = 1 << 5,
881   INDEX_BUFFER         = 1 << 6,
882   VERTEX_BUFFER        = 1 << 7,
883   INDIRECT_BUFFER      = 1 << 8,
884 };
885
886 using BufferUsageFlags = uint32_t;
887
888 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
889 {
890   flags |= static_cast<uint32_t>(usage);
891   return flags;
892 }
893
894 /**
895  * @brief Buffer property bits
896  *
897  * Use these bits to set BufferPropertiesFlags.
898  */
899 enum class BufferPropertiesFlagBit : uint32_t
900 {
901   CPU_ALLOCATED    = 1 << 0, ///< Buffer is allocated on the CPU side
902   TRANSIENT_MEMORY = 1 << 1, ///< Buffer memory will be short-lived
903 };
904
905 /**
906  * @brief BufferPropetiesFlags alters behaviour of implementation
907  */
908 using BufferPropertiesFlags = uint32_t;
909
910 inline BufferPropertiesFlags operator|(BufferPropertiesFlags flags, BufferPropertiesFlagBit usage)
911 {
912   flags |= static_cast<uint32_t>(usage);
913   return flags;
914 }
915
916 /**
917  * @brief The structure describes memory requirements of GPU resource (texture, buffer)
918  */
919 struct MemoryRequirements
920 {
921   size_t size;
922   size_t alignment;
923 };
924
925 using TextureUpdateFlags = uint32_t;
926 enum class TextureUpdateFlagBits
927 {
928   KEEP_SOURCE = 1 << 0,
929 };
930
931 /**
932  * @brief Texture update info
933  *
934  * Describes the texture update to be executed by
935  * Controller::UpdateTextures()
936  */
937 struct TextureUpdateInfo
938 {
939   Texture* dstTexture{};
940   Offset2D dstOffset2D;
941   uint32_t layer{};
942   uint32_t level{};
943
944   uint32_t srcReference{};
945   Extent2D srcExtent2D{};
946   uint32_t srcOffset{};
947   uint32_t srcSize{};
948   uint32_t srcStride{};
949   Format   srcFormat{}; ///< Should match dstTexture's format, otherwise conversion may occur
950 };
951
952 /**
953  * @brief Texture update source info
954  *
955  * Describes the source of data (memory, buffer or another texture)
956  * to be used when updating textures using Controller::UpdateTextures().
957  */
958 struct TextureUpdateSourceInfo
959 {
960   enum class Type
961   {
962     BUFFER,
963     MEMORY,
964     TEXTURE
965   };
966
967   Type sourceType;
968
969   struct BufferSource
970   {
971     Buffer* buffer;
972   } bufferSource;
973
974   struct MemorySource
975   {
976     void* memory;
977   } memorySource;
978
979   struct TextureSource
980   {
981     Texture* texture;
982   } textureSource;
983 };
984
985 /**
986  * @brief Properties of texture
987  */
988 struct TextureProperties
989 {
990   Format   format;                   ///< Texture format
991   Format   format1;                  ///< Texture format (if emulated)
992   bool     emulated;                 ///< Format is emulated (for example RGB as RGBA)
993   bool     compressed;               ///< Texture is compressed
994   bool     packed;                   ///< Texture is packed
995   Extent2D extent2D;                 ///< Size of texture
996   bool     directWriteAccessEnabled; ///< Direct write access (mappable textures)
997   uint32_t nativeHandle;             ///< Native texture handle
998 };
999
1000 /**
1001  * @brief Texture tiling that directly refers to the tiling
1002  * mode supported by the Vulkan. Other implementations
1003  * of the backend may ignore the value.
1004  */
1005 enum class TextureTiling
1006 {
1007   OPTIMAL,
1008   LINEAR
1009 };
1010
1011 /**
1012  * @brief Texture color attachment used by FramebufferCreateInfo
1013  */
1014 struct ColorAttachment
1015 {
1016   uint32_t attachmentId;
1017   Texture* texture;
1018   uint32_t layerId;
1019   uint32_t levelId;
1020 };
1021
1022 /**
1023  * @brief Depth stencil attachment used by FramebufferCreateInfo
1024  */
1025 struct DepthStencilAttachment
1026 {
1027   enum class Usage
1028   {
1029     WRITE, // If no texture, will create a RenderBuffer instead
1030     NONE   // If no attachment/RenderBuffer required
1031   };
1032   Texture* depthTexture{nullptr};
1033   Texture* stencilTexture{nullptr};
1034   uint32_t depthLevel{0};
1035   uint32_t stencilLevel{0};
1036   Usage    depthUsage{Usage::NONE};
1037   Usage    stencilUsage{Usage::NONE};
1038 };
1039
1040 /**
1041  * @brief Submit flags
1042  */
1043 using SubmitFlags = uint32_t;
1044
1045 /**
1046  * Submit flag bits
1047  */
1048 enum class SubmitFlagBits : uint32_t
1049 {
1050   FLUSH         = 1 << 0, // Flush immediately
1051   DONT_OPTIMIZE = 1 << 1  // Tells controller not to optimize commands
1052 };
1053
1054 template<typename T>
1055 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
1056 {
1057   return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
1058 }
1059
1060 /**
1061  * @brief Describes command buffers submission
1062  */
1063 struct SubmitInfo
1064 {
1065   std::vector<CommandBuffer*> cmdBuffer;
1066   SubmitFlags                 flags;
1067 };
1068
1069 /**
1070  * @brief Shader language enum
1071  */
1072 enum class ShaderLanguage
1073 {
1074   GLSL_1,
1075   GLSL_3_1,
1076   GLSL_3_2,
1077   SPIRV_1_0,
1078   SPIRV_1_1,
1079 };
1080
1081 /**
1082  * @brief Pipeline stages
1083  */
1084 enum class PipelineStage
1085 {
1086   TOP_OF_PIPELINE,
1087   VERTEX_SHADER,
1088   GEOMETRY_SHADER,
1089   FRAGMENT_SHADER,
1090   COMPUTE_SHADER,
1091   TESSELATION_CONTROL,
1092   TESSELATION_EVALUATION,
1093   BOTTOM_OF_PIPELINE
1094 };
1095
1096 /**
1097  * @brief Vertex attribute format
1098  *
1099  * TODO: to be replaced with Format
1100  */
1101 enum class VertexInputAttributeFormat
1102 {
1103   UNDEFINED,
1104   FLOAT,
1105   INTEGER,
1106   VEC2,
1107   VEC3,
1108   VEC4
1109 };
1110
1111 /**
1112  * @brief Uniform class
1113  */
1114 enum class UniformClass
1115 {
1116   SAMPLER,
1117   IMAGE,
1118   COMBINED_IMAGE_SAMPLER,
1119   UNIFORM_BUFFER,
1120   UNIFORM,
1121   UNDEFINED
1122 };
1123
1124 /**
1125  * @brief Type of texture
1126  */
1127 enum class TextureType
1128 {
1129   TEXTURE_2D,
1130   TEXTURE_3D,
1131   TEXTURE_CUBEMAP,
1132 };
1133
1134 /**
1135  * @brief The information of the uniform
1136  */
1137 struct UniformInfo
1138 {
1139   std::string  name{""};
1140   UniformClass uniformClass{UniformClass::UNDEFINED};
1141   uint32_t     binding{0u};
1142   uint32_t     bufferIndex{0u};
1143   uint32_t     offset{0u};
1144   uint32_t     location{0u};
1145
1146   bool operator==(const UniformInfo& rhs)
1147   {
1148     return name == rhs.name &&
1149            uniformClass == rhs.uniformClass &&
1150            binding == rhs.binding &&
1151            bufferIndex == rhs.bufferIndex &&
1152            offset == rhs.offset &&
1153            location == rhs.location;
1154   }
1155 };
1156
1157 /**
1158  * @brief The information of the uniform block
1159  */
1160 struct UniformBlockInfo
1161 {
1162   std::string              name{""};
1163   uint32_t                 descriptorSet{0u};
1164   uint32_t                 binding{0u};
1165   uint32_t                 size{0u};
1166   std::vector<UniformInfo> members{};
1167 };
1168
1169 /**
1170  * @brief Describes pipeline's shading stages
1171  *
1172  * Shader state binds shader and pipeline stage that the
1173  * shader will be executed. The shader may be created with
1174  * pipeline stage and the pipelineStage member may be ignored
1175  * by setting inheritPipelineStage to true.
1176  */
1177 struct ShaderState
1178 {
1179   const Shader* shader{nullptr};             // shader to attach
1180   PipelineStage pipelineStage{};             // pipeline stage to execute the shader
1181   bool          inheritPipelineStage{false}; // stage inheritance
1182
1183   auto& SetShader(const Shader& value)
1184   {
1185     shader = &value;
1186     return *this;
1187   }
1188
1189   auto& SetPipelineStage(PipelineStage value)
1190   {
1191     pipelineStage = value;
1192     return *this;
1193   }
1194
1195   auto& SetInheritPipelineStage(bool value)
1196   {
1197     inheritPipelineStage = value;
1198     return *this;
1199   }
1200 };
1201
1202 /**
1203  * @brief Flag determining usage of texture
1204  */
1205 using TextureUsageFlags = uint32_t;
1206 enum class TextureUsageFlagBits : uint32_t
1207 {
1208   SAMPLE                   = 1 << 0,
1209   COLOR_ATTACHMENT         = 1 << 1,
1210   DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1211   DONT_CARE                = 1 << 4,
1212 };
1213
1214 template<typename T>
1215 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1216 {
1217   return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1218 }
1219
1220 using TextureFormat = Dali::Graphics::Format;
1221
1222 /**
1223  * @brief Texture mipmap disable/enable enum
1224  */
1225 enum class TextureMipMapFlag
1226 {
1227   ENABLED,
1228   DISABLED,
1229 };
1230
1231 /**
1232  * @brief Depth/stencil attachment flag
1233  */
1234 enum class TextureDepthStencilFlag
1235 {
1236   NONE,
1237   DEPTH,
1238   STENCIL,
1239   DEPTH_STENCIL,
1240 };
1241
1242 /**
1243  * @brief Layout of texture
1244  *
1245  * Specifies how the memory will be allocated, organized and accessed.
1246  */
1247 enum class TextureLayout
1248 {
1249   LINEAR, ///< Creates linear memory, mapping possible
1250   OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1251 };
1252
1253 /**
1254  * @brief Level of command buffer
1255  */
1256 enum class CommandBufferLevel
1257 {
1258   PRIMARY,  ///< Primary buffer can be executed on its own
1259   SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1260 };
1261
1262 /**
1263  * @brief Enum indicating whether shader source
1264  * is text-based or binary.
1265  */
1266 enum class ShaderSourceMode
1267 {
1268   TEXT,
1269   BINARY
1270 };
1271
1272 /**
1273  * @brief Memory usage flags to be set when mapping the buffer
1274  */
1275 using MemoryUsageFlags = uint32_t;
1276 enum class MemoryUsageFlagBits : uint32_t
1277 {
1278   WRITE        = 1 << 0,
1279   READ         = 1 << 1,
1280   PERSISTENT   = 1 << 2,
1281   ASYNCHRONOUS = 1 << 3,
1282   DONT_CARE    = 1 << 4,
1283 };
1284
1285 template<typename T>
1286 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1287 {
1288   return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1289 }
1290
1291 /**
1292  * @brief Describes buffer mapping details
1293  */
1294 struct MapBufferInfo
1295 {
1296   Buffer*          buffer;
1297   MemoryUsageFlags usage;
1298   uint32_t         offset;
1299   uint32_t         size;
1300 };
1301
1302 /**
1303  * @brief Describes buffer mapping details
1304  * TODO: mapping by texture level and layer
1305  */
1306 struct MapTextureInfo
1307 {
1308   Texture*         texture;
1309   MemoryUsageFlags usage;
1310   uint32_t         offset;
1311   uint32_t         size;
1312 };
1313
1314 /**
1315  * @brief GraphicsStructureType enum is used by all create info structures
1316  * in order to identify by the implementation which structure it is
1317  * dealing with.
1318  */
1319 enum class GraphicsStructureType : uint32_t
1320 {
1321   BUFFER_CREATE_INFO_STRUCT,
1322   COMMAND_BUFFER_CREATE_INFO_STRUCT,
1323   FRAMEBUFFER_CREATE_INFO_STRUCT,
1324   PROGRAM_CREATE_INFO_STRUCT,
1325   PIPELINE_CREATE_INFO_STRUCT,
1326   RENDERPASS_CREATE_INFO_STRUCT,
1327   SAMPLER_CREATE_INFO_STRUCT,
1328   SHADER_CREATE_INFO_STRUCT,
1329   TEXTURE_CREATE_INFO_STRUCT,
1330   RENDER_TARGET_CREATE_INFO_STRUCT,
1331   SYNC_OBJECT_CREATE_INFO_STRUCT
1332 };
1333
1334 /**
1335  * @brief Enum describes load operation associated
1336  * with particular framebuffer attachment
1337  */
1338 enum class AttachmentLoadOp
1339 {
1340   LOAD,     ///< Load previous content
1341   CLEAR,    ///< Clear the attachment
1342   DONT_CARE ///< Let driver decide
1343 };
1344
1345 /**
1346  * @brief Enum describes store operation associated
1347  * with particular framebuffer attachment
1348  */
1349 enum class AttachmentStoreOp
1350 {
1351   STORE,    ///< Store content (color attachemnts)
1352   DONT_CARE ///< Let driver decide (depth/stencil attachemnt with no intention of reading)
1353 };
1354
1355 /**
1356  * @brief The structure describes the read/write
1357  * modes of a single framebuffer attachment
1358  *
1359  * The attachment description specifies what is going to
1360  * happen to the attachment at the beginning and end of the
1361  * render pass.
1362  *
1363  * The stencil operation is separated as it may be set
1364  * independent from the depth component (use loadOp, storeOp
1365  * to set up the depth component and stencilLoadOp, stencilStoreOp
1366  * for stencil component).
1367  */
1368 struct AttachmentDescription
1369 {
1370   /**
1371    * @brief Sets load operation for the attachment
1372    *
1373    * @param value Load operation
1374    * @return this structure
1375    */
1376   auto& SetLoadOp(AttachmentLoadOp value)
1377   {
1378     loadOp = value;
1379     return *this;
1380   }
1381
1382   /**
1383    * @brief Sets store operation for the attachment
1384    *
1385    * @param value Store operation
1386    * @return this structure
1387    */
1388   auto& SetStoreOp(AttachmentStoreOp value)
1389   {
1390     storeOp = value;
1391     return *this;
1392   }
1393
1394   /**
1395    * @brief Sets load operation for the stencil part of attachment
1396    *
1397    * @param value load operation
1398    * @return this structure
1399    */
1400   auto& SetStencilLoadOp(AttachmentLoadOp value)
1401   {
1402     stencilLoadOp = value;
1403     return *this;
1404   }
1405
1406   /**
1407    * @brief Sets store operation for the stencil part of attachment
1408    *
1409    * @param value store operation
1410    * @return this structure
1411    */
1412   auto& SetStencilStoreOp(AttachmentStoreOp value)
1413   {
1414     stencilStoreOp = value;
1415     return *this;
1416   }
1417
1418   AttachmentLoadOp  loadOp{};
1419   AttachmentStoreOp storeOp{};
1420   AttachmentLoadOp  stencilLoadOp{};
1421   AttachmentStoreOp stencilStoreOp{};
1422 };
1423
1424 /**
1425  * @brief Helper function to be used by the extension developers
1426  *
1427  * The value of custom type must be unique and recognizable by the
1428  * implementation.
1429  *
1430  * @param customValue Custom value of GraphicsStructureType
1431  * @return Integer converted to GraphicsStructureType
1432  */
1433 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1434 {
1435   return static_cast<GraphicsStructureType>(customValue);
1436 }
1437
1438 /**
1439  * @brief The allocation callbacks may be passed when the object is created.
1440  */
1441 struct AllocationCallbacks
1442 {
1443   void* userData                                                                          = nullptr; ///< User data passed to the allocator
1444   void* (*allocCallback)(size_t size, size_t alignment, void* userData)                   = nullptr;
1445   void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1446   void (*freeCallback)(void* memory, void* userData)                                      = nullptr;
1447 };
1448
1449 /**
1450  * @brief The ExtensionCreateInfo structure should be a base of any
1451  * extension create info structure. The structure isn't virtual
1452  * so the implementation must prevent slicing it.
1453  */
1454 struct ExtensionCreateInfo
1455 {
1456   GraphicsStructureType type{};
1457   ExtensionCreateInfo*  nextExtension{};
1458 };
1459
1460 /**
1461  * @brief Default deleter for graphics unique pointers
1462  *
1463  * Returned unique_ptr may require custom deleter. To get it working
1464  * with std::unique_ptr the custom type is used with polymorphic deleter
1465  */
1466 template<class T>
1467 struct DefaultDeleter
1468 {
1469   DefaultDeleter() = default;
1470
1471   /**
1472    * @brief Conversion constructor
1473    *
1474    * This constructor will set the lambda for type passed
1475    * as an argument.
1476    */
1477   template<class P, template<typename> typename U>
1478   DefaultDeleter(const U<P>& deleter)
1479   {
1480     deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
1481   }
1482
1483   /**
1484    * @brief Conversion constructor from DefaultDelete<P>
1485    *
1486    * This constructor transfers deleteFunction only
1487    */
1488   template<class P>
1489   explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
1490   {
1491     deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
1492   }
1493
1494   /**
1495    * @brief Default deleter
1496    *
1497    * Default deleter will use standard 'delete' call in order
1498    * to discard graphics objects unless a custom deleter was
1499    * used.
1500    *
1501    * @param[in] object Object to delete
1502    */
1503   void operator()(T* object)
1504   {
1505     if(deleteFunction)
1506     {
1507       deleteFunction(object);
1508     }
1509     else
1510     {
1511       delete object;
1512     }
1513   }
1514
1515   void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
1516 };
1517
1518 /**
1519  * Surface type is just a void* to any native object.
1520  */
1521 using Surface = void;
1522
1523 /**
1524  * @brief Enum describing preTransform of render target
1525  */
1526 enum class RenderTargetTransformFlagBits
1527 {
1528   TRANSFORM_IDENTITY_BIT           = 0x00000001,
1529   ROTATE_90_BIT                    = 0x00000002,
1530   ROTATE_180_BIT                   = 0x00000004,
1531   ROTATE_270_BIT                   = 0x00000008,
1532   HORIZONTAL_MIRROR_BIT            = 0x00000010,
1533   HORIZONTAL_MIRROR_ROTATE_90_BIT  = 0x00000020,
1534   HORIZONTAL_MIRROR_ROTATE_180_BIT = 0x00000040,
1535   HORIZONTAL_MIRROR_ROTATE_270_BIT = 0x00000080,
1536 };
1537
1538 using RenderTargetTransformFlags = uint32_t;
1539
1540 template<typename T>
1541 inline RenderTargetTransformFlags operator|(T flags, RenderTargetTransformFlagBits bit)
1542 {
1543   return static_cast<RenderTargetTransformFlags>(flags) | static_cast<RenderTargetTransformFlags>(bit);
1544 }
1545
1546 /**
1547  * unique_ptr defined in the Graphics scope
1548  */
1549 template<class T, class D = DefaultDeleter<T>>
1550 using UniquePtr = std::unique_ptr<T, D>;
1551
1552 /**
1553  * @brief MakeUnique<> version that returns Graphics::UniquePtr
1554  * @param[in] args Arguments for construction
1555  * @return
1556  */
1557 template<class T, class Deleter = DefaultDeleter<T>, class... Args>
1558 std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
1559 MakeUnique(Args&&... args)
1560 {
1561   return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
1562 }
1563
1564 } // namespace Graphics
1565 } // namespace Dali
1566
1567 #endif //DALI_GRAPHICS_API_TYPES_H