blob: d2377a570ba5a42f2202a08dc5c9aa08f1e68c25 [file] [log] [blame]
bsalomon682c2692015-05-22 14:01:46 -07001/*
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 Nicholasd1b2eec2017-11-01 15:45:43 -040011#include "SkData.h"
bsalomon682c2692015-05-22 14:01:46 -070012#include "SkTypes.h"
csmartdalton008b9d82017-02-22 12:00:42 -070013#include "GrTypes.h"
Brian Osman195c05b2017-08-30 15:14:04 -040014#include "../private/GrTypesPriv.h"
Adrienne Walkerab7181d2018-05-14 14:02:03 -070015#include "GrDriverBugWorkarounds.h"
bsalomon682c2692015-05-22 14:01:46 -070016
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040017#include <vector>
18
Brian Osman51279982017-08-23 10:12:00 -040019class SkExecutor;
20
Adrienne Walkerab7181d2018-05-14 14:02:03 -070021#if SK_SUPPORT_GPU
bsalomon682c2692015-05-22 14:01:46 -070022struct GrContextOptions {
Brian Salomon43f8bf02017-10-18 08:33:29 -040023 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
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040034 /**
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:
41 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
Mike Kleinfc6c37b2016-09-27 09:34:10 -040051 GrContextOptions() {}
bsalomon682c2692015-05-22 14:01:46 -070052
bsalomon682c2692015-05-22 14:01:46 -070053 // Suppress prints for the GrContext.
bsalomon6b2552f2016-09-15 13:50:26 -070054 bool fSuppressPrints = false;
bsalomon4ee6bd82015-05-27 13:23:23 -070055
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
bsalomon6b2552f2016-09-15 13:50:26 -070060 int fMaxTextureSizeOverride = SK_MaxS32;
61
joshualitte5b74c62015-06-01 14:17:47 -070062 /** 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. */
bsalomon6b2552f2016-09-15 13:50:26 -070065 int fBufferMapThreshold = -1;
joshualitt83bc2292015-06-18 14:18:02 -070066
Brian Osman51279982017-08-23 10:12:00 -040067 /**
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
brianosman9a3fbf72016-06-09 13:11:08 -070075 /** 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). */
bsalomon6b2552f2016-09-15 13:50:26 -070078 bool fDoManualMipmapping = false;
csmartdaltone0d36292016-07-29 08:14:20 -070079
bsalomon39ef7fb2016-09-21 11:16:05 -070080 /**
Chris Daltonef125092018-06-26 18:16:47 -060081 * 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 /**
Brian Osmanb350ae22017-08-29 16:15:39 -040088 * 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 /**
bsalomon39ef7fb2016-09-21 11:16:05 -070094 * 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 */
Brian Osman36dcd7f2017-09-27 15:31:29 -040097 bool fAllowPathMaskCaching = true;
bsalomon39ef7fb2016-09-21 11:16:05 -070098
99 /**
Brian Osman46da1cc2017-02-14 14:15:48 -0500100 * 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;
csmartdalton008b9d82017-02-22 12:00:42 -0700104
105 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400106 * The maximum size of cache textures used for Skia's Glyph cache.
107 */
Khushalfa8ff092018-06-06 17:46:38 -0700108 size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
Brian Osman195c05b2017-08-30 15:14:04 -0400109
110 /**
Brian Salomonaf597482017-11-07 16:23:34 -0500111 * 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 /**
Brian Salomon9f545bc2017-11-06 10:36:57 -0500124 * 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 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400130 * 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
Brian Salomon43f8bf02017-10-18 08:33:29 -0400135 /**
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500136 * When specifing new data for a vertex/index buffer that replaces old data Ganesh can give
137 * a hint to the driver that the previous data will not be used in future draws like this:
138 * glBufferData(GL_..._BUFFER, size, NULL, usage); //<--hint, NULL means
139 * glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) // old data can't be
140 * // used again.
141 * However, this can be an unoptimization on some platforms, esp. Chrome.
142 * Chrome's cmd buffer will create a new allocation and memset the whole thing
143 * to zero (for security reasons).
144 * Defaults to the value of GR_GL_USE_BUFFER_DATA_NULL_HINT #define (which is, by default, 1).
145 */
146 Enable fUseGLBufferDataNullHint = Enable::kDefault;
147
148 /**
Brian Osman8a83ca42018-02-12 14:32:17 -0500149 * 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 /**
Brian Salomon43f8bf02017-10-18 08:33:29 -0400156 * Enables driver workaround to use draws instead of glClear. This only applies to
157 * kOpenGL_GrBackend.
158 */
159 Enable fUseDrawInsteadOfGLClear = Enable::kDefault;
160
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400161 /**
Robert Phillips4150eea2018-02-07 17:08:21 -0500162 * Allow Ganesh to explicitly allocate resources at flush time rather than incrementally while
163 * drawing. This will eventually just be the way it is but, for now, it is optional.
164 */
Robert Phillipsa3f70262018-02-08 10:59:38 -0500165 Enable fExplicitlyAllocateGPUResources = Enable::kDefault;
Robert Phillips4150eea2018-02-07 17:08:21 -0500166
167 /**
168 * Allow Ganesh to sort the opLists prior to allocating resources. This is an optional
169 * behavior that is only relevant when 'fExplicitlyAllocateGPUResources' is enabled.
170 * Eventually this will just be what is done and will not be optional.
171 */
Robert Phillipsa3f70262018-02-08 10:59:38 -0500172 Enable fSortRenderTargets = Enable::kDefault;
Robert Phillips4150eea2018-02-07 17:08:21 -0500173
174 /**
Brian Osman06d37462018-05-08 13:00:42 -0400175 * Some ES3 contexts report the ES2 external image extension, but not the ES3 version.
176 * If support for external images is critical, enabling this option will cause Ganesh to limit
177 * shaders to the ES2 shading language in that situation.
178 */
179 bool fPreferExternalImagesOverES3 = false;
180
181 /**
Brian Salomon01b476a2018-01-23 11:06:41 -0500182 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
183 * This does not affect code path choices that are made for perfomance reasons nor does it
184 * override other GrContextOption settings.
185 */
186 bool fDisableDriverCorrectnessWorkarounds = false;
187
188 /**
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400189 * Cache in which to store compiled shader binaries between runs.
190 */
191 PersistentCache* fPersistentCache = nullptr;
192
Brian Osman195c05b2017-08-30 15:14:04 -0400193#if GR_TEST_UTILS
194 /**
195 * Private options that are only meant for testing within Skia's tools.
196 */
197
198 /**
199 * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered
200 * by SkGpuDevice.
201 */
202 int fMaxTileSizeOverride = 0;
203
204 /**
205 * Prevents use of dual source blending, to test that all xfer modes work correctly without it.
206 */
207 bool fSuppressDualSourceBlending = false;
208
209 /**
csmartdalton008b9d82017-02-22 12:00:42 -0700210 * If true, the caps will never report driver support for path rendering.
211 */
212 bool fSuppressPathRendering = false;
213
214 /**
Chris Dalton040238b2017-12-18 14:22:34 -0700215 * If true, the caps will never support geometry shaders.
216 */
217 bool fSuppressGeometryShaders = false;
218
219 /**
Jim Van Verthfbdc0802017-05-02 16:15:53 -0400220 * Render everything in wireframe
221 */
222 bool fWireframeMode = false;
223
224 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400225 * Include or exclude specific GPU path renderers.
csmartdalton008b9d82017-02-22 12:00:42 -0700226 */
Brian Osman8b0f2652017-08-29 15:18:34 -0400227 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400228
229 /**
230 * Disables using multiple texture units to batch multiple images into a single draw on
231 * supported GPUs.
232 */
233 bool fDisableImageMultitexturing = false;
Brian Osman195c05b2017-08-30 15:14:04 -0400234#endif
Brian Salomonb5086962017-12-13 10:59:33 -0500235
236#if SK_SUPPORT_ATLAS_TEXT
237 /**
238 * Controls whether distance field glyph vertices always have 3 components even when the view
239 * matrix does not have perspective.
240 */
241 Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
242#endif
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700243
244 GrDriverBugWorkarounds fDriverBugWorkarounds;
bsalomon682c2692015-05-22 14:01:46 -0700245};
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700246#else
247struct GrContextOptions {
248 struct PersistentCache {};
249};
250#endif
bsalomon682c2692015-05-22 14:01:46 -0700251
bsalomon682c2692015-05-22 14:01:46 -0700252#endif