diff options
Diffstat (limited to 'src/gpu/gl/GrGLCaps.cpp')
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 90 |
1 files changed, 68 insertions, 22 deletions
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index e05a4bb970..9af54b1dec 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -1167,8 +1167,8 @@ void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { writer->appendHexU32("flags", fConfigTable[i].fFlags); writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat); writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat); - writer->appendHexU32("e_format", - fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage]); + writer->appendHexU32("e_format_read_pixels", + fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]); writer->appendHexU32( "e_format_teximage", fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]); @@ -1200,7 +1200,7 @@ bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig ext bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig, GrGLenum* externalFormat, GrGLenum* externalType) const { - if (!this->getExternalFormat(surfaceConfig, externalConfig, kOther_ExternalFormatUsage, + if (!this->getExternalFormat(surfaceConfig, externalConfig, kReadPixels_ExternalFormatUsage, externalFormat, externalType)) { return false; } @@ -1322,6 +1322,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, bool disableSRGBWriteControlForAdreno4xx = false; bool disableR8TexStorageForANGLEGL = false; bool disableSRGBRenderWithMSAAForMacAMD = false; + bool disableRGB8ForMali400 = false; if (!contextOptions.fDisableDriverCorrectnessWorkarounds) { // ARB_texture_rg is part of OpenGL 3.0, but osmesa doesn't support GL_RED @@ -1348,6 +1349,8 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, #if defined(SK_BUILD_FOR_MAC) disableSRGBRenderWithMSAAForMacAMD = kATI_GrGLVendor == ctxInfo.vendor(); #endif + // Mali-400 fails ReadPixels tests, mostly with non-0xFF alpha values when read as GL_RGBA8. + disableRGB8ForMali400 = kMali4xx_GrGLRenderer == ctxInfo.renderer(); } uint32_t nonMSAARenderFlags = ConfigInfo::kRenderable_Flag | @@ -1386,14 +1389,14 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0; fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0; - fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = 0; + fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0; fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0; fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; - fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1415,7 +1418,41 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, } fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); - fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kRGB_888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB; + fConfigTable[kRGB_888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB8; + // Our external RGB data always has a byte where alpha would be. When calling read pixels we + // want to read to kRGB_888x color type and ensure that gets 0xFF written. Using GL_RGB would + // read back unaligned 24bit RGB color values. Note that this all a bit moot as we don't + // currently expect to ever read back GrColorType::kRGB_888x because our implementation of + // supportedReadPixelsColorType never returns it. + fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; + fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; + fConfigTable[kRGB_888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; + fConfigTable[kRGB_888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; + if (kGL_GrGLStandard == standard) { + // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be a + // supported render buffer format. Since we usually use render buffers for MSAA on non-ES GL + // we don't support MSAA for GL_RGB8. On 4.2+ we could check using + // glGetInternalFormativ(GL_RENDERBUFFER, GL_RGB8, GL_INTERNALFORMAT_SUPPORTED, ...) if this + // becomes an issue. + // This also would probably work in mixed-samples mode where there is no MSAA color buffer + // but we don't support that just for simplicity's sake. + fConfigTable[kRGB_888_GrPixelConfig].fFlags |= nonMSAARenderFlags; + } else { + // 3.0 and the extension support this as a render buffer format. + if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_rgb8_rgba8")) { + fConfigTable[kRGB_888_GrPixelConfig].fFlags |= allRenderFlags; + } + } + if (texStorageSupported) { + fConfigTable[kRGB_888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; + } + fConfigTable[kRGB_888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); + if (disableRGB8ForMali400) { + fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0; + } + + fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_BGRA; fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1527,7 +1564,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8; // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub]Image. - fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1547,7 +1584,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8; // GL does not do srgb<->rgb conversions when transferring between cpu and gpu. Thus, the // external format is GL_BGRA. - fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_BGRA; fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1567,7 +1604,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, } else { fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5; } - fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGB; fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5; fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1593,7 +1630,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4; - fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; fConfigTable[kRGBA_4444_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1612,7 +1649,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB10_A2; - fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV; @@ -1640,7 +1677,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, } alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA; alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8; - alphaInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_ALPHA; + alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA; alphaInfo.fSwizzle = GrSwizzle::AAAA(); if (fAlpha8IsRenderable && alpha8IsValidForGL) { alphaInfo.fFlags |= allRenderFlags; @@ -1651,7 +1688,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, redInfo.fFormatType = kNormalizedFixedPoint_FormatType; redInfo.fFormats.fBaseInternalFormat = GR_GL_RED; redInfo.fFormats.fSizedInternalFormat = GR_GL_R8; - redInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED; + redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED; redInfo.fSwizzle = GrSwizzle::RRRR(); // ES2 Command Buffer does not allow TexStorage with R8_EXT (so Alpha_8 and Gray_8) @@ -1680,7 +1717,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType; grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE; grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8; - grayLumInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_LUMINANCE; + grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE; grayLumInfo.fSwizzle = GrSwizzle::RGBA(); if ((standard == kGL_GrGLStandard && version <= GR_GL_VER(3, 0)) || (standard == kGLES_GrGLStandard && version < GR_GL_VER(3, 0))) { @@ -1692,7 +1729,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType; grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED; grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8; - grayRedInfo.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED; + grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED; grayRedInfo.fSwizzle = GrSwizzle::RRRA(); grayRedInfo.fFlags = ConfigInfo::kTextureable_Flag; @@ -1762,7 +1799,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format; fConfigTable[fpconfig].fFormats.fSizedInternalFormat = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F; - fConfigTable[fpconfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = format; + fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format; fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT; fConfigTable[fpconfig].fFormatType = kFloat_FormatType; if (hasFPTextures) { @@ -1794,7 +1831,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, redHalf.fFormatType = kFloat_FormatType; redHalf.fFormats.fBaseInternalFormat = GR_GL_RED; redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F; - redHalf.fFormats.fExternalFormat[kOther_ExternalFormatUsage] = GR_GL_RED; + redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED; redHalf.fSwizzle = GrSwizzle::RRRR(); if (textureRedSupport && hasHalfFPTextures) { redHalf.fFlags = ConfigInfo::kTextureable_Flag; @@ -1816,7 +1853,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F; - fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = + fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA; if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) { fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT; @@ -1850,10 +1887,10 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, bool useSizedRbFormats = kGLES_GrGLStandard == ctxInfo.standard(); for (int i = 0; i < kGrPixelConfigCnt; ++i) { - // Almost always we want to pass fExternalFormat[kOther_ExternalFormatUsage] as the <format> - // param to glTex[Sub]Image. + // Almost always we want to pass fExternalFormat[kReadPixels_ExternalFormatUsage] as the + // <format> param to glTex[Sub]Image. fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = - fConfigTable[i].fFormats.fExternalFormat[kOther_ExternalFormatUsage]; + fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]; fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ? fConfigTable[i].fFormats.fSizedInternalFormat : fConfigTable[i].fFormats.fBaseInternalFormat; @@ -1888,6 +1925,12 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, // unsupported. (If we have no sRGB support at all, this will get overwritten below). fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0; } + // On ES 2.0 we have to use GL_RGB with glTexImage as the internal/external formats must + // be the same. Moreover, if we write kRGB_888x data to a texture format on non-ES2 we want to + // be sure that we write 1 for alpha not whatever happens to be in the client provided the 'x' + // slot. + fConfigTable[kRGB_888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] = + GR_GL_RGB; // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image // as a base format. @@ -2561,7 +2604,10 @@ bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* confi } break; case kRGB_888x_SkColorType: - return false; + if (GR_GL_RGB8 == format) { + *config = kRGB_888_GrPixelConfig; + } + break; case kBGRA_8888_SkColorType: if (GR_GL_RGBA8 == format) { if (kGL_GrGLStandard == standard) { |