* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/gpu/GrContextOptions.h"
#include "src/core/SkTSearch.h"
#include "src/core/SkTSort.h"
#include "src/gpu/GrRenderTargetProxyPriv.h"
#include "src/gpu/GrShaderCaps.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTextureProxyPriv.h"
#include "src/gpu/SkGr.h"
#include "src/gpu/gl/GrGLCaps.h"
#include "src/gpu/gl/GrGLContext.h"
#include "src/gpu/gl/GrGLRenderTarget.h"
#include "src/gpu/gl/GrGLTexture.h"
#include "src/utils/SkJSONWriter.h"
GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo,
const GrGLInterface* glInterface) : INHERITED(contextOptions) {
fStandard = ctxInfo.standard();
fStencilFormats.reset();
fMSFBOType = kNone_MSFBOType;
fInvalidateFBType = kNone_InvalidateFBType;
fMapBufferType = kNone_MapBufferType;
fTransferBufferType = kNone_TransferBufferType;
fMaxFragmentUniformVectors = 0;
fPackFlipYSupport = false;
fTextureUsageSupport = false;
fAlpha8IsRenderable = false;
fImagingSupport = false;
fVertexArrayObjectSupport = false;
fDebugSupport = false;
fES2CompatibilitySupport = false;
fDrawIndirectSupport = false;
fMultiDrawIndirectSupport = false;
fBaseInstanceSupport = false;
fIsCoreProfile = false;
fBindFragDataLocationSupport = false;
fRectangleTextureSupport = false;
fRGBA8888PixelsOpsAreSlow = false;
fPartialFBOReadIsSlow = false;
fMipMapLevelAndLodControlSupport = false;
fRGBAToBGRAReadbackConversionsAreSlow = false;
fUseBufferDataNullHint = false;
fDoManualMipmapping = false;
fClearToBoundaryValuesIsBroken = false;
fClearTextureSupport = false;
fDrawArraysBaseVertexIsBroken = false;
fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = false;
fUseDrawInsteadOfAllRenderTargetWrites = false;
fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
fDetachStencilFromMSAABuffersBeforeReadPixels = false;
fDontSetBaseOrMaxLevelForExternalTextures = false;
fNeverDisableColorWrites = false;
fProgramBinarySupport = false;
fProgramParameterSupport = false;
fSamplerObjectSupport = false;
fFBFetchRequiresEnablePerSample = false;
fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
fMaxInstancesPerDrawWithoutCrashing = 0;
fShaderCaps.reset(new GrShaderCaps(contextOptions));
this->init(contextOptions, ctxInfo, glInterface);
}
void GrGLCaps::init(const GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo,
const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
sk_ignore_unused_variable(standard);
GrGLVersion version = ctxInfo.version();
if (GR_IS_GR_GL(standard)) {
GrGLint max;
GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
fMaxFragmentUniformVectors = max / 4;
if (version >= GR_GL_VER(3, 2)) {
GrGLint profileMask;
GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
}
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
&fMaxFragmentUniformVectors);
}
if (fDriverBugWorkarounds.max_fragment_uniform_vectors_32) {
fMaxFragmentUniformVectors = SkMin32(fMaxFragmentUniformVectors, 32);
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
if (GR_IS_GR_GL(standard)) {
fWritePixelsRowBytesSupport = true;
fReadPixelsRowBytesSupport = true;
fPackFlipYSupport = false;
} else if (GR_IS_GR_GL_ES(standard)) {
fWritePixelsRowBytesSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_unpack_subimage");
fReadPixelsRowBytesSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_NV_pack_subimage");
fPackFlipYSupport =
ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
} else if (GR_IS_GR_WEBGL(standard)) {
fWritePixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
fReadPixelsRowBytesSupport = version >= GR_GL_VER(2, 0);
}
if (fDriverBugWorkarounds.pack_parameters_workaround_with_pack_buffer) {
fReadPixelsRowBytesSupport = false;
}
fTextureUsageSupport = GR_IS_GR_GL_ES(standard) &&
ctxInfo.hasExtension("GL_ANGLE_texture_usage");
if (GR_IS_GR_GL(standard)) {
fTextureBarrierSupport = version >= GR_GL_VER(4,5) ||
ctxInfo.hasExtension("GL_ARB_texture_barrier") ||
ctxInfo.hasExtension("GL_NV_texture_barrier");
} else if (GR_IS_GR_GL_ES(standard)) {
fTextureBarrierSupport = ctxInfo.hasExtension("GL_NV_texture_barrier");
}
if (GR_IS_GR_GL(standard)) {
fSampleLocationsSupport = version >= GR_GL_VER(3,2) ||
ctxInfo.hasExtension("GL_ARB_texture_multisample");
} else if (GR_IS_GR_GL_ES(standard)) {
fSampleLocationsSupport = version >= GR_GL_VER(3,1);
}
fImagingSupport = GR_IS_GR_GL(standard) &&
ctxInfo.hasExtension("GL_ARB_imaging");
if (((GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)) ||
ctxInfo.hasExtension("GL_ARB_invalidate_subdata"))) {
fInvalidateFBType = kInvalidate_InvalidateFBType;
} else if (ctxInfo.hasExtension("GL_EXT_discard_framebuffer")) {
fInvalidateFBType = kDiscard_InvalidateFBType;
}
if (GR_IS_GR_GL_ES(standard)) {
if (kARM_GrGLVendor == ctxInfo.vendor()) {
fUsePrimitiveRestart = version >= GR_GL_VER(3,0);
}
}
if (kARM_GrGLVendor == ctxInfo.vendor() ||
kImagination_GrGLVendor == ctxInfo.vendor() ||
kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
fPreferFullscreenClears = true;
}
if (GR_IS_GR_GL(standard)) {
fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_ARB_vertex_array_object") ||
ctxInfo.hasExtension("GL_APPLE_vertex_array_object");
} else if (GR_IS_GR_GL_ES(standard)) {
fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_vertex_array_object");
} else if (GR_IS_GR_WEBGL(standard)) {
fVertexArrayObjectSupport = version >= GR_GL_VER(2, 0) ||
ctxInfo.hasExtension("GL_OES_vertex_array_object") ||
ctxInfo.hasExtension("OES_vertex_array_object");
}
if (GR_IS_GR_GL(standard) && version >= GR_GL_VER(4,3)) {
fDebugSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
fDebugSupport = ctxInfo.hasExtension("GL_KHR_debug");
}
if (GR_IS_GR_GL(standard)) {
fES2CompatibilitySupport = ctxInfo.hasExtension("GL_ARB_ES2_compatibility");
}
else if (GR_IS_GR_GL_ES(standard)) {
fES2CompatibilitySupport = true;
} else if (GR_IS_GR_WEBGL(standard)) {
fES2CompatibilitySupport = true;
}
if (GR_IS_GR_GL(standard)) {
fMultisampleDisableSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
fMultisampleDisableSupport = ctxInfo.hasExtension("GL_EXT_multisample_compatibility");
}
if (GR_IS_GR_GL(standard)) {
fInstanceAttribSupport =
version >= GR_GL_VER(3, 2) ||
(ctxInfo.hasExtension("GL_ARB_draw_instanced") &&
ctxInfo.hasExtension("GL_ARB_instanced_arrays"));
} else if (GR_IS_GR_GL_ES(standard)) {
fInstanceAttribSupport =
version >= GR_GL_VER(3, 0) ||
(ctxInfo.hasExtension("GL_EXT_draw_instanced") &&
ctxInfo.hasExtension("GL_EXT_instanced_arrays"));
} else if (GR_IS_GR_WEBGL(standard)) {
fInstanceAttribSupport = version >= GR_GL_VER(2, 0);
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0)) {
fBindFragDataLocationSupport = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) && ctxInfo.hasExtension("GL_EXT_blend_func_extended")) {
fBindFragDataLocationSupport = true;
}
}
fBindUniformLocationSupport = ctxInfo.hasExtension("GL_CHROMIUM_bind_uniform_location");
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 1) || ctxInfo.hasExtension("GL_ARB_texture_rectangle") ||
ctxInfo.hasExtension("GL_ANGLE_texture_rectangle")) {
fRectangleTextureSupport = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fRectangleTextureSupport = ctxInfo.hasExtension("GL_ANGLE_texture_rectangle") &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
}
if (GR_IS_GR_GL(standard)) {
if (version < GR_GL_VER(1, 3) && !ctxInfo.hasExtension("GL_ARB_texture_border_clamp")) {
fClampToBorderSupport = false;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version < GR_GL_VER(3, 2) && !ctxInfo.hasExtension("GL_EXT_texture_border_clamp") &&
!ctxInfo.hasExtension("GL_NV_texture_border_clamp") &&
!ctxInfo.hasExtension("GL_OES_texture_border_clamp")) {
fClampToBorderSupport = false;
}
} else if (GR_IS_GR_WEBGL(standard)) {
fClampToBorderSupport = false;
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) {
this->fShaderCaps->fTextureSwizzleAppliedInShader = false;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0)) {
this->fShaderCaps->fTextureSwizzleAppliedInShader = false;
}
}
if (GR_IS_GR_GL(standard)) {
fMipMapLevelAndLodControlSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0)) {
fMipMapLevelAndLodControlSupport = true;
}
}
#ifdef SK_BUILD_FOR_WIN
bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() ||
kChromium_GrGLDriver == ctxInfo.driver();
fRGBA8888PixelsOpsAreSlow = isANGLE;
fPartialFBOReadIsSlow = isANGLE;
#endif
bool isMESA = kMesa_GrGLDriver == ctxInfo.driver();
bool isMAC = false;
#ifdef SK_BUILD_FOR_MAC
isMAC = true;
#endif
fRGBAToBGRAReadbackConversionsAreSlow = isMESA || isMAC;
if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
fUseBufferDataNullHint = kChromium_GrGLDriver != ctxInfo.driver();
} else if (GR_IS_GR_WEBGL(standard)) {
fUseBufferDataNullHint = false;
}
if (GR_IS_GR_GL(standard)) {
fClearTextureSupport = (version >= GR_GL_VER(4,4) ||
ctxInfo.hasExtension("GL_ARB_clear_texture"));
} else if (GR_IS_GR_GL_ES(standard)) {
fClearTextureSupport = ctxInfo.hasExtension("GL_EXT_clear_texture");
}
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
fSupportsAHardwareBufferImages = true;
#endif
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3,0)) {
fSRGBSupport = true;
} else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
fSRGBSupport = true;
}
}
if (fSRGBSupport) {
fSRGBWriteControl = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fSRGBSupport = version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB");
fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
} else if (GR_IS_GR_WEBGL(standard)) {
fSRGBSupport = version >= GR_GL_VER(2,0) || ctxInfo.hasExtension("GL_EXT_sRGB") ||
ctxInfo.hasExtension("EXT_sRGB");
}
if (kSkia8888_GrPixelConfig == kBGRA_8888_GrPixelConfig &&
(GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard))) {
fSRGBSupport = false;
}
* GrShaderCaps fields
**************************************************************************/
this->initGLSL(ctxInfo, gli);
GrShaderCaps* shaderCaps = fShaderCaps.get();
shaderCaps->fPathRenderingSupport = this->hasPathRenderingSupport(ctxInfo, gli);
if (GR_IS_GR_GL(standard)) {
shaderCaps->fDualSourceBlendingSupport = (version >= GR_GL_VER(3, 3) ||
ctxInfo.hasExtension("GL_ARB_blend_func_extended")) &&
ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
shaderCaps->fShaderDerivativeSupport = true;
shaderCaps->fGeometryShaderSupport = version >= GR_GL_VER(3, 2) &&
ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
if (shaderCaps->fGeometryShaderSupport) {
if (ctxInfo.glslGeneration() >= k400_GrGLSLGeneration) {
shaderCaps->fGSInvocationsSupport = true;
} else if (ctxInfo.hasExtension("GL_ARB_gpu_shader5")) {
shaderCaps->fGSInvocationsSupport = true;
shaderCaps->fGSInvocationsExtensionString = "GL_ARB_gpu_shader5";
}
}
shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fDualSourceBlendingSupport = ctxInfo.hasExtension("GL_EXT_blend_func_extended");
shaderCaps->fShaderDerivativeSupport = version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_standard_derivatives");
if (kARM_GrGLVendor != ctxInfo.vendor() &&
kAdreno3xx_GrGLRenderer != ctxInfo.renderer() &&
kAdreno4xx_other_GrGLRenderer != ctxInfo.renderer()) {
if (version >= GR_GL_VER(3,2)) {
shaderCaps->fGeometryShaderSupport = true;
} else if (ctxInfo.hasExtension("GL_EXT_geometry_shader")) {
shaderCaps->fGeometryShaderSupport = true;
shaderCaps->fGeometryShaderExtensionString = "GL_EXT_geometry_shader";
}
shaderCaps->fGSInvocationsSupport = shaderCaps->fGeometryShaderSupport;
}
shaderCaps->fIntegerSupport = version >= GR_GL_VER(3, 0) &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
} else if (GR_IS_GR_WEBGL(standard)) {
shaderCaps->fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives") ||
ctxInfo.hasExtension("OES_standard_derivatives");
}
static const uint8_t kMaxSaneSamplers = 32;
GrGLint maxSamplers;
GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxSamplers);
shaderCaps->fMaxFragmentSamplers = SkTMin<GrGLint>(kMaxSaneSamplers, maxSamplers);
if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.driver() != kChromium_GrGLDriver && !fIsCoreProfile &&
(ctxInfo.vendor() == kARM_GrGLVendor || ctxInfo.vendor() == kImagination_GrGLVendor ||
ctxInfo.vendor() == kQualcomm_GrGLVendor)) {
fPreferClientSideDynamicBuffers = true;
}
}
if (!contextOptions.fAvoidStencilBuffers) {
this->initFSAASupport(contextOptions, ctxInfo, gli);
this->initStencilSupport(ctxInfo);
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object") ||
ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
fBlitFramebufferFlags = 0;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0)) {
fBlitFramebufferFlags = kNoFormatConversionForMSAASrc_BlitFramebufferFlag |
kNoMSAADst_BlitFramebufferFlag |
kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
} else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") ||
ctxInfo.hasExtension("GL_ANGLE_framebuffer_blit")) {
fBlitFramebufferFlags = kNoScalingOrMirroring_BlitFramebufferFlag |
kResolveMustBeFull_BlitFrambufferFlag |
kNoMSAADst_BlitFramebufferFlag |
kNoFormatConversion_BlitFramebufferFlag |
kRectsMustMatchForMSAASrc_BlitFramebufferFlag;
}
}
this->initBlendEqationSupport(ctxInfo);
if (GR_IS_GR_GL(standard)) {
fMapBufferFlags = kCanMap_MapFlag;
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_map_buffer_range")) {
fMapBufferFlags |= kSubset_MapFlag;
fMapBufferType = kMapBufferRange_MapBufferType;
} else {
fMapBufferType = kMapBuffer_MapBufferType;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fMapBufferFlags = kNone_MapBufferType;
if (ctxInfo.hasExtension("GL_CHROMIUM_map_sub")) {
fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
fMapBufferType = kChromium_MapBufferType;
} else if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_map_buffer_range")) {
fMapBufferFlags = kCanMap_MapFlag | kSubset_MapFlag;
fMapBufferType = kMapBufferRange_MapBufferType;
} else if (ctxInfo.hasExtension("GL_OES_mapbuffer")) {
fMapBufferFlags = kCanMap_MapFlag;
fMapBufferType = kMapBuffer_MapBufferType;
}
} else if (GR_IS_GR_WEBGL(standard)) {
fMapBufferFlags = kNone_MapBufferType;
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(2, 1) || ctxInfo.hasExtension("GL_ARB_pixel_buffer_object") ||
ctxInfo.hasExtension("GL_EXT_pixel_buffer_object")) {
fTransferBufferSupport = true;
fTransferBufferType = kPBO_TransferBufferType;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) ||
(ctxInfo.hasExtension("GL_NV_pixel_buffer_object") &&
ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
fTransferBufferSupport = true;
fTransferBufferType = kPBO_TransferBufferType;
}
}
if (fBufferMapThreshold < 0) {
#if 0
fBufferMapThreshold = kChromium_GrGLDriver == ctxInfo.driver() ? 0 : SK_MaxS32;
#else
fBufferMapThreshold = SK_MaxS32;
#endif
}
if (GR_IS_GR_GL(standard)) {
fNPOTTextureTileSupport = true;
fMipMapSupport = true;
} else if (GR_IS_GR_GL_ES(standard)) {
fNPOTTextureTileSupport = version >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_OES_texture_npot");
fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
} else if (GR_IS_GR_WEBGL(standard)) {
fNPOTTextureTileSupport = version >= GR_GL_VER(2,0);
fMipMapSupport = fNPOTTextureTileSupport;
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
if (fDriverBugWorkarounds.max_texture_size_limit_4096) {
fMaxTextureSize = SkTMin(fMaxTextureSize, 4096);
}
GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
fMaxRenderTargetSize = SkTMin(fMaxTextureSize, fMaxRenderTargetSize);
fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
if (kARM_GrGLVendor == ctxInfo.vendor()) {
fMaxPreferredRenderTargetSize = SkTMin(4096, fMaxPreferredRenderTargetSize);
}
fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
#if 0
fReuseScratchBuffers = kARM_GrGLVendor != ctxInfo.vendor() &&
kQualcomm_GrGLVendor != ctxInfo.vendor();
#endif
if (ctxInfo.hasExtension("GL_EXT_window_rectangles")) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_WINDOW_RECTANGLES, &fMaxWindowRectangles);
}
#ifdef SK_BUILD_FOR_WIN
fPreferVRAMUseOverFlushes = !isANGLE;
#endif
if (kARM_GrGLVendor == ctxInfo.vendor()) {
fPreferTrianglesOverSampleMask = true;
}
if (kChromium_GrGLDriver == ctxInfo.driver()) {
fMustClearUploadedBufferData = true;
}
if (GR_IS_GR_WEBGL(standard)) {
fShouldInitializeTextures = true;
}
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
fOversizedStencilSupport = true;
} else {
SkASSERT(ctxInfo.hasExtension("GL_EXT_framebuffer_object"));
}
} else if (GR_IS_GR_GL_ES(standard)) {
fOversizedStencilSupport = version >= GR_GL_VER(3, 0);
} else if (GR_IS_GR_WEBGL(standard)) {
fOversizedStencilSupport = version >= GR_GL_VER(2, 0);
}
if (GR_IS_GR_GL(standard)) {
fDrawIndirectSupport = version >= GR_GL_VER(4,0) ||
ctxInfo.hasExtension("GL_ARB_draw_indirect");
fBaseInstanceSupport = version >= GR_GL_VER(4,2);
fMultiDrawIndirectSupport = version >= GR_GL_VER(4,3) ||
(fDrawIndirectSupport &&
!fBaseInstanceSupport &&
ctxInfo.hasExtension("GL_ARB_multi_draw_indirect"));
fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
} else if (GR_IS_GR_GL_ES(standard)) {
fDrawIndirectSupport = version >= GR_GL_VER(3,1);
fMultiDrawIndirectSupport = fDrawIndirectSupport &&
ctxInfo.hasExtension("GL_EXT_multi_draw_indirect");
fBaseInstanceSupport = fDrawIndirectSupport &&
ctxInfo.hasExtension("GL_EXT_base_instance");
fDrawRangeElementsSupport = version >= GR_GL_VER(3,0);
} else if (GR_IS_GR_WEBGL(standard)) {
fDrawRangeElementsSupport = version >= GR_GL_VER(2,0);
}
if (GR_IS_GR_GL(standard)) {
fFenceSyncSupport = (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_ARB_sync"));
} else if (GR_IS_GR_GL_ES(standard)) {
fFenceSyncSupport = (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_APPLE_sync"));
} else if (GR_IS_GR_WEBGL(standard)) {
fFenceSyncSupport = version >= GR_GL_VER(2, 0);
}
fSemaphoreSupport = fFenceSyncSupport;
fCrossContextTextureSupport = fSemaphoreSupport;
if (GR_IS_GR_GL(standard)) {
fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
} else if (GR_IS_GR_GL_ES(standard)) {
fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(3, 0));
} else if (GR_IS_GR_WEBGL(standard)) {
fHalfFloatVertexAttributeSupport = (version >= GR_GL_VER(2, 0));
}
fDynamicStateArrayGeometryProcessorTextureSupport = true;
if (GR_IS_GR_GL(standard)) {
fProgramBinarySupport = (version >= GR_GL_VER(4, 1));
fProgramParameterSupport = (version >= GR_GL_VER(4, 1));
} else if (GR_IS_GR_GL_ES(standard)) {
fProgramBinarySupport =
(version >= GR_GL_VER(3, 0)) || ctxInfo.hasExtension("GL_OES_get_program_binary");
fProgramParameterSupport = (version >= GR_GL_VER(3, 0));
}
if (fProgramBinarySupport) {
GrGLint count;
GR_GL_GetIntegerv(gli, GR_GL_NUM_PROGRAM_BINARY_FORMATS, &count);
fProgramBinarySupport = count > 0;
}
if (GR_IS_GR_GL(standard)) {
fSamplerObjectSupport =
version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_sampler_objects");
} else if (GR_IS_GR_GL_ES(standard)) {
fSamplerObjectSupport = version >= GR_GL_VER(3,0);
} else if (GR_IS_GR_WEBGL(standard)) {
fSamplerObjectSupport = version >= GR_GL_VER(2,0);
}
FormatWorkarounds formatWorkarounds;
if (!contextOptions.fDisableDriverCorrectnessWorkarounds) {
this->applyDriverCorrectnessWorkarounds(ctxInfo, contextOptions, shaderCaps,
&formatWorkarounds);
}
this->initFormatTable(ctxInfo, gli, formatWorkarounds);
this->applyOptionsOverrides(contextOptions);
shaderCaps->applyOptionsOverrides(contextOptions);
shaderCaps->fDstReadInShaderSupport = shaderCaps->fFBFetchSupport;
}
const char* get_glsl_version_decl_string(GrGLStandard standard, GrGLSLGeneration generation,
bool isCoreProfile) {
if (GR_IS_GR_GL(standard)) {
switch (generation) {
case k110_GrGLSLGeneration:
return "#version 110\n";
case k130_GrGLSLGeneration:
return "#version 130\n";
case k140_GrGLSLGeneration:
return "#version 140\n";
case k150_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 150\n";
} else {
return "#version 150 compatibility\n";
}
case k330_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 330\n";
} else {
return "#version 330 compatibility\n";
}
case k400_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 400\n";
} else {
return "#version 400 compatibility\n";
}
case k420_GrGLSLGeneration:
if (isCoreProfile) {
return "#version 420\n";
} else {
return "#version 420 compatibility\n";
}
default:
break;
}
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
switch (generation) {
case k110_GrGLSLGeneration:
return "#version 100\n";
case k330_GrGLSLGeneration:
return "#version 300 es\n";
case k310es_GrGLSLGeneration:
return "#version 310 es\n";
case k320es_GrGLSLGeneration:
return "#version 320 es\n";
default:
break;
}
}
return "<no version>";
}
bool is_float_fp32(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, GrGLenum precision) {
if (GR_IS_GR_GL(ctxInfo.standard()) &&
ctxInfo.version() < GR_GL_VER(4,1) &&
!ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
return true;
}
for (GrGLenum shader : {GR_GL_FRAGMENT_SHADER, GR_GL_VERTEX_SHADER}) {
GrGLint range[2];
GrGLint bits;
GR_GL_GetShaderPrecisionFormat(gli, shader, precision, range, &bits);
if (range[0] < 127 || range[1] < 127 || bits < 23) {
return false;
}
}
return true;
}
void GrGLCaps::initGLSL(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
GrGLVersion version = ctxInfo.version();
* Caps specific to GrShaderCaps
**************************************************************************/
GrShaderCaps* shaderCaps = fShaderCaps.get();
shaderCaps->fGLSLGeneration = ctxInfo.glslGeneration();
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
shaderCaps->fFBFetchNeedsCustomOutput = (version >= GR_GL_VER(3, 0));
shaderCaps->fFBFetchSupport = true;
shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
shaderCaps->fFBFetchExtensionString = "GL_EXT_shader_framebuffer_fetch";
fFBFetchRequiresEnablePerSample = false;
} else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
shaderCaps->fFBFetchNeedsCustomOutput = false;
shaderCaps->fFBFetchSupport = true;
shaderCaps->fFBFetchColorName = "gl_LastFragData[0]";
shaderCaps->fFBFetchExtensionString = "GL_NV_shader_framebuffer_fetch";
fFBFetchRequiresEnablePerSample = false;
} else if (ctxInfo.hasExtension("GL_ARM_shader_framebuffer_fetch")) {
shaderCaps->fFBFetchNeedsCustomOutput = false;
shaderCaps->fFBFetchSupport = true;
shaderCaps->fFBFetchColorName = "gl_LastFragColorARM";
shaderCaps->fFBFetchExtensionString = "GL_ARM_shader_framebuffer_fetch";
fFBFetchRequiresEnablePerSample = true;
}
shaderCaps->fUsesPrecisionModifiers = true;
} else if (GR_IS_GR_WEBGL(standard)) {
shaderCaps->fUsesPrecisionModifiers = true;
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fFlatInterpolationSupport = ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
shaderCaps->fFlatInterpolationSupport =
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
}
shaderCaps->fPreferFlatInterpolation = shaderCaps->fFlatInterpolationSupport &&
kQualcomm_GrGLVendor != ctxInfo.vendor() &&
kANGLE_GrGLDriver != ctxInfo.driver();
if (GR_IS_GR_GL(standard)) {
shaderCaps->fNoPerspectiveInterpolationSupport =
ctxInfo.glslGeneration() >= k130_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_NV_shader_noperspective_interpolation") &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration ) {
shaderCaps->fNoPerspectiveInterpolationSupport = true;
shaderCaps->fNoPerspectiveInterpolationExtensionString =
"GL_NV_shader_noperspective_interpolation";
}
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fSampleVariablesSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration) {
shaderCaps->fSampleVariablesSupport = true;
} else if (ctxInfo.hasExtension("GL_OES_sample_variables")) {
shaderCaps->fSampleVariablesSupport = true;
shaderCaps->fSampleVariablesExtensionString = "GL_OES_sample_variables";
}
}
shaderCaps->fSampleVariablesStencilSupport = shaderCaps->fSampleVariablesSupport;
if (kQualcomm_GrGLVendor == ctxInfo.vendor() || kATI_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fSampleVariablesSupport = false;
}
shaderCaps->fVersionDeclString = get_glsl_version_decl_string(standard,
shaderCaps->fGLSLGeneration,
fIsCoreProfile);
if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
if (k110_GrGLSLGeneration == shaderCaps->fGLSLGeneration) {
shaderCaps->fShaderDerivativeExtensionString = "GL_OES_standard_derivatives";
}
}
if (GR_IS_GR_GL(standard) &&
(ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"))) {
shaderCaps->fFragCoordConventionsExtensionString = "GL_ARB_fragment_coord_conventions";
}
if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fSecondaryOutputExtensionString = "GL_EXT_blend_func_extended";
}
if (ctxInfo.hasExtension("GL_OES_EGL_image_external")) {
if (ctxInfo.glslGeneration() == k110_GrGLSLGeneration) {
shaderCaps->fExternalTextureSupport = true;
shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
} else if (ctxInfo.hasExtension("GL_OES_EGL_image_external_essl3") ||
ctxInfo.hasExtension("OES_EGL_image_external_essl3")) {
shaderCaps->fExternalTextureSupport = true;
shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
}
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fVertexIDSupport = true;
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
shaderCaps->fVertexIDSupport = ctxInfo.glslGeneration() >= k330_GrGLSLGeneration;
}
if (GR_IS_GR_GL(standard)) {
shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
shaderCaps->fFPManipulationSupport = ctxInfo.glslGeneration() >= k310es_GrGLSLGeneration;
}
shaderCaps->fFloatIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_HIGH_FLOAT);
shaderCaps->fHalfIs32Bits = is_float_fp32(ctxInfo, gli, GR_GL_MEDIUM_FLOAT);
shaderCaps->fHasLowFragmentPrecision = kMali4xx_GrGLRenderer == ctxInfo.renderer();
if (GR_IS_GR_GL(standard)) {
shaderCaps->fBuiltinFMASupport = ctxInfo.glslGeneration() >= k400_GrGLSLGeneration;
} else if (GR_IS_GR_GL_ES(standard)) {
shaderCaps->fBuiltinFMASupport = ctxInfo.glslGeneration() >= k320es_GrGLSLGeneration;
}
}
bool GrGLCaps::hasPathRenderingSupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
bool hasChromiumPathRendering = ctxInfo.hasExtension("GL_CHROMIUM_path_rendering");
if (!(ctxInfo.hasExtension("GL_NV_path_rendering") || hasChromiumPathRendering)) {
return false;
}
if (GR_IS_GR_GL(ctxInfo.standard())) {
if (ctxInfo.version() < GR_GL_VER(4, 3) &&
!ctxInfo.hasExtension("GL_ARB_program_interface_query")) {
return false;
}
} else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
if (!hasChromiumPathRendering &&
ctxInfo.version() < GR_GL_VER(3, 1)) {
return false;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
return false;
}
if (!gli->fFunctions.fStencilThenCoverFillPath ||
!gli->fFunctions.fStencilThenCoverStrokePath ||
!gli->fFunctions.fStencilThenCoverFillPathInstanced ||
!gli->fFunctions.fStencilThenCoverStrokePathInstanced ||
!gli->fFunctions.fProgramPathFragmentInputGen) {
return false;
}
return true;
}
void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
const GrGLInterface* gli) {
if (fMultisampleDisableSupport && this->shaderCaps()->dualSourceBlendingSupport()) {
fMixedSamplesSupport = ctxInfo.hasExtension("GL_NV_framebuffer_mixed_samples") ||
ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_mixed_samples");
}
if (GR_IS_GR_GL(ctxInfo.standard())) {
if (ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
fMSFBOType = kStandard_MSFBOType;
if (!fIsCoreProfile && ctxInfo.renderer() != kOSMesa_GrGLRenderer) {
fAlpha8IsRenderable = true;
}
} else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
fMSFBOType = kStandard_MSFBOType;
}
} else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
if (ctxInfo.version() >= GR_GL_VER(3,0) &&
ctxInfo.renderer() != kGalliumLLVM_GrGLRenderer) {
fAlpha8IsRenderable = true;
}
if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
fMSAAResolvesAutomatically = true;
} else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
fMSAAResolvesAutomatically = true;
} else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
fMSFBOType = kStandard_MSFBOType;
} else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
fMSFBOType = kStandard_MSFBOType;
} else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) {
fMSFBOType = kStandard_MSFBOType;
} else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
fMSFBOType = kES_Apple_MSFBOType;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
fMSFBOType = kNone_MSFBOType;
}
if (kIntel_GrGLVendor == ctxInfo.vendor()) {
fMSFBOType = kNone_MSFBOType;
}
}
void GrGLCaps::initBlendEqationSupport(const GrGLContextInfo& ctxInfo) {
GrShaderCaps* shaderCaps = static_cast<GrShaderCaps*>(fShaderCaps.get());
bool layoutQualifierSupport = false;
if ((GR_IS_GR_GL(fStandard) && shaderCaps->generation() >= k140_GrGLSLGeneration) ||
(GR_IS_GR_GL_ES(fStandard) && shaderCaps->generation() >= k330_GrGLSLGeneration)) {
layoutQualifierSupport = true;
} else if (GR_IS_GR_WEBGL(fStandard)) {
return;
}
if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced_coherent")) {
fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
} else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced_coherent") &&
layoutQualifierSupport) {
fBlendEquationSupport = kAdvancedCoherent_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
} else if (ctxInfo.hasExtension("GL_NV_blend_equation_advanced")) {
fBlendEquationSupport = kAdvanced_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kAutomatic_AdvBlendEqInteraction;
} else if (ctxInfo.hasExtension("GL_KHR_blend_equation_advanced") && layoutQualifierSupport) {
fBlendEquationSupport = kAdvanced_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kGeneralEnable_AdvBlendEqInteraction;
}
}
namespace {
const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount;
}
void GrGLCaps::initStencilSupport(const GrGLContextInfo& ctxInfo) {
static const StencilFormat
gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
if (GR_IS_GR_GL(ctxInfo.standard())) {
bool supportsPackedDS =
ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
ctxInfo.hasExtension("GL_ARB_framebuffer_object");
fStencilFormats.push_back() = gS8;
fStencilFormats.push_back() = gS16;
if (supportsPackedDS) {
fStencilFormats.push_back() = gD24S8;
}
fStencilFormats.push_back() = gS4;
if (supportsPackedDS) {
fStencilFormats.push_back() = gDS;
}
} else if (GR_IS_GR_GL_ES(ctxInfo.standard())) {
fStencilFormats.push_back() = gS8;
if (ctxInfo.version() >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
fStencilFormats.push_back() = gD24S8;
}
if (ctxInfo.hasExtension("GL_OES_stencil4")) {
fStencilFormats.push_back() = gS4;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
fStencilFormats.push_back() = gS8;
if (ctxInfo.version() >= GR_GL_VER(2,0)) {
fStencilFormats.push_back() = gD24S8;
}
}
}
#ifdef SK_ENABLE_DUMP_GPU
void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
writer->beginObject("GL caps");
writer->beginArray("Stencil Formats");
for (int i = 0; i < fStencilFormats.count(); ++i) {
writer->beginObject(nullptr, false);
writer->appendS32("stencil bits", fStencilFormats[i].fStencilBits);
writer->appendS32("total bits", fStencilFormats[i].fTotalBits);
writer->endObject();
}
writer->endArray();
static const char* kMSFBOExtStr[] = {
"None",
"Standard",
"Apple",
"IMG MS To Texture",
"EXT MS To Texture",
};
GR_STATIC_ASSERT(0 == kNone_MSFBOType);
GR_STATIC_ASSERT(1 == kStandard_MSFBOType);
GR_STATIC_ASSERT(2 == kES_Apple_MSFBOType);
GR_STATIC_ASSERT(3 == kES_IMG_MsToTexture_MSFBOType);
GR_STATIC_ASSERT(4 == kES_EXT_MsToTexture_MSFBOType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
static const char* kInvalidateFBTypeStr[] = {
"None",
"Discard",
"Invalidate",
};
GR_STATIC_ASSERT(0 == kNone_InvalidateFBType);
GR_STATIC_ASSERT(1 == kDiscard_InvalidateFBType);
GR_STATIC_ASSERT(2 == kInvalidate_InvalidateFBType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kInvalidateFBTypeStr) == kLast_InvalidateFBType + 1);
static const char* kMapBufferTypeStr[] = {
"None",
"MapBuffer",
"MapBufferRange",
"Chromium",
};
GR_STATIC_ASSERT(0 == kNone_MapBufferType);
GR_STATIC_ASSERT(1 == kMapBuffer_MapBufferType);
GR_STATIC_ASSERT(2 == kMapBufferRange_MapBufferType);
GR_STATIC_ASSERT(3 == kChromium_MapBufferType);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
writer->appendBool("Core Profile", fIsCoreProfile);
writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
writer->appendBool("Pack Flip Y support", fPackFlipYSupport);
writer->appendBool("Texture Usage support", fTextureUsageSupport);
writer->appendBool("Alpha8 is renderable", fAlpha8IsRenderable);
writer->appendBool("GL_ARB_imaging support", fImagingSupport);
writer->appendBool("Vertex array object support", fVertexArrayObjectSupport);
writer->appendBool("Debug support", fDebugSupport);
writer->appendBool("Draw indirect support", fDrawIndirectSupport);
writer->appendBool("Multi draw indirect support", fMultiDrawIndirectSupport);
writer->appendBool("Base instance support", fBaseInstanceSupport);
writer->appendBool("RGBA 8888 pixel ops are slow", fRGBA8888PixelsOpsAreSlow);
writer->appendBool("Partial FBO read is slow", fPartialFBOReadIsSlow);
writer->appendBool("Bind uniform location support", fBindUniformLocationSupport);
writer->appendBool("Rectangle texture support", fRectangleTextureSupport);
writer->appendBool("BGRA to RGBA readback conversions are slow",
fRGBAToBGRAReadbackConversionsAreSlow);
writer->appendBool("Use buffer data null hint", fUseBufferDataNullHint);
writer->appendBool("Intermediate texture for partial updates of unorm textures ever bound to FBOs",
fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
writer->appendBool("Intermediate texture for all updates of textures bound to FBOs",
fUseDrawInsteadOfAllRenderTargetWrites);
writer->appendBool("Max instances per draw without crashing (or zero)",
fMaxInstancesPerDrawWithoutCrashing);
writer->beginArray("formats");
for (int i = 0; i < kGrGLFormatCount; ++i) {
writer->beginObject(nullptr, false);
writer->appendHexU32("flags", fFormatTable[i].fFlags);
writer->appendHexU32("f_type", (uint32_t)fFormatTable[i].fFormatType);
writer->appendHexU32("b_internal", fFormatTable[i].fBaseInternalFormat);
writer->appendHexU32("s_internal", fFormatTable[i].fSizedInternalFormat);
writer->appendHexU32("c_internal", fFormatTable[i].fCompressedInternalFormat);
writer->appendHexU32("i_for_teximage", fFormatTable[i].fInternalFormatForTexImage);
writer->appendHexU32("i_for_renderbuffer", fFormatTable[i].fInternalFormatForRenderbuffer);
writer->appendHexU32("default_ex_type", fFormatTable[i].fDefaultExternalType);
writer->beginArray("surface color types");
for (int j = 0; j < fFormatTable[i].fColorTypeInfoCount; ++j) {
const auto& ctInfo = fFormatTable[i].fColorTypeInfos[j];
writer->beginObject(nullptr, false);
writer->appendHexU32("colorType", (uint32_t)ctInfo.fColorType);
writer->appendHexU32("flags", ctInfo.fFlags);
writer->beginArray("data color types");
for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) {
const auto& ioInfo = ctInfo.fExternalIOFormats[k];
writer->beginObject(nullptr, false);
writer->appendHexU32("colorType", (uint32_t)ioInfo.fColorType);
writer->appendHexU32("ex_type", ioInfo.fExternalType);
writer->appendHexU32("ex_teximage", ioInfo.fExternalTexImageFormat);
writer->appendHexU32("ex_read", ioInfo.fExternalReadFormat);
writer->endObject();
}
writer->endArray();
writer->endObject();
}
writer->endArray();
writer->endObject();
}
writer->endArray();
writer->endObject();
}
#else
void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { }
#endif
void GrGLCaps::getTexImageFormats(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
GrColorType memoryColorType, GrGLenum* internalFormat,
GrGLenum* externalFormat, GrGLenum* externalType) const {
this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType,
kTexImage_ExternalFormatUsage, externalFormat, externalType);
*internalFormat = this->getTexImageInternalFormat(surfaceFormat);
}
void GrGLCaps::getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
GrColorType memoryColorType, GrGLenum* externalFormat,
GrGLenum* externalType) const {
this->getExternalFormat(surfaceFormat, surfaceColorType, memoryColorType,
kReadPixels_ExternalFormatUsage, externalFormat, externalType);
}
void GrGLCaps::getExternalFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType,
GrColorType memoryColorType, ExternalFormatUsage usage,
GrGLenum* externalFormat, GrGLenum* externalType) const {
SkASSERT(externalFormat && externalType);
*externalFormat = this->getFormatInfo(surfaceFormat).externalFormat(
surfaceColorType, memoryColorType, usage);
*externalType = this->getFormatInfo(surfaceFormat).externalType(
surfaceColorType, memoryColorType);
}
void GrGLCaps::setStencilFormatIndexForFormat(GrGLFormat format, int index) {
SkASSERT(!this->hasStencilFormatBeenDeterminedForFormat(format));
this->getFormatInfo(format).fStencilFormatIndex =
index < 0 ? FormatInfo::kUnsupported_StencilFormatIndex : index;
}
void GrGLCaps::setColorTypeFormat(GrColorType colorType, GrGLFormat format) {
int idx = static_cast<int>(colorType);
SkASSERT(fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown);
fColorTypeToFormatTable[idx] = format;
}
void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
const FormatWorkarounds& formatWorkarounds) {
GrGLStandard standard = ctxInfo.standard();
sk_ignore_unused_variable(standard);
GrGLVersion version = ctxInfo.version();
uint32_t nonMSAARenderFlags = FormatInfo::kFBOColorAttachment_Flag;
uint32_t msaaRenderFlags = nonMSAARenderFlags;
if (kNone_MSFBOType != fMSFBOType) {
msaaRenderFlags |= FormatInfo::kFBOColorAttachmentWithMSAA_Flag;
}
bool texStorageSupported = false;
if (GR_IS_GR_GL(standard)) {
texStorageSupported = version >= GR_GL_VER(4,2) ||
ctxInfo.hasExtension("GL_ARB_texture_storage") ||
ctxInfo.hasExtension("GL_EXT_texture_storage");
} else if (GR_IS_GR_GL_ES(standard)) {
texStorageSupported = version >= GR_GL_VER(3,0) ||
ctxInfo.hasExtension("GL_EXT_texture_storage");
} else if (GR_IS_GR_WEBGL(standard)) {
texStorageSupported = version >= GR_GL_VER(2,0);
}
if (fDriverBugWorkarounds.disable_texture_storage) {
texStorageSupported = false;
}
#ifdef SK_BUILD_FOR_ANDROID
texStorageSupported = false;
#endif
bool texImageSupportsSizedInternalFormat =
(GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)));
bool textureRedSupport = false;
if (!formatWorkarounds.fDisableTextureRedForMesa) {
if (GR_IS_GR_GL(standard)) {
textureRedSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg");
} else if (GR_IS_GR_GL_ES(standard)) {
textureRedSupport =
version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_EXT_texture_rg");
}
}
bool hasFP16Textures = false;
enum class HalfFPRenderTargetSupport { kNone, kRGBAOnly, kAll };
HalfFPRenderTargetSupport halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kNone;
uint32_t fpRenderFlags = (GR_IS_GR_GL(standard)) ? msaaRenderFlags : nonMSAARenderFlags;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0)) {
hasFP16Textures = true;
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0)) {
hasFP16Textures = true;
} else if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_float")) {
hasFP16Textures = true;
} else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_half_float")) {
hasFP16Textures = true;
}
if (version >= GR_GL_VER(3, 2)) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
} else if (ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
} else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float")) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
}
} else if (GR_IS_GR_WEBGL(standard)) {
if ((ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_float")) ||
(ctxInfo.hasExtension("OES_texture_float_linear") &&
ctxInfo.hasExtension("OES_texture_float"))) {
hasFP16Textures = true;
} else if ((ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_half_float")) ||
(ctxInfo.hasExtension("OES_texture_half_float_linear") &&
ctxInfo.hasExtension("OES_texture_half_float"))) {
hasFP16Textures = true;
}
if (ctxInfo.hasExtension("GL_WEBGL_color_buffer_float") ||
ctxInfo.hasExtension("WEBGL_color_buffer_float")) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kAll;
} else if (ctxInfo.hasExtension("GL_EXT_color_buffer_half_float") ||
ctxInfo.hasExtension("EXT_color_buffer_half_float")) {
halfFPRenderTargetSupport = HalfFPRenderTargetSupport::kRGBAOnly;
}
}
bool r16AndRG1616Supported = false;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) {
r16AndRG1616Supported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_texture_norm16")) {
r16AndRG1616Supported = true;
}
}
for (int i = 0; i < kGrColorTypeCnt; ++i) {
fColorTypeToFormatTable[i] = GrGLFormat::kUnknown;
}
GrGLenum halfFloatType = GR_GL_HALF_FLOAT;
if (GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) {
halfFloatType = GR_GL_HALF_FLOAT_OES;
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
info.fFlags = FormatInfo::kTexturable_Flag;
if (GR_IS_GR_GL(standard)) {
info.fFlags |= msaaRenderFlags;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
ctxInfo.hasExtension("GL_ARM_rgba8")) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
bool supportsBGRAColorType = GR_IS_GR_GL(standard) &&
(version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra"));
info.fColorTypeInfoCount = supportsBGRAColorType ? 3 : 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGBA_8888;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRGBA_8888, GrGLFormat::kRGBA8);
ctInfo.fExternalIOFormatCount = 1;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
if (supportsBGRAColorType) {
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kBGRA_8888;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kRGBA8);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kBGRA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGB_888x;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RGB1();
ctInfo.fExternalIOFormatCount = 1;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGB_888x;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kR8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED;
info.fInternalFormatForRenderbuffer = GR_GL_R8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (textureRedSupport) {
info.fFlags |= FormatInfo::kTexturable_Flag | msaaRenderFlags;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (textureRedSupport) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kAlpha_8;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kR8);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kAlpha_8;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_RED;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kAlpha_8xxx;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kGray_8;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fTextureSwizzle = GrSwizzle("rrr1");
this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kR8);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kGray_8;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_RED;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kGray_8xxx;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
bool alpha8IsValidForGL = GR_IS_GR_GL(standard) &&
(!fIsCoreProfile || version <= GR_GL_VER(3, 0));
bool alpha8IsValidForGLES = GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0);
bool alpha8IsValidForWebGL = GR_IS_GR_WEBGL(standard);
FormatInfo& info = this->getFormatInfo(GrGLFormat::kALPHA8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_ALPHA;
info.fSizedInternalFormat = GR_GL_ALPHA8;
if (GR_IS_GR_GL_ES(standard) || !texImageSupportsSizedInternalFormat) {
info.fInternalFormatForTexImage = GR_GL_ALPHA;
} else {
info.fInternalFormatForTexImage = GR_GL_ALPHA8;
}
info.fInternalFormatForRenderbuffer = GR_GL_ALPHA8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
if (fAlpha8IsRenderable && alpha8IsValidForGL) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2 &&
!formatWorkarounds.fDisableNonRedSingleChannelTexStorageForANGLEGL) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kAlpha_8;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag |
ColorTypeInfo::kRenderable_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::AAAA();
int idx = static_cast<int>(GrColorType::kAlpha_8);
if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kALPHA8);
}
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kAlpha_8;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_ALPHA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_LUMINANCE;
info.fSizedInternalFormat = GR_GL_LUMINANCE8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_LUMINANCE8 : GR_GL_LUMINANCE;
info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
bool supportsLum = (GR_IS_GR_GL(standard) && version <= GR_GL_VER(3, 0)) ||
(GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) ||
(GR_IS_GR_WEBGL(standard));
if (supportsLum) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2 &&
!formatWorkarounds.fDisableNonRedSingleChannelTexStorageForANGLEGL) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (supportsLum) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kGray_8;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
int idx = static_cast<int>(GrColorType::kGray_8);
if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kLUMINANCE8);
}
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kGray_8;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kBGRA8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_BGRA;
info.fSizedInternalFormat = GR_GL_BGRA8;
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
info.fInternalFormatForTexImage = GR_GL_RGBA;
} else {
info.fInternalFormatForTexImage = GR_GL_BGRA;
}
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
} else {
info.fInternalFormatForRenderbuffer = GR_GL_BGRA8;
}
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
bool supportsBGRATexStorage = false;
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
info.fFlags = FormatInfo::kTexturable_Flag | nonMSAARenderFlags;
if (ctxInfo.hasExtension("GL_EXT_texture_storage") &&
!formatWorkarounds.fDisableBGRATextureStorageForIntelWindowsES) {
supportsBGRATexStorage = true;
}
} else if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
if (version >= GR_GL_VER(3,0)) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
supportsBGRATexStorage = true;
}
}
}
if (texStorageSupported && supportsBGRATexStorage) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kBGRA_8888;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kBGRA8);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kBGRA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_BGRA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB565);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fSizedInternalFormat = GR_GL_RGB565;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB;
info.fInternalFormatForRenderbuffer = GR_GL_RGB565;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
}
if (texStorageSupported && GR_IS_GR_GL_ES(standard)) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kBGR_565;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kBGR_565, GrGLFormat::kRGB565);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kBGR_565;
ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
ioFormat.fExternalTexImageFormat = GR_GL_RGB;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16F);
info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer = GR_GL_RGBA16F;
info.fDefaultExternalType = halfFloatType;
if (hasFP16Textures) {
info.fFlags = FormatInfo::kTexturable_Flag;
if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) {
info.fFlags |= fpRenderFlags;
}
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (hasFP16Textures) {
uint32_t flags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGBA_F16;
ctInfo.fFlags = flags;
this->setColorTypeFormat(GrColorType::kRGBA_F16, GrGLFormat::kRGBA16F);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F16;
ioFormat.fExternalType = halfFloatType;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F32;
ioFormat.fExternalType = GR_GL_FLOAT;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGBA_F16_Clamped;
ctInfo.fFlags = flags;
this->setColorTypeFormat(GrColorType::kRGBA_F16_Clamped, GrGLFormat::kRGBA16F);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F16_Clamped;
ioFormat.fExternalType = halfFloatType;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F32;
ioFormat.fExternalType = GR_GL_FLOAT;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16F);
info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED;
info.fInternalFormatForRenderbuffer = GR_GL_R16F;
info.fDefaultExternalType = halfFloatType;
if (textureRedSupport && hasFP16Textures) {
info.fFlags = FormatInfo::kTexturable_Flag;
if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) {
info.fFlags |= fpRenderFlags;
}
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (textureRedSupport && hasFP16Textures) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kAlpha_F16;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kR16F);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kAlpha_F16;
ioFormat.fExternalType = halfFloatType;
ioFormat.fExternalTexImageFormat = GR_GL_RED;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kAlpha_F32xxx;
ioFormat.fExternalType = GR_GL_FLOAT;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
bool lum16FSupported = false;
if (GR_IS_GR_GL(standard)) {
if (ctxInfo.hasExtension("GL_ARB_texture_float")) {
lum16FSupported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_OES_texture_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_float")) {
lum16FSupported = true;
} else if (ctxInfo.hasExtension("GL_OES_texture_half_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_half_float")) {
lum16FSupported = true;
}
}
if (formatWorkarounds.fDisableLuminance16F) {
lum16FSupported = false;
}
FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE16F);
info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_LUMINANCE;
info.fSizedInternalFormat = GR_GL_LUMINANCE16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_LUMINANCE16F : GR_GL_LUMINANCE;
info.fInternalFormatForRenderbuffer = GR_GL_LUMINANCE16F;
info.fDefaultExternalType = halfFloatType;
if (lum16FSupported) {
info.fFlags = FormatInfo::kTexturable_Flag;
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kAlpha_F16;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
int idx = static_cast<int>(GrColorType::kAlpha_F16);
if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kLUMINANCE16F);
}
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kAlpha_F16;
ioFormat.fExternalType = halfFloatType;
ioFormat.fExternalTexImageFormat = GR_GL_LUMINANCE;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F32;
ioFormat.fExternalType = GR_GL_FLOAT;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fSizedInternalFormat = GR_GL_RGB8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB;
info.fInternalFormatForRenderbuffer = GR_GL_RGB8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
info.fFlags = FormatInfo::kTexturable_Flag;
if (GR_IS_GR_GL(standard)) {
info.fFlags |= nonMSAARenderFlags;
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (formatWorkarounds.fDisableRGB8ForMali400) {
info.fFlags = 0;
}
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGB_888x;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGB8);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGB_888x;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_RGB;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG;
info.fInternalFormatForRenderbuffer = GR_GL_RG8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (textureRedSupport) {
info.fFlags |= FormatInfo::kTexturable_Flag | msaaRenderFlags;
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
}
if (textureRedSupport) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRG_88;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRG_88, GrGLFormat::kRG8);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRG_88;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = GR_GL_RG;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB10_A2);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGB10_A2;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer = GR_GL_RGB10_A2;
info.fDefaultExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
if (GR_IS_GR_GL(standard) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
} else if (GR_IS_GR_GL_ES(standard) &&
ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGBA_1010102;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRGBA_1010102, GrGLFormat::kRGB10_A2);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_1010102;
ioFormat.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA4);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA4;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer = GR_GL_RGBA4;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
info.fFlags = FormatInfo::kTexturable_Flag;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2)) {
info.fFlags |= msaaRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
info.fFlags |= msaaRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
}
if (texStorageSupported) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kABGR_4444;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kABGR_4444, GrGLFormat::kRGBA4);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kABGR_4444;
ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA32F);
info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA32F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA32F : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer = GR_GL_RGBA32F;
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kSRGB8_ALPHA8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_SRGB_ALPHA;
info.fInternalFormatForRenderbuffer = GR_GL_SRGB8_ALPHA8;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (fSRGBSupport) {
uint32_t srgbRenderFlags =
formatWorkarounds.fDisableSRGBRenderWithMSAAForMacAMD ? nonMSAARenderFlags
: msaaRenderFlags;
info.fFlags = FormatInfo::kTexturable_Flag | srgbRenderFlags;
}
if (texStorageSupported &&
!formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) {
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
if (fSRGBSupport) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGBA_8888_SRGB;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRGBA_8888_SRGB, GrGLFormat::kSRGB8_ALPHA8);
ctInfo.fExternalIOFormatCount = 1;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
GrGLenum texImageFormat = GR_GL_RGBA;
if (GR_IS_GR_GL_ES(standard) && version == GR_GL_VER(2,0)) {
texImageFormat = GR_GL_SRGB_ALPHA;
}
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888_SRGB;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = texImageFormat;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_ETC2);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fInternalFormatForTexImage = GR_GL_COMPRESSED_RGB8_ETC2;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) ||
ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture")) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fInternalFormatForTexImage = GR_GL_COMPRESSED_ETC1_RGB8;
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ASTC_RGB8);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fInternalFormatForTexImage = GR_GL_COMPRESSED_RGBA_ASTC_4x4;
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_OES_texture_compression_astc")) {
info.fFlags = FormatInfo::kTexturable_Flag;
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R16 : GR_GL_RED;
info.fInternalFormatForRenderbuffer = GR_GL_R16;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (r16AndRG1616Supported) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
}
if (r16AndRG1616Supported) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kR_16;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kR_16, GrGLFormat::kR16);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kR_16;
ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
ioFormat.fExternalTexImageFormat = GR_GL_RED;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
info.fInternalFormatForRenderbuffer = GR_GL_RG16;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (r16AndRG1616Supported) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
}
if (r16AndRG1616Supported) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRG_1616;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRG_1616, GrGLFormat::kRG16);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRG_1616;
ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
ioFormat.fExternalTexImageFormat = GR_GL_RG;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
bool rgba16161616Supported = false;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0)) {
rgba16161616Supported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_EXT_texture_norm16")) {
rgba16161616Supported = true;
}
}
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16);
info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA16 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer = GR_GL_RGBA16;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (rgba16161616Supported) {
info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags;
}
if (rgba16161616Supported) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRGBA_16161616;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRGBA_16161616, GrGLFormat::kRGBA16);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_16161616;
ioFormat.fExternalType = GR_GL_UNSIGNED_SHORT;
ioFormat.fExternalTexImageFormat = GR_GL_RGBA;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
{
bool rg16fTexturesSupported = false;
bool rg16fRenderingSupported = false;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_rg")) {
rg16fTexturesSupported = true;
rg16fRenderingSupported = true;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 2) || ctxInfo.hasExtension("GL_EXT_color_buffer_float")) {
rg16fTexturesSupported = true;
rg16fRenderingSupported = true;
} else if (version >= GR_GL_VER(3, 0)) {
rg16fTexturesSupported = true;
}
}
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16F);
info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG16F : GR_GL_RG;
info.fInternalFormatForRenderbuffer = GR_GL_RG16F;
info.fDefaultExternalType = halfFloatType;
if (rg16fTexturesSupported) {
info.fFlags |= FormatInfo::kTexturable_Flag;
}
if (rg16fRenderingSupported) {
info.fFlags |= fpRenderFlags;
}
SkASSERT(rg16fTexturesSupported || !rg16fRenderingSupported);
if (rg16fTexturesSupported) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
{
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = GrColorType::kRG_F16;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
this->setColorTypeFormat(GrColorType::kRG_F16, GrGLFormat::kRG16F);
ctInfo.fExternalIOFormatCount = 2;
ctInfo.fExternalIOFormats.reset(
new ColorTypeInfo::ExternalIOFormats[ctInfo.fExternalIOFormatCount]());
int ioIdx = 0;
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRG_F16;
ioFormat.fExternalType = halfFloatType;
ioFormat.fExternalTexImageFormat = GR_GL_RG;
ioFormat.fExternalReadFormat = 0;
}
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F32;
ioFormat.fExternalType = GR_GL_FLOAT;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
}
}
}
}
this->setupSampleCounts(ctxInfo, gli);
#ifdef SK_DEBUG
for (int i = 0; i < kGrGLFormatCount; ++i) {
if (GrGLFormat::kUnknown == static_cast<GrGLFormat>(i)) {
continue;
}
const auto& formatInfo = fFormatTable[i];
SkASSERT(!((formatInfo.fFlags & FormatInfo::kFBOColorAttachmentWithMSAA_Flag) &&
!(formatInfo.fFlags & FormatInfo::kFBOColorAttachment_Flag)));
SkASSERT(formatInfo.fFormatType != FormatType::kUnknown);
for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) {
const auto& ctInfo = formatInfo.fColorTypeInfos[j];
SkASSERT(ctInfo.fColorType != GrColorType::kUnknown);
SkASSERT(ctInfo.fFlags);
for (int k = 0; k < ctInfo.fExternalIOFormatCount; ++k) {
const auto& ioInfo = ctInfo.fExternalIOFormats[k];
SkASSERT(ioInfo.fColorType != GrColorType::kUnknown);
SkASSERT(ioInfo.fExternalReadFormat || ioInfo.fExternalTexImageFormat);
}
}
}
#endif
}
void GrGLCaps::setupSampleCounts(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
GrGLStandard standard = ctxInfo.standard();
sk_ignore_unused_variable(standard);
GrGLVersion version = ctxInfo.version();
for (int i = 0; i < kGrGLFormatCount; ++i) {
if (FormatInfo::kFBOColorAttachmentWithMSAA_Flag & fFormatTable[i].fFlags) {
SkASSERT(FormatInfo::kFBOColorAttachment_Flag & fFormatTable[i].fFlags);
if ((GR_IS_GR_GL(standard) &&
(version >= GR_GL_VER(4,2) ||
ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0))) {
int count;
GrGLFormat grGLFormat = static_cast<GrGLFormat>(i);
GrGLenum glFormat = this->getRenderbufferInternalFormat(grGLFormat);
GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, glFormat,
GR_GL_NUM_SAMPLE_COUNTS, 1, &count);
if (count) {
std::unique_ptr<int[]> temp(new int[count]);
GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, glFormat, GR_GL_SAMPLES,
count, temp.get());
if (count && temp[count - 1] == 1) {
--count;
SkASSERT(!count || temp[count -1] > 1);
}
fFormatTable[i].fColorSampleCounts.setCount(count+1);
fFormatTable[i].fColorSampleCounts[0] = 1;
for (int j = 0; j < count; ++j) {
fFormatTable[i].fColorSampleCounts[j+1] = temp[count - j - 1];
}
}
} else {
int maxSampleCnt = 1;
if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &maxSampleCnt);
} else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &maxSampleCnt);
}
maxSampleCnt = SkTMax(1, maxSampleCnt);
static constexpr int kDefaultSamples[] = {1, 2, 4, 8};
int count = SK_ARRAY_COUNT(kDefaultSamples);
for (; count > 0; --count) {
if (kDefaultSamples[count - 1] <= maxSampleCnt) {
break;
}
}
if (count > 0) {
fFormatTable[i].fColorSampleCounts.append(count, kDefaultSamples);
}
}
} else if (FormatInfo::kFBOColorAttachment_Flag & fFormatTable[i].fFlags) {
fFormatTable[i].fColorSampleCounts.setCount(1);
fFormatTable[i].fColorSampleCounts[0] = 1;
}
}
}
bool GrGLCaps::canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer,
const GrTextureType* dstTypeIfTexture,
GrGLFormat srcFormat, bool srcHasMSAARenderBuffer,
const GrTextureType* srcTypeIfTexture) const {
if (GR_IS_GR_GL_ES(fStandard) &&
(dstFormat == GrGLFormat::kBGRA8 || srcFormat == GrGLFormat::kBGRA8)) {
return false;
}
if (dstHasMSAARenderBuffer || srcHasMSAARenderBuffer) {
return false;
}
if (!dstTypeIfTexture) {
return false;
}
return this->canFormatBeFBOColorAttachment(srcFormat) &&
(!srcTypeIfTexture || *srcTypeIfTexture != GrTextureType::kExternal) &&
*dstTypeIfTexture != GrTextureType::kExternal;
}
bool GrGLCaps::canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt,
const GrTextureType* dstTypeIfTexture,
GrGLFormat srcFormat, int srcSampleCnt,
const GrTextureType* srcTypeIfTexture,
const SkRect& srcBounds, bool srcBoundsExact,
const SkIRect& srcRect, const SkIPoint& dstPoint) const {
auto blitFramebufferFlags = this->blitFramebufferSupportFlags();
if (!this->canFormatBeFBOColorAttachment(dstFormat) ||
!this->canFormatBeFBOColorAttachment(srcFormat)) {
return false;
}
if (dstTypeIfTexture && *dstTypeIfTexture == GrTextureType::kExternal) {
return false;
}
if (srcTypeIfTexture && *srcTypeIfTexture == GrTextureType::kExternal) {
return false;
}
if (GrGLCaps::kNoSupport_BlitFramebufferFlag & blitFramebufferFlags) {
return false;
}
if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & blitFramebufferFlags) {
if (srcSampleCnt > 1) {
if (1 == dstSampleCnt) {
return false;
}
if (SkRect::Make(srcRect) != srcBounds || !srcBoundsExact) {
return false;
}
}
}
if (GrGLCaps::kNoMSAADst_BlitFramebufferFlag & blitFramebufferFlags) {
if (dstSampleCnt > 1) {
return false;
}
}
if (GrGLCaps::kNoFormatConversion_BlitFramebufferFlag & blitFramebufferFlags) {
if (srcFormat != dstFormat) {
return false;
}
} else if (GrGLCaps::kNoFormatConversionForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
if (srcSampleCnt > 1 && srcFormat != dstFormat) {
return false;
}
}
if (GrGLCaps::kRectsMustMatchForMSAASrc_BlitFramebufferFlag & blitFramebufferFlags) {
if (srcSampleCnt > 1) {
if (dstPoint.fX != srcRect.fLeft || dstPoint.fY != srcRect.fTop) {
return false;
}
}
}
return true;
}
bool GrGLCaps::canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const {
return this->isFormatRenderable(dstFormat, 1) && srcIsTexturable;
}
static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) {
const GrRenderTargetProxy* rt = surf->asRenderTargetProxy();
if (!rt) {
return false;
}
return rt->numSamples() > 1 &&
glCaps.usesMSAARenderBuffers() &&
!rt->rtPriv().glRTFBOIDIs0();
}
bool GrGLCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
const SkIRect& srcRect, const SkIPoint& dstPoint) const {
int dstSampleCnt = 0;
int srcSampleCnt = 0;
if (const GrRenderTargetProxy* rtProxy = dst->asRenderTargetProxy()) {
dstSampleCnt = rtProxy->numSamples();
}
if (const GrRenderTargetProxy* rtProxy = src->asRenderTargetProxy()) {
srcSampleCnt = rtProxy->numSamples();
}
SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTargetProxy()));
SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTargetProxy()));
const GrTextureProxy* dstTex = dst->asTextureProxy();
const GrTextureProxy* srcTex = src->asTextureProxy();
GrTextureType dstTexType;
GrTextureType* dstTexTypePtr = nullptr;
GrTextureType srcTexType;
GrTextureType* srcTexTypePtr = nullptr;
if (dstTex) {
dstTexType = dstTex->textureType();
dstTexTypePtr = &dstTexType;
}
if (srcTex) {
srcTexType = srcTex->textureType();
srcTexTypePtr = &srcTexType;
}
auto dstFormat = dst->backendFormat().asGLFormat();
auto srcFormat = src->backendFormat().asGLFormat();
return this->canCopyTexSubImage(dstFormat, has_msaa_render_buffer(dst, *this), dstTexTypePtr,
srcFormat, has_msaa_render_buffer(src, *this), srcTexTypePtr) ||
this->canCopyAsBlit(dstFormat, dstSampleCnt, dstTexTypePtr, srcFormat, srcSampleCnt,
srcTexTypePtr, src->getBoundsRect(), src->priv().isExact(), srcRect,
dstPoint) ||
this->canCopyAsDraw(dstFormat, SkToBool(srcTex));
}
GrCaps::DstCopyRestrictions GrGLCaps::getDstCopyRestrictions(const GrRenderTargetProxy* src,
GrColorType colorType) const {
if (src->asTextureProxy() && !this->isFormatAsColorTypeRenderable(colorType,
src->backendFormat())) {
return {};
}
if (const auto* texProxy = src->asTextureProxy()) {
if (texProxy->textureType() == GrTextureType::kExternal) {
return {};
}
}
DstCopyRestrictions blitFramebufferRestrictions = {};
if (src->numSamples() > 1 &&
(this->blitFramebufferSupportFlags() & kResolveMustBeFull_BlitFrambufferFlag)) {
blitFramebufferRestrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
blitFramebufferRestrictions.fMustCopyWholeSrc = true;
} else if (src->numSamples() > 1 && (this->blitFramebufferSupportFlags() &
kRectsMustMatchForMSAASrc_BlitFramebufferFlag)) {
blitFramebufferRestrictions.fRectsMustMatch = GrSurfaceProxy::RectsMustMatch::kYes;
}
auto srcFormat = src->backendFormat().asGLFormat();
if (srcFormat == GrGLFormat::kBGRA8) {
if (this->canFormatBeFBOColorAttachment(srcFormat)) {
return blitFramebufferRestrictions;
}
return {};
}
{
bool srcIsMSAARenderbuffer = src->numSamples() > 1 &&
this->usesMSAARenderBuffers();
if (srcIsMSAARenderbuffer) {
if (this->canFormatBeFBOColorAttachment(srcFormat)) {
return blitFramebufferRestrictions;
}
return {};
}
}
return {};
}
void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
const GrContextOptions& contextOptions,
GrShaderCaps* shaderCaps,
FormatWorkarounds* formatWorkarounds) {
if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
fDriverBugWorkarounds.disable_discard_framebuffer) {
fInvalidateFBType = kNone_InvalidateFBType;
}
if (GR_IS_GR_GL(ctxInfo.standard()) &&
ctxInfo.driver() == kNVIDIA_GrGLDriver &&
ctxInfo.driverVersion() < GR_GL_DRIVER_VER(367, 57, 0)) {
fClearTextureSupport = false;
}
#ifdef SK_BUILD_FOR_MAC
if (kATI_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fGeometryShaderSupport = false;
}
shaderCaps->fGSInvocationsSupport = false;
#endif
if (kQualcomm_GrGLDriver == ctxInfo.driver() &&
ctxInfo.driverVersion() < GR_GL_DRIVER_VER(127, 0, 0)) {
shaderCaps->fGeometryShaderSupport = false;
}
#if defined(__has_feature)
#if defined(SK_BUILD_FOR_MAC) && __has_feature(thread_sanitizer)
fMapBufferType = kNone_MapBufferType;
fMapBufferFlags = kNone_MapFlags;
fTransferBufferSupport = false;
fTransferBufferType = kNone_TransferBufferType;
#endif
#endif
if (ctxInfo.renderer() == kAdreno3xx_GrGLRenderer &&
ctxInfo.driverVersion() > GR_GL_DRIVER_VER(127, 0, 0)) {
fMapBufferType = kNone_MapBufferType;
fMapBufferFlags = kNone_MapFlags;
fTransferBufferSupport = false;
fTransferBufferType = kNone_TransferBufferType;
}
if (kANGLE_GrGLDriver == ctxInfo.driver()) {
fTransferBufferSupport = false;
fTransferBufferType = kNone_TransferBufferType;
}
if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
fMipMapSupport = false;
}
#ifndef SK_BUILD_FOR_IOS
if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer() ||
kPowerVRRogue_GrGLRenderer == ctxInfo.renderer() ||
(kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
ctxInfo.driver() != kChromium_GrGLDriver)) {
fPerformColorClearsAsDraws = true;
}
#endif
if (kAMDRadeonHD7xxx_GrGLRenderer == ctxInfo.renderer() ||
kAMDRadeonR9M4xx_GrGLRenderer == ctxInfo.renderer()) {
fPerformColorClearsAsDraws = true;
}
#ifdef SK_BUILD_FOR_MAC
if (kIntel_GrGLVendor == ctxInfo.vendor() &&
ctxInfo.driverVersion() < GR_GL_DRIVER_VER(10, 30, 12)) {
fPerformColorClearsAsDraws = true;
}
if (kNVIDIA_GrGLVendor == ctxInfo.vendor()) {
fPerformColorClearsAsDraws = true;
}
#endif
if (GrGLANGLEBackend::kD3D11 == ctxInfo.angleBackend()) {
fPerformColorClearsAsDraws = true;
}
if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
if (ctxInfo.driverVersion() <= GR_GL_DRIVER_VER(219, 0, 0)) {
fPerformStencilClearsAsDraws = true;
}
fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
}
if (fDriverBugWorkarounds.gl_clear_broken) {
fPerformColorClearsAsDraws = true;
fPerformStencilClearsAsDraws = true;
}
if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() &&
ctxInfo.driverVersion() > GR_GL_DRIVER_VER(53, 0, 0)) {
fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = true;
}
if (kQualcomm_GrGLDriver == ctxInfo.driver()) {
fDetachStencilFromMSAABuffersBeforeReadPixels = true;
}
if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
fMaxInstancesPerDrawWithoutCrashing = 999;
} else if (fDriverBugWorkarounds.disallow_large_instanced_draw) {
fMaxInstancesPerDrawWithoutCrashing = 0x4000000;
}
if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO = true;
fUseDrawInsteadOfAllRenderTargetWrites = true;
}
#ifdef SK_BUILD_FOR_MAC
static constexpr bool isMAC = true;
#else
static constexpr bool isMAC = false;
#endif
if (fMipMapLevelAndLodControlSupport &&
(contextOptions.fDoManualMipmapping ||
(kIntel_GrGLVendor == ctxInfo.vendor()) ||
(kNVIDIA_GrGLDriver == ctxInfo.driver() && isMAC) ||
(kATI_GrGLVendor == ctxInfo.vendor()))) {
fDoManualMipmapping = true;
}
#ifdef SK_BUILD_FOR_MAC
if (kIntelBroadwell_GrGLRenderer == ctxInfo.renderer()) {
fClearToBoundaryValuesIsBroken = true;
}
#endif
if (kQualcomm_GrGLVendor == ctxInfo.vendor()) {
fDrawArraysBaseVertexIsBroken = true;
}
if (kAdreno5xx_GrGLRenderer == ctxInfo.renderer()) {
shaderCaps->fFBFetchSupport = false;
}
shaderCaps->fCanUseAnyFunctionInShader = kImagination_GrGLVendor != ctxInfo.vendor();
if (kIntel_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fFragCoordConventionsExtensionString = nullptr;
}
if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
shaderCaps->fCanUseMinAndAbsTogether = false;
shaderCaps->fCanUseFractForNegativeValues = false;
}
if (kIntel_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fMustForceNegatedAtanParamToFloat = true;
}
if (kIntel_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fMustDoOpBetweenFloorAndAbs = true;
}
if (shaderCaps->fFBFetchSupport && kQualcomm_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fRequiresLocalOutputColorForFBFetch = true;
}
if (kMaliT_GrGLRenderer == ctxInfo.renderer()) {
shaderCaps->fMustObfuscateUniformColor = true;
}
#ifdef SK_BUILD_FOR_WIN
if (kANGLE_GrGLDriver == ctxInfo.driver() || kChromium_GrGLDriver == ctxInfo.driver()) {
shaderCaps->fMustGuardDivisionEvenAfterExplicitZeroCheck = true;
}
#endif
if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer()) {
shaderCaps->fCanUseFragCoord = false;
}
if (kTegra_PreK1_GrGLRenderer == ctxInfo.renderer()) {
shaderCaps->fCanUseFragCoord = false;
}
if (kARM_GrGLVendor == ctxInfo.vendor()) {
shaderCaps->fIncompleteShortIntPrecision = true;
}
if (fDriverBugWorkarounds.add_and_true_to_loop_condition) {
shaderCaps->fAddAndTrueToLoopCondition = true;
}
if (fDriverBugWorkarounds.unfold_short_circuit_as_ternary_operation) {
shaderCaps->fUnfoldShortCircuitAsTernary = true;
}
if (fDriverBugWorkarounds.emulate_abs_int_function) {
shaderCaps->fEmulateAbsIntFunction = true;
}
if (fDriverBugWorkarounds.rewrite_do_while_loops) {
shaderCaps->fRewriteDoWhileLoops = true;
}
if (fDriverBugWorkarounds.remove_pow_with_constant_exponent) {
shaderCaps->fRemovePowWithConstantExponent = true;
}
if (kAdreno3xx_GrGLRenderer == ctxInfo.renderer() ||
kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
shaderCaps->fMustWriteToFragColor = true;
}
if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
kAdreno5xx_GrGLRenderer == ctxInfo.renderer() ||
kIntel_GrGLDriver == ctxInfo.driver() ||
kChromium_GrGLDriver == ctxInfo.driver()) {
fBlendEquationSupport = kBasic_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
}
if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
ctxInfo.driverVersion() < GR_GL_DRIVER_VER(337, 00, 0) &&
kAdvanced_BlendEquationSupport == fBlendEquationSupport) {
fBlendEquationSupport = kBasic_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
}
if (fDriverBugWorkarounds.disable_blend_equation_advanced) {
fBlendEquationSupport = kBasic_BlendEquationSupport;
shaderCaps->fAdvBlendEqInteraction = GrShaderCaps::kNotSupported_AdvBlendEqInteraction;
}
if (this->advancedBlendEquationSupport()) {
if (kNVIDIA_GrGLDriver == ctxInfo.driver() &&
ctxInfo.driverVersion() < GR_GL_DRIVER_VER(355, 00, 0)) {
fAdvBlendEqBlacklist |= (1 << kColorDodge_GrBlendEquation) |
(1 << kColorBurn_GrBlendEquation);
}
if (kARM_GrGLVendor == ctxInfo.vendor()) {
fAdvBlendEqBlacklist |= (1 << kColorBurn_GrBlendEquation);
}
}
if (fMultisampleDisableSupport &&
this->shaderCaps()->dualSourceBlendingSupport() &&
this->shaderCaps()->pathRenderingSupport() &&
fMixedSamplesSupport &&
#if GR_TEST_UTILS
(contextOptions.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) &&
#endif
(kNVIDIA_GrGLDriver == ctxInfo.driver() ||
kChromium_GrGLDriver == ctxInfo.driver())) {
fInvalidateFBType = kNone_InvalidateFBType;
}
if (ctxInfo.hasExtension("GL_OES_EGL_image_external") &&
ctxInfo.glslGeneration() >= k330_GrGLSLGeneration &&
!shaderCaps->fExternalTextureSupport) {
shaderCaps->fExternalTextureSupport = true;
shaderCaps->fExternalTextureExtensionString = "GL_OES_EGL_image_external";
shaderCaps->fSecondExternalTextureExtensionString = "GL_OES_EGL_image_external_essl3";
}
#ifdef SK_BUILD_FOR_IOS
fWritePixelsRowBytesSupport = false;
#endif
if (kMesa_GrGLDriver == ctxInfo.driver() &&
(kIntelSandyBridge_GrGLRenderer == ctxInfo.renderer() ||
kIntelIvyBridge_GrGLRenderer == ctxInfo.renderer() ||
kIntelValleyView_GrGLRenderer == ctxInfo.renderer())) {
fDriverBlacklistCCPR = true;
}
if (kATI_GrGLVendor == ctxInfo.vendor() ||
kImagination_GrGLVendor == ctxInfo.vendor() ||
kQualcomm_GrGLVendor == ctxInfo.vendor() ) {
fDriverBlacklistMSAACCPR = true;
}
#ifdef SK_BUILD_FOR_ANDROID
fDontSetBaseOrMaxLevelForExternalTextures = true;
#endif
if (kPowerVRRogue_GrGLRenderer == ctxInfo.renderer()) {
fNeverDisableColorWrites = true;
shaderCaps->fMustWriteToFragColor = true;
}
if (kQualcomm_GrGLVendor == ctxInfo.vendor() &&
k320es_GrGLSLGeneration != ctxInfo.glslGeneration()) {
shaderCaps->fNoPerspectiveInterpolationSupport = false;
}
if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer()) {
fSRGBWriteControl = false;
}
formatWorkarounds->fDisableTextureRedForMesa = kOSMesa_GrGLRenderer == ctxInfo.renderer();
#if defined(SK_BUILD_FOR_MAC)
formatWorkarounds->fDisableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor();
#endif
formatWorkarounds->fDisablePerFormatTextureStorageForCommandBufferES2 =
kChromium_GrGLDriver == ctxInfo.driver() && ctxInfo.version() < GR_GL_VER(3, 0);
formatWorkarounds->fDisableNonRedSingleChannelTexStorageForANGLEGL =
GrGLANGLEBackend::kOpenGL == ctxInfo.angleBackend();
#if defined(SK_BUILD_FOR_WIN)
formatWorkarounds->fDisableBGRATextureStorageForIntelWindowsES =
kIntel_GrGLDriver == ctxInfo.driver() && GR_IS_GR_GL_ES(ctxInfo.standard());
#endif
formatWorkarounds->fDisableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer();
formatWorkarounds->fDisableLuminance16F = kIntelBroadwell_GrGLRenderer == ctxInfo.renderer() ||
ctxInfo.vendor() == kQualcomm_GrGLVendor;
if (kAndroidEmulator_GrGLDriver == ctxInfo.driver()) {
shaderCaps->fNoDefaultPrecisionForExternalSamplers = true;
}
}
void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
if (options.fDisableDriverCorrectnessWorkarounds) {
SkASSERT(!fDoManualMipmapping);
SkASSERT(!fClearToBoundaryValuesIsBroken);
SkASSERT(0 == fMaxInstancesPerDrawWithoutCrashing);
SkASSERT(!fDrawArraysBaseVertexIsBroken);
SkASSERT(!fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO);
SkASSERT(!fUseDrawInsteadOfAllRenderTargetWrites);
SkASSERT(!fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines);
SkASSERT(!fDetachStencilFromMSAABuffersBeforeReadPixels);
SkASSERT(!fDontSetBaseOrMaxLevelForExternalTextures);
SkASSERT(!fNeverDisableColorWrites);
}
if (options.fDoManualMipmapping) {
fDoManualMipmapping = true;
}
if (options.fDisallowGLSLBinaryCaching) {
fProgramBinarySupport = false;
}
#if GR_TEST_UTILS
if (options.fCacheSKSL) {
fProgramBinarySupport = false;
}
#endif
}
bool GrGLCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
if (tex->hasBaseLevelBeenBoundToFBO()) {
return false;
}
}
} if (auto rt = surface->asRenderTarget()) {
if (fUseDrawInsteadOfAllRenderTargetWrites) {
return false;
}
if (rt->numSamples() > 1 && this->usesMSAARenderBuffers()) {
return false;
}
return SkToBool(surface->asTexture());
}
return true;
}
GrCaps::SurfaceReadPixelsSupport GrGLCaps::surfaceSupportsReadPixels(
const GrSurface* surface) const {
if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
return SurfaceReadPixelsSupport::kCopyToTexture2D;
}
}
return SurfaceReadPixelsSupport::kSupported;
}
size_t offset_alignment_for_transfer_buffer(GrGLenum externalType) {
switch (externalType) {
case GR_GL_UNSIGNED_BYTE: return sizeof(GrGLubyte);
case GR_GL_BYTE: return sizeof(GrGLbyte);
case GR_GL_UNSIGNED_SHORT: return sizeof(GrGLushort);
case GR_GL_SHORT: return sizeof(GrGLshort);
case GR_GL_UNSIGNED_INT: return sizeof(GrGLuint);
case GR_GL_INT: return sizeof(GrGLint);
case GR_GL_HALF_FLOAT: return sizeof(GrGLhalf);
case GR_GL_FLOAT: return sizeof(GrGLfloat);
case GR_GL_UNSIGNED_SHORT_5_6_5: return sizeof(GrGLushort);
case GR_GL_UNSIGNED_SHORT_4_4_4_4: return sizeof(GrGLushort);
case GR_GL_UNSIGNED_SHORT_5_5_5_1: return sizeof(GrGLushort);
case GR_GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GrGLuint);
#if 0
case GR_GL_UNSIGNED_BYTE_3_3_2: return sizeof(GrGLubyte);
case GR_GL_UNSIGNED_BYTE_2_3_3_REV: return sizeof(GrGLubyte);
case GR_GL_UNSIGNED_SHORT_5_6_5_REV: return sizeof(GrGLushort);
case GR_GL_UNSIGNED_SHORT_4_4_4_4_REV: return sizeof(GrGLushort);
case GR_GL_UNSIGNED_SHORT_1_5_5_5_REV: return sizeof(GrGLushort);
case GR_GL_UNSIGNED_INT_8_8_8_8: return sizeof(GrGLuint);
case GR_GL_UNSIGNED_INT_8_8_8_8_REV: return sizeof(GrGLuint);
case GR_GL_UNSIGNED_INT_10_10_10_2: return sizeof(GrGLuint);
case GR_GL_UNSIGNED_INT_24_8: return sizeof(GrGLuint);
case GR_GL_UNSIGNED_INT_10F_11F_11F_REV: return sizeof(GrGLuint);
case GR_GL_UNSIGNED_INT_5_9_9_9_REV: return sizeof(GrGLuint);
case GR_GL_FLOAT_32_UNSIGNED_INT_24_8_REV: return 4;
#endif
default: return 0;
}
}
GrCaps::SupportedRead GrGLCaps::onSupportedReadPixelsColorType(
GrColorType srcColorType, const GrBackendFormat& srcBackendFormat,
GrColorType dstColorType) const {
GrCaps::SupportedRead fallbackRead = {GrColorType::kUnknown, 0};
const auto& formatInfo = this->getFormatInfo(srcBackendFormat.asGLFormat());
bool foundSrcCT = false;
for (int i = 0; !foundSrcCT && i < formatInfo.fColorTypeInfoCount; ++i) {
if (formatInfo.fColorTypeInfos[i].fColorType == srcColorType) {
const ColorTypeInfo& ctInfo = formatInfo.fColorTypeInfos[i];
foundSrcCT = true;
for (int j = 0; j < ctInfo.fExternalIOFormatCount; ++j) {
const auto& ioInfo = ctInfo.fExternalIOFormats[j];
if (ioInfo.fExternalReadFormat != 0) {
GrGLenum transferOffsetAlignment =
offset_alignment_for_transfer_buffer(ioInfo.fExternalType);
if (ioInfo.fColorType == dstColorType) {
return {dstColorType, transferOffsetAlignment};
}
if (fallbackRead.fColorType == GrColorType::kUnknown) {
fallbackRead = {ioInfo.fColorType, transferOffsetAlignment};
}
}
}
}
}
return fallbackRead;
}
GrCaps::SupportedWrite GrGLCaps::supportedWritePixelsColorType(GrColorType surfaceColorType,
const GrBackendFormat& surfaceFormat,
GrColorType srcColorType) const {
GrColorType fallbackCT = GrColorType::kUnknown;
const auto& formatInfo = this->getFormatInfo(surfaceFormat.asGLFormat());
bool foundSurfaceCT = false;
for (int i = 0; !foundSurfaceCT && i < formatInfo.fColorTypeInfoCount; ++i) {
if (formatInfo.fColorTypeInfos[i].fColorType == surfaceColorType) {
const ColorTypeInfo& ctInfo = formatInfo.fColorTypeInfos[i];
foundSurfaceCT = true;
for (int j = 0; j < ctInfo.fExternalIOFormatCount; ++j) {
const auto& ioInfo = ctInfo.fExternalIOFormats[j];
if (ioInfo.fExternalTexImageFormat != 0) {
if (ioInfo.fColorType == srcColorType) {
return {srcColorType, 1};
}
if (fallbackCT == GrColorType::kUnknown) {
fallbackCT = ioInfo.fColorType;
}
}
}
}
}
return {fallbackCT, 1};
}
bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const {
GrGLFramebufferInfo fbInfo;
SkAssertResult(backendRT.getGLFramebufferInfo(&fbInfo));
return fbInfo.fFBOID != 0;
}
bool GrGLCaps::isFormatSRGB(const GrBackendFormat& format) const {
return format.asGLFormat() == GrGLFormat::kSRGB8_ALPHA8;
}
bool GrGLCaps::isFormatCompressed(const GrBackendFormat& format) const {
auto fmt = format.asGLFormat();
return fmt == GrGLFormat::kCOMPRESSED_RGB8_ETC2 || fmt == GrGLFormat::kCOMPRESSED_ETC1_RGB8
|| fmt == GrGLFormat::kCOMPRESSED_ASTC_RGB8;
}
bool GrGLCaps::isFormatTexturableAndUploadable(GrColorType ct,
const GrBackendFormat& format) const {
auto glFormat = format.asGLFormat();
const FormatInfo& info = this->getFormatInfo(glFormat);
return this->isFormatTexturable(glFormat) &&
SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kUploadData_Flag);
}
bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format) const {
return this->isFormatTexturable(format.asGLFormat());
}
bool GrGLCaps::isFormatTexturable(GrGLFormat format) const {
const FormatInfo& info = this->getFormatInfo(format);
return SkToBool(info.fFlags & FormatInfo::kTexturable_Flag);
}
bool GrGLCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
int sampleCount) const {
auto f = format.asGLFormat();
const FormatInfo& info = this->getFormatInfo(f);
if (!SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kRenderable_Flag)) {
return false;
}
return this->isFormatRenderable(f, sampleCount);
}
bool GrGLCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
return this->isFormatRenderable(format.asGLFormat(), sampleCount);
}
int GrGLCaps::getRenderTargetSampleCount(int requestedCount, GrGLFormat format) const {
const FormatInfo& info = this->getFormatInfo(format);
int count = info.fColorSampleCounts.count();
if (!count) {
return 0;
}
requestedCount = SkTMax(1, requestedCount);
if (1 == requestedCount) {
return info.fColorSampleCounts[0] == 1 ? 1 : 0;
}
for (int i = 0; i < count; ++i) {
if (info.fColorSampleCounts[i] >= requestedCount) {
int count = info.fColorSampleCounts[i];
if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
count = SkTMin(count, 4);
}
return count;
}
}
return 0;
}
int GrGLCaps::maxRenderTargetSampleCount(GrGLFormat format) const {
const FormatInfo& info = this->getFormatInfo(format);
const auto& table = info.fColorSampleCounts;
if (!table.count()) {
return 0;
}
int count = table[table.count() - 1];
if (fDriverBugWorkarounds.max_msaa_sample_count_4) {
count = SkTMin(count, 4);
}
return count;
}
bool GrGLCaps::canFormatBeFBOColorAttachment(GrGLFormat format) const {
return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kFBOColorAttachment_Flag);
}
bool GrGLCaps::isFormatCopyable(const GrBackendFormat& format) const {
return this->canFormatBeFBOColorAttachment(format.asGLFormat());
}
bool GrGLCaps::formatSupportsTexStorage(GrGLFormat format) const {
return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kCanUseTexStorage_Flag);
}
static GrPixelConfig validate_sized_format(GrGLFormat format,
GrColorType ct,
GrGLStandard standard) {
switch (ct) {
case GrColorType::kUnknown:
return kUnknown_GrPixelConfig;
case GrColorType::kAlpha_8:
if (format == GrGLFormat::kALPHA8) {
return kAlpha_8_as_Alpha_GrPixelConfig;
} else if (format == GrGLFormat::kR8) {
return kAlpha_8_as_Red_GrPixelConfig;
}
break;
case GrColorType::kBGR_565:
if (format == GrGLFormat::kRGB565) {
return kRGB_565_GrPixelConfig;
}
break;
case GrColorType::kABGR_4444:
if (format == GrGLFormat::kRGBA4) {
return kRGBA_4444_GrPixelConfig;
}
break;
case GrColorType::kRGBA_8888:
if (format == GrGLFormat::kRGBA8) {
return kRGBA_8888_GrPixelConfig;
}
break;
case GrColorType::kRGBA_8888_SRGB:
if (format == GrGLFormat::kSRGB8_ALPHA8) {
return kSRGBA_8888_GrPixelConfig;
}
break;
case GrColorType::kRGB_888x:
if (format == GrGLFormat::kRGB8) {
return kRGB_888_GrPixelConfig;
} else if (format == GrGLFormat::kRGBA8) {
return kRGB_888X_GrPixelConfig;
} else if (format == GrGLFormat::kCOMPRESSED_RGB8_ETC2 ||
format == GrGLFormat::kCOMPRESSED_ETC1_RGB8) {
return kRGB_ETC1_GrPixelConfig;
} else if (format == GrGLFormat::kCOMPRESSED_ASTC_RGB8) {
return kRGB_ASTC_GrPixelConfig;
}
break;
case GrColorType::kRG_88:
if (format == GrGLFormat::kRG8) {
return kRG_88_GrPixelConfig;
}
break;
case GrColorType::kBGRA_8888:
if (format == GrGLFormat::kRGBA8) {
if (GR_IS_GR_GL(standard)) {
return kBGRA_8888_GrPixelConfig;
}
} else if (format == GrGLFormat::kBGRA8) {
if (GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard)) {
return kBGRA_8888_GrPixelConfig;
}
}
break;
case GrColorType::kRGBA_1010102:
if (format == GrGLFormat::kRGB10_A2) {
return kRGBA_1010102_GrPixelConfig;
}
break;
case GrColorType::kGray_8:
if (format == GrGLFormat::kLUMINANCE8) {
return kGray_8_as_Lum_GrPixelConfig;
} else if (format == GrGLFormat::kR8) {
return kGray_8_as_Red_GrPixelConfig;
}
break;
case GrColorType::kAlpha_F16:
if (format == GrGLFormat::kLUMINANCE16F) {
return kAlpha_half_as_Lum_GrPixelConfig;
} else if (format == GrGLFormat::kR16F) {
return kAlpha_half_as_Red_GrPixelConfig;
}
break;
case GrColorType::kRGBA_F16:
if (format == GrGLFormat::kRGBA16F) {
return kRGBA_half_GrPixelConfig;
}
break;
case GrColorType::kRGBA_F16_Clamped:
if (format == GrGLFormat::kRGBA16F) {
return kRGBA_half_Clamped_GrPixelConfig;
}
break;
case GrColorType::kRGBA_F32:
if (format == GrGLFormat::kRGBA32F) {
return kRGBA_float_GrPixelConfig;
}
break;
case GrColorType::kR_16:
if (format == GrGLFormat::kR16) {
return kR_16_GrPixelConfig;
}
break;
case GrColorType::kRG_1616:
if (format == GrGLFormat::kRG16) {
return kRG_1616_GrPixelConfig;
}
break;
case GrColorType::kRGBA_16161616:
if (format == GrGLFormat::kRGBA16) {
return kRGBA_16161616_GrPixelConfig;
}
break;
case GrColorType::kRG_F16:
if (format == GrGLFormat::kRG16F) {
return kRG_half_GrPixelConfig;
}
break;
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
break;
}
SkDebugf("Unknown pixel config 0x%x\n", format);
return kUnknown_GrPixelConfig;
}
bool GrGLCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
const GrBackendFormat& format) const {
GrGLFormat glFormat = format.asGLFormat();
const auto& info = this->getFormatInfo(glFormat);
for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
if (info.fColorTypeInfos[i].fColorType == ct) {
return true;
}
}
return false;
}
GrPixelConfig GrGLCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
GrColorType ct) const {
return validate_sized_format(format.asGLFormat(), ct, fStandard);
}
GrColorType GrGLCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
bool isAlphaChannel) const {
switch (format.asGLFormat()) {
case GrGLFormat::kLUMINANCE8:
case GrGLFormat::kR8:
case GrGLFormat::kALPHA8:
return isAlphaChannel ? GrColorType::kAlpha_8
: GrColorType::kGray_8;
case GrGLFormat::kRG8: return GrColorType::kRG_88;
case GrGLFormat::kRGBA8: return GrColorType::kRGBA_8888;
case GrGLFormat::kRGB8: return GrColorType::kRGB_888x;
case GrGLFormat::kBGRA8: return GrColorType::kBGRA_8888;
case GrGLFormat::kRGB10_A2: return GrColorType::kRGBA_1010102;
case GrGLFormat::kLUMINANCE16F:
case GrGLFormat::kR16F: return GrColorType::kAlpha_F16;
case GrGLFormat::kR16: return GrColorType::kR_16;
case GrGLFormat::kRG16: return GrColorType::kRG_1616;
case GrGLFormat::kRGBA16: return GrColorType::kRGBA_16161616;
case GrGLFormat::kRG16F: return GrColorType::kRG_F16;
default: return GrColorType::kUnknown;
}
SkUNREACHABLE;
}
GrBackendFormat GrGLCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
auto format = this->getFormatFromColorType(ct);
if (format == GrGLFormat::kUnknown) {
return GrBackendFormat();
}
return GrBackendFormat::MakeGL(this->getSizedInternalFormat(format), GR_GL_TEXTURE_2D);
}
GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
SkImage::CompressionType compressionType) const {
switch (compressionType) {
case SkImage::kETC1_CompressionType:
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D);
case SkImage::kASTC_CompressionType:
if (this->isFormatTexturable(GrGLFormat::kCOMPRESSED_ASTC_RGB8)) {
return GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGBA_ASTC_4x4, GR_GL_TEXTURE_2D);
}
return {};
}
SK_ABORT("Invalid compression type");
}
bool GrGLCaps::canClearTextureOnCreation() const { return fClearTextureSupport; }
GrSwizzle GrGLCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
const auto& info = this->getFormatInfo(format.asGLFormat());
for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
const auto& ctInfo = info.fColorTypeInfos[i];
if (ctInfo.fColorType == colorType) {
return ctInfo.fTextureSwizzle;
}
}
return GrSwizzle::RGBA();
}
GrSwizzle GrGLCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
const auto& info = this->getFormatInfo(format.asGLFormat());
for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
const auto& ctInfo = info.fColorTypeInfos[i];
if (ctInfo.fColorType == colorType) {
return ctInfo.fOutputSwizzle;
}
}
return GrSwizzle::RGBA();
}
#if GR_TEST_UTILS
std::vector<GrCaps::TestFormatColorTypeCombination> GrGLCaps::getTestingCombinations() const {
std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
{ GrColorType::kAlpha_8,
GrBackendFormat::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D) },
{ GrColorType::kAlpha_8,
GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D) },
{ GrColorType::kBGR_565,
GrBackendFormat::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D) },
{ GrColorType::kABGR_4444,
GrBackendFormat::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_8888,
GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_8888_SRGB,
GrBackendFormat::MakeGL(GR_GL_SRGB8_ALPHA8, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGB_888x,
GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGB_888x,
GrBackendFormat::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGB_888x,
GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGB8_ETC2, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGB_888x,
GrBackendFormat::MakeGL(GR_GL_COMPRESSED_ETC1_RGB8, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGB_888x,
GrBackendFormat::MakeGL(GR_GL_COMPRESSED_RGBA_ASTC_4x4, GR_GL_TEXTURE_2D) },
{ GrColorType::kRG_88,
GrBackendFormat::MakeGL(GR_GL_RG8, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_1010102,
GrBackendFormat::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D) },
{ GrColorType::kGray_8,
GrBackendFormat::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D) },
{ GrColorType::kGray_8,
GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D) },
{ GrColorType::kAlpha_F16,
GrBackendFormat::MakeGL(GR_GL_R16F, GR_GL_TEXTURE_2D) },
{ GrColorType::kAlpha_F16,
GrBackendFormat::MakeGL(GR_GL_LUMINANCE16F, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_F16,
GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_F16_Clamped,
GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_F32,
GrBackendFormat::MakeGL(GR_GL_RGBA32F, GR_GL_TEXTURE_2D) },
{ GrColorType::kR_16,
GrBackendFormat::MakeGL(GR_GL_R16, GR_GL_TEXTURE_2D) },
{ GrColorType::kRG_1616,
GrBackendFormat::MakeGL(GR_GL_RG16, GR_GL_TEXTURE_2D) },
{ GrColorType::kRGBA_16161616,
GrBackendFormat::MakeGL(GR_GL_RGBA16, GR_GL_TEXTURE_2D) },
{ GrColorType::kRG_F16,
GrBackendFormat::MakeGL(GR_GL_RG16F, GR_GL_TEXTURE_2D) },
};
if (GR_IS_GR_GL(fStandard)) {
combos.push_back({ GrColorType::kBGRA_8888,
GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D) });
} else {
SkASSERT(GR_IS_GR_GL_ES(fStandard) || GR_IS_GR_WEBGL(fStandard));
combos.push_back({ GrColorType::kBGRA_8888,
GrBackendFormat::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D) });
}
return combos;
}
#endif