Move base and various sized formats off of GrGLCaps ConfigInfo.

Change-Id: Id3355d963ba61c19f5dbd85853536fafc2fd5c7f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227064
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Greg Daniel 2019-07-15 10:51:05 -04:00 committed by Skia Commit-Bot
parent a495d6d985
commit 85c375b4e6
3 changed files with 198 additions and 171 deletions

View File

@ -1281,19 +1281,20 @@ void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
writer->beginObject(nullptr, false);
writer->appendHexU32("flags", fConfigTable[i].fFlags);
writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
// writer->appendHexU32("b_internal", fConfigTable[i].fFormats.fBaseInternalFormat);
// writer->appendHexU32("s_internal", fConfigTable[i].fFormats.fSizedInternalFormat);
writer->appendHexU32("e_format_read_pixels",
fConfigTable[i].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]);
writer->appendHexU32(
"e_format_teximage",
fConfigTable[i].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage]);
writer->appendHexU32("e_type", fConfigTable[i].fFormats.fExternalType);
writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
writer->appendHexU32("i_for_renderbuffer",
fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
// writer->appendHexU32("i_for_teximage", fConfigTable[i].fFormats.fInternalFormatTexImage);
// writer->appendHexU32("i_for_renderbuffer",
// fConfigTable[i].fFormats.fInternalFormatRenderbuffer);
writer->endObject();
}
// TODO: Add dump of FormatInfos
writer->endArray();
writer->endObject();
@ -1303,7 +1304,7 @@ void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const { }
#endif
bool GrGLCaps::bgraIsInternalFormat() const {
return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA;
return this->getFormatFromColorType(GrColorType::kBGRA_8888) == GrGLFormat::kBGRA8;
}
bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
@ -1313,7 +1314,7 @@ bool GrGLCaps::getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig ext
externalFormat, externalType)) {
return false;
}
*internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
*internalFormat = this->getTexImageInternalFormat(this->pixelConfigToFormat(surfaceConfig));
return true;
}
@ -1322,7 +1323,7 @@ bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig,
if (!GrPixelConfigIsCompressed(surfaceConfig)) {
return false;
}
*internalFormat = fConfigTable[surfaceConfig].fFormats.fInternalFormatTexImage;
*internalFormat = this->getTexImageInternalFormat(this->pixelConfigToFormat(surfaceConfig));
return true;
}
@ -1335,15 +1336,6 @@ bool GrGLCaps::getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig ex
return true;
}
void GrGLCaps::getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
SkASSERT(!GrPixelConfigIsCompressed(config));
*internalFormat = fConfigTable[config].fFormats.fInternalFormatRenderbuffer;
}
void GrGLCaps::getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const {
*internalFormat = fConfigTable[config].fFormats.fSizedInternalFormat;
}
bool GrGLCaps::getExternalFormat(GrPixelConfig surfaceConfig, GrPixelConfig memoryConfig,
ExternalFormatUsage usage, GrGLenum* externalFormat,
GrGLenum* externalType) const {
@ -1377,6 +1369,12 @@ void GrGLCaps::setStencilFormatIndexForFormat(GrGLFormat format, int index) {
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 GrContextOptions& contextOptions,
const GrGLContextInfo& ctxInfo, const GrGLInterface* gli,
const FormatWorkarounds& formatWorkarounds) {
@ -1417,6 +1415,11 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
bool texImageSupportsSizedInternalFormat =
(GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)));
// All ES versions (thus far) require sized internal formats for render buffers.
// TODO: Always use sized internal format?
bool renderbufferStorageSupportsSizedInternalFormat =
GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard);
// This is set when we know we have both texture and render support for:
// R 8/16/16F
// RG 8/16/16F
@ -1508,6 +1511,10 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
}
} // No WebGL support
for (int i = 0; i < kGrColorTypeCnt; ++i) {
fColorTypeToFormatTable[i] = GrGLFormat::kUnknown;
}
///////////////////////////////////////////////////////////////////////////
GrGLenum halfFloatType = GR_GL_HALF_FLOAT;
@ -1522,6 +1529,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGBA8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
@ -1543,6 +1552,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_8888, flags);
this->setColorTypeFormat(GrColorType::kRGBA_8888, GrGLFormat::kRGBA8);
}
// kBGRA_8888
@ -1551,6 +1561,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGRA_8888, flags);
this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kRGBA8);
}
}
}
@ -1569,6 +1580,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_R8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_R8 : GR_GL_RED;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (textureRedSupport) {
info.fFlags |= FormatInfo::kTextureable_Flag | msaaRenderFlags;
@ -1584,11 +1597,13 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
// kAlpha_8
{
info.fColorTypeInfos.emplace_back(GrColorType::kAlpha_8, flags);
this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kR8);
}
// kGray_8
{
info.fColorTypeInfos.emplace_back(GrColorType::kGray_8, flags);
this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kR8);
}
}
}
@ -1609,6 +1624,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
} else {
info.fInternalFormatForTexImage = GR_GL_ALPHA8;
}
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_ALPHA8 : GR_GL_ALPHA;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
@ -1629,6 +1646,10 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) {
info.fColorTypeInfos.emplace_back(GrColorType::kAlpha_8, flags);
int idx = static_cast<int>(GrColorType::kAlpha_8);
if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
this->setColorTypeFormat(GrColorType::kAlpha_8, GrGLFormat::kALPHA8);
}
}
}
}
@ -1641,6 +1662,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_LUMINANCE8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_LUMINANCE8 : GR_GL_LUMINANCE;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_LUMINANCE8 : GR_GL_LUMINANCE;
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)) ||
@ -1667,6 +1690,10 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kGray_8, flags);
int idx = static_cast<int>(GrColorType::kGray_8);
if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
this->setColorTypeFormat(GrColorType::kGray_8, GrGLFormat::kLUMINANCE8);
}
}
}
@ -1693,6 +1720,16 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fInternalFormatForTexImage = GR_GL_BGRA;
}
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
if (renderbufferStorageSupportsSizedInternalFormat) {
info.fInternalFormatForRenderbuffer = GR_GL_RGBA8;
} else {
info.fInternalFormatForRenderbuffer = GR_GL_RGBA;
}
} else {
info.fInternalFormatForRenderbuffer = GR_GL_BGRA;
}
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
// TexStorage requires using a sized internal format and BGRA8 is only supported if we have
// the GL_APPLE_texture_format_BGRA8888 extension or if we have GL_EXT_texture_storage and
@ -1734,6 +1771,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGRA_8888, flags);
this->setColorTypeFormat(GrColorType::kBGRA_8888, GrGLFormat::kBGRA8);
}
}
}
@ -1745,16 +1783,17 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGB565;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGB565 : GR_GL_RGB;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) {
info.fFlags |= msaaRenderFlags;
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
info.fFlags |= msaaRenderFlags;
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
} else if (GR_IS_GR_WEBGL(standard)) {
info.fFlags |= msaaRenderFlags;
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
}
// 565 is not a sized internal format on desktop GL. So on desktop with
// 565 we always use an unsized internal format to let the system pick
@ -1767,10 +1806,13 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fFlags |= FormatInfo::kCanUseTexStorage_Flag;
}
// kBGR_565
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGR_565, flags);
if (SkToBool(info.fFlags &FormatInfo::kTextureable_Flag)) {
// kBGR_565
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kBGR_565, flags);
this->setColorTypeFormat(GrColorType::kBGR_565, GrGLFormat::kRGB565);
}
}
}
@ -1781,6 +1823,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGBA16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGBA16F : GR_GL_RGBA;
info.fDefaultExternalType = halfFloatType;
if (hasFP16Textures) {
info.fFlags = FormatInfo::kTextureable_Flag;
@ -1799,12 +1843,14 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_F16, flags);
this->setColorTypeFormat(GrColorType::kRGBA_F16, GrGLFormat::kRGBA16F);
}
// kRGBA_F16_Clamped
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_F16_Clamped, flags);
this->setColorTypeFormat(GrColorType::kRGBA_F16_Clamped, GrGLFormat::kRGBA16F);
}
}
}
@ -1816,6 +1862,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_R16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_R16F : GR_GL_RED;
info.fDefaultExternalType = halfFloatType;
if (textureRedSupport && hasFP16Textures) {
info.fFlags = FormatInfo::kTextureable_Flag;
@ -1833,6 +1881,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kAlpha_F16, flags);
this->setColorTypeFormat(GrColorType::kAlpha_F16, GrGLFormat::kR16F);
}
}
}
@ -1844,6 +1893,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGB8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
@ -1875,6 +1926,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGB_888x, flags);
this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGB8);
}
}
@ -1885,6 +1937,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RG8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RG8 : GR_GL_RG;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (textureRedSupport) {
info.fFlags |= FormatInfo::kTextureable_Flag | msaaRenderFlags;
@ -1899,6 +1953,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRG_88, flags);
this->setColorTypeFormat(GrColorType::kRG_88, GrGLFormat::kRG8);
}
}
}
@ -1910,6 +1965,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGB10_A2;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGB10_A2 : GR_GL_RGBA;
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))) {
@ -1927,6 +1984,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_1010102, flags);
this->setColorTypeFormat(GrColorType::kRGBA_1010102, GrGLFormat::kRGB10_A2);
}
}
}
@ -1938,6 +1996,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGBA4;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
info.fFlags = FormatInfo::kTextureable_Flag;
if (GR_IS_GR_GL(standard)) {
@ -1957,12 +2017,19 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kABGR_4444, flags);
this->setColorTypeFormat(GrColorType::kABGR_4444, GrGLFormat::kRGBA4);
}
}
// RGBA32F
{
// FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA32F);
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA32F);
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA32F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA32F : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGBA32F : GR_GL_RGBA;
// We don't allow texturing or rendering to this format
}
@ -1973,6 +2040,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_SRGB8_ALPHA8 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
if (fSRGBSupport) {
uint32_t srgbRenderFlags =
@ -1991,6 +2060,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_8888_SRGB, flags);
this->setColorTypeFormat(GrColorType::kRGBA_8888_SRGB, GrGLFormat::kSRGB8_ALPHA8);
}
}
}
@ -2035,6 +2105,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_R16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_R16 : GR_GL_RED;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_R16 : GR_GL_RED;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (r16AndRG1616Supported) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
@ -2045,6 +2117,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kR_16, flags);
this->setColorTypeFormat(GrColorType::kR_16, GrGLFormat::kR16);
}
}
}
@ -2056,6 +2129,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RG16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RG16 : GR_GL_RG;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (r16AndRG1616Supported) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
@ -2066,6 +2141,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRG_1616, flags);
this->setColorTypeFormat(GrColorType::kRG_1616, GrGLFormat::kRG16);
}
}
}
@ -2096,6 +2172,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RGBA16;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RGBA16 : GR_GL_RGBA;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RGBA16 : GR_GL_RGBA;
info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT;
if (rgba16161616Supported) {
info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags;
@ -2106,6 +2184,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRGBA_16161616, flags);
this->setColorTypeFormat(GrColorType::kRGBA_16161616, GrGLFormat::kRGBA16);
}
}
}
@ -2140,6 +2219,8 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
info.fSizedInternalFormat = GR_GL_RG16F;
info.fInternalFormatForTexImage =
texImageSupportsSizedInternalFormat ? GR_GL_RG16F : GR_GL_RG;
info.fInternalFormatForRenderbuffer =
renderbufferStorageSupportsSizedInternalFormat ? GR_GL_RG16F : GR_GL_RG;
info.fDefaultExternalType = halfFloatType;
if (rg16fTexturesSupported) {
info.fFlags |= FormatInfo::kTextureable_Flag;
@ -2154,6 +2235,7 @@ void GrGLCaps::initFormatTable(const GrContextOptions& contextOptions,
{
uint32_t flags = ColorTypeInfo::kUploadData_Flag;
info.fColorTypeInfos.emplace_back(GrColorType::kRG_F16, flags);
this->setColorTypeFormat(GrColorType::kRG_F16, GrGLFormat::kRG16F);
}
}
}
@ -2273,14 +2355,10 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
}
} // No WebGL support
fConfigTable[kUnknown_GrPixelConfig].fFormats.fBaseInternalFormat = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormats.fSizedInternalFormat = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0;
fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
@ -2298,8 +2376,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags;
}
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.
@ -2334,8 +2410,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
// uninitialized.
fConfigTable[kRGB_888X_GrPixelConfig].fFlags = 0;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RG;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RG8;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RG;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
@ -2352,15 +2426,11 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL(standard)) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8;
if (version >= GR_GL_VER(1, 2) || ctxInfo.hasExtension("GL_EXT_bgra")) {
// Since the internal format is RGBA8, it is also renderable.
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = allRenderFlags;
}
} else if (GR_IS_GR_GL_ES(standard)) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = nonMSAARenderFlags;
@ -2383,10 +2453,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kBGRA_8888_GrPixelConfig].fFlags = allRenderFlags;
}
}
} else if (GR_IS_GR_WEBGL(standard)) {
// Guess based on ES 2.0 support
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_BGRA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_BGRA8;
}
uint32_t srgbRenderFlags = allRenderFlags;
@ -2394,8 +2460,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag;
}
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
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[kReadPixels_ExternalFormatUsage] =
@ -2406,12 +2470,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = srgbRenderFlags;
}
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
if (this->ES2CompatibilitySupport()) {
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
} else {
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB5;
}
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGB;
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_SHORT_5_6_5;
@ -2426,8 +2484,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags;
}
fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4;
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;
@ -2442,8 +2498,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags;
}
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[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kRGBA_1010102_GrPixelConfig].fFormats.fExternalType =
@ -2460,8 +2514,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
alphaInfo.fFormats.fBaseInternalFormat = GR_GL_ALPHA;
alphaInfo.fFormats.fSizedInternalFormat = GR_GL_ALPHA8;
alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
alphaInfo.fRGBAReadSwizzle = GrSwizzle("000a");
if (fAlpha8IsRenderable && alpha8IsValidForGL) {
@ -2469,8 +2521,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
}
ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
redInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
redInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
@ -2481,20 +2531,15 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
fConfigTable[kAlpha_8_GrPixelConfig] = redInfo;
} else {
redInfo.fFlags = 0;
fConfigTable[kAlpha_8_GrPixelConfig] = alphaInfo;
}
ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
grayLumInfo.fFormats.fBaseInternalFormat = GR_GL_LUMINANCE;
grayLumInfo.fFormats.fSizedInternalFormat = GR_GL_LUMINANCE8;
grayLumInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_LUMINANCE;
grayLumInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
grayLumInfo.fFormatType = kNormalizedFixedPoint_FormatType;
ConfigInfo& grayRedInfo = fConfigTable[kGray_8_as_Red_GrPixelConfig];
grayRedInfo.fFormats.fBaseInternalFormat = GR_GL_RED;
grayRedInfo.fFormats.fSizedInternalFormat = GR_GL_R8;
grayRedInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
@ -2566,9 +2611,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
// We disable all texturing and rendering to F32 formats.
for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) {
const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG;
fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format;
fConfigTable[fpconfig].fFormats.fSizedInternalFormat =
kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F;
fConfigTable[fpconfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = format;
fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT;
fConfigTable[fpconfig].fFormatType = kFloat_FormatType;
@ -2584,8 +2626,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
redHalf.fFormats.fExternalType = redHalfExternalType;
redHalf.fFormatType = kFloat_FormatType;
redHalf.fFormats.fBaseInternalFormat = GR_GL_RED;
redHalf.fFormats.fSizedInternalFormat = GR_GL_R16F;
redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
redHalf.fRGBAReadSwizzle = GrSwizzle("000r");
if (textureRedSupport && hasFP16Textures) {
@ -2595,8 +2635,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
}
fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA;
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F;
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
if (GR_IS_GR_GL(standard) ||
@ -2624,21 +2662,10 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
// No sized/unsized internal format distinction for compressed formats, no external format.
// Below we set the external formats and types to 0.
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_RGB8_ETC2;
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fSizedInternalFormat =
GR_GL_COMPRESSED_RGB8_ETC2;
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]
= 0;
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fExternalType = 0;
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
if (GR_IS_GR_GL_ES(standard)) {
if (ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fBaseInternalFormat =
GR_GL_COMPRESSED_ETC1_RGB8;
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fSizedInternalFormat =
GR_GL_COMPRESSED_ETC1_RGB8;
}
}
// 16 bit formats
{
@ -2681,8 +2708,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
{
ConfigInfo& r16Info = fConfigTable[kR_16_GrPixelConfig];
r16Info.fFormats.fBaseInternalFormat = GR_GL_RED;
r16Info.fFormats.fSizedInternalFormat = GR_GL_R16;
r16Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
r16Info.fFormats.fExternalType = GR_GL_UNSIGNED_SHORT;
r16Info.fFormatType = kNormalizedFixedPoint_FormatType;
@ -2694,8 +2719,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
{
ConfigInfo& rg1616Info = fConfigTable[kRG_1616_GrPixelConfig];
rg1616Info.fFormats.fBaseInternalFormat = GR_GL_RG;
rg1616Info.fFormats.fSizedInternalFormat = GR_GL_RG16;
rg1616Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RG;
rg1616Info.fFormats.fExternalType = GR_GL_UNSIGNED_SHORT;
rg1616Info.fFormatType = kNormalizedFixedPoint_FormatType;
@ -2708,8 +2731,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
{
ConfigInfo& rgba16161616Info = fConfigTable[kRGBA_16161616_GrPixelConfig];
rgba16161616Info.fFormats.fBaseInternalFormat = GR_GL_RGBA;
rgba16161616Info.fFormats.fSizedInternalFormat = GR_GL_RGBA16;
rgba16161616Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
rgba16161616Info.fFormats.fExternalType = GR_GL_UNSIGNED_SHORT;
rgba16161616Info.fFormatType = kNormalizedFixedPoint_FormatType;
@ -2741,8 +2762,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
ConfigInfo& rgHalf = fConfigTable[kRG_half_GrPixelConfig];
rgHalf.fFormats.fBaseInternalFormat = GR_GL_RG;
rgHalf.fFormats.fSizedInternalFormat = GR_GL_RG16F;
rgHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RG;
if (GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) {
rgHalf.fFormats.fExternalType = GR_GL_HALF_FLOAT;
@ -2755,37 +2774,11 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
}
}
// ES 2.0 requires that the internal/external formats match.
bool useSizedTexFormats = (GR_IS_GR_GL(standard) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0)));
// All ES versions (thus far) require sized internal formats for render buffers.
// TODO: Always use sized internal format?
bool useSizedRbFormats = GR_IS_GR_GL_ES(standard) || GR_IS_GR_WEBGL(standard);
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
// 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[kReadPixels_ExternalFormatUsage];
fConfigTable[i].fFormats.fInternalFormatTexImage = useSizedTexFormats ?
fConfigTable[i].fFormats.fSizedInternalFormat :
fConfigTable[i].fFormats.fBaseInternalFormat;
fConfigTable[i].fFormats.fInternalFormatRenderbuffer = useSizedRbFormats ?
fConfigTable[i].fFormats.fSizedInternalFormat :
fConfigTable[i].fFormats.fBaseInternalFormat;
}
// If we're on ES 3.0+ but because of a driver workaround selected GL_ALPHA to implement the
// kAlpha_8_GrPixelConfig then we actually have to use a base internal format rather than a
// sized internal format. This is because there is no valid 8 bit alpha sized internal format
// in ES.
if (useSizedTexFormats && GR_IS_GR_GL_ES(standard) && !textureRedSupport) {
SkASSERT(fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_ALPHA8);
SkASSERT(fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat ==
GR_GL_ALPHA8);
fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fInternalFormatTexImage =
fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat;
fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fInternalFormatTexImage =
fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig].fFormats.fBaseInternalFormat;
}
// OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the <format>
@ -2804,26 +2797,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
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.
// GL_EXT_texture_format_BGRA8888:
// This extension GL_BGRA as an unsized internal format. However, it is written against ES
// 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
// formats.
// GL_APPLE_texture_format_BGRA8888:
// ES 2.0: the extension makes BGRA an external format but not an internal format.
// ES 3.0: the extension explicitly states GL_BGRA8 is not a valid internal format for
// glTexImage (just for glTexStorage).
if (useSizedTexFormats && this->bgraIsInternalFormat()) {
if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_RGBA;
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatRenderbuffer =
GR_GL_RGBA8;
} else {
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
}
}
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
if (ConfigInfo::kRenderableWithMSAA_Flag & fConfigTable[i].fFlags) {
// We assume that MSAA rendering is supported only if we support non-MSAA rendering.
@ -2833,7 +2806,8 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
ctxInfo.hasExtension("GL_ARB_internalformat_query"))) ||
(GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3,0))) {
int count;
GrGLenum format = fConfigTable[i].fFormats.fInternalFormatRenderbuffer;
GrGLFormat grGLFormat = this->pixelConfigToFormat((GrPixelConfig)i);
GrGLenum format = this->getRenderbufferInternalFormat(grGLFormat);
GR_GL_GetInternalformativ(gli, GR_GL_RENDERBUFFER, format, GR_GL_NUM_SAMPLE_COUNTS,
1, &count);
if (count) {
@ -2893,10 +2867,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions,
SkASSERT(!((fConfigTable[i].fFlags & ConfigInfo::kRenderableWithMSAA_Flag) &&
!(fConfigTable[i].fFlags & ConfigInfo::kRenderable_Flag)));
SkASSERT(defaultEntry.fFormats.fBaseInternalFormat !=
fConfigTable[i].fFormats.fBaseInternalFormat);
SkASSERT(defaultEntry.fFormats.fSizedInternalFormat !=
fConfigTable[i].fFormats.fSizedInternalFormat);
for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
fConfigTable[i].fFormats.fExternalFormat[j]);
@ -3756,6 +3726,52 @@ bool GrGLCaps::formatSupportsTexStorage(GrGLFormat format) const {
return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kCanUseTexStorage_Flag);
}
GrGLFormat GrGLCaps::pixelConfigToFormat(GrPixelConfig config) const {
switch (config) {
case kRGB_888X_GrPixelConfig:
return GrGLFormat::kRGBA8;
case kAlpha_8_as_Alpha_GrPixelConfig:
return GrGLFormat::kALPHA8;
case kAlpha_8_as_Red_GrPixelConfig:
return GrGLFormat::kR8;
case kGray_8_as_Lum_GrPixelConfig:
return GrGLFormat::kLUMINANCE8;
case kGray_8_as_Red_GrPixelConfig:
return GrGLFormat::kR8;
case kAlpha_half_as_Red_GrPixelConfig:
return GrGLFormat::kR16F;
case kRGB_ETC1_GrPixelConfig: {
auto info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8);
bool usesETC1 = SkToBool(info.fFlags & FormatInfo::kTextureable_Flag);
return usesETC1 ? GrGLFormat::kCOMPRESSED_ETC1_RGB8
: GrGLFormat::kCOMPRESSED_RGB8_ETC2;
}
case kUnknown_GrPixelConfig:
case kAlpha_8_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
case kRGB_888_GrPixelConfig:
case kRG_88_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kRGBA_1010102_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
case kAlpha_half_GrPixelConfig:
case kRGBA_half_GrPixelConfig:
case kRGBA_half_Clamped_GrPixelConfig:
case kR_16_GrPixelConfig:
case kRG_1616_GrPixelConfig:
case kRGBA_16161616_GrPixelConfig:
case kRG_half_GrPixelConfig:
return this->getFormatFromColorType(GrPixelConfigToColorType(config));
}
SkUNREACHABLE;
return GrGLFormat::kUnknown;
}
// A near clone of format_color_type_valid_pair
GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandard standard) {
switch (ct) {
@ -3957,11 +3973,11 @@ GrPixelConfig GrGLCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& fo
}
GrBackendFormat GrGLCaps::getBackendFormatFromColorType(GrColorType ct) const {
GrPixelConfig config = GrColorTypeToPixelConfig(ct);
if (config == kUnknown_GrPixelConfig) {
auto format = this->getFormatFromColorType(ct);
if (format == GrGLFormat::kUnknown) {
return GrBackendFormat();
}
return GrBackendFormat::MakeGL(this->configSizedInternalFormat(config), GR_GL_TEXTURE_2D);
return GrBackendFormat::MakeGL(this->getSizedInternalFormat(format), GR_GL_TEXTURE_2D);
}
GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(

View File

@ -113,9 +113,9 @@ public:
bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override;
bool isConfigTexturable(GrPixelConfig config) const override {
GrGLenum glFormat = this->configSizedInternalFormat(config);
GrColorType ct = GrPixelConfigToColorType(config);
return this->isFormatTexturable(ct, GrGLFormatFromGLEnum(glFormat));
auto format = this->pixelConfigToFormat(config);
return this->isFormatTexturable(ct, format);
}
int getRenderTargetSampleCount(int requestedCount,
@ -137,23 +137,22 @@ public:
bool canFormatBeFBOColorAttachment(GrGLFormat) const;
bool canConfigBeFBOColorAttachment(GrPixelConfig config) const {
GrGLenum format = this->configSizedInternalFormat(config);
if (!format) {
return false;
}
return this->canFormatBeFBOColorAttachment(GrGLFormatFromGLEnum(format));
auto format = this->pixelConfigToFormat(config);
return this->canFormatBeFBOColorAttachment(format);
}
bool configSupportsTexStorage(GrPixelConfig config) const {
GrGLenum format = this->configSizedInternalFormat(config);
if (!format) {
return false;
}
return this->formatSupportsTexStorage(GrGLFormatFromGLEnum(format));
auto format = this->pixelConfigToFormat(config);
return this->formatSupportsTexStorage(format);
}
GrGLFormat getFormatFromColorType(GrColorType colorType) const {
int idx = static_cast<int>(colorType);
return fColorTypeToFormatTable[idx];
}
GrGLenum configSizedInternalFormat(GrPixelConfig config) const {
return fConfigTable[config].fFormats.fSizedInternalFormat;
return this->getSizedInternalFormat(this->pixelConfigToFormat(config));
}
bool getTexImageFormats(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
@ -166,9 +165,6 @@ public:
bool getReadPixelsFormat(GrPixelConfig surfaceConfig, GrPixelConfig externalConfig,
GrGLenum* externalFormat, GrGLenum* externalType) const;
void getRenderbufferFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
void getSizedInternalFormat(GrPixelConfig config, GrGLenum* internalFormat) const;
/**
* Gets an array of legal stencil formats. These formats are not guaranteed
* to be supported by the driver but are legal GLenum names given the GL
@ -186,6 +182,14 @@ public:
return this->getFormatInfo(format).fInternalFormatForTexImage;
}
/**
* Gets the internal format to use with glRenderbufferStorageMultisample...(). May be sized or
* base depending upon the GL. Not applicable to compressed textures.
*/
GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const {
return this->getFormatInfo(format).fInternalFormatForRenderbuffer;
}
GrGLenum getSizedInternalFormat(GrGLFormat format) const {
return this->getFormatInfo(format).fSizedInternalFormat;
}
@ -498,6 +502,9 @@ private:
bool isFormatTexturable(GrColorType, GrGLFormat) const;
bool formatSupportsTexStorage(GrGLFormat) const;
// TODO: Once pixel config is no longer used in the caps remove this helper function.
GrGLFormat pixelConfigToFormat(GrPixelConfig) const;
GrGLStandard fStandard;
SkTArray<StencilFormat, true> fStencilFormats;
@ -567,8 +574,6 @@ private:
// Inits to known bad GL enum values.
memset(this, 0xAB, sizeof(ConfigFormats));
}
GrGLenum fBaseInternalFormat;
GrGLenum fSizedInternalFormat;
/** The external format and type are to be used when uploading/downloading data using this
config where both the CPU data and GrSurface are the same config. To get the external
@ -578,10 +583,6 @@ private:
GL contexts. */
GrGLenum fExternalFormat[kExternalFormatUsageCnt];
GrGLenum fExternalType;
// Either the base or sized internal format depending on the GL and config.
GrGLenum fInternalFormatTexImage;
GrGLenum fInternalFormatRenderbuffer;
};
struct ConfigInfo {
@ -659,7 +660,12 @@ private:
// Value to uses as the "internalformat" argument to glTexImage... Usually one of
// fBaseInternalFormat or fSizedInternalFormat but may vary depending on the particular
// format, GL version, extensions.
GrGLenum fInternalFormatForTexImage;
GrGLenum fInternalFormatForTexImage = 0;
// Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample...
// Usually one of fBaseInternalFormat or fSizedInternalFormat but may vary depending on the
// particular format, GL version, extensions.
GrGLenum fInternalFormatForRenderbuffer = 0;
// Default value to use along with fBaseInternalFormat for functions such as glTexImage2D
// when not input providing data (passing nullptr). Not defined for compressed formats.
@ -685,6 +691,9 @@ private:
return fFormatTable[static_cast<int>(format)];
}
GrGLFormat fColorTypeToFormatTable[kGrColorTypeCnt];
void setColorTypeFormat(GrColorType, GrGLFormat);
typedef GrCaps INHERITED;
};

View File

@ -1368,7 +1368,10 @@ bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc,
!idDesc->fMSColorRenderbufferID) {
goto FAILED;
}
this->glCaps().getRenderbufferFormat(desc.fConfig, &colorRenderbufferFormat);
GrGLFormat glFormat =
GrGLFormatFromGLEnum(this->glCaps().configSizedInternalFormat(desc.fConfig));
colorRenderbufferFormat =
this->glCaps().getRenderbufferInternalFormat(glFormat);
} else {
idDesc->fRTFBOID = idDesc->fTexFBOID;
}
@ -4007,6 +4010,7 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h
if (!this->glCaps().isConfigRenderable(config)) {
return {};
}
auto format = this->glCaps().getFormatFromColorType(colorType);
bool useTexture = false;
GrGLenum colorBufferFormat;
GrGLenum externalFormat = 0, externalType = 0;
@ -4016,10 +4020,8 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h
&externalType);
useTexture = true;
} else {
this->glCaps().getRenderbufferFormat(config, &colorBufferFormat);
colorBufferFormat = this->glCaps().getRenderbufferInternalFormat(format);
}
auto format =
GrGLBackendFormatToGLFormat(this->caps()->getBackendFormatFromColorType(colorType));
int sFormatIdx = this->getCompatibleStencilIndex(format);
if (sFormatIdx < 0) {
return {};
@ -4052,7 +4054,7 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h
GrGLFramebufferInfo info;
info.fFBOID = 0;
this->glCaps().getSizedInternalFormat(config, &info.fFormat);
info.fFormat = this->glCaps().configSizedInternalFormat(config);
GL_CALL(GenFramebuffers(1, &info.fFBOID));
if (!info.fFBOID) {
deleteIDs();