blob: 2640d51e1bac319fdafdea451aec19a0e0b60d6a [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"
bsalomon682c2692015-05-22 14:01:46 -070015
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040016#include <vector>
17
Brian Osman51279982017-08-23 10:12:00 -040018class SkExecutor;
19
bsalomon682c2692015-05-22 14:01:46 -070020struct GrContextOptions {
Brian Salomon43f8bf02017-10-18 08:33:29 -040021 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 Nicholasd1b2eec2017-11-01 15:45:43 -040032 /**
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 Kleinfc6c37b2016-09-27 09:34:10 -040049 GrContextOptions() {}
bsalomon682c2692015-05-22 14:01:46 -070050
bsalomon682c2692015-05-22 14:01:46 -070051 // Suppress prints for the GrContext.
bsalomon6b2552f2016-09-15 13:50:26 -070052 bool fSuppressPrints = false;
bsalomon4ee6bd82015-05-27 13:23:23 -070053
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
bsalomon6b2552f2016-09-15 13:50:26 -070058 int fMaxTextureSizeOverride = SK_MaxS32;
59
joshualitte5b74c62015-06-01 14:17:47 -070060 /** 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. */
bsalomon6b2552f2016-09-15 13:50:26 -070063 int fBufferMapThreshold = -1;
joshualitt83bc2292015-06-18 14:18:02 -070064
Brian Osman51279982017-08-23 10:12:00 -040065 /**
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
joshualitt83bc2292015-06-18 14:18:02 -070073 /** some gpus have problems with partial writes of the rendertarget */
bsalomon6b2552f2016-09-15 13:50:26 -070074 bool fUseDrawInsteadOfPartialRenderTargetWrite = false;
bsalomon648c6962015-10-23 09:06:59 -070075
brianosman9a3fbf72016-06-09 13:11:08 -070076 /** 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). */
bsalomon6b2552f2016-09-15 13:50:26 -070079 bool fDoManualMipmapping = false;
csmartdaltone0d36292016-07-29 08:14:20 -070080
bsalomon39ef7fb2016-09-21 11:16:05 -070081 /**
Brian Osmanb350ae22017-08-29 16:15:39 -040082 * 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 /**
bsalomon39ef7fb2016-09-21 11:16:05 -070088 * 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 */
Brian Osman36dcd7f2017-09-27 15:31:29 -040091 bool fAllowPathMaskCaching = true;
bsalomon39ef7fb2016-09-21 11:16:05 -070092
93 /**
brianosman20471892016-12-02 06:43:32 -080094 * 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;
Brian Osman46da1cc2017-02-14 14:15:48 -0500100
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;
csmartdalton008b9d82017-02-22 12:00:42 -0700106
107 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400108 * The maximum size of cache textures used for Skia's Glyph cache.
109 */
110 float fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
111
112 /**
Brian Salomonaf597482017-11-07 16:23:34 -0500113 * 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 /**
Brian Salomon9f545bc2017-11-06 10:36:57 -0500126 * 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 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400132 * 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
Brian Salomon43f8bf02017-10-18 08:33:29 -0400137 /**
138 * Enables driver workaround to use draws instead of glClear. This only applies to
139 * kOpenGL_GrBackend.
140 */
141 Enable fUseDrawInsteadOfGLClear = Enable::kDefault;
142
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400143 /**
144 * Cache in which to store compiled shader binaries between runs.
145 */
146 PersistentCache* fPersistentCache = nullptr;
147
Brian Osman195c05b2017-08-30 15:14:04 -0400148#if GR_TEST_UTILS
149 /**
150 * Private options that are only meant for testing within Skia's tools.
151 */
152
153 /**
154 * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered
155 * by SkGpuDevice.
156 */
157 int fMaxTileSizeOverride = 0;
158
159 /**
160 * Prevents use of dual source blending, to test that all xfer modes work correctly without it.
161 */
162 bool fSuppressDualSourceBlending = false;
163
164 /**
csmartdalton008b9d82017-02-22 12:00:42 -0700165 * If true, the caps will never report driver support for path rendering.
166 */
167 bool fSuppressPathRendering = false;
168
169 /**
Chris Dalton040238b2017-12-18 14:22:34 -0700170 * If true, the caps will never support geometry shaders.
171 */
172 bool fSuppressGeometryShaders = false;
173
174 /**
Jim Van Verthfbdc0802017-05-02 16:15:53 -0400175 * Render everything in wireframe
176 */
177 bool fWireframeMode = false;
178
179 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400180 * Include or exclude specific GPU path renderers.
csmartdalton008b9d82017-02-22 12:00:42 -0700181 */
Brian Osman8b0f2652017-08-29 15:18:34 -0400182 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
Brian Salomon0b4d8aa2017-10-11 15:34:27 -0400183
184 /**
185 * Disables using multiple texture units to batch multiple images into a single draw on
186 * supported GPUs.
187 */
188 bool fDisableImageMultitexturing = false;
Brian Osman195c05b2017-08-30 15:14:04 -0400189#endif
Brian Salomonb5086962017-12-13 10:59:33 -0500190
191#if SK_SUPPORT_ATLAS_TEXT
192 /**
193 * Controls whether distance field glyph vertices always have 3 components even when the view
194 * matrix does not have perspective.
195 */
196 Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
197#endif
bsalomon682c2692015-05-22 14:01:46 -0700198};
199
bsalomon682c2692015-05-22 14:01:46 -0700200#endif