• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup NativeWindow
18  * @{
19  *
20  * @brief Provides the native window capability for connection to the EGL.
21  *
22  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
23  * @since 8
24  * @version 1.0
25  */
26 
27 /**
28  * @file external_window.h
29  *
30  * @brief Defines the functions for obtaining and using a native window.
31  *
32  * @kit ArkGraphics2D
33  * @library libnative_window.so
34  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
35  * @since 8
36  * @version 1.0
37  */
38 
39 #ifndef NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_
40 #define NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_
41 
42 #include <stdint.h>
43 #include "buffer_handle.h"
44 #include "../native_buffer/buffer_common.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 typedef struct OH_NativeBuffer OH_NativeBuffer;
50 
51 /**
52  * @brief Defines the ipc parcel.
53  *
54  * @since 12
55  * @version 1.0
56  */
57 typedef struct OHIPCParcel OHIPCParcel;
58 
59 /**
60  * @brief native window.
61  * @since 8
62  */
63 struct NativeWindow;
64 
65 /**
66  * @brief native window buffer.
67  * @since 8
68  */
69 struct NativeWindowBuffer;
70 
71 /**
72  * @brief define the new type name OHNativeWindow for struct NativeWindow.
73  * @since 8
74  */
75 typedef struct NativeWindow OHNativeWindow;
76 
77 /**
78  * @brief define the new type name OHNativeWindowBuffer for struct NativeWindowBuffer.
79  * @since 8
80  */
81 typedef struct NativeWindowBuffer OHNativeWindowBuffer;
82 
83 /**
84  * @brief indicates a dirty region where content is updated.
85  * @since 8
86  */
87 typedef struct Region {
88     /** if rects is nullptr, fill the Buffer dirty size by default */
89     struct Rect {
90         int32_t x;
91         int32_t y;
92         uint32_t w;
93         uint32_t h;
94     } *rects;
95     /** if rectNumber is 0, fill the Buffer dirty size by default */
96     int32_t rectNumber;
97 }Region;
98 
99 
100 /**
101  * @brief Indicates the operation code in the function OH_NativeWindow_NativeWindowHandleOpt.
102  * @since 8
103  */
104 typedef enum NativeWindowOperation {
105     /**
106      * set native window buffer geometry,
107      * variable parameter in function is
108      * [in] int32_t width, [in] int32_t height
109      */
110     SET_BUFFER_GEOMETRY,
111     /**
112      * get native window buffer geometry,
113      * variable parameter in function is
114      * [out] int32_t *height, [out] int32_t *width
115      */
116     GET_BUFFER_GEOMETRY,
117     /**
118      * get native window buffer format,
119      * variable parameter in function is
120      * [out] int32_t *format, the enumeration value refers to {@link OH_NativeBuffer_Format}.
121      */
122     GET_FORMAT,
123     /**
124      * set native window buffer format,
125      * variable parameter in function is
126      * [in] int32_t format, the enumeration value refers to {@link OH_NativeBuffer_Format}.
127      */
128     SET_FORMAT,
129     /**
130      * get native window buffer usage,
131      * variable parameter in function is
132      * [out] uint64_t *usage, the enumeration value refers to {@link OH_NativeBuffer_Usage}.
133      */
134     GET_USAGE,
135     /**
136      * set native window buffer usage,
137      * variable parameter in function is
138      * [in] uint64_t usage, the enumeration value refers to {@link OH_NativeBuffer_Usage}.
139      */
140     SET_USAGE,
141     /**
142      * set native window buffer stride,
143      * variable parameter in function is
144      * [in] int32_t stride.
145      * @deprecated since 16
146      */
147     SET_STRIDE,
148     /**
149      * get native window buffer stride,
150      * variable parameter in function is
151      * [out] int32_t *stride.
152      * @deprecated since 16
153      * @useinstead Use {@link OH_NativeWindow_GetBufferHandleFromNative} to get a {@link BufferHandleand} from a buffer
154      * and then retrieve the stride from the {@link BufferHandle}.
155      */
156     GET_STRIDE,
157     /**
158      * set native window buffer swap interval,
159      * variable parameter in function is
160      * [in] int32_t interval.
161      */
162     SET_SWAP_INTERVAL,
163     /**
164      * get native window buffer swap interval,
165      * variable parameter in function is
166      * [out] int32_t *interval.
167      */
168     GET_SWAP_INTERVAL,
169     /**
170      * set the timeout in milliseconds when the native window requests a buffer,
171      * the default value is 3000 milliseconds when not set,
172      * variable parameter in function is
173      * [in] int32_t timeout, in milliseconds.
174      */
175     SET_TIMEOUT,
176     /**
177      * get the timeout in milliseconds when the native window requests a buffer,
178      * the default value is 3000 milliseconds when not set,
179      * variable parameter in function is
180      * [out] int32_t *timeout, in milliseconds.
181      */
182     GET_TIMEOUT,
183     /**
184      * set native window buffer colorGamut,
185      * variable parameter in function is
186      * [in] int32_t colorGamut, the enumeration value refers to {@link OH_NativeBuffer_ColorGamut}.
187      */
188     SET_COLOR_GAMUT,
189     /**
190      * get native window buffer colorGamut,
191      * variable parameter in function is
192      * [out] int32_t *colorGamut, the enumeration value refers to {@link OH_NativeBuffer_ColorGamut}.
193      */
194     GET_COLOR_GAMUT,
195     /**
196      * set native window buffer transform,
197      * variable parameter in function is
198      * [in] int32_t transform, the enumeration value refers to {@link OH_NativeBuffer_TransformType}.
199      */
200     SET_TRANSFORM,
201     /**
202      * get native window buffer transform,
203      * variable parameter in function is
204      * [out] int32_t *transform, the enumeration value refers to {@link OH_NativeBuffer_TransformType}.
205      */
206     GET_TRANSFORM,
207     /**
208      * set native window buffer uiTimestamp,
209      * variable parameter in function is
210      * [in] uint64_t uiTimestamp.
211      */
212     SET_UI_TIMESTAMP,
213     /**
214      * get native window bufferqueue size,
215      * variable parameter in function is
216      * [out] int32_t *size.
217      * @since 12
218      */
219     GET_BUFFERQUEUE_SIZE,
220     /**
221      * set surface source type,
222      * variable parameter in function is
223      * [in] int32_t sourceType, the enumeration value refers to {@link OHSurfaceSource}.
224      * @since 12
225      */
226     SET_SOURCE_TYPE,
227     /**
228      * get surface source type,
229      * variable parameter in function is
230      * [out] int32_t *sourceType, the enumeration value refers to {@link OHSurfaceSource}.
231      * @since 12
232      */
233     GET_SOURCE_TYPE,
234     /**
235      * set app framework type,
236      * variable parameter in function is
237      * [in] char* frameworkType. maximum length is 64 bytes, otherwise the setting fails.
238      * @since 12
239      */
240     SET_APP_FRAMEWORK_TYPE,
241     /**
242      * get app framework type,
243      * variable parameter in function is
244      * [out] char** frameworkType.
245      * @since 12
246      */
247     GET_APP_FRAMEWORK_TYPE,
248     /**
249      * set hdr white point brightness,
250      * variable parameter in function is
251      * [in] float brightness. the value range is 0.0f to 1.0f.
252      * @since 12
253      */
254     SET_HDR_WHITE_POINT_BRIGHTNESS,
255     /**
256      * set sdr white point brightness,
257      * variable parameter in function is
258      * [in] float brightness. the value range is 0.0f to 1.0f.
259      * @since 12
260      */
261     SET_SDR_WHITE_POINT_BRIGHTNESS,
262     /**
263      * Set native window buffer desiredPresentTimestamp, indicates the desired time to present the buffer.\n
264      * Which should be generated by std::chrono::steady_clock in nanoseconds.\n
265      * It is only effective when RenderService is the consumer.\n
266      * The buffer will wait until desiredPresentTimestamp is reached before being consumed and displayed.\n
267      * If multiple buffers reach desiredPresentTimestamp, the earlier buffer will be dropped.\n
268      * This Operation should be called before calling <b>OH_NativeWindow_NativeWindowFlushBuffer</b>.\n
269      * If desiredPresentTimestamp is greater than 1 second of the consumer-provided timestamp,
270      * the desiredPresentTimestamp will be ignored.\n
271      * Variable parameter in function is
272      * [in] int64_t desiredPresentTimestamp.
273      * @since 13
274      */
275     SET_DESIRED_PRESENT_TIMESTAMP = 24,
276 } NativeWindowOperation;
277 
278 /**
279  * @brief Indicates Scaling Mode.
280  * @since 9
281  * @deprecated(since = "10")
282  * @useinstead OHScalingModeV2
283  */
284 typedef enum {
285     /**
286      * the window content is not updated until a buffer of
287      * the window size is received
288      */
289     OH_SCALING_MODE_FREEZE = 0,
290     /**
291      * the buffer is scaled in two dimensions to match the window size
292      */
293     OH_SCALING_MODE_SCALE_TO_WINDOW,
294     /**
295      * the buffer is uniformly scaled so that the smaller size of
296      * the buffer matches the window size
297      */
298     OH_SCALING_MODE_SCALE_CROP,
299     /**
300      * the window is clipped to the size of the buffer's clipping rectangle
301      * pixels outside the clipping rectangle are considered fully transparent.
302      */
303     OH_SCALING_MODE_NO_SCALE_CROP,
304 } OHScalingMode;
305 
306 /**
307  * @brief Indicates Scaling Mode.
308  * @since 12
309  */
310 typedef enum {
311     /**
312      * the window content is not updated until a buffer of
313      * the window size is received
314      */
315     OH_SCALING_MODE_FREEZE_V2 = 0,
316     /**
317      * the buffer is scaled in two dimensions to match the window size
318      */
319     OH_SCALING_MODE_SCALE_TO_WINDOW_V2,
320     /**
321      * the buffer is uniformly scaled so that the smaller size of
322      * the buffer matches the window size
323      */
324     OH_SCALING_MODE_SCALE_CROP_V2,
325     /**
326      * the window is clipped to the size of the buffer's clipping rectangle
327      * pixels outside the clipping rectangle are considered fully transparent.
328      */
329     OH_SCALING_MODE_NO_SCALE_CROP_V2,
330     /**
331      * Adapt to the buffer and scale proportionally to the buffer size. Prioritize displaying all buffer content.
332      * If the size is not the same as the window size, fill the unfilled area of the window with a background color.
333      */
334     OH_SCALING_MODE_SCALE_FIT_V2,
335 } OHScalingModeV2;
336 
337 /**
338  * @brief Enumerates the HDR metadata keys.
339  * @since 9
340  * @deprecated(since = "10")
341  */
342 typedef enum {
343     OH_METAKEY_RED_PRIMARY_X = 0,
344     OH_METAKEY_RED_PRIMARY_Y = 1,
345     OH_METAKEY_GREEN_PRIMARY_X = 2,
346     OH_METAKEY_GREEN_PRIMARY_Y = 3,
347     OH_METAKEY_BLUE_PRIMARY_X = 4,
348     OH_METAKEY_BLUE_PRIMARY_Y = 5,
349     OH_METAKEY_WHITE_PRIMARY_X = 6,
350     OH_METAKEY_WHITE_PRIMARY_Y = 7,
351     OH_METAKEY_MAX_LUMINANCE = 8,
352     OH_METAKEY_MIN_LUMINANCE = 9,
353     OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL = 10,
354     OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11,
355     OH_METAKEY_HDR10_PLUS = 12,
356     OH_METAKEY_HDR_VIVID = 13,
357 } OHHDRMetadataKey;
358 
359 /**
360  * @brief Defines the HDR metadata.
361  * @since 9
362  * @deprecated(since = "10")
363  */
364 typedef struct {
365     OHHDRMetadataKey key;
366     float value;
367 } OHHDRMetaData;
368 
369 /**
370  * @brief Defines the ExtData Handle
371  * @since 9
372  * @deprecated(since = "10")
373  */
374 typedef struct OHExtDataHandle {
375     /**< Handle fd, -1 if not supported */
376     int32_t fd;
377     /**< the number of reserved integer value */
378     uint32_t reserveInts;
379     /**< the reserved data */
380     int32_t reserve[0];
381 } OHExtDataHandle;
382 
383 /**
384  * @brief Indicates the source type of surface.
385  * @since 12
386  */
387 typedef enum {
388     /*
389      * the default source type of surface.
390      */
391     OH_SURFACE_SOURCE_DEFAULT = 0,
392     /*
393      * the surface is created by ui.
394      */
395     OH_SURFACE_SOURCE_UI,
396     /*
397      * the surface is created by game.
398      */
399     OH_SURFACE_SOURCE_GAME,
400     /*
401      * the surface is created by camera.
402      */
403     OH_SURFACE_SOURCE_CAMERA,
404     /*
405      * the surface is created by video.
406      */
407     OH_SURFACE_SOURCE_VIDEO,
408 } OHSurfaceSource;
409 
410 /**
411  * @brief Creates a <b>OHNativeWindow</b> instance. A new <b>OHNativeWindow</b> instance is created each time this function is called.
412  *
413  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
414  * @param pSurface Indicates the pointer to a <b>ProduceSurface</b>. The type is a pointer to <b>sptr<OHOS::Surface></b>.
415  * @return Returns the pointer to the <b>OHNativeWindow</b> instance created.
416  * @since 8
417  * @version 1.0
418  * @deprecated since 12
419  */
420 OHNativeWindow* OH_NativeWindow_CreateNativeWindow(void* pSurface);
421 
422 /**
423  * @brief Decreases the reference count of a <b>OHNativeWindow</b> instance by 1,
424  * and when the reference count reaches 0, destroys the instance.\n
425  * This interface is a non-thread-safe type interface.\n
426  *
427  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
428  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
429  * @since 8
430  * @version 1.0
431  */
432 void OH_NativeWindow_DestroyNativeWindow(OHNativeWindow* window);
433 
434 /**
435  * @brief Creates a <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called.
436  *
437  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
438  * @param pSurfaceBuffer Indicates the pointer to a produce buffer. The type is <b>sptr<OHOS::SurfaceBuffer></b>.
439  * @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created.
440  * @since 8
441  * @version 1.0
442  * @deprecated since 12
443  * @useinstead OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
444  */
445 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
446 
447 /**
448  * @brief Creates a <b>OHNativeWindowBuffer</b> instance.\n
449  * A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called.\n
450  * This interface needs to be used in conjunction with <b>OH_NativeWindow_DestroyNativeWindowBuffer</b>,
451  * otherwise memory leaks will occur.\n
452  * This interface is a non-thread-safe type interface.\n
453  *
454  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
455  * @param nativeBuffer Indicates the pointer to a native buffer. The type is <b>OH_NativeBuffer*</b>.
456  * @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created.
457  * @since 11
458  * @version 1.0
459  */
460 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer);
461 
462 /**
463  * @brief Decreases the reference count of a <b>OHNativeWindowBuffer</b> instance by 1 and,
464  * when the reference count reaches 0, destroys the instance.\n
465  * This interface is a non-thread-safe type interface.\n
466  *
467  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
468  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
469  * @since 8
470  * @version 1.0
471  */
472 void OH_NativeWindow_DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer);
473 
474 /**
475  * @brief Requests a <b>OHNativeWindowBuffer</b> through a <b>OHNativeWindow</b> instance for content production.\n
476  * Before calling this interface, you need to set the width and height of
477  * <b>OHNativeWindow</b> through <b>SET_BUFFER_GEOMETRY</b>.\n
478  * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeWindowFlushBuffer</b>,
479  * otherwise buffer will be exhausted.\n
480  * When the fenceFd is used up, you need to close it.\n
481  * This interface is a non-thread-safe type interface.\n
482  *
483  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
484  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
485  * @param buffer Indicates the double pointer to a <b>OHNativeWindowBuffer</b> instance.
486  * @param fenceFd Indicates the pointer to a file descriptor handle.
487  * @return Returns an error code, 0 is success, otherwise, failed.
488  * @since 8
489  * @version 1.0
490  */
491 int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window,
492     OHNativeWindowBuffer **buffer, int *fenceFd);
493 
494 /**
495  * @brief Flushes the <b>OHNativeWindowBuffer</b> filled with the content to the buffer queue
496  * through a <b>OHNativeWindow</b> instance for content consumption.\n
497  * The fenceFd will be close by system.\n
498  * This interface is a non-thread-safe type interface.\n
499  *
500  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
501  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
502  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
503  * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization.
504  * @param region Indicates a dirty region where content is updated.
505  * @return Returns an error code, 0 is success, otherwise, failed.
506  * @since 8
507  * @version 1.0
508  */
509 int32_t OH_NativeWindow_NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer,
510     int fenceFd, Region region);
511 
512 /**
513  * @brief Get the last flushed <b>OHNativeWindowBuffer</b> from a <b>OHNativeWindow</b> instance.
514  *
515  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
516  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
517  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> pointer.
518  * @param fenceFd Indicates the pointer to a file descriptor handle.
519  * @param matrix Indicates the retrieved 4*4 transform matrix.
520  * @return Returns an error code, 0 is success, otherwise, failed.
521  * @since 11
522  * @version 1.0
523  * @deprecated since 12
524  * @useinstead OH_NativeWindow_GetLastFlushedBufferV2
525  */
526 int32_t OH_NativeWindow_GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer,
527     int *fenceFd, float matrix[16]);
528 
529  /**
530  * @brief Returns the <b>OHNativeWindowBuffer</b> to the buffer queue through a <b>OHNativeWindow</b> instance,
531  * without filling in any content. The <b>OHNativeWindowBuffer</b> can be used for another request.\n
532  * This interface is a non-thread-safe type interface.\n
533  *
534  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
535  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
536  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
537  * @return Returns an error code, 0 is success, otherwise, failed.
538  * @since 8
539  * @version 1.0
540  */
541 int32_t OH_NativeWindow_NativeWindowAbortBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
542 
543 /**
544  * @brief Sets or obtains the attributes of a native window, including the width, height, and content format.\n
545  * This interface is a non-thread-safe type interface.\n
546  *
547  * <p><strong>API Note</strong>
548  *
549  * <strong>Performance Note</strong>
550  * <p>By default, the window buffer in the current operating system is accessed via the CPU. If an application
551  * does not need to access the window buffer data using the CPU, it can proactively disable CPU access to
552  * enhance energy efficiency and reduce power consumption.
553  * </p>
554  * <p>For details about how to optimize power consumption for data read/write operations in data buffers,
555  * see [How do I proactively disable CPU access to window buffers to reduce power consumption?]{@link https://developer.huawei.com/consumer/en/doc/harmonyos-faqs/faqs-arkgraphics-2d-14}.</p>
556  * </p>
557  *
558  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
559  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
560  * @param code Indicates the operation code, pointer to <b>NativeWindowOperation</b>.
561  * @param ... variable parameter, must correspond to code one-to-one.
562  * @return Returns an error code, 0 is success, otherwise, failed.
563  * @since 8
564  * @version 1.0
565  */
566 int32_t OH_NativeWindow_NativeWindowHandleOpt(OHNativeWindow *window, int code, ...);
567 
568 /**
569  * @brief Obtains the pointer to a <b>BufferHandle</b> of a <b>OHNativeWindowBuffer</b> instance.\n
570  * This interface is a non-thread-safe type interface.\n
571  *
572  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
573  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
574  * @return Returns the pointer to the <b>BufferHandle</b> instance obtained.
575  * @since 8
576  * @version 1.0
577  */
578 BufferHandle *OH_NativeWindow_GetBufferHandleFromNative(OHNativeWindowBuffer *buffer);
579 
580 /**
581  * @brief Adds the reference count of a native object.\n
582  * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeObjectUnreference</b>,
583  * otherwise memory leaks will occur.\n
584  * This interface is a non-thread-safe type interface.\n
585  *
586  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
587  * @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
588  * @return Returns an error code, 0 is success, otherwise, failed.
589  * @since 8
590  * @version 1.0
591  */
592 int32_t OH_NativeWindow_NativeObjectReference(void *obj);
593 
594 /**
595  * @brief Decreases the reference count of a native object and,
596  * when the reference count reaches 0, destroys this object.\n
597  * This interface is a non-thread-safe type interface.\n
598  *
599  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
600  * @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
601  * @return Returns an error code, 0 is success, otherwise, failed.
602  * @since 8
603  * @version 1.0
604  */
605 int32_t OH_NativeWindow_NativeObjectUnreference(void *obj);
606 
607 /**
608  * @brief Obtains the magic ID of a native object.\n
609  * This interface is a non-thread-safe type interface.\n
610  *
611  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
612  * @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
613  * @return Returns the magic ID, which is unique for each native object.
614  * @since 8
615  * @version 1.0
616  */
617 int32_t OH_NativeWindow_GetNativeObjectMagic(void *obj);
618 
619 /**
620  * @brief Sets scalingMode of a native window.
621  *
622  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
623  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
624  * @param sequence Indicates the sequence to a produce buffer.
625  * @param scalingMode Indicates the enum value to <b>OHScalingMode</b>
626  * @return Returns an error code, 0 is success, otherwise, failed.
627  * @since 9
628  * @version 1.0
629  * @deprecated(since = "10")
630  * @useinstead OH_NativeWindow_NativeWindowSetScalingModeV2
631  */
632 int32_t OH_NativeWindow_NativeWindowSetScalingMode(OHNativeWindow *window, uint32_t sequence,
633                                                    OHScalingMode scalingMode);
634 
635 /**
636  * @brief Sets metaData of a native window.
637  *
638  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
639  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
640  * @param sequence Indicates the sequence to a produce buffer.
641  * @param size Indicates the size of a <b>OHHDRMetaData</b> vector.
642  * @param metaDate Indicates the pointer to a <b>OHHDRMetaData</b> vector.
643  * @return Returns an error code, 0 is success, otherwise, failed.
644  * @since 9
645  * @version 1.0
646  * @deprecated(since = "10")
647  */
648 int32_t OH_NativeWindow_NativeWindowSetMetaData(OHNativeWindow *window, uint32_t sequence, int32_t size,
649                                                 const OHHDRMetaData *metaData);
650 
651 /**
652  * @brief Sets metaDataSet of a native window.
653  *
654  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
655  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
656  * @param sequence Indicates the sequence to a produce buffer.
657  * @param key Indicates the enum value to <b>OHHDRMetadataKey</b>
658  * @param size Indicates the size of a uint8_t vector.
659  * @param metaDate Indicates the pointer to a uint8_t vector.
660  * @return Returns an error code, 0 is success, otherwise, failed.
661  * @since 9
662  * @version 1.0
663  * @deprecated(since = "10")
664  */
665 int32_t OH_NativeWindow_NativeWindowSetMetaDataSet(OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key,
666                                                    int32_t size, const uint8_t *metaData);
667 
668 /**
669  * @brief Sets tunnel handle of a native window.
670  *
671  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
672  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
673  * @param handle Indicates the pointer to a <b>OHExtDataHandle</b>.
674  * @return Returns an error code, 0 is success, otherwise, failed.
675  * @since 9
676  * @version 1.0
677  * @deprecated(since = "10")
678  */
679 int32_t OH_NativeWindow_NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandle *handle);
680 
681 /**
682  * @brief Attach a buffer to an <b>OHNativeWindow</b> instance.\n
683  * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeWindowDetachBuffer</b>,
684  * otherwise buffer management will be chaotic.\n
685  * This interface is a non-thread-safe type interface.\n
686  *
687  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
688  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
689  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
690  * @return Returns an error code, 0 is success, otherwise, failed.
691  * @since 12
692  * @version 1.0
693  */
694 int32_t OH_NativeWindow_NativeWindowAttachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
695 
696 /**
697  * @brief Detach a buffer from an <b>OHNativeWindow</b> instance.\n
698  * This interface is a non-thread-safe type interface.\n
699  *
700  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
701  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
702  * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
703  * @return Returns an error code, 0 is success, otherwise, failed.
704  * @since 12
705  * @version 1.0
706  */
707 int32_t OH_NativeWindow_NativeWindowDetachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
708 
709 /**
710  * @brief Get surfaceId from native window.\n
711  * This interface is a non-thread-safe type interface.\n
712  *
713  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
714  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
715  * @param surfaceId Indicates the pointer to a surfaceId.
716  * @return Returns an error code, 0 is success, otherwise, failed.
717  * @since 12
718  * @version 1.0
719  */
720 int32_t OH_NativeWindow_GetSurfaceId(OHNativeWindow *window, uint64_t *surfaceId);
721 
722 /**
723  * @brief Creates an <b>OHNativeWindow</b> instance.\n
724  * This interface needs to be used in conjunction with <b>OH_NativeWindow_DestroyNativeWindow</b>,
725  * otherwise memory leaks will occur.\n
726  * If there is a concurrent destroy OHNativeWindow, you need to add once and decrement once to the
727  * OHNativeWindow reference count through <b>OH_NativeWindow_NativeObjectReference</b> and
728  * <b>OH_NativeWindow_NativeObjectUnreference</b>.\n
729  * If the surface obtained through surfaceId is created in this process, the surface cannot be obtained
730  * across processes.\n
731  * This interface is a non-thread-safe type interface.\n
732  *
733  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
734  * @param surfaceId Indicates the surfaceId to a surface.
735  * @param window indicates the pointer to an <b>OHNativeWindow</b> instance.
736  * @return Returns an error code, 0 is Success, otherwise, failed.
737  * @since 12
738  * @version 1.0
739  */
740 int32_t OH_NativeWindow_CreateNativeWindowFromSurfaceId(uint64_t surfaceId, OHNativeWindow **window);
741 
742 /**
743  * @brief Sets scalingMode of a native window.\n
744  * This interface is a non-thread-safe type interface.\n
745  *
746  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
747  * @param window indicates the pointer to an <b>OHNativeWindow</b> instance.
748  * @param scalingMode Indicates the enum value to <b>OHScalingModeV2</b>
749  * @return Returns an error code, 0 is Success, otherwise, failed.
750  * @since 12
751  * @version 1.0
752  */
753 int32_t OH_NativeWindow_NativeWindowSetScalingModeV2(OHNativeWindow *window, OHScalingModeV2 scalingMode);
754 
755 /**
756  * @brief Set native window buffer hold.\n
757  * This interface is a non-thread-safe type interface.\n
758  *
759  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
760  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
761  * @since 12
762  * @version 1.0
763  */
764 void OH_NativeWindow_SetBufferHold(OHNativeWindow *window);
765 
766 /**
767  * @brief Write an OHNativeWindow to an OHIPCParcel.\n
768  * This interface is a non-thread-safe type interface.\n
769  *
770  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
771  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
772  * @param parcel Indicates the pointer to an <b>OHIPCParcel</b> instance.
773  * @return {@link NATIVE_ERROR_OK} 0 - Success.
774  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - parcel is NULL or window is NULL.
775  * @since 12
776  * @version 1.0
777  */
778 int32_t OH_NativeWindow_WriteToParcel(OHNativeWindow *window, OHIPCParcel *parcel);
779 
780 /**
781  * @brief Read an OHNativeWindow from an OHIPCParcel.\n
782  * This interface is a non-thread-safe type interface.\n
783  *
784  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
785  * @param parcel Indicates the pointer to an <b>OHIPCParcel</b> instance.
786  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
787  * @return {@link NATIVE_ERROR_OK} 0 - Success.
788  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - parcel is NULL or parcel does not contain the window.
789  * @since 12
790  * @version 1.0
791  */
792 int32_t OH_NativeWindow_ReadFromParcel(OHIPCParcel *parcel, OHNativeWindow **window);
793 
794 /**
795  * @brief Get the last flushed <b>OHNativeWindowBuffer</b> from an <b>OHNativeWindow</b> instance.\n
796  * When the fenceFd is used up, you need to close it.\n
797  * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeObjectUnreference</b>,
798  * otherwise memory leaks will occur.\n
799  * This interface is a non-thread-safe type interface.\n
800  *
801  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
802  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
803  * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> pointer.
804  * @param fenceFd Indicates the pointer to a file descriptor handle.
805  * @param matrix Indicates the retrieved 4*4 transform matrix.
806  * @return {@link NATIVE_ERROR_OK} 0 - Success.
807  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL or buffer is NULL or fenceFd is NULL.
808  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - buffer state is wrong.
809  * @since 12
810  * @version 1.0
811  */
812 
813 int32_t OH_NativeWindow_GetLastFlushedBufferV2(OHNativeWindow *window, OHNativeWindowBuffer **buffer,
814     int *fenceFd, float matrix[16]);
815 /**
816  * @brief Set the color space of the native window.\n
817  * This interface is a non-thread-safe type interface.\n
818  *
819  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
820  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
821  * @param colorSpace Indicates the color space of native window, see <b>OH_NativeBuffer_ColorSpace</b>.
822  * @return {@link NATIVE_ERROR_OK} 0 - Success.
823  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL.
824  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect colorSpace state.
825  * @since 12
826  * @version 1.0
827  */
828 int32_t OH_NativeWindow_SetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace colorSpace);
829 
830 /**
831  * @brief Get the color space of the native window.\n
832  * This interface is a non-thread-safe type interface.\n
833  *
834  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
835  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
836  * @param colorSpace Indicates the color space of native window, see <b>OH_NativeBuffer_ColorSpace</b>.
837  * @return {@link NATIVE_ERROR_OK} 0 - Success.
838  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL.
839  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect colorSpace state.
840  * @since 12
841  * @version 1.0
842  */
843 int32_t OH_NativeWindow_GetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace);
844 
845 /**
846  * @brief Set the metadata type of the native window.\n
847  * This interface is a non-thread-safe type interface.\n
848  *
849  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
850  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
851  * @param metadataKey Indicates the metadata type of native window, see <b>OH_NativeBuffer_MetadataKey</b>.
852  * @param size Indicates the size of a uint8_t vector.
853  * @param metadata Indicates the pointer to a uint8_t vector.
854  * @return {@link NATIVE_ERROR_OK} 0 - Success.
855  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window or metadata is NULL.
856  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state.
857  *     {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key.
858  * @since 12
859  * @version 1.0
860  */
861 int32_t OH_NativeWindow_SetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey,
862     int32_t size, uint8_t *metadata);
863 
864 /**
865  * @brief Set the metadata type of the native window.\n
866  * This interface is a non-thread-safe type interface.\n
867  *
868  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
869  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
870  * @param metadataKey Indicates the metadata type of native window, see <b>OH_NativeBuffer_MetadataKey</b>.
871  * @param size Indicates the size of a uint8_t vector.
872  * @param metadata Indicates the pointer to a uint8_t vector.
873  * @return {@link NATIVE_ERROR_OK} 0 - Success.
874  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window, metadata, or size is NULL.
875  *     {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state.
876  *     {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key.
877  * @since 12
878  * @version 1.0
879  */
880 int32_t OH_NativeWindow_GetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey,
881     int32_t *size, uint8_t **metadata);
882 
883 /**
884  * @brief Clean all <b>OHNativeWindowBuffer</b> caches of this <b>OHNativeWindow</b>
885  * This interface is a non-thread-safe type interface.\n
886  *
887  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
888  * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance.
889  * @return {@link NATIVE_ERROR_OK} 0 - Success.
890  *     {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL.
891  *     {@link NATIVE_ERROR_CONSUMER_DISCONNECTED} 41211000 - the consumer is disconnected.
892  *     {@link NATIVE_ERROR_BINDER_ERROR} 50401000 - ipc send failed.
893  * @since 19
894  * @version 1.0
895  */
896 int32_t OH_NativeWindow_CleanCache(OHNativeWindow *window);
897 #ifdef __cplusplus
898 }
899 #endif
900 
901 /** @} */
902 #endif