• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 ARK_OHOS_NATIVE_BUFFER_ADAPTER_H
17 #define ARK_OHOS_NATIVE_BUFFER_ADAPTER_H
18 #pragma once
19 
20 #include "base/include/ark_web_base_ref_counted.h"
21 #include "base/include/ark_web_types.h"
22 
23 namespace OHOS::ArkWeb {
24 /*--ark web(source=webcore)--*/
25 class ArkNativeBufferConfigAdapter : public virtual ArkWebBaseRefCounted {
26 public:
27     /*--ark web()--*/
28     virtual int GetBufferWidth() = 0;
29 
30     /*--ark web()--*/
31     virtual int GetBufferHeight() = 0;
32 
33     /*--ark web()--*/
34     virtual int GetBufferFormat() = 0;
35 
36     /*--ark web()--*/
37     virtual int GetBufferUsage() = 0;
38 
39     /*--ark web()--*/
40     virtual int GetBufferStride() = 0;
41 
42     /*--ark web()--*/
43     virtual void SetBufferWidth(int width) = 0;
44 
45     /*--ark web()--*/
46     virtual void SetBufferHeight(int height) = 0;
47 
48     /*--ark web()--*/
49     virtual void SetBufferFormat(int format) = 0;
50 
51     /*--ark web()--*/
52     virtual void SetBufferUsage(int usage) = 0;
53 
54     /*--ark web()--*/
55     virtual void SetBufferStride(int stride) = 0;
56 };
57 
58 /*--ark web(source=webview)--*/
59 class ArkOhosNativeBufferAdapter : public virtual ArkWebBaseRefCounted {
60 public:
61     ArkOhosNativeBufferAdapter() = default;
62 
63     virtual ~ArkOhosNativeBufferAdapter() = default;
64 
65     /**
66      * @Description: Adds the reference count of a OH_NativeBuffer.
67      * @Input buffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
68      * @Since 12005
69      */
70     /*--ark web()--*/
71     virtual void AcquireBuffer(void* buffer) = 0;
72 
73     /**
74      * @Description: Decreases the reference count of a OH_NativeBuffer and, when the reference count reaches 0, \n
75      *               destroys this OH_NativeBuffer.
76      * @Input buffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
77      * @Since 12005
78      */
79     /*--ark web()--*/
80     virtual void Release(void* buffer) = 0;
81 
82     /**
83      * @Description: Get the egl buffer from the <b>OH_NativeBuffer</b> instance.
84      * @Input buffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
85      * @Output eglBuffer: Indicates the pointer to a egl buffer pointer.
86      * @Return:Returns an error code, 0 is sucess, otherwise, failed.
87      * @Since 12005
88      */
89     /*--ark web()--*/
90     virtual int GetEGLBuffer(void* buffer, void** eglBuffer) = 0;
91 
92     /**
93      * @Description: Free egl buffer.
94      * @Input eglBuffer: Indicates the pointer to an egl buffer.
95      * @Return:Returns an error code, 0 is sucess, otherwise, failed.
96      * @Since 12005
97      */
98     /*--ark web()--*/
99     virtual int FreeEGLBuffer(void* eglBuffer) = 0;
100 
101     /**
102      * @Description: Converts an <b>OHNativeWindowBuffer</b> instance to an <b>OH_NativeBuffer</b>.
103      * @Input nativeWindowBuffer: Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
104      * @Output nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> pointer.
105      * @Return:Returns an error code, 0 is sucess, otherwise, failed.
106      * @Since 12005
107      */
108     /*--ark web()--*/
109     virtual int NativeBufferFromNativeWindowBuffer(void* nativeWindowBuffer, void** nativeBuffer) = 0;
110 
111     /**
112      * @Description: Get the sequence number of native buffer .
113      * @Input nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
114      * @Return:Returns a sequence number.
115      * @Since 12005
116      */
117     /*--ark web()--*/
118     virtual uint32_t GetSeqNum(void* nativeBuffer) = 0;
119 
120     /**
121      * @Description: allocate a native buffer and match with outbuffer.
122      * @Input bufferConfig: Indicates the pointer to a ArkNativeBufferConfigAdapter instance.
123      * @Output nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> pointer.
124      * @Since 14001
125      */
126     /*--ark web()--*/
127     virtual void Allocate(const ArkWebRefPtr<ArkNativeBufferConfigAdapter> bufferConfig, void** outBuffer) = 0;
128 
129     /**
130      * @Description: revise NativeBufferConfigAdapter describing the given buffer.
131      * @Input nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
132      * @Output bufferConfig: Indicates the pointer to a ArkNativeBufferConfigAdapter instance.
133      * @Since 14001
134      */
135     /*--ark web()--*/
136     virtual void Describe(ArkWebRefPtr<ArkNativeBufferConfigAdapter> bufferConfig, void* buffer) = 0;
137 
138     /**
139      * @Description: Locks the specified <b>OH_NativeBuffer</b> for access.
140      * @Input nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
141      * @Input usage: Indicates usage of buffer.
142      * @Input fence: Indicates gpu handle.
143      * @Output out_virtual_address: Indicates the address of the <b>OH_NativeBuffer</b> in virtual memory;
144      * @Return:Returns 0 on success, or -1 if the buffer is null or already locked.
145      * @Since 14001
146      */
147     /*--ark web()--*/
148     virtual int Lock(void* buffer,
149         uint64_t usage, int32_t fence, void** out_virtual_address) = 0;
150 
151     /**
152      * @Description: Receives a <b>OH_NativeBuffer</b> handle from a Unix socket.
153      * @Input socketFd: The file descriptor of the Unix socket.
154      * @Output nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> pointer.
155      * @Return:Always returns 0, indicating success or no operation performed.
156      * @Since 14001
157      */
158     /*--ark web()--*/
159     virtual int RecvHandleFromUnixSocket(int socketFd, void** outBuffer) = 0;
160 
161     /**
162      * @Description: Sends a <b>OH_NativeBuffer</b> handle to a Unix socket.
163      * @Input nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
164      * @Input socketFd: The file descriptor of the Unix socket.
165      * @Return:Returns 0 if the buffer is valid, or -1 if the buffer is null.
166      * @Since 14001
167      */
168     /*--ark web()--*/
169     virtual int SendHandleToUnixSocket(const void* buffer, int socketFd) = 0;
170 
171     /**
172      * @Description: Unlocks the specified <b>OH_NativeBuffer</b>.
173      * @Input nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
174      * @Output fence: Indicates gpu handle.
175      * @Return:Returns 0 on success, or -1 if the buffer is null or not locked.
176      * @Since 14001
177      */
178     /*--ark web()--*/
179     virtual int Unlock(void* buffer, int32_t* fence) = 0;
180 
181     /**
182      * @Description: Frees the specified native buffer by unreferencing it.
183      * @Input nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> instance.
184      * @Return:Returns 0 on success, or -1 if the native buffer is null.
185      * @Since 14001
186      */
187     /*--ark web()--*/
188     virtual int FreeNativeBuffer(void* nativeBuffer) = 0;
189 };
190 
191 } // namespace OHOS::ArkWeb
192 
193 #endif // ARK_OHOS_NATIVE_BUFFER_ADAPTER_H
194