Add support for GL_ANGLE_rgbx_internal_format format
Angle/Vulkan added GL_ANGLE_rgbx_internal_format extension for RGBX
texture format. Add support for that format in Skia.
Bug: chromium:1261867, chromium:1269826, angle:6690
Change-Id: I74fc91699dc1eaf2b275b29fbcf3d4060e63c5a1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/485157
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/include/gpu/gl/GrGLTypes.h b/include/gpu/gl/GrGLTypes.h
index 49f5ee7..d516778 100644
--- a/include/gpu/gl/GrGLTypes.h
+++ b/include/gpu/gl/GrGLTypes.h
@@ -68,6 +68,7 @@
kRGBA16F,
kR16F,
kRGB8,
+ kRGBX8,
kRG8,
kRGB10_A2,
kRGBA4,
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 64a76c0..e1defda 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2413,6 +2413,61 @@
}
}
+ // Format: RGBx8
+ {
+ FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBX8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
+ info.fInternalFormatForRenderbuffer = GR_GL_RGBX8;
+ info.fDefaultExternalFormat = GR_GL_RGB;
+ info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE;
+ info.fDefaultColorType = GrColorType::kRGB_888x;
+
+ bool supportsRGBXTexStorage = false;
+
+ if (GR_IS_GR_GL_ES(standard) && ctxInfo.hasExtension("GL_ANGLE_rgbx_internal_format")) {
+ info.fFlags =
+ FormatInfo::kTexturable_Flag | FormatInfo::kTransfers_Flag | msaaRenderFlags;
+ supportsRGBXTexStorage = true;
+ }
+
+ if (texStorageSupported && supportsRGBXTexStorage) {
+ info.fFlags |= FormatInfo::kUseTexStorage_Flag;
+ info.fColorTypeInfoCount = 1;
+ info.fColorTypeInfos = std::make_unique<ColorTypeInfo[]>(info.fColorTypeInfoCount);
+ int ctIdx = 0;
+ // Format: RGBX8, Surface: kRGB_888x
+ {
+ auto& ctInfo = info.fColorTypeInfos[ctIdx++];
+ ctInfo.fColorType = GrColorType::kRGB_888x;
+ ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
+ this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGBX8);
+
+ // External IO ColorTypes:
+ ctInfo.fExternalIOFormatCount = 2;
+ ctInfo.fExternalIOFormats = std::make_unique<ColorTypeInfo::ExternalIOFormats[]>(
+ ctInfo.fExternalIOFormatCount);
+ int ioIdx = 0;
+ // Format: RGBX8, Surface: kRGB_888x, Data: kRGB_888x
+ {
+ auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
+ ioFormat.fColorType = GrColorType::kRGB_888x;
+ ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
+ ioFormat.fExternalTexImageFormat = GR_GL_RGB;
+ ioFormat.fExternalReadFormat = 0;
+ }
+
+ // Format: RGBX8, Surface: kRGB_888x, Data: kRGBA_8888
+ {
+ auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
+ ioFormat.fColorType = GrColorType::kRGBA_8888;
+ ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
+ ioFormat.fExternalTexImageFormat = 0;
+ ioFormat.fExternalReadFormat = GR_GL_RGBA;
+ }
+ }
+ }
+ }
+
// Format: RGB8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB8);
@@ -2454,7 +2509,11 @@
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);
+
+ int idx = static_cast<int>(GrColorType::kRGB_888x);
+ if (fColorTypeToFormatTable[idx] == GrGLFormat::kUnknown) {
+ this->setColorTypeFormat(GrColorType::kRGB_888x, GrGLFormat::kRGB8);
+ }
// External IO ColorTypes:
ctInfo.fExternalIOFormatCount = 2;
diff --git a/src/gpu/gl/GrGLDefines.h b/src/gpu/gl/GrGLDefines.h
index 7f6cc5c..eebd891 100644
--- a/src/gpu/gl/GrGLDefines.h
+++ b/src/gpu/gl/GrGLDefines.h
@@ -508,6 +508,7 @@
#define GR_GL_RGB565 0x8D62
#define GR_GL_RGB8 0x8051
#define GR_GL_SRGB8 0x8C41
+#define GR_GL_RGBX8 0x96BA
/* RGB integer sized formats */
#define GR_GL_RGB8I 0x8D8F
diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp
index cafbc40..5d31b56 100644
--- a/src/gpu/gl/GrGLUtil.cpp
+++ b/src/gpu/gl/GrGLUtil.cpp
@@ -752,6 +752,7 @@
case GrGLFormat::kR16F:
case GrGLFormat::kLUMINANCE16F:
case GrGLFormat::kRGB8:
+ case GrGLFormat::kRGBX8:
case GrGLFormat::kRG8:
case GrGLFormat::kRGB10_A2:
case GrGLFormat::kRGBA4:
diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h
index 01bcbc4..21f630d 100644
--- a/src/gpu/gl/GrGLUtil.h
+++ b/src/gpu/gl/GrGLUtil.h
@@ -51,6 +51,7 @@
case GrGLFormat::kRGBA16F: return kRGBA_SkColorChannelFlags;
case GrGLFormat::kR16F: return kRed_SkColorChannelFlag;
case GrGLFormat::kRGB8: return kRGB_SkColorChannelFlags;
+ case GrGLFormat::kRGBX8: return kRGB_SkColorChannelFlags;
case GrGLFormat::kRG8: return kRG_SkColorChannelFlags;
case GrGLFormat::kRGB10_A2: return kRGBA_SkColorChannelFlags;
case GrGLFormat::kRGBA4: return kRGBA_SkColorChannelFlags;
@@ -95,6 +96,8 @@
return GrColorFormatDesc::MakeR(16, GrColorTypeEncoding::kFloat);
case GrGLFormat::kRGB8:
return GrColorFormatDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm);
+ case GrGLFormat::kRGBX8:
+ return GrColorFormatDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm);
case GrGLFormat::kRG8:
return GrColorFormatDesc::MakeRG(8, GrColorTypeEncoding::kUnorm);
case GrGLFormat::kRGB10_A2:
@@ -384,6 +387,7 @@
case GR_GL_LUMINANCE16F: return GrGLFormat::kLUMINANCE16F;
case GR_GL_R16F: return GrGLFormat::kR16F;
case GR_GL_RGB8: return GrGLFormat::kRGB8;
+ case GR_GL_RGBX8: return GrGLFormat::kRGBX8;
case GR_GL_RG8: return GrGLFormat::kRG8;
case GR_GL_RGB10_A2: return GrGLFormat::kRGB10_A2;
case GR_GL_RGBA4: return GrGLFormat::kRGBA4;
@@ -419,6 +423,7 @@
case GrGLFormat::kLUMINANCE16F: return GR_GL_LUMINANCE16F;
case GrGLFormat::kR16F: return GR_GL_R16F;
case GrGLFormat::kRGB8: return GR_GL_RGB8;
+ case GrGLFormat::kRGBX8: return GR_GL_RGBX8;
case GrGLFormat::kRG8: return GR_GL_RG8;
case GrGLFormat::kRGB10_A2: return GR_GL_RGB10_A2;
case GrGLFormat::kRGBA4: return GR_GL_RGBA4;
@@ -453,6 +458,7 @@
case GrGLFormat::kR16F: return 2;
// We assume the GPU stores this format 4 byte aligned
case GrGLFormat::kRGB8: return 4;
+ case GrGLFormat::kRGBX8: return 4;
case GrGLFormat::kRG8: return 2;
case GrGLFormat::kRGB10_A2: return 4;
case GrGLFormat::kRGBA4: return 2;
@@ -496,6 +502,7 @@
case GrGLFormat::kR16F:
case GrGLFormat::kLUMINANCE16F:
case GrGLFormat::kRGB8:
+ case GrGLFormat::kRGBX8:
case GrGLFormat::kRG8:
case GrGLFormat::kRGB10_A2:
case GrGLFormat::kRGBA4:
@@ -529,6 +536,7 @@
case GrGLFormat::kR16F:
case GrGLFormat::kLUMINANCE16F:
case GrGLFormat::kRGB8:
+ case GrGLFormat::kRGBX8:
case GrGLFormat::kRG8:
case GrGLFormat::kRGB10_A2:
case GrGLFormat::kRGBA4:
@@ -564,6 +572,7 @@
case GrGLFormat::kR16F:
case GrGLFormat::kLUMINANCE16F:
case GrGLFormat::kRGB8:
+ case GrGLFormat::kRGBX8:
case GrGLFormat::kRG8:
case GrGLFormat::kRGB10_A2:
case GrGLFormat::kRGBA4:
diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp
index 6c883a4..9a4ec28 100644
--- a/tests/BackendAllocationTest.cpp
+++ b/tests/BackendAllocationTest.cpp
@@ -765,6 +765,7 @@
{ GrColorType::kRGB_888x, GR_GL_RGBA8, SkColors::kYellow },
{ GrColorType::kRGB_888x, GR_GL_RGB8, SkColors::kCyan },
+ { GrColorType::kRGB_888x, GR_GL_RGBX8, SkColors::kCyan },
{ GrColorType::kBGRA_8888, GR_GL_RGBA8, SkColors::kBlue },
{ GrColorType::kBGRA_8888, GR_GL_BGRA8, SkColors::kBlue },