1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup OH_NativeBuffer 18 * @{ 19 * 20 * @brief Provides the native buffer capability. 21 * 22 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 23 * @since 9 24 * @version 1.0 25 */ 26 27 /** 28 * @file native_buffer.h 29 * 30 * @brief Defines the functions for obtaining and using a native buffer. 31 * 32 * @library libnative_buffer.so 33 * @since 9 34 * @version 1.0 35 */ 36 37 #ifndef NDK_INCLUDE_NATIVE_BUFFER_H_ 38 #define NDK_INCLUDE_NATIVE_BUFFER_H_ 39 40 #include <stdint.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 struct OH_NativeBuffer; 47 typedef struct OH_NativeBuffer OH_NativeBuffer; 48 typedef struct NativeWindowBuffer OHNativeWindowBuffer; 49 50 /** 51 * @brief Indicates the usage of a native buffer. 52 * 53 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 54 * @since 10 55 * @version 1.0 56 */ 57 typedef enum OH_NativeBuffer_Usage { 58 NATIVEBUFFER_USAGE_CPU_READ = (1ULL << 0), /// < CPU read buffer */ 59 NATIVEBUFFER_USAGE_CPU_WRITE = (1ULL << 1), /// < CPU write memory */ 60 NATIVEBUFFER_USAGE_MEM_DMA = (1ULL << 3), /// < Direct memory access (DMA) buffer */ 61 /** 62 * MMZ with cache 63 * @since 20 64 */ 65 NATIVEBUFFER_USAGE_MEM_MMZ_CACHE = (1ULL << 5), 66 NATIVEBUFFER_USAGE_HW_RENDER = (1ULL << 8), /// < For GPU write case */ 67 NATIVEBUFFER_USAGE_HW_TEXTURE = (1ULL << 9), /// < For GPU read case */ 68 NATIVEBUFFER_USAGE_CPU_READ_OFTEN = (1ULL << 16), /// < Often be mapped for direct CPU reads */ 69 NATIVEBUFFER_USAGE_ALIGNMENT_512 = (1ULL << 18), /// < 512 bytes alignment */ 70 } OH_NativeBuffer_Usage; 71 72 /** 73 * @brief Indicates the format of a native buffer. 74 * 75 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 76 * @since 10 77 * @version 1.0 78 */ 79 typedef enum OH_NativeBuffer_Format { 80 /** 81 * CLUT8 format 82 * @since 12 83 */ 84 NATIVEBUFFER_PIXEL_FMT_CLUT8 = 0, 85 /** 86 * CLUT1 format 87 * @since 12 88 */ 89 NATIVEBUFFER_PIXEL_FMT_CLUT1, 90 /** 91 * CLUT4 format 92 * @since 12 93 */ 94 NATIVEBUFFER_PIXEL_FMT_CLUT4, 95 NATIVEBUFFER_PIXEL_FMT_RGB_565 = 3, /// < RGB565 format */ 96 NATIVEBUFFER_PIXEL_FMT_RGBA_5658, /// < RGBA5658 format */ 97 NATIVEBUFFER_PIXEL_FMT_RGBX_4444, /// < RGBX4444 format */ 98 NATIVEBUFFER_PIXEL_FMT_RGBA_4444, /// < RGBA4444 format */ 99 NATIVEBUFFER_PIXEL_FMT_RGB_444, /// < RGB444 format */ 100 NATIVEBUFFER_PIXEL_FMT_RGBX_5551, /// < RGBX5551 format */ 101 NATIVEBUFFER_PIXEL_FMT_RGBA_5551, /// < RGBA5551 format */ 102 NATIVEBUFFER_PIXEL_FMT_RGB_555, /// < RGB555 format */ 103 NATIVEBUFFER_PIXEL_FMT_RGBX_8888, /// < RGBX8888 format */ 104 NATIVEBUFFER_PIXEL_FMT_RGBA_8888, /// < RGBA8888 format */ 105 NATIVEBUFFER_PIXEL_FMT_RGB_888, /// < RGB888 format */ 106 NATIVEBUFFER_PIXEL_FMT_BGR_565, /// < BGR565 format */ 107 NATIVEBUFFER_PIXEL_FMT_BGRX_4444, /// < BGRX4444 format */ 108 NATIVEBUFFER_PIXEL_FMT_BGRA_4444, /// < BGRA4444 format */ 109 NATIVEBUFFER_PIXEL_FMT_BGRX_5551, /// < BGRX5551 format */ 110 NATIVEBUFFER_PIXEL_FMT_BGRA_5551, /// < BGRA5551 format */ 111 NATIVEBUFFER_PIXEL_FMT_BGRX_8888, /// < BGRX8888 format */ 112 NATIVEBUFFER_PIXEL_FMT_BGRA_8888, /// < BGRA8888 format */ 113 /** 114 * YUV422 interleaved format 115 * @since 12 116 */ 117 NATIVEBUFFER_PIXEL_FMT_YUV_422_I, 118 /** 119 * YCBCR422 semi-planar format 120 * @since 12 121 */ 122 NATIVEBUFFER_PIXEL_FMT_YCBCR_422_SP, 123 /** 124 * YCRCB422 semi-planar format 125 * @since 12 126 */ 127 NATIVEBUFFER_PIXEL_FMT_YCRCB_422_SP, 128 /** 129 * YCBCR420 semi-planar format 130 * @since 12 131 */ 132 NATIVEBUFFER_PIXEL_FMT_YCBCR_420_SP, 133 /** 134 * YCRCB420 semi-planar format 135 * @since 12 136 */ 137 NATIVEBUFFER_PIXEL_FMT_YCRCB_420_SP, 138 /** 139 * YCBCR422 planar format 140 * @since 12 141 */ 142 NATIVEBUFFER_PIXEL_FMT_YCBCR_422_P, 143 /** 144 * YCRCB422 planar format 145 * @since 12 146 */ 147 NATIVEBUFFER_PIXEL_FMT_YCRCB_422_P, 148 /** 149 * YCBCR420 planar format 150 * @since 12 151 */ 152 NATIVEBUFFER_PIXEL_FMT_YCBCR_420_P, 153 /** 154 * YCRCB420 planar format 155 * @since 12 156 */ 157 NATIVEBUFFER_PIXEL_FMT_YCRCB_420_P, 158 /** 159 * YUYV422 packed format 160 * @since 12 161 */ 162 NATIVEBUFFER_PIXEL_FMT_YUYV_422_PKG, 163 /** 164 * UYVY422 packed format 165 * @since 12 166 */ 167 NATIVEBUFFER_PIXEL_FMT_UYVY_422_PKG, 168 /** 169 * YVYU422 packed format 170 * @since 12 171 */ 172 NATIVEBUFFER_PIXEL_FMT_YVYU_422_PKG, 173 /** 174 * VYUY422 packed format 175 * @since 12 176 */ 177 NATIVEBUFFER_PIXEL_FMT_VYUY_422_PKG, 178 /** 179 * RGBA_1010102 packed format 180 * @since 12 181 */ 182 NATIVEBUFFER_PIXEL_FMT_RGBA_1010102, 183 /** 184 * YCBCR420 semi-planar 10bit packed format 185 * @since 12 186 */ 187 NATIVEBUFFER_PIXEL_FMT_YCBCR_P010, 188 /** 189 * YCRCB420 semi-planar 10bit packed format 190 * @since 12 191 */ 192 NATIVEBUFFER_PIXEL_FMT_YCRCB_P010, 193 /** 194 * Raw 10bit packed format 195 * @since 12 196 */ 197 NATIVEBUFFER_PIXEL_FMT_RAW10, 198 /** 199 * BLOB format 200 * @since 15 201 */ 202 NATIVEBUFFER_PIXEL_FMT_BLOB, 203 /** 204 * RGBA16 float format 205 * @since 15 206 */ 207 NATIVEBUFFER_PIXEL_FMT_RGBA16_FLOAT, 208 /** 209 * Y8 format 210 * @since 20 211 */ 212 NATIVEBUFFER_PIXEL_FMT_Y8 = 40, 213 /** 214 * Y16 format 215 * @since 20 216 */ 217 NATIVEBUFFER_PIXEL_FMT_Y16 = 41, 218 /** 219 * vendor mask format 220 * @since 12 221 */ 222 NATIVEBUFFER_PIXEL_FMT_VENDER_MASK = 0X7FFF0000, 223 NATIVEBUFFER_PIXEL_FMT_BUTT = 0X7FFFFFFF /// < Invalid pixel format */ 224 } OH_NativeBuffer_Format; 225 226 /** 227 * @brief Indicates the color space of a native buffer. 228 * 229 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 230 * @since 11 231 * @version 1.0 232 */ 233 typedef enum OH_NativeBuffer_ColorSpace { 234 /** None color space */ 235 OH_COLORSPACE_NONE, 236 /** COLORPRIMARIES_BT601_P | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_P << 16) | (RANGE_FULL << 21) */ 237 OH_COLORSPACE_BT601_EBU_FULL, 238 /** COLORPRIMARIES_BT601_N | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_N << 16) | (RANGE_FULL << 21)*/ 239 OH_COLORSPACE_BT601_SMPTE_C_FULL, 240 /** COLORPRIMARIES_BT709 | (TRANSFUNC_BT709 << 8) | (MATRIX_BT709 << 16) | (RANGE_FULL << 21) */ 241 OH_COLORSPACE_BT709_FULL, 242 /** COLORPRIMARIES_BT2020 | (TRANSFUNC_HLG << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */ 243 OH_COLORSPACE_BT2020_HLG_FULL, 244 /** COLORPRIMARIES_BT2020 | (TRANSFUNC_PQ << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */ 245 OH_COLORSPACE_BT2020_PQ_FULL, 246 /** COLORPRIMARIES_BT601_P | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_P << 16) | (RANGE_LIMITED << 21) */ 247 OH_COLORSPACE_BT601_EBU_LIMIT, 248 /** COLORPRIMARIES_BT601_N | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_N << 16) | (RANGE_LIMITED << 21) */ 249 OH_COLORSPACE_BT601_SMPTE_C_LIMIT, 250 /** COLORPRIMARIES_BT709 | (TRANSFUNC_BT709 << 8) | (MATRIX_BT709 << 16) | (RANGE_LIMITED << 21) */ 251 OH_COLORSPACE_BT709_LIMIT, 252 /** COLORPRIMARIES_BT2020 | (TRANSFUNC_HLG << 8) | (MATRIX_BT2020 << 16) | (RANGE_LIMITED << 21) */ 253 OH_COLORSPACE_BT2020_HLG_LIMIT, 254 /** COLORPRIMARIES_BT2020 | (TRANSFUNC_PQ << 8) | (MATRIX_BT2020 << 16) | (RANGE_LIMITED << 21) */ 255 OH_COLORSPACE_BT2020_PQ_LIMIT, 256 /** COLORPRIMARIES_SRGB | (TRANSFUNC_SRGB << 8) | (MATRIX_BT601_N << 16) | (RANGE_FULL << 21) */ 257 OH_COLORSPACE_SRGB_FULL, 258 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_SRGB << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */ 259 OH_COLORSPACE_P3_FULL, 260 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_HLG << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */ 261 OH_COLORSPACE_P3_HLG_FULL, 262 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_PQ << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */ 263 OH_COLORSPACE_P3_PQ_FULL, 264 /** COLORPRIMARIES_ADOBERGB | (TRANSFUNC_ADOBERGB << 8) | (MATRIX_ADOBERGB << 16) | (RANGE_FULL << 21) */ 265 OH_COLORSPACE_ADOBERGB_FULL, 266 /** COLORPRIMARIES_SRGB | (TRANSFUNC_SRGB << 8) | (MATRIX_BT601_N << 16) | (RANGE_LIMITED << 21) */ 267 OH_COLORSPACE_SRGB_LIMIT, 268 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_SRGB << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */ 269 OH_COLORSPACE_P3_LIMIT, 270 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_HLG << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */ 271 OH_COLORSPACE_P3_HLG_LIMIT, 272 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_PQ << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */ 273 OH_COLORSPACE_P3_PQ_LIMIT, 274 /** COLORPRIMARIES_ADOBERGB | (TRANSFUNC_ADOBERGB << 8) | (MATRIX_ADOBERGB << 16) | (RANGE_LIMITED << 21) */ 275 OH_COLORSPACE_ADOBERGB_LIMIT, 276 /** COLORPRIMARIES_SRGB | (TRANSFUNC_LINEAR << 8) */ 277 OH_COLORSPACE_LINEAR_SRGB, 278 /** equal to OH_COLORSPACE_LINEAR_SRGB */ 279 OH_COLORSPACE_LINEAR_BT709, 280 /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_LINEAR << 8) */ 281 OH_COLORSPACE_LINEAR_P3, 282 /** COLORPRIMARIES_BT2020 | (TRANSFUNC_LINEAR << 8) */ 283 OH_COLORSPACE_LINEAR_BT2020, 284 /** equal to OH_COLORSPACE_SRGB_FULL */ 285 OH_COLORSPACE_DISPLAY_SRGB, 286 /** equal to OH_COLORSPACE_P3_FULL */ 287 OH_COLORSPACE_DISPLAY_P3_SRGB, 288 /** equal to OH_COLORSPACE_P3_HLG_FULL */ 289 OH_COLORSPACE_DISPLAY_P3_HLG, 290 /** equal to OH_COLORSPACE_P3_PQ_FULL */ 291 OH_COLORSPACE_DISPLAY_P3_PQ, 292 /** COLORPRIMARIES_BT2020 | (TRANSFUNC_SRGB << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */ 293 OH_COLORSPACE_DISPLAY_BT2020_SRGB, 294 /** equal to OH_COLORSPACE_BT2020_HLG_FULL */ 295 OH_COLORSPACE_DISPLAY_BT2020_HLG, 296 /** equal to OH_COLORSPACE_BT2020_PQ_FULL */ 297 OH_COLORSPACE_DISPLAY_BT2020_PQ, 298 } OH_NativeBuffer_ColorSpace; 299 300 /** 301 * @brief Indicates the transform type of a native buffer. 302 * 303 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 304 * @since 12 305 * @version 1.0 306 */ 307 typedef enum OH_NativeBuffer_TransformType { 308 NATIVEBUFFER_ROTATE_NONE = 0, /**< No rotation */ 309 NATIVEBUFFER_ROTATE_90, /**< Rotation by 90 degrees */ 310 NATIVEBUFFER_ROTATE_180, /**< Rotation by 180 degrees */ 311 NATIVEBUFFER_ROTATE_270, /**< Rotation by 270 degrees */ 312 NATIVEBUFFER_FLIP_H, /**< Flip horizontally */ 313 NATIVEBUFFER_FLIP_V, /**< Flip vertically */ 314 NATIVEBUFFER_FLIP_H_ROT90, /**< Flip horizontally and rotate 90 degrees */ 315 NATIVEBUFFER_FLIP_V_ROT90, /**< Flip vertically and rotate 90 degrees */ 316 NATIVEBUFFER_FLIP_H_ROT180, /**< Flip horizontally and rotate 180 degrees */ 317 NATIVEBUFFER_FLIP_V_ROT180, /**< Flip vertically and rotate 180 degrees */ 318 NATIVEBUFFER_FLIP_H_ROT270, /**< Flip horizontally and rotate 270 degrees */ 319 NATIVEBUFFER_FLIP_V_ROT270, /**< Flip vertically and rotate 270 degrees */ 320 } OH_NativeBuffer_TransformType; 321 322 /** 323 * @brief Indicates the color gamut of a native buffer. 324 * 325 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 326 * @since 12 327 * @version 1.0 328 */ 329 typedef enum OH_NativeBuffer_ColorGamut { 330 NATIVEBUFFER_COLOR_GAMUT_NATIVE = 0, /**< Native or default */ 331 NATIVEBUFFER_COLOR_GAMUT_STANDARD_BT601 = 1, /**< Standard BT601 */ 332 NATIVEBUFFER_COLOR_GAMUT_STANDARD_BT709 = 2, /**< Standard BT709 */ 333 NATIVEBUFFER_COLOR_GAMUT_DCI_P3 = 3, /**< DCI P3 */ 334 NATIVEBUFFER_COLOR_GAMUT_SRGB = 4, /**< SRGB */ 335 NATIVEBUFFER_COLOR_GAMUT_ADOBE_RGB = 5, /**< Adobe RGB */ 336 NATIVEBUFFER_COLOR_GAMUT_DISPLAY_P3 = 6, /**< Display P3 */ 337 NATIVEBUFFER_COLOR_GAMUT_BT2020 = 7, /**< BT2020 */ 338 NATIVEBUFFER_COLOR_GAMUT_BT2100_PQ = 8, /**< BT2100 PQ */ 339 NATIVEBUFFER_COLOR_GAMUT_BT2100_HLG = 9, /**< BT2100 HLG */ 340 NATIVEBUFFER_COLOR_GAMUT_DISPLAY_BT2020 = 10, /**< Display BT2020 */ 341 } OH_NativeBuffer_ColorGamut; 342 343 /** 344 * @brief <b>OH_NativeBuffer</b> config. \n 345 * Used to allocating new <b>OH_NativeBuffer</b> and query parameters if existing ones. 346 * 347 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 348 * @since 9 349 * @version 1.0 350 */ 351 typedef struct { 352 int32_t width; ///< Width in pixels 353 int32_t height; ///< Height in pixels 354 int32_t format; ///< One of PixelFormat 355 int32_t usage; ///< Combination of buffer usage 356 int32_t stride; ///< the stride of memory in bytes 357 } OH_NativeBuffer_Config; 358 359 /** 360 * @brief Holds info for a single image plane. \n 361 * 362 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 363 * @since 12 364 * @version 1.0 365 */ 366 typedef struct { 367 /** 368 * Offset in bytes of plane. 369 */ 370 uint64_t offset; 371 /** 372 * Distance in bytes from the first value of one row of the image to the first value of the next row. 373 */ 374 uint32_t rowStride; 375 /** 376 * Distance in bytes from the first value of one column of the image to the first value of the next column. 377 */ 378 uint32_t columnStride; 379 } OH_NativeBuffer_Plane; 380 381 /** 382 * @brief Holds all image plane. \n 383 * 384 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 385 * @since 12 386 * @version 1.0 387 */ 388 typedef struct { 389 uint32_t planeCount; ///< Number of distinct planes. 390 OH_NativeBuffer_Plane planes[4]; ///< Array of image planes. 391 } OH_NativeBuffer_Planes; 392 393 /** 394 * @brief Indicates the HDR metadata type of a native buffer. 395 * 396 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 397 * @since 12 398 * @version 1.0 399 */ 400 typedef enum OH_NativeBuffer_MetadataType { 401 OH_VIDEO_HDR_HLG, /**< HLG */ 402 OH_VIDEO_HDR_HDR10, /**< HDR10 */ 403 OH_VIDEO_HDR_VIVID, /**< HDR VIVID */ 404 OH_VIDEO_NONE /**< NONE Metadata */ 405 } OH_NativeBuffer_MetadataType; 406 407 /** 408 * @brief Indicates the color x and y. 409 * 410 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 411 * @since 12 412 * @version 1.0 413 */ 414 typedef struct { 415 float x; /**< color X */ 416 float y; /**< color Y */ 417 } OH_NativeBuffer_ColorXY; 418 419 /** 420 * @brief Indicates the smpte2086 metadata. 421 * 422 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 423 * @since 12 424 * @version 1.0 425 */ 426 typedef struct { 427 OH_NativeBuffer_ColorXY displaPrimaryRed; /**< primary red */ 428 OH_NativeBuffer_ColorXY displaPrimaryGreen; /**< primary green */ 429 OH_NativeBuffer_ColorXY displaPrimaryBlue; /**< primary blue */ 430 OH_NativeBuffer_ColorXY whitePoint; /**< white point */ 431 float maxLuminance; /**< max luminance */ 432 float minLuminance; /**< min luminance */ 433 } OH_NativeBuffer_Smpte2086; 434 435 /** 436 * @brief Indicates the cta861.3 metadata. 437 * 438 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 439 * @since 12 440 * @version 1.0 441 */ 442 typedef struct { 443 float maxContentLightLevel; /**< max content lightLevel */ 444 float maxFrameAverageLightLevel; /**< max frame average light level */ 445 } OH_NativeBuffer_Cta861; 446 447 /** 448 * @brief Indicates the HDR static metadata. 449 * 450 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 451 * @since 12 452 * @version 1.0 453 */ 454 typedef struct { 455 OH_NativeBuffer_Smpte2086 smpte2086; /**< smpte 2086 metadata*/ 456 OH_NativeBuffer_Cta861 cta861; /**< CTA-861.3 metadata*/ 457 } OH_NativeBuffer_StaticMetadata; 458 459 /** 460 * @brief Indicates the HDR metadata key of a native buffer. 461 * 462 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 463 * @since 12 464 * @version 1.0 465 */ 466 typedef enum OH_NativeBuffer_MetadataKey { 467 OH_HDR_METADATA_TYPE, /**< value: OH_NativeBuffer_MetadataType*/ 468 OH_HDR_STATIC_METADATA, /**< value: OH_NativeBuffer_StaticMetadata*/ 469 OH_HDR_DYNAMIC_METADATA /**< byte stream of SEI in video stream*/ 470 } OH_NativeBuffer_MetadataKey; 471 472 /** 473 * @brief Alloc a <b>OH_NativeBuffer</b> that matches the passed BufferRequestConfig. \n 474 * A new <b>OH_NativeBuffer</b> instance is created each time this function is called. 475 * 476 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 477 * @param config Indicates the pointer to a <b>BufferRequestConfig</b> instance. 478 * @return Returns the pointer to the <b>OH_NativeBuffer</b> instance created if the operation is successful, \n 479 * returns <b>NULL</b> otherwise. 480 * @since 9 481 * @version 1.0 482 */ 483 OH_NativeBuffer* OH_NativeBuffer_Alloc(const OH_NativeBuffer_Config* config); 484 485 /** 486 * @brief Adds the reference count of a OH_NativeBuffer. 487 * 488 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 489 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 490 * @return Returns an error code, 0 is success, otherwise, failed. 491 * @since 9 492 * @version 1.0 493 */ 494 int32_t OH_NativeBuffer_Reference(OH_NativeBuffer *buffer); 495 496 /** 497 * @brief Decreases the reference count of a OH_NativeBuffer and, when the reference count reaches 0, \n 498 * destroys this OH_NativeBuffer. 499 * 500 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 501 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 502 * @return Returns an error code, 0 is success, otherwise, failed. 503 * @since 9 504 * @version 1.0 505 */ 506 int32_t OH_NativeBuffer_Unreference(OH_NativeBuffer *buffer); 507 508 /** 509 * @brief Return a config of the OH_NativeBuffer in the passed OHNativeBufferConfig struct. 510 * 511 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 512 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 513 * @param config Indicates the pointer to the <b>NativeBufferConfig</b> of the buffer. 514 * @return <b>void</b> 515 * @since 9 516 * @version 1.0 517 */ 518 void OH_NativeBuffer_GetConfig(OH_NativeBuffer *buffer, OH_NativeBuffer_Config* config); 519 520 /** 521 * @brief Provide direct cpu access to the OH_NativeBuffer in the process's address space. 522 * 523 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 524 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 525 * @param virAddr Indicates the address of the <b>OH_NativeBuffer</b> in virtual memory. 526 * @return Returns an error code, 0 is success, otherwise, failed. 527 * @since 9 528 * @version 1.0 529 */ 530 531 int32_t OH_NativeBuffer_Map(OH_NativeBuffer *buffer, void **virAddr); 532 533 /** 534 * @brief Remove direct cpu access ability of the OH_NativeBuffer in the process's address space. 535 * 536 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 537 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 538 * @return Returns an error code, 0 is success, otherwise, failed. 539 * @since 9 540 * @version 1.0 541 */ 542 int32_t OH_NativeBuffer_Unmap(OH_NativeBuffer *buffer); 543 544 /** 545 * @brief Get the systen wide unique sequence number of the OH_NativeBuffer. 546 * 547 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 548 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 549 * @return Returns the sequence number, which is unique for each OH_NativeBuffer. 550 * @since 9 551 * @version 1.0 552 */ 553 uint32_t OH_NativeBuffer_GetSeqNum(OH_NativeBuffer *buffer); 554 555 /** 556 * @brief Provide direct cpu access to the potentially multi-planar OH_NativeBuffer in the process's address space. 557 * 558 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 559 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 560 * @param virAddr Indicates the address of the <b>OH_NativeBuffer</b> in virtual memory. 561 * @param outPlanes Indicates all image planes that contain the pixel data. 562 * @return Returns an error code, 0 is success, otherwise, failed. 563 * @since 12 564 * @version 1.0 565 */ 566 int32_t OH_NativeBuffer_MapPlanes(OH_NativeBuffer *buffer, void **virAddr, OH_NativeBuffer_Planes *outPlanes); 567 568 /** 569 * @brief Converts an <b>OHNativeWindowBuffer</b> instance to an <b>OH_NativeBuffer</b>. 570 * 571 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 572 * @param nativeWindowBuffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 573 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> pointer. 574 * @return Returns an error code, 0 is success, otherwise, failed. 575 * @since 12 576 * @version 1.0 577 */ 578 int32_t OH_NativeBuffer_FromNativeWindowBuffer(OHNativeWindowBuffer *nativeWindowBuffer, OH_NativeBuffer **buffer); 579 580 /** 581 * @brief Set the color space of the OH_NativeBuffer. 582 * 583 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 584 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 585 * @param colorSpace Indicates the color space of native buffer, see <b>OH_NativeBuffer_ColorSpace</b>. 586 * @return Returns an error code, 0 is success, otherwise, failed. 587 * @since 11 588 * @version 1.0 589 */ 590 int32_t OH_NativeBuffer_SetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_ColorSpace colorSpace); 591 592 /** 593 * @brief Get the color space of the OH_NativeBuffer. 594 * 595 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 596 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 597 * @param colorSpace Indicates the color space of native buffer, see <b>OH_NativeBuffer_ColorSpace</b>. 598 * @return {@link NATIVE_ERROR_OK} 0 - Success. 599 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - buffer is NULL. 600 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect colorSpace state. 601 * @since 12 602 * @version 1.0 603 */ 604 int32_t OH_NativeBuffer_GetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_ColorSpace *colorSpace); 605 606 /** 607 * @brief Set the metadata type of the OH_NativeBuffer. 608 * 609 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 610 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 611 * @param metadataKey Indicates the metadata type of native buffer, see <b>OH_NativeBuffer_MetadataKey</b>. 612 * @param size Indicates the size of a uint8_t vector. 613 * @param metadata Indicates the pointer to a uint8_t vector. 614 * @return {@link NATIVE_ERROR_OK} 0 - Success. 615 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - buffer or metadata is NULL. 616 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state. 617 * {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key. 618 * @since 12 619 * @version 1.0 620 */ 621 int32_t OH_NativeBuffer_SetMetadataValue(OH_NativeBuffer *buffer, OH_NativeBuffer_MetadataKey metadataKey, 622 int32_t size, uint8_t *metadata); 623 624 /** 625 * @brief Set the metadata type of the OH_NativeBuffer. 626 * 627 * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer 628 * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance. 629 * @param metadataKey Indicates the metadata type of native buffer, see <b>OH_NativeBuffer_MetadataKey</b>. 630 * @param size Indicates the size of a uint8_t vector. 631 * @param metadata Indicates the pointer to a uint8_t vector. 632 * @return {@link NATIVE_ERROR_OK} 0 - Success. 633 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - buffer, metadata, or size is NULL. 634 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state. 635 * {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key. 636 * @since 12 637 * @version 1.0 638 */ 639 int32_t OH_NativeBuffer_GetMetadataValue(OH_NativeBuffer *buffer, OH_NativeBuffer_MetadataKey metadataKey, 640 int32_t *size, uint8_t **metadata); 641 #ifdef __cplusplus 642 } 643 #endif 644 645 /** @} */ 646 #endif