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