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