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