GrContextOptions.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. #ifndef GrContextOptions_DEFINED
  8. #define GrContextOptions_DEFINED
  9. #include "include/core/SkData.h"
  10. #include "include/core/SkTypes.h"
  11. #include "include/gpu/GrDriverBugWorkarounds.h"
  12. #include "include/gpu/GrTypes.h"
  13. #include "include/private/GrTypesPriv.h"
  14. #include <vector>
  15. class SkExecutor;
  16. #if SK_SUPPORT_GPU
  17. struct SK_API GrContextOptions {
  18. enum class Enable {
  19. /** Forces an option to be disabled. */
  20. kNo,
  21. /** Forces an option to be enabled. */
  22. kYes,
  23. /**
  24. * Uses Skia's default behavior, which may use runtime properties (e.g. driver version).
  25. */
  26. kDefault
  27. };
  28. /**
  29. * Abstract class which stores Skia data in a cache that persists between sessions. Currently,
  30. * Skia stores compiled shader binaries (only when glProgramBinary / glGetProgramBinary are
  31. * supported) when provided a persistent cache, but this may extend to other data in the future.
  32. */
  33. class SK_API PersistentCache {
  34. public:
  35. virtual ~PersistentCache() {}
  36. /**
  37. * Returns the data for the key if it exists in the cache, otherwise returns null.
  38. */
  39. virtual sk_sp<SkData> load(const SkData& key) = 0;
  40. virtual void store(const SkData& key, const SkData& data) = 0;
  41. };
  42. /**
  43. * Abstract class to report errors when compiling shaders. If fShaderErrorHandler is present,
  44. * it will be called to report any compilation failures. Otherwise, failures will be reported
  45. * via SkDebugf and asserts.
  46. */
  47. class SK_API ShaderErrorHandler {
  48. public:
  49. virtual ~ShaderErrorHandler() {}
  50. virtual void compileError(const char* shader, const char* errors) = 0;
  51. };
  52. GrContextOptions() {}
  53. // Suppress prints for the GrContext.
  54. bool fSuppressPrints = false;
  55. /** Overrides: These options override feature detection using backend API queries. These
  56. overrides can only reduce the feature set or limits, never increase them beyond the
  57. detected values. */
  58. int fMaxTextureSizeOverride = SK_MaxS32;
  59. /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index
  60. buffers to CPU memory in order to update them. A value of -1 means the GrContext should
  61. deduce the optimal value for this platform. */
  62. int fBufferMapThreshold = -1;
  63. /**
  64. * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be
  65. * done serially on the main thread. To have worker threads assist with various tasks, set this
  66. * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used
  67. * for other tasks.
  68. */
  69. SkExecutor* fExecutor = nullptr;
  70. /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when
  71. the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap
  72. level and LOD control (ie desktop or ES3). */
  73. bool fDoManualMipmapping = false;
  74. /**
  75. * Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause
  76. * artifacts along shared edges if care isn't taken to ensure both contours wind in the same
  77. * direction.
  78. */
  79. // FIXME: Once this is removed from Chrome and Android, rename to fEnable"".
  80. bool fDisableCoverageCountingPaths = true;
  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. * If true this allows path mask textures to be cached. This is only really useful if paths
  88. * are commonly rendered at the same scale and fractional translation.
  89. */
  90. bool fAllowPathMaskCaching = true;
  91. /**
  92. * If true, the GPU will not be used to perform YUV -> RGB conversion when generating
  93. * textures from codec-backed images.
  94. */
  95. bool fDisableGpuYUVConversion = false;
  96. /**
  97. * The maximum size of cache textures used for Skia's Glyph cache.
  98. */
  99. size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
  100. /**
  101. * Below this threshold size in device space distance field fonts won't be used. Distance field
  102. * fonts don't support hinting which is more important at smaller sizes. A negative value means
  103. * use the default threshold.
  104. */
  105. float fMinDistanceFieldFontSize = -1.f;
  106. /**
  107. * Above this threshold size in device space glyphs are drawn as individual paths. A negative
  108. * value means use the default threshold.
  109. */
  110. float fGlyphsAsPathsFontSize = -1.f;
  111. /**
  112. * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by
  113. * fGlypheCacheTextureMaximumBytes.
  114. */
  115. Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault;
  116. /**
  117. * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid
  118. * allocating stencil buffers and use alternate rasterization paths, avoiding the leak.
  119. */
  120. bool fAvoidStencilBuffers = false;
  121. /**
  122. * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels.
  123. * This has the effect of sharpening those textures, at the cost of some aliasing, and possible
  124. * performance impact.
  125. */
  126. bool fSharpenMipmappedTextures = false;
  127. /**
  128. * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend.
  129. */
  130. Enable fUseDrawInsteadOfClear = Enable::kDefault;
  131. /**
  132. * Allow Ganesh to more aggressively reorder operations.
  133. * Eventually this will just be what is done and will not be optional.
  134. */
  135. Enable fReduceOpListSplitting = Enable::kDefault;
  136. /**
  137. * Some ES3 contexts report the ES2 external image extension, but not the ES3 version.
  138. * If support for external images is critical, enabling this option will cause Ganesh to limit
  139. * shaders to the ES2 shading language in that situation.
  140. */
  141. bool fPreferExternalImagesOverES3 = false;
  142. /**
  143. * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
  144. * This does not affect code path choices that are made for perfomance reasons nor does it
  145. * override other GrContextOption settings.
  146. */
  147. bool fDisableDriverCorrectnessWorkarounds = false;
  148. /**
  149. * Cache in which to store compiled shader binaries between runs.
  150. */
  151. PersistentCache* fPersistentCache = nullptr;
  152. /**
  153. * This affects the usage of the PersistentCache. If this is set to true GLSL shader strings
  154. * rather than GL program binaries will be cached. It is intended to be used when the driver's
  155. * binary loading/storing is believed to have bugs. Caching GLSL strings still saves a
  156. * significant amount of CPU work when a GL program is created.
  157. */
  158. bool fDisallowGLSLBinaryCaching = false;
  159. /**
  160. * If present, use this object to report shader compilation failures. If not, report failures
  161. * via SkDebugf and assert.
  162. */
  163. ShaderErrorHandler* fShaderErrorHandler = nullptr;
  164. /**
  165. * Specifies the number of samples Ganesh should use when performing internal draws with MSAA or
  166. * mixed samples (hardware capabilities permitting).
  167. *
  168. * If 0, Ganesh will disable internal code paths that use multisampling.
  169. */
  170. int fInternalMultisampleCount = 4;
  171. #if GR_TEST_UTILS
  172. /**
  173. * Private options that are only meant for testing within Skia's tools.
  174. */
  175. /**
  176. * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered
  177. * by SkGpuDevice.
  178. */
  179. int fMaxTileSizeOverride = 0;
  180. /**
  181. * Prevents use of dual source blending, to test that all xfer modes work correctly without it.
  182. */
  183. bool fSuppressDualSourceBlending = false;
  184. /**
  185. * If true, the caps will never support geometry shaders.
  186. */
  187. bool fSuppressGeometryShaders = false;
  188. /**
  189. * Render everything in wireframe
  190. */
  191. bool fWireframeMode = false;
  192. /**
  193. * Similar to fDisallowGLSLBinaryCaching. If set to true, SkSL shader strings will be cached.
  194. */
  195. bool fCacheSKSL = false;
  196. /**
  197. * Enforces clearing of all textures when they're created.
  198. */
  199. bool fClearAllTextures = false;
  200. /**
  201. * Include or exclude specific GPU path renderers.
  202. */
  203. GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
  204. #endif
  205. #if SK_SUPPORT_ATLAS_TEXT
  206. /**
  207. * Controls whether distance field glyph vertices always have 3 components even when the view
  208. * matrix does not have perspective.
  209. */
  210. Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
  211. #endif
  212. GrDriverBugWorkarounds fDriverBugWorkarounds;
  213. };
  214. #else
  215. struct GrContextOptions {
  216. struct PersistentCache {};
  217. };
  218. #endif
  219. #endif