1# NativeWindow 2 3 4## Overview 5 6The **NativeWindow** module provides the **NativeWindow** capability for connection to the EGL. 7 8**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 9 10**Since**: 8 11 12 13## Summary 14 15 16### Files 17 18| Name| Description| 19| -------- | -------- | 20| [external_window.h](external__window_8h.md) | Declares the functions for obtaining and using **NativeWindow**.| 21 22 23### Structs 24 25| Name| Description| 26| -------- | -------- | 27| struct [Region](_region.md) | Describes the rectangle (dirty region) where the content is to be updated in the local **OHNativeWindow**.| 28| struct [OHHDRMetaData](_o_h_h_d_r_meta_data.md) | Describes the HDR metadata.<br>**Deprecated**: This struct is deprecated since API version 10. No substitute is provided.| 29| struct [OHExtDataHandle](_o_h_ext_data_handle.md) | Describes the extended data handle.<br>**Deprecated**: This struct is deprecated since API version 10. No substitute is provided.| 30 31 32### Types 33 34| Name| Description| 35| -------- | -------- | 36| typedef struct [OHIPCParcel](#ohipcparcel) [OHIPCParcel](#ohipcparcel) | Provides access to **OHIPCParcel**, which is an IPC parcelable object.| 37| typedef struct NativeWindow [OHNativeWindow](#ohnativewindow) | Provides the capability of accessing the **OHNativeWindow**.| 38| typedef struct NativeWindowBuffer [OHNativeWindowBuffer](#ohnativewindowbuffer) | Provides the capability of accessing the **OHNativeWindowBuffer**.| 39| typedef struct [Region](_region.md) [Region](#region) | Defines a struct for the rectangle (dirty region) where the content is to be updated in the local **OHNativeWindow**.| 40| typedef enum [OHNativeErrorCode](#ohnativeerrorcode) [OHNativeErrorCode](#ohnativeerrorcode) | Defines an enum for the error codes. | 41| typedef enum [NativeWindowOperation](#nativewindowoperation) [NativeWindowOperation](#nativewindowoperation) | Defines an enum for the operation codes in the **OH_NativeWindow_NativeWindowHandleOpt** function. | 42| typedef enum [OHScalingModeV2](#ohscalingmodev2) [OHScalingModeV2](#ohscalingmodev2) | Defines an enum for the rendering scaling modes. | 43| typedef enum [OHSurfaceSource](#ohsurfacesource) [OHSurfaceSource](#ohsurfacesource) | Defines an enum for the sources of content displayed in the local window.| 44 45### Enums 46 47| Name| Description| 48| -------- | -------- | 49| [NativeWindowOperation](#nativewindowoperation-1) {<br>SET_BUFFER_GEOMETRY, GET_BUFFER_GEOMETRY, GET_FORMAT, SET_FORMAT,<br>GET_USAGE, SET_USAGE, SET_STRIDE, GET_STRIDE,<br>SET_SWAP_INTERVAL, GET_SWAP_INTERVAL, SET_TIMEOUT, GET_TIMEOUT,<br>SET_COLOR_GAMUT, GET_COLOR_GAMUT, SET_TRANSFORM, GET_TRANSFORM,<br>SET_UI_TIMESTAMP, GET_BUFFERQUEUE_SIZE, SET_SOURCE_TYPE, GET_SOURCE_TYPE,<br>SET_APP_FRAMEWORK_TYPE, GET_APP_FRAMEWORK_TYPE, SET_HDR_WHITE_POINT_BRIGHTNESS, SET_SDR_WHITE_POINT_BRIGHTNESS,<br>SET_DESIRED_PRESENT_TIMESTAMP = 24<br>} | Enumerates the operation codes in the **OH_NativeWindow_NativeWindowHandleOpt** function.| 50| [OHScalingMode](#ohscalingmode) { OH_SCALING_MODE_FREEZE = 0, OH_SCALING_MODE_SCALE_TO_WINDOW, OH_SCALING_MODE_SCALE_CROP, OH_SCALING_MODE_NO_SCALE_CROP } | Enumerates the scaling modes.<br>**Deprecated**: This enum is deprecated since API version 10. No substitute is provided.| 51| [OHScalingModeV2](#ohscalingmodev2-1) {<br>OH_SCALING_MODE_FREEZE_V2 = 0, OH_SCALING_MODE_SCALE_TO_WINDOW_V2, OH_SCALING_MODE_SCALE_CROP_V2, OH_SCALING_MODE_NO_SCALE_CROP_V2,<br>OH_SCALING_MODE_SCALE_FIT_V2<br>} | Enumerates the rendering scaling modes. | 52| [OHHDRMetadataKey](#ohhdrmetadatakey) {<br>OH_METAKEY_RED_PRIMARY_X = 0, OH_METAKEY_RED_PRIMARY_Y = 1, OH_METAKEY_GREEN_PRIMARY_X = 2, OH_METAKEY_GREEN_PRIMARY_Y = 3,<br>OH_METAKEY_BLUE_PRIMARY_X = 4, OH_METAKEY_BLUE_PRIMARY_Y = 5, OH_METAKEY_WHITE_PRIMARY_X = 6, OH_METAKEY_WHITE_PRIMARY_Y = 7,<br>OH_METAKEY_MAX_LUMINANCE = 8, OH_METAKEY_MIN_LUMINANCE = 9, OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11,<br>OH_METAKEY_HDR10_PLUS = 12, OH_METAKEY_HDR_VIVID = 13<br>} | Enumerates the HDR metadata keys.<br>**Deprecated**: This enum is deprecated since API version 10. No substitute is provided.| 53| [OHNativeErrorCode](#ohnativeerrorcode-1) {<br>NATIVE_ERROR_OK = 0, NATIVE_ERROR_INVALID_ARGUMENTS = 40001000, NATIVE_ERROR_NO_PERMISSION = 40301000, NATIVE_ERROR_NO_BUFFER = 40601000,<br>NATIVE_ERROR_NO_CONSUMER = 41202000, NATIVE_ERROR_NOT_INIT = 41203000, NATIVE_ERROR_CONSUMER_CONNECTED = 41206000, NATIVE_ERROR_BUFFER_STATE_INVALID = 41207000,<br>NATIVE_ERROR_BUFFER_IN_CACHE = 41208000, NATIVE_ERROR_BUFFER_QUEUE_FULL = 41209000, NATIVE_ERROR_BUFFER_NOT_IN_CACHE = 41210000,NATIVE_ERROR_CONSUMER_DISCONNECTED = 41211000,NATIVE_ERROR_CONSUMER_NO_LISTENER_REGISTERED = 41212000, NATIVE_ERROR_UNSUPPORTED = 50102000,<br>NATIVE_ERROR_UNKNOWN = 50002000, NATIVE_ERROR_HDI_ERROR = 50007000,NATIVE_ERROR_BINDER_ERROR = 50401000,NATIVE_ERROR_EGL_STATE_UNKNOWN = 60001000, NATIVE_ERROR_EGL_API_FAILED = 60002000<br>} | Enumerates the error codes. | 54| [OHSurfaceSource](#ohsurfacesource-1) {<br>OH_SURFACE_SOURCE_DEFAULT = 0, OH_SURFACE_SOURCE_UI, OH_SURFACE_SOURCE_GAME, OH_SURFACE_SOURCE_CAMERA,OH_SURFACE_SOURCE_VIDEO<br>} | Enumerates the sources of content displayed in the local window.| 55 56### Functions 57 58| Name| Description| 59| -------- | -------- | 60| [OHNativeWindow](#ohnativewindow) \* [OH_NativeWindow_CreateNativeWindow](#oh_nativewindow_createnativewindow) (void \*pSurface) | Creates an **OHNativeWindow** instance. A new **OHNativeWindow** instance is created each time this function is called. If this function is unavailable, you can create an **OHNativeWindow** instance by calling **OH_NativeImage_AcquireNativeWindow** or through the **XComponent**.| 61| void [OH_NativeWindow_DestroyNativeWindow](#oh_nativewindow_destroynativewindow) ([OHNativeWindow](#ohnativewindow) \*window) | Decreases the reference count of an **OHNativeWindow** instance by 1 and when the reference count reaches 0, destroys the instance.| 62| [OHNativeWindowBuffer](#ohnativewindowbuffer) \* [OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer](#oh_nativewindow_createnativewindowbufferfromsurfacebuffer) (void \*pSurfaceBuffer) | Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called. This function is deprecated since API version 12 and replaced by [OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer](#oh_nativewindow_createnativewindowbufferfromnativebuffer).| 63| [OHNativeWindowBuffer](#ohnativewindowbuffer) \* [OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer](#oh_nativewindow_createnativewindowbufferfromnativebuffer) (OH_NativeBuffer \*nativeBuffer) | Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called.| 64| void [OH_NativeWindow_DestroyNativeWindowBuffer](#oh_nativewindow_destroynativewindowbuffer) ([OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer) | Decreases the reference count of an **OHNativeWindowBuffer** instance by 1 and when the reference count reaches 0, destroys the instance.| 65| int32_t [OH_NativeWindow_NativeWindowRequestBuffer](#oh_nativewindow_nativewindowrequestbuffer) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*\*buffer, int \*fenceFd) | Requests an **OHNativeWindowBuffer** through an **OHNativeWindow** instance for content production.| 66| int32_t [OH_NativeWindow_NativeWindowFlushBuffer](#oh_nativewindow_nativewindowflushbuffer) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer, int fenceFd, [Region](_region.md) region) | Flushes the **OHNativeWindowBuffer** filled with the produced content to the buffer queue through an **OHNativeWindow** instance for content consumption.| 67| int32_t [OH_NativeWindow_GetLastFlushedBuffer](#oh_nativewindow_getlastflushedbuffer) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*\*buffer, int \*fenceFd, float matrix[16]) | Obtains the **OHNativeWindowBuffer** that was flushed to the buffer queue last time through an **OHNativeWindow** instance.| 68| int32_t [OH_NativeWindow_NativeWindowAbortBuffer](#oh_nativewindow_nativewindowabortbuffer) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer) | Returns the **OHNativeWindowBuffer** to the buffer queue through an **OHNativeWindow** instance, without filling in any content. The **OHNativeWindowBuffer** can be used for a new request.| 69| int32_t [OH_NativeWindow_NativeWindowHandleOpt](#oh_nativewindow_nativewindowhandleopt) ([OHNativeWindow](#ohnativewindow) \*window, int code,...) | Sets or obtains the attributes of an **OHNativeWindow** instance, including the width, height, and content format.| 70| BufferHandle \* [OH_NativeWindow_GetBufferHandleFromNative](#oh_nativewindow_getbufferhandlefromnative) ([OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer) | Obtains the pointer to a **BufferHandle** of an **OHNativeWindowBuffer** instance.| 71| int32_t [OH_NativeWindow_NativeObjectReference](#oh_nativewindow_nativeobjectreference) (void \*obj) | Adds the reference count of a native object.| 72| int32_t [OH_NativeWindow_NativeObjectUnreference](#oh_nativewindow_nativeobjectunreference) (void \*obj) | Decreases the reference count of a native object and, when the reference count reaches 0, destroys this object.| 73| int32_t [OH_NativeWindow_GetNativeObjectMagic](#oh_nativewindow_getnativeobjectmagic) (void \*obj) | Obtains the magic ID of a native object.| 74| int32_t [OH_NativeWindow_NativeWindowSetScalingMode](#oh_nativewindow_nativewindowsetscalingmode) ([OHNativeWindow](#ohnativewindow) \*window, uint32_t sequence, [OHScalingMode](#ohscalingmode) scalingMode) | Sets a scaling mode for an **OHNativeWindow**.<br>**Deprecated**: This function is deprecated since API version 10. No substitute is provided.| 75| int32_t [OH_NativeWindow_NativeWindowSetMetaData](#oh_nativewindow_nativewindowsetmetadata) ([OHNativeWindow](#ohnativewindow) \*window, uint32_t sequence, int32_t size, const [OHHDRMetaData](_o_h_h_d_r_meta_data.md) \*metaData) | Sets metadata for an **OHNativeWindow**.<br>**Deprecated**: This function is deprecated since API version 10. No substitute is provided.| 76| int32_t [OH_NativeWindow_NativeWindowSetMetaDataSet](#oh_nativewindow_nativewindowsetmetadataset) ([OHNativeWindow](#ohnativewindow) \*window, uint32_t sequence, [OHHDRMetadataKey](#ohhdrmetadatakey) key, int32_t size, const uint8_t \*metaData) | Sets a metadata set for an **OHNativeWindow**.<br>**Deprecated**: This function is deprecated since API version 10. No substitute is provided.| 77| int32_t [OH_NativeWindow_NativeWindowSetTunnelHandle](#oh_nativewindow_nativewindowsettunnelhandle) ([OHNativeWindow](#ohnativewindow) \*window, const [OHExtDataHandle](_o_h_ext_data_handle.md) \*handle) | Sets a tunnel handle to an **OHNativeWindow**.<br>**Deprecated**: This function is deprecated since API version 10. No substitute is provided.| 78| int32_t [OH_NativeWindow_NativeWindowAttachBuffer](#oh_nativewindow_nativewindowattachbuffer) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer) | Attaches an **OHNativeWindowBuffer** to an **OHNativeWindow** instance.| 79| int32_t [OH_NativeWindow_NativeWindowDetachBuffer](#oh_nativewindow_nativewindowdetachbuffer) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer) | Detaches an **OHNativeWindowBuffer** from an **OHNativeWindow** instance.| 80| int32_t [OH_NativeWindow_GetSurfaceId](#oh_nativewindow_getsurfaceid) ([OHNativeWindow](#ohnativewindow) \*window, uint64_t \*surfaceId) | Obtains a surface ID through an **OHNativeWindow**.| 81| int32_t [OH_NativeWindow_CreateNativeWindowFromSurfaceId](#oh_nativewindow_createnativewindowfromsurfaceid) (uint64_t surfaceId, [OHNativeWindow](#ohnativewindow) \*\*window) | Creates an **OHNativeWindow** instance based on a surface ID.| 82| int32_t [OH_NativeWindow_NativeWindowSetScalingModeV2](#oh_nativewindow_nativewindowsetscalingmodev2) ([OHNativeWindow](#ohnativewindow) \*window, [OHScalingModeV2](#ohscalingmodev2) scalingMode) | Sets a rendering scaling mode for an **OHNativeWindow** instance. | 83| int32_t [OH_NativeWindow_GetLastFlushedBufferV2](#oh_nativewindow_getlastflushedbufferv2) ([OHNativeWindow](#ohnativewindow) \*window, [OHNativeWindowBuffer](#ohnativewindowbuffer) \*\*buffer, int \*fenceFd, float matrix[16]) | Obtains the **OHNativeWindowBuffer** that was flushed to the buffer queue last time through an **OHNativeWindow** instance. The difference between this function and **OH_NativeWindow_GetLastFlushedBuffer** lies in the matrix. | 84| void [OH_NativeWindow_SetBufferHold](#oh_nativewindow_setbufferhold) ([OHNativeWindow](#ohnativewindow) \*window) | Buffers a frame in advance and holds it for the interval of a frame to offset the possible loss of subsequent oversized frames. | 85| int32_t [OH_NativeWindow_WriteToParcel](#oh_nativewindow_writetoparcel) ([OHNativeWindow](#ohnativewindow) \*window, [OHIPCParcel](#ohipcparcel) \*parcel) | Writes an **OHNativeWindow** instance to an **OHIPCParcel** instance.| 86| int32_t [OH_NativeWindow_ReadFromParcel](#oh_nativewindow_readfromparcel) ([OHIPCParcel](#ohipcparcel) \*parcel, [OHNativeWindow](#ohnativewindow) \*\*window) | Reads an **OHNativeWindow** instance from an **OHIPCParcel** instance.| 87| int32_t [OH_NativeWindow_SetColorSpace](#oh_nativewindow_setcolorspace) ([OHNativeWindow](#ohnativewindow) \*window, [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace) colorSpace) | Sets the color space for an **OHNativeWindow** instance.| 88| int32_t [OH_NativeWindow_GetColorSpace](#oh_nativewindow_getcolorspace) ([OHNativeWindow](#ohnativewindow) \*window, [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace) \*colorSpace) | Obtains the color space of an **OHNativeWindow** instance.| 89| int32_t [OH_NativeWindow_SetMetadataValue](#oh_nativewindow_setmetadatavalue) ([OHNativeWindow](#ohnativewindow) \*window, [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey) metadataKey, int32_t size, uint8_t \*metaData) | Sets a metadata value for an **OHNativeWindow** instance.| 90| int32_t [OH_NativeWindow_GetMetadataValue](#oh_nativewindow_getmetadatavalue) ([OHNativeWindow](#ohnativewindow) \*window, [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey) metadataKey, int32_t \*size, uint8_t \*\*metaData) | Obtains the metadata value of an **OHNativeWindow** instance.| 91 92## Type Description 93 94### OHSurfaceSource 95 96``` 97typedef enum OHSurfaceSource OHSurfaceSource 98``` 99 100**Description** 101 102Defines an enum for the sources of content displayed in the local window. 103 104**Since**: 12 105 106### OHIPCParcel 107 108``` 109typedef struct OHIPCParcel OHIPCParcel 110``` 111 112**Description** 113 114Provides access to **OHIPCParcel**, which is an IPC parcelable object. 115 116**Since**: 12 117 118### NativeWindowOperation 119 120``` 121typedef enum NativeWindowOperation NativeWindowOperation 122``` 123 124**Description** 125 126Defines an enum for the operation codes in the **OH_NativeWindow_NativeWindowHandleOpt** function. 127 128**Since**: 8 129 130### OHNativeErrorCode 131 132``` 133typedef enum OHNativeErrorCode OHNativeErrorCode 134``` 135 136**Description** 137 138Defines an enum for the error codes. 139 140**Since**: 12 141 142 143### OHNativeWindow 144 145``` 146typedef struct NativeWindow OHNativeWindow 147``` 148 149**Description** 150 151Provides the capability of accessing the **OHNativeWindow**. 152 153**Since**: 8 154 155 156### OHNativeWindowBuffer 157 158``` 159typedef struct NativeWindowBuffer OHNativeWindowBuffer 160``` 161 162**Description** 163 164Provides the capability of accessing the **OHNativeWindowBuffer**. 165 166**Since**: 8 167 168### OHScalingModeV2 169 170``` 171typedef enum OHScalingModeV2 OHScalingModeV2 172``` 173**Description** 174 175Defines an enum for the rendering scaling modes. 176 177**Since**: 12 178 179 180 181### Region 182 183``` 184typedef struct Region Region 185``` 186 187**Description** 188 189Defines a struct for the rectangle (dirty region) where the content is to be updated in the local **OHNativeWindow**. 190 191**Since**: 8 192 193 194## Enum Description 195 196### OHSurfaceSource 197 198``` 199enum OHSurfaceSource 200``` 201 202**Description** 203 204Enumerates the sources of content displayed in the local window. 205 206**Since**: 12 207 208| Value| Description| 209| -------- | -------- | 210| OH_SURFACE_SOURCE_DEFAULT | Default source.| 211| OH_SURFACE_SOURCE_UI | The window content comes from UIs.| 212| OH_SURFACE_SOURCE_GAME | The window content comes from games.| 213| OH_SURFACE_SOURCE_CAMERA | The window content comes from cameras.| 214| OH_SURFACE_SOURCE_VIDEO | The window content comes from videos.| 215 216### OHNativeErrorCode 217 218``` 219enum OHNativeErrorCode 220``` 221**Description** 222 223Enumerates the error codes. 224 225**Since**: 12 226 227| Value| Description| 228| -------- | -------- | 229| NATIVE_ERROR_OK | The operation is successful. | 230| NATIVE_ERROR_INVALID_ARGUMENTS | An input parameter is invalid. | 231| NATIVE_ERROR_NO_PERMISSION | You do not have the permission to perform the operation. | 232| NATIVE_ERROR_NO_BUFFER | No buffer is available. | 233| NATIVE_ERROR_NO_CONSUMER | The consumer does not exist. | 234| NATIVE_ERROR_NOT_INIT | Not initialized. | 235| NATIVE_ERROR_CONSUMER_CONNECTED | The consumer is connected. | 236| NATIVE_ERROR_BUFFER_STATE_INVALID | The buffer status does not meet the expectation. | 237| NATIVE_ERROR_BUFFER_IN_CACHE | The buffer is already in the buffer queue. | 238| NATIVE_ERROR_BUFFER_QUEUE_FULL | The queue is full. | 239| NATIVE_ERROR_BUFFER_NOT_IN_CACHE | The buffer is not in the buffer queue. | 240| NATIVE_ERROR_CONSUMER_DISCONNECTED | The consumer is disconnected.| 241| NATIVE_ERROR_CONSUMER_NO_LISTENER_REGISTERED | No listener is registered on the consumer side.| 242| NATIVE_ERROR_UNSUPPORTED | The device or platform does not support the operation. | 243| NATIVE_ERROR_UNKNOWN | Unknown error. Check the log. | 244| NATIVE_ERROR_HDI_ERROR | Failed to call the HDI. | 245| NATIVE_ERROR_BINDER_ERROR | Cross-process communication failed. | 246| NATIVE_ERROR_EGL_STATE_UNKNOWN | The EGL environment is abnormal. | 247| NATIVE_ERROR_EGL_API_FAILED | Failed to call the EGL APIs. | 248 249 250### NativeWindowOperation 251 252``` 253enum NativeWindowOperation 254``` 255 256**Description** 257 258Enumerates the operation codes in the **OH_NativeWindow_NativeWindowHandleOpt** function. 259 260**Since**: 8 261 262| Value| Description| 263| -------- | -------- | 264| SET_BUFFER_GEOMETRY | Setting the geometry for the local window buffer.<br>Variable arguments in the function: [Input] int32_t width and [Input] int32_t height.| 265| GET_BUFFER_GEOMETRY | Obtaining the geometry of the local window buffer.<br>Variable arguments in the function: [Output] int32_t *height and [Output] int32_t *width.| 266| GET_FORMAT | Obtaining the format of the local window buffer.<br>Variable argument in the function: [Output] int32_t \*format.<br>For details about the available options, see [OH_NativeBuffer_Format](_o_h___native_buffer.md#oh_nativebuffer_format-1).| 267| SET_FORMAT | Setting the format for the local window buffer.<br>Variable argument in the function: [Input] int32_t format.<br>For details about the available options, see [OH_NativeBuffer_Format](_o_h___native_buffer.md#oh_nativebuffer_format-1).| 268| GET_USAGE | Obtaining the usage mode of the local window buffer.<br>Variable argument in the function: [Output] uint64_t \*usage.<br>For details about the available options, see [OH_NativeBuffer_Usage](_o_h___native_buffer.md#oh_nativebuffer_usage-1).| 269| SET_USAGE | Setting the usage mode for the local window buffer.<br>Variable argument in the function: [Input] uint64_t usage.<br>For details about the available options, see [OH_NativeBuffer_Usage](_o_h___native_buffer.md#oh_nativebuffer_usage-1).| 270| SET_STRIDE | Setting the stride for the local window buffer, in bytes.<br>Variable argument in the function: [Input] int32_t stride.| 271| GET_STRIDE | Obtaining the stride of the local window buffer, in bytes.<br>Variable argument in the function: [Output] int32_t \*stride.| 272| SET_SWAP_INTERVAL | Setting the swap interval for the local window buffer.<br>Variable argument in the function: [Input] int32_t interval.| 273| GET_SWAP_INTERVAL | Obtaining the swap interval of the local window buffer.<br>Variable argument in the function: [Output] int32_t \*interval.| 274| SET_TIMEOUT | Setting the timeout duration for requesting the local window buffer, in ms.<br>Default value: 3000 ms.<br>Variable argument in the function: [Input] int32_t timeout.| 275| GET_TIMEOUT | Obtaining the timeout duration for requesting the local window buffer, in ms.<br>Default value: 3000 ms.<br>Variable argument in the function: [Output] int32_t \*timeout.| 276| SET_COLOR_GAMUT | Setting the color gamut for the local window buffer.<br>Variable argument in the function: [Input] int32_t colorGamut.<br>For details about the available options, see [OH_NativeBuffer_ColorGamut](_o_h___native_buffer.md#oh_nativebuffer_colorgamut-1).| 277| GET_COLOR_GAMUT | Obtaining the color gamut of the local window buffer.<br>Variable argument in the function: [Output] int32_t \*colorGamut.<br>For details about the available options, see [OH_NativeBuffer_ColorGamut](_o_h___native_buffer.md#oh_nativebuffer_colorgamut-1).| 278| SET_TRANSFORM | Setting the transform for the local window buffer.<br>Variable argument in the function: [Input] int32_t transform.<br>For details about the available options, see [OH_NativeBuffer_TransformType](_o_h___native_buffer.md#oh_nativebuffer_transformtype-1). | 279| GET_TRANSFORM | Obtaining the transform of the local window buffer.<br>Variable argument in the function: [Output] int32_t \*transform.<br>For details about the available options, see [OH_NativeBuffer_TransformType](_o_h___native_buffer.md#oh_nativebuffer_transformtype-1). | 280| SET_UI_TIMESTAMP | Setting the UI timestamp for the local window buffer.<br>Variable argument in the function: [Input] uint64_t uiTimestamp.| 281| GET_BUFFERQUEUE_SIZE<sup>12+</sup> | Obtaining the memory queue size.<br>Variable argument in the function: [Output] int32_t \*size.| 282| SET_SOURCE_TYPE<sup>12+</sup> | Setting the source of content displayed in the local window.<br>Variable argument in the function: [Input] int32_t sourceType. For details about the available options, see [OHSurfaceSource](#ohsurfacesource).| 283| GET_SOURCE_TYPE<sup>12+</sup> | Obtaining the source of content displayed in the local window.<br>Variable argument in the function: [Output] int32_t \*sourceType. For details about the available options, see [OHSurfaceSource](#ohsurfacesource).| 284| SET_APP_FRAMEWORK_TYPE<sup>12+</sup> | Setting the application framework name of the local window.<br>Variable argument in the function: [Input] char\* frameworkType. A maximum of 64 bytes are supported.| 285| GET_APP_FRAMEWORK_TYPE<sup>12+</sup> | Obtaining the application framework name of the local window.<br>Variable argument in the function: [Output] char\* frameworkType.| 286| SET_HDR_WHITE_POINT_BRIGHTNESS<sup>12+</sup> | Setting the brightness of HDR white points.<br>Variable arguments in the function: [Input] float brightness. The value range is [0.0f, 1.0f].| 287| SET_SDR_WHITE_POINT_BRIGHTNESS<sup>12+</sup> | Setting the brightness of SDR white points.<br>Variable arguments in the function: [Input] float brightness. The value range is [0.0f, 1.0f].| 288| SET_DESIRED_PRESENT_TIMESTAMP<sup>13+</sup> | Setting a timestamp indicating when the local window buffer is expected to show on the screen. The timestamp takes effect only when RenderService is the consumer of the local window and after [OH_NativeWindow_NativeWindowFlushBuffer](#oh_nativewindow_nativewindowflushbuffer) is called. The next buffer added to the queue by the producer is consumed by RenderService and displayed on the screen only after the expected on-screen time arrives. If there are multiple buffers in the queue from various producers, all of them have set **desiredPresentTimestamp**, and the desired time arrives, the buffer that was enqueued earliest will be pushed back into the queue by the consumer. If the expected on-screen time exceeds the time provided by the consumer by over 1 second, the expected timestamp is ignored. Variable argument in the function: [Input] int64_t desiredPresentTimestamp. The value must be greater than 0 and should be generated by the standard library std::chrono::steady_clock, in nanoseconds.| 289 290### OHHDRMetadataKey 291 292``` 293enum OHHDRMetadataKey 294``` 295 296**Description** 297 298Enumerates the HDR metadata keys. 299 300**Since**: 9 301 302**Deprecated**: This enum is deprecated since API version 10. No substitute is provided. 303 304| Value| Description| 305| -------- | -------- | 306| OH_METAKEY_RED_PRIMARY_X | X coordinate of the red primary color.| 307| OH_METAKEY_RED_PRIMARY_Y | Y coordinate of the red primary color.| 308| OH_METAKEY_GREEN_PRIMARY_X | X coordinate of the green primary color.| 309| OH_METAKEY_GREEN_PRIMARY_Y | Y coordinate of the green primary color.| 310| OH_METAKEY_BLUE_PRIMARY_X | X coordinate of the blue primary color.| 311| OH_METAKEY_BLUE_PRIMARY_Y | Y coordinate of the blue primary color.| 312| OH_METAKEY_WHITE_PRIMARY_X | X coordinate of the white point.| 313| OH_METAKEY_WHITE_PRIMARY_Y | Y coordinate of the white point.| 314| OH_METAKEY_MAX_LUMINANCE | Maximum luminance.| 315| OH_METAKEY_MIN_LUMINANCE | Minimum luminance.| 316| OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL | Maximum content light level (MaxCLL).| 317| OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL | Maximum frame average light level (MaxFALLL).| 318| OH_METAKEY_HDR10_PLUS | HDR10 Plus.| 319| OH_METAKEY_HDR_VIVID | Vivid.| 320 321 322### OHScalingMode 323 324``` 325enum OHScalingMode 326``` 327 328**Description** 329 330Enumerates the scaling modes. 331 332**Since**: 9 333 334**Deprecated**: This enum is deprecated since API version 10. No substitute is provided. 335 336| Value| Description| 337| -------- | -------- | 338| OH_SCALING_MODE_FREEZE | The window content cannot be updated before the buffer of the window size is received.| 339| OH_SCALING_MODE_SCALE_TO_WINDOW | The buffer is scaled in two dimensions to match the window size.| 340| OH_SCALING_MODE_SCALE_CROP | The buffer is scaled uniformly so that its smaller size can match the window size.| 341| OH_SCALING_MODE_NO_SCALE_CROP | The window is cropped to the size of the buffer's cropping rectangle. Pixels outside the cropping rectangle are considered completely transparent.| 342 343 344### OHScalingModeV2 345 346``` 347enum OHScalingModeV2 348``` 349**Description** 350 351Enumerates the rendering scaling modes. 352 353**Since**: 12 354 355| Value| Description| 356| -------- | -------- | 357| OH_SCALING_MODE_FREEZE_V2 | Freezes the window. The window content is not updated until a buffer with the same size as the window is received.| 358| OH_SCALING_MODE_SCALE_TO_WINDOW_V2 | Scales the buffer to match the window size.| 359| OH_SCALING_MODE_SCALE_CROP_V2 | Scales the buffer at the original aspect ratio to enable the smaller side of the buffer to match the window, while making the excess part transparent.| 360| OH_SCALING_MODE_NO_SCALE_CROP_V2 | Crops the buffer by window size. Pixels outside the cropping rectangle are considered completely transparent.| 361| OH_SCALING_MODE_SCALE_FIT_V2 | Scales the buffer at the original aspect ratio to fully display the buffer content, while filling the unfilled area of the window with the background color. This mode is not available for the<!--Del--> development board and<!--DelEnd--> Emulator.| 362 363 364## Function Description 365 366### OH_NativeWindow_SetColorSpace() 367 368``` 369int32_t OH_NativeWindow_SetColorSpace (OHNativeWindow *window, OH_NativeBuffer_ColorSpace colorSpace ) 370``` 371 372**Description** 373 374Sets the color space for an **OHNativeWindow** instance. 375 376This function is not thread-safe. 377 378**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 379 380**Since**: 12 381 382**Parameters** 383 384| Name| Description| 385| -------- | -------- | 386| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 387| colorSpace | Color space. For details about the available options, see [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace).| 388 389**Returns** 390 391Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 392 393 394### OH_NativeWindow_SetMetadataValue() 395 396``` 397int32_t OH_NativeWindow_SetMetadataValue (OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t size, uint8_t * metaData ) 398``` 399 400**Description** 401 402Sets a metadata value for an **OHNativeWindow** instance. 403 404This function is not thread-safe. 405 406**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 407 408**Since**: 12 409 410**Parameters** 411 412| Name| Description| 413| -------- | -------- | 414| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 415| metadataKey | Key of the metadata. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).| 416| size | Size of the uint8_t vector. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).| 417| metaData| Pointer to the uint8_t vector.| 418 419**Returns** 420 421Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 422 423### OH_NativeWindow_GetColorSpace() 424 425``` 426int32_t OH_NativeWindow_GetColorSpace (OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace ) 427``` 428 429**Description** 430 431Obtains the color space of an **OHNativeWindow** instance. 432 433This function is not thread-safe. 434 435**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 436 437**Since**: 12 438 439**Parameters** 440 441| Name| Description| 442| -------- | -------- | 443| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 444| colorSpace | Pointer to the color space. For details about the available options, see [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace).| 445 446**Returns** 447 448Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 449 450 451### OH_NativeWindow_GetMetadataValue() 452 453``` 454int32_t OH_NativeWindow_GetMetadataValue (OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t *size, uint8_t **metaData ) 455``` 456 457**Description** 458 459Obtains the metadata value of an **OHNativeWindow** instance. 460 461This function is not thread-safe. 462 463**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 464 465**Since**: 12 466 467**Parameters** 468 469| Name| Description| 470| -------- | -------- | 471| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 472| metadataKey | Key of the metadata. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).| 473| size | Pointer to the size of the uint8_t vector. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).| 474| metaData| Double pointer to the uint8_t vector.| 475 476**Returns** 477 478Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 479 480 481### OH_NativeWindow_WriteToParcel() 482 483``` 484int32_t OH_NativeWindow_WriteToParcel (OHNativeWindow *window, OHIPCParcel *parcel ) 485``` 486 487**Description** 488 489Writes an **OHNativeWindow** instance to an **OHIPCParcel** instance. 490 491This function is not thread-safe. 492 493**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 494 495**Since**: 12 496 497**Parameters** 498 499| Name| Description| 500| -------- | -------- | 501| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 502| parcel | Pointer to an [OHIPCParcel](#ohipcparcel) instance.| 503 504**Returns** 505 506Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 507 508 509### OH_NativeWindow_ReadFromParcel() 510 511``` 512int32_t OH_NativeWindow_ReadFromParcel (OHIPCParcel *parcel, OHNativeWindow **window ) 513``` 514 515**Description** 516 517Reads an **OHNativeWindow** instance from an **OHIPCParcel** instance. 518 519This function is not thread-safe. 520 521**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 522 523**Since**: 12 524 525**Parameters** 526 527| Name| Description| 528| -------- | -------- | 529| parcel | Pointer to an [OHIPCParcel](#ohipcparcel) instance.| 530| window | Double pointer to an [OHNativeWindow](#ohnativewindow) instance.| 531 532**Returns** 533 534Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 535 536 537 538### OH_NativeWindow_GetLastFlushedBufferV2() 539 540``` 541int32_t OH_NativeWindow_GetLastFlushedBufferV2 (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16] ) 542``` 543 544**Description** 545 546Obtains the **OHNativeWindowBuffer** that was flushed to the buffer queue last time through an **OHNativeWindow** instance. The difference between this function and **OH_NativeWindow_GetLastFlushedBuffer** lies in the matrix. 547 548This function must be used in pair with **OH_NativeWindow_NativeObjectUnreference**. Otherwise, memory leak occurs. 549 550This function is not thread-safe. 551 552**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 553 554**Since**: 12 555 556**Parameters** 557 558| Name| Description| 559| -------- | -------- | 560| window | Pointer to an **OHNativeWindow** instance. | 561| buffer | Double pointer to an **OHNativeWindowBuffer** instance. | 562| fenceFd | Pointer to a file descriptor. | 563| matrix | Retrieved 4*4 transformation matrix. | 564 565**Returns** 566 567Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 568 569 570 571### OH_NativeWindow_SetBufferHold() 572 573``` 574void OH_NativeWindow_SetBufferHold (OHNativeWindow *window) 575``` 576**Description** 577Buffers a frame in advance and holds it for the interval of a frame to offset the possible loss of subsequent oversized frames. 578 579This function is not thread-safe. 580 581**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 582 583**Since**: 12 584 585**Parameters** 586 587| Name| Description| 588| -------- | -------- | 589| window | Pointer to an [OHNativeWindow](_o_h___native_image.md#ohnativewindow) instance. | 590 591 592 593### OH_NativeWindow_CreateNativeWindow() 594 595``` 596OHNativeWindow* OH_NativeWindow_CreateNativeWindow (void* pSurface) 597``` 598 599**Description** 600 601Creates an **OHNativeWindow** instance. A new **OHNativeWindow** instance is created each time this function is called. If this function is unavailable, you can create an **OHNativeWindow** instance by calling **OH_NativeImage_AcquireNativeWindow** or through the **XComponent**. 602 603**Deprecated from**: 12 604 605**Substitute**: No substitute is provided. 606 607**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 608 609**Since**: 8 610 611**Parameters** 612 613| Name| Description| 614| -------- | -------- | 615| pSurface | Pointer to a **ProduceSurface**. The type is **sptr<OHOS::Surface>**.| 616 617**Returns** 618 619Returns the pointer to the **OHNativeWindow** instance created. 620 621 622### OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer() 623 624``` 625OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer (OH_NativeBuffer* nativeBuffer) 626``` 627 628**Description** 629 630Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called. 631 632This function must be used in pair with **OH_NativeWindow_DestroyNativeWindowBuffer**. Otherwise, memory leak occurs. 633 634This function is not thread-safe. 635 636**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 637 638**Since**: 11 639 640**Parameters** 641 642| Name| Description| 643| -------- | -------- | 644| nativeBuffer | Pointer to an **OH_NativeBuffer** instance.| 645 646**Returns** 647 648Returns the pointer to the **OHNativeWindowBuffer** instance created. 649 650 651### OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer() 652 653``` 654OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer (void* pSurfaceBuffer) 655``` 656 657**Description** 658 659Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called. 660 661**Deprecated from**: 12 662 663**Substitute**: [OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer](#oh_nativewindow_createnativewindowbufferfromnativebuffer) 664 665**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 666 667**Since**: 8 668 669**Parameters** 670 671| Name| Description| 672| -------- | -------- | 673| pSurfaceBuffer | Pointer to a **ProduceSurfaceBuffer**. The type is **sptr<OHOS::SurfaceBuffer>**.| 674 675**Returns** 676 677Returns the pointer to the **OHNativeWindowBuffer** instance created. 678 679 680### OH_NativeWindow_CreateNativeWindowFromSurfaceId() 681 682``` 683int32_t OH_NativeWindow_CreateNativeWindowFromSurfaceId (uint64_t surfaceId, OHNativeWindow **window ) 684``` 685 686**Description** 687 688Creates an **OHNativeWindow** instance based on a surface ID. 689This function must be used in pair with **OH_NativeWindow_DestroyNativeWindow**. Otherwise, memory leak occurs. 690 691If **OHNativeWindow** needs to be released concurrently, call **OH_NativeWindow_NativeObjectReference** and **OH_NativeWindow_NativeObjectUnreference** to increase or decrease the reference count by 1 for **OHNativeWindow**. 692 693The surface obtained by using the surface ID must be created in the current process, but not in a different process. 694 695This function is not thread-safe. 696 697**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 698 699**Since**: 12 700 701**Parameters** 702 703| Name| Description| 704| -------- | -------- | 705| surfaceId | Surface ID.| 706| window | Double pointer to an **OHNativeWindow** instance.| 707 708**Returns** 709 710Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 711 712 713### OH_NativeWindow_DestroyNativeWindow() 714 715``` 716void OH_NativeWindow_DestroyNativeWindow (OHNativeWindow* window) 717``` 718 719**Description** 720 721Decreases the reference count of an **OHNativeWindow** instance by 1 and when the reference count reaches 0, destroys the instance. 722 723This function is not thread-safe. 724 725**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 726 727**Since**: 8 728 729**Parameters** 730 731| Name| Description| 732| -------- | -------- | 733| window | Pointer to an **OHNativeWindow** instance.| 734 735 736### OH_NativeWindow_DestroyNativeWindowBuffer() 737 738``` 739void OH_NativeWindow_DestroyNativeWindowBuffer (OHNativeWindowBuffer* buffer) 740``` 741 742**Description** 743 744Decreases the reference count of an **OHNativeWindowBuffer** instance by 1 and when the reference count reaches 0, destroys the instance. 745 746This function is not thread-safe. 747 748**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 749 750**Since**: 8 751 752**Parameters** 753 754| Name| Description| 755| -------- | -------- | 756| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 757 758 759### OH_NativeWindow_GetBufferHandleFromNative() 760 761``` 762BufferHandle* OH_NativeWindow_GetBufferHandleFromNative (OHNativeWindowBuffer* buffer) 763``` 764 765**Description** 766 767Obtains the pointer to a **BufferHandle** of an **OHNativeWindowBuffer** instance. 768 769This function is not thread-safe. 770 771**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 772 773**Since**: 8 774 775**Parameters** 776 777| Name| Description| 778| -------- | -------- | 779| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 780 781**Returns** 782 783Returns the pointer to the **BufferHandle** instance obtained. 784 785 786### OH_NativeWindow_GetLastFlushedBuffer() 787 788``` 789int32_t OH_NativeWindow_GetLastFlushedBuffer (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16] ) 790``` 791 792**Description** 793 794Obtains the **OHNativeWindowBuffer** that was flushed to the buffer queue last time through an **OHNativeWindow** instance. 795 796**Deprecated from**: 12 797 798**Substitute**: [OH_NativeWindow_GetLastFlushedBufferV2](#oh_nativewindow_getlastflushedbufferv2) 799 800**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 801 802**Since**: 11 803 804**Parameters** 805 806| Name| Description| 807| -------- | -------- | 808| window | Pointer to an **OHNativeWindow** instance.| 809| buffer | Double pointer to an **OHNativeWindowBuffer** instance.| 810| fenceFd | Pointer to a file descriptor.| 811| matrix | Retrieved 4*4 transformation matrix.| 812 813**Returns** 814 815Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 816 817 818### OH_NativeWindow_GetNativeObjectMagic() 819 820``` 821int32_t OH_NativeWindow_GetNativeObjectMagic (void *obj) 822``` 823 824**Description** 825 826Obtains the magic ID of a native object. 827 828This function is not thread-safe. 829 830**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 831 832**Since**: 8 833 834**Parameters** 835 836| Name| Description| 837| -------- | -------- | 838| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.| 839 840**Returns** 841 842Returns the magic ID, which is unique for each native object. 843 844 845### OH_NativeWindow_GetSurfaceId() 846 847``` 848int32_t OH_NativeWindow_GetSurfaceId (OHNativeWindow *window, uint64_t *surfaceId ) 849``` 850 851**Description** 852 853Obtains a surface ID through an **OHNativeWindow**. 854 855This function is not thread-safe. 856 857**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 858 859**Since**: 12 860 861**Parameters** 862 863| Name| Description| 864| -------- | -------- | 865| window | Pointer to an **OHNativeWindow** instance.| 866| surfaceId | Pointer to the surface ID.| 867 868**Returns** 869 870Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 871 872 873### OH_NativeWindow_NativeObjectReference() 874 875``` 876int32_t OH_NativeWindow_NativeObjectReference (void *obj) 877``` 878 879**Description** 880 881Adds the reference count of a native object. 882 883This function must be used in pair with **OH_NativeWindow_NativeObjectUnreference**. Otherwise, memory leak occurs. 884 885This function is not thread-safe. 886 887**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 888 889**Since**: 8 890 891**Parameters** 892 893| Name| Description| 894| -------- | -------- | 895| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.| 896 897**Returns** 898 899Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 900 901 902### OH_NativeWindow_NativeObjectUnreference() 903 904``` 905int32_t OH_NativeWindow_NativeObjectUnreference (void *obj) 906``` 907 908**Description** 909 910Decreases the reference count of a native object and when the reference count reaches 0, destroys this object. 911 912This function is not thread-safe. 913 914**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 915 916**Since**: 8 917 918**Parameters** 919 920| Name| Description| 921| -------- | -------- | 922| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.| 923 924**Returns** 925 926Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 927 928 929### OH_NativeWindow_NativeWindowAbortBuffer() 930 931``` 932int32_t OH_NativeWindow_NativeWindowAbortBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer ) 933``` 934 935**Description** 936 937Returns the **OHNativeWindowBuffer** to the buffer queue through an **OHNativeWindow** instance, without filling in any content. The **OHNativeWindowBuffer** can be used for a new request. 938 939This function is not thread-safe. 940 941**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 942 943**Since**: 8 944 945**Parameters** 946 947| Name| Description| 948| -------- | -------- | 949| window | Pointer to an **OHNativeWindow** instance.| 950| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 951 952**Returns** 953 954Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 955 956### OH_NativeWindow_NativeWindowAttachBuffer() 957 958``` 959int32_t OH_NativeWindow_NativeWindowAttachBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer ) 960``` 961 962**Description** 963 964Attaches an **OHNativeWindowBuffer** to an **OHNativeWindow** instance. 965 966This function must be used in pair with **OH_NativeWindow_NativeWindowDetachBuffer**. Otherwise, memory management disorder may occur. 967 968This function is not thread-safe. 969 970**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 971 972**Since**: 12 973 974**Parameters** 975 976| Name| Description| 977| -------- | -------- | 978| window | Pointer to an **OHNativeWindow** instance.| 979| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 980 981**Returns** 982 983Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 984 985 986### OH_NativeWindow_NativeWindowDetachBuffer() 987 988``` 989int32_t OH_NativeWindow_NativeWindowDetachBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer ) 990``` 991 992**Description** 993 994Detaches an **OHNativeWindowBuffer** from an **OHNativeWindow** instance. 995 996This function is not thread-safe. 997 998**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 999 1000**Since**: 12 1001 1002**Parameters** 1003 1004| Name| Description| 1005| -------- | -------- | 1006| window | Pointer to an **OHNativeWindow** instance.| 1007| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 1008 1009**Returns** 1010 1011Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1012 1013 1014### OH_NativeWindow_NativeWindowFlushBuffer() 1015 1016``` 1017int32_t OH_NativeWindow_NativeWindowFlushBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer, int fenceFd, Region region ) 1018``` 1019 1020**Description** 1021 1022Flushes the **OHNativeWindowBuffer** filled with the produced content to the buffer queue through an **OHNativeWindow** instance for content consumption. 1023 1024The system will close **fenFd**. You do not need to close it. 1025 1026This function is not thread-safe. 1027 1028**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1029 1030**Since**: 8 1031 1032**Parameters** 1033 1034| Name| Description| 1035| -------- | -------- | 1036| window | Pointer to an **OHNativeWindow** instance.| 1037| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 1038| fenceFd | File descriptor handle, which is used for timing synchronization.| 1039| region | Dirty region where content is updated.| 1040 1041**Returns** 1042 1043Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1044 1045 1046### OH_NativeWindow_NativeWindowHandleOpt() 1047 1048``` 1049int32_t OH_NativeWindow_NativeWindowHandleOpt (OHNativeWindow *window, int code, ... ) 1050``` 1051 1052**Description** 1053 1054Sets or obtains the attributes of an **OHNativeWindow** instance, including the width, height, and content format. 1055 1056This function is not thread-safe. 1057 1058**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1059 1060**Since**: 8 1061 1062**Parameters** 1063 1064| Name| Description| 1065| -------- | -------- | 1066| window | Pointer to an **OHNativeWindow** instance.| 1067| code | Operation code. For details, see [NativeWindowOperation](#nativewindowoperation).| 1068| ... | Variable argument, which must be the same as the data type corresponding to the operation code. The number of input parameters must be the same as that of the operation code. Otherwise, undefined behavior may occur.| 1069 1070**Returns** 1071 1072Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1073 1074 1075### OH_NativeWindow_NativeWindowRequestBuffer() 1076 1077``` 1078int32_t OH_NativeWindow_NativeWindowRequestBuffer (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd ) 1079``` 1080 1081**Description** 1082 1083Requests an **OHNativeWindowBuffer** through an **OHNativeWindow** instance for content production. 1084 1085Before calling this function, you must call **SET_BUFFER_GEOMETRY** to set the width and height of **OHNativeWindow**. 1086 1087This function must be used in pair with **OH_NativeWindow_NativeWindowFlushBuffer**. Otherwise, memory leak occurs. 1088 1089When **fenceFd** is used up, you must close it. 1090 1091This function is not thread-safe. 1092 1093**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1094 1095**Since**: 8 1096 1097**Parameters** 1098 1099| Name| Description| 1100| -------- | -------- | 1101| window | Pointer to an **OHNativeWindow** instance.| 1102| buffer | Double pointer to an **OHNativeWindowBuffer** instance.| 1103| fenceFd | Pointer to a file descriptor handle.| 1104 1105**Returns** 1106 1107Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1108 1109 1110### OH_NativeWindow_NativeWindowSetMetaData() 1111 1112``` 1113int32_t OH_NativeWindow_NativeWindowSetMetaData (OHNativeWindow *window, uint32_t sequence, int32_t size, const OHHDRMetaData *metaData ) 1114``` 1115 1116**Description** 1117 1118Sets metadata for an **OHNativeWindow**. 1119 1120**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1121 1122**Since**: 9 1123 1124**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1125 1126**Parameters** 1127 1128| Name| Description| 1129| -------- | -------- | 1130| window | Pointer to an **OHNativeWindow** instance.| 1131| sequence | Sequence of the producer buffer.| 1132| size | Size of the **OHHDRMetaData** array.| 1133| metaData| Pointer to the **OHHDRMetaData** array.| 1134 1135**Returns** 1136 1137Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1138 1139 1140### OH_NativeWindow_NativeWindowSetMetaDataSet() 1141 1142``` 1143int32_t OH_NativeWindow_NativeWindowSetMetaDataSet (OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key, int32_t size, const uint8_t *metaData ) 1144``` 1145 1146**Description** 1147 1148Sets a metadata set for an **OHNativeWindow**. 1149 1150**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1151 1152**Since**: 9 1153 1154**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1155 1156**Parameters** 1157 1158| Name| Description| 1159| -------- | -------- | 1160| window | Pointer to an **OHNativeWindow** instance.| 1161| sequence | Sequence of the producer buffer.| 1162| key | Metadata key. For details, see [OHHDRMetadataKey](#ohhdrmetadatakey).| 1163| size | Size of the uint8_t vector.| 1164| metaData| Pointer to the uint8_t vector.| 1165 1166**Returns** 1167 1168Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1169 1170 1171### OH_NativeWindow_NativeWindowSetScalingMode() 1172 1173``` 1174int32_t OH_NativeWindow_NativeWindowSetScalingMode (OHNativeWindow *window, uint32_t sequence, OHScalingMode scalingMode ) 1175``` 1176 1177**Description** 1178 1179Sets a scaling mode for an **OHNativeWindow**. 1180 1181**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1182 1183**Since**: 9 1184 1185**Deprecated from**: 10 1186 1187**Substitute**: [OH_NativeWindow_NativeWindowSetScalingModeV2](#oh_nativewindow_nativewindowsetscalingmodev2) 1188 1189**Parameters** 1190 1191| Name| Description| 1192| -------- | -------- | 1193| window | Pointer to an **OHNativeWindow** instance.| 1194| sequence | Sequence of the producer buffer.| 1195| scalingMode | Scaling mode to set. For details, see [OHScalingMode](#ohscalingmode).| 1196 1197**Returns** 1198 1199Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1200 1201 1202### OH_NativeWindow_NativeWindowSetScalingModeV2() 1203 1204``` 1205int32_t OH_NativeWindow_NativeWindowSetScalingModeV2 (OHNativeWindow* window, OHScalingModeV2 scalingMode ) 1206``` 1207**Description** 1208Sets a rendering scaling mode for an **OHNativeWindow** instance. 1209 1210This function is not thread-safe. 1211 1212**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1213 1214**Since**: 12 1215 1216**Parameters** 1217 1218| Name| Description| 1219| -------- | -------- | 1220| window | Pointer to an **OHNativeWindow** instance. | 1221| scalingMode | Scaling mode. For details about the available options, see **OHScalingModeV2**. | 1222 1223**Returns** 1224 1225Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1226 1227### OH_NativeWindow_NativeWindowSetTunnelHandle() 1228 1229``` 1230int32_t OH_NativeWindow_NativeWindowSetTunnelHandle (OHNativeWindow *window, const OHExtDataHandle *handle ) 1231``` 1232 1233**Description** 1234 1235Sets a tunnel handle to an **OHNativeWindow**. 1236 1237**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1238 1239**Since**: 9 1240 1241**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1242 1243**Parameters** 1244 1245| Name| Description| 1246| -------- | -------- | 1247| window | Pointer to an **OHNativeWindow** instance.| 1248| handle | Pointer to an [OHExtDataHandle](_o_h_ext_data_handle.md).| 1249 1250**Returns** 1251 1252Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1253