• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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"
16 
17 #include <vector>
18 
19 class SkExecutor;
20 
21 #if SK_SUPPORT_GPU
22 struct SK_API 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 SK_API 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 
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:
~ShaderErrorHandlerGrContextOptions58         virtual ~ShaderErrorHandler() {}
59         virtual void compileError(const char* shader, const char* errors) = 0;
60     };
61 
GrContextOptionsGrContextOptions62     GrContextOptions() {}
63 
64     // Suppress prints for the GrContext.
65     bool fSuppressPrints = false;
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 
71     int  fMaxTextureSizeOverride = SK_MaxS32;
72 
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. */
76     int  fBufferMapThreshold = -1;
77 
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 
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). */
89     bool fDoManualMipmapping = false;
90 
91     /**
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.
95      */
96     // FIXME: Once this is removed from Chrome and Android, rename to fEnable"".
97     bool fDisableCoverageCountingPaths = true;
98 
99     /**
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     /**
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      */
109     bool fAllowPathMaskCaching = true;
110 
111     /**
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;
116 
117     /**
118      * The maximum size of cache textures used for Skia's Glyph cache.
119      */
120     size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
121 
122     int fPlotOldThreshold = 128;
123     /**
124      * Below this threshold size in device space distance field fonts won't be used. Distance field
125      * fonts don't support hinting which is more important at smaller sizes. A negative value means
126      * use the default threshold.
127      */
128     float fMinDistanceFieldFontSize = -1.f;
129 
130     /**
131      * Above this threshold size in device space glyphs are drawn as individual paths. A negative
132      * value means use the default threshold.
133      */
134     float fGlyphsAsPathsFontSize = -1.f;
135 
136     /**
137      * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by
138      * fGlypheCacheTextureMaximumBytes.
139      */
140     Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault;
141 
142     /**
143      * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid
144      * allocating stencil buffers and use alternate rasterization paths, avoiding the leak.
145      */
146     bool fAvoidStencilBuffers = false;
147 
148     /**
149      * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels.
150      * This has the effect of sharpening those textures, at the cost of some aliasing, and possible
151      * performance impact.
152      */
153     bool fSharpenMipmappedTextures = false;
154 
155     /**
156      * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend.
157      */
158     Enable fUseDrawInsteadOfClear = Enable::kDefault;
159 
160     /**
161      * Allow Ganesh to more aggressively reorder operations.
162      * Eventually this will just be what is done and will not be optional.
163      */
164     Enable fReduceOpListSplitting = Enable::kDefault;
165 
166     /**
167      * Some ES3 contexts report the ES2 external image extension, but not the ES3 version.
168      * If support for external images is critical, enabling this option will cause Ganesh to limit
169      * shaders to the ES2 shading language in that situation.
170      */
171     bool fPreferExternalImagesOverES3 = false;
172 
173     /**
174      * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
175      * This does not affect code path choices that are made for perfomance reasons nor does it
176      * override other GrContextOption settings.
177      */
178     bool fDisableDriverCorrectnessWorkarounds = false;
179 
180     /**
181      * Cache in which to store compiled shader binaries between runs.
182      */
183     PersistentCache* fPersistentCache = nullptr;
184 
185     /**
186      * This affects the usage of the PersistentCache. If this is set to true GLSL shader strings
187      * rather than GL program binaries will be cached. It is intended to be used when the driver's
188      * binary loading/storing is believed to have bugs. Caching GLSL strings still saves a
189      * significant amount of CPU work when a GL program is created.
190      */
191      bool fDisallowGLSLBinaryCaching = false;
192 
193      /**
194       * If present, use this object to report shader compilation failures. If not, report failures
195       * via SkDebugf and assert.
196       */
197      ShaderErrorHandler* fShaderErrorHandler = nullptr;
198 
199     /**
200      * Specifies the number of samples Ganesh should use when performing internal draws with MSAA or
201      * mixed samples (hardware capabilities permitting).
202      *
203      * If 0, Ganesh will disable internal code paths that use multisampling.
204      */
205     int  fInternalMultisampleCount = 4;
206 
207 #if GR_TEST_UTILS
208     /**
209      * Private options that are only meant for testing within Skia's tools.
210      */
211 
212     /**
213      * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered
214      * by SkGpuDevice.
215      */
216     int  fMaxTileSizeOverride = 0;
217 
218     /**
219      * Prevents use of dual source blending, to test that all xfer modes work correctly without it.
220      */
221     bool fSuppressDualSourceBlending = false;
222 
223     /**
224      * If true, the caps will never support geometry shaders.
225      */
226     bool fSuppressGeometryShaders = false;
227 
228     /**
229      * Render everything in wireframe
230      */
231     bool fWireframeMode = false;
232 
233     /**
234      * Similar to fDisallowGLSLBinaryCaching. If set to true, SkSL shader strings will be cached.
235      */
236     bool fCacheSKSL = false;
237 
238     /**
239      * Enforces clearing of all textures when they're created.
240      */
241     bool fClearAllTextures = false;
242 
243     /**
244      * Include or exclude specific GPU path renderers.
245      */
246     GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
247 #endif
248 
249 #if SK_SUPPORT_ATLAS_TEXT
250     /**
251      * Controls whether distance field glyph vertices always have 3 components even when the view
252      * matrix does not have perspective.
253      */
254     Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
255 #endif
256 
257     GrDriverBugWorkarounds fDriverBugWorkarounds;
258 };
259 #else
260 struct GrContextOptions {
261     struct PersistentCache {};
262 };
263 #endif
264 
265 #endif
266