blob: 0490e650a7a42c58a602756c1787bb7a54447dba [file] [log] [blame]
Bo Liu788d9572018-12-12 16:08:29 -08001// 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 <vulkan/vulkan.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19// In order to make small changes backwards compatible, all structs passed from
20// android to chromium are versioned.
21//
22// 1 is Android Q. This matches kAwDrawGLInfoVersion version 3.
23static const int kAwDrawFnVersion = 1;
24
25struct AwDrawFn_OnSyncParams {
26 int version;
27
28 bool apply_force_dark;
29};
30
31struct AwDrawFn_DrawGLParams {
32 int version;
33
34 // Input: current clip rect in surface coordinates. Reflects the current state
35 // of the OpenGL scissor rect. Both the OpenGL scissor rect and viewport are
36 // set by the caller of the draw function and updated during View animations.
37 int clip_left;
38 int clip_top;
39 int clip_right;
40 int clip_bottom;
41
42 // Input: current width/height of destination surface.
43 int width;
44 int height;
45
46 // Input: is the View rendered into an independent layer.
47 // If false, the surface is likely to hold to the full screen contents, with
48 // the scissor box set by the caller to the actual View location and size.
49 // Also the transformation matrix will contain at least a translation to the
50 // position of the View to render, plus any other transformations required as
51 // part of any ongoing View animation. View translucency (alpha) is ignored,
52 // although the framework will set is_layer to true for non-opaque cases.
53 // Can be requested via the View.setLayerType(View.LAYER_TYPE_NONE, ...)
54 // Android API method.
55 //
56 // If true, the surface is dedicated to the View and should have its size.
57 // The viewport and scissor box are set by the caller to the whole surface.
58 // Animation transformations are handled by the caller and not reflected in
59 // the provided transformation matrix. Translucency works normally.
60 // Can be requested via the View.setLayerType(View.LAYER_TYPE_HARDWARE, ...)
61 // Android API method.
62 bool is_layer;
63
64 // Input: current transformation matrix in surface pixels.
65 // Uses the column-based OpenGL matrix format.
66 float transform[16];
67};
68
69struct AwDrawFn_InitVkParams {
70 int version;
71 VkInstance instance;
72 VkPhysicalDevice physical_device;
73 VkDevice device;
74 VkQueue queue;
75 uint32_t graphics_queue_index;
76 uint32_t instance_version;
Bo Liu7b8c1eb2019-01-08 20:17:55 -080077 const char* const* enabled_instance_extension_names;
78 uint32_t enabled_instance_extension_names_length;
79 const char* const* enabled_device_extension_names;
80 uint32_t enabled_device_extension_names_length;
Bo Liu788d9572018-12-12 16:08:29 -080081 // Only one of device_features and device_features_2 should be non-null.
82 // If both are null then no features are enabled.
83 VkPhysicalDeviceFeatures* device_features;
84 VkPhysicalDeviceFeatures2* device_features_2;
85};
86
87struct AwDrawFn_DrawVkParams {
88 int version;
89
90 // Input: current width/height of destination surface.
91 int width;
92 int height;
93
94 // Input: is the render target a FBO
95 bool is_layer;
96
97 // Input: current transform matrix
98 float transform[16];
99
100 // Input WebView should do its main compositing draws into this. It cannot do
101 // anything that would require stopping the render pass.
102 VkCommandBuffer secondary_command_buffer;
103
104 // Input: The main color attachment index where secondary_command_buffer will
105 // eventually be submitted.
106 uint32_t color_attachment_index;
107
108 // Input: A render pass which will be compatible to the one which the
109 // secondary_command_buffer will be submitted into.
110 VkRenderPass compatible_render_pass;
111
112 // Input: Format of the destination surface.
113 VkFormat format;
114
Chris Blume1a2bdc82019-01-11 16:52:12 -0800115 // Input: Color space parameters.
116 float transfer_function_g;
117 float transfer_function_a;
118 float transfer_function_b;
119 float transfer_function_c;
120 float transfer_function_d;
121 float transfer_function_e;
122 float transfer_function_f;
123 float color_space_toXYZD50[9];
Bo Liu788d9572018-12-12 16:08:29 -0800124
125 // Input: current clip rect
126 int clip_left;
127 int clip_top;
128 int clip_right;
129 int clip_bottom;
130};
131
132struct AwDrawFn_PostDrawVkParams {
133 int version;
Bo Liu788d9572018-12-12 16:08:29 -0800134};
135
136// Called on render thread while UI thread is blocked. Called for both GL and
137// VK.
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800138typedef void AwDrawFn_OnSync(int functor,
139 void* data,
140 AwDrawFn_OnSyncParams* params);
Bo Liu788d9572018-12-12 16:08:29 -0800141
142// Called on render thread when either the context is destroyed _or_ when the
143// functor's last reference goes away. Will always be called with an active
144// context. Called for both GL and VK.
Bo Liud6668e72018-12-14 19:37:41 -0800145typedef void AwDrawFn_OnContextDestroyed(int functor, void* data);
Bo Liu788d9572018-12-12 16:08:29 -0800146
147// Called on render thread when the last reference to the handle goes away and
Bo Liud6668e72018-12-14 19:37:41 -0800148// the handle is considered irrevocably destroyed. Will always be preceded by
Bo Liu788d9572018-12-12 16:08:29 -0800149// a call to OnContextDestroyed if this functor had ever been drawn. Called for
150// both GL and VK.
Bo Liud6668e72018-12-14 19:37:41 -0800151typedef void AwDrawFn_OnDestroyed(int functor, void* data);
Bo Liu788d9572018-12-12 16:08:29 -0800152
153// Only called for GL.
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800154typedef void AwDrawFn_DrawGL(int functor,
155 void* data,
156 AwDrawFn_DrawGLParams* params);
Bo Liu788d9572018-12-12 16:08:29 -0800157
158// Initialize vulkan state. Needs to be called again after any
159// OnContextDestroyed. Only called for Vulkan.
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800160typedef void AwDrawFn_InitVk(int functor,
161 void* data,
162 AwDrawFn_InitVkParams* params);
Bo Liu788d9572018-12-12 16:08:29 -0800163
164// Only called for Vulkan.
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800165typedef void AwDrawFn_DrawVk(int functor,
166 void* data,
167 AwDrawFn_DrawVkParams* params);
Bo Liu788d9572018-12-12 16:08:29 -0800168
169// Only called for Vulkan.
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800170typedef void AwDrawFn_PostDrawVk(int functor,
171 void* data,
Bo Liu788d9572018-12-12 16:08:29 -0800172 AwDrawFn_PostDrawVkParams* params);
173
174struct AwDrawFnFunctorCallbacks {
175 // No version here since this is passed from chromium to android.
176 AwDrawFn_OnSync* on_sync;
177 AwDrawFn_OnContextDestroyed* on_context_destroyed;
178 AwDrawFn_OnDestroyed* on_destroyed;
179 AwDrawFn_DrawGL* draw_gl;
180 AwDrawFn_InitVk* init_vk;
181 AwDrawFn_DrawVk* draw_vk;
182 AwDrawFn_PostDrawVk* post_draw_vk;
183};
184
185enum AwDrawFnRenderMode {
186 AW_DRAW_FN_RENDER_MODE_OPENGL_ES = 0,
187 AW_DRAW_FN_RENDER_MODE_VULKAN = 1,
188};
189
190// Get the render mode. Result is static for the process.
191typedef AwDrawFnRenderMode AwDrawFn_QueryRenderMode(void);
192
193// Create a functor. |functor_callbacks| should be valid until OnDestroyed.
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800194typedef int AwDrawFn_CreateFunctor(void* data,
195 AwDrawFnFunctorCallbacks* functor_callbacks);
Bo Liu788d9572018-12-12 16:08:29 -0800196
197// May be called on any thread to signal that the functor should be destroyed.
198// The functor will receive an onDestroyed when the last usage of it is
199// released, and it should be considered alive & active until that point.
200typedef void AwDrawFn_ReleaseFunctor(int functor);
201
202struct AwDrawFnFunctionTable {
203 int version;
204 AwDrawFn_QueryRenderMode* query_render_mode;
205 AwDrawFn_CreateFunctor* create_functor;
206 AwDrawFn_ReleaseFunctor* release_functor;
207};
208
209#ifdef __cplusplus
210} // extern "C"
211#endif
212
213#endif // ANDROID_WEBVIEW_PUBLIC_BROWSER_DRAW_FN_H_