Debian Codegraph @

native/webview/plat_support/draw_fn.h

raw symbols SCIP
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 //******************************************************************************
6 // This is a copy of the coresponding android_webview/public/browser header.
7 // Any changes to the interface should be made there as well.
8 //******************************************************************************
9
10 #ifndef ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_FN_H_
11 #define ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_FN_H_
12
13 #include <android/surface_control.h>
14 #include <vulkan/vulkan.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 // In order to make small changes backwards compatible, all structs passed from
21 // android to chromium are versioned.
22 //
23 // 1 is Android Q. This matches kAwDrawGLInfoVersion version 3.
24 // 2 Adds transfer_function_* and color_space_toXYZD50 to AwDrawFn_DrawGLParams.
25 // 3 Adds SurfaceControl related functions.
26 static const int kAwDrawFnVersion = 3;
27
28 // Returns parent ASurfaceControl for WebView overlays. It will be have same
29 // geometry as the surface we draw into and positioned below it (underlay).
30 // This does not pass ownership to webview, but guaranteed to be alive until
31 // transaction from next removeOverlays call or functor destruction will be
32 // finished.
33 typedef ASurfaceControl* AwDrawFn_GetSurfaceControl();
34
35 // Merges WebView transaction to be applied synchronously with current draw.
36 // This doesn't pass ownership of the transaction, changes will be copied and
37 // webview can free transaction right after the call.
38 typedef void AwDrawFn_MergeTransaction(ASurfaceTransaction* transaction);
39
40 enum AwDrawFnOverlaysMode {
41 // Indicated that webview should not promote anything to overlays this draw
42 // and remove all visible overlays.
43 // Added in version 3.
44 AW_DRAW_FN_OVERLAYS_MODE_DISABLED = 0,
45
46 // Indicates that webview can use overlays.
47 // Added in version 3.
48 AW_DRAW_FN_OVERLAYS_MODE_ENABLED = 1,
49 };
50
51 struct AwDrawFn_OnSyncParams {
52 int version;
53
54 bool apply_force_dark;
55 };
56
57 struct AwDrawFn_DrawGLParams {
58 int version;
59
60 // Input: current clip rect in surface coordinates. Reflects the current state
61 // of the OpenGL scissor rect. Both the OpenGL scissor rect and viewport are
62 // set by the caller of the draw function and updated during View animations.
63 int clip_left;
64 int clip_top;
65 int clip_right;
66 int clip_bottom;
67
68 // Input: current width/height of destination surface.
69 int width;
70 int height;
71
72 // Used to be is_layer.
73 bool deprecated_0;
74
75 // Input: current transformation matrix in surface pixels.
76 // Uses the column-based OpenGL matrix format.
77 float transform[16];
78
79 // Input: Color space parameters.
80 float transfer_function_g;
81 float transfer_function_a;
82 float transfer_function_b;
83 float transfer_function_c;
84 float transfer_function_d;
85 float transfer_function_e;
86 float transfer_function_f;
87 float color_space_toXYZD50[9];
88
89 // Input: Indicates how webview should use overlays for this draw.
90 // Added in version 3.
91 AwDrawFnOverlaysMode overlays_mode;
92
93 // Input: WebView can call it to obtain parent surface control for overlays.
94 // Added in version 3.
95 AwDrawFn_GetSurfaceControl* get_surface_control;
96
97 // Input: WebView call this to apply ASurfaceTransaction synchronously with
98 // the draw.
99 // Added in version 3.
100 AwDrawFn_MergeTransaction* merge_transaction;
101 };
102
103 struct AwDrawFn_InitVkParams {
104 int version;
105 VkInstance instance;
106 VkPhysicalDevice physical_device;
107 VkDevice device;
108 VkQueue queue;
109 uint32_t graphics_queue_index;
110 uint32_t api_version;
111 const char* const* enabled_instance_extension_names;
112 uint32_t enabled_instance_extension_names_length;
113 const char* const* enabled_device_extension_names;
114 uint32_t enabled_device_extension_names_length;
115 // Only one of device_features and device_features_2 should be non-null.
116 // If both are null then no features are enabled.
117 VkPhysicalDeviceFeatures* device_features;
118 VkPhysicalDeviceFeatures2* device_features_2;
119 };
120
121 struct AwDrawFn_DrawVkParams {
122 int version;
123
124 // Input: current width/height of destination surface.
125 int width;
126 int height;
127
128 bool deprecated_0;
129
130 // Input: current transform matrix
131 float transform[16];
132
133 // Input WebView should do its main compositing draws into this. It cannot do
134 // anything that would require stopping the render pass.
135 VkCommandBuffer secondary_command_buffer;
136
137 // Input: The main color attachment index where secondary_command_buffer will
138 // eventually be submitted.
139 uint32_t color_attachment_index;
140
141 // Input: A render pass which will be compatible to the one which the
142 // secondary_command_buffer will be submitted into.
143 VkRenderPass compatible_render_pass;
144
145 // Input: Format of the destination surface.
146 VkFormat format;
147
148 // Input: Color space parameters.
149 float transfer_function_g;
150 float transfer_function_a;
151 float transfer_function_b;
152 float transfer_function_c;
153 float transfer_function_d;
154 float transfer_function_e;
155 float transfer_function_f;
156 float color_space_toXYZD50[9];
157
158 // Input: current clip rect
159 int clip_left;
160 int clip_top;
161 int clip_right;
162 int clip_bottom;
163
164 // Input: Indicates how webview should use overlays for this draw.
165 // Added in version 3.
166 AwDrawFnOverlaysMode overlays_mode;
167
168 // Input: WebView can call it to obtain parent surface control for overlays.
169 // Added in version 3.
170 AwDrawFn_GetSurfaceControl* get_surface_control;
171
172 // Input: WebView call this to apply ASurfaceTransaction synchronously with
173 // the draw.
174 // Added in version 3.
175 AwDrawFn_MergeTransaction* merge_transaction;
176 };
177
178 struct AwDrawFn_PostDrawVkParams {
179 int version;
180 };
181
182 struct AwDrawFn_RemoveOverlaysParams {
183 int version;
184 // Input: WebView call this to apply ASurfaceTransaction synchronously with
185 // the draw.
186 // Added in version 3.
187 AwDrawFn_MergeTransaction* merge_transaction;
188 };
189
190 // Called on render thread while UI thread is blocked. Called for both GL and
191 // VK.
192 typedef void AwDrawFn_OnSync(int functor,
193 void* data,
194 AwDrawFn_OnSyncParams* params);
195
196 // Called on render thread when either the context is destroyed _or_ when the
197 // functor's last reference goes away. Will always be called with an active
198 // context. Called for both GL and VK.
199 typedef void AwDrawFn_OnContextDestroyed(int functor, void* data);
200
201 // Called on render thread when the last reference to the handle goes away and
202 // the handle is considered irrevocably destroyed. Will always be preceded by
203 // a call to OnContextDestroyed if this functor had ever been drawn. Called for
204 // both GL and VK.
205 typedef void AwDrawFn_OnDestroyed(int functor, void* data);
206
207 // Only called for GL.
208 typedef void AwDrawFn_DrawGL(int functor,
209 void* data,
210 AwDrawFn_DrawGLParams* params);
211
212 // Initialize vulkan state. Needs to be called again after any
213 // OnContextDestroyed. Only called for Vulkan.
214 typedef void AwDrawFn_InitVk(int functor,
215 void* data,
216 AwDrawFn_InitVkParams* params);
217
218 // Only called for Vulkan.
219 typedef void AwDrawFn_DrawVk(int functor,
220 void* data,
221 AwDrawFn_DrawVkParams* params);
222
223 // Only called for Vulkan.
224 typedef void AwDrawFn_PostDrawVk(int functor,
225 void* data,
226 AwDrawFn_PostDrawVkParams* params);
227
228 // Can be called to make webview hide all overlays and stop updating them until
229 // next draw. WebView must obtain new ASurfaceControl after this call to use as
230 // parent for the overlays on next draw.
231 typedef void AwDrawFn_RemoveOverlays(int functor,
232 void* data,
233 AwDrawFn_RemoveOverlaysParams* params);
234
235 struct AwDrawFnFunctorCallbacks {
236 // version is passed in CreateFunctor call.
237 AwDrawFn_OnSync* on_sync;
238 AwDrawFn_OnContextDestroyed* on_context_destroyed;
239 AwDrawFn_OnDestroyed* on_destroyed;
240 AwDrawFn_DrawGL* draw_gl;
241 AwDrawFn_InitVk* init_vk;
242 AwDrawFn_DrawVk* draw_vk;
243 AwDrawFn_PostDrawVk* post_draw_vk;
244 // Added in version 3.
245 AwDrawFn_RemoveOverlays* remove_overlays;
246 };
247
248 enum AwDrawFnRenderMode {
249 AW_DRAW_FN_RENDER_MODE_OPENGL_ES = 0,
250 AW_DRAW_FN_RENDER_MODE_VULKAN = 1,
251 };
252
253 // Get the render mode. Result is static for the process.
254 typedef AwDrawFnRenderMode AwDrawFn_QueryRenderMode(void);
255
256 // This available up to version 3, use the one below.
257 typedef int AwDrawFn_CreateFunctor(void* data,
258 AwDrawFnFunctorCallbacks* functor_callbacks);
259
260 // Create a functor. |functor_callbacks| should be valid until OnDestroyed.
261 typedef int AwDrawFn_CreateFunctor_v3(
262 void* data,
263 int version,
264 AwDrawFnFunctorCallbacks* functor_callbacks);
265
266 // May be called on any thread to signal that the functor should be destroyed.
267 // The functor will receive an onDestroyed when the last usage of it is
268 // released, and it should be considered alive & active until that point.
269 typedef void AwDrawFn_ReleaseFunctor(int functor);
270
271 struct AwDrawFnFunctionTable {
272 int version;
273 AwDrawFn_QueryRenderMode* query_render_mode;
274 // Available up to version 3.
275 AwDrawFn_CreateFunctor* create_functor;
276 AwDrawFn_ReleaseFunctor* release_functor;
277 // Added in version 3.
278 AwDrawFn_CreateFunctor_v3* create_functor_v3;
279 };
280
281 #ifdef __cplusplus
282 } // extern "C"
283 #endif
284
285 #endif // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_FN_H_