1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H
18 #define FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H
19 
20 #include <cutils/compiler.h>
21 #include <private/hwui/DrawGlInfo.h>
22 #include <private/hwui/DrawVkInfo.h>
23 
24 namespace android::uirenderer {
25 
26 enum class RenderMode {
27     OpenGL_ES,
28     Vulkan,
29 };
30 
31 // Static for the lifetime of the process
32 ANDROID_API RenderMode WebViewFunctor_queryPlatformRenderMode();
33 
34 struct WebViewSyncData {
35     bool applyForceDark;
36 };
37 
38 struct WebViewFunctorCallbacks {
39     // kModeSync, called on RenderThread
40     void (*onSync)(int functor, void* data, const WebViewSyncData& syncData);
41 
42     // Called when either the context is destroyed _or_ when the functor's last reference goes
43     // away. Will always be called with an active context and always on renderthread.
44     void (*onContextDestroyed)(int functor, void* data);
45 
46     // Called when the last reference to the handle goes away and the handle is considered
47     // irrevocably destroyed. Will always be proceeded by a call to onContextDestroyed if
48     // this functor had ever been drawn.
49     void (*onDestroyed)(int functor, void* data);
50 
51     union {
52         struct {
53             // Called on RenderThread. initialize is guaranteed to happen before this call
54             void (*draw)(int functor, void* data, const DrawGlInfo& params);
55         } gles;
56         struct {
57             // Called either the first time the functor is used or the first time it's used after
58             // a call to onContextDestroyed.
59             void (*initialize)(int functor, void* data, const VkFunctorInitParams& params);
60             void (*draw)(int functor, void* data, const VkFunctorDrawParams& params);
61             void (*postDraw)(int functor, void*);
62         } vk;
63     };
64 };
65 
66 // Creates a new WebViewFunctor from the given prototype. The prototype is copied after
67 // this function returns. Caller retains full ownership of it.
68 // Returns -1 if the creation fails (such as an unsupported functorMode + platform mode combination)
69 ANDROID_API int WebViewFunctor_create(void* data, const WebViewFunctorCallbacks& prototype, RenderMode functorMode);
70 
71 // May be called on any thread to signal that the functor should be destroyed.
72 // The functor will receive an onDestroyed when the last usage of it is released,
73 // and it should be considered alive & active until that point.
74 ANDROID_API void WebViewFunctor_release(int functor);
75 
76 }  // namespace android::uirenderer
77 
78 #endif  // FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H
79