132a6e48fSopenharmony_ci/*
232a6e48fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
332a6e48fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
432a6e48fSopenharmony_ci * you may not use this file except in compliance with the License.
532a6e48fSopenharmony_ci * You may obtain a copy of the License at
632a6e48fSopenharmony_ci *
732a6e48fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
832a6e48fSopenharmony_ci *
932a6e48fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1032a6e48fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1132a6e48fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1232a6e48fSopenharmony_ci * See the License for the specific language governing permissions and
1332a6e48fSopenharmony_ci * limitations under the License.
1432a6e48fSopenharmony_ci */
1532a6e48fSopenharmony_ci
1632a6e48fSopenharmony_ci#ifndef NDK_INCLUDE_NATIVE_WINDOW_H_
1732a6e48fSopenharmony_ci#define NDK_INCLUDE_NATIVE_WINDOW_H_
1832a6e48fSopenharmony_ci
1932a6e48fSopenharmony_ci#include "external_window.h"
2032a6e48fSopenharmony_ci#include "native_buffer.h"
2132a6e48fSopenharmony_ci
2232a6e48fSopenharmony_ci#ifdef __cplusplus
2332a6e48fSopenharmony_ciextern "C" {
2432a6e48fSopenharmony_ci#endif
2532a6e48fSopenharmony_ci
2632a6e48fSopenharmony_ci#define MKMAGIC(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + ((d) << 0))
2732a6e48fSopenharmony_ci
2832a6e48fSopenharmony_cienum NativeObjectMagic {
2932a6e48fSopenharmony_ci    NATIVE_OBJECT_MAGIC_WINDOW = MKMAGIC('W', 'I', 'N', 'D'),
3032a6e48fSopenharmony_ci    NATIVE_OBJECT_MAGIC_WINDOW_BUFFER = MKMAGIC('W', 'B', 'U', 'F'),
3132a6e48fSopenharmony_ci};
3232a6e48fSopenharmony_ci
3332a6e48fSopenharmony_ci// pSurface type is OHOS::sptr<OHOS::Surface>*
3432a6e48fSopenharmony_ciOHNativeWindow* CreateNativeWindowFromSurface(void* pSurface);
3532a6e48fSopenharmony_civoid DestoryNativeWindow(OHNativeWindow* window);
3632a6e48fSopenharmony_ci
3732a6e48fSopenharmony_ci// pSurfaceBuffer type is OHOS::sptr<OHOS::SurfaceBuffer>*
3832a6e48fSopenharmony_ciOHNativeWindowBuffer* CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer);
3932a6e48fSopenharmony_ciOHNativeWindowBuffer* CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer);
4032a6e48fSopenharmony_civoid DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer);
4132a6e48fSopenharmony_ci
4232a6e48fSopenharmony_ciint32_t NativeWindowRequestBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd);
4332a6e48fSopenharmony_ciint32_t NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer,
4432a6e48fSopenharmony_ci    int fenceFd, Region region);
4532a6e48fSopenharmony_ciint32_t GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer,
4632a6e48fSopenharmony_ci    int *fenceFd, float matrix[16]);
4732a6e48fSopenharmony_ciint32_t NativeWindowCancelBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
4832a6e48fSopenharmony_ci
4932a6e48fSopenharmony_ci// The meaning and quantity of parameters vary according to the code type.
5032a6e48fSopenharmony_ci// For details, see the NativeWindowOperation comment.
5132a6e48fSopenharmony_ciint32_t NativeWindowHandleOpt(OHNativeWindow *window, int code, ...);
5232a6e48fSopenharmony_ciBufferHandle *GetBufferHandleFromNative(OHNativeWindowBuffer *buffer);
5332a6e48fSopenharmony_ci
5432a6e48fSopenharmony_ci// NativeObject: NativeWindow, NativeWindowBuffer
5532a6e48fSopenharmony_ciint32_t NativeObjectReference(void *obj);
5632a6e48fSopenharmony_ciint32_t NativeObjectUnreference(void *obj);
5732a6e48fSopenharmony_ciint32_t GetNativeObjectMagic(void *obj);
5832a6e48fSopenharmony_ci
5932a6e48fSopenharmony_ciint32_t NativeWindowSetScalingMode(OHNativeWindow *window, uint32_t sequence, OHScalingMode scalingMode);
6032a6e48fSopenharmony_ciint32_t NativeWindowSetMetaData(OHNativeWindow *window, uint32_t sequence, int32_t size,
6132a6e48fSopenharmony_ci                                const OHHDRMetaData *metaData);
6232a6e48fSopenharmony_ciint32_t NativeWindowSetMetaDataSet(OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key,
6332a6e48fSopenharmony_ci                                   int32_t size, const uint8_t *metaData);
6432a6e48fSopenharmony_ciint32_t NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandle *handle);
6532a6e48fSopenharmony_ciint32_t GetSurfaceId(OHNativeWindow *window, uint64_t *surfaceId);
6632a6e48fSopenharmony_ciint32_t CreateNativeWindowFromSurfaceId(uint64_t surfaceId, OHNativeWindow **window);
6732a6e48fSopenharmony_ciint32_t NativeWindowAttachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
6832a6e48fSopenharmony_ciint32_t NativeWindowDetachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer);
6932a6e48fSopenharmony_ciint32_t NativeWindowGetTransformHint(OHNativeWindow *window, OH_NativeBuffer_TransformType *transform);
7032a6e48fSopenharmony_ciint32_t NativeWindowSetTransformHint(OHNativeWindow *window, OH_NativeBuffer_TransformType transform);
7132a6e48fSopenharmony_ciint32_t NativeWindowGetDefaultWidthAndHeight(OHNativeWindow *window, int32_t *width, int32_t *height);
7232a6e48fSopenharmony_ciint32_t NativeWindowSetRequestWidthAndHeight(OHNativeWindow *window, int32_t width, int32_t height);
7332a6e48fSopenharmony_civoid NativeWindowSetBufferHold(OHNativeWindow *window);
7432a6e48fSopenharmony_ciint32_t NativeWindowWriteToParcel(OHNativeWindow *window, OHIPCParcel *parcel);
7532a6e48fSopenharmony_ciint32_t NativeWindowReadFromParcel(OHIPCParcel *parcel, OHNativeWindow **window);
7632a6e48fSopenharmony_ciint32_t GetLastFlushedBufferV2(OHNativeWindow *window, OHNativeWindowBuffer **buffer, int *fenceFd, float matrix[16]);
7732a6e48fSopenharmony_ciint32_t NativeWindowSetScalingModeV2(OHNativeWindow *window, OHScalingModeV2 scalingMode);
7832a6e48fSopenharmony_ciint32_t NativeWindowDisconnect(OHNativeWindow *window);
7932a6e48fSopenharmony_ciint32_t OH_NativeWindow_SetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace colorSpace);
8032a6e48fSopenharmony_ciint32_t OH_NativeWindow_GetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace);
8132a6e48fSopenharmony_ciint32_t OH_NativeWindow_SetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey,
8232a6e48fSopenharmony_ci    int32_t size, uint8_t *metadata);
8332a6e48fSopenharmony_ciint32_t OH_NativeWindow_GetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey,
8432a6e48fSopenharmony_ci    int32_t *size, uint8_t **metadata);
8532a6e48fSopenharmony_ci
8632a6e48fSopenharmony_ci#ifdef __cplusplus
8732a6e48fSopenharmony_ci}
8832a6e48fSopenharmony_ci#endif
8932a6e48fSopenharmony_ci
9032a6e48fSopenharmony_ci#endif