• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef __ANDROID__  // Layoutlib does not support surface control
21 #include <android/surface_control.h>
22 #else
23 // To avoid ifdefs around overlay implementation all over the place we typedef these to void *. They
24 // won't be used.
25 typedef void* ASurfaceControl;
26 typedef void* ASurfaceTransaction;
27 #endif
28 
29 #include <cutils/compiler.h>
30 #include <private/hwui/DrawGlInfo.h>
31 #include <private/hwui/DrawVkInfo.h>
32 
33 namespace android::uirenderer {
34 
35 enum class RenderMode {
36     OpenGL_ES,
37     Vulkan,
38 };
39 
40 enum class OverlaysMode {
41     // Indicated that webview should not promote anything to overlays this draw
42     // and remove all visible overlays.
43     Disabled,
44     // Indicates that webview can use overlays.
45     Enabled
46 };
47 
48 // Static for the lifetime of the process
49 ANDROID_API RenderMode WebViewFunctor_queryPlatformRenderMode();
50 
51 struct WebViewSyncData {
52     bool applyForceDark;
53 };
54 
55 struct WebViewOverlayData {
56     // Desired overlay mode for this draw.
57     OverlaysMode overlaysMode;
58 
59     // Returns parent ASurfaceControl for WebView overlays. It will be have same
60     // geometry as the surface we draw into and positioned below it (underlay).
61     // This does not pass ownership to webview, but guaranteed to be alive until
62     // transaction from next removeOverlays call or functor destruction will be
63     // finished.
64     ASurfaceControl* (*getSurfaceControl)();
65 
66     // Merges WebView transaction to be applied synchronously with current draw.
67     // This doesn't pass ownership of the transaction, changes will be copied and
68     // webview can free transaction right after the call.
69     void (*mergeTransaction)(ASurfaceTransaction*);
70 };
71 
72 struct WebViewFunctorCallbacks {
73     // kModeSync, called on RenderThread
74     void (*onSync)(int functor, void* data, const WebViewSyncData& syncData);
75 
76     // Called when either the context is destroyed _or_ when the functor's last reference goes
77     // away. Will always be called with an active context and always on renderthread.
78     void (*onContextDestroyed)(int functor, void* data);
79 
80     // Called when the last reference to the handle goes away and the handle is considered
81     // irrevocably destroyed. Will always be proceeded by a call to onContextDestroyed if
82     // this functor had ever been drawn.
83     void (*onDestroyed)(int functor, void* data);
84 
85     // Called on render thread to force webview hide all overlays and stop updating them.
86     // Should happen during hwui draw (e.g can be called instead of draw if webview
87     // isn't visible and won't receive draw) and support MergeTransaction call.
88     void (*removeOverlays)(int functor, void* data, void (*mergeTransaction)(ASurfaceTransaction*));
89 
90     union {
91         struct {
92             // Called on RenderThread. initialize is guaranteed to happen before this call
93             void (*draw)(int functor, void* data, const DrawGlInfo& params,
94                          const WebViewOverlayData& overlayParams);
95         } gles;
96         struct {
97             // Called either the first time the functor is used or the first time it's used after
98             // a call to onContextDestroyed.
99             void (*initialize)(int functor, void* data, const VkFunctorInitParams& params);
100             void (*draw)(int functor, void* data, const VkFunctorDrawParams& params,
101                          const WebViewOverlayData& overlayParams);
102             void (*postDraw)(int functor, void*);
103         } vk;
104     };
105 };
106 
107 // Creates a new WebViewFunctor from the given prototype. The prototype is copied after
108 // this function returns. Caller retains full ownership of it.
109 // Returns -1 if the creation fails (such as an unsupported functorMode + platform mode combination)
110 ANDROID_API int WebViewFunctor_create(void* data, const WebViewFunctorCallbacks& prototype, RenderMode functorMode);
111 
112 // May be called on any thread to signal that the functor should be destroyed.
113 // The functor will receive an onDestroyed when the last usage of it is released,
114 // and it should be considered alive & active until that point.
115 ANDROID_API void WebViewFunctor_release(int functor);
116 
117 }  // namespace android::uirenderer
118 
119 #endif  // FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H
120