• 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 #ifndef NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_
17 #define NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_
18 
19 /**
20  * @addtogroup NativeWindow
21  * @{
22  *
23  * @brief Provides the native window capability for connection to the EGL.
24  *
25  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
26  * @since 8
27  * @version 1.0
28  */
29 
30 /**
31  * @file external_window.h
32  *
33  * @brief Defines the functions for obtaining and using a native window.
34  *
35  * @library libnative_window.so
36  * @since 8
37  * @version 1.0
38  */
39 
40 #include <stdint.h>
41 #include "buffer_handle.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 typedef struct OH_NativeBuffer OH_NativeBuffer;
47 /**
48  * @brief native window.
49  * @since 8
50  */
51 struct NativeWindow;
52 
53 /**
54  * @brief native window buffer.
55  * @since 8
56  */
57 struct NativeWindowBuffer;
58 
59 /**
60  * @brief define the new type name OHNativeWindow for struct NativeWindow.
61  * @since 8
62  */
63 typedef struct NativeWindow OHNativeWindow;
64 
65 /**
66  * @brief define the new type name OHNativeWindowBuffer for struct NativeWindowBuffer.
67  * @since 8
68  */
69 typedef struct NativeWindowBuffer OHNativeWindowBuffer;
70 
71 /**
72  * @brief indicates a dirty region where content is updated.
73  * @since 8
74  */
75 typedef struct Region {
76     /** if rects is nullptr, fill the Buffer dirty size by default */
77     struct Rect {
78         int32_t x;
79         int32_t y;
80         uint32_t w;
81         uint32_t h;
82     } *rects;
83     /** if rectNumber is 0, fill the Buffer dirty size by default */
84     int32_t rectNumber;
85 }Region;
86 
87 
88 /**
89  * @brief Indicates the operation code in the function OH_NativeWindow_NativeWindowHandleOpt.
90  * @since 8
91  */
92 enum NativeWindowOperation {
93     /**
94      * set native window buffer geometry,
95      * variable parameter in function is
96      * [in] int32_t width, [in] int32_t height
97      */
98     SET_BUFFER_GEOMETRY,
99     /**
100      * get native window buffer geometry,
101      * variable parameter in function is
102      * [out] int32_t *height, [out] int32_t *width
103      */
104     GET_BUFFER_GEOMETRY,
105     /**
106      * get native window buffer format,
107      * variable parameter in function is
108      * [out] int32_t *format
109      */
110     GET_FORMAT,
111     /**
112      * set native window buffer format,
113      * variable parameter in function is
114      * [in] int32_t format
115      */
116     SET_FORMAT,
117     /**
118      * get native window buffer usage,
119      * variable parameter in function is
120      * [out] int32_t *usage.
121      */
122     GET_USAGE,
123     /**
124      * set native window buffer usage,
125      * variable parameter in function is
126      * [in] int32_t usage.
127      */
128     SET_USAGE,
129     /**
130      * set native window buffer stride,
131      * variable parameter in function is
132      * [in] int32_t stride.
133      */
134     SET_STRIDE,
135     /**
136      * get native window buffer stride,
137      * variable parameter in function is
138      * [out] int32_t *stride.
139      */
140     GET_STRIDE,
141     /**
142      * set native window buffer swap interval,
143      * variable parameter in function is
144      * [in] int32_t interval.
145      */
146     SET_SWAP_INTERVAL,
147     /**
148      * get native window buffer swap interval,
149      * variable parameter in function is
150      * [out] int32_t *interval.
151      */
152     GET_SWAP_INTERVAL,
153     /**
154      * set native window buffer timeout,
155      * variable parameter in function is
156      * [in] int32_t timeout.
157      */
158     SET_TIMEOUT,
159     /**
160      * get native window buffer timeout,
161      * variable parameter in function is
162      * [out] int32_t *timeout.
163      */
164     GET_TIMEOUT,
165     /**
166      * set native window buffer colorGamut,
167      * variable parameter in function is
168      * [in] int32_t colorGamut.
169      */
170     SET_COLOR_GAMUT,
171     /**
172      * get native window buffer colorGamut,
173      * variable parameter in function is
174      * [out int32_t *colorGamut].
175      */
176     GET_COLOR_GAMUT,
177     /**
178      * set native window buffer transform,
179      * variable parameter in function is
180      * [in] int32_t transform.
181      */
182     SET_TRANSFORM,
183     /**
184      * get native window buffer transform,
185      * variable parameter in function is
186      * [out] int32_t *transform.
187      */
188     GET_TRANSFORM,
189     /**
190      * set native window buffer uiTimestamp,
191      * variable parameter in function is
192      * [in] uint64_t uiTimestamp.
193      */
194     SET_UI_TIMESTAMP,
195 };
196 
197 /**
198  * @brief Indicates Scaling Mode.
199  * @since 9
200  * @deprecated(since = "10")
201  */
202 typedef enum {
203     /**
204      * the window content is not updated until a buffer of
205      * the window size is received
206      */
207     OH_SCALING_MODE_FREEZE = 0,
208     /**
209      * the buffer is scaled in two dimensions to match the window size
210      */
211     OH_SCALING_MODE_SCALE_TO_WINDOW,
212     /**
213      * the buffer is uniformly scaled so that the smaller size of
214      * the buffer matches the window size
215      */
216     OH_SCALING_MODE_SCALE_CROP,
217     /**
218      * the window is clipped to the size of the buffer's clipping rectangle
219      * pixels outside the clipping rectangle are considered fully transparent.
220      */
221     OH_SCALING_MODE_NO_SCALE_CROP,
222 } OHScalingMode;
223 
224 /**
225  * @brief Enumerates the HDR metadata keys.
226  * @since 9
227  * @deprecated(since = "10")
228  */
229 typedef enum {
230     OH_METAKEY_RED_PRIMARY_X = 0,
231     OH_METAKEY_RED_PRIMARY_Y = 1,
232     OH_METAKEY_GREEN_PRIMARY_X = 2,
233     OH_METAKEY_GREEN_PRIMARY_Y = 3,
234     OH_METAKEY_BLUE_PRIMARY_X = 4,
235     OH_METAKEY_BLUE_PRIMARY_Y = 5,
236     OH_METAKEY_WHITE_PRIMARY_X = 6,
237     OH_METAKEY_WHITE_PRIMARY_Y = 7,
238     OH_METAKEY_MAX_LUMINANCE = 8,
239     OH_METAKEY_MIN_LUMINANCE = 9,
240     OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL = 10,
241     OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11,
242     OH_METAKEY_HDR10_PLUS = 12,
243     OH_METAKEY_HDR_VIVID = 13,
244 } OHHDRMetadataKey;
245 
246 /**
247  * @brief Defines the HDR metadata.
248  * @since 9
249  * @deprecated(since = "10")
250  */
251 typedef struct {
252     OHHDRMetadataKey key;
253     float value;
254 } OHHDRMetaData;
255 
256 /**
257  * @brief Defines the ExtData Handle
258  * @since 9
259  * @deprecated(since = "10")
260  */
261 typedef struct OHExtDataHandle {
262     /**< Handle fd, -1 if not supported */
263     int32_t fd;
264     /**< the number of reserved integer value */
265     uint32_t reserveInts;
266     /**< the reserved data */
267     int32_t reserve[0];
268 } OHExtDataHandle;
269 
270 /**
271  * @brief Creates an <b>OHNativeWindow</b> instance. A new <b>OHNativeWindow</b> instance is \n
272  * created each time this function is called.
273  *
274  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
275  * @param pSurface Indicates the pointer to a <b>ProduceSurface</b>. The type is a pointer \n
276  * to <b>sptr<OHOS::Surface></b>.
277  * @return Returns the pointer to the <b>OHNativeWindow</b> instance created.
278  * @since 8
279  * @version 1.0
280  */
281 OHNativeWindow* OH_NativeWindow_CreateNativeWindow(void* pSurface);
282 
283 /**
284  * @brief Decreases the reference count of an <b>OHNativeWindow</b> instance by 1, and when the reference count \n
285  * reaches 0, destroys the instance.
286  *
287  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
288  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
289  * @since 8
290  * @version 1.0
291  */
292 void OH_NativeWindow_DestroyNativeWindow(OHNativeWindow* window);
293 
294 /**
295  * @brief Creates an <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created \n
296  * each time this function is called.
297  *
298  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
299  * @param pSurfaceBuffer Indicates the pointer to a produce buffer. The type is <b>sptr<OHOS::SurfaceBuffer></b>.
300  * @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created.
301  * @since 8
302  * @version 1.0
303  */
304 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
305 
306 /**
307  * @brief Creates an <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created \n
308  * each time this function is called.
309  *
310  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
311  * @param nativeBuffer Indicates the pointer to a native buffer. The type is <b>OH_NativeBuffer*</b>.
312  * @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created.
313  * @since 11
314  * @version 1.0
315  */
316 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer);
317 
318 /**
319  * @brief Decreases the reference count of an <b>OHNativeWindowBuffer</b> instance by 1 and, when the reference \n
320  * count reaches 0, destroys the instance.
321  *
322  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
323  * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
324  * @since 8
325  * @version 1.0
326  */
327 void OH_NativeWindow_DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer);
328 
329 /**
330  * @brief Requests an <b>OHNativeWindowBuffer</b> through an <b>OHNativeWindow</b> instance for content production.
331  *
332  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
333  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
334  * @param buffer Indicates the double pointer to an <b>OHNativeWindowBuffer</b> instance.
335  * @param fenceFd Indicates the pointer to a file descriptor handle.
336  * @return Returns an error code, 0 is success, otherwise, failed.
337  * @since 8
338  * @version 1.0
339  */
340 int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window,
341     OHNativeWindowBuffer **buffer, int *fenceFd);
342 
343 /**
344  * @brief Flushes the <b>OHNativeWindowBuffer</b> filled with the content to the buffer queue through an \n
345  * <b>OHNativeWindow</b> instance for content consumption.
346  *
347  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
348  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
349  * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
350  * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization.
351  * @param region Indicates a dirty region where content is updated.
352  * @return Returns an error code, 0 is success, otherwise, failed.
353  * @since 8
354  * @version 1.0
355  */
356 int32_t OH_NativeWindow_NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer,
357     int fenceFd, Region region);
358 
359 /**
360  * @brief Get the last flushed <b>OHNativeWindowBuffer</b> from an <b>OHNativeWindow</b> instance.
361  *
362  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
363  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
364  * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> pointer.
365  * @param fenceFd Indicates the pointer to a file descriptor handle.
366  * @param matrix Indicates the retrieved 4*4 transform matrix.
367  * @return Returns an error code, 0 is success, otherwise, failed.
368  * @since 11
369  * @version 1.0
370  */
371 int32_t OH_NativeWindow_GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer,
372     int *fenceFd, float matrix[16]);
373 
374  /**
375  * @brief Returns the <b>OHNativeWindowBuffer</b> to the buffer queue through an <b>OHNativeWindow</b> instance, \n
376  * without filling in any content. The <b>OHNativeWindowBuffer</b> can be used for another request.
377  *
378  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
379  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
380  * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
381  * @return Returns an error code, 0 is success, otherwise, failed.
382  * @since 8
383  * @version 1.0
384  */
385 int32_t OH_NativeWindow_NativeWindowAbortBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
386 
387 /**
388  * @brief Sets or obtains the attributes of a native window, including the width, height, and content format.
389  *
390  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
391  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
392  * @param code Indicates the operation code, pointer to <b>NativeWindowOperation</b>.
393  * @param ... variable parameter, must correspond to code one-to-one.
394  * @return Returns an error code, 0 is success, otherwise, failed.
395  * @since 8
396  * @version 1.0
397  */
398 int32_t OH_NativeWindow_NativeWindowHandleOpt(OHNativeWindow *window, int code, ...);
399 
400 /**
401  * @brief Obtains the pointer to a <b>BufferHandle</b> of an <b>OHNativeWindowBuffer</b> instance.
402  *
403  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
404  * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
405  * @return Returns the pointer to the <b>BufferHandle</b> instance obtained.
406  * @since 8
407  * @version 1.0
408  */
409 BufferHandle *OH_NativeWindow_GetBufferHandleFromNative(OHNativeWindowBuffer *buffer);
410 
411 /**
412  * @brief Adds the reference count of a native object.
413  *
414  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
415  * @param obj Indicates the pointer to an <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
416  * @return Returns an error code, 0 is success, otherwise, failed.
417  * @since 8
418  * @version 1.0
419  */
420 int32_t OH_NativeWindow_NativeObjectReference(void *obj);
421 
422 /**
423  * @brief Decreases the reference count of a native object and, when the reference count reaches 0, \n
424  * destroys this object.
425  *
426  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
427  * @param obj Indicates the pointer to an <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
428  * @return Returns an error code, 0 is success, otherwise, failed.
429  * @since 8
430  * @version 1.0
431  */
432 int32_t OH_NativeWindow_NativeObjectUnreference(void *obj);
433 
434 /**
435  * @brief Obtains the magic ID of a native object.
436  *
437  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
438  * @param obj Indicates the pointer to an <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance.
439  * @return Returns the magic ID, which is unique for each native object.
440  * @since 8
441  * @version 1.0
442  */
443 int32_t OH_NativeWindow_GetNativeObjectMagic(void *obj);
444 
445 /**
446  * @brief Sets scalingMode of a native window.
447  *
448  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
449  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
450  * @param sequence Indicates the sequence to a produce buffer.
451  * @param scalingMode Indicates the enum value to <b>OHScalingMode</b>
452  * @return Returns an error code, 0 is success, otherwise, failed.
453  * @since 9
454  * @version 1.0
455  * @deprecated(since = "10")
456  */
457 int32_t OH_NativeWindow_NativeWindowSetScalingMode(OHNativeWindow *window, uint32_t sequence,
458                                                    OHScalingMode scalingMode);
459 
460 /**
461  * @brief Sets metaData of a native window.
462  *
463  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
464  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
465  * @param sequence Indicates the sequence to a produce buffer.
466  * @param size Indicates the size of a <b>OHHDRMetaData</b> vector.
467  * @param metaDate Indicates the pointer to a <b>OHHDRMetaData</b> vector.
468  * @return Returns an error code, 0 is success, otherwise, failed.
469  * @since 9
470  * @version 1.0
471  * @deprecated(since = "10")
472  */
473 int32_t OH_NativeWindow_NativeWindowSetMetaData(OHNativeWindow *window, uint32_t sequence, int32_t size,
474                                                 const OHHDRMetaData *metaData);
475 
476 /**
477  * @brief Sets metaDataSet of a native window.
478  *
479  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
480  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
481  * @param sequence Indicates the sequence to a produce buffer.
482  * @param key Indicates the enum value to <b>OHHDRMetadataKey</b>
483  * @param size Indicates the size of a uint8_t vector.
484  * @param metaDate Indicates the pointer to a uint8_t vector.
485  * @return Returns an error code, 0 is success, otherwise, failed.
486  * @since 9
487  * @version 1.0
488  * @deprecated(since = "10")
489  */
490 int32_t OH_NativeWindow_NativeWindowSetMetaDataSet(OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key,
491                                                    int32_t size, const uint8_t *metaData);
492 
493 /**
494  * @brief Sets tunnel handle of a native window.
495  *
496  * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow
497  * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance.
498  * @param handle Indicates the pointer to a <b>OHExtDataHandle</b>.
499  * @return Returns an error code, 0 is success, otherwise, failed.
500  * @since 9
501  * @version 1.0
502  * @deprecated(since = "10")
503  */
504 int32_t OH_NativeWindow_NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandle *handle);
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 /** @} */
511 #endif