• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      * BLOB format
195      * @since 15
196      */
197     NATIVEBUFFER_PIXEL_FMT_BLOB,
198     /**
199      * RGBA16 float format
200      * @since 15
201      */
202     NATIVEBUFFER_PIXEL_FMT_RGBA16_FLOAT,
203     /**
204      * vender mask format
205      * @since 12
206      */
207     NATIVEBUFFER_PIXEL_FMT_VENDER_MASK = 0X7FFF0000,
208     NATIVEBUFFER_PIXEL_FMT_BUTT = 0X7FFFFFFF          /// < Invalid pixel format */
209 } OH_NativeBuffer_Format;
210 
211 /**
212  * @brief Indicates the color space of a native buffer.
213  *
214  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
215  * @since 11
216  * @version 1.0
217  */
218 typedef enum OH_NativeBuffer_ColorSpace {
219     /** None color space */
220     OH_COLORSPACE_NONE,
221     /** COLORPRIMARIES_BT601_P | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_P << 16) | (RANGE_FULL << 21) */
222     OH_COLORSPACE_BT601_EBU_FULL,
223     /** COLORPRIMARIES_BT601_N | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_N << 16) | (RANGE_FULL << 21)*/
224     OH_COLORSPACE_BT601_SMPTE_C_FULL,
225     /** COLORPRIMARIES_BT709 | (TRANSFUNC_BT709 << 8) | (MATRIX_BT709 << 16) | (RANGE_FULL << 21) */
226     OH_COLORSPACE_BT709_FULL,
227     /** COLORPRIMARIES_BT2020 | (TRANSFUNC_HLG << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */
228     OH_COLORSPACE_BT2020_HLG_FULL,
229     /** COLORPRIMARIES_BT2020 | (TRANSFUNC_PQ << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */
230     OH_COLORSPACE_BT2020_PQ_FULL,
231     /** COLORPRIMARIES_BT601_P | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_P << 16) | (RANGE_LIMITED << 21) */
232     OH_COLORSPACE_BT601_EBU_LIMIT,
233     /** COLORPRIMARIES_BT601_N | (TRANSFUNC_BT709 << 8) | (MATRIX_BT601_N << 16) | (RANGE_LIMITED << 21) */
234     OH_COLORSPACE_BT601_SMPTE_C_LIMIT,
235     /** COLORPRIMARIES_BT709 | (TRANSFUNC_BT709 << 8) | (MATRIX_BT709 << 16) | (RANGE_LIMITED << 21) */
236     OH_COLORSPACE_BT709_LIMIT,
237     /** COLORPRIMARIES_BT2020 | (TRANSFUNC_HLG << 8) | (MATRIX_BT2020 << 16) | (RANGE_LIMITED << 21) */
238     OH_COLORSPACE_BT2020_HLG_LIMIT,
239     /** COLORPRIMARIES_BT2020 | (TRANSFUNC_PQ << 8) | (MATRIX_BT2020 << 16) | (RANGE_LIMITED << 21) */
240     OH_COLORSPACE_BT2020_PQ_LIMIT,
241     /** COLORPRIMARIES_SRGB | (TRANSFUNC_SRGB << 8) | (MATRIX_BT601_N << 16) | (RANGE_FULL << 21) */
242     OH_COLORSPACE_SRGB_FULL,
243     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_SRGB << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */
244     OH_COLORSPACE_P3_FULL,
245     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_HLG << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */
246     OH_COLORSPACE_P3_HLG_FULL,
247     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_PQ << 8) | (MATRIX_P3 << 16) | (RANGE_FULL << 21) */
248     OH_COLORSPACE_P3_PQ_FULL,
249     /** COLORPRIMARIES_ADOBERGB | (TRANSFUNC_ADOBERGB << 8) | (MATRIX_ADOBERGB << 16) | (RANGE_FULL << 21) */
250     OH_COLORSPACE_ADOBERGB_FULL,
251     /** COLORPRIMARIES_SRGB | (TRANSFUNC_SRGB << 8) | (MATRIX_BT601_N << 16) | (RANGE_LIMITED << 21) */
252     OH_COLORSPACE_SRGB_LIMIT,
253     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_SRGB << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */
254     OH_COLORSPACE_P3_LIMIT,
255     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_HLG << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */
256     OH_COLORSPACE_P3_HLG_LIMIT,
257     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_PQ << 8) | (MATRIX_P3 << 16) | (RANGE_LIMITED << 21) */
258     OH_COLORSPACE_P3_PQ_LIMIT,
259     /** COLORPRIMARIES_ADOBERGB | (TRANSFUNC_ADOBERGB << 8) | (MATRIX_ADOBERGB << 16) | (RANGE_LIMITED << 21) */
260     OH_COLORSPACE_ADOBERGB_LIMIT,
261     /** COLORPRIMARIES_SRGB | (TRANSFUNC_LINEAR << 8) */
262     OH_COLORSPACE_LINEAR_SRGB,
263     /** equal to OH_COLORSPACE_LINEAR_SRGB */
264     OH_COLORSPACE_LINEAR_BT709,
265     /** COLORPRIMARIES_P3_D65 | (TRANSFUNC_LINEAR << 8) */
266     OH_COLORSPACE_LINEAR_P3,
267     /** COLORPRIMARIES_BT2020 | (TRANSFUNC_LINEAR << 8) */
268     OH_COLORSPACE_LINEAR_BT2020,
269     /** equal to OH_COLORSPACE_SRGB_FULL */
270     OH_COLORSPACE_DISPLAY_SRGB,
271     /** equal to OH_COLORSPACE_P3_FULL */
272     OH_COLORSPACE_DISPLAY_P3_SRGB,
273     /** equal to OH_COLORSPACE_P3_HLG_FULL */
274     OH_COLORSPACE_DISPLAY_P3_HLG,
275     /** equal to OH_COLORSPACE_P3_PQ_FULL */
276     OH_COLORSPACE_DISPLAY_P3_PQ,
277     /** COLORPRIMARIES_BT2020 | (TRANSFUNC_SRGB << 8) | (MATRIX_BT2020 << 16) | (RANGE_FULL << 21) */
278     OH_COLORSPACE_DISPLAY_BT2020_SRGB,
279     /** equal to OH_COLORSPACE_BT2020_HLG_FULL */
280     OH_COLORSPACE_DISPLAY_BT2020_HLG,
281     /** equal to OH_COLORSPACE_BT2020_PQ_FULL */
282     OH_COLORSPACE_DISPLAY_BT2020_PQ,
283 } OH_NativeBuffer_ColorSpace;
284 
285 /**
286  * @brief Indicates the transform type of a native buffer.
287  *
288  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
289  * @since 12
290  * @version 1.0
291  */
292 typedef enum OH_NativeBuffer_TransformType {
293     NATIVEBUFFER_ROTATE_NONE = 0,         /**< No rotation */
294     NATIVEBUFFER_ROTATE_90,               /**< Rotation by 90 degrees */
295     NATIVEBUFFER_ROTATE_180,              /**< Rotation by 180 degrees */
296     NATIVEBUFFER_ROTATE_270,              /**< Rotation by 270 degrees */
297     NATIVEBUFFER_FLIP_H,                  /**< Flip horizontally */
298     NATIVEBUFFER_FLIP_V,                  /**< Flip vertically */
299     NATIVEBUFFER_FLIP_H_ROT90,            /**< Flip horizontally and rotate 90 degrees */
300     NATIVEBUFFER_FLIP_V_ROT90,            /**< Flip vertically and rotate 90 degrees */
301     NATIVEBUFFER_FLIP_H_ROT180,           /**< Flip horizontally and rotate 180 degrees */
302     NATIVEBUFFER_FLIP_V_ROT180,           /**< Flip vertically and rotate 180 degrees */
303     NATIVEBUFFER_FLIP_H_ROT270,           /**< Flip horizontally and rotate 270 degrees */
304     NATIVEBUFFER_FLIP_V_ROT270,           /**< Flip vertically and rotate 270 degrees */
305 } OH_NativeBuffer_TransformType;
306 
307 /**
308  * @brief Indicates the color gamut of a native buffer.
309  *
310  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
311  * @since 12
312  * @version 1.0
313  */
314 typedef enum OH_NativeBuffer_ColorGamut {
315     NATIVEBUFFER_COLOR_GAMUT_NATIVE = 0,            /**< Native or default */
316     NATIVEBUFFER_COLOR_GAMUT_STANDARD_BT601 = 1,    /**< Standard BT601 */
317     NATIVEBUFFER_COLOR_GAMUT_STANDARD_BT709 = 2,    /**< Standard BT709 */
318     NATIVEBUFFER_COLOR_GAMUT_DCI_P3 = 3,            /**< DCI P3 */
319     NATIVEBUFFER_COLOR_GAMUT_SRGB = 4,              /**< SRGB */
320     NATIVEBUFFER_COLOR_GAMUT_ADOBE_RGB = 5,         /**< Adobe RGB */
321     NATIVEBUFFER_COLOR_GAMUT_DISPLAY_P3 = 6,        /**< Display P3 */
322     NATIVEBUFFER_COLOR_GAMUT_BT2020 = 7,            /**< BT2020 */
323     NATIVEBUFFER_COLOR_GAMUT_BT2100_PQ = 8,         /**< BT2100 PQ */
324     NATIVEBUFFER_COLOR_GAMUT_BT2100_HLG = 9,        /**< BT2100 HLG */
325     NATIVEBUFFER_COLOR_GAMUT_DISPLAY_BT2020 = 10,   /**< Display BT2020 */
326 } OH_NativeBuffer_ColorGamut;
327 
328 /**
329  * @brief <b>OH_NativeBuffer</b> config. \n
330  * Used to allocating new <b>OH_NativeBuffer</b> andquery parameters if existing ones.
331  *
332  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
333  * @since 9
334  * @version 1.0
335  */
336 typedef struct {
337     int32_t width;           ///< Width in pixels
338     int32_t height;          ///< Height in pixels
339     int32_t format;          ///< One of PixelFormat
340     int32_t usage;           ///< Combination of buffer usage
341     int32_t stride;          ///< the stride of memory
342 } OH_NativeBuffer_Config;
343 
344 /**
345  * @brief Holds info for a single image plane. \n
346  *
347  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
348  * @since 12
349  * @version 1.0
350  */
351 typedef struct {
352     /**
353      * Offset in bytes of plane.
354      */
355     uint64_t offset;
356     /**
357      * Distance in bytes from the first value of one row of the image to the first value of the next row.
358      */
359     uint32_t rowStride;
360     /**
361      * Distance in bytes from the first value of one column of the image to the first value of the next column.
362      */
363     uint32_t columnStride;
364 } OH_NativeBuffer_Plane;
365 
366 /**
367  * @brief Holds all image plane. \n
368  *
369  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
370  * @since 12
371  * @version 1.0
372  */
373 typedef struct {
374     uint32_t planeCount;              ///< Number of distinct planes.
375     OH_NativeBuffer_Plane planes[4];  ///< Array of image planes.
376 } OH_NativeBuffer_Planes;
377 
378 /**
379  * @brief Indicates the HDR metadata type of a native buffer.
380  *
381  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
382  * @since 12
383  * @version 1.0
384  */
385 typedef enum OH_NativeBuffer_MetadataType {
386     OH_VIDEO_HDR_HLG,      /**< HLG */
387     OH_VIDEO_HDR_HDR10,    /**< HDR10 */
388     OH_VIDEO_HDR_VIVID,    /**< HDR VIVID */
389     OH_VIDEO_NONE          /**< NONE Metadata */
390 } OH_NativeBuffer_MetadataType;
391 
392 /**
393  * @brief Indicates the color x and y.
394  *
395  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
396  * @since 12
397  * @version 1.0
398  */
399 typedef struct {
400     float x;              /**< color X */
401     float y;              /**< color Y */
402 } OH_NativeBuffer_ColorXY;
403 
404 /**
405  * @brief Indicates the smpte2086 metadata.
406  *
407  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
408  * @since 12
409  * @version 1.0
410  */
411 typedef struct {
412     OH_NativeBuffer_ColorXY displaPrimaryRed;    /**< primary red */
413     OH_NativeBuffer_ColorXY displaPrimaryGreen;  /**< primary green */
414     OH_NativeBuffer_ColorXY displaPrimaryBlue;   /**< primary blue */
415     OH_NativeBuffer_ColorXY whitePoint;          /**< white point */
416     float maxLuminance;                          /**< max luminance */
417     float minLuminance;                          /**< min luminance */
418 } OH_NativeBuffer_Smpte2086;
419 
420 /**
421  * @brief Indicates the cta861.3 metadata.
422  *
423  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
424  * @since 12
425  * @version 1.0
426  */
427 typedef struct {
428     float maxContentLightLevel;                  /**< max content lightLevel */
429     float maxFrameAverageLightLevel;             /**< max frame average light level */
430 } OH_NativeBuffer_Cta861;
431 
432 /**
433  * @brief Indicates the HDR static metadata.
434  *
435  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
436  * @since 12
437  * @version 1.0
438  */
439 typedef struct {
440     OH_NativeBuffer_Smpte2086 smpte2086;         /**< smpte 2086 metadata*/
441     OH_NativeBuffer_Cta861 cta861;               /**< CTA-861.3 metadata*/
442 } OH_NativeBuffer_StaticMetadata;
443 
444 /**
445  * @brief Indicates the HDR metadata key of a native buffer.
446  *
447  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
448  * @since 12
449  * @version 1.0
450  */
451 typedef enum OH_NativeBuffer_MetadataKey {
452     OH_HDR_METADATA_TYPE,            /**< value: OH_NativeBuffer_MetadataType*/
453     OH_HDR_STATIC_METADATA,          /**< value: OH_NativeBuffer_StaticMetadata*/
454     OH_HDR_DYNAMIC_METADATA          /**< byte stream of SEI in video stream*/
455 } OH_NativeBuffer_MetadataKey;
456 
457 /**
458  * @brief Alloc a <b>OH_NativeBuffer</b> that matches the passed BufferRequestConfig. \n
459  * A new <b>OH_NativeBuffer</b> instance is created each time this function is called.
460  *
461  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
462  * @param config Indicates the pointer to a <b>BufferRequestConfig</b> instance.
463  * @return Returns the pointer to the <b>OH_NativeBuffer</b> instance created if the operation is successful, \n
464  * returns <b>NULL</b> otherwise.
465  * @since 9
466  * @version 1.0
467  */
468 OH_NativeBuffer* OH_NativeBuffer_Alloc(const OH_NativeBuffer_Config* config);
469 
470 /**
471  * @brief Adds the reference count of a OH_NativeBuffer.
472  *
473  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
474  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
475  * @return Returns an error code, 0 is success, otherwise, failed.
476  * @since 9
477  * @version 1.0
478  */
479 int32_t OH_NativeBuffer_Reference(OH_NativeBuffer *buffer);
480 
481 /**
482  * @brief Decreases the reference count of a OH_NativeBuffer and, when the reference count reaches 0, \n
483  * destroys this OH_NativeBuffer.
484  *
485  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
486  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
487  * @return Returns an error code, 0 is success, otherwise, failed.
488  * @since 9
489  * @version 1.0
490  */
491 int32_t OH_NativeBuffer_Unreference(OH_NativeBuffer *buffer);
492 
493 /**
494  * @brief Return a config of the OH_NativeBuffer in the passed OHNativeBufferConfig struct.
495  *
496  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
497  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
498  * @param config Indicates the pointer to the <b>NativeBufferConfig</b> of the buffer.
499  * @return <b>void</b>
500  * @since 9
501  * @version 1.0
502  */
503 void OH_NativeBuffer_GetConfig(OH_NativeBuffer *buffer, OH_NativeBuffer_Config* config);
504 
505 /**
506  * @brief Provide direct cpu access to the OH_NativeBuffer in the process's address space.
507  *
508  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
509  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
510  * @param virAddr Indicates the address of the <b>OH_NativeBuffer</b> in virtual memory.
511  * @return Returns an error code, 0 is success, otherwise, failed.
512  * @since 9
513  * @version 1.0
514  */
515 
516 int32_t OH_NativeBuffer_Map(OH_NativeBuffer *buffer, void **virAddr);
517 
518 /**
519  * @brief Remove direct cpu access ability of the OH_NativeBuffer in the process's address space.
520  *
521  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
522  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
523  * @return Returns an error code, 0 is success, otherwise, failed.
524  * @since 9
525  * @version 1.0
526  */
527 int32_t OH_NativeBuffer_Unmap(OH_NativeBuffer *buffer);
528 
529 /**
530  * @brief Get the systen wide unique sequence number of the OH_NativeBuffer.
531  *
532  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
533  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
534  * @return Returns the sequence number, which is unique for each OH_NativeBuffer.
535  * @since 9
536  * @version 1.0
537  */
538 uint32_t OH_NativeBuffer_GetSeqNum(OH_NativeBuffer *buffer);
539 
540 /**
541  * @brief Provide direct cpu access to the potentially multi-plannar OH_NativeBuffer in the process's address space.
542  *
543  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
544  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
545  * @param virAddr Indicates the address of the <b>OH_NativeBuffer</b> in virtual memory.
546  * @param outPlanes Indicates all image planes that contain the pixel data.
547  * @return Returns an error code, 0 is sucess, otherwise, failed.
548  * @since 12
549  * @version 1.0
550  */
551 int32_t OH_NativeBuffer_MapPlanes(OH_NativeBuffer *buffer, void **virAddr, OH_NativeBuffer_Planes *outPlanes);
552 
553 /**
554  * @brief Converts an <b>OHNativeWindowBuffer</b> instance to an <b>OH_NativeBuffer</b>.
555  *
556  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
557  * @param nativeWindowBuffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
558  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> pointer.
559  * @return Returns an error code, 0 is sucess, otherwise, failed.
560  * @since 12
561  * @version 1.0
562  */
563 int32_t OH_NativeBuffer_FromNativeWindowBuffer(OHNativeWindowBuffer *nativeWindowBuffer, OH_NativeBuffer **buffer);
564 
565 /**
566  * @brief Set the color space of the OH_NativeBuffer.
567  *
568  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
569  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
570  * @param colorSpace Indicates the color space of native buffer, see <b>OH_NativeBuffer_ColorSpace</b>.
571  * @return Returns an error code, 0 is success, otherwise, failed.
572  * @since 11
573  * @version 1.0
574  */
575 int32_t OH_NativeBuffer_SetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_ColorSpace colorSpace);
576 
577 /**
578  * @brief Get the color space of the OH_NativeBuffer.
579  *
580  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
581  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
582  * @param colorSpace Indicates the color space of native buffer, see <b>OH_NativeBuffer_ColorSpace</b>.
583  * @return {@link NATIVE_ERROR_OK} 0 - Success.
584  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - buffer is NULL.
585  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect colorSpace state.
586  * @since 12
587  * @version 1.0
588  */
589 int32_t OH_NativeBuffer_GetColorSpace(OH_NativeBuffer *buffer, OH_NativeBuffer_ColorSpace *colorSpace);
590 
591 /**
592  * @brief Set the metadata type of the OH_NativeBuffer.
593  *
594  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
595  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
596  * @param metadataKey Indicates the metadata type of native buffer, see <b>OH_NativeBuffer_MetadataKey</b>.
597  * @param size Indicates the size of a uint8_t vector.
598  * @param metadata Indicates the pointer to a uint8_t vector.
599  * @return {@link NATIVE_ERROR_OK} 0 - Success.
600  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - buffer or metadata is NULL.
601  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state.
602  *     {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key.
603  * @since 12
604  * @version 1.0
605  */
606 int32_t OH_NativeBuffer_SetMetadataValue(OH_NativeBuffer *buffer, OH_NativeBuffer_MetadataKey metadataKey,
607     int32_t size, uint8_t *metadata);
608 
609 /**
610  * @brief Set the metadata type of the OH_NativeBuffer.
611  *
612  * @syscap SystemCapability.Graphic.Graphic2D.NativeBuffer
613  * @param buffer Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
614  * @param metadataKey Indicates the metadata type of native buffer, see <b>OH_NativeBuffer_MetadataKey</b>.
615  * @param size Indicates the size of a uint8_t vector.
616  * @param metadata Indicates the pointer to a uint8_t vector.
617  * @return {@link NATIVE_ERROR_OK} 0 - Success.
618  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - buffer, metadata, or size is NULL.
619  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state.
620  *     {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key.
621  * @since 12
622  * @version 1.0
623  */
624 int32_t OH_NativeBuffer_GetMetadataValue(OH_NativeBuffer *buffer, OH_NativeBuffer_MetadataKey metadataKey,
625     int32_t *size, uint8_t **metadata);
626 #ifdef __cplusplus
627 }
628 #endif
629 
630 /** @} */
631 #endif