[Tizen] Create Texture by ResourceId + Set Texture size and format internally.
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-texture-upload-helper.h
1 #ifndef DALI_GRAPHICS_TEXTURE_UPLOAD_INTERFACE_H
2 #define DALI_GRAPHICS_TEXTURE_UPLOAD_INTERFACE_H
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 <dali/public-api/rendering/texture.h>
23
24 // INTERNAL INCLUDES
25 #include "graphics-types.h"
26
27 namespace Dali
28 {
29 namespace Graphics
30 {
31 /**
32  * @brief Structure used to pass parameters to the Upload method
33  */
34 struct UploadParams
35 {
36   uint32_t dataXOffset; ///< Specifies a pixeldata offset in the x direction within the pixeldata buffer.
37   uint32_t dataYOffset; ///< Specifies a pixeldata offset in the y direction within the pixeldata buffer.
38   uint16_t dataWidth;   ///< Specifies the width of the pixeldata subimage.
39   uint16_t dataHeight;  ///< Specifies the height of the pixeldata subimage.
40   uint16_t layer;       ///< Specifies the layer of a cube map or array texture
41   uint16_t mipmap;      ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
42   uint16_t xOffset;     ///< Specifies a texel offset in the x direction within the texture array.
43   uint16_t yOffset;     ///< Specifies a texel offset in the y direction within the texture array.
44   uint16_t width;       ///< Specifies the width of the texture subimage
45   uint16_t height;      ///< Specifies the height of the texture subimage.
46 };
47
48 /**
49  * @brief Converts DALi pixel format to Graphics::Format.
50  * @param[in] format Dali::Pixel::Format.
51  * @return Converted Graphics::Format.
52  */
53 constexpr Graphics::Format ConvertPixelFormat(Dali::Pixel::Format format)
54 {
55   switch(format)
56   {
57     case Pixel::INVALID:
58       return Graphics::Format::UNDEFINED;
59     case Pixel::A8:
60       return Graphics::Format::R8_UNORM;
61
62     case Pixel::L8:
63       return Graphics::Format::L8;
64     case Pixel::LA88:
65       return Graphics::Format::L8A8;
66     case Pixel::RGB565:
67       return Graphics::Format::R5G6B5_UNORM_PACK16;
68     case Pixel::BGR565:
69       return Graphics::Format::B5G6R5_UNORM_PACK16;
70     case Pixel::RGBA4444:
71       return Graphics::Format::R4G4B4A4_UNORM_PACK16;
72
73     case Pixel::BGRA4444:
74       return Graphics::Format::B4G4R4A4_UNORM_PACK16;
75     case Pixel::RGBA5551:
76       return Graphics::Format::R5G5B5A1_UNORM_PACK16;
77     case Pixel::BGRA5551:
78       return Graphics::Format::B5G5R5A1_UNORM_PACK16;
79     case Pixel::RGB888:
80       return Graphics::Format::R8G8B8_UNORM;
81     case Pixel::RGB8888:
82       return Graphics::Format::R8G8B8A8_UNORM;
83     case Pixel::BGR8888:
84       return Graphics::Format::B8G8R8A8_UNORM;
85     case Pixel::RGBA8888:
86       return Graphics::Format::R8G8B8A8_UNORM;
87     case Pixel::BGRA8888:
88       return Graphics::Format::B8G8R8A8_UNORM;
89
90     case Pixel::DEPTH_UNSIGNED_INT:
91       return Graphics::Format::D16_UNORM;
92     case Pixel::DEPTH_FLOAT:
93       return Graphics::Format::D32_SFLOAT;
94     case Pixel::DEPTH_STENCIL:
95       return Graphics::Format::D24_UNORM_S8_UINT;
96
97     // EAC
98     case Pixel::COMPRESSED_R11_EAC:
99       return Graphics::Format::EAC_R11_UNORM_BLOCK;
100     case Pixel::COMPRESSED_SIGNED_R11_EAC:
101       return Graphics::Format::EAC_R11_SNORM_BLOCK;
102     case Pixel::COMPRESSED_RG11_EAC:
103       return Graphics::Format::EAC_R11G11_UNORM_BLOCK;
104     case Pixel::COMPRESSED_SIGNED_RG11_EAC:
105       return Graphics::Format::EAC_R11G11_SNORM_BLOCK;
106
107     // ETC
108     case Pixel::COMPRESSED_RGB8_ETC2:
109       return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK;
110     case Pixel::COMPRESSED_SRGB8_ETC2:
111       return Graphics::Format::ETC2_R8G8B8_SRGB_BLOCK;
112
113     case Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
114       return Graphics::Format::ETC2_R8G8B8A1_UNORM_BLOCK; // no 'punchthrough' format
115
116     case Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
117       return Graphics::Format::ETC2_R8G8B8A1_SRGB_BLOCK; // no 'punchthrough' format
118
119     case Pixel::COMPRESSED_RGBA8_ETC2_EAC:
120       return Graphics::Format::ETC2_R8G8B8A8_UNORM_BLOCK;
121
122     case Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
123       return Graphics::Format::ETC2_R8G8B8A8_SRGB_BLOCK;
124
125     case Pixel::COMPRESSED_RGB8_ETC1:
126       return Graphics::Format::ETC2_R8G8B8_UNORM_BLOCK; // doesn't seem to be supported at all
127
128     case Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
129       return Graphics::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG; // or SRGB?
130
131     // ASTC
132     case Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
133       return Graphics::Format::ASTC_4x4_UNORM_BLOCK; // or SRGB?
134     case Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
135       return Graphics::Format::ASTC_5x4_UNORM_BLOCK;
136     case Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
137       return Graphics::Format::ASTC_5x5_UNORM_BLOCK;
138     case Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
139       return Graphics::Format::ASTC_6x5_UNORM_BLOCK;
140     case Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
141       return Graphics::Format::ASTC_6x6_UNORM_BLOCK;
142     case Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
143       return Graphics::Format::ASTC_8x5_UNORM_BLOCK;
144     case Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
145       return Graphics::Format::ASTC_8x6_UNORM_BLOCK;
146     case Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
147       return Graphics::Format::ASTC_8x8_UNORM_BLOCK;
148     case Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
149       return Graphics::Format::ASTC_10x5_UNORM_BLOCK;
150     case Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
151       return Graphics::Format::ASTC_10x6_UNORM_BLOCK;
152     case Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
153       return Graphics::Format::ASTC_10x8_UNORM_BLOCK;
154     case Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
155       return Graphics::Format::ASTC_10x10_UNORM_BLOCK;
156     case Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
157       return Graphics::Format::ASTC_12x10_UNORM_BLOCK;
158     case Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
159       return Graphics::Format::ASTC_12x12_UNORM_BLOCK;
160     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
161       return Graphics::Format::ASTC_4x4_SRGB_BLOCK; // not type with alpha, but likely to use SRGB
162     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
163       return Graphics::Format::ASTC_5x4_SRGB_BLOCK;
164     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
165       return Graphics::Format::ASTC_5x5_SRGB_BLOCK;
166     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
167       return Graphics::Format::ASTC_6x5_SRGB_BLOCK;
168     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
169       return Graphics::Format::ASTC_6x6_SRGB_BLOCK;
170     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
171       return Graphics::Format::ASTC_8x5_SRGB_BLOCK;
172     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
173       return Graphics::Format::ASTC_8x6_UNORM_BLOCK;
174     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
175       return Graphics::Format::ASTC_8x8_SRGB_BLOCK;
176     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
177       return Graphics::Format::ASTC_10x5_SRGB_BLOCK;
178     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
179       return Graphics::Format::ASTC_10x6_SRGB_BLOCK;
180     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
181       return Graphics::Format::ASTC_10x8_SRGB_BLOCK;
182     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
183       return Graphics::Format::ASTC_10x10_SRGB_BLOCK;
184     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
185       return Graphics::Format::ASTC_12x10_SRGB_BLOCK;
186     case Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
187       return Graphics::Format::ASTC_12x12_SRGB_BLOCK;
188
189     case Pixel::RGB16F:
190       return Graphics::Format::R16G16B16_SFLOAT;
191     case Pixel::RGB32F:
192       return Graphics::Format::R32G32B32_SFLOAT;
193     case Pixel::R11G11B10F:
194       return Graphics::Format::R11G11B10_UFLOAT_PACK32;
195
196     case Pixel::CHROMINANCE_U:
197       return Graphics::Format::L8;
198     case Pixel::CHROMINANCE_V:
199       return Graphics::Format::L8;
200   }
201   return Graphics::Format::UNDEFINED;
202 }
203
204 /**
205  * @brief Converts DALi texture type to Graphics::TextureType.
206  *
207  * @param[in] type Dali::Texture::Type.
208  * @return converted Graphics::TextureType.
209  */
210 constexpr Graphics::TextureType ConvertTextureType(Dali::TextureType::Type type)
211 {
212   switch(type)
213   {
214     case Dali::TextureType::TEXTURE_2D:
215       return Graphics::TextureType::TEXTURE_2D;
216     case Dali::TextureType::TEXTURE_CUBE:
217       return Graphics::TextureType::TEXTURE_CUBEMAP;
218   }
219   return Graphics::TextureType::TEXTURE_2D;
220 }
221
222 } // namespace Graphics
223 } // namespace Dali
224
225 #endif // DALI_GRAPHICS_TEXTURE_UPLOAD_INTERFACE_H