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