• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_NATIVE_WINDOW_H_
17 #define NDK_INCLUDE_NATIVE_WINDOW_H_
18 
19 #include <stdint.h>
20 #include <buffer_handle.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct NativeWindow;
27 struct NativeWindowBuffer;
28 
29 #define MKMAGIC(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + ((d) << 0))
30 
31 enum NativeObjectMagic {
32     NATIVE_OBJECT_MAGIC_WINDOW = MKMAGIC('W', 'I', 'N', 'D'),
33     NATIVE_OBJECT_MAGIC_WINDOW_BUFFER = MKMAGIC('W', 'B', 'U', 'F'),
34 };
35 
36 enum NativeObjectType {
37     NATIVE_OBJECT_WINDOW,
38     NATIVE_OBJECT_WINDOW_BUFFER,
39 };
40 
41 struct Region {
42     struct Rect {
43         int32_t x;
44         int32_t y;
45         uint32_t w;
46         uint32_t h;
47     } *rects;           // if nullptr,  fill the Buffer dirty size by defualt
48     int32_t rectNumber; // if rectNumber is 0, fill the Buffer dirty size by defualt
49 };
50 
51 enum NativeWindowOperation {
52     SET_BUFFER_GEOMETRY,    // ([in] int32_t height, [in] int32_t width)
53     GET_BUFFER_GEOMETRY,    // ([out] int32_t *height, [out] int32_t *width)
54     GET_FORMAT,             // ([out] int32_t *format)
55     SET_FORMAT,             // ([in] int32_t format)
56     GET_USAGE,              // ([out] int32_t *usage)
57     SET_USAGE,              // ([in] int32_t usage)
58     SET_STRIDE,             // ([in] int32_t stride)
59     GET_STRIDE,             // ([out] int32_t *stride)
60     SET_SWAP_INTERVAL,      // ([in] int32_t interval)
61     GET_SWAP_INTERVAL,
62     SET_COLOR_GAMUT,        // ([in] int32_t colorGamut)
63     GET_COLOR_GAMUT,        // ([out int32_t *colorGamut])
64 };
65 
66 // pSurface type is OHOS::sptr<OHOS::Surface>*
67 struct NativeWindow* CreateNativeWindowFromSurface(void* pSurface);
68 void DestoryNativeWindow(struct NativeWindow* window);
69 
70 // pSurfaceBuffer type is OHOS::sptr<OHOS::SurfaceBuffer>*
71 struct NativeWindowBuffer* CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
72 void DestoryNativeWindowBuffer(struct NativeWindowBuffer* buffer);
73 
74 int32_t NativeWindowRequestBuffer(struct NativeWindow *window, /* [out] */ struct NativeWindowBuffer **buffer,
75     /* [out] get release fence */ int *fenceFd);
76 int32_t NativeWindowFlushBuffer(struct NativeWindow *window, struct NativeWindowBuffer *buffer,
77     int fenceFd, Region region);
78 int32_t NativeWindowCancelBuffer(struct NativeWindow *window, struct NativeWindowBuffer *buffer);
79 
80 // The meaning and quantity of parameters vary according to the code type.
81 // For details, see the NativeWindowOperation comment.
82 int32_t NativeWindowHandleOpt(struct NativeWindow *window, int code, ...);
83 BufferHandle *GetBufferHandleFromNative(struct NativeWindowBuffer *buffer);
84 
85 // NativeObject: NativeWindow, NativeWindowBuffer
86 int32_t NativeObjectReference(void *obj);
87 int32_t NativeObjectUnreference(void *obj);
88 int32_t GetNativeObjectMagic(void *obj);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif