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>} | 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 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.| 267| SET_FORMAT | Setting the format for the local window buffer.<br>Variable argument in the function: [Input] int32_t format.| 268| GET_USAGE | Obtaining the usage mode of the local window buffer.<br>Variable argument in the function: [Output] uint64_t \*usage.| 269| SET_USAGE | Setting the usage mode for the local window buffer.<br>Variable argument in the function: [Input] uint64_t usage.| 270| SET_STRIDE | Setting the stride for the local window buffer.<br>Variable argument in the function: [Input] int32_t stride.| 271| GET_STRIDE | Obtaining the stride of the local window buffer.<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.<br>Variable argument in the function: [Input] int32_t timeout.| 275| GET_TIMEOUT | Obtaining the timeout duration for requesting the local window buffer.<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.| 277| GET_COLOR_GAMUT | Obtaining the color gamut of the local window buffer.<br>Variable argument in the function: [Output] int32_t *colorGamut.| 278| SET_TRANSFORM | Setting the transform for the local window buffer.<br>Variable argument in the function: [Input] int32_t transform.| 279| GET_TRANSFORM | Obtaining the transform of the local window buffer.<br>Variable argument in the function: [Output] int32_t *transform.| 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 289### OHHDRMetadataKey 290 291``` 292enum OHHDRMetadataKey 293``` 294 295**Description** 296 297Enumerates the HDR metadata keys. 298 299**Since**: 9 300 301**Deprecated**: This enum is deprecated since API version 10. No substitute is provided. 302 303| Value| Description| 304| -------- | -------- | 305| OH_METAKEY_RED_PRIMARY_X | X coordinate of the red primary color.| 306| OH_METAKEY_RED_PRIMARY_Y | Y coordinate of the red primary color.| 307| OH_METAKEY_GREEN_PRIMARY_X | X coordinate of the green primary color.| 308| OH_METAKEY_GREEN_PRIMARY_Y | Y coordinate of the green primary color.| 309| OH_METAKEY_BLUE_PRIMARY_X | X coordinate of the blue primary color.| 310| OH_METAKEY_BLUE_PRIMARY_Y | Y coordinate of the blue primary color.| 311| OH_METAKEY_WHITE_PRIMARY_X | X coordinate of the white point.| 312| OH_METAKEY_WHITE_PRIMARY_Y | Y coordinate of the white point.| 313| OH_METAKEY_MAX_LUMINANCE | Maximum luminance.| 314| OH_METAKEY_MIN_LUMINANCE | Minimum luminance.| 315| OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL | Maximum content light level (MaxCLL).| 316| OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL | Maximum frame average light level (MaxFALLL).| 317| OH_METAKEY_HDR10_PLUS | HDR10 Plus.| 318| OH_METAKEY_HDR_VIVID | Vivid.| 319 320 321### OHScalingMode 322 323``` 324enum OHScalingMode 325``` 326 327**Description** 328 329Enumerates the scaling modes. 330 331**Since**: 9 332 333**Deprecated**: This enum is deprecated since API version 10. No substitute is provided. 334 335| Value| Description| 336| -------- | -------- | 337| OH_SCALING_MODE_FREEZE | The window content cannot be updated before the buffer of the window size is received.| 338| OH_SCALING_MODE_SCALE_TO_WINDOW | The buffer is scaled in two dimensions to match the window size.| 339| OH_SCALING_MODE_SCALE_CROP | The buffer is scaled uniformly so that its smaller size can match the window size.| 340| 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.| 341 342 343### OHScalingModeV2 344 345``` 346enum OHScalingModeV2 347``` 348**Description** 349 350Enumerates the rendering scaling modes. 351 352**Since**: 12 353 354| Value| Description| 355| -------- | -------- | 356| 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.| 357| OH_SCALING_MODE_SCALE_TO_WINDOW_V2 | Scales the buffer to match the window size.| 358| 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.| 359| OH_SCALING_MODE_NO_SCALE_CROP_V2 | Crops the buffer by window size. Pixels outside the cropping rectangle are considered completely transparent.| 360| 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.| 361 362 363## Function Description 364 365### OH_NativeWindow_SetColorSpace() 366 367``` 368int32_t OH_NativeWindow_SetColorSpace (OHNativeWindow *window, OH_NativeBuffer_ColorSpace colorSpace ) 369``` 370 371**Description** 372 373Sets the color space for an **OHNativeWindow** instance. 374 375This function is not thread-safe. 376 377**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 378 379**Since**: 12 380 381**Parameters** 382 383| Name| Description| 384| -------- | -------- | 385| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 386| colorSpace | Color space. For details about the available options, see [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace).| 387 388**Returns** 389 390Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 391 392 393### OH_NativeWindow_SetMetadataValue() 394 395``` 396int32_t OH_NativeWindow_SetMetadataValue (OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t size, uint8_t * metaData ) 397``` 398 399**Description** 400 401Sets a metadata value for an **OHNativeWindow** instance. 402 403This function is not thread-safe. 404 405**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 406 407**Since**: 12 408 409**Parameters** 410 411| Name| Description| 412| -------- | -------- | 413| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 414| metadataKey | Key of the metadata. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).| 415| 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).| 416| metaData| Pointer to the uint8_t vector.| 417 418**Returns** 419 420Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 421 422### OH_NativeWindow_GetColorSpace() 423 424``` 425int32_t OH_NativeWindow_GetColorSpace (OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace ) 426``` 427 428**Description** 429 430Obtains the color space of an **OHNativeWindow** instance. 431 432This function is not thread-safe. 433 434**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 435 436**Since**: 12 437 438**Parameters** 439 440| Name| Description| 441| -------- | -------- | 442| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 443| colorSpace | Pointer to the color space. For details about the available options, see [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace).| 444 445**Returns** 446 447Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 448 449 450### OH_NativeWindow_GetMetadataValue() 451 452``` 453int32_t OH_NativeWindow_GetMetadataValue (OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t *size, uint8_t **metaData ) 454``` 455 456**Description** 457 458Obtains the metadata value of an **OHNativeWindow** instance. 459 460This function is not thread-safe. 461 462**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 463 464**Since**: 12 465 466**Parameters** 467 468| Name| Description| 469| -------- | -------- | 470| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 471| metadataKey | Key of the metadata. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).| 472| 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).| 473| metaData| Double pointer to the uint8_t vector.| 474 475**Returns** 476 477Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode) otherwise. 478 479 480### OH_NativeWindow_WriteToParcel() 481 482``` 483int32_t OH_NativeWindow_WriteToParcel (OHNativeWindow *window, OHIPCParcel *parcel ) 484``` 485 486**Description** 487 488Writes an **OHNativeWindow** instance to an **OHIPCParcel** instance. 489 490This function is not thread-safe. 491 492**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 493 494**Since**: 12 495 496**Parameters** 497 498| Name| Description| 499| -------- | -------- | 500| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.| 501| parcel | Pointer to an [OHIPCParcel](#ohipcparcel) instance.| 502 503**Returns** 504 505Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 506 507 508### OH_NativeWindow_ReadFromParcel() 509 510``` 511int32_t OH_NativeWindow_ReadFromParcel (OHIPCParcel *parcel, OHNativeWindow **window ) 512``` 513 514**Description** 515 516Reads an **OHNativeWindow** instance from an **OHIPCParcel** instance. 517 518This function is not thread-safe. 519 520**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 521 522**Since**: 12 523 524**Parameters** 525 526| Name| Description| 527| -------- | -------- | 528| parcel | Pointer to an [OHIPCParcel](#ohipcparcel) instance.| 529| window | Double pointer to an [OHNativeWindow](#ohnativewindow) instance.| 530 531**Returns** 532 533Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 534 535 536 537### OH_NativeWindow_GetLastFlushedBufferV2() 538 539``` 540int32_t OH_NativeWindow_GetLastFlushedBufferV2 (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16] ) 541``` 542 543**Description** 544 545Obtains 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. 546 547This function must be used in pair with **OH_NativeWindow_NativeObjectUnreference**. Otherwise, memory leak occurs. 548 549This function is not thread-safe. 550 551**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 552 553**Since**: 12 554 555**Parameters** 556 557| Name| Description| 558| -------- | -------- | 559| window | Pointer to an **OHNativeWindow** instance. | 560| buffer | Double pointer to an **OHNativeWindowBuffer** instance. | 561| fenceFd | Pointer to a file descriptor. | 562| matrix | Retrieved 4*4 transformation matrix. | 563 564**Returns** 565 566Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 567 568 569 570### OH_NativeWindow_SetBufferHold() 571 572``` 573void OH_NativeWindow_SetBufferHold (OHNativeWindow *window) 574``` 575**Description** 576Buffers a frame in advance and holds it for the interval of a frame to offset the possible loss of subsequent oversized frames. 577 578This function is not thread-safe. 579 580**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 581 582**Since**: 12 583 584**Parameters** 585 586| Name| Description| 587| -------- | -------- | 588| window | Pointer to an [OHNativeWindow](_o_h___native_image.md#ohnativewindow) instance. | 589 590 591 592### OH_NativeWindow_CreateNativeWindow() 593 594``` 595OHNativeWindow* OH_NativeWindow_CreateNativeWindow (void* pSurface) 596``` 597 598**Description** 599 600Creates 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**. 601 602**Deprecated from**: 12 603 604**Substitute**: No substitute is provided. 605 606**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 607 608**Since**: 8 609 610**Parameters** 611 612| Name| Description| 613| -------- | -------- | 614| pSurface | Pointer to a **ProduceSurface**. The type is **sptr<OHOS::Surface>**.| 615 616**Returns** 617 618Returns the pointer to the **OHNativeWindow** instance created. 619 620 621### OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer() 622 623``` 624OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer (OH_NativeBuffer* nativeBuffer) 625``` 626 627**Description** 628 629Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called. 630 631This function must be used in pair with **OH_NativeWindow_DestroyNativeWindowBuffer**. Otherwise, memory leak occurs. 632 633This function is not thread-safe. 634 635**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 636 637**Since**: 11 638 639**Parameters** 640 641| Name| Description| 642| -------- | -------- | 643| nativeBuffer | Pointer to an **OH_NativeBuffer** instance.| 644 645**Returns** 646 647Returns the pointer to the **OHNativeWindowBuffer** instance created. 648 649 650### OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer() 651 652``` 653OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer (void* pSurfaceBuffer) 654``` 655 656**Description** 657 658Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called. 659 660**Deprecated from**: 12 661 662**Substitute**: [OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer](#oh_nativewindow_createnativewindowbufferfromnativebuffer) 663 664**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 665 666**Since**: 8 667 668**Parameters** 669 670| Name| Description| 671| -------- | -------- | 672| pSurfaceBuffer | Pointer to a **ProduceSurfaceBuffer**. The type is **sptr<OHOS::SurfaceBuffer>**.| 673 674**Returns** 675 676Returns the pointer to the **OHNativeWindowBuffer** instance created. 677 678 679### OH_NativeWindow_CreateNativeWindowFromSurfaceId() 680 681``` 682int32_t OH_NativeWindow_CreateNativeWindowFromSurfaceId (uint64_t surfaceId, OHNativeWindow **window ) 683``` 684 685**Description** 686 687Creates an **OHNativeWindow** instance based on a surface ID. 688This function must be used in pair with **OH_NativeWindow_DestroyNativeWindow**. Otherwise, memory leak occurs. 689 690If **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**. 691 692The surface obtained by using the surface ID must be created in the current process, but not in a different process. 693 694This function is not thread-safe. 695 696**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 697 698**Since**: 12 699 700**Parameters** 701 702| Name| Description| 703| -------- | -------- | 704| surfaceId | Surface ID.| 705| window | Double pointer to an **OHNativeWindow** instance.| 706 707**Returns** 708 709Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 710 711 712### OH_NativeWindow_DestroyNativeWindow() 713 714``` 715void OH_NativeWindow_DestroyNativeWindow (OHNativeWindow* window) 716``` 717 718**Description** 719 720Decreases the reference count of an **OHNativeWindow** instance by 1 and when the reference count reaches 0, destroys the instance. 721 722This function is not thread-safe. 723 724**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 725 726**Since**: 8 727 728**Parameters** 729 730| Name| Description| 731| -------- | -------- | 732| window | Pointer to an **OHNativeWindow** instance.| 733 734 735### OH_NativeWindow_DestroyNativeWindowBuffer() 736 737``` 738void OH_NativeWindow_DestroyNativeWindowBuffer (OHNativeWindowBuffer* buffer) 739``` 740 741**Description** 742 743Decreases the reference count of an **OHNativeWindowBuffer** instance by 1 and when the reference count reaches 0, destroys the instance. 744 745This function is not thread-safe. 746 747**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 748 749**Since**: 8 750 751**Parameters** 752 753| Name| Description| 754| -------- | -------- | 755| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 756 757 758### OH_NativeWindow_GetBufferHandleFromNative() 759 760``` 761BufferHandle* OH_NativeWindow_GetBufferHandleFromNative (OHNativeWindowBuffer* buffer) 762``` 763 764**Description** 765 766Obtains the pointer to a **BufferHandle** of an **OHNativeWindowBuffer** instance. 767 768This function is not thread-safe. 769 770**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 771 772**Since**: 8 773 774**Parameters** 775 776| Name| Description| 777| -------- | -------- | 778| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 779 780**Returns** 781 782Returns the pointer to the **BufferHandle** instance obtained. 783 784 785### OH_NativeWindow_GetLastFlushedBuffer() 786 787``` 788int32_t OH_NativeWindow_GetLastFlushedBuffer (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16] ) 789``` 790 791**Description** 792 793Obtains the **OHNativeWindowBuffer** that was flushed to the buffer queue last time through an **OHNativeWindow** instance. 794 795**Deprecated from**: 12 796 797**Substitute**: [OH_NativeWindow_GetLastFlushedBufferV2](#oh_nativewindow_getlastflushedbufferv2) 798 799**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 800 801**Since**: 11 802 803**Parameters** 804 805| Name| Description| 806| -------- | -------- | 807| window | Pointer to an **OHNativeWindow** instance.| 808| buffer | Double pointer to an **OHNativeWindowBuffer** instance.| 809| fenceFd | Pointer to a file descriptor.| 810| matrix | Retrieved 4*4 transformation matrix.| 811 812**Returns** 813 814Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 815 816 817### OH_NativeWindow_GetNativeObjectMagic() 818 819``` 820int32_t OH_NativeWindow_GetNativeObjectMagic (void *obj) 821``` 822 823**Description** 824 825Obtains the magic ID of a native object. 826 827This function is not thread-safe. 828 829**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 830 831**Since**: 8 832 833**Parameters** 834 835| Name| Description| 836| -------- | -------- | 837| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.| 838 839**Returns** 840 841Returns the magic ID, which is unique for each native object. 842 843 844### OH_NativeWindow_GetSurfaceId() 845 846``` 847int32_t OH_NativeWindow_GetSurfaceId (OHNativeWindow *window, uint64_t *surfaceId ) 848``` 849 850**Description** 851 852Obtains a surface ID through an **OHNativeWindow**. 853 854This function is not thread-safe. 855 856**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 857 858**Since**: 12 859 860**Parameters** 861 862| Name| Description| 863| -------- | -------- | 864| window | Pointer to an **OHNativeWindow** instance.| 865| surfaceId | Pointer to the surface ID.| 866 867**Returns** 868 869Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 870 871 872### OH_NativeWindow_NativeObjectReference() 873 874``` 875int32_t OH_NativeWindow_NativeObjectReference (void *obj) 876``` 877 878**Description** 879 880Adds the reference count of a native object. 881 882This function must be used in pair with **OH_NativeWindow_NativeObjectUnreference**. Otherwise, memory leak occurs. 883 884This function is not thread-safe. 885 886**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 887 888**Since**: 8 889 890**Parameters** 891 892| Name| Description| 893| -------- | -------- | 894| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.| 895 896**Returns** 897 898Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 899 900 901### OH_NativeWindow_NativeObjectUnreference() 902 903``` 904int32_t OH_NativeWindow_NativeObjectUnreference (void *obj) 905``` 906 907**Description** 908 909Decreases the reference count of a native object and when the reference count reaches 0, destroys this object. 910 911This function is not thread-safe. 912 913**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 914 915**Since**: 8 916 917**Parameters** 918 919| Name| Description| 920| -------- | -------- | 921| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.| 922 923**Returns** 924 925Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 926 927 928### OH_NativeWindow_NativeWindowAbortBuffer() 929 930``` 931int32_t OH_NativeWindow_NativeWindowAbortBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer ) 932``` 933 934**Description** 935 936Returns the **OHNativeWindowBuffer** to the buffer queue through an **OHNativeWindow** instance, without filling in any content. The **OHNativeWindowBuffer** can be used for a new request. 937 938This function is not thread-safe. 939 940**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 941 942**Since**: 8 943 944**Parameters** 945 946| Name| Description| 947| -------- | -------- | 948| window | Pointer to an **OHNativeWindow** instance.| 949| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 950 951**Returns** 952 953Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 954 955### OH_NativeWindow_NativeWindowAttachBuffer() 956 957``` 958int32_t OH_NativeWindow_NativeWindowAttachBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer ) 959``` 960 961**Description** 962 963Attaches an **OHNativeWindowBuffer** to an **OHNativeWindow** instance. 964 965This function must be used in pair with **OH_NativeWindow_NativeWindowDetachBuffer**. Otherwise, memory management disorder may occur. 966 967This function is not thread-safe. 968 969**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 970 971**Since**: 12 972 973**Parameters** 974 975| Name| Description| 976| -------- | -------- | 977| window | Pointer to an **OHNativeWindow** instance.| 978| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 979 980**Returns** 981 982Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 983 984 985### OH_NativeWindow_NativeWindowDetachBuffer() 986 987``` 988int32_t OH_NativeWindow_NativeWindowDetachBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer ) 989``` 990 991**Description** 992 993Detaches an **OHNativeWindowBuffer** from an **OHNativeWindow** instance. 994 995This function is not thread-safe. 996 997**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 998 999**Since**: 12 1000 1001**Parameters** 1002 1003| Name| Description| 1004| -------- | -------- | 1005| window | Pointer to an **OHNativeWindow** instance.| 1006| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 1007 1008**Returns** 1009 1010Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1011 1012 1013### OH_NativeWindow_NativeWindowFlushBuffer() 1014 1015``` 1016int32_t OH_NativeWindow_NativeWindowFlushBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer, int fenceFd, Region region ) 1017``` 1018 1019**Description** 1020 1021Flushes the **OHNativeWindowBuffer** filled with the produced content to the buffer queue through an **OHNativeWindow** instance for content consumption. 1022 1023The system will close **fenFd**. You do not need to close it. 1024 1025This function is not thread-safe. 1026 1027**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1028 1029**Since**: 8 1030 1031**Parameters** 1032 1033| Name| Description| 1034| -------- | -------- | 1035| window | Pointer to an **OHNativeWindow** instance.| 1036| buffer | Pointer to an **OHNativeWindowBuffer** instance.| 1037| fenceFd | File descriptor handle, which is used for timing synchronization.| 1038| region | Dirty region where content is updated.| 1039 1040**Returns** 1041 1042Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1043 1044 1045### OH_NativeWindow_NativeWindowHandleOpt() 1046 1047``` 1048int32_t OH_NativeWindow_NativeWindowHandleOpt (OHNativeWindow *window, int code, ... ) 1049``` 1050 1051**Description** 1052 1053Sets or obtains the attributes of an **OHNativeWindow** instance, including the width, height, and content format. 1054 1055This function is not thread-safe. 1056 1057**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1058 1059**Since**: 8 1060 1061**Parameters** 1062 1063| Name| Description| 1064| -------- | -------- | 1065| window | Pointer to an **OHNativeWindow** instance.| 1066| code | Operation code. For details, see [NativeWindowOperation](#nativewindowoperation).| 1067| ... | 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.| 1068 1069**Returns** 1070 1071Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1072 1073 1074### OH_NativeWindow_NativeWindowRequestBuffer() 1075 1076``` 1077int32_t OH_NativeWindow_NativeWindowRequestBuffer (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd ) 1078``` 1079 1080**Description** 1081 1082Requests an **OHNativeWindowBuffer** through an **OHNativeWindow** instance for content production. 1083 1084Before calling this function, you must call **SET_BUFFER_GEOMETRY** to set the width and height of **OHNativeWindow**. 1085 1086This function must be used in pair with **OH_NativeWindow_NativeWindowFlushBuffer**. Otherwise, memory leak occurs. 1087 1088When **fenceFd** is used up, you must close it. 1089 1090This function is not thread-safe. 1091 1092**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1093 1094**Since**: 8 1095 1096**Parameters** 1097 1098| Name| Description| 1099| -------- | -------- | 1100| window | Pointer to an **OHNativeWindow** instance.| 1101| buffer | Double pointer to an **OHNativeWindowBuffer** instance.| 1102| fenceFd | Pointer to a file descriptor handle.| 1103 1104**Returns** 1105 1106Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1107 1108 1109### OH_NativeWindow_NativeWindowSetMetaData() 1110 1111``` 1112int32_t OH_NativeWindow_NativeWindowSetMetaData (OHNativeWindow *window, uint32_t sequence, int32_t size, const OHHDRMetaData *metaData ) 1113``` 1114 1115**Description** 1116 1117Sets metadata for an **OHNativeWindow**. 1118 1119**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1120 1121**Since**: 9 1122 1123**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1124 1125**Parameters** 1126 1127| Name| Description| 1128| -------- | -------- | 1129| window | Pointer to an **OHNativeWindow** instance.| 1130| sequence | Sequence of the producer buffer.| 1131| size | Size of the **OHHDRMetaData** array.| 1132| metaData| Pointer to the **OHHDRMetaData** array.| 1133 1134**Returns** 1135 1136Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1137 1138 1139### OH_NativeWindow_NativeWindowSetMetaDataSet() 1140 1141``` 1142int32_t OH_NativeWindow_NativeWindowSetMetaDataSet (OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key, int32_t size, const uint8_t *metaData ) 1143``` 1144 1145**Description** 1146 1147Sets a metadata set for an **OHNativeWindow**. 1148 1149**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1150 1151**Since**: 9 1152 1153**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1154 1155**Parameters** 1156 1157| Name| Description| 1158| -------- | -------- | 1159| window | Pointer to an **OHNativeWindow** instance.| 1160| sequence | Sequence of the producer buffer.| 1161| key | Metadata key. For details, see [OHHDRMetadataKey](#ohhdrmetadatakey).| 1162| size | Size of the uint8_t vector.| 1163| metaData| Pointer to the uint8_t vector.| 1164 1165**Returns** 1166 1167Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1168 1169 1170### OH_NativeWindow_NativeWindowSetScalingMode() 1171 1172``` 1173int32_t OH_NativeWindow_NativeWindowSetScalingMode (OHNativeWindow *window, uint32_t sequence, OHScalingMode scalingMode ) 1174``` 1175 1176**Description** 1177 1178Sets a scaling mode for an **OHNativeWindow**. 1179 1180**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1181 1182**Since**: 9 1183 1184**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1185 1186**Parameters** 1187 1188| Name| Description| 1189| -------- | -------- | 1190| window | Pointer to an **OHNativeWindow** instance.| 1191| sequence | Sequence of the producer buffer.| 1192| scalingMode | Scaling mode to set. For details, see [OHScalingMode](#ohscalingmode).| 1193 1194**Returns** 1195 1196Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1197 1198 1199### OH_NativeWindow_NativeWindowSetScalingModeV2() 1200 1201``` 1202int32_t OH_NativeWindow_NativeWindowSetScalingModeV2 (OHNativeWindow* window, OHScalingModeV2 scalingMode ) 1203``` 1204**Description** 1205Sets a rendering scaling mode for an **OHNativeWindow** instance. 1206 1207This function is not thread-safe. 1208 1209**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1210 1211**Since**: 12 1212 1213**Parameters** 1214 1215| Name| Description| 1216| -------- | -------- | 1217| window | Pointer to an **OHNativeWindow** instance. | 1218| scalingMode | Scaling mode. For details about the available options, see **OHScalingModeV2**. | 1219 1220**Returns** 1221 1222Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1223 1224### OH_NativeWindow_NativeWindowSetTunnelHandle() 1225 1226``` 1227int32_t OH_NativeWindow_NativeWindowSetTunnelHandle (OHNativeWindow *window, const OHExtDataHandle *handle ) 1228``` 1229 1230**Description** 1231 1232Sets a tunnel handle to an **OHNativeWindow**. 1233 1234**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow 1235 1236**Since**: 9 1237 1238**Deprecated**: This function is deprecated since API version 10. No substitute is provided. 1239 1240**Parameters** 1241 1242| Name| Description| 1243| -------- | -------- | 1244| window | Pointer to an **OHNativeWindow** instance.| 1245| handle | Pointer to an [OHExtDataHandle](_o_h_ext_data_handle.md).| 1246 1247**Returns** 1248 1249Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 1250