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