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 16#include <vector> 17 18class SkExecutor; 19 20struct GrContextOptions { 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 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 49 GrContextOptions() {} 50 51 // Suppress prints for the GrContext. 52 bool fSuppressPrints = false; 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 58 int fMaxTextureSizeOverride = SK_MaxS32; 59 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. */ 63 int fBufferMapThreshold = -1; 64 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 73 /** some gpus have problems with partial writes of the rendertarget */ 74 bool fUseDrawInsteadOfPartialRenderTargetWrite = false; 75 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). */ 79 bool fDoManualMipmapping = false; 80 81 /** 82 * Disables distance field rendering for paths. Distance field computation can be expensive, 83 * and yields no benefit if a path is not rendered multiple times with different transforms. 84 */ 85 bool fDisableDistanceFieldPaths = false; 86 87 /** 88 * If true this allows path mask textures to be cached. This is only really useful if paths 89 * are commonly rendered at the same scale and fractional translation. 90 */ 91 bool fAllowPathMaskCaching = true; 92 93 /** 94 * If true, sRGB support will not be enabled unless sRGB decoding can be disabled (via an 95 * extension). If mixed use of "legacy" mode and sRGB/color-correct mode is not required, this 96 * can be set to false, which will significantly expand the number of devices that qualify for 97 * sRGB support. 98 */ 99 bool fRequireDecodeDisableForSRGB = true; 100 101 /** 102 * If true, the GPU will not be used to perform YUV -> RGB conversion when generating 103 * textures from codec-backed images. 104 */ 105 bool fDisableGpuYUVConversion = false; 106 107 /** 108 * The maximum size of cache textures used for Skia's Glyph cache. 109 */ 110 float fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; 111 112 /** 113 * Below this threshold size in device space distance field fonts won't be used. Distance field 114 * fonts don't support hinting which is more important at smaller sizes. A negative value means 115 * use the default threshold. 116 */ 117 float fMinDistanceFieldFontSize = -1.f; 118 119 /** 120 * Above this threshold size in device space glyphs are drawn as individual paths. A negative 121 * value means use the default threshold. 122 */ 123 float fGlyphsAsPathsFontSize = -1.f; 124 125 /** 126 * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by 127 * fGlypheCacheTextureMaximumBytes. 128 */ 129 Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; 130 131 /** 132 * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid 133 * allocating stencil buffers and use alternate rasterization paths, avoiding the leak. 134 */ 135 bool fAvoidStencilBuffers = false; 136 137 /** 138 * Enables driver workaround to use draws instead of glClear. This only applies to 139 * kOpenGL_GrBackend. 140 */ 141 Enable fUseDrawInsteadOfGLClear = Enable::kDefault; 142 143 /** 144 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. 145 * This does not affect code path choices that are made for perfomance reasons nor does it 146 * override other GrContextOption settings. 147 */ 148 bool fDisableDriverCorrectnessWorkarounds = false; 149 150 /** 151 * Cache in which to store compiled shader binaries between runs. 152 */ 153 PersistentCache* fPersistentCache = nullptr; 154 155#if GR_TEST_UTILS 156 /** 157 * Private options that are only meant for testing within Skia's tools. 158 */ 159 160 /** 161 * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered 162 * by SkGpuDevice. 163 */ 164 int fMaxTileSizeOverride = 0; 165 166 /** 167 * Prevents use of dual source blending, to test that all xfer modes work correctly without it. 168 */ 169 bool fSuppressDualSourceBlending = false; 170 171 /** 172 * If true, the caps will never report driver support for path rendering. 173 */ 174 bool fSuppressPathRendering = false; 175 176 /** 177 * If true, the caps will never support geometry shaders. 178 */ 179 bool fSuppressGeometryShaders = false; 180 181 /** 182 * Render everything in wireframe 183 */ 184 bool fWireframeMode = false; 185 186 /** 187 * Include or exclude specific GPU path renderers. 188 */ 189 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; 190 191 /** 192 * Disables using multiple texture units to batch multiple images into a single draw on 193 * supported GPUs. 194 */ 195 bool fDisableImageMultitexturing = false; 196#endif 197 198#if SK_SUPPORT_ATLAS_TEXT 199 /** 200 * Controls whether distance field glyph vertices always have 3 components even when the view 201 * matrix does not have perspective. 202 */ 203 Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault; 204#endif 205}; 206 207#endif 208