bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrContextOptions_DEFINED |
| 9 | #define GrContextOptions_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkData.h" |
| 12 | #include "include/core/SkTypes.h" |
| 13 | #include "include/gpu/GrDriverBugWorkarounds.h" |
| 14 | #include "include/gpu/GrTypes.h" |
| 15 | #include "include/private/GrTypesPriv.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 16 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 19 | class SkExecutor; |
| 20 | |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 21 | #if SK_SUPPORT_GPU |
Brian Salomon | f5cdd9b | 2019-02-15 09:39:52 -0500 | [diff] [blame] | 22 | struct SK_API GrContextOptions { |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 23 | enum class Enable { |
| 24 | /** Forces an option to be disabled. */ |
| 25 | kNo, |
| 26 | /** Forces an option to be enabled. */ |
| 27 | kYes, |
| 28 | /** |
| 29 | * Uses Skia's default behavior, which may use runtime properties (e.g. driver version). |
| 30 | */ |
| 31 | kDefault |
| 32 | }; |
| 33 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 34 | /** |
| 35 | * Abstract class which stores Skia data in a cache that persists between sessions. Currently, |
| 36 | * Skia stores compiled shader binaries (only when glProgramBinary / glGetProgramBinary are |
| 37 | * supported) when provided a persistent cache, but this may extend to other data in the future. |
| 38 | */ |
Brian Salomon | f5cdd9b | 2019-02-15 09:39:52 -0500 | [diff] [blame] | 39 | class SK_API PersistentCache { |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 40 | public: |
| 41 | virtual ~PersistentCache() {} |
| 42 | |
| 43 | /** |
| 44 | * Returns the data for the key if it exists in the cache, otherwise returns null. |
| 45 | */ |
| 46 | virtual sk_sp<SkData> load(const SkData& key) = 0; |
| 47 | |
| 48 | virtual void store(const SkData& key, const SkData& data) = 0; |
| 49 | }; |
| 50 | |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 51 | /** |
| 52 | * Abstract class to report errors when compiling shaders. If fShaderErrorHandler is present, |
| 53 | * it will be called to report any compilation failures. Otherwise, failures will be reported |
| 54 | * via SkDebugf and asserts. |
| 55 | */ |
| 56 | class SK_API ShaderErrorHandler { |
| 57 | public: |
| 58 | virtual ~ShaderErrorHandler() {} |
| 59 | virtual void compileError(const char* shader, const char* errors) = 0; |
| 60 | }; |
| 61 | |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 62 | GrContextOptions() {} |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 63 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 64 | // Suppress prints for the GrContext. |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 65 | bool fSuppressPrints = false; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 66 | |
| 67 | /** Overrides: These options override feature detection using backend API queries. These |
| 68 | overrides can only reduce the feature set or limits, never increase them beyond the |
| 69 | detected values. */ |
| 70 | |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 71 | int fMaxTextureSizeOverride = SK_MaxS32; |
| 72 | |
joshualitt | e5b74c6 | 2015-06-01 14:17:47 -0700 | [diff] [blame] | 73 | /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index |
| 74 | buffers to CPU memory in order to update them. A value of -1 means the GrContext should |
| 75 | deduce the optimal value for this platform. */ |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 76 | int fBufferMapThreshold = -1; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 77 | |
Brian Osman | 5127998 | 2017-08-23 10:12:00 -0400 | [diff] [blame] | 78 | /** |
| 79 | * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be |
| 80 | * done serially on the main thread. To have worker threads assist with various tasks, set this |
| 81 | * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used |
| 82 | * for other tasks. |
| 83 | */ |
| 84 | SkExecutor* fExecutor = nullptr; |
| 85 | |
brianosman | 9a3fbf7 | 2016-06-09 13:11:08 -0700 | [diff] [blame] | 86 | /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when |
| 87 | the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap |
| 88 | level and LOD control (ie desktop or ES3). */ |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 89 | bool fDoManualMipmapping = false; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 90 | |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 91 | /** |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 92 | * Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause |
| 93 | * artifacts along shared edges if care isn't taken to ensure both contours wind in the same |
| 94 | * direction. |
Chris Dalton | ef12509 | 2018-06-26 18:16:47 -0600 | [diff] [blame] | 95 | */ |
Chris Dalton | f774818 | 2019-03-18 16:22:30 +0000 | [diff] [blame] | 96 | // FIXME: Once this is removed from Chrome and Android, rename to fEnable"". |
| 97 | bool fDisableCoverageCountingPaths = true; |
Chris Dalton | ef12509 | 2018-06-26 18:16:47 -0600 | [diff] [blame] | 98 | |
| 99 | /** |
Brian Osman | b350ae2 | 2017-08-29 16:15:39 -0400 | [diff] [blame] | 100 | * Disables distance field rendering for paths. Distance field computation can be expensive, |
| 101 | * and yields no benefit if a path is not rendered multiple times with different transforms. |
| 102 | */ |
| 103 | bool fDisableDistanceFieldPaths = false; |
| 104 | |
| 105 | /** |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 106 | * If true this allows path mask textures to be cached. This is only really useful if paths |
| 107 | * are commonly rendered at the same scale and fractional translation. |
| 108 | */ |
Brian Osman | 36dcd7f | 2017-09-27 15:31:29 -0400 | [diff] [blame] | 109 | bool fAllowPathMaskCaching = true; |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
Brian Osman | 46da1cc | 2017-02-14 14:15:48 -0500 | [diff] [blame] | 112 | * If true, the GPU will not be used to perform YUV -> RGB conversion when generating |
| 113 | * textures from codec-backed images. |
| 114 | */ |
| 115 | bool fDisableGpuYUVConversion = false; |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 116 | |
| 117 | /** |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 118 | * The maximum size of cache textures used for Skia's Glyph cache. |
| 119 | */ |
Khushal | fa8ff09 | 2018-06-06 17:46:38 -0700 | [diff] [blame] | 120 | size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 121 | |
| 122 | /** |
Brian Salomon | af59748 | 2017-11-07 16:23:34 -0500 | [diff] [blame] | 123 | * Below this threshold size in device space distance field fonts won't be used. Distance field |
| 124 | * fonts don't support hinting which is more important at smaller sizes. A negative value means |
| 125 | * use the default threshold. |
| 126 | */ |
| 127 | float fMinDistanceFieldFontSize = -1.f; |
| 128 | |
| 129 | /** |
| 130 | * Above this threshold size in device space glyphs are drawn as individual paths. A negative |
| 131 | * value means use the default threshold. |
| 132 | */ |
| 133 | float fGlyphsAsPathsFontSize = -1.f; |
| 134 | |
| 135 | /** |
Brian Salomon | 9f545bc | 2017-11-06 10:36:57 -0500 | [diff] [blame] | 136 | * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by |
| 137 | * fGlypheCacheTextureMaximumBytes. |
| 138 | */ |
| 139 | Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; |
| 140 | |
| 141 | /** |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 142 | * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid |
| 143 | * allocating stencil buffers and use alternate rasterization paths, avoiding the leak. |
| 144 | */ |
| 145 | bool fAvoidStencilBuffers = false; |
| 146 | |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 147 | /** |
Brian Osman | 8a83ca4 | 2018-02-12 14:32:17 -0500 | [diff] [blame] | 148 | * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels. |
| 149 | * This has the effect of sharpening those textures, at the cost of some aliasing, and possible |
| 150 | * performance impact. |
| 151 | */ |
| 152 | bool fSharpenMipmappedTextures = false; |
| 153 | |
| 154 | /** |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 155 | * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend. |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 156 | */ |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 157 | Enable fUseDrawInsteadOfClear = Enable::kDefault; |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 158 | |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 159 | /** |
Robert Phillips | d425dee | 2019-04-26 11:12:24 -0400 | [diff] [blame] | 160 | * Allow Ganesh to more aggressively reorder operations. |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 161 | * Eventually this will just be what is done and will not be optional. |
| 162 | */ |
| 163 | Enable fReduceOpListSplitting = Enable::kDefault; |
| 164 | |
| 165 | /** |
Brian Osman | 06d3746 | 2018-05-08 13:00:42 -0400 | [diff] [blame] | 166 | * Some ES3 contexts report the ES2 external image extension, but not the ES3 version. |
| 167 | * If support for external images is critical, enabling this option will cause Ganesh to limit |
| 168 | * shaders to the ES2 shading language in that situation. |
| 169 | */ |
| 170 | bool fPreferExternalImagesOverES3 = false; |
| 171 | |
| 172 | /** |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 173 | * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. |
| 174 | * This does not affect code path choices that are made for perfomance reasons nor does it |
| 175 | * override other GrContextOption settings. |
| 176 | */ |
| 177 | bool fDisableDriverCorrectnessWorkarounds = false; |
| 178 | |
| 179 | /** |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 180 | * Cache in which to store compiled shader binaries between runs. |
| 181 | */ |
| 182 | PersistentCache* fPersistentCache = nullptr; |
| 183 | |
Brian Salomon | 28bafb0 | 2019-02-15 10:05:06 -0500 | [diff] [blame] | 184 | /** |
| 185 | * This affects the usage of the PersistentCache. If this is set to true GLSL shader strings |
| 186 | * rather than GL program binaries will be cached. It is intended to be used when the driver's |
| 187 | * binary loading/storing is believed to have bugs. Caching GLSL strings still saves a |
| 188 | * significant amount of CPU work when a GL program is created. |
| 189 | */ |
| 190 | bool fDisallowGLSLBinaryCaching = false; |
| 191 | |
Brian Osman | 8518f2e | 2019-05-01 14:13:41 -0400 | [diff] [blame] | 192 | /** |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 193 | * If present, use this object to report shader compilation failures. If not, report failures |
| 194 | * via SkDebugf and assert. |
Brian Osman | 8518f2e | 2019-05-01 14:13:41 -0400 | [diff] [blame] | 195 | */ |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 196 | ShaderErrorHandler* fShaderErrorHandler = nullptr; |
Brian Osman | 8518f2e | 2019-05-01 14:13:41 -0400 | [diff] [blame] | 197 | |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 198 | /** |
| 199 | * Specifies the number of samples Ganesh should use when performing internal draws with MSAA or |
| 200 | * mixed samples (hardware capabilities permitting). |
Chris Dalton | a1638a5 | 2019-06-24 11:54:24 -0600 | [diff] [blame] | 201 | * |
| 202 | * If 0, Ganesh will disable internal code paths that use multisampling. |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 203 | */ |
Chris Dalton | a1638a5 | 2019-06-24 11:54:24 -0600 | [diff] [blame] | 204 | int fInternalMultisampleCount = 4; |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 205 | |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 206 | #if GR_TEST_UTILS |
| 207 | /** |
| 208 | * Private options that are only meant for testing within Skia's tools. |
| 209 | */ |
| 210 | |
| 211 | /** |
| 212 | * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered |
| 213 | * by SkGpuDevice. |
| 214 | */ |
| 215 | int fMaxTileSizeOverride = 0; |
| 216 | |
| 217 | /** |
| 218 | * Prevents use of dual source blending, to test that all xfer modes work correctly without it. |
| 219 | */ |
| 220 | bool fSuppressDualSourceBlending = false; |
| 221 | |
| 222 | /** |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 223 | * If true, the caps will never support geometry shaders. |
| 224 | */ |
| 225 | bool fSuppressGeometryShaders = false; |
| 226 | |
| 227 | /** |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 228 | * Render everything in wireframe |
| 229 | */ |
| 230 | bool fWireframeMode = false; |
| 231 | |
| 232 | /** |
Brian Osman | cbc33b8 | 2019-04-19 14:16:19 -0400 | [diff] [blame] | 233 | * Similar to fDisallowGLSLBinaryCaching. If set to true, SkSL shader strings will be cached. |
| 234 | */ |
| 235 | bool fCacheSKSL = false; |
| 236 | |
| 237 | /** |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame^] | 238 | * Enforces clearing of all textures when they're created. |
| 239 | */ |
| 240 | bool fClearAllTextures = false; |
| 241 | |
| 242 | /** |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 243 | * Include or exclude specific GPU path renderers. |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 244 | */ |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 245 | GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 246 | #endif |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 247 | |
| 248 | #if SK_SUPPORT_ATLAS_TEXT |
| 249 | /** |
| 250 | * Controls whether distance field glyph vertices always have 3 components even when the view |
| 251 | * matrix does not have perspective. |
| 252 | */ |
| 253 | Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault; |
| 254 | #endif |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 255 | |
| 256 | GrDriverBugWorkarounds fDriverBugWorkarounds; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 257 | }; |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 258 | #else |
| 259 | struct GrContextOptions { |
| 260 | struct PersistentCache {}; |
| 261 | }; |
| 262 | #endif |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 263 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 264 | #endif |