• 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_NATIVE_WINDOW_H_
17 #define NDK_INCLUDE_NATIVE_WINDOW_H_
18 
19 #include "external_window.h"
20 #include "native_buffer.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define MKMAGIC(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + ((d) << 0))
27 
28 enum NativeObjectMagic {
29     NATIVE_OBJECT_MAGIC_WINDOW = MKMAGIC('W', 'I', 'N', 'D'),
30     NATIVE_OBJECT_MAGIC_WINDOW_BUFFER = MKMAGIC('W', 'B', 'U', 'F'),
31     NATIVE_OBJECT_MAGIC_WINDOW_INVALID = MKMAGIC('I', 'V', 'L', 'D'),
32 };
33 
34 // pSurface type is OHOS::sptr<OHOS::Surface>*
35 OHNativeWindow* CreateNativeWindowFromSurface(void* pSurface);
36 void DestoryNativeWindow(OHNativeWindow* window);
37 
38 // pSurfaceBuffer type is OHOS::sptr<OHOS::SurfaceBuffer>*
39 OHNativeWindowBuffer* CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
40 OHNativeWindowBuffer* CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer);
41 void DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer);
42 
43 int32_t NativeWindowRequestBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd);
44 int32_t NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer,
45     int fenceFd, Region region);
46 int32_t GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer,
47     int *fenceFd, float matrix[16]);
48 int32_t NativeWindowCancelBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
49 
50 // The meaning and quantity of parameters vary according to the code type.
51 // For details, see the NativeWindowOperation comment.
52 int32_t NativeWindowHandleOpt(OHNativeWindow *window, int code, ...);
53 BufferHandle *GetBufferHandleFromNative(OHNativeWindowBuffer *buffer);
54 
55 // NativeObject: NativeWindow, NativeWindowBuffer
56 int32_t NativeObjectReference(void *obj);
57 int32_t NativeObjectUnreference(void *obj);
58 int32_t GetNativeObjectMagic(void *obj);
59 
60 int32_t NativeWindowSetScalingMode(OHNativeWindow *window, uint32_t sequence, OHScalingMode scalingMode);
61 int32_t NativeWindowSetMetaData(OHNativeWindow *window, uint32_t sequence, int32_t size,
62                                 const OHHDRMetaData *metaData);
63 int32_t NativeWindowSetMetaDataSet(OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key,
64                                    int32_t size, const uint8_t *metaData);
65 int32_t NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandle *handle);
66 int32_t GetSurfaceId(OHNativeWindow *window, uint64_t *surfaceId);
67 int32_t CreateNativeWindowFromSurfaceId(uint64_t surfaceId, OHNativeWindow **window);
68 int32_t NativeWindowAttachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
69 int32_t NativeWindowDetachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
70 int32_t NativeWindowGetTransformHint(OHNativeWindow *window, OH_NativeBuffer_TransformType *transform);
71 int32_t NativeWindowSetTransformHint(OHNativeWindow *window, OH_NativeBuffer_TransformType transform);
72 int32_t NativeWindowGetDefaultWidthAndHeight(OHNativeWindow *window, int32_t *width, int32_t *height);
73 int32_t NativeWindowSetRequestWidthAndHeight(OHNativeWindow *window, int32_t width, int32_t height);
74 void NativeWindowSetBufferHold(OHNativeWindow *window);
75 int32_t NativeWindowWriteToParcel(OHNativeWindow *window, OHIPCParcel *parcel);
76 int32_t NativeWindowReadFromParcel(OHIPCParcel *parcel, OHNativeWindow **window);
77 int32_t GetLastFlushedBufferV2(OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16]);
78 int32_t NativeWindowSetScalingModeV2(OHNativeWindow *window, OHScalingModeV2 scalingMode);
79 int32_t NativeWindowDisconnect(OHNativeWindow *window);
80 int32_t OH_NativeWindow_SetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace colorSpace);
81 int32_t OH_NativeWindow_GetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace);
82 int32_t OH_NativeWindow_SetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey,
83     int32_t size, uint8_t *metadata);
84 int32_t OH_NativeWindow_GetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey,
85     int32_t *size, uint8_t **metadata);
86 int32_t NativeWindowCleanCache(OHNativeWindow *window);
87 /**
88  * @brief Request native window buffer with lock.
89  * 1. The lock and unlock interfaces need to be used in pairs;
90  * 2. The internal usage of the interface is set to CPU read/write
91  * 3. The lock interface has requestBuffer logic inside, so there is no need to call the requestBuffer interface again;
92  * 4. If fenceFd is not equal to -1 inside the lock interface after requestBuffer, it will wait;
93  * 5. Repeated locking or unlocking will result in an illegal operation error code;
94  * @param window Indicates the window.
95  * @param region Indicates the info of the dirty region.
96  * @param buffer Indicates the pointer to a <b>NativeWindowBuffer</b> instance.
97  * @return Returns the error code of the request of lock.
98  */
99 int32_t NativeWindowLockBuffer(OHNativeWindow *window, Region region, OHNativeWindowBuffer **buffer);
100 /**
101  * @brief Unlock native window buffer with lock.
102  * The lock and unlock interfaces need to be used in pairs;
103  * @param window Indicates the window.
104  * @return Returns the error code of the request of unlock.
105  */
106 int32_t NativeWindowUnlockAndFlushBuffer(OHNativeWindow *window);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif