1 | use std::os::raw; |
2 | |
3 | use skia_bindings::{self as sb, GrContextOptions}; |
4 | |
5 | use crate::{gpu::DriverBugWorkarounds, prelude::*}; |
6 | |
7 | pub use skia_bindings::GrContextOptions_Enable as Enable; |
8 | variant_name!(Enable::Yes); |
9 | |
10 | pub use skia_bindings::GrContextOptions_ShaderCacheStrategy as ShaderCacheStrategy; |
11 | variant_name!(ShaderCacheStrategy::BackendSource); |
12 | |
13 | #[repr (C)] |
14 | #[derive (Debug)] |
15 | pub struct ContextOptions { |
16 | // Suppress prints for the GrContext. |
17 | pub suppress_prints: bool, |
18 | |
19 | /// Controls whether we check for GL errors after functions that allocate resources (e.g. |
20 | /// `glTexImage2d`), at the end of a GPU submission, or checking framebuffer completeness. The |
21 | /// results of shader compilation and program linking are always checked, regardless of this |
22 | /// option. Ignored on backends other than GL. |
23 | pub skip_gl_error_checks: Enable, |
24 | |
25 | /// Overrides: These options override feature detection using backend API queries. These |
26 | /// overrides can only reduce the feature set or limits, never increase them beyond the detected |
27 | /// values. |
28 | pub max_texture_size_override: raw::c_int, |
29 | |
30 | /// The threshold in bytes above which we will use a buffer mapping API to map vertex and index |
31 | /// buffers to CPU memory in order to update them. A value of -1 means the `Context` should |
32 | /// deduce the optimal value for this platform. |
33 | pub buffer_map_threshold: raw::c_int, |
34 | |
35 | /// Default minimum size to use when allocating buffers for uploading data to textures. The |
36 | /// larger the value the more uploads can be packed into one buffer, but at the cost of |
37 | /// more gpu memory allocated that may not be used. Uploads larger than the minimum will still |
38 | /// work by allocating a dedicated buffer. |
39 | pub minimum_staging_buffer_size: usize, |
40 | |
41 | executor: *mut sb::SkExecutor, |
42 | |
43 | /// Construct mipmaps manually, via repeated downsampling draw-calls. This is used when |
44 | /// the driver's implementation (`gl_generate_mipmap`) contains bugs. This requires mipmap |
45 | /// level control (ie desktop or ES3). |
46 | pub do_manual_mipmapping: bool, |
47 | |
48 | /// Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause |
49 | /// artifacts along shared edges if care isn't taken to ensure both contours wind in the same |
50 | /// direction. |
51 | pub disable_coverage_counting_paths: bool, |
52 | |
53 | /// Disables distance field rendering for paths. Distance field computation can be expensive, |
54 | /// and yields no benefit if a path is not rendered multiple times with different transforms. |
55 | pub disable_distance_field_paths: bool, |
56 | |
57 | /// If `true` this allows path mask textures to be cached. This is only really useful if paths |
58 | /// are commonly rendered at the same scale and fractional translation. |
59 | pub allow_path_mask_caching: bool, |
60 | |
61 | /// If `true`, the GPU will not be used to perform YUV -> RGB conversion when generating |
62 | /// textures from codec-backed images. |
63 | pub disable_gpu_yuv_conversion: bool, |
64 | |
65 | /// The maximum size of cache textures used for Skia's Glyph cache. |
66 | pub glyph_cache_texture_maximum_bytes: usize, |
67 | |
68 | /// Below this threshold size in device space distance field fonts won't be used. Distance field |
69 | /// fonts don't support hinting which is more important at smaller sizes. |
70 | pub min_distance_field_font_size: f32, |
71 | |
72 | /// Above this threshold size in device space glyphs are drawn as individual paths. |
73 | pub glyphs_as_paths_font_size: f32, |
74 | |
75 | /// Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by |
76 | /// `glyph_cache_texture_maximum_bytes`. |
77 | pub allow_multiple_glyph_cache_textures: Enable, |
78 | |
79 | /// Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid |
80 | /// allocating stencil buffers and use alternate rasterization paths, avoiding the leak. |
81 | pub avoid_stencil_buffers: bool, |
82 | |
83 | /// Enables driver workaround to use draws instead of HW clears, e.g. `glClear` on the GL |
84 | /// backend. |
85 | pub use_draw_instead_of_clear: Enable, |
86 | |
87 | /// Allow Ganesh to more aggressively reorder operations to reduce the number of render passes. |
88 | /// Offscreen draws will be done upfront instead of interrupting the main render pass when |
89 | /// possible. May increase VRAM usage, but still observes the resource cache limit. |
90 | /// |
91 | /// Enabled by default. |
92 | pub reduce_ops_task_splitting: Enable, |
93 | |
94 | /// Some ES3 contexts report the ES2 external image extension, but not the ES3 version. |
95 | /// If support for external images is critical, enabling this option will cause Ganesh to limit |
96 | /// shaders to the ES2 shading language in that situation. |
97 | pub prefer_external_images_over_es3: bool, |
98 | |
99 | /// Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. |
100 | /// This does not affect code path choices that are made for performance reasons nor does it |
101 | /// override other [`ContextOptions`] settings. |
102 | pub disable_driver_correctness_workarounds: bool, |
103 | |
104 | /// Maximum number of GPU programs or pipelines to keep active in the runtime cache. |
105 | pub runtime_program_cache_size: raw::c_int, |
106 | |
107 | /// Cache in which to store compiled shader binaries between runs. |
108 | persistent_cache: *mut sb::GrContextOptions_PersistentCache, |
109 | |
110 | /// This affects the usage of the PersistentCache. We can cache `SL`, backend source (GLSL), or |
111 | /// backend binaries (GL program binaries). By default we cache binaries, but if the driver's |
112 | /// binary loading/storing is believed to have bugs, this can be limited to caching GLSL. |
113 | /// Caching GLSL strings still saves CPU work when a GL program is created. |
114 | pub shader_cache_strategy: ShaderCacheStrategy, |
115 | |
116 | /// If present, use this object to report shader compilation failures. If not, report failures |
117 | /// via [`Debugf`] and assert. |
118 | shader_error_handler: *mut sb::GrContextOptions_ShaderErrorHandler, |
119 | |
120 | /// Specifies the number of samples Ganesh should use when performing internal draws with MSAA |
121 | /// (hardware capabilities permitting). |
122 | /// |
123 | /// If 0, Ganesh will disable internal code paths that use multisampling. |
124 | pub internal_multisample_count: raw::c_int, |
125 | |
126 | /// In Skia's vulkan backend a single `Context` submit equates to the submission of a single |
127 | /// primary command buffer to the VkQueue. This value specifies how many vulkan secondary command |
128 | /// buffers we will cache for reuse on a given primary command buffer. A single submit may use |
129 | /// more than this many secondary command buffers, but after the primary command buffer is |
130 | /// finished on the GPU it will only hold on to this many secondary command buffers for reuse. |
131 | /// |
132 | /// A value of -1 means we will pick a limit value internally. |
133 | pub max_cached_vulkan_secondary_command_buffers: raw::c_int, |
134 | |
135 | /// If `true`, the caps will never support mipmaps. |
136 | pub suppress_mipmap_support: bool, |
137 | |
138 | /// If `true`, the TessellationPathRenderer will not be used for path rendering. |
139 | /// If `false`, will fallback to any driver workarounds, if set. |
140 | pub disable_tessellation_path_renderer: bool, |
141 | |
142 | /// If `true`, and if supported, enables hardware tessellation in the caps. |
143 | /// DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled. |
144 | pub enable_experimental_hardware_tessellation: bool, |
145 | |
146 | /// If `true`, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp |
147 | /// rendering of all glyphs. This must be set to `true` to use Slugs. |
148 | pub support_bilerp_from_glyph_atlas: bool, |
149 | |
150 | /// Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce |
151 | /// jank due to shader compilations. |
152 | pub reduced_shader_variations: bool, |
153 | |
154 | /// If `true`, then allow to enable MSAA on new Intel GPUs. |
155 | pub allow_msaa_on_new_intel: bool, |
156 | |
157 | /// Currently on ARM Android we disable the use of GL TexStorage because of memory regressions. |
158 | /// However, some clients may still want to use TexStorage. For example, TexStorage support is |
159 | /// required for creating protected textures. |
160 | /// |
161 | /// This flag has no impact on non GL backends. |
162 | pub always_use_text_storage_when_available: bool, |
163 | |
164 | /// Optional callback that can be passed into the [`DirectContext`] which will be called when the |
165 | /// [`DirectContext`] is about to be destroyed. When this call is made, it will be safe for the |
166 | /// client to delete the GPU backend context that is backing the [`DirectContext`]. The |
167 | /// [`DirectContextDestroyedContext`] will be passed back to the client in the callback. |
168 | context_delete_context: sb::GrDirectContextDestroyedContext, |
169 | context_delete_proc: sb::GrDirectContextDestroyedProc, |
170 | pub driver_bug_workarounds: DriverBugWorkarounds, |
171 | } |
172 | unsafe_send_sync!(ContextOptions); |
173 | |
174 | impl Default for ContextOptions { |
175 | fn default() -> Self { |
176 | Self::construct(|ptr: *mut GrContextOptions| unsafe { sb::C_GrContextOptions_Construct(uninitialized:ptr) }) |
177 | } |
178 | } |
179 | |
180 | impl ContextOptions { |
181 | pub fn new() -> Self { |
182 | Self::default() |
183 | } |
184 | } |
185 | |
186 | native_transmutable!(GrContextOptions, ContextOptions, context_options_layout); |
187 | |
188 | // TODO: PersistentCache, ShaderErrorHandler |
189 | |