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