1 /* 2 * Copyright 2012 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 9 #ifndef GrGLCaps_DEFINED 10 #define GrGLCaps_DEFINED 11 12 #include <functional> 13 #include "include/private/GrGLTypesPriv.h" 14 #include "include/private/SkChecksum.h" 15 #include "include/private/SkTArray.h" 16 #include "include/private/SkTHash.h" 17 #include "src/gpu/GrCaps.h" 18 #include "src/gpu/GrSwizzle.h" 19 #include "src/gpu/gl/GrGLAttachment.h" 20 #include "src/gpu/gl/GrGLUtil.h" 21 22 class GrGLContextInfo; 23 class GrGLRenderTarget; 24 25 /** 26 * Stores some capabilities of a GL context. Most are determined by the GL 27 * version and the extensions string. It also tracks formats that have passed 28 * the FBO completeness test. 29 */ 30 class GrGLCaps : public GrCaps { 31 public: 32 /** 33 * The type of MSAA for FBOs supported. Different extensions have different 34 * semantics of how / when a resolve is performed. 35 */ 36 enum MSFBOType { 37 /** 38 * no support for MSAA FBOs 39 */ 40 kNone_MSFBOType = 0, 41 /** 42 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object, 43 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample, 44 * or GL_EXT_framebuffer_multisample 45 */ 46 kStandard_MSFBOType, 47 /** 48 * GL_APPLE_framebuffer_multisample ES extension 49 */ 50 kES_Apple_MSFBOType, 51 /** 52 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers. 53 * Instead the texture is multisampled when bound to the FBO and then resolved automatically 54 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call 55 * GR_GL_MAX_SAMPLES_IMG). 56 */ 57 kES_IMG_MsToTexture_MSFBOType, 58 /** 59 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard 60 * GL_MAX_SAMPLES value. 61 */ 62 kES_EXT_MsToTexture_MSFBOType, 63 64 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType 65 }; 66 67 enum BlitFramebufferFlags { 68 kNoSupport_BlitFramebufferFlag = 1 << 0, 69 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1, 70 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2, 71 kNoMSAADst_BlitFramebufferFlag = 1 << 3, 72 kNoFormatConversion_BlitFramebufferFlag = 1 << 4, 73 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5, 74 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6, 75 }; 76 77 enum InvalidateFBType { 78 kNone_InvalidateFBType, 79 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer() 80 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer() 81 82 kLast_InvalidateFBType = kInvalidate_InvalidateFBType 83 }; 84 85 enum MapBufferType { 86 kNone_MapBufferType, 87 kMapBuffer_MapBufferType, // glMapBuffer() 88 kMapBufferRange_MapBufferType, // glMapBufferRange() 89 kChromium_MapBufferType, // GL_CHROMIUM_map_sub 90 91 kLast_MapBufferType = kChromium_MapBufferType, 92 }; 93 94 enum class TransferBufferType { 95 kNone, 96 kNV_PBO, // NV_pixel_buffer_object 97 kARB_PBO, // ARB_pixel_buffer_object 98 kChromium, // CHROMIUM_pixel_transfer_buffer_object 99 }; 100 101 enum class FenceType { 102 kNone, 103 kSyncObject, 104 kNVFence 105 }; 106 107 enum class MultiDrawType { 108 kNone, 109 kMultiDrawIndirect, // ARB_multi_draw_indirect, EXT_multi_draw_indirect, or GL 4.3 core. 110 kANGLEOrWebGL // ANGLE_base_vertex_base_instance or 111 // WEBGL_draw_instanced_base_vertex_base_instance 112 }; 113 114 /** 115 * Initializes the GrGLCaps to the set of features supported in the current 116 * OpenGL context accessible via ctxInfo. 117 */ 118 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, 119 const GrGLInterface* glInterface); 120 121 bool isFormatSRGB(const GrBackendFormat&) const override; 122 123 bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; 124 bool isFormatTexturable(GrGLFormat) const; 125 126 bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, 127 int sampleCount = 1) const override; 128 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override; isFormatRenderable(GrGLFormat format,int sampleCount)129 bool isFormatRenderable(GrGLFormat format, int sampleCount) const { 130 return sampleCount <= this->maxRenderTargetSampleCount(format); 131 } 132 getRenderTargetSampleCount(int requestedCount,const GrBackendFormat & format)133 int getRenderTargetSampleCount(int requestedCount, 134 const GrBackendFormat& format) const override { 135 return this->getRenderTargetSampleCount(requestedCount, format.asGLFormat()); 136 } 137 int getRenderTargetSampleCount(int requestedCount, GrGLFormat) const; 138 maxRenderTargetSampleCount(const GrBackendFormat & format)139 int maxRenderTargetSampleCount(const GrBackendFormat& format) const override { 140 return this->maxRenderTargetSampleCount(format.asGLFormat()); 141 } 142 int maxRenderTargetSampleCount(GrGLFormat) const; 143 144 bool isFormatCopyable(const GrBackendFormat&) const override; 145 146 bool canFormatBeFBOColorAttachment(GrGLFormat) const; 147 getFormatFromColorType(GrColorType colorType)148 GrGLFormat getFormatFromColorType(GrColorType colorType) const { 149 int idx = static_cast<int>(colorType); 150 return fColorTypeToFormatTable[idx]; 151 } 152 153 /** 154 * Gets the internal format to use with glTexImage...() and glTexStorage...(). May be sized or 155 * base depending upon the GL. Not applicable to compressed textures. 156 */ getTexImageOrStorageInternalFormat(GrGLFormat format)157 GrGLenum getTexImageOrStorageInternalFormat(GrGLFormat format) const { 158 return this->getFormatInfo(format).fInternalFormatForTexImageOrStorage; 159 } 160 161 /** 162 * Gets the external format and type to pass to glTexImage2D with nullptr to create an 163 * uninitialized texture. See getTexImageOrStorageInternalFormat() for the internal format. 164 */ 165 void getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum* externalFormat, 166 GrGLenum* externalType) const; 167 168 /** 169 * Given a src data color type and a color type interpretation for a texture of a given format 170 * this provides the external GL format and type to use with glTexSubImage2d. The color types 171 * should originate from supportedWritePixelsColorType(). 172 */ 173 void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 174 GrColorType memoryColorType, GrGLenum* externalFormat, 175 GrGLenum* externalType) const; 176 177 /** 178 * Gets the external format, type, and bytes per pixel to use when uploading solid color data 179 * via glTexSubImage...() to clear the texture at creation. 180 */ 181 void getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format, 182 GrGLenum* externalFormat, 183 GrGLenum* externalType, 184 GrColorType* colorType) const; 185 186 void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 187 GrColorType memoryColorType, GrGLenum* externalFormat, 188 GrGLenum* externalType) const; 189 190 /** 191 * Gets an array of legal stencil formats. These formats are not guaranteed 192 * to be supported by the driver but are legal GLenum names given the GL 193 * version and extensions supported. 194 */ stencilFormats()195 const SkTArray<GrGLFormat, true>& stencilFormats() const { 196 return fStencilFormats; 197 } 198 199 bool formatSupportsTexStorage(GrGLFormat) const; 200 201 /** 202 * Would it be useful to check GL_IMPLEMENTATION_READ_FORMAT and _TYPE for this format to 203 * detect more efficient glReadPixels arguments? 204 */ 205 bool shouldQueryImplementationReadSupport(GrGLFormat format) const; 206 207 /** 208 * Let caps know the result of GL_IMPLEMENTATION_READ_FORMAT and _TYPE query for a format 209 * to update supported glReadPixels arguments. 210 */ 211 void didQueryImplementationReadSupport(GrGLFormat format, 212 GrGLenum readFormat, 213 GrGLenum readType) const; 214 215 /** 216 * Gets the internal format to use with glRenderbufferStorageMultisample...(). May be sized or 217 * base depending upon the GL. Not applicable to compressed textures. 218 */ getRenderbufferInternalFormat(GrGLFormat format)219 GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const { 220 return this->getFormatInfo(format).fInternalFormatForRenderbuffer; 221 } 222 223 /** 224 * Gets the default external type to use with glTex[Sub]Image... when the data pointer is null. 225 */ getFormatDefaultExternalType(GrGLFormat format)226 GrGLenum getFormatDefaultExternalType(GrGLFormat format) const { 227 return this->getFormatInfo(format).fDefaultExternalType; 228 } 229 230 /** 231 * Has a stencil format index been found for the format (or we've found that no format works). 232 */ hasStencilFormatBeenDeterminedForFormat(GrGLFormat format)233 bool hasStencilFormatBeenDeterminedForFormat(GrGLFormat format) const { 234 return this->getFormatInfo(format).fStencilFormatIndex != FormatInfo::kUnknown_StencilIndex; 235 } 236 237 /** 238 * Gets the stencil format index for the format. This assumes 239 * hasStencilFormatBeenDeterminedForFormat has already been checked. Returns a value < 0 if 240 * no stencil format is supported with the format. Otherwise, returned index refers to the array 241 * returned by stencilFormats(). 242 */ getStencilFormatIndexForFormat(GrGLFormat format)243 int getStencilFormatIndexForFormat(GrGLFormat format) const { 244 SkASSERT(this->hasStencilFormatBeenDeterminedForFormat(format)); 245 return this->getFormatInfo(format).fStencilFormatIndex; 246 } 247 248 /** 249 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for 250 * the format. If < 0 it records that the format has no supported stencil format index. 251 */ 252 void setStencilFormatIndexForFormat(GrGLFormat, int index); 253 254 /** 255 * Reports the type of MSAA FBO support. 256 */ msFBOType()257 MSFBOType msFBOType() const { return fMSFBOType; } 258 259 /** 260 * Does the preferred MSAA FBO extension have MSAA renderbuffers? 261 */ usesMSAARenderBuffers()262 bool usesMSAARenderBuffers() const { 263 return kNone_MSFBOType != fMSFBOType && 264 kES_IMG_MsToTexture_MSFBOType != fMSFBOType && 265 kES_EXT_MsToTexture_MSFBOType != fMSFBOType; 266 } 267 268 /** 269 * Is it unsupported to only resolve a sub-rectangle of a framebuffer? 270 */ framebufferResolvesMustBeFullSize()271 bool framebufferResolvesMustBeFullSize() const { 272 SkASSERT(fMSFBOType != kNone_MSFBOType); 273 return fMSFBOType == kES_Apple_MSFBOType || 274 (fBlitFramebufferFlags & kResolveMustBeFull_BlitFrambufferFlag); 275 } 276 277 /** 278 * Can we resolve a single-sample framebuffer into an MSAA framebuffer? 279 */ canResolveSingleToMSAA()280 bool canResolveSingleToMSAA() const { 281 SkASSERT(fMSFBOType != kNone_MSFBOType); 282 return fMSFBOType != kES_Apple_MSFBOType && 283 !(fBlitFramebufferFlags & GrGLCaps::kNoMSAADst_BlitFramebufferFlag); 284 } 285 286 /** 287 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and 288 * then implicitly resolved when read. 289 */ usesImplicitMSAAResolve()290 bool usesImplicitMSAAResolve() const { 291 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType || 292 kES_EXT_MsToTexture_MSFBOType == fMSFBOType; 293 } 294 invalidateFBType()295 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; } 296 297 /// What type of buffer mapping is supported? mapBufferType()298 MapBufferType mapBufferType() const { return fMapBufferType; } 299 300 /// What type of transfer buffer is supported? transferBufferType()301 TransferBufferType transferBufferType() const { return fTransferBufferType; } 302 303 /// How are GrFences implemented? fenceType()304 FenceType fenceType() const { return fFenceType; } 305 306 /// How are multi draws implemented (if at all)? multiDrawType()307 MultiDrawType multiDrawType() const { return fMultiDrawType; } 308 309 /// The maximum number of fragment uniform vectors (GLES has min. 16). maxFragmentUniformVectors()310 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } 311 312 /// Is there support for GL_PACK_REVERSE_ROW_ORDER packFlipYSupport()313 bool packFlipYSupport() const { return fPackFlipYSupport; } 314 315 /// Is there support for texture parameter GL_TEXTURE_USAGE textureUsageSupport()316 bool textureUsageSupport() const { return fTextureUsageSupport; } 317 318 /// Is GL_ARB_IMAGING supported imagingSupport()319 bool imagingSupport() const { return fImagingSupport; } 320 321 /// Is there support for Vertex Array Objects? vertexArrayObjectSupport()322 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } 323 324 /// Is there support for GL_KHR_debug? debugSupport()325 bool debugSupport() const { return fDebugSupport; } 326 327 /// Is there support for ES2 compatability? ES2CompatibilitySupport()328 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; } 329 330 /// Is there support for glDrawRangeElements? drawRangeElementsSupport()331 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; } 332 333 /// Are the glDraw*Base(VertexBase)Instance methods, and baseInstance fields in indirect draw 334 //commands supported? baseVertexBaseInstanceSupport()335 bool baseVertexBaseInstanceSupport() const { return fBaseVertexBaseInstanceSupport; } 336 337 SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; 338 339 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, 340 const GrBackendFormat& surfaceFormat, 341 GrColorType srcColorType) const override; 342 isCoreProfile()343 bool isCoreProfile() const { return fIsCoreProfile; } 344 bindFragDataLocationSupport()345 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; } 346 bindUniformLocationSupport()347 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; } 348 349 /// Are textures with GL_TEXTURE_RECTANGLE type supported. rectangleTextureSupport()350 bool rectangleTextureSupport() const { return fRectangleTextureSupport; } 351 352 /// Can set the BASE and MAX mip map level. mipmapLevelControlSupport()353 bool mipmapLevelControlSupport() const { return fMipmapLevelControlSupport; } 354 355 /// Can set the MIN/MAX LOD value. mipmapLodControlSupport()356 bool mipmapLodControlSupport() const { return fMipmapLodControlSupport; } 357 doManualMipmapping()358 bool doManualMipmapping() const { return fDoManualMipmapping; } 359 360 void onDumpJSON(SkJSONWriter*) const override; 361 useBufferDataNullHint()362 bool useBufferDataNullHint() const { return fUseBufferDataNullHint; } 363 364 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s. clearToBoundaryValuesIsBroken()365 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; } 366 367 /// glClearTex(Sub)Image support clearTextureSupport()368 bool clearTextureSupport() const { return fClearTextureSupport; } 369 370 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to 371 // glDrawArrays is nonzero. 372 // https://bugs.chromium.org/p/skia/issues/detail?id=6650 drawArraysBaseVertexIsBroken()373 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; } 374 375 // If true then we must use an intermediate surface to perform partial updates to unorm textures 376 // that have ever been bound to a FBO. disallowTexSubImageForUnormConfigTexturesEverBoundToFBO()377 bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const { 378 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO; 379 } 380 381 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture 382 // that is bound to an FBO. useDrawInsteadOfAllRenderTargetWrites()383 bool useDrawInsteadOfAllRenderTargetWrites() const { 384 return fUseDrawInsteadOfAllRenderTargetWrites; 385 } 386 387 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling 388 // face culling on and off seems to resolve this. requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines()389 bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const { 390 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines; 391 } 392 393 // Older Android versions seem to have an issue with setting GL_TEXTURE_BASE_LEVEL or 394 // GL_TEXTURE_MAX_LEVEL for GL_TEXTURE_EXTERNAL_OES textures. dontSetBaseOrMaxLevelForExternalTextures()395 bool dontSetBaseOrMaxLevelForExternalTextures() const { 396 return fDontSetBaseOrMaxLevelForExternalTextures; 397 } 398 399 // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled. neverDisableColorWrites()400 bool neverDisableColorWrites() const { return fNeverDisableColorWrites; } 401 402 // Texture parameters must be used to enable MIP mapping even when a sampler object is used. mustSetAnyTexParameterToEnableMipmapping()403 bool mustSetAnyTexParameterToEnableMipmapping() const { 404 return fMustSetAnyTexParameterToEnableMipmapping; 405 } 406 407 // Whether we must reset the blend function to not reference src2 when disabling blending after 408 // previously referencing src2. mustResetBlendFuncBetweenDualSourceAndDisable()409 bool mustResetBlendFuncBetweenDualSourceAndDisable() const { 410 return fMustResetBlendFuncBetweenDualSourceAndDisable; 411 } 412 413 // Before changing the sample count of a texture bound to an FBO with 414 // glFramebufferTexture2DMultisample() temporarily bind texture 0 to avoid corruption int the 415 // texture contents. bindTexture0WhenChangingTextureFBOMultisampleCount()416 bool bindTexture0WhenChangingTextureFBOMultisampleCount() const { 417 return fBindTexture0WhenChangingTextureFBOMultisampleCount; 418 } 419 420 // After using glCheckFramebufferStatus() bind 0 to the color attachment and then rebind the 421 // original color attachment. rebindColorAttachmentAfterCheckFramebufferStatus()422 bool rebindColorAttachmentAfterCheckFramebufferStatus() const { 423 return fRebindColorAttachmentAfterCheckFramebufferStatus; 424 } 425 426 // Returns the observed maximum number of instances the driver can handle in a single draw call 427 // without crashing, or 'pendingInstanceCount' if this workaround is not necessary. 428 // NOTE: the return value may be larger than pendingInstanceCount. maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount)429 int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const { 430 return (fMaxInstancesPerDrawWithoutCrashing) 431 ? fMaxInstancesPerDrawWithoutCrashing : pendingInstanceCount; 432 } 433 434 bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer, 435 const GrTextureType* dstTypeIfTexture, 436 GrGLFormat srcFormat, bool srcHasMSAARenderBuffer, 437 const GrTextureType* srcTypeIfTexture) const; 438 bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, 439 const GrTextureType* dstTypeIfTexture, 440 GrGLFormat srcFormat, int srcSampleCnt, 441 const GrTextureType* srcTypeIfTexture, 442 const SkRect& srcBounds, bool srcBoundsExact, 443 const SkIRect& srcRect, const SkIPoint& dstPoint) const; 444 bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const; 445 446 DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, 447 GrColorType) const override; 448 programBinarySupport()449 bool programBinarySupport() const { return fProgramBinarySupport; } programParameterSupport()450 bool programParameterSupport() const { return fProgramParameterSupport; } 451 452 /** Are sampler objects available in this GL? */ samplerObjectSupport()453 bool samplerObjectSupport() const { return fSamplerObjectSupport; } 454 455 /** 456 * Are we using sampler objects in favor of texture parameters? (This will only be true if 457 * samplerObjectSupport()). 458 */ useSamplerObjects()459 bool useSamplerObjects() const { return fUseSamplerObjects; } 460 textureSwizzleSupport()461 bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } 462 tiledRenderingSupport()463 bool tiledRenderingSupport() const { return fTiledRenderingSupport; } 464 fbFetchRequiresEnablePerSample()465 bool fbFetchRequiresEnablePerSample() const { return fFBFetchRequiresEnablePerSample; } 466 467 /* Is there support for enabling/disabling sRGB writes for sRGB-capable color buffers? */ srgbWriteControl()468 bool srgbWriteControl() const { return fSRGBWriteControl; } 469 470 /** Skip checks for GL errors, shader compilation success, program link success. */ skipErrorChecks()471 bool skipErrorChecks() const { return fSkipErrorChecks; } 472 clientCanDisableMultisample()473 bool clientCanDisableMultisample() const { return fClientCanDisableMultisample; } 474 475 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; 476 477 GrSwizzle getWriteSwizzle(const GrBackendFormat&, GrColorType) const override; 478 479 uint64_t computeFormatKey(const GrBackendFormat&) const override; 480 481 GrProgramDesc makeDesc(GrRenderTarget*, 482 const GrProgramInfo&, 483 ProgramDescOverrideFlags) const override; 484 485 #if GR_TEST_UTILS standard()486 GrGLStandard standard() const { return fStandard; } 487 488 std::vector<TestFormatColorTypeCombination> getTestingCombinations() const override; 489 #endif 490 491 private: 492 enum ExternalFormatUsage { 493 kTexImage_ExternalFormatUsage, 494 kReadPixels_ExternalFormatUsage, 495 }; 496 void getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 497 GrColorType memoryColorType, ExternalFormatUsage usage, 498 GrGLenum* externalFormat, GrGLenum* externalType) const; 499 500 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*); 501 void initGLSL(const GrGLContextInfo&, const GrGLInterface*); 502 503 struct FormatWorkarounds { 504 bool fDisableSRGBRenderWithMSAAForMacAMD = false; 505 bool fDisableRGBA16FTexStorageForCrBug1008003 = false; 506 bool fDisableBGRATextureStorageForIntelWindowsES = false; 507 bool fDisableLuminance16F = false; 508 bool fDontDisableTexStorageOnAndroid = false; 509 bool fDisallowDirectRG8ReadPixels = false; 510 bool fDisallowBGRA8ReadPixels = false; 511 bool fDisallowR8ForPowerVRSGX54x = false; 512 bool fDisallowUnorm16Transfers = false; 513 bool fDisallowTextureUnorm16 = false; 514 bool fDisallowETC2Compression = false; 515 }; 516 517 void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&, 518 const GrGLInterface*, 519 GrShaderCaps*, FormatWorkarounds*); 520 521 void onApplyOptionsOverrides(const GrContextOptions& options) override; 522 523 bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override; 524 525 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&, 526 const GrGLInterface*); 527 void initBlendEqationSupport(const GrGLContextInfo&); 528 void initStencilSupport(const GrGLContextInfo&); 529 // This must be called after initFSAASupport(). 530 void initFormatTable(const GrGLContextInfo&, const GrGLInterface*, const FormatWorkarounds&); 531 void setupSampleCounts(const GrGLContextInfo&, const GrGLInterface*); 532 bool onSurfaceSupportsWritePixels(const GrSurface*) const override; 533 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, 534 const SkIRect& srcRect, const SkIPoint& dstPoint) const override; 535 GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override; 536 bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; 537 538 SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&, 539 GrColorType) const override; 540 541 GrSwizzle onGetReadSwizzle(const GrBackendFormat&, GrColorType) const override; 542 543 GrDstSampleFlags onGetDstSampleFlagsForProxy(const GrRenderTargetProxy*) const override; 544 545 bool onSupportsDynamicMSAA(const GrRenderTargetProxy*) const override; 546 547 GrGLStandard fStandard = kNone_GrGLStandard; 548 549 SkTArray<GrGLFormat, true> fStencilFormats; 550 551 int fMaxFragmentUniformVectors = 0; 552 553 MSFBOType fMSFBOType = kNone_MSFBOType; 554 InvalidateFBType fInvalidateFBType = kNone_InvalidateFBType; 555 MapBufferType fMapBufferType = kNone_MapBufferType; 556 TransferBufferType fTransferBufferType = TransferBufferType::kNone; 557 FenceType fFenceType = FenceType::kNone; 558 MultiDrawType fMultiDrawType = MultiDrawType::kNone; 559 560 bool fPackFlipYSupport : 1; 561 bool fTextureUsageSupport : 1; 562 bool fImagingSupport : 1; 563 bool fVertexArrayObjectSupport : 1; 564 bool fDebugSupport : 1; 565 bool fES2CompatibilitySupport : 1; 566 bool fDrawRangeElementsSupport : 1; 567 bool fBaseVertexBaseInstanceSupport : 1; 568 bool fIsCoreProfile : 1; 569 bool fBindFragDataLocationSupport : 1; 570 bool fBindUniformLocationSupport : 1; 571 bool fRectangleTextureSupport : 1; 572 bool fMipmapLevelControlSupport : 1; 573 bool fMipmapLodControlSupport : 1; 574 bool fUseBufferDataNullHint : 1; 575 bool fClearTextureSupport : 1; 576 bool fProgramBinarySupport : 1; 577 bool fProgramParameterSupport : 1; 578 bool fSamplerObjectSupport : 1; 579 bool fUseSamplerObjects : 1; 580 bool fTextureSwizzleSupport : 1; 581 bool fTiledRenderingSupport : 1; 582 bool fFBFetchRequiresEnablePerSample : 1; 583 bool fSRGBWriteControl : 1; 584 bool fSkipErrorChecks : 1; 585 bool fClientCanDisableMultisample : 1; 586 587 // Driver workarounds 588 bool fDoManualMipmapping : 1; 589 bool fClearToBoundaryValuesIsBroken : 1; 590 bool fDrawArraysBaseVertexIsBroken : 1; 591 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1; 592 bool fUseDrawInsteadOfAllRenderTargetWrites : 1; 593 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1; 594 bool fDontSetBaseOrMaxLevelForExternalTextures : 1; 595 bool fNeverDisableColorWrites : 1; 596 bool fMustSetAnyTexParameterToEnableMipmapping : 1; 597 bool fAllowBGRA8CopyTexSubImage : 1; 598 bool fDisallowDynamicMSAA : 1; 599 bool fMustResetBlendFuncBetweenDualSourceAndDisable : 1; 600 bool fBindTexture0WhenChangingTextureFBOMultisampleCount : 1; 601 bool fRebindColorAttachmentAfterCheckFramebufferStatus : 1; 602 int fMaxInstancesPerDrawWithoutCrashing = 0; 603 604 uint32_t fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag; 605 606 struct ReadPixelsFormat { ReadPixelsFormatReadPixelsFormat607 ReadPixelsFormat() : fFormat(0), fType(0) {} 608 GrGLenum fFormat; 609 GrGLenum fType; 610 }; 611 612 /** Number type of the components (with out considering number of bits.) */ 613 enum class FormatType { 614 kUnknown, 615 kNormalizedFixedPoint, 616 kFloat, 617 }; 618 619 // ColorTypeInfo for a specific format 620 struct ColorTypeInfo { 621 GrColorType fColorType = GrColorType::kUnknown; 622 enum { 623 kUploadData_Flag = 0x1, 624 // Does Ganesh itself support rendering to this colorType & format pair. Renderability 625 // still additionally depends on if the format can be an FBO color attachment. 626 kRenderable_Flag = 0x2, 627 }; 628 uint32_t fFlags = 0; 629 630 GrSwizzle fReadSwizzle; 631 GrSwizzle fWriteSwizzle; 632 633 struct ExternalIOFormats { 634 GrColorType fColorType = GrColorType::kUnknown; 635 636 /** The external format and type are to be used when uploading/downloading data using 637 data of fColorType and uploading to a texture of a given GrGLFormat and its 638 intended GrColorType. The fExternalTexImageFormat is the format to use for TexImage 639 calls. The fExternalReadFormat is used when calling ReadPixels. If either is zero 640 that signals that either TexImage or ReadPixels is not supported for the combination 641 of format and color types. */ 642 GrGLenum fExternalType = 0; 643 GrGLenum fExternalTexImageFormat = 0; 644 GrGLenum fExternalReadFormat = 0; 645 /** 646 * Must check whether GL_IMPLEMENTATION_COLOR_READ_FORMAT and _TYPE match 647 * fExternalReadFormat and fExternalType before using with glReadPixels. 648 */ 649 bool fRequiresImplementationReadQuery = false; 650 }; 651 externalFormatColorTypeInfo652 GrGLenum externalFormat(GrColorType externalColorType, ExternalFormatUsage usage, 653 bool haveQueriedImplementationReadFormat) const { 654 for (int i = 0; i < fExternalIOFormatCount; ++i) { 655 if (fExternalIOFormats[i].fColorType == externalColorType) { 656 if (usage == kTexImage_ExternalFormatUsage) { 657 return fExternalIOFormats[i].fExternalTexImageFormat; 658 } else { 659 SkASSERT(usage == kReadPixels_ExternalFormatUsage); 660 if (!haveQueriedImplementationReadFormat && 661 fExternalIOFormats[i].fRequiresImplementationReadQuery) { 662 return 0; 663 } 664 return fExternalIOFormats[i].fExternalReadFormat; 665 } 666 } 667 } 668 return 0; 669 } 670 externalTypeColorTypeInfo671 GrGLenum externalType(GrColorType externalColorType) const { 672 for (int i = 0; i < fExternalIOFormatCount; ++i) { 673 if (fExternalIOFormats[i].fColorType == externalColorType) { 674 return fExternalIOFormats[i].fExternalType; 675 } 676 } 677 return 0; 678 } 679 680 std::unique_ptr<ExternalIOFormats[]> fExternalIOFormats; 681 int fExternalIOFormatCount = 0; 682 }; 683 684 struct FormatInfo { colorTypeFlagsFormatInfo685 uint32_t colorTypeFlags(GrColorType colorType) const { 686 for (int i = 0; i < fColorTypeInfoCount; ++i) { 687 if (fColorTypeInfos[i].fColorType == colorType) { 688 return fColorTypeInfos[i].fFlags; 689 } 690 } 691 return 0; 692 } 693 externalFormatFormatInfo694 GrGLenum externalFormat(GrColorType surfaceColorType, GrColorType externalColorType, 695 ExternalFormatUsage usage) const { 696 for (int i = 0; i < fColorTypeInfoCount; ++i) { 697 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 698 return fColorTypeInfos[i].externalFormat(externalColorType, usage, 699 fHaveQueriedImplementationReadSupport); 700 } 701 } 702 return 0; 703 } 704 externalTypeFormatInfo705 GrGLenum externalType(GrColorType surfaceColorType, GrColorType externalColorType) const { 706 for (int i = 0; i < fColorTypeInfoCount; ++i) { 707 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 708 return fColorTypeInfos[i].externalType(externalColorType); 709 } 710 } 711 return 0; 712 } 713 714 enum { 715 kTexturable_Flag = 0x01, 716 /** kFBOColorAttachment means that even if the format cannot be a GrRenderTarget, we can 717 still attach it to a FBO for blitting or reading pixels. */ 718 kFBOColorAttachment_Flag = 0x02, 719 kFBOColorAttachmentWithMSAA_Flag = 0x04, 720 kUseTexStorage_Flag = 0x08, 721 /** 722 * Are pixel buffer objects supported in/out of this format? Ignored if PBOs are not 723 * supported at all. 724 */ 725 kTransfers_Flag = 0x10, 726 }; 727 uint32_t fFlags = 0; 728 729 FormatType fFormatType = FormatType::kUnknown; 730 731 // Not defined for uncompressed formats. Passed to glCompressedTexImage... 732 GrGLenum fCompressedInternalFormat = 0; 733 734 // Value to uses as the "internalformat" argument to glTexImage or glTexStorage. It is 735 // initialized in coordination with the presence/absence of the kUseTexStorage flag. In 736 // other words, it is only guaranteed to be compatible with glTexImage if the flag is not 737 // set and or with glTexStorage if the flag is set. 738 GrGLenum fInternalFormatForTexImageOrStorage = 0; 739 740 // Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample... 741 GrGLenum fInternalFormatForRenderbuffer = 0; 742 743 // Default values to use along with fInternalFormatForTexImageOrStorage for function 744 // glTexImage2D when not input providing data (passing nullptr) or when clearing it by 745 // uploading a block of solid color data. Not defined for compressed formats. 746 GrGLenum fDefaultExternalFormat = 0; 747 GrGLenum fDefaultExternalType = 0; 748 // When the above two values are used to initialize a texture by uploading cleared data to 749 // it the data should be of this color type. 750 GrColorType fDefaultColorType = GrColorType::kUnknown; 751 752 bool fHaveQueriedImplementationReadSupport = false; 753 754 enum { 755 // This indicates that a stencil format has not yet been determined for the config. 756 kUnknown_StencilIndex = -1, 757 // This indicates that there is no supported stencil format for the config. 758 kUnsupported_StencilFormatIndex = -2 759 }; 760 761 // Index fStencilFormats. 762 int fStencilFormatIndex = kUnknown_StencilIndex; 763 764 SkTDArray<int> fColorSampleCounts; 765 766 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos; 767 int fColorTypeInfoCount = 0; 768 }; 769 770 FormatInfo fFormatTable[kGrGLColorFormatCount]; 771 getFormatInfo(GrGLFormat format)772 FormatInfo& getFormatInfo(GrGLFormat format) { return fFormatTable[static_cast<int>(format)]; } getFormatInfo(GrGLFormat format)773 const FormatInfo& getFormatInfo(GrGLFormat format) const { 774 return fFormatTable[static_cast<int>(format)]; 775 } 776 777 GrGLFormat fColorTypeToFormatTable[kGrColorTypeCnt]; 778 void setColorTypeFormat(GrColorType, GrGLFormat); 779 780 using INHERITED = GrCaps; 781 }; 782 783 #endif 784