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