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 11 #include "SkData.h" 12 #include "SkTypes.h" 13 #include "GrTypes.h" 14 #include "../private/GrTypesPriv.h" 15 #include "GrDriverBugWorkarounds.h" 16 17 #include <vector> 18 19 class SkExecutor; 20 21 #if SK_SUPPORT_GPU 22 struct GrContextOptions { 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 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 */ 39 class PersistentCache { 40 public: ~PersistentCacheGrContextOptions41 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 GrContextOptionsGrContextOptions51 GrContextOptions() {} 52 53 // Suppress prints for the GrContext. 54 bool fSuppressPrints = false; 55 56 /** Overrides: These options override feature detection using backend API queries. These 57 overrides can only reduce the feature set or limits, never increase them beyond the 58 detected values. */ 59 60 int fMaxTextureSizeOverride = SK_MaxS32; 61 62 /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index 63 buffers to CPU memory in order to update them. A value of -1 means the GrContext should 64 deduce the optimal value for this platform. */ 65 int fBufferMapThreshold = -1; 66 67 /** 68 * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be 69 * done serially on the main thread. To have worker threads assist with various tasks, set this 70 * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used 71 * for other tasks. 72 */ 73 SkExecutor* fExecutor = nullptr; 74 75 /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when 76 the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap 77 level and LOD control (ie desktop or ES3). */ 78 bool fDoManualMipmapping = false; 79 80 /** 81 * Disables the coverage counting path renderer. Coverage counting can sometimes cause new 82 * rendering artifacts along shared edges if care isn't taken to ensure both contours wind in 83 * the same direction. 84 */ 85 bool fDisableCoverageCountingPaths = false; 86 87 /** 88 * Disables distance field rendering for paths. Distance field computation can be expensive, 89 * and yields no benefit if a path is not rendered multiple times with different transforms. 90 */ 91 bool fDisableDistanceFieldPaths = false; 92 93 /** 94 * If true this allows path mask textures to be cached. This is only really useful if paths 95 * are commonly rendered at the same scale and fractional translation. 96 */ 97 bool fAllowPathMaskCaching = true; 98 99 /** 100 * If true, the GPU will not be used to perform YUV -> RGB conversion when generating 101 * textures from codec-backed images. 102 */ 103 bool fDisableGpuYUVConversion = false; 104 105 /** 106 * The maximum size of cache textures used for Skia's Glyph cache. 107 */ 108 size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; 109 110 /** 111 * Below this threshold size in device space distance field fonts won't be used. Distance field 112 * fonts don't support hinting which is more important at smaller sizes. A negative value means 113 * use the default threshold. 114 */ 115 float fMinDistanceFieldFontSize = -1.f; 116 117 /** 118 * Above this threshold size in device space glyphs are drawn as individual paths. A negative 119 * value means use the default threshold. 120 */ 121 float fGlyphsAsPathsFontSize = -1.f; 122 123 /** 124 * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by 125 * fGlypheCacheTextureMaximumBytes. 126 */ 127 Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; 128 129 /** 130 * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid 131 * allocating stencil buffers and use alternate rasterization paths, avoiding the leak. 132 */ 133 bool fAvoidStencilBuffers = false; 134 135 /** 136 * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels. 137 * This has the effect of sharpening those textures, at the cost of some aliasing, and possible 138 * performance impact. 139 */ 140 bool fSharpenMipmappedTextures = false; 141 142 /** 143 * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend. 144 */ 145 Enable fUseDrawInsteadOfClear = Enable::kDefault; 146 147 /** 148 * Allow Ganesh to explicitly allocate resources at flush time rather than incrementally while 149 * drawing. This will eventually just be the way it is but, for now, it is optional. 150 */ 151 Enable fExplicitlyAllocateGPUResources = Enable::kDefault; 152 153 /** 154 * Allow Ganesh to sort the opLists prior to allocating resources. This is an optional 155 * behavior that is only relevant when 'fExplicitlyAllocateGPUResources' is enabled. 156 * Eventually this will just be what is done and will not be optional. 157 */ 158 Enable fSortRenderTargets = Enable::kDefault; 159 160 /** 161 * Allow Ganesh to more aggressively reorder operations. This is an optional 162 * behavior that is only relevant when 'fSortRenderTargets' is enabled. 163 * Eventually this will just be what is done and will not be optional. 164 */ 165 Enable fReduceOpListSplitting = Enable::kDefault; 166 167 /** 168 * Some ES3 contexts report the ES2 external image extension, but not the ES3 version. 169 * If support for external images is critical, enabling this option will cause Ganesh to limit 170 * shaders to the ES2 shading language in that situation. 171 */ 172 bool fPreferExternalImagesOverES3 = false; 173 174 /** 175 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. 176 * This does not affect code path choices that are made for perfomance reasons nor does it 177 * override other GrContextOption settings. 178 */ 179 bool fDisableDriverCorrectnessWorkarounds = false; 180 181 /** 182 * Cache in which to store compiled shader binaries between runs. 183 */ 184 PersistentCache* fPersistentCache = nullptr; 185 186 #if GR_TEST_UTILS 187 /** 188 * Private options that are only meant for testing within Skia's tools. 189 */ 190 191 /** 192 * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered 193 * by SkGpuDevice. 194 */ 195 int fMaxTileSizeOverride = 0; 196 197 /** 198 * Prevents use of dual source blending, to test that all xfer modes work correctly without it. 199 */ 200 bool fSuppressDualSourceBlending = false; 201 202 /** 203 * If true, the caps will never report driver support for path rendering. 204 */ 205 bool fSuppressPathRendering = false; 206 207 /** 208 * If true, the caps will never support geometry shaders. 209 */ 210 bool fSuppressGeometryShaders = false; 211 212 /** 213 * Render everything in wireframe 214 */ 215 bool fWireframeMode = false; 216 217 /** 218 * Include or exclude specific GPU path renderers. 219 */ 220 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll; 221 222 /** 223 * Disables using multiple texture units to batch multiple images into a single draw on 224 * supported GPUs. 225 */ 226 bool fDisableImageMultitexturing = false; 227 #endif 228 229 #if SK_SUPPORT_ATLAS_TEXT 230 /** 231 * Controls whether distance field glyph vertices always have 3 components even when the view 232 * matrix does not have perspective. 233 */ 234 Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault; 235 #endif 236 237 GrDriverBugWorkarounds fDriverBugWorkarounds; 238 }; 239 #else 240 struct GrContextOptions { 241 struct PersistentCache {}; 242 }; 243 #endif 244 245 #endif 246