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