Merge "Make property resetter age down correctly" into devel/master
[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     //@todo Add actual rate...
634   };
635
636   /**
637    * @brief Attribute description
638    */
639   struct Attribute
640   {
641     Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
642     : location(_location),
643       binding(_binding),
644       offset(_offset),
645       format(_format)
646     {
647     }
648
649     uint32_t          location;
650     uint32_t          binding;
651     uint32_t          offset;
652     VertexInputFormat format;
653   };
654
655   VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
656   : bufferBindings(std::move(_bufferBindings)),
657     attributes(std::move(_attributes))
658   {
659   }
660
661   std::vector<Binding>   bufferBindings{};
662   std::vector<Attribute> attributes{};
663 };
664
665 /**
666  * @brief List of all possible formats
667  * Not all formats may be supported
668  */
669 enum class Format
670 {
671   UNDEFINED,
672   // GLES compatible, luminance doesn't exist in Vulkan
673   L8,
674   L8A8,
675
676   // Vulkan compatible
677   R4G4_UNORM_PACK8,
678   R4G4B4A4_UNORM_PACK16,
679   B4G4R4A4_UNORM_PACK16,
680   R5G6B5_UNORM_PACK16,
681   B5G6R5_UNORM_PACK16,
682   R5G5B5A1_UNORM_PACK16,
683   B5G5R5A1_UNORM_PACK16,
684   A1R5G5B5_UNORM_PACK16,
685   R8_UNORM,
686   R8_SNORM,
687   R8_USCALED,
688   R8_SSCALED,
689   R8_UINT,
690   R8_SINT,
691   R8_SRGB,
692   R8G8_UNORM,
693   R8G8_SNORM,
694   R8G8_USCALED,
695   R8G8_SSCALED,
696   R8G8_UINT,
697   R8G8_SINT,
698   R8G8_SRGB,
699   R8G8B8_UNORM,
700   R8G8B8_SNORM,
701   R8G8B8_USCALED,
702   R8G8B8_SSCALED,
703   R8G8B8_UINT,
704   R8G8B8_SINT,
705   R8G8B8_SRGB,
706   B8G8R8_UNORM,
707   B8G8R8_SNORM,
708   B8G8R8_USCALED,
709   B8G8R8_SSCALED,
710   B8G8R8_UINT,
711   B8G8R8_SINT,
712   B8G8R8_SRGB,
713   R8G8B8A8_UNORM,
714   R8G8B8A8_SNORM,
715   R8G8B8A8_USCALED,
716   R8G8B8A8_SSCALED,
717   R8G8B8A8_UINT,
718   R8G8B8A8_SINT,
719   R8G8B8A8_SRGB,
720   B8G8R8A8_UNORM,
721   B8G8R8A8_SNORM,
722   B8G8R8A8_USCALED,
723   B8G8R8A8_SSCALED,
724   B8G8R8A8_UINT,
725   B8G8R8A8_SINT,
726   B8G8R8A8_SRGB,
727   A8B8G8R8_UNORM_PACK32,
728   A8B8G8R8_SNORM_PACK32,
729   A8B8G8R8_USCALED_PACK32,
730   A8B8G8R8_SSCALED_PACK32,
731   A8B8G8R8_UINT_PACK32,
732   A8B8G8R8_SINT_PACK32,
733   A8B8G8R8_SRGB_PACK32,
734   A2R10G10B10_UNORM_PACK32,
735   A2R10G10B10_SNORM_PACK32,
736   A2R10G10B10_USCALED_PACK32,
737   A2R10G10B10_SSCALED_PACK32,
738   A2R10G10B10_UINT_PACK32,
739   A2R10G10B10_SINT_PACK32,
740   A2B10G10R10_UNORM_PACK32,
741   A2B10G10R10_SNORM_PACK32,
742   A2B10G10R10_USCALED_PACK32,
743   A2B10G10R10_SSCALED_PACK32,
744   A2B10G10R10_UINT_PACK32,
745   A2B10G10R10_SINT_PACK32,
746   R16_UNORM,
747   R16_SNORM,
748   R16_USCALED,
749   R16_SSCALED,
750   R16_UINT,
751   R16_SINT,
752   R16_SFLOAT,
753   R16G16_UNORM,
754   R16G16_SNORM,
755   R16G16_USCALED,
756   R16G16_SSCALED,
757   R16G16_UINT,
758   R16G16_SINT,
759   R16G16_SFLOAT,
760   R16G16B16_UNORM,
761   R16G16B16_SNORM,
762   R16G16B16_USCALED,
763   R16G16B16_SSCALED,
764   R16G16B16_UINT,
765   R16G16B16_SINT,
766   R16G16B16_SFLOAT,
767   R16G16B16A16_UNORM,
768   R16G16B16A16_SNORM,
769   R16G16B16A16_USCALED,
770   R16G16B16A16_SSCALED,
771   R16G16B16A16_UINT,
772   R16G16B16A16_SINT,
773   R16G16B16A16_SFLOAT,
774   R32_UINT,
775   R32_SINT,
776   R32_SFLOAT,
777   R32G32_UINT,
778   R32G32_SINT,
779   R32G32_SFLOAT,
780   R32G32B32_UINT,
781   R32G32B32_SINT,
782   R32G32B32_SFLOAT,
783   R32G32B32A32_UINT,
784   R32G32B32A32_SINT,
785   R32G32B32A32_SFLOAT,
786   R64_UINT,
787   R64_SINT,
788   R64_SFLOAT,
789   R64G64_UINT,
790   R64G64_SINT,
791   R64G64_SFLOAT,
792   R64G64B64_UINT,
793   R64G64B64_SINT,
794   R64G64B64_SFLOAT,
795   R64G64B64A64_UINT,
796   R64G64B64A64_SINT,
797   R64G64B64A64_SFLOAT,
798   R11G11B10_UFLOAT_PACK32,
799   B10G11R11_UFLOAT_PACK32,
800   E5B9G9R9_UFLOAT_PACK32,
801   D16_UNORM,
802   X8_D24_UNORM_PACK32,
803   D32_SFLOAT,
804   S8_UINT,
805   D16_UNORM_S8_UINT,
806   D24_UNORM_S8_UINT,
807   D32_SFLOAT_S8_UINT,
808   BC1_RGB_UNORM_BLOCK,
809   BC1_RGB_SRGB_BLOCK,
810   BC1_RGBA_UNORM_BLOCK,
811   BC1_RGBA_SRGB_BLOCK,
812   BC2_UNORM_BLOCK,
813   BC2_SRGB_BLOCK,
814   BC3_UNORM_BLOCK,
815   BC3_SRGB_BLOCK,
816   BC4_UNORM_BLOCK,
817   BC4_SNORM_BLOCK,
818   BC5_UNORM_BLOCK,
819   BC5_SNORM_BLOCK,
820   BC6H_UFLOAT_BLOCK,
821   BC6H_SFLOAT_BLOCK,
822   BC7_UNORM_BLOCK,
823   BC7_SRGB_BLOCK,
824   ETC2_R8G8B8_UNORM_BLOCK,
825   ETC2_R8G8B8_SRGB_BLOCK,
826   ETC2_R8G8B8A1_UNORM_BLOCK,
827   ETC2_R8G8B8A1_SRGB_BLOCK,
828   ETC2_R8G8B8A8_UNORM_BLOCK,
829   ETC2_R8G8B8A8_SRGB_BLOCK,
830   EAC_R11_UNORM_BLOCK,
831   EAC_R11_SNORM_BLOCK,
832   EAC_R11G11_UNORM_BLOCK,
833   EAC_R11G11_SNORM_BLOCK,
834   ASTC_4x4_UNORM_BLOCK,
835   ASTC_4x4_SRGB_BLOCK,
836   ASTC_5x4_UNORM_BLOCK,
837   ASTC_5x4_SRGB_BLOCK,
838   ASTC_5x5_UNORM_BLOCK,
839   ASTC_5x5_SRGB_BLOCK,
840   ASTC_6x5_UNORM_BLOCK,
841   ASTC_6x5_SRGB_BLOCK,
842   ASTC_6x6_UNORM_BLOCK,
843   ASTC_6x6_SRGB_BLOCK,
844   ASTC_8x5_UNORM_BLOCK,
845   ASTC_8x5_SRGB_BLOCK,
846   ASTC_8x6_UNORM_BLOCK,
847   ASTC_8x6_SRGB_BLOCK,
848   ASTC_8x8_UNORM_BLOCK,
849   ASTC_8x8_SRGB_BLOCK,
850   ASTC_10x5_UNORM_BLOCK,
851   ASTC_10x5_SRGB_BLOCK,
852   ASTC_10x6_UNORM_BLOCK,
853   ASTC_10x6_SRGB_BLOCK,
854   ASTC_10x8_UNORM_BLOCK,
855   ASTC_10x8_SRGB_BLOCK,
856   ASTC_10x10_UNORM_BLOCK,
857   ASTC_10x10_SRGB_BLOCK,
858   ASTC_12x10_UNORM_BLOCK,
859   ASTC_12x10_SRGB_BLOCK,
860   ASTC_12x12_UNORM_BLOCK,
861   ASTC_12x12_SRGB_BLOCK,
862   PVRTC1_2BPP_UNORM_BLOCK_IMG,
863   PVRTC1_4BPP_UNORM_BLOCK_IMG,
864   PVRTC2_2BPP_UNORM_BLOCK_IMG,
865   PVRTC2_4BPP_UNORM_BLOCK_IMG,
866   PVRTC1_2BPP_SRGB_BLOCK_IMG,
867   PVRTC1_4BPP_SRGB_BLOCK_IMG,
868   PVRTC2_2BPP_SRGB_BLOCK_IMG,
869   PVRTC2_4BPP_SRGB_BLOCK_IMG,
870 };
871
872 /**
873  * @brief Flags specifying a buffer usage
874  */
875 enum class BufferUsage
876 {
877   TRANSFER_SRC         = 1 << 0,
878   TRANSFER_DST         = 1 << 1,
879   UNIFORM_TEXEL_BUFFER = 1 << 2,
880   STORAGE_TEXEL_BUFFER = 1 << 3,
881   UNIFORM_BUFFER       = 1 << 4,
882   STORAGE_BUFFER       = 1 << 5,
883   INDEX_BUFFER         = 1 << 6,
884   VERTEX_BUFFER        = 1 << 7,
885   INDIRECT_BUFFER      = 1 << 8,
886 };
887
888 using BufferUsageFlags = uint32_t;
889
890 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
891 {
892   flags |= static_cast<uint32_t>(usage);
893   return flags;
894 }
895
896 /**
897  * @brief Buffer property bits
898  *
899  * Use these bits to set BufferPropertiesFlags.
900  */
901 enum class BufferPropertiesFlagBit : uint32_t
902 {
903   CPU_ALLOCATED    = 1 << 0, ///< Buffer is allocated on the CPU side
904   TRANSIENT_MEMORY = 1 << 1, ///< Buffer memory will be short-lived
905 };
906
907 /**
908  * @brief BufferPropetiesFlags alters behaviour of implementation
909  */
910 using BufferPropertiesFlags = uint32_t;
911
912 inline BufferPropertiesFlags operator|(BufferPropertiesFlags flags, BufferPropertiesFlagBit usage)
913 {
914   flags |= static_cast<uint32_t>(usage);
915   return flags;
916 }
917
918 /**
919  * @brief The structure describes memory requirements of GPU resource (texture, buffer)
920  */
921 struct MemoryRequirements
922 {
923   size_t size{0u};
924   size_t alignment{1u};
925 };
926
927 using TextureUpdateFlags = uint32_t;
928 enum class TextureUpdateFlagBits
929 {
930   KEEP_SOURCE = 1 << 0,
931 };
932
933 /**
934  * @brief Texture update info
935  *
936  * Describes the texture update to be executed by
937  * Controller::UpdateTextures()
938  */
939 struct TextureUpdateInfo
940 {
941   Texture* dstTexture{};
942   Offset2D dstOffset2D;
943   uint32_t layer{};
944   uint32_t level{};
945
946   uint32_t srcReference{};
947   Extent2D srcExtent2D{};
948   uint32_t srcOffset{};
949   uint32_t srcSize{};
950   uint32_t srcStride{};
951   Format   srcFormat{}; ///< Should match dstTexture's format, otherwise conversion may occur
952 };
953
954 /**
955  * @brief Texture update source info
956  *
957  * Describes the source of data (memory, buffer or another texture)
958  * to be used when updating textures using Controller::UpdateTextures().
959  */
960 struct TextureUpdateSourceInfo
961 {
962   enum class Type
963   {
964     BUFFER,
965     MEMORY,
966     PIXEL_DATA,
967     TEXTURE
968   };
969
970   Type sourceType;
971
972   struct BufferSource
973   {
974     Buffer* buffer;
975   } bufferSource;
976
977   struct MemorySource
978   {
979     void* memory;
980   } memorySource;
981
982   struct PixelDataSource
983   {
984     Dali::PixelData pixelData;
985   } pixelDataSource;
986
987   struct TextureSource
988   {
989     Texture* texture;
990   } textureSource;
991 };
992
993 /**
994  * @brief Properties of texture
995  */
996 struct TextureProperties
997 {
998   Format   format;                   ///< Texture format
999   Format   format1;                  ///< Texture format (if emulated)
1000   bool     emulated;                 ///< Format is emulated (for example RGB as RGBA)
1001   bool     compressed;               ///< Texture is compressed
1002   bool     packed;                   ///< Texture is packed
1003   Extent2D extent2D;                 ///< Size of texture
1004   bool     directWriteAccessEnabled; ///< Direct write access (mappable textures)
1005   uint32_t nativeHandle;             ///< Native texture handle
1006 };
1007
1008 /**
1009  * @brief Texture tiling that directly refers to the tiling
1010  * mode supported by the Vulkan. Other implementations
1011  * of the backend may ignore the value.
1012  */
1013 enum class TextureTiling
1014 {
1015   OPTIMAL,
1016   LINEAR
1017 };
1018
1019 /**
1020  * @brief Texture color attachment used by FramebufferCreateInfo
1021  */
1022 struct ColorAttachment
1023 {
1024   uint32_t attachmentId;
1025   Texture* texture;
1026   uint32_t layerId;
1027   uint32_t levelId;
1028 };
1029
1030 /**
1031  * @brief Depth stencil attachment used by FramebufferCreateInfo
1032  */
1033 struct DepthStencilAttachment
1034 {
1035   enum class Usage
1036   {
1037     WRITE, // If no texture, will create a RenderBuffer instead
1038     NONE   // If no attachment/RenderBuffer required
1039   };
1040   Texture* depthTexture{nullptr};
1041   Texture* stencilTexture{nullptr};
1042   uint32_t depthLevel{0};
1043   uint32_t stencilLevel{0};
1044   Usage    depthUsage{Usage::NONE};
1045   Usage    stencilUsage{Usage::NONE};
1046 };
1047
1048 /**
1049  * @brief Submit flags
1050  */
1051 using SubmitFlags = uint32_t;
1052
1053 /**
1054  * Submit flag bits
1055  */
1056 enum class SubmitFlagBits : uint32_t
1057 {
1058   FLUSH         = 1 << 0, // Flush immediately
1059   DONT_OPTIMIZE = 1 << 1  // Tells controller not to optimize commands
1060 };
1061
1062 template<typename T>
1063 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
1064 {
1065   return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
1066 }
1067
1068 /**
1069  * @brief Describes command buffers submission
1070  */
1071 struct SubmitInfo
1072 {
1073   std::vector<CommandBuffer*> cmdBuffer;
1074   SubmitFlags                 flags;
1075 };
1076
1077 /**
1078  * @brief Shader language enum
1079  */
1080 enum class ShaderLanguage
1081 {
1082   GLSL_1,
1083   GLSL_3_1,
1084   GLSL_3_2,
1085   SPIRV_1_0,
1086   SPIRV_1_1,
1087 };
1088
1089 /**
1090  * @brief Pipeline stages
1091  */
1092 enum class PipelineStage
1093 {
1094   TOP_OF_PIPELINE,
1095   VERTEX_SHADER,
1096   GEOMETRY_SHADER,
1097   FRAGMENT_SHADER,
1098   COMPUTE_SHADER,
1099   TESSELATION_CONTROL,
1100   TESSELATION_EVALUATION,
1101   BOTTOM_OF_PIPELINE
1102 };
1103
1104 /**
1105  * @brief Vertex attribute format
1106  *
1107  * TODO: to be replaced with Format
1108  */
1109 enum class VertexInputAttributeFormat
1110 {
1111   UNDEFINED,
1112   FLOAT,
1113   INTEGER,
1114   VEC2,
1115   VEC3,
1116   VEC4
1117 };
1118
1119 /**
1120  * @brief Uniform class
1121  */
1122 enum class UniformClass
1123 {
1124   SAMPLER,
1125   IMAGE,
1126   COMBINED_IMAGE_SAMPLER,
1127   UNIFORM_BUFFER,
1128   UNIFORM,
1129   UNDEFINED
1130 };
1131
1132 /**
1133  * @brief Type of texture
1134  */
1135 enum class TextureType
1136 {
1137   TEXTURE_2D,
1138   TEXTURE_3D,
1139   TEXTURE_CUBEMAP,
1140 };
1141
1142 /**
1143  * @brief The information of the uniform
1144  */
1145 struct UniformInfo
1146 {
1147   std::string  name{""};
1148   UniformClass uniformClass{UniformClass::UNDEFINED};
1149   uint32_t     binding{0u};
1150   uint32_t     bufferIndex{0u};
1151   uint32_t     offset{0u};
1152   uint32_t     location{0u};
1153   uint32_t     elementCount{0u};
1154
1155   bool operator==(const UniformInfo& rhs)
1156   {
1157     return name == rhs.name &&
1158            uniformClass == rhs.uniformClass &&
1159            binding == rhs.binding &&
1160            bufferIndex == rhs.bufferIndex &&
1161            offset == rhs.offset &&
1162            location == rhs.location &&
1163            elementCount == rhs.elementCount;
1164   }
1165 };
1166
1167 /**
1168  * @brief The information of the uniform block
1169  */
1170 struct UniformBlockInfo
1171 {
1172   std::string              name{""};
1173   uint32_t                 descriptorSet{0u};
1174   uint32_t                 binding{0u};
1175   uint32_t                 size{0u};
1176   std::vector<UniformInfo> members{};
1177 };
1178
1179 /**
1180  * @brief Describes pipeline's shading stages
1181  *
1182  * Shader state binds shader and pipeline stage that the
1183  * shader will be executed. The shader may be created with
1184  * pipeline stage and the pipelineStage member may be ignored
1185  * by setting inheritPipelineStage to true.
1186  */
1187 struct ShaderState
1188 {
1189   const Shader* shader{nullptr};             // shader to attach
1190   PipelineStage pipelineStage{};             // pipeline stage to execute the shader
1191   bool          inheritPipelineStage{false}; // stage inheritance
1192
1193   auto& SetShader(const Shader& value)
1194   {
1195     shader = &value;
1196     return *this;
1197   }
1198
1199   auto& SetPipelineStage(PipelineStage value)
1200   {
1201     pipelineStage = value;
1202     return *this;
1203   }
1204
1205   auto& SetInheritPipelineStage(bool value)
1206   {
1207     inheritPipelineStage = value;
1208     return *this;
1209   }
1210 };
1211
1212 /**
1213  * @brief Flag determining usage of texture
1214  */
1215 using TextureUsageFlags = uint32_t;
1216 enum class TextureUsageFlagBits : uint32_t
1217 {
1218   SAMPLE                   = 1 << 0,
1219   COLOR_ATTACHMENT         = 1 << 1,
1220   DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1221   DONT_CARE                = 1 << 4,
1222 };
1223
1224 template<typename T>
1225 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1226 {
1227   return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1228 }
1229
1230 using TextureFormat = Dali::Graphics::Format;
1231
1232 /**
1233  * @brief Texture mipmap disable/enable enum
1234  */
1235 enum class TextureMipMapFlag
1236 {
1237   ENABLED,
1238   DISABLED,
1239 };
1240
1241 /**
1242  * @brief Depth/stencil attachment flag
1243  */
1244 enum class TextureDepthStencilFlag
1245 {
1246   NONE,
1247   DEPTH,
1248   STENCIL,
1249   DEPTH_STENCIL,
1250 };
1251
1252 /**
1253  * @brief Layout of texture
1254  *
1255  * Specifies how the memory will be allocated, organized and accessed.
1256  */
1257 enum class TextureLayout
1258 {
1259   LINEAR, ///< Creates linear memory, mapping possible
1260   OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1261 };
1262
1263 /**
1264  * @brief Texture allocation policy defines when the GPU texture memory is allocated.
1265  */
1266 enum class TextureAllocationPolicy
1267 {
1268   CREATION, ///< GPU Memory will be allocated when creation.
1269   UPLOAD,   ///< GPU Memory will be allocated when upload image data.
1270 };
1271
1272 /**
1273  * @brief Level of command buffer
1274  */
1275 enum class CommandBufferLevel
1276 {
1277   PRIMARY,  ///< Primary buffer can be executed on its own
1278   SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1279 };
1280
1281 /**
1282  * @brief Enum indicating whether shader source
1283  * is text-based or binary.
1284  */
1285 enum class ShaderSourceMode
1286 {
1287   TEXT,
1288   BINARY
1289 };
1290
1291 /**
1292  * @brief Memory usage flags to be set when mapping the buffer
1293  */
1294 using MemoryUsageFlags = uint32_t;
1295 enum class MemoryUsageFlagBits : uint32_t
1296 {
1297   WRITE        = 1 << 0,
1298   READ         = 1 << 1,
1299   PERSISTENT   = 1 << 2,
1300   ASYNCHRONOUS = 1 << 3,
1301   DONT_CARE    = 1 << 4,
1302 };
1303
1304 template<typename T>
1305 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1306 {
1307   return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1308 }
1309
1310 /**
1311  * @brief Describes buffer mapping details
1312  */
1313 struct MapBufferInfo
1314 {
1315   Buffer*          buffer;
1316   MemoryUsageFlags usage;
1317   uint32_t         offset;
1318   uint32_t         size;
1319 };
1320
1321 /**
1322  * @brief Describes buffer mapping details
1323  * TODO: mapping by texture level and layer
1324  */
1325 struct MapTextureInfo
1326 {
1327   Texture*         texture;
1328   MemoryUsageFlags usage;
1329   uint32_t         offset;
1330   uint32_t         size;
1331 };
1332
1333 /**
1334  * @brief GraphicsStructureType enum is used by all create info structures
1335  * in order to identify by the implementation which structure it is
1336  * dealing with.
1337  */
1338 enum class GraphicsStructureType : uint32_t
1339 {
1340   BUFFER_CREATE_INFO_STRUCT,
1341   COMMAND_BUFFER_CREATE_INFO_STRUCT,
1342   FRAMEBUFFER_CREATE_INFO_STRUCT,
1343   PROGRAM_CREATE_INFO_STRUCT,
1344   PIPELINE_CREATE_INFO_STRUCT,
1345   RENDERPASS_CREATE_INFO_STRUCT,
1346   SAMPLER_CREATE_INFO_STRUCT,
1347   SHADER_CREATE_INFO_STRUCT,
1348   TEXTURE_CREATE_INFO_STRUCT,
1349   RENDER_TARGET_CREATE_INFO_STRUCT,
1350   SYNC_OBJECT_CREATE_INFO_STRUCT
1351 };
1352
1353 /**
1354  * @brief Enum describes load operation associated
1355  * with particular framebuffer attachment
1356  */
1357 enum class AttachmentLoadOp
1358 {
1359   LOAD,     ///< Load previous content
1360   CLEAR,    ///< Clear the attachment
1361   DONT_CARE ///< Let driver decide
1362 };
1363
1364 /**
1365  * @brief Enum describes store operation associated
1366  * with particular framebuffer attachment
1367  */
1368 enum class AttachmentStoreOp
1369 {
1370   STORE,    ///< Store content (color attachemnts)
1371   DONT_CARE ///< Let driver decide (depth/stencil attachemnt with no intention of reading)
1372 };
1373
1374 /**
1375  * @brief The structure describes the read/write
1376  * modes of a single framebuffer attachment
1377  *
1378  * The attachment description specifies what is going to
1379  * happen to the attachment at the beginning and end of the
1380  * render pass.
1381  *
1382  * The stencil operation is separated as it may be set
1383  * independent from the depth component (use loadOp, storeOp
1384  * to set up the depth component and stencilLoadOp, stencilStoreOp
1385  * for stencil component).
1386  */
1387 struct AttachmentDescription
1388 {
1389   /**
1390    * @brief Sets load operation for the attachment
1391    *
1392    * @param value Load operation
1393    * @return this structure
1394    */
1395   auto& SetLoadOp(AttachmentLoadOp value)
1396   {
1397     loadOp = value;
1398     return *this;
1399   }
1400
1401   /**
1402    * @brief Sets store operation for the attachment
1403    *
1404    * @param value Store operation
1405    * @return this structure
1406    */
1407   auto& SetStoreOp(AttachmentStoreOp value)
1408   {
1409     storeOp = value;
1410     return *this;
1411   }
1412
1413   /**
1414    * @brief Sets load operation for the stencil part of attachment
1415    *
1416    * @param value load operation
1417    * @return this structure
1418    */
1419   auto& SetStencilLoadOp(AttachmentLoadOp value)
1420   {
1421     stencilLoadOp = value;
1422     return *this;
1423   }
1424
1425   /**
1426    * @brief Sets store operation for the stencil part of attachment
1427    *
1428    * @param value store operation
1429    * @return this structure
1430    */
1431   auto& SetStencilStoreOp(AttachmentStoreOp value)
1432   {
1433     stencilStoreOp = value;
1434     return *this;
1435   }
1436
1437   AttachmentLoadOp  loadOp{};
1438   AttachmentStoreOp storeOp{};
1439   AttachmentLoadOp  stencilLoadOp{};
1440   AttachmentStoreOp stencilStoreOp{};
1441 };
1442
1443 /**
1444  * @brief Helper function to be used by the extension developers
1445  *
1446  * The value of custom type must be unique and recognizable by the
1447  * implementation.
1448  *
1449  * @param customValue Custom value of GraphicsStructureType
1450  * @return Integer converted to GraphicsStructureType
1451  */
1452 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1453 {
1454   return static_cast<GraphicsStructureType>(customValue);
1455 }
1456
1457 /**
1458  * @brief The allocation callbacks may be passed when the object is created.
1459  */
1460 struct AllocationCallbacks
1461 {
1462   void* userData                                                                          = nullptr; ///< User data passed to the allocator
1463   void* (*allocCallback)(size_t size, size_t alignment, void* userData)                   = nullptr;
1464   void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1465   void (*freeCallback)(void* memory, void* userData)                                      = nullptr;
1466 };
1467
1468 /**
1469  * @brief The ExtensionCreateInfo structure should be a base of any
1470  * extension create info structure. The structure isn't virtual
1471  * so the implementation must prevent slicing it.
1472  */
1473 struct ExtensionCreateInfo
1474 {
1475   GraphicsStructureType type{};
1476   ExtensionCreateInfo*  nextExtension{};
1477 };
1478
1479 /**
1480  * @brief Default deleter for graphics unique pointers
1481  *
1482  * Returned unique_ptr may require custom deleter. To get it working
1483  * with std::unique_ptr the custom type is used with polymorphic deleter
1484  */
1485 template<class T>
1486 struct DefaultDeleter
1487 {
1488   DefaultDeleter() = default;
1489
1490   /**
1491    * @brief Conversion constructor
1492    *
1493    * This constructor will set the lambda for type passed
1494    * as an argument.
1495    */
1496   template<class P, template<typename> typename U>
1497   DefaultDeleter(const U<P>& deleter)
1498   {
1499     deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
1500   }
1501
1502   /**
1503    * @brief Conversion constructor from DefaultDelete<P>
1504    *
1505    * This constructor transfers deleteFunction only
1506    */
1507   template<class P>
1508   explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
1509   {
1510     deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
1511   }
1512
1513   /**
1514    * @brief Default deleter
1515    *
1516    * Default deleter will use standard 'delete' call in order
1517    * to discard graphics objects unless a custom deleter was
1518    * used.
1519    *
1520    * @param[in] object Object to delete
1521    */
1522   void operator()(T* object)
1523   {
1524     if(deleteFunction)
1525     {
1526       deleteFunction(object);
1527     }
1528     else
1529     {
1530       delete object;
1531     }
1532   }
1533
1534   void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
1535 };
1536
1537 /**
1538  * Surface type is just a void* to any native object.
1539  */
1540 using Surface = void;
1541
1542 /**
1543  * @brief Enum describing preTransform of render target
1544  */
1545 enum class RenderTargetTransformFlagBits
1546 {
1547   TRANSFORM_IDENTITY_BIT           = 0x00000001,
1548   ROTATE_90_BIT                    = 0x00000002,
1549   ROTATE_180_BIT                   = 0x00000004,
1550   ROTATE_270_BIT                   = 0x00000008,
1551   HORIZONTAL_MIRROR_BIT            = 0x00000010,
1552   HORIZONTAL_MIRROR_ROTATE_90_BIT  = 0x00000020,
1553   HORIZONTAL_MIRROR_ROTATE_180_BIT = 0x00000040,
1554   HORIZONTAL_MIRROR_ROTATE_270_BIT = 0x00000080,
1555 };
1556
1557 using RenderTargetTransformFlags = uint32_t;
1558
1559 template<typename T>
1560 inline RenderTargetTransformFlags operator|(T flags, RenderTargetTransformFlagBits bit)
1561 {
1562   return static_cast<RenderTargetTransformFlags>(flags) | static_cast<RenderTargetTransformFlags>(bit);
1563 }
1564
1565 /**
1566  * unique_ptr defined in the Graphics scope
1567  */
1568 template<class T, class D = DefaultDeleter<T>>
1569 using UniquePtr = std::unique_ptr<T, D>;
1570
1571 /**
1572  * @brief MakeUnique<> version that returns Graphics::UniquePtr
1573  * @param[in] args Arguments for construction
1574  * @return
1575  */
1576 template<class T, class Deleter = DefaultDeleter<T>, class... Args>
1577 std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
1578 MakeUnique(Args&&... args)
1579 {
1580   return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
1581 }
1582
1583 } // namespace Graphics
1584 } // namespace Dali
1585
1586 #endif //DALI_GRAPHICS_API_TYPES_H