GrContextOptions.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 "SkData.h"
  10. #include "SkTypes.h"
  11. #include "GrTypes.h"
  12. #include "../private/GrTypesPriv.h"
  13. #include "GrDriverBugWorkarounds.h"
  14. #include <vector>
  15. class SkExecutor;
  16. #if SK_SUPPORT_GPU
  17. struct 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 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. GrContextOptions() {}
  43. // Suppress prints for the GrContext.
  44. bool fSuppressPrints = false;
  45. /** Overrides: These options override feature detection using backend API queries. These
  46. overrides can only reduce the feature set or limits, never increase them beyond the
  47. detected values. */
  48. int fMaxTextureSizeOverride = SK_MaxS32;
  49. /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index
  50. buffers to CPU memory in order to update them. A value of -1 means the GrContext should
  51. deduce the optimal value for this platform. */
  52. int fBufferMapThreshold = -1;
  53. /**
  54. * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be
  55. * done serially on the main thread. To have worker threads assist with various tasks, set this
  56. * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used
  57. * for other tasks.
  58. */
  59. SkExecutor* fExecutor = nullptr;
  60. /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when
  61. the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap
  62. level and LOD control (ie desktop or ES3). */
  63. bool fDoManualMipmapping = false;
  64. /**
  65. * Disables the coverage counting path renderer. Coverage counting can sometimes cause new
  66. * rendering artifacts along shared edges if care isn't taken to ensure both contours wind in
  67. * the same direction.
  68. */
  69. bool fDisableCoverageCountingPaths = false;
  70. /**
  71. * Disables distance field rendering for paths. Distance field computation can be expensive,
  72. * and yields no benefit if a path is not rendered multiple times with different transforms.
  73. */
  74. bool fDisableDistanceFieldPaths = false;
  75. /**
  76. * If true this allows path mask textures to be cached. This is only really useful if paths
  77. * are commonly rendered at the same scale and fractional translation.
  78. */
  79. bool fAllowPathMaskCaching = true;
  80. /**
  81. * If true, the GPU will not be used to perform YUV -> RGB conversion when generating
  82. * textures from codec-backed images.
  83. */
  84. bool fDisableGpuYUVConversion = false;
  85. /**
  86. * The maximum size of cache textures used for Skia's Glyph cache.
  87. */
  88. size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
  89. /**
  90. * Below this threshold size in device space distance field fonts won't be used. Distance field
  91. * fonts don't support hinting which is more important at smaller sizes. A negative value means
  92. * use the default threshold.
  93. */
  94. float fMinDistanceFieldFontSize = -1.f;
  95. /**
  96. * Above this threshold size in device space glyphs are drawn as individual paths. A negative
  97. * value means use the default threshold.
  98. */
  99. float fGlyphsAsPathsFontSize = -1.f;
  100. /**
  101. * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by
  102. * fGlypheCacheTextureMaximumBytes.
  103. */
  104. Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault;
  105. /**
  106. * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid
  107. * allocating stencil buffers and use alternate rasterization paths, avoiding the leak.
  108. */
  109. bool fAvoidStencilBuffers = false;
  110. /**
  111. * When specifing new data for a vertex/index buffer that replaces old data Ganesh can give
  112. * a hint to the driver that the previous data will not be used in future draws like this:
  113. * glBufferData(GL_..._BUFFER, size, NULL, usage); //<--hint, NULL means
  114. * glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) // old data can't be
  115. * // used again.
  116. * However, this can be an unoptimization on some platforms, esp. Chrome.
  117. * Chrome's cmd buffer will create a new allocation and memset the whole thing
  118. * to zero (for security reasons).
  119. * Defaults to the value of GR_GL_USE_BUFFER_DATA_NULL_HINT #define (which is, by default, 1).
  120. */
  121. Enable fUseGLBufferDataNullHint = Enable::kDefault;
  122. /**
  123. * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels.
  124. * This has the effect of sharpening those textures, at the cost of some aliasing, and possible
  125. * performance impact.
  126. */
  127. bool fSharpenMipmappedTextures = false;
  128. /**
  129. * Enables driver workaround to use draws instead of glClear. This only applies to
  130. * GrBackendApi::kOpenGL.
  131. */
  132. Enable fUseDrawInsteadOfGLClear = Enable::kDefault;
  133. /**
  134. * Allow Ganesh to explicitly allocate resources at flush time rather than incrementally while
  135. * drawing. This will eventually just be the way it is but, for now, it is optional.
  136. */
  137. Enable fExplicitlyAllocateGPUResources = Enable::kDefault;
  138. /**
  139. * Allow Ganesh to sort the opLists prior to allocating resources. This is an optional
  140. * behavior that is only relevant when 'fExplicitlyAllocateGPUResources' is enabled.
  141. * Eventually this will just be what is done and will not be optional.
  142. */
  143. Enable fSortRenderTargets = Enable::kDefault;
  144. /**
  145. * Allow Ganesh to more aggressively reorder operations. This is an optional
  146. * behavior that is only relevant when 'fSortRenderTargets' is enabled.
  147. * Eventually this will just be what is done and will not be optional.
  148. */
  149. Enable fReduceOpListSplitting = Enable::kDefault;
  150. /**
  151. * Some ES3 contexts report the ES2 external image extension, but not the ES3 version.
  152. * If support for external images is critical, enabling this option will cause Ganesh to limit
  153. * shaders to the ES2 shading language in that situation.
  154. */
  155. bool fPreferExternalImagesOverES3 = false;
  156. /**
  157. * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
  158. * This does not affect code path choices that are made for perfomance reasons nor does it
  159. * override other GrContextOption settings.
  160. */
  161. bool fDisableDriverCorrectnessWorkarounds = false;
  162. /**
  163. * Cache in which to store compiled shader binaries between runs.
  164. */
  165. PersistentCache* fPersistentCache = nullptr;
  166. #if GR_TEST_UTILS
  167. /**
  168. * Private options that are only meant for testing within Skia's tools.
  169. */
  170. /**
  171. * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered
  172. * by SkGpuDevice.
  173. */
  174. int fMaxTileSizeOverride = 0;
  175. /**
  176. * Prevents use of dual source blending, to test that all xfer modes work correctly without it.
  177. */
  178. bool fSuppressDualSourceBlending = false;
  179. /**
  180. * If true, the caps will never report driver support for path rendering.
  181. */
  182. bool fSuppressPathRendering = false;
  183. /**
  184. * If true, the caps will never support geometry shaders.
  185. */
  186. bool fSuppressGeometryShaders = false;
  187. /**
  188. * Render everything in wireframe
  189. */
  190. bool fWireframeMode = false;
  191. /**
  192. * Include or exclude specific GPU path renderers.
  193. */
  194. GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
  195. /**
  196. * Disables using multiple texture units to batch multiple images into a single draw on
  197. * supported GPUs.
  198. */
  199. bool fDisableImageMultitexturing = false;
  200. #endif
  201. #if SK_SUPPORT_ATLAS_TEXT
  202. /**
  203. * Controls whether distance field glyph vertices always have 3 components even when the view
  204. * matrix does not have perspective.
  205. */
  206. Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
  207. #endif
  208. GrDriverBugWorkarounds fDriverBugWorkarounds;
  209. };
  210. #else
  211. struct GrContextOptions {
  212. struct PersistentCache {};
  213. };
  214. #endif
  215. #endif