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