1 /*
2  * Copyright (c) 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 ARK_GRAPHIC_ADAPTER_H
17 #define ARK_GRAPHIC_ADAPTER_H
18 #pragma once
19 
20 #include "ohos_adapter/include/ark_web_adapter_structs.h"
21 
22 #include "base/include/ark_web_base_ref_counted.h"
23 #include "base/include/ark_web_types.h"
24 
25 namespace OHOS::ArkWeb {
26 
27 /*--ark web(source=webview)--*/
28 class ArkVSyncAdapter : public virtual ArkWebBaseRefCounted {
29 public:
30     /*--ark web()--*/
31     virtual uint32_t RequestVsync(void* data, void* cb) = 0;
32 
33     /*--ark web()--*/
34     virtual int64_t GetVSyncPeriod() = 0;
35 
36     /*--ark web()--*/
37     virtual void SetFrameRateLinkerEnable(bool enabled) = 0;
38 
39     /*--ark web()--*/
40     virtual void SetFramePreferredRate(int32_t preferredRate) = 0;
41 
42     /*--ark web()--*/
43     virtual void SetOnVsyncCallback(OnVsyncCallback callback) = 0;
44 
45     /*--ark web()--*/
46     virtual void SetOnVsyncEndCallback(OnVsyncCallback onVsyncEndCallback) = 0;
47 };
48 
49 /*--ark web(source=webcore)--*/
50 class ArkBufferRequestConfigAdapter : public virtual ArkWebBaseRefCounted {
51 public:
52     /*--ark web()--*/
53     virtual int32_t GetWidth() = 0;
54 
55     /*--ark web()--*/
56     virtual int32_t GetHeight() = 0;
57 
58     /*--ark web()--*/
59     virtual int32_t GetStrideAlignment() = 0;
60 
61     /*--ark web()--*/
62     virtual int32_t GetFormat() = 0;
63 
64     /*--ark web()--*/
65     virtual uint64_t GetUsage() = 0;
66 
67     /*--ark web()--*/
68     virtual int32_t GetTimeout() = 0;
69 
70     /*--ark web()--*/
71     virtual int32_t GetColorGamut() = 0;
72 
73     /*--ark web()--*/
74     virtual int32_t GetTransformType() = 0;
75 };
76 
77 /*--ark web(source=webcore)--*/
78 class ArkBufferFlushConfigAdapter : public virtual ArkWebBaseRefCounted {
79 public:
80     /*--ark web()--*/
81     virtual int32_t GetX() = 0;
82 
83     /*--ark web()--*/
84     virtual int32_t GetY() = 0;
85 
86     /*--ark web()--*/
87     virtual int32_t GetW() = 0;
88 
89     /*--ark web()--*/
90     virtual int32_t GetH() = 0;
91 
92     /*--ark web()--*/
93     virtual int64_t GetTimestamp() = 0;
94 };
95 
96 /*--ark web(source=webview)--*/
97 class ArkSurfaceBufferAdapter : public virtual ArkWebBaseRefCounted {
98 public:
99     /*--ark web()--*/
100     virtual int32_t GetFileDescriptor() = 0;
101 
102     /*--ark web()--*/
103     virtual int32_t GetWidth() = 0;
104 
105     /*--ark web()--*/
106     virtual int32_t GetHeight() = 0;
107 
108     /*--ark web()--*/
109     virtual int32_t GetStride() = 0;
110 
111     /*--ark web()--*/
112     virtual int32_t GetFormat() = 0;
113 
114     /*--ark web()--*/
115     virtual uint32_t GetSize() = 0;
116 
117     /*--ark web()--*/
118     virtual void* GetVirAddr() = 0;
119 };
120 
121 /*--ark web(source=webcore)--*/
122 class ArkIBufferConsumerListenerAdapter : public virtual ArkWebBaseRefCounted {
123 public:
124     /*--ark web()--*/
125     virtual void OnBufferAvailable(ArkWebRefPtr<ArkSurfaceBufferAdapter> buffer) = 0;
126 };
127 
128 /*--ark web(source=webview)--*/
129 class ArkIConsumerSurfaceAdapter : public virtual ArkWebBaseRefCounted {
130 public:
131     /*--ark web()--*/
132     virtual int32_t RegisterConsumerListener(ArkWebRefPtr<ArkIBufferConsumerListenerAdapter> listener) = 0;
133 
134     /*--ark web()--*/
135     virtual int32_t ReleaseBuffer(ArkWebRefPtr<ArkSurfaceBufferAdapter> buffer, int32_t fence) = 0;
136 
137     /*--ark web()--*/
138     virtual int32_t SetUserData(const ArkWebString& key, const ArkWebString& val) = 0;
139 
140     /*--ark web()--*/
141     virtual int32_t SetQueueSize(uint32_t queueSize) = 0;
142 };
143 
144 /*--ark web(source=webview)--*/
145 class ArkWindowAdapter : public virtual ArkWebBaseRefCounted {
146 public:
147     /*--ark web()--*/
148     virtual void* CreateNativeWindowFromSurface(void* pSurface) = 0;
149 
150     /*--ark web()--*/
151     virtual void DestroyNativeWindow(void* window) = 0;
152 
153     /*--ark web()--*/
154     virtual int32_t NativeWindowSetBufferGeometry(void* window, int32_t width, int32_t height) = 0;
155 
156     /*--ark web()--*/
157     virtual void NativeWindowSurfaceCleanCache(void* window) = 0;
158 
159     /*--ark web()--*/
160     virtual void NativeWindowSurfaceCleanCacheWithPara(void* window, bool cleanAll) = 0;
161 };
162 
163 /*--ark web(source=webview)--*/
164 class ArkAshmemAdapter : public virtual ArkWebBaseRefCounted {
165 public:
166     /*--ark web()--*/
167     static int AshmemCreate(const char* name, size_t size);
168 };
169 
170 /*--ark web(source=webcore)--*/
171 class ArkFrameAvailableListener : public virtual ArkWebBaseRefCounted {
172 public:
173     /*--ark web()--*/
174     virtual void* GetContext() = 0;
175 
176     /*--ark web()--*/
177     virtual void* GetOnFrameAvailableCb() = 0;
178 };
179 
180 /*--ark web(source=webview)--*/
181 class ArkNativeImageAdapter : public virtual ArkWebBaseRefCounted {
182 public:
183     /*--ark web()--*/
184     virtual void CreateNativeImage(uint32_t textureId, uint32_t textureTarget) = 0;
185 
186     /*--ark web()--*/
187     virtual void* AquireNativeWindowFromNativeImage() = 0;
188 
189     /*--ark web()--*/
190     virtual int32_t AttachContext(uint32_t textureId) = 0;
191 
192     /*--ark web()--*/
193     virtual int32_t DetachContext() = 0;
194 
195     /*--ark web()--*/
196     virtual int32_t UpdateSurfaceImage() = 0;
197 
198     /*--ark web()--*/
199     virtual int64_t GetTimestamp() = 0;
200 
201     /*--ark web()--*/
202     virtual int32_t GetTransformMatrix(float matrix[16]) = 0;
203 
204     /*--ark web()--*/
205     virtual int32_t GetSurfaceId(uint64_t* surfaceId) = 0;
206 
207     /*--ark web()--*/
208     virtual int32_t SetOnFrameAvailableListener(ArkWebRefPtr<ArkFrameAvailableListener> listener) = 0;
209 
210     /*--ark web()--*/
211     virtual int32_t UnsetOnFrameAvailableListener() = 0;
212 
213     /*--ark web()--*/
214     virtual void DestroyNativeImage() = 0;
215 
216     /**
217      * @Description: Create a <b>OH_NativeImage</b> as surface consumer.
218      * @Since 12005
219      */
220     /*--ark web()--*/
221     virtual void NewNativeImage() = 0;
222 
223     /**
224      * @Description: Acquire an <b>OHNativeWindowBuffer</b> for content consumer.
225      * @Output windowBuffer: Indicates the pointer to an <b>OHNativeWindowBuffer</b> point.
226 	 * @Output acquireFenceFd: Indicates the pointer to a file descriptor handle.
227      * @Return:Returns an error code, 0 is sucess, otherwise, failed.
228      * @Since 12005
229      */
230     /*--ark web()--*/
231     virtual int32_t AcquireNativeWindowBuffer(
232         void** windowBuffer,
233         int* acquireFenceFd) = 0;
234 
235     /**
236      * @Description: Converts an <b>OHNativeWindowBuffer</b> instance to an <b>OH_NativeBuffer</b>.
237      * @Input windowBuffer: Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance.
238      * @Output nativeBuffer: Indicates the pointer to a <b>OH_NativeBuffer</b> pointer.
239      * @Return:Returns an error code, 0 is sucess, otherwise, failed.
240      * @Since 12005
241      */
242     /*--ark web()--*/
243     virtual int32_t GetNativeBuffer(
244         void* windowBuffer,
245         void** nativeBuffer) = 0;
246 
247     /**
248      * @Description: Release the <b>OHNativeWindowBuffer</b> to the buffer queue for reuse.
249      * @Input windowBuffer: Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
250      * @Input fenceFd: Indicates a file descriptor handle, which is used for timing synchronization.
251      * @Return:Returns an error code, 0 is sucess, otherwise, failed.
252      * @Since 12005
253      */
254     /*--ark web()--*/
255     virtual int32_t ReleaseNativeWindowBuffer(void* windowBuffer, int fenceFd) = 0;
256 
257     /**
258      * @Description: Get the size of the <b>OHNativeWindowBuffer</b>.
259      * @Input windowBuffer: Indicates the pointer to an <b>OHNativeWindowBuffer</b> instance.
260      * @Output width: Indicates the width of the window buffer size.
261      * @Output height: Indicates the height of the window buffer size.
262      * @Since 12005
263      */
264     /*--ark web()--*/
265     virtual void GetNativeWindowBufferSize(
266         void* windowBuffer,
267         uint32_t* width,
268         uint32_t* height) = 0;
269 };
270 
271 /*--ark web(source=webview)--*/
272 class ArkProducerSurfaceAdapter : public virtual ArkWebBaseRefCounted {
273 public:
274     /*--ark web()--*/
275     virtual ArkWebRefPtr<ArkSurfaceBufferAdapter> RequestBuffer(
276         int32_t& fence, ArkWebRefPtr<ArkBufferRequestConfigAdapter> config) = 0;
277 
278     /*--ark web()--*/
279     virtual int32_t FlushBuffer(ArkWebRefPtr<ArkSurfaceBufferAdapter> buffer, int32_t fence,
280         ArkWebRefPtr<ArkBufferFlushConfigAdapter> config) = 0;
281 };
282 
283 } // namespace OHOS::ArkWeb
284 
285 #endif // Ark_GRAPHIC_ADAPTER_H
286