• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# NativeWindow
2
3
4## Overview
5
6The NativeWindow module provides the image buffer rotation capability, compatible with EGL. As the producer of the image buffer, your application produces the buffer and transfers the buffer through NativeWindow for the consumer to read.
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| struct  [BufferHandle](_buffer_handle.md) | Describes the buffer handle, which is used to transfer and obtain buffer information. The handle contains the file descriptor, size, format, usage, virtual address, shared memory key, physical address, and custom data of the buffer. |
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_MEM_OPERATION_ERROR = 30001000, 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](_buffer_handle.md) \* [OH_NativeWindow_GetBufferHandleFromNative](#oh_nativewindow_getbufferhandlefromnative) ([OHNativeWindowBuffer](#ohnativewindowbuffer) \*buffer) | Obtains the pointer to a **BufferHandle** of an **OHNativeWindowBuffer** instance.<br>This function is not thread-safe.|
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  | Success.  |
230| NATIVE_ERROR_MEM_OPERATION_ERROR<sup>15+</sup> | An error occurs during memory manipulation.|
231| NATIVE_ERROR_INVALID_ARGUMENTS  | Invalid input parameter.  |
232| NATIVE_ERROR_NO_PERMISSION  | You do not have the permission to perform the operation.  |
233| NATIVE_ERROR_NO_BUFFER  | No buffer is available.  |
234| NATIVE_ERROR_NO_CONSUMER  | The consumer does not exist.  |
235| NATIVE_ERROR_NOT_INIT  | Not initialized.  |
236| NATIVE_ERROR_CONSUMER_CONNECTED  | The consumer is connected.  |
237| NATIVE_ERROR_BUFFER_STATE_INVALID  | The buffer status does not meet the expectation.  |
238| NATIVE_ERROR_BUFFER_IN_CACHE  | The buffer is already in the buffer queue.  |
239| NATIVE_ERROR_BUFFER_QUEUE_FULL  | The queue is full.  |
240| NATIVE_ERROR_BUFFER_NOT_IN_CACHE  | The buffer is not in the buffer queue.  |
241| NATIVE_ERROR_CONSUMER_DISCONNECTED | The consumer is disconnected.|
242| NATIVE_ERROR_CONSUMER_NO_LISTENER_REGISTERED | No listener is registered on the consumer side.|
243| NATIVE_ERROR_UNSUPPORTED  | The device or platform does not support the operation.  |
244| NATIVE_ERROR_UNKNOWN  | Unknown error. Check the log.  |
245| NATIVE_ERROR_HDI_ERROR  | Failed to call the HDI.  |
246| NATIVE_ERROR_BINDER_ERROR  | Cross-process communication failed.  |
247| NATIVE_ERROR_EGL_STATE_UNKNOWN  | The EGL environment is abnormal.  |
248| NATIVE_ERROR_EGL_API_FAILED  | Failed to call the EGL APIs.  |
249
250
251### NativeWindowOperation
252
253```
254enum NativeWindowOperation
255```
256
257**Description**
258
259Enumerates the operation codes in the **OH_NativeWindow_NativeWindowHandleOpt** function.
260
261**Since**: 8
262
263| Value| Description|
264| -------- | -------- |
265| 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.|
266| 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.|
267| 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).|
268| 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).|
269| 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).|
270| 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).|
271| SET_STRIDE<sup>(deprecated)</sup>  | Setting the stride for the local window buffer.<br>Variable argument in the function: [Input] int32_t stride.<br>**Deprecated**: This API is deprecated since API version 16.|
272| GET_STRIDE<sup>(deprecated)</sup>  | Obtaining the stride of the local window buffer.<br>Variable argument in the function: [Output] int32_t *stride.<br>**Deprecated**: This API is deprecated since API version 16.<br>**Substitute**: Use [OH_NativeWindow_GetBufferHandleFromNative](#oh_nativewindow_getbufferhandlefromnative) to obtain a [BufferHandle](_buffer_handle.md) instance, and obtain the stride from this instance.|
273| SET_SWAP_INTERVAL | Setting the swap interval for the local window buffer.<br>Variable argument in the function: [Input] int32_t interval.|
274| GET_SWAP_INTERVAL | Obtaining the swap interval of the local window buffer.<br>Variable argument in the function: [Output] int32_t \*interval.|
275| 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.|
276| 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.|
277| 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).|
278| 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).|
279| 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). |
280| 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). |
281| SET_UI_TIMESTAMP | Setting the UI timestamp for the local window buffer.<br>Variable argument in the function: [Input] uint64_t uiTimestamp.|
282| GET_BUFFERQUEUE_SIZE<sup>12+</sup> | Obtaining the memory queue size.<br>Variable argument in the function: [Output] int32_t \*size.|
283| 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).|
284| 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).|
285| 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.|
286| 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.|
287| 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].|
288| 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].|
289| 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.|
290
291### OHHDRMetadataKey
292
293```
294enum OHHDRMetadataKey
295```
296
297**Description**
298
299Enumerates the HDR metadata keys.
300
301**Since**: 9
302
303**Deprecated**: This enum is deprecated since API version 10. No substitute is provided.
304
305| Value| Description|
306| -------- | -------- |
307| OH_METAKEY_RED_PRIMARY_X | X coordinate of the red primary color.|
308| OH_METAKEY_RED_PRIMARY_Y | Y coordinate of the red primary color.|
309| OH_METAKEY_GREEN_PRIMARY_X | X coordinate of the green primary color.|
310| OH_METAKEY_GREEN_PRIMARY_Y | Y coordinate of the green primary color.|
311| OH_METAKEY_BLUE_PRIMARY_X | X coordinate of the blue primary color.|
312| OH_METAKEY_BLUE_PRIMARY_Y | Y coordinate of the blue primary color.|
313| OH_METAKEY_WHITE_PRIMARY_X | X coordinate of the white point.|
314| OH_METAKEY_WHITE_PRIMARY_Y | Y coordinate of the white point.|
315| OH_METAKEY_MAX_LUMINANCE | Maximum luminance.|
316| OH_METAKEY_MIN_LUMINANCE | Minimum luminance.|
317| OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL | Maximum content light level (MaxCLL).|
318| OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL | Maximum frame average light level (MaxFALLL).|
319| OH_METAKEY_HDR10_PLUS | HDR10 Plus.|
320| OH_METAKEY_HDR_VIVID | Vivid.|
321
322
323### OHScalingMode
324
325```
326enum OHScalingMode
327```
328
329**Description**
330
331Enumerates the scaling modes.
332
333**Since**: 9
334
335**Deprecated**: This enum is deprecated since API version 10. No substitute is provided.
336
337| Value| Description|
338| -------- | -------- |
339| OH_SCALING_MODE_FREEZE | The window content cannot be updated before the buffer of the window size is received.|
340| OH_SCALING_MODE_SCALE_TO_WINDOW | The buffer is scaled in two dimensions to match the window size.|
341| OH_SCALING_MODE_SCALE_CROP | The buffer is scaled uniformly so that its smaller size can match the window size.|
342| 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.|
343
344
345### OHScalingModeV2
346
347```
348enum OHScalingModeV2
349```
350**Description**
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.
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 | Pointer to the 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-1) 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.
402This function is not thread-safe.
403
404**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
405
406**Since**: 12
407
408**Parameters**
409
410| Name| Description|
411| -------- | -------- |
412| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.|
413| metadataKey | Key of the metadata. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).|
414| 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).|
415| metaData| Pointer to the uint8_t vector.|
416
417**Returns**
418
419Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode-1) otherwise.
420
421### OH_NativeWindow_GetColorSpace()
422
423```
424int32_t OH_NativeWindow_GetColorSpace (OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace )
425```
426
427**Description**
428
429Obtains the color space of an **OHNativeWindow** instance.
430This function is not thread-safe.
431
432**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
433
434**Since**: 12
435
436**Parameters**
437
438| Name| Description|
439| -------- | -------- |
440| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.|
441| colorSpace | Pointer to the color space. For details about the available options, see [OH_NativeBuffer_ColorSpace](_o_h___native_buffer.md#oh_nativebuffer_colorspace).|
442
443**Returns**
444
445Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode-1) otherwise.
446
447
448### OH_NativeWindow_GetMetadataValue()
449
450```
451int32_t OH_NativeWindow_GetMetadataValue (OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, int32_t *size, uint8_t **metaData )
452```
453
454**Description**
455
456Obtains the metadata value of an **OHNativeWindow** instance.
457This function is not thread-safe.
458
459**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
460
461**Since**: 12
462
463**Parameters**
464
465| Name| Description|
466| -------- | -------- |
467| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.|
468| metadataKey | Key of the metadata. For details about the available options, see [OH_NativeBuffer_MetadataKey](_o_h___native_buffer.md#oh_nativebuffer_metadatakey).|
469| 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).|
470| metaData| Double pointer to the uint8_t vector.|
471
472**Returns**
473
474Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](_o_h___native_buffer.md#ohnativeerrorcode-1) otherwise.
475
476
477### OH_NativeWindow_WriteToParcel()
478
479```
480int32_t OH_NativeWindow_WriteToParcel (OHNativeWindow *window, OHIPCParcel *parcel )
481```
482
483**Description**
484
485Writes an **OHNativeWindow** instance to an **OHIPCParcel** instance.
486This function is not thread-safe.
487
488**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
489
490**Since**: 12
491
492**Parameters**
493
494| Name| Description|
495| -------- | -------- |
496| window | Pointer to an [OHNativeWindow](#ohnativewindow) instance.|
497| parcel | Pointer to an [OHIPCParcel](#ohipcparcel) instance.|
498
499**Returns**
500
501Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
502
503
504### OH_NativeWindow_ReadFromParcel()
505
506```
507int32_t OH_NativeWindow_ReadFromParcel (OHIPCParcel *parcel, OHNativeWindow **window )
508```
509
510**Description**
511
512Reads an **OHNativeWindow** instance from an **OHIPCParcel** instance.
513This function is not thread-safe.
514
515**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
516
517**Since**: 12
518
519**Parameters**
520
521| Name| Description|
522| -------- | -------- |
523| parcel | Pointer to an [OHIPCParcel](#ohipcparcel) instance.|
524| window | Double pointer to an [OHNativeWindow](#ohnativewindow) instance.|
525
526**Returns**
527
528Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
529
530
531
532### OH_NativeWindow_GetLastFlushedBufferV2()
533
534```
535int32_t OH_NativeWindow_GetLastFlushedBufferV2 (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16] )
536```
537
538**Description**
539
540Obtains 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.
541This function must be used in pair with **OH_NativeWindow_NativeObjectUnreference**. Otherwise, memory leak occurs.
542This function is not thread-safe.
543
544**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
545
546**Since**: 12
547
548**Parameters**
549
550| Name| Description|
551| -------- | -------- |
552| window | Pointer to an **OHNativeWindow** instance. |
553| buffer | Double pointer to an **OHNativeWindowBuffer** instance. |
554| fenceFd | Pointer to a file descriptor. |
555| matrix | Retrieved 4*4 transformation matrix. |
556
557**Returns**
558
559Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
560
561
562
563### OH_NativeWindow_SetBufferHold()
564
565```
566void OH_NativeWindow_SetBufferHold (OHNativeWindow *window)
567```
568**Description**
569Buffers a frame in advance and holds it for the interval of a frame to offset the possible loss of subsequent oversized frames.
570This function is not thread-safe.
571
572**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
573
574**Since**: 12
575
576**Parameters**
577
578| Name| Description|
579| -------- | -------- |
580| window | Pointer to an [OHNativeWindow](_o_h___native_image.md#ohnativewindow) instance. |
581
582
583
584### OH_NativeWindow_CreateNativeWindow()
585
586```
587OHNativeWindow* OH_NativeWindow_CreateNativeWindow (void* pSurface)
588```
589
590**Description**
591
592Creates 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**.
593
594**Deprecated from**: 12
595
596**Substitute**: No substitute is provided.
597
598**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
599
600**Since**: 8
601
602**Parameters**
603
604| Name| Description|
605| -------- | -------- |
606| pSurface | Pointer to a **ProduceSurface**. The type is **sptr&lt;OHOS::Surface&gt;**.|
607
608**Returns**
609
610Returns the pointer to the **OHNativeWindow** instance created.
611
612
613### OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer()
614
615```
616OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer (OH_NativeBuffer* nativeBuffer)
617```
618
619**Description**
620
621Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called.
622This function must be used in pair with **OH_NativeWindow_DestroyNativeWindowBuffer**. Otherwise, memory leak occurs.
623This function is not thread-safe.
624
625**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
626
627**Since**: 11
628
629**Parameters**
630
631| Name| Description|
632| -------- | -------- |
633| nativeBuffer | Pointer to an **OH_NativeBuffer** instance.|
634
635**Returns**
636
637Returns the pointer to the **OHNativeWindowBuffer** instance created.
638
639
640### OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer()
641
642```
643OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer (void* pSurfaceBuffer)
644```
645
646**Description**
647
648Creates an **OHNativeWindowBuffer** instance. A new **OHNativeWindowBuffer** instance is created each time this function is called.
649
650**Deprecated from**: 12
651
652**Substitute**: [OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer](#oh_nativewindow_createnativewindowbufferfromnativebuffer)
653
654**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
655
656**Since**: 8
657
658**Parameters**
659
660| Name| Description|
661| -------- | -------- |
662| pSurfaceBuffer | Pointer to a **ProduceSurfaceBuffer**. The type is **sptr&lt;OHOS::SurfaceBuffer&gt;**.|
663
664**Returns**
665
666Returns the pointer to the **OHNativeWindowBuffer** instance created.
667
668
669### OH_NativeWindow_CreateNativeWindowFromSurfaceId()
670
671```
672int32_t OH_NativeWindow_CreateNativeWindowFromSurfaceId (uint64_t surfaceId, OHNativeWindow **window )
673```
674
675**Description**
676
677Creates an **OHNativeWindow** instance based on a surface ID.
678This function must be used in pair with **OH_NativeWindow_DestroyNativeWindow**. Otherwise, memory leak occurs.
679If **OHNativeWindow** needs to be released concurrently, call **OH_NativeWindow_NativeObjectReference** and
680**OH_NativeWindow_NativeObjectUnreference** to increase or decrease the reference count by 1 for **OHNativeWindow**.
681The surface obtained by using the surface ID must be created in the current process, but not in a different process.
682This function is not thread-safe.
683
684**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
685
686**Since**: 12
687
688**Parameters**
689
690| Name| Description|
691| -------- | -------- |
692| surfaceId | Surface ID.|
693| window | Double pointer to an **OHNativeWindow** instance.|
694
695**Returns**
696
697Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
698
699
700### OH_NativeWindow_DestroyNativeWindow()
701
702```
703void OH_NativeWindow_DestroyNativeWindow (OHNativeWindow* window)
704```
705
706**Description**
707
708Decreases the reference count of an **OHNativeWindow** instance by 1 and when the reference count reaches 0, destroys the instance.
709This function is not thread-safe.
710
711**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
712
713**Since**: 8
714
715**Parameters**
716
717| Name| Description|
718| -------- | -------- |
719| window | Pointer to an **OHNativeWindow** instance.|
720
721
722### OH_NativeWindow_DestroyNativeWindowBuffer()
723
724```
725void OH_NativeWindow_DestroyNativeWindowBuffer (OHNativeWindowBuffer* buffer)
726```
727
728**Description**
729
730Decreases the reference count of an **OHNativeWindowBuffer** instance by 1 and when the reference count reaches 0, destroys the instance.
731This function is not thread-safe.
732
733**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
734
735**Since**: 8
736
737**Parameters**
738
739| Name| Description|
740| -------- | -------- |
741| buffer | Pointer to an **OHNativeWindowBuffer** instance.|
742
743
744### OH_NativeWindow_GetBufferHandleFromNative()
745
746```
747BufferHandle* OH_NativeWindow_GetBufferHandleFromNative (OHNativeWindowBuffer* buffer)
748```
749
750**Description**
751
752Obtains the pointer to a **BufferHandle** of an **OHNativeWindowBuffer** instance.
753
754This function is not thread-safe.
755
756**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
757
758**Since**: 8
759
760**Parameters**
761
762| Name| Description|
763| -------- | -------- |
764| buffer | Pointer to an **OHNativeWindowBuffer** instance.|
765
766**Returns**
767
768Returns the pointer to the [BufferHandle](_buffer_handle.md) instance created.
769
770
771### OH_NativeWindow_GetLastFlushedBuffer()
772
773```
774int32_t OH_NativeWindow_GetLastFlushedBuffer (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16] )
775```
776
777**Description**
778
779Obtains the **OHNativeWindowBuffer** that was flushed to the buffer queue last time through an **OHNativeWindow** instance.
780
781**Deprecated from**: 12
782
783**Substitute**: [OH_NativeWindow_GetLastFlushedBufferV2](#oh_nativewindow_getlastflushedbufferv2)
784
785**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
786
787**Since**: 11
788
789**Parameters**
790
791| Name| Description|
792| -------- | -------- |
793| window | Pointer to an **OHNativeWindow** instance.|
794| buffer | Double pointer to an **OHNativeWindowBuffer** instance.|
795| fenceFd | Pointer to a file descriptor.|
796| matrix | Retrieved 4*4 transformation matrix.|
797
798**Returns**
799
800Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
801
802
803### OH_NativeWindow_GetNativeObjectMagic()
804
805```
806int32_t OH_NativeWindow_GetNativeObjectMagic (void *obj)
807```
808
809**Description**
810
811Obtains the magic ID of a native object.
812This function is not thread-safe.
813
814**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
815
816**Since**: 8
817
818**Parameters**
819
820| Name| Description|
821| -------- | -------- |
822| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.|
823
824**Returns**
825
826Returns the magic ID, which is unique for each native object.
827
828
829### OH_NativeWindow_GetSurfaceId()
830
831```
832int32_t OH_NativeWindow_GetSurfaceId (OHNativeWindow *window, uint64_t *surfaceId )
833```
834
835**Description**
836
837Obtains a surface ID through an **OHNativeWindow**.
838This function is not thread-safe.
839
840**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
841
842**Since**: 12
843
844**Parameters**
845
846| Name| Description|
847| -------- | -------- |
848| window | Pointer to an **OHNativeWindow** instance.|
849| surfaceId | Pointer to the surface ID.|
850
851**Returns**
852
853Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
854
855
856### OH_NativeWindow_NativeObjectReference()
857
858```
859int32_t OH_NativeWindow_NativeObjectReference (void *obj)
860```
861
862**Description**
863
864Adds the reference count of a native object.
865This function must be used in pair with **OH_NativeWindow_NativeObjectUnreference**. Otherwise, memory leak occurs.
866This function is not thread-safe.
867
868**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
869
870**Since**: 8
871
872**Parameters**
873
874| Name| Description|
875| -------- | -------- |
876| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.|
877
878**Returns**
879
880Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
881
882
883### OH_NativeWindow_NativeObjectUnreference()
884
885```
886int32_t OH_NativeWindow_NativeObjectUnreference (void *obj)
887```
888
889**Description**
890
891Decreases the reference count of a native object and when the reference count reaches 0, destroys this object.
892This function is not thread-safe.
893
894**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
895
896**Since**: 8
897
898**Parameters**
899
900| Name| Description|
901| -------- | -------- |
902| obj | Pointer to an **OHNativeWindow** or **OHNativeWindowBuffer** instance.|
903
904**Returns**
905
906Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
907
908
909### OH_NativeWindow_NativeWindowAbortBuffer()
910
911```
912int32_t OH_NativeWindow_NativeWindowAbortBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer )
913```
914
915**Description**
916
917Returns the **OHNativeWindowBuffer** to the buffer queue through an **OHNativeWindow** instance, without filling in any content. The **OHNativeWindowBuffer** can be used for a new request.
918This function is not thread-safe.
919
920**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
921
922**Since**: 8
923
924**Parameters**
925
926| Name| Description|
927| -------- | -------- |
928| window | Pointer to an **OHNativeWindow** instance.|
929| buffer | Pointer to an **OHNativeWindowBuffer** instance.|
930
931**Returns**
932
933Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
934
935### OH_NativeWindow_NativeWindowAttachBuffer()
936
937```
938int32_t OH_NativeWindow_NativeWindowAttachBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer )
939```
940
941**Description**
942
943Attaches an **OHNativeWindowBuffer** to an **OHNativeWindow** instance.
944This function must be used in pair with **OH_NativeWindow_NativeWindowDetachBuffer**. Otherwise, memory management disorder may occur.
945This function is not thread-safe.
946
947**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
948
949**Since**: 12
950
951**Parameters**
952
953| Name| Description|
954| -------- | -------- |
955| window | Pointer to an **OHNativeWindow** instance.|
956| buffer | Pointer to an **OHNativeWindowBuffer** instance.|
957
958**Returns**
959
960Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
961
962
963### OH_NativeWindow_NativeWindowDetachBuffer()
964
965```
966int32_t OH_NativeWindow_NativeWindowDetachBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer )
967```
968
969**Description**
970
971Detaches an **OHNativeWindowBuffer** from an **OHNativeWindow** instance.
972This function is not thread-safe.
973
974**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
975
976**Since**: 12
977
978**Parameters**
979
980| Name| Description|
981| -------- | -------- |
982| window | Pointer to an **OHNativeWindow** instance.|
983| buffer | Pointer to an **OHNativeWindowBuffer** instance.|
984
985**Returns**
986
987Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
988
989
990### OH_NativeWindow_NativeWindowFlushBuffer()
991
992```
993int32_t OH_NativeWindow_NativeWindowFlushBuffer (OHNativeWindow *window, OHNativeWindowBuffer *buffer, int fenceFd, Region region )
994```
995
996**Description**
997
998Flushes the **OHNativeWindowBuffer** filled with the produced content to the buffer queue through an **OHNativeWindow** instance for content consumption.
999The system will close **fenFd**. You do not need to close it.
1000This function is not thread-safe.
1001
1002**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1003
1004**Since**: 8
1005
1006**Parameters**
1007
1008| Name| Description|
1009| -------- | -------- |
1010| window | Pointer to an **OHNativeWindow** instance.|
1011| buffer | Pointer to an **OHNativeWindowBuffer** instance.|
1012| fenceFd | File descriptor handle, which is used for timing synchronization.|
1013| region | Dirty region where content is updated.|
1014
1015**Returns**
1016
1017Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
1018
1019
1020### OH_NativeWindow_NativeWindowHandleOpt()
1021
1022```
1023int32_t OH_NativeWindow_NativeWindowHandleOpt (OHNativeWindow *window, int code,  ... )
1024```
1025
1026**Description**
1027
1028Sets or obtains the attributes of an **OHNativeWindow** instance, including the width, height, and content format.
1029This function is not thread-safe.
1030
1031**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1032
1033**Since**: 8
1034
1035**Parameters**
1036
1037| Name| Description|
1038| -------- | -------- |
1039| window | Pointer to an **OHNativeWindow** instance.|
1040| code | Operation code. For details, see [NativeWindowOperation](#nativewindowoperation).|
1041| ... | 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.|
1042
1043**Returns**
1044
1045Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
1046
1047
1048### OH_NativeWindow_NativeWindowRequestBuffer()
1049
1050```
1051int32_t OH_NativeWindow_NativeWindowRequestBuffer (OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd )
1052```
1053
1054**Description**
1055
1056Requests an **OHNativeWindowBuffer** through an **OHNativeWindow** instance for content production.
1057Before calling this function, you must call **SET_BUFFER_GEOMETRY** to set the width and height of **OHNativeWindow**.
1058This function must be used in pair with **OH_NativeWindow_NativeWindowFlushBuffer**. Otherwise, memory leak occurs.
1059When **fenceFd** is used up, you must close it.
1060This function is not thread-safe.
1061
1062**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1063
1064**Since**: 8
1065
1066**Parameters**
1067
1068| Name| Description|
1069| -------- | -------- |
1070| window | Pointer to an **OHNativeWindow** instance.|
1071| buffer | Double pointer to an **OHNativeWindowBuffer** instance.|
1072| fenceFd | Pointer to a file descriptor handle.|
1073
1074**Returns**
1075
1076Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
1077
1078
1079### OH_NativeWindow_NativeWindowSetMetaData()
1080
1081```
1082int32_t OH_NativeWindow_NativeWindowSetMetaData (OHNativeWindow *window, uint32_t sequence, int32_t size, const OHHDRMetaData *metaData )
1083```
1084
1085**Description**
1086
1087Sets metadata for an **OHNativeWindow**.
1088
1089**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1090
1091**Since**: 9
1092
1093**Deprecated**: This function is deprecated since API version 10. No substitute is provided.
1094
1095**Parameters**
1096
1097| Name| Description|
1098| -------- | -------- |
1099| window | Pointer to an **OHNativeWindow** instance.|
1100| sequence | Sequence of the producer buffer.|
1101| size | Size of the **OHHDRMetaData** array.|
1102| metaData| Pointer to the **OHHDRMetaData** array.|
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_NativeWindowSetMetaDataSet()
1110
1111```
1112int32_t OH_NativeWindow_NativeWindowSetMetaDataSet (OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key, int32_t size, const uint8_t *metaData )
1113```
1114
1115**Description**
1116
1117Sets a metadata set 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| key | Metadata key. For details, see [OHHDRMetadataKey](#ohhdrmetadatakey).|
1132| size | Size of the uint8_t vector.|
1133| metaData| Pointer to the uint8_t vector.|
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_NativeWindowSetScalingMode()
1141
1142```
1143int32_t OH_NativeWindow_NativeWindowSetScalingMode (OHNativeWindow *window, uint32_t sequence, OHScalingMode scalingMode )
1144```
1145
1146**Description**
1147
1148Sets a scaling mode for an **OHNativeWindow**.
1149
1150**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1151
1152**Since**: 9
1153
1154**Deprecated from**: 10
1155
1156**Substitute**: [OH_NativeWindow_NativeWindowSetScalingModeV2](#oh_nativewindow_nativewindowsetscalingmodev2)
1157
1158**Parameters**
1159
1160| Name| Description|
1161| -------- | -------- |
1162| window | Pointer to an **OHNativeWindow** instance.|
1163| sequence | Sequence of the producer buffer.|
1164| scalingMode | Scaling mode to set. For details, see [OHScalingMode](#ohscalingmode).|
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_NativeWindowSetScalingModeV2()
1172
1173```
1174int32_t OH_NativeWindow_NativeWindowSetScalingModeV2 (OHNativeWindow* window, OHScalingModeV2 scalingMode )
1175```
1176**Description**
1177Sets a rendering scaling mode for an **OHNativeWindow** instance.
1178This function is not thread-safe.
1179
1180**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1181
1182**Since**: 12
1183
1184**Parameters**
1185
1186| Name| Description|
1187| -------- | -------- |
1188| window | Pointer to an **OHNativeWindow** instance. |
1189| scalingMode | Scaling mode. For details about the available options, see **OHScalingModeV2**. |
1190
1191**Returns**
1192
1193Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
1194
1195### OH_NativeWindow_NativeWindowSetTunnelHandle()
1196
1197```
1198int32_t OH_NativeWindow_NativeWindowSetTunnelHandle (OHNativeWindow *window, const OHExtDataHandle *handle )
1199```
1200
1201**Description**
1202
1203Sets a tunnel handle to an **OHNativeWindow**.
1204
1205**System capability**: SystemCapability.Graphic.Graphic2D.NativeWindow
1206
1207**Since**: 9
1208
1209**Deprecated**: This function is deprecated since API version 10. No substitute is provided.
1210
1211**Parameters**
1212
1213| Name| Description|
1214| -------- | -------- |
1215| window | Pointer to an **OHNativeWindow** instance.|
1216| handle | Pointer to an [OHExtDataHandle](_o_h_ext_data_handle.md).|
1217
1218**Returns**
1219
1220Returns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise.
1221