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/GrGLStencilAttachment.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 typedef GrGLStencilAttachment::Format StencilFormat; 33 34 /** 35 * The type of MSAA for FBOs supported. Different extensions have different 36 * semantics of how / when a resolve is performed. 37 */ 38 enum MSFBOType { 39 /** 40 * no support for MSAA FBOs 41 */ 42 kNone_MSFBOType = 0, 43 /** 44 * OpenGL 3.0+, OpenGL ES 3.0+, GL_ARB_framebuffer_object, 45 * GL_CHROMIUM_framebuffer_multisample, GL_ANGLE_framebuffer_multisample, 46 * or GL_EXT_framebuffer_multisample 47 */ 48 kStandard_MSFBOType, 49 /** 50 * GL_APPLE_framebuffer_multisample ES extension 51 */ 52 kES_Apple_MSFBOType, 53 /** 54 * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers. 55 * Instead the texture is multisampled when bound to the FBO and then resolved automatically 56 * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call 57 * GR_GL_MAX_SAMPLES_IMG). 58 */ 59 kES_IMG_MsToTexture_MSFBOType, 60 /** 61 * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard 62 * GL_MAX_SAMPLES value. 63 */ 64 kES_EXT_MsToTexture_MSFBOType, 65 66 kLast_MSFBOType = kES_EXT_MsToTexture_MSFBOType 67 }; 68 69 enum BlitFramebufferFlags { 70 kNoSupport_BlitFramebufferFlag = 1 << 0, 71 kNoScalingOrMirroring_BlitFramebufferFlag = 1 << 1, 72 kResolveMustBeFull_BlitFrambufferFlag = 1 << 2, 73 kNoMSAADst_BlitFramebufferFlag = 1 << 3, 74 kNoFormatConversion_BlitFramebufferFlag = 1 << 4, 75 kNoFormatConversionForMSAASrc_BlitFramebufferFlag = 1 << 5, 76 kRectsMustMatchForMSAASrc_BlitFramebufferFlag = 1 << 6, 77 }; 78 79 enum InvalidateFBType { 80 kNone_InvalidateFBType, 81 kDiscard_InvalidateFBType, //<! glDiscardFramebuffer() 82 kInvalidate_InvalidateFBType, //<! glInvalidateFramebuffer() 83 84 kLast_InvalidateFBType = kInvalidate_InvalidateFBType 85 }; 86 87 enum MapBufferType { 88 kNone_MapBufferType, 89 kMapBuffer_MapBufferType, // glMapBuffer() 90 kMapBufferRange_MapBufferType, // glMapBufferRange() 91 kChromium_MapBufferType, // GL_CHROMIUM_map_sub 92 93 kLast_MapBufferType = kChromium_MapBufferType, 94 }; 95 96 enum TransferBufferType { 97 kNone_TransferBufferType, 98 kPBO_TransferBufferType, // ARB_pixel_buffer_object 99 kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object 100 101 kLast_TransferBufferType = kChromium_TransferBufferType, 102 }; 103 104 /** 105 * Initializes the GrGLCaps to the set of features supported in the current 106 * OpenGL context accessible via ctxInfo. 107 */ 108 GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo, 109 const GrGLInterface* glInterface); 110 111 bool isFormatSRGB(const GrBackendFormat&) const override; 112 bool isFormatCompressed(const GrBackendFormat&) const override; 113 114 bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override; 115 bool isFormatTexturable(const GrBackendFormat&) const override; 116 bool isFormatTexturable(GrGLFormat) const; 117 118 bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, 119 int sampleCount = 1) const override; 120 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override; isFormatRenderable(GrGLFormat format,int sampleCount)121 bool isFormatRenderable(GrGLFormat format, int sampleCount) const { 122 return sampleCount <= this->maxRenderTargetSampleCount(format); 123 } 124 getRenderTargetSampleCount(int requestedCount,const GrBackendFormat & format)125 int getRenderTargetSampleCount(int requestedCount, 126 const GrBackendFormat& format) const override { 127 return this->getRenderTargetSampleCount(requestedCount, format.asGLFormat()); 128 } 129 int getRenderTargetSampleCount(int requestedCount, GrGLFormat) const; 130 maxRenderTargetSampleCount(const GrBackendFormat & format)131 int maxRenderTargetSampleCount(const GrBackendFormat& format) const override { 132 return this->maxRenderTargetSampleCount(format.asGLFormat()); 133 } 134 int maxRenderTargetSampleCount(GrGLFormat) const; 135 136 bool isFormatCopyable(const GrBackendFormat&) const override; 137 138 bool canFormatBeFBOColorAttachment(GrGLFormat) const; 139 getFormatFromColorType(GrColorType colorType)140 GrGLFormat getFormatFromColorType(GrColorType colorType) const { 141 int idx = static_cast<int>(colorType); 142 return fColorTypeToFormatTable[idx]; 143 } 144 formatSizedInternalFormat(GrGLFormat format)145 GrGLenum formatSizedInternalFormat(GrGLFormat format) const { 146 return this->getFormatInfo(format).fSizedInternalFormat; 147 } 148 149 void getTexImageFormats(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 150 GrColorType memoryColorType, GrGLenum* internalFormat, 151 GrGLenum* externalFormat, GrGLenum* externalType) const; 152 153 void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 154 GrColorType memoryColorType, GrGLenum* externalFormat, 155 GrGLenum* externalType) const; 156 157 /** 158 * Gets an array of legal stencil formats. These formats are not guaranteed 159 * to be supported by the driver but are legal GLenum names given the GL 160 * version and extensions supported. 161 */ stencilFormats()162 const SkTArray<StencilFormat, true>& stencilFormats() const { 163 return fStencilFormats; 164 } 165 166 bool formatSupportsTexStorage(GrGLFormat) const; 167 168 /** 169 * Gets the internal format to use with glTexImage...() and glTexStorage...(). May be sized or 170 * base depending upon the GL. Not applicable to compressed textures. 171 */ getTexImageInternalFormat(GrGLFormat format)172 GrGLenum getTexImageInternalFormat(GrGLFormat format) const { 173 return this->getFormatInfo(format).fInternalFormatForTexImage; 174 } 175 176 /** 177 * Gets the internal format to use with glRenderbufferStorageMultisample...(). May be sized or 178 * base depending upon the GL. Not applicable to compressed textures. 179 */ getRenderbufferInternalFormat(GrGLFormat format)180 GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const { 181 return this->getFormatInfo(format).fInternalFormatForRenderbuffer; 182 } 183 getSizedInternalFormat(GrGLFormat format)184 GrGLenum getSizedInternalFormat(GrGLFormat format) const { 185 return this->getFormatInfo(format).fSizedInternalFormat; 186 } 187 getBaseInternalFormat(GrGLFormat format)188 GrGLenum getBaseInternalFormat(GrGLFormat format) const { 189 return this->getFormatInfo(format).fBaseInternalFormat; 190 } 191 192 /** 193 * Gets the default external type to use with glTex[Sub]Image... when the data pointer is null. 194 */ getFormatDefaultExternalType(GrGLFormat format)195 GrGLenum getFormatDefaultExternalType(GrGLFormat format) const { 196 return this->getFormatInfo(format).fDefaultExternalType; 197 } 198 199 /** 200 * Has a stencil format index been found for the format (or we've found that no format works). 201 */ hasStencilFormatBeenDeterminedForFormat(GrGLFormat format)202 bool hasStencilFormatBeenDeterminedForFormat(GrGLFormat format) const { 203 return this->getFormatInfo(format).fStencilFormatIndex != FormatInfo::kUnknown_StencilIndex; 204 } 205 206 /** 207 * Gets the stencil format index for the format. This assumes 208 * hasStencilFormatBeenDeterminedForFormat has already been checked. Returns a value < 0 if 209 * no stencil format is supported with the format. Otherwise, returned index refers to the array 210 * returned by stencilFormats(). 211 */ getStencilFormatIndexForFormat(GrGLFormat format)212 int getStencilFormatIndexForFormat(GrGLFormat format) const { 213 SkASSERT(this->hasStencilFormatBeenDeterminedForFormat(format)); 214 return this->getFormatInfo(format).fStencilFormatIndex; 215 } 216 217 /** 218 * If index is >= 0 this records an index into stencilFormats() as the best stencil format for 219 * the format. If < 0 it records that the format has no supported stencil format index. 220 */ 221 void setStencilFormatIndexForFormat(GrGLFormat, int index); 222 223 /** 224 * Call to note that a GrGLFormat has been verified as a valid color attachment. This may save 225 * future calls to glCheckFramebufferStatus using isFormatVerifiedColorAttachment(). 226 */ markFormatAsValidColorAttachment(GrGLFormat format)227 void markFormatAsValidColorAttachment(GrGLFormat format) { 228 this->getFormatInfo(format).fVerifiedColorAttachment = true; 229 } 230 231 /** 232 * Call to check whether a format has been verified as a valid color attachment. 233 */ isFormatVerifiedColorAttachment(GrGLFormat format)234 bool isFormatVerifiedColorAttachment(GrGLFormat format) const { 235 return this->getFormatInfo(format).fVerifiedColorAttachment; 236 } 237 238 /** 239 * Reports the type of MSAA FBO support. 240 */ msFBOType()241 MSFBOType msFBOType() const { return fMSFBOType; } 242 243 /** 244 * Does the preferred MSAA FBO extension have MSAA renderbuffers? 245 */ usesMSAARenderBuffers()246 bool usesMSAARenderBuffers() const { 247 return kNone_MSFBOType != fMSFBOType && 248 kES_IMG_MsToTexture_MSFBOType != fMSFBOType && 249 kES_EXT_MsToTexture_MSFBOType != fMSFBOType; 250 } 251 252 /** 253 * What functionality is supported by glBlitFramebuffer. 254 */ blitFramebufferSupportFlags()255 uint32_t blitFramebufferSupportFlags() const { return fBlitFramebufferFlags; } 256 257 /** 258 * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and 259 * then implicitly resolved when read. 260 */ usesImplicitMSAAResolve()261 bool usesImplicitMSAAResolve() const { 262 return kES_IMG_MsToTexture_MSFBOType == fMSFBOType || 263 kES_EXT_MsToTexture_MSFBOType == fMSFBOType; 264 } 265 invalidateFBType()266 InvalidateFBType invalidateFBType() const { return fInvalidateFBType; } 267 268 /// What type of buffer mapping is supported? mapBufferType()269 MapBufferType mapBufferType() const { return fMapBufferType; } 270 271 /// What type of transfer buffer is supported? transferBufferType()272 TransferBufferType transferBufferType() const { return fTransferBufferType; } 273 274 /// The maximum number of fragment uniform vectors (GLES has min. 16). maxFragmentUniformVectors()275 int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; } 276 277 /// Is there support for GL_PACK_REVERSE_ROW_ORDER packFlipYSupport()278 bool packFlipYSupport() const { return fPackFlipYSupport; } 279 280 /// Is there support for texture parameter GL_TEXTURE_USAGE textureUsageSupport()281 bool textureUsageSupport() const { return fTextureUsageSupport; } 282 283 /// Is GL_ALPHA8 renderable alpha8IsRenderable()284 bool alpha8IsRenderable() const { return fAlpha8IsRenderable; } 285 286 /// Is GL_ARB_IMAGING supported imagingSupport()287 bool imagingSupport() const { return fImagingSupport; } 288 289 /// Is there support for Vertex Array Objects? vertexArrayObjectSupport()290 bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; } 291 292 /// Is there support for GL_KHR_debug? debugSupport()293 bool debugSupport() const { return fDebugSupport; } 294 295 /// Is there support for ES2 compatability? ES2CompatibilitySupport()296 bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; } 297 298 /// Is there support for glDraw*Instanced? drawInstancedSupport()299 bool drawInstancedSupport() const { return fDrawInstancedSupport; } 300 301 /// Is there support for glDraw*Indirect? Note that the baseInstance fields of indirect draw 302 /// commands cannot be used unless we have base instance support. drawIndirectSupport()303 bool drawIndirectSupport() const { return fDrawIndirectSupport; } 304 305 /// Is there support for glMultiDraw*Indirect? Note that the baseInstance fields of indirect 306 /// draw commands cannot be used unless we have base instance support. multiDrawIndirectSupport()307 bool multiDrawIndirectSupport() const { return fMultiDrawIndirectSupport; } 308 309 /// Is there support for glDrawRangeElements? drawRangeElementsSupport()310 bool drawRangeElementsSupport() const { return fDrawRangeElementsSupport; } 311 312 /// Are the baseInstance fields supported in indirect draw commands? baseInstanceSupport()313 bool baseInstanceSupport() const { return fBaseInstanceSupport; } 314 315 /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content. useNonVBOVertexAndIndexDynamicData()316 bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; } 317 318 SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; 319 320 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, 321 const GrBackendFormat& surfaceFormat, 322 GrColorType srcColorType) const override; 323 isCoreProfile()324 bool isCoreProfile() const { return fIsCoreProfile; } 325 bindFragDataLocationSupport()326 bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; } 327 bindUniformLocationSupport()328 bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; } 329 330 /// Are textures with GL_TEXTURE_RECTANGLE type supported. rectangleTextureSupport()331 bool rectangleTextureSupport() const { return fRectangleTextureSupport; } 332 mipMapLevelAndLodControlSupport()333 bool mipMapLevelAndLodControlSupport() const { return fMipMapLevelAndLodControlSupport; } 334 doManualMipmapping()335 bool doManualMipmapping() const { return fDoManualMipmapping; } 336 337 void onDumpJSON(SkJSONWriter*) const override; 338 rgba8888PixelsOpsAreSlow()339 bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; } partialFBOReadIsSlow()340 bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; } rgbaToBgraReadbackConversionsAreSlow()341 bool rgbaToBgraReadbackConversionsAreSlow() const { 342 return fRGBAToBGRAReadbackConversionsAreSlow; 343 } 344 useBufferDataNullHint()345 bool useBufferDataNullHint() const { return fUseBufferDataNullHint; } 346 347 // Certain Intel GPUs on Mac fail to clear if the glClearColor is made up of only 1s and 0s. clearToBoundaryValuesIsBroken()348 bool clearToBoundaryValuesIsBroken() const { return fClearToBoundaryValuesIsBroken; } 349 350 /// glClearTex(Sub)Image support clearTextureSupport()351 bool clearTextureSupport() const { return fClearTextureSupport; } 352 353 // Adreno/MSAA drops a draw on the imagefiltersbase GM if the base vertex param to 354 // glDrawArrays is nonzero. 355 // https://bugs.chromium.org/p/skia/issues/detail?id=6650 drawArraysBaseVertexIsBroken()356 bool drawArraysBaseVertexIsBroken() const { return fDrawArraysBaseVertexIsBroken; } 357 358 // If true then we must use an intermediate surface to perform partial updates to unorm textures 359 // that have ever been bound to a FBO. disallowTexSubImageForUnormConfigTexturesEverBoundToFBO()360 bool disallowTexSubImageForUnormConfigTexturesEverBoundToFBO() const { 361 return fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO; 362 } 363 364 // Use an intermediate surface to write pixels (full or partial overwrite) to into a texture 365 // that is bound to an FBO. useDrawInsteadOfAllRenderTargetWrites()366 bool useDrawInsteadOfAllRenderTargetWrites() const { 367 return fUseDrawInsteadOfAllRenderTargetWrites; 368 } 369 370 // At least some Adreno 3xx drivers draw lines incorrectly after drawing non-lines. Toggling 371 // face culling on and off seems to resolve this. requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines()372 bool requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() const { 373 return fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines; 374 } 375 376 // Some Adreno drivers refuse to ReadPixels from an MSAA buffer that has stencil attached. detachStencilFromMSAABuffersBeforeReadPixels()377 bool detachStencilFromMSAABuffersBeforeReadPixels() const { 378 return fDetachStencilFromMSAABuffersBeforeReadPixels; 379 } 380 381 // Older Android versions seem to have an issue with setting GL_TEXTURE_BASE_LEVEL or 382 // GL_TEXTURE_MAX_LEVEL for GL_TEXTURE_EXTERNAL_OES textures. dontSetBaseOrMaxLevelForExternalTextures()383 bool dontSetBaseOrMaxLevelForExternalTextures() const { 384 return fDontSetBaseOrMaxLevelForExternalTextures; 385 } 386 387 // PowerVRGX6250 drops every pixel if we modify the sample mask while color writes are disabled. neverDisableColorWrites()388 bool neverDisableColorWrites() const { return fNeverDisableColorWrites; } 389 390 // Returns the observed maximum number of instances the driver can handle in a single draw call 391 // without crashing, or 'pendingInstanceCount' if this workaround is not necessary. 392 // NOTE: the return value may be larger than pendingInstanceCount. maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount)393 int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const { 394 return (fMaxInstancesPerDrawWithoutCrashing) 395 ? fMaxInstancesPerDrawWithoutCrashing : pendingInstanceCount; 396 } 397 398 bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer, 399 const GrTextureType* dstTypeIfTexture, 400 GrGLFormat srcFormat, bool srcHasMSAARenderBuffer, 401 const GrTextureType* srcTypeIfTexture) const; 402 bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, 403 const GrTextureType* dstTypeIfTexture, 404 GrGLFormat srcFormat, int srcSampleCnt, 405 const GrTextureType* srcTypeIfTexture, 406 const SkRect& srcBounds, bool srcBoundsExact, 407 const SkIRect& srcRect, const SkIPoint& dstPoint) const; 408 bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const; 409 410 DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, 411 GrColorType) const override; 412 programBinarySupport()413 bool programBinarySupport() const { return fProgramBinarySupport; } programParameterSupport()414 bool programParameterSupport() const { return fProgramParameterSupport; } 415 samplerObjectSupport()416 bool samplerObjectSupport() const { return fSamplerObjectSupport; } 417 fbFetchRequiresEnablePerSample()418 bool fbFetchRequiresEnablePerSample() const { return fFBFetchRequiresEnablePerSample; } 419 420 GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&, 421 bool isAlphaChannel) const override; 422 423 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; 424 425 bool canClearTextureOnCreation() const override; 426 427 GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override; 428 GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override; 429 430 #if GR_TEST_UTILS standard()431 GrGLStandard standard() const { return fStandard; } 432 433 std::vector<TestFormatColorTypeCombination> getTestingCombinations() const override; 434 #endif 435 436 private: 437 enum ExternalFormatUsage { 438 kTexImage_ExternalFormatUsage, 439 kReadPixels_ExternalFormatUsage, 440 }; 441 void getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, 442 GrColorType memoryColorType, ExternalFormatUsage usage, 443 GrGLenum* externalFormat, GrGLenum* externalType) const; 444 445 void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*); 446 void initGLSL(const GrGLContextInfo&, const GrGLInterface*); 447 bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*); 448 449 struct FormatWorkarounds { 450 bool fDisableTextureRedForMesa = false; 451 bool fDisableSRGBRenderWithMSAAForMacAMD = false; 452 bool fDisablePerFormatTextureStorageForCommandBufferES2 = false; 453 bool fDisableNonRedSingleChannelTexStorageForANGLEGL = false; 454 bool fDisableBGRATextureStorageForIntelWindowsES = false; 455 bool fDisableRGB8ForMali400 = false; 456 bool fDisableLuminance16F = false; 457 }; 458 459 void applyDriverCorrectnessWorkarounds(const GrGLContextInfo&, const GrContextOptions&, 460 GrShaderCaps*, FormatWorkarounds*); 461 462 void onApplyOptionsOverrides(const GrContextOptions& options) override; 463 464 bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override; 465 466 void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&, 467 const GrGLInterface*); 468 void initBlendEqationSupport(const GrGLContextInfo&); 469 void initStencilSupport(const GrGLContextInfo&); 470 // This must be called after initFSAASupport(). 471 void initFormatTable(const GrGLContextInfo&, const GrGLInterface*, const FormatWorkarounds&); 472 void setupSampleCounts(const GrGLContextInfo&, const GrGLInterface*); 473 bool onSurfaceSupportsWritePixels(const GrSurface*) const override; 474 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, 475 const SkIRect& srcRect, const SkIPoint& dstPoint) const override; 476 GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override; 477 GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override; 478 bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; 479 480 SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&, 481 GrColorType) const override; 482 483 GrGLStandard fStandard; 484 485 SkTArray<StencilFormat, true> fStencilFormats; 486 487 int fMaxFragmentUniformVectors; 488 489 MSFBOType fMSFBOType; 490 InvalidateFBType fInvalidateFBType; 491 MapBufferType fMapBufferType; 492 TransferBufferType fTransferBufferType; 493 494 bool fPackFlipYSupport : 1; 495 bool fTextureUsageSupport : 1; 496 bool fAlpha8IsRenderable: 1; 497 bool fImagingSupport : 1; 498 bool fVertexArrayObjectSupport : 1; 499 bool fDebugSupport : 1; 500 bool fES2CompatibilitySupport : 1; 501 bool fDrawInstancedSupport : 1; 502 bool fDrawIndirectSupport : 1; 503 bool fDrawRangeElementsSupport : 1; 504 bool fMultiDrawIndirectSupport : 1; 505 bool fBaseInstanceSupport : 1; 506 bool fUseNonVBOVertexAndIndexDynamicData : 1; 507 bool fIsCoreProfile : 1; 508 bool fBindFragDataLocationSupport : 1; 509 bool fRGBA8888PixelsOpsAreSlow : 1; 510 bool fPartialFBOReadIsSlow : 1; 511 bool fBindUniformLocationSupport : 1; 512 bool fRectangleTextureSupport : 1; 513 bool fMipMapLevelAndLodControlSupport : 1; 514 bool fRGBAToBGRAReadbackConversionsAreSlow : 1; 515 bool fUseBufferDataNullHint : 1; 516 bool fClearTextureSupport : 1; 517 bool fProgramBinarySupport : 1; 518 bool fProgramParameterSupport : 1; 519 bool fSamplerObjectSupport : 1; 520 bool fFBFetchRequiresEnablePerSample : 1; 521 522 // Driver workarounds 523 bool fDoManualMipmapping : 1; 524 bool fClearToBoundaryValuesIsBroken : 1; 525 bool fDrawArraysBaseVertexIsBroken : 1; 526 bool fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO : 1; 527 bool fUseDrawInsteadOfAllRenderTargetWrites : 1; 528 bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1; 529 bool fDetachStencilFromMSAABuffersBeforeReadPixels : 1; 530 bool fDontSetBaseOrMaxLevelForExternalTextures : 1; 531 bool fNeverDisableColorWrites : 1; 532 int fMaxInstancesPerDrawWithoutCrashing; 533 534 uint32_t fBlitFramebufferFlags; 535 536 struct ReadPixelsFormat { ReadPixelsFormatReadPixelsFormat537 ReadPixelsFormat() : fFormat(0), fType(0) {} 538 GrGLenum fFormat; 539 GrGLenum fType; 540 }; 541 542 /** Number type of the components (with out considering number of bits.) */ 543 enum class FormatType { 544 kUnknown, 545 kNormalizedFixedPoint, 546 kFloat, 547 }; 548 549 // ColorTypeInfo for a specific format 550 struct ColorTypeInfo { 551 GrColorType fColorType = GrColorType::kUnknown; 552 enum { 553 kUploadData_Flag = 0x1, 554 // Does Ganesh itself support rendering to this colorType & format pair. Renderability 555 // still additionally depends on if the format can be an FBO color attachment. 556 kRenderable_Flag = 0x2, 557 }; 558 uint32_t fFlags = 0; 559 560 GrSwizzle fTextureSwizzle; 561 GrSwizzle fOutputSwizzle; 562 563 struct ExternalIOFormats { 564 GrColorType fColorType = GrColorType::kUnknown; 565 566 /** The external format and type are to be used when uploading/downloading data using 567 data of fColorType and uploading to a texture of a given GrGLFormat and its 568 intended GrColorType. The fExternalTexImageFormat is the format to use for TexImage 569 calls. The fExternalReadFormat is used when calling ReadPixels. If either is zero 570 that signals that either TexImage or ReadPixels is not supported for the combination 571 of format and color types. */ 572 GrGLenum fExternalType = 0; 573 GrGLenum fExternalTexImageFormat = 0; 574 GrGLenum fExternalReadFormat = 0; 575 }; 576 externalFormatColorTypeInfo577 GrGLenum externalFormat(GrColorType externalColorType, ExternalFormatUsage usage) const { 578 for (int i = 0; i < fExternalIOFormatCount; ++i) { 579 if (fExternalIOFormats[i].fColorType == externalColorType) { 580 if (usage == kTexImage_ExternalFormatUsage) { 581 return fExternalIOFormats[i].fExternalTexImageFormat; 582 } else { 583 SkASSERT(usage == kReadPixels_ExternalFormatUsage); 584 return fExternalIOFormats[i].fExternalReadFormat; 585 } 586 } 587 } 588 return 0; 589 } 590 externalTypeColorTypeInfo591 GrGLenum externalType(GrColorType externalColorType) const { 592 for (int i = 0; i < fExternalIOFormatCount; ++i) { 593 if (fExternalIOFormats[i].fColorType == externalColorType) { 594 return fExternalIOFormats[i].fExternalType; 595 } 596 } 597 return 0; 598 } 599 600 std::unique_ptr<ExternalIOFormats[]> fExternalIOFormats; 601 int fExternalIOFormatCount = 0; 602 }; 603 604 struct FormatInfo { colorTypeFlagsFormatInfo605 uint32_t colorTypeFlags(GrColorType colorType) const { 606 for (int i = 0; i < fColorTypeInfoCount; ++i) { 607 if (fColorTypeInfos[i].fColorType == colorType) { 608 return fColorTypeInfos[i].fFlags; 609 } 610 } 611 return 0; 612 } 613 externalFormatFormatInfo614 GrGLenum externalFormat(GrColorType surfaceColorType, GrColorType externalColorType, 615 ExternalFormatUsage usage) const { 616 for (int i = 0; i < fColorTypeInfoCount; ++i) { 617 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 618 return fColorTypeInfos[i].externalFormat(externalColorType, usage); 619 } 620 } 621 return 0; 622 } 623 externalTypeFormatInfo624 GrGLenum externalType(GrColorType surfaceColorType, GrColorType externalColorType) const { 625 for (int i = 0; i < fColorTypeInfoCount; ++i) { 626 if (fColorTypeInfos[i].fColorType == surfaceColorType) { 627 return fColorTypeInfos[i].externalType(externalColorType); 628 } 629 } 630 return 0; 631 } 632 633 enum { 634 kTexturable_Flag = 0x1, 635 /** kFBOColorAttachment means that even if the format cannot be a GrRenderTarget, we can 636 still attach it to a FBO for blitting or reading pixels. */ 637 kFBOColorAttachment_Flag = 0x2, 638 kFBOColorAttachmentWithMSAA_Flag = 0x4, 639 kCanUseTexStorage_Flag = 0x8, 640 }; 641 uint32_t fFlags = 0; 642 643 FormatType fFormatType = FormatType::kUnknown; 644 645 // Both compressed and uncompressed formats have base internal formats. 646 GrGLenum fBaseInternalFormat = 0; 647 648 // Not defined for compressed formats. 649 GrGLenum fSizedInternalFormat = 0; 650 651 // Not defined for uncompressed formats. Passed to glCompressedTexImage... 652 GrGLenum fCompressedInternalFormat = 0; 653 654 // Value to uses as the "internalformat" argument to glTexImage and glCompressedTexImage... 655 // Usually one of fBaseInternalFormat or fSizedInternalFormat but may vary depending on the 656 // particular format, GL version, extensions. 657 GrGLenum fInternalFormatForTexImage = 0; 658 659 // Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample... 660 // Usually one of fBaseInternalFormat or fSizedInternalFormat but may vary depending on the 661 // particular format, GL version, extensions. 662 GrGLenum fInternalFormatForRenderbuffer = 0; 663 664 // Default value to use along with fBaseInternalFormat for functions such as glTexImage2D 665 // when not input providing data (passing nullptr). Not defined for compressed formats. 666 GrGLenum fDefaultExternalType = 0; 667 668 enum { 669 // This indicates that a stencil format has not yet been determined for the config. 670 kUnknown_StencilIndex = -1, 671 // This indicates that there is no supported stencil format for the config. 672 kUnsupported_StencilFormatIndex = -2 673 }; 674 675 // Index fStencilFormats. 676 int fStencilFormatIndex = kUnknown_StencilIndex; 677 678 SkTDArray<int> fColorSampleCounts; 679 680 // verification of color attachment validity is done while flushing. Although only ever 681 // used in the (sole) rendering thread it can cause races if it is glommed into fFlags. 682 bool fVerifiedColorAttachment = false; 683 684 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos; 685 int fColorTypeInfoCount = 0; 686 }; 687 688 FormatInfo fFormatTable[kGrGLFormatCount]; 689 getFormatInfo(GrGLFormat format)690 FormatInfo& getFormatInfo(GrGLFormat format) { return fFormatTable[static_cast<int>(format)]; } getFormatInfo(GrGLFormat format)691 const FormatInfo& getFormatInfo(GrGLFormat format) const { 692 return fFormatTable[static_cast<int>(format)]; 693 } 694 695 GrGLFormat fColorTypeToFormatTable[kGrColorTypeCnt]; 696 void setColorTypeFormat(GrColorType, GrGLFormat); 697 698 typedef GrCaps INHERITED; 699 }; 700 701 #endif 702