| 1 |  | 
|---|
| 2 | /* | 
|---|
| 3 | * Copyright 2013 Google Inc. | 
|---|
| 4 | * | 
|---|
| 5 | * Use of this source code is governed by a BSD-style license that can be | 
|---|
| 6 | * found in the LICENSE file. | 
|---|
| 7 | */ | 
|---|
| 8 | #ifndef GrCaps_DEFINED | 
|---|
| 9 | #define GrCaps_DEFINED | 
|---|
| 10 |  | 
|---|
| 11 | #include "include/core/SkImageInfo.h" | 
|---|
| 12 | #include "include/core/SkRefCnt.h" | 
|---|
| 13 | #include "include/core/SkString.h" | 
|---|
| 14 | #include "include/gpu/GrDriverBugWorkarounds.h" | 
|---|
| 15 | #include "include/private/GrTypesPriv.h" | 
|---|
| 16 | #include "src/core/SkCompressedDataUtils.h" | 
|---|
| 17 | #include "src/gpu/GrBlend.h" | 
|---|
| 18 | #include "src/gpu/GrSamplerState.h" | 
|---|
| 19 | #include "src/gpu/GrShaderCaps.h" | 
|---|
| 20 | #include "src/gpu/GrSurfaceProxy.h" | 
|---|
| 21 |  | 
|---|
| 22 | class GrBackendFormat; | 
|---|
| 23 | class GrBackendRenderTarget; | 
|---|
| 24 | class GrBackendTexture; | 
|---|
| 25 | struct GrContextOptions; | 
|---|
| 26 | class GrProcessorKeyBuilder; | 
|---|
| 27 | class GrProgramDesc; | 
|---|
| 28 | class GrProgramInfo; | 
|---|
| 29 | class GrRenderTargetProxy; | 
|---|
| 30 | class GrSurface; | 
|---|
| 31 | class SkJSONWriter; | 
|---|
| 32 |  | 
|---|
| 33 | /** | 
|---|
| 34 | * Represents the capabilities of a GrContext. | 
|---|
| 35 | */ | 
|---|
| 36 | class GrCaps : public SkRefCnt { | 
|---|
| 37 | public: | 
|---|
| 38 | GrCaps(const GrContextOptions&); | 
|---|
| 39 |  | 
|---|
| 40 | void dumpJSON(SkJSONWriter*) const; | 
|---|
| 41 |  | 
|---|
| 42 | const GrShaderCaps* shaderCaps() const { return fShaderCaps.get(); } | 
|---|
| 43 | sk_sp<const GrShaderCaps> refShaderCaps() const { return fShaderCaps; } | 
|---|
| 44 |  | 
|---|
| 45 | bool npotTextureTileSupport() const { return fNPOTTextureTileSupport; } | 
|---|
| 46 | /** To avoid as-yet-unnecessary complexity we don't allow any partial support of MIP Maps (e.g. | 
|---|
| 47 | only for POT textures) */ | 
|---|
| 48 | bool mipmapSupport() const { return fMipmapSupport; } | 
|---|
| 49 |  | 
|---|
| 50 | bool gpuTracingSupport() const { return fGpuTracingSupport; } | 
|---|
| 51 | bool oversizedStencilSupport() const { return fOversizedStencilSupport; } | 
|---|
| 52 | bool textureBarrierSupport() const { return fTextureBarrierSupport; } | 
|---|
| 53 | bool sampleLocationsSupport() const { return fSampleLocationsSupport; } | 
|---|
| 54 | bool multisampleDisableSupport() const { return fMultisampleDisableSupport; } | 
|---|
| 55 | bool drawInstancedSupport() const { return fDrawInstancedSupport; } | 
|---|
| 56 | // Is there hardware support for indirect draws? (Ganesh always supports indirect draws as long | 
|---|
| 57 | // as it can polyfill them with instanced calls, but this cap tells us if they are supported | 
|---|
| 58 | // natively.) | 
|---|
| 59 | bool nativeDrawIndirectSupport() const { return fNativeDrawIndirectSupport; } | 
|---|
| 60 | bool useClientSideIndirectBuffers() const { | 
|---|
| 61 | #ifdef SK_DEBUG | 
|---|
| 62 | if (!fNativeDrawIndirectSupport || fNativeDrawIndexedIndirectIsBroken) { | 
|---|
| 63 | // We might implement indirect draws with a polyfill, so the commands need to reside in | 
|---|
| 64 | // CPU memory. | 
|---|
| 65 | SkASSERT(fUseClientSideIndirectBuffers); | 
|---|
| 66 | } | 
|---|
| 67 | #endif | 
|---|
| 68 | return fUseClientSideIndirectBuffers; | 
|---|
| 69 | } | 
|---|
| 70 | bool mixedSamplesSupport() const { return fMixedSamplesSupport; } | 
|---|
| 71 | bool conservativeRasterSupport() const { return fConservativeRasterSupport; } | 
|---|
| 72 | bool wireframeSupport() const { return fWireframeSupport; } | 
|---|
| 73 | // This flag indicates that we never have to resolve MSAA. In practice, it means that we have | 
|---|
| 74 | // an MSAA-render-to-texture extension: Any render target we create internally will use the | 
|---|
| 75 | // extension, and any wrapped render target is the client's responsibility. | 
|---|
| 76 | bool msaaResolvesAutomatically() const { return fMSAAResolvesAutomatically; } | 
|---|
| 77 | bool halfFloatVertexAttributeSupport() const { return fHalfFloatVertexAttributeSupport; } | 
|---|
| 78 |  | 
|---|
| 79 | // Primitive restart functionality is core in ES 3.0, but using it will cause slowdowns on some | 
|---|
| 80 | // systems. This cap is only set if primitive restart will improve performance. | 
|---|
| 81 | bool usePrimitiveRestart() const { return fUsePrimitiveRestart; } | 
|---|
| 82 |  | 
|---|
| 83 | bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; } | 
|---|
| 84 |  | 
|---|
| 85 | // On tilers, an initial fullscreen clear is an OPTIMIZATION. It allows the hardware to | 
|---|
| 86 | // initialize each tile with a constant value rather than loading each pixel from memory. | 
|---|
| 87 | bool preferFullscreenClears() const { return fPreferFullscreenClears; } | 
|---|
| 88 |  | 
|---|
| 89 | // Should we discard stencil values after a render pass? (Tilers get better performance if we | 
|---|
| 90 | // always load stencil buffers with a "clear" op, and then discard the content when finished.) | 
|---|
| 91 | bool discardStencilValuesAfterRenderPass() const { | 
|---|
| 92 | // This method is actually just a duplicate of preferFullscreenClears(), with a descriptive | 
|---|
| 93 | // name for the sake of readability. | 
|---|
| 94 | return this->preferFullscreenClears(); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | // D3D does not allow the refs or masks to differ on a two-sided stencil draw. | 
|---|
| 98 | bool twoSidedStencilRefsAndMasksMustMatch() const { | 
|---|
| 99 | return fTwoSidedStencilRefsAndMasksMustMatch; | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | bool preferVRAMUseOverFlushes() const { return fPreferVRAMUseOverFlushes; } | 
|---|
| 103 |  | 
|---|
| 104 | bool preferTrianglesOverSampleMask() const { return fPreferTrianglesOverSampleMask; } | 
|---|
| 105 |  | 
|---|
| 106 | bool avoidStencilBuffers() const { return fAvoidStencilBuffers; } | 
|---|
| 107 |  | 
|---|
| 108 | bool avoidWritePixelsFastPath() const { return fAvoidWritePixelsFastPath; } | 
|---|
| 109 |  | 
|---|
| 110 | // http://skbug.com/9739 | 
|---|
| 111 | bool requiresManualFBBarrierAfterTessellatedStencilDraw() const { | 
|---|
| 112 | return fRequiresManualFBBarrierAfterTessellatedStencilDraw; | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | // glDrawElementsIndirect fails GrMeshTest on every Win10 Intel bot. | 
|---|
| 116 | bool nativeDrawIndexedIndirectIsBroken() const { return fNativeDrawIndexedIndirectIsBroken; } | 
|---|
| 117 |  | 
|---|
| 118 | /** | 
|---|
| 119 | * Indicates the capabilities of the fixed function blend unit. | 
|---|
| 120 | */ | 
|---|
| 121 | enum BlendEquationSupport { | 
|---|
| 122 | kBasic_BlendEquationSupport,             //<! Support to select the operator that | 
|---|
| 123 | //   combines src and dst terms. | 
|---|
| 124 | kAdvanced_BlendEquationSupport,          //<! Additional fixed function support for specific | 
|---|
| 125 | //   SVG/PDF blend modes. Requires blend barriers. | 
|---|
| 126 | kAdvancedCoherent_BlendEquationSupport,  //<! Advanced blend equation support that does not | 
|---|
| 127 | //   require blend barriers, and permits overlap. | 
|---|
| 128 |  | 
|---|
| 129 | kLast_BlendEquationSupport = kAdvancedCoherent_BlendEquationSupport | 
|---|
| 130 | }; | 
|---|
| 131 |  | 
|---|
| 132 | BlendEquationSupport blendEquationSupport() const { return fBlendEquationSupport; } | 
|---|
| 133 |  | 
|---|
| 134 | bool advancedBlendEquationSupport() const { | 
|---|
| 135 | return fBlendEquationSupport >= kAdvanced_BlendEquationSupport; | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | bool advancedCoherentBlendEquationSupport() const { | 
|---|
| 139 | return kAdvancedCoherent_BlendEquationSupport == fBlendEquationSupport; | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | bool isAdvancedBlendEquationDisabled(GrBlendEquation equation) const { | 
|---|
| 143 | SkASSERT(GrBlendEquationIsAdvanced(equation)); | 
|---|
| 144 | SkASSERT(this->advancedBlendEquationSupport()); | 
|---|
| 145 | return SkToBool(fAdvBlendEqDisableFlags & (1 << equation)); | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | // On some GPUs it is a performance win to disable blending instead of doing src-over with a src | 
|---|
| 149 | // alpha equal to 1. To disable blending we collapse src-over to src and the backends will | 
|---|
| 150 | // handle the disabling of blending. | 
|---|
| 151 | bool shouldCollapseSrcOverToSrcWhenAble() const { | 
|---|
| 152 | return fShouldCollapseSrcOverToSrcWhenAble; | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | /** | 
|---|
| 156 | * Indicates whether GPU->CPU memory mapping for GPU resources such as vertex buffers and | 
|---|
| 157 | * textures allows partial mappings or full mappings. | 
|---|
| 158 | */ | 
|---|
| 159 | enum MapFlags { | 
|---|
| 160 | kNone_MapFlags      = 0x0,   //<! Cannot map the resource. | 
|---|
| 161 |  | 
|---|
| 162 | kCanMap_MapFlag     = 0x1,   //<! The resource can be mapped. Must be set for any of | 
|---|
| 163 | //   the other flags to have meaning. | 
|---|
| 164 | kSubset_MapFlag     = 0x2,   //<! The resource can be partially mapped. | 
|---|
| 165 | kAsyncRead_MapFlag  = 0x4,   //<! Are maps for reading asynchronous WRT GrOpsRenderPass | 
|---|
| 166 | //   submitted to GrGpu. | 
|---|
| 167 | }; | 
|---|
| 168 |  | 
|---|
| 169 | uint32_t mapBufferFlags() const { return fMapBufferFlags; } | 
|---|
| 170 |  | 
|---|
| 171 | // Scratch textures not being reused means that those scratch textures | 
|---|
| 172 | // that we upload to (i.e., don't have a render target) will not be | 
|---|
| 173 | // recycled in the texture cache. This is to prevent ghosting by drivers | 
|---|
| 174 | // (in particular for deferred architectures). | 
|---|
| 175 | bool reuseScratchTextures() const { return fReuseScratchTextures; } | 
|---|
| 176 | bool reuseScratchBuffers() const { return fReuseScratchBuffers; } | 
|---|
| 177 |  | 
|---|
| 178 | /// maximum number of attribute values per vertex | 
|---|
| 179 | int maxVertexAttributes() const { return fMaxVertexAttributes; } | 
|---|
| 180 |  | 
|---|
| 181 | int maxRenderTargetSize() const { return fMaxRenderTargetSize; } | 
|---|
| 182 |  | 
|---|
| 183 | /** This is the largest render target size that can be used without incurring extra perfomance | 
|---|
| 184 | cost. It is usually the max RT size, unless larger render targets are known to be slower. */ | 
|---|
| 185 | int maxPreferredRenderTargetSize() const { return fMaxPreferredRenderTargetSize; } | 
|---|
| 186 |  | 
|---|
| 187 | int maxTextureSize() const { return fMaxTextureSize; } | 
|---|
| 188 |  | 
|---|
| 189 | /** This is the maximum tile size to use by GPU devices for rendering sw-backed images/bitmaps. | 
|---|
| 190 | It is usually the max texture size, unless we're overriding it for testing. */ | 
|---|
| 191 | int maxTileSize() const { | 
|---|
| 192 | SkASSERT(fMaxTileSize <= fMaxTextureSize); | 
|---|
| 193 | return fMaxTileSize; | 
|---|
| 194 | } | 
|---|
| 195 |  | 
|---|
| 196 | int maxWindowRectangles() const { return fMaxWindowRectangles; } | 
|---|
| 197 |  | 
|---|
| 198 | // Returns whether mixed samples is supported for the given backend render target. | 
|---|
| 199 | bool isWindowRectanglesSupportedForRT(const GrBackendRenderTarget& rt) const { | 
|---|
| 200 | return this->maxWindowRectangles() > 0 && this->onIsWindowRectanglesSupportedForRT(rt); | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | virtual bool isFormatSRGB(const GrBackendFormat&) const = 0; | 
|---|
| 204 |  | 
|---|
| 205 | bool isFormatCompressed(const GrBackendFormat& format) const; | 
|---|
| 206 |  | 
|---|
| 207 | // Can a texture be made with the GrBackendFormat, and then be bound and sampled in a shader. | 
|---|
| 208 | virtual bool isFormatTexturable(const GrBackendFormat&) const = 0; | 
|---|
| 209 |  | 
|---|
| 210 | // Returns whether a texture of the given format can be copied to a texture of the same format. | 
|---|
| 211 | virtual bool isFormatCopyable(const GrBackendFormat&) const = 0; | 
|---|
| 212 |  | 
|---|
| 213 | // Returns the maximum supported sample count for a format. 0 means the format is not renderable | 
|---|
| 214 | // 1 means the format is renderable but doesn't support MSAA. | 
|---|
| 215 | virtual int maxRenderTargetSampleCount(const GrBackendFormat&) const = 0; | 
|---|
| 216 |  | 
|---|
| 217 | // Returns the number of samples to use when performing internal draws to the given config with | 
|---|
| 218 | // MSAA or mixed samples. If 0, Ganesh should not attempt to use internal multisampling. | 
|---|
| 219 | int internalMultisampleCount(const GrBackendFormat& format) const { | 
|---|
| 220 | return std::min(fInternalMultisampleCount, this->maxRenderTargetSampleCount(format)); | 
|---|
| 221 | } | 
|---|
| 222 |  | 
|---|
| 223 | virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, | 
|---|
| 224 | int sampleCount = 1) const = 0; | 
|---|
| 225 |  | 
|---|
| 226 | virtual bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const = 0; | 
|---|
| 227 |  | 
|---|
| 228 | // Find a sample count greater than or equal to the requested count which is supported for a | 
|---|
| 229 | // render target of the given format or 0 if no such sample count is supported. If the requested | 
|---|
| 230 | // sample count is 1 then 1 will be returned if non-MSAA rendering is supported, otherwise 0. | 
|---|
| 231 | // For historical reasons requestedCount==0 is handled identically to requestedCount==1. | 
|---|
| 232 | virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0; | 
|---|
| 233 |  | 
|---|
| 234 | // Returns the number of bytes per pixel for the given GrBackendFormat. This is only supported | 
|---|
| 235 | // for "normal" formats. For compressed formats this will return 0. | 
|---|
| 236 | virtual size_t bytesPerPixel(const GrBackendFormat&) const = 0; | 
|---|
| 237 |  | 
|---|
| 238 | /** | 
|---|
| 239 | * Backends may have restrictions on what types of surfaces support GrGpu::writePixels(). | 
|---|
| 240 | * If this returns false then the caller should implement a fallback where a temporary texture | 
|---|
| 241 | * is created, pixels are written to it, and then that is copied or drawn into the the surface. | 
|---|
| 242 | */ | 
|---|
| 243 | bool surfaceSupportsWritePixels(const GrSurface*) const; | 
|---|
| 244 |  | 
|---|
| 245 | /** | 
|---|
| 246 | * Indicates whether surface supports GrGpu::readPixels, must be copied, or cannot be read. | 
|---|
| 247 | */ | 
|---|
| 248 | enum class SurfaceReadPixelsSupport { | 
|---|
| 249 | /** GrGpu::readPixels is supported by the surface. */ | 
|---|
| 250 | kSupported, | 
|---|
| 251 | /** | 
|---|
| 252 | * GrGpu::readPixels is not supported by this surface but this surface can be drawn | 
|---|
| 253 | * or copied to a Ganesh-created GrTextureType::kTexture2D and then that surface will be | 
|---|
| 254 | * readable. | 
|---|
| 255 | */ | 
|---|
| 256 | kCopyToTexture2D, | 
|---|
| 257 | /** | 
|---|
| 258 | * Not supported | 
|---|
| 259 | */ | 
|---|
| 260 | kUnsupported, | 
|---|
| 261 | }; | 
|---|
| 262 | /** | 
|---|
| 263 | * Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may | 
|---|
| 264 | * either be able to read directly from the surface, read from a copy of the surface, or not | 
|---|
| 265 | * read at all. | 
|---|
| 266 | */ | 
|---|
| 267 | virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const = 0; | 
|---|
| 268 |  | 
|---|
| 269 | struct SupportedWrite { | 
|---|
| 270 | GrColorType fColorType; | 
|---|
| 271 | // If the write is occurring using GrGpu::transferPixelsTo then this provides the | 
|---|
| 272 | // minimum alignment of the offset into the transfer buffer. | 
|---|
| 273 | size_t fOffsetAlignmentForTransferBuffer; | 
|---|
| 274 | }; | 
|---|
| 275 |  | 
|---|
| 276 | /** | 
|---|
| 277 | * Given a dst pixel config and a src color type what color type must the caller coax the | 
|---|
| 278 | * the data into in order to use GrGpu::writePixels(). | 
|---|
| 279 | */ | 
|---|
| 280 | virtual SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, | 
|---|
| 281 | const GrBackendFormat& surfaceFormat, | 
|---|
| 282 | GrColorType srcColorType) const = 0; | 
|---|
| 283 |  | 
|---|
| 284 | struct SupportedRead { | 
|---|
| 285 | GrColorType fColorType; | 
|---|
| 286 | // If the read is occurring using GrGpu::transferPixelsFrom then this provides the | 
|---|
| 287 | // minimum alignment of the offset into the transfer buffer. | 
|---|
| 288 | size_t fOffsetAlignmentForTransferBuffer; | 
|---|
| 289 | }; | 
|---|
| 290 |  | 
|---|
| 291 | /** | 
|---|
| 292 | * Given a src surface's color type and its backend format as well as a color type the caller | 
|---|
| 293 | * would like read into, this provides a legal color type that the caller may pass to | 
|---|
| 294 | * GrGpu::readPixels(). The returned color type may differ from the passed dstColorType, in | 
|---|
| 295 | * which case the caller must convert the read pixel data (see GrConvertPixels). When converting | 
|---|
| 296 | * to dstColorType the swizzle in the returned struct should be applied. The caller must check | 
|---|
| 297 | * the returned color type for kUnknown. | 
|---|
| 298 | */ | 
|---|
| 299 | SupportedRead supportedReadPixelsColorType(GrColorType srcColorType, | 
|---|
| 300 | const GrBackendFormat& srcFormat, | 
|---|
| 301 | GrColorType dstColorType) const; | 
|---|
| 302 |  | 
|---|
| 303 | /** | 
|---|
| 304 | * Do GrGpu::writePixels() and GrGpu::transferPixelsTo() support a src buffer where the row | 
|---|
| 305 | * bytes is not equal to bpp * w? | 
|---|
| 306 | */ | 
|---|
| 307 | bool writePixelsRowBytesSupport() const { return fWritePixelsRowBytesSupport; } | 
|---|
| 308 | /** | 
|---|
| 309 | * Does GrGpu::readPixels() support a dst buffer where the row bytes is not equal to bpp * w? | 
|---|
| 310 | */ | 
|---|
| 311 | bool readPixelsRowBytesSupport() const { return fReadPixelsRowBytesSupport; } | 
|---|
| 312 |  | 
|---|
| 313 | bool transferFromSurfaceToBufferSupport() const { return fTransferFromSurfaceToBufferSupport; } | 
|---|
| 314 | bool transferFromBufferToTextureSupport() const { return fTransferFromBufferToTextureSupport; } | 
|---|
| 315 |  | 
|---|
| 316 | bool suppressPrints() const { return fSuppressPrints; } | 
|---|
| 317 |  | 
|---|
| 318 | size_t bufferMapThreshold() const { | 
|---|
| 319 | SkASSERT(fBufferMapThreshold >= 0); | 
|---|
| 320 | return fBufferMapThreshold; | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | /** True in environments that will issue errors if memory uploaded to buffers | 
|---|
| 324 | is not initialized (even if not read by draw calls). */ | 
|---|
| 325 | bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; } | 
|---|
| 326 |  | 
|---|
| 327 | /** For some environments, there is a performance or safety concern to not | 
|---|
| 328 | initializing textures. For example, with WebGL and Firefox, there is a large | 
|---|
| 329 | performance hit to not doing it. | 
|---|
| 330 | */ | 
|---|
| 331 | bool shouldInitializeTextures() const { return fShouldInitializeTextures; } | 
|---|
| 332 |  | 
|---|
| 333 | /** Returns true if the given backend supports importing AHardwareBuffers via the | 
|---|
| 334 | * GrAHardwarebufferImageGenerator. This will only ever be supported on Android devices with API | 
|---|
| 335 | * level >= 26. | 
|---|
| 336 | * */ | 
|---|
| 337 | bool supportsAHardwareBufferImages() const { return fSupportsAHardwareBufferImages; } | 
|---|
| 338 |  | 
|---|
| 339 | bool wireframeMode() const { return fWireframeMode; } | 
|---|
| 340 |  | 
|---|
| 341 | /** Supports using GrFence. */ | 
|---|
| 342 | bool fenceSyncSupport() const { return fFenceSyncSupport; } | 
|---|
| 343 |  | 
|---|
| 344 | /** Supports using GrSemaphore. */ | 
|---|
| 345 | bool semaphoreSupport() const { return fSemaphoreSupport; } | 
|---|
| 346 |  | 
|---|
| 347 | bool crossContextTextureSupport() const { return fCrossContextTextureSupport; } | 
|---|
| 348 | /** | 
|---|
| 349 | * Returns whether or not we will be able to do a copy given the passed in params | 
|---|
| 350 | */ | 
|---|
| 351 | bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, | 
|---|
| 352 | const SkIRect& srcRect, const SkIPoint& dstPoint) const; | 
|---|
| 353 |  | 
|---|
| 354 | bool dynamicStateArrayGeometryProcessorTextureSupport() const { | 
|---|
| 355 | return fDynamicStateArrayGeometryProcessorTextureSupport; | 
|---|
| 356 | } | 
|---|
| 357 |  | 
|---|
| 358 | // Not all backends support clearing with a scissor test (e.g. Metal), this will always | 
|---|
| 359 | // return true if performColorClearsAsDraws() returns true. | 
|---|
| 360 | bool performPartialClearsAsDraws() const { | 
|---|
| 361 | return fPerformColorClearsAsDraws || fPerformPartialClearsAsDraws; | 
|---|
| 362 | } | 
|---|
| 363 |  | 
|---|
| 364 | // Many drivers have issues with color clears. | 
|---|
| 365 | bool performColorClearsAsDraws() const { return fPerformColorClearsAsDraws; } | 
|---|
| 366 |  | 
|---|
| 367 | bool avoidLargeIndexBufferDraws() const { return fAvoidLargeIndexBufferDraws; } | 
|---|
| 368 |  | 
|---|
| 369 | /// Adreno 4xx devices experience an issue when there are a large number of stencil clip bit | 
|---|
| 370 | /// clears. The minimal repro steps are not precisely known but drawing a rect with a stencil | 
|---|
| 371 | /// op instead of using glClear seems to resolve the issue. | 
|---|
| 372 | bool performStencilClearsAsDraws() const { return fPerformStencilClearsAsDraws; } | 
|---|
| 373 |  | 
|---|
| 374 | // Can we use coverage counting shortcuts to render paths? Coverage counting can cause artifacts | 
|---|
| 375 | // along shared edges if care isn't taken to ensure both contours wind in the same direction. | 
|---|
| 376 | bool allowCoverageCounting() const { return fAllowCoverageCounting; } | 
|---|
| 377 |  | 
|---|
| 378 | // Should we disable the CCPR code due to a faulty driver? | 
|---|
| 379 | bool driverDisableCCPR() const { return fDriverDisableCCPR; } | 
|---|
| 380 | bool driverDisableMSAACCPR() const { return fDriverDisableMSAACCPR; } | 
|---|
| 381 |  | 
|---|
| 382 | /** | 
|---|
| 383 | * This is used to try to ensure a successful copy a dst in order to perform shader-based | 
|---|
| 384 | * blending. | 
|---|
| 385 | * | 
|---|
| 386 | * fRectsMustMatch will be set to true if the copy operation must ensure that the src and dest | 
|---|
| 387 | * rects are identical. | 
|---|
| 388 | * | 
|---|
| 389 | * fMustCopyWholeSrc will be set to true if copy rect must equal src's bounds. | 
|---|
| 390 | * | 
|---|
| 391 | * Caller will detect cases when copy cannot succeed and try copy-as-draw as a fallback. | 
|---|
| 392 | */ | 
|---|
| 393 | struct DstCopyRestrictions { | 
|---|
| 394 | GrSurfaceProxy::RectsMustMatch fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kNo; | 
|---|
| 395 | bool fMustCopyWholeSrc = false; | 
|---|
| 396 | }; | 
|---|
| 397 | virtual DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, | 
|---|
| 398 | GrColorType ct) const { | 
|---|
| 399 | return {}; | 
|---|
| 400 | } | 
|---|
| 401 |  | 
|---|
| 402 | bool validateSurfaceParams(const SkISize&, const GrBackendFormat&, GrRenderable renderable, | 
|---|
| 403 | int renderTargetSampleCnt, GrMipmapped) const; | 
|---|
| 404 |  | 
|---|
| 405 | bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat& format) const; | 
|---|
| 406 |  | 
|---|
| 407 | /** These are used when creating a new texture internally. */ | 
|---|
| 408 | GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const; | 
|---|
| 409 |  | 
|---|
| 410 | virtual GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const = 0; | 
|---|
| 411 |  | 
|---|
| 412 | /** | 
|---|
| 413 | * The CLAMP_TO_BORDER wrap mode for texture coordinates was added to desktop GL in 1.3, and | 
|---|
| 414 | * GLES 3.2, but is also available in extensions. Vulkan and Metal always have support. | 
|---|
| 415 | */ | 
|---|
| 416 | bool clampToBorderSupport() const { return fClampToBorderSupport; } | 
|---|
| 417 |  | 
|---|
| 418 | /** | 
|---|
| 419 | * Returns the GrSwizzle to use when sampling or reading back from a texture with the passed in | 
|---|
| 420 | * GrBackendFormat and GrColorType. | 
|---|
| 421 | */ | 
|---|
| 422 | GrSwizzle getReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const; | 
|---|
| 423 |  | 
|---|
| 424 | /** | 
|---|
| 425 | * Returns the GrSwizzle to use when writing colors to a surface with the passed in | 
|---|
| 426 | * GrBackendFormat and GrColorType. | 
|---|
| 427 | */ | 
|---|
| 428 | virtual GrSwizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const = 0; | 
|---|
| 429 |  | 
|---|
| 430 | virtual uint64_t computeFormatKey(const GrBackendFormat&) const = 0; | 
|---|
| 431 |  | 
|---|
| 432 | const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; } | 
|---|
| 433 |  | 
|---|
| 434 | /** | 
|---|
| 435 | * Adds fields to the key to represent the sampler that will be created for the passed | 
|---|
| 436 | * in parameters. Currently this extra keying is only needed when building a vulkan pipeline | 
|---|
| 437 | * with immutable samplers. | 
|---|
| 438 | */ | 
|---|
| 439 | virtual void (GrProcessorKeyBuilder*, | 
|---|
| 440 | GrSamplerState, | 
|---|
| 441 | const GrBackendFormat&) const {} | 
|---|
| 442 |  | 
|---|
| 443 | virtual GrProgramDesc makeDesc(GrRenderTarget*, const GrProgramInfo&) const = 0; | 
|---|
| 444 |  | 
|---|
| 445 | #if GR_TEST_UTILS | 
|---|
| 446 | struct TestFormatColorTypeCombination { | 
|---|
| 447 | GrColorType fColorType; | 
|---|
| 448 | GrBackendFormat fFormat; | 
|---|
| 449 | }; | 
|---|
| 450 |  | 
|---|
| 451 | virtual std::vector<TestFormatColorTypeCombination> getTestingCombinations() const = 0; | 
|---|
| 452 | #endif | 
|---|
| 453 |  | 
|---|
| 454 | protected: | 
|---|
| 455 | // Subclasses must call this at the end of their init method in order to do final processing on | 
|---|
| 456 | // the caps (including overrides requested by the client). | 
|---|
| 457 | // NOTE: this method will only reduce the caps, never expand them. | 
|---|
| 458 | void finishInitialization(const GrContextOptions& options); | 
|---|
| 459 |  | 
|---|
| 460 | sk_sp<GrShaderCaps> fShaderCaps; | 
|---|
| 461 |  | 
|---|
| 462 | bool fNPOTTextureTileSupport                     : 1; | 
|---|
| 463 | bool fMipmapSupport                              : 1; | 
|---|
| 464 | bool fReuseScratchTextures                       : 1; | 
|---|
| 465 | bool fReuseScratchBuffers                        : 1; | 
|---|
| 466 | bool fGpuTracingSupport                          : 1; | 
|---|
| 467 | bool fOversizedStencilSupport                    : 1; | 
|---|
| 468 | bool fTextureBarrierSupport                      : 1; | 
|---|
| 469 | bool fSampleLocationsSupport                     : 1; | 
|---|
| 470 | bool fMultisampleDisableSupport                  : 1; | 
|---|
| 471 | bool fDrawInstancedSupport                       : 1; | 
|---|
| 472 | bool fNativeDrawIndirectSupport                  : 1; | 
|---|
| 473 | bool fUseClientSideIndirectBuffers               : 1; | 
|---|
| 474 | bool fMixedSamplesSupport                        : 1; | 
|---|
| 475 | bool fConservativeRasterSupport                  : 1; | 
|---|
| 476 | bool fWireframeSupport                           : 1; | 
|---|
| 477 | bool fMSAAResolvesAutomatically                  : 1; | 
|---|
| 478 | bool fUsePrimitiveRestart                        : 1; | 
|---|
| 479 | bool fPreferClientSideDynamicBuffers             : 1; | 
|---|
| 480 | bool fPreferFullscreenClears                     : 1; | 
|---|
| 481 | bool fTwoSidedStencilRefsAndMasksMustMatch       : 1; | 
|---|
| 482 | bool fMustClearUploadedBufferData                : 1; | 
|---|
| 483 | bool fShouldInitializeTextures                   : 1; | 
|---|
| 484 | bool fSupportsAHardwareBufferImages              : 1; | 
|---|
| 485 | bool fHalfFloatVertexAttributeSupport            : 1; | 
|---|
| 486 | bool fClampToBorderSupport                       : 1; | 
|---|
| 487 | bool fPerformPartialClearsAsDraws                : 1; | 
|---|
| 488 | bool fPerformColorClearsAsDraws                  : 1; | 
|---|
| 489 | bool fAvoidLargeIndexBufferDraws                 : 1; | 
|---|
| 490 | bool fPerformStencilClearsAsDraws                : 1; | 
|---|
| 491 | bool fAllowCoverageCounting                      : 1; | 
|---|
| 492 | bool fTransferFromBufferToTextureSupport         : 1; | 
|---|
| 493 | bool fTransferFromSurfaceToBufferSupport         : 1; | 
|---|
| 494 | bool fWritePixelsRowBytesSupport                 : 1; | 
|---|
| 495 | bool fReadPixelsRowBytesSupport                  : 1; | 
|---|
| 496 | bool fShouldCollapseSrcOverToSrcWhenAble         : 1; | 
|---|
| 497 |  | 
|---|
| 498 | // Driver workaround | 
|---|
| 499 | bool fDriverDisableCCPR                          : 1; | 
|---|
| 500 | bool fDriverDisableMSAACCPR                      : 1; | 
|---|
| 501 | bool fAvoidStencilBuffers                        : 1; | 
|---|
| 502 | bool fAvoidWritePixelsFastPath                   : 1; | 
|---|
| 503 | bool fRequiresManualFBBarrierAfterTessellatedStencilDraw : 1; | 
|---|
| 504 | bool fNativeDrawIndexedIndirectIsBroken          : 1; | 
|---|
| 505 |  | 
|---|
| 506 | // ANGLE performance workaround | 
|---|
| 507 | bool fPreferVRAMUseOverFlushes                   : 1; | 
|---|
| 508 |  | 
|---|
| 509 | // On some platforms it's better to make more triangles than to use the sample mask (MSAA only). | 
|---|
| 510 | bool fPreferTrianglesOverSampleMask              : 1; | 
|---|
| 511 |  | 
|---|
| 512 | bool fFenceSyncSupport                           : 1; | 
|---|
| 513 | bool fSemaphoreSupport                           : 1; | 
|---|
| 514 |  | 
|---|
| 515 | // Requires fence sync support in GL. | 
|---|
| 516 | bool fCrossContextTextureSupport                 : 1; | 
|---|
| 517 |  | 
|---|
| 518 | // Not (yet) implemented in VK backend. | 
|---|
| 519 | bool fDynamicStateArrayGeometryProcessorTextureSupport : 1; | 
|---|
| 520 |  | 
|---|
| 521 | BlendEquationSupport fBlendEquationSupport; | 
|---|
| 522 | uint32_t fAdvBlendEqDisableFlags; | 
|---|
| 523 | static_assert(kLast_GrBlendEquation < 32); | 
|---|
| 524 |  | 
|---|
| 525 | uint32_t fMapBufferFlags; | 
|---|
| 526 | int fBufferMapThreshold; | 
|---|
| 527 |  | 
|---|
| 528 | int fMaxRenderTargetSize; | 
|---|
| 529 | int fMaxPreferredRenderTargetSize; | 
|---|
| 530 | int fMaxVertexAttributes; | 
|---|
| 531 | int fMaxTextureSize; | 
|---|
| 532 | int fMaxTileSize; | 
|---|
| 533 | int fMaxWindowRectangles; | 
|---|
| 534 | int fInternalMultisampleCount; | 
|---|
| 535 |  | 
|---|
| 536 | GrDriverBugWorkarounds fDriverBugWorkarounds; | 
|---|
| 537 |  | 
|---|
| 538 | private: | 
|---|
| 539 | void applyOptionsOverrides(const GrContextOptions& options); | 
|---|
| 540 |  | 
|---|
| 541 | virtual void onApplyOptionsOverrides(const GrContextOptions&) {} | 
|---|
| 542 | virtual void onDumpJSON(SkJSONWriter*) const {} | 
|---|
| 543 | virtual bool onSurfaceSupportsWritePixels(const GrSurface*) const = 0; | 
|---|
| 544 | virtual bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, | 
|---|
| 545 | const SkIRect& srcRect, const SkIPoint& dstPoint) const = 0; | 
|---|
| 546 | virtual GrBackendFormat onGetDefaultBackendFormat(GrColorType) const = 0; | 
|---|
| 547 |  | 
|---|
| 548 | // Backends should implement this if they have any extra requirements for use of window | 
|---|
| 549 | // rectangles for a specific GrBackendRenderTarget outside of basic support. | 
|---|
| 550 | virtual bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const { | 
|---|
| 551 | return true; | 
|---|
| 552 | } | 
|---|
| 553 |  | 
|---|
| 554 | virtual bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const = 0; | 
|---|
| 555 |  | 
|---|
| 556 | virtual SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType, | 
|---|
| 557 | const GrBackendFormat& srcFormat, | 
|---|
| 558 | GrColorType dstColorType) const = 0; | 
|---|
| 559 |  | 
|---|
| 560 | virtual GrSwizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const = 0; | 
|---|
| 561 |  | 
|---|
| 562 |  | 
|---|
| 563 | bool fSuppressPrints : 1; | 
|---|
| 564 | bool fWireframeMode  : 1; | 
|---|
| 565 |  | 
|---|
| 566 | typedef SkRefCnt INHERITED; | 
|---|
| 567 | }; | 
|---|
| 568 |  | 
|---|
| 569 | #endif | 
|---|
| 570 |  | 
|---|