Move FormatType from ConfigInfo to FormatInfo.
Bug: skia:6718
Change-Id: Ia4cab74983a92a7ff6c9d7d6f683971bacbc10da
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228122
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 48f9658..b324429 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -371,7 +371,8 @@
return true;
}
-GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrPixelConfig config,
+GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorType,
+ GrPixelConfig config,
const GrBackendFormat&,
GrColorType dstColorType) const {
return SupportedRead{GrSwizzle::RGBA(), GrPixelConfigToColorType(config)};
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 3410a49..10f930f 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -244,7 +244,8 @@
* to dstColorType the swizzle in the returned struct should be applied. The caller must check
* the returned color type for kUnknown.
*/
- virtual SupportedRead supportedReadPixelsColorType(GrPixelConfig srcConfig,
+ virtual SupportedRead supportedReadPixelsColorType(GrColorType srcColorType,
+ GrPixelConfig srcConfig,
const GrBackendFormat& srcFormat,
GrColorType dstColorType) const;
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 673e70c..911ed0c 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -1742,14 +1742,17 @@
}
auto dstCT = SkColorTypeToGrColorType(info.colorType());
bool needsRescale = srcRect.width() != info.width() || srcRect.height() != info.height();
+ auto colorTypeOfFinalContext = this->colorSpaceInfo().colorType();
GrPixelConfig configOfFinalContext = fRenderTargetProxy->config();
auto backendFormatOfFinalContext = fRenderTargetProxy->backendFormat();
if (needsRescale) {
+ colorTypeOfFinalContext = dstCT;
backendFormatOfFinalContext = this->caps()->getBackendFormatFromColorType(dstCT);
configOfFinalContext = this->caps()->getConfigFromBackendFormat(backendFormatOfFinalContext,
dstCT);
}
- auto readInfo = this->caps()->supportedReadPixelsColorType(configOfFinalContext,
+ auto readInfo = this->caps()->supportedReadPixelsColorType(colorTypeOfFinalContext,
+ configOfFinalContext,
backendFormatOfFinalContext, dstCT);
// Fail if we can't read from the source surface's color type.
if (readInfo.fColorType == GrColorType::kUnknown) {
@@ -1838,7 +1841,8 @@
return {};
}
auto supportedRead = this->caps()->supportedReadPixelsColorType(
- fRenderTargetProxy->config(), fRenderTargetProxy->backendFormat(), dstCT);
+ this->colorSpaceInfo().colorType(), fRenderTargetProxy->config(),
+ fRenderTargetProxy->backendFormat(), dstCT);
// Fail if read color type does not have all of dstCT's color channels and those missing color
// channels are in the src.
uint32_t dstComponents = GrColorTypeComponentFlags(dstCT);
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 6d24a73..47a8940 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -172,7 +172,8 @@
bool flip = srcProxy->origin() == kBottomLeft_GrSurfaceOrigin;
auto supportedRead = caps->supportedReadPixelsColorType(
- srcProxy->config(), srcProxy->backendFormat(), dstInfo.colorType());
+ this->colorSpaceInfo().colorType(), srcProxy->config(), srcProxy->backendFormat(),
+ dstInfo.colorType());
bool makeTight = !caps->readPixelsRowBytesSupport() && tightRowBytes != rowBytes;
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 9803efa..c4355f3 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -1451,6 +1451,7 @@
// RGBA8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA8;
info.fInternalFormatForTexImage =
@@ -1503,6 +1504,7 @@
// R8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kR8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R8;
info.fInternalFormatForTexImage =
@@ -1544,6 +1546,7 @@
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) {
@@ -1586,6 +1589,7 @@
// LUMINANCE8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kLUMINANCE8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_LUMINANCE;
info.fSizedInternalFormat = GR_GL_LUMINANCE8;
info.fInternalFormatForTexImage =
@@ -1630,6 +1634,7 @@
// BGRA8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kBGRA8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_BGRA;
info.fSizedInternalFormat = GR_GL_BGRA8;
// If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
@@ -1723,6 +1728,7 @@
// RGB565
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB565);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fSizedInternalFormat = GR_GL_RGB565;
info.fInternalFormatForTexImage =
@@ -1763,6 +1769,7 @@
// RGBA16F
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16F);
+ info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA16F;
info.fInternalFormatForTexImage =
@@ -1801,6 +1808,7 @@
// R16F
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16F);
+ info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R16F;
info.fInternalFormatForTexImage =
@@ -1832,6 +1840,7 @@
// RGB8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fSizedInternalFormat = GR_GL_RGB8;
info.fInternalFormatForTexImage =
@@ -1876,6 +1885,7 @@
// RG8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG8;
info.fInternalFormatForTexImage =
@@ -1904,6 +1914,7 @@
// RGB10_A2
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGB10_A2);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGB10_A2;
info.fInternalFormatForTexImage =
@@ -1935,6 +1946,7 @@
// RGBA4
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA4);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA4;
info.fInternalFormatForTexImage =
@@ -1967,6 +1979,7 @@
// RGBA32F
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA32F);
+ info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA32F;
info.fInternalFormatForTexImage =
@@ -1979,6 +1992,7 @@
// SRGB8_ALPHA8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kSRGB8_ALPHA8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_SRGB8_ALPHA8;
info.fInternalFormatForTexImage =
@@ -2012,6 +2026,7 @@
// COMPRESSED_RGB8_ETC2
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_ETC2);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fCompressedInternalFormat = GR_GL_COMPRESSED_RGB8_ETC2;
if (GR_IS_GR_GL(standard)) {
@@ -2031,6 +2046,7 @@
// COMPRESSED_ETC1_RGB8
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGB;
info.fCompressedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8;
if (GR_IS_GR_GL_ES(standard)) {
@@ -2045,6 +2061,7 @@
// GR_GL_R16
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kR16);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RED;
info.fSizedInternalFormat = GR_GL_R16;
info.fInternalFormatForTexImage =
@@ -2069,6 +2086,7 @@
// GR_GL_RG16
{
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG16;
info.fInternalFormatForTexImage =
@@ -2112,6 +2130,7 @@
} // No WebGL support
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRGBA16);
+ info.fFormatType = FormatType::kNormalizedFixedPoint;
info.fBaseInternalFormat = GR_GL_RGBA;
info.fSizedInternalFormat = GR_GL_RGBA16;
info.fInternalFormatForTexImage =
@@ -2159,6 +2178,7 @@
}
FormatInfo& info = this->getFormatInfo(GrGLFormat::kRG16F);
+ info.fFormatType = FormatType::kFloat;
info.fBaseInternalFormat = GR_GL_RG;
info.fSizedInternalFormat = GR_GL_RG16F;
info.fInternalFormatForTexImage =
@@ -2188,9 +2208,15 @@
#ifdef SK_DEBUG
for (int i = 0; i < kGrGLFormatCount; ++i) {
+ if (GrGLFormat::kUnknown == static_cast<GrGLFormat>(i)) {
+ continue;
+ }
// Make sure we didn't set fbo attachable with msaa and not fbo attachable.
SkASSERT(!((fFormatTable[i].fFlags & FormatInfo::kFBOColorAttachmentWithMSAA_Flag) &&
!(fFormatTable[i].fFlags & FormatInfo::kFBOColorAttachment_Flag)));
+
+ // Make sure we set all the formats' FormatType
+ SkASSERT(fFormatTable[i].fFormatType != FormatType::kUnknown);
}
#endif
}
@@ -2361,65 +2387,54 @@
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.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RGBA;
fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- fConfigTable[kRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
// 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.
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_888X_GrPixelConfig] = fConfigTable[kRGBA_8888_GrPixelConfig];
fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] =
GR_GL_RG;
fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- fConfigTable[kRG_88_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
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;
// 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] =
GR_GL_RGBA;
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
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;
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;
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;
- fConfigTable[kRGBA_1010102_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
ConfigInfo& alphaInfo = fConfigTable[kAlpha_8_as_Alpha_GrPixelConfig];
alphaInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- alphaInfo.fFormatType = kNormalizedFixedPoint_FormatType;
alphaInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_ALPHA;
alphaInfo.fRGBAReadSwizzle = GrSwizzle("000a");
ConfigInfo& redInfo = fConfigTable[kAlpha_8_as_Red_GrPixelConfig];
redInfo.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
redInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- redInfo.fFormatType = kNormalizedFixedPoint_FormatType;
redInfo.fRGBAReadSwizzle = GrSwizzle("000r");
if (textureRedSupport) {
@@ -2431,12 +2446,10 @@
ConfigInfo& grayLumInfo = fConfigTable[kGray_8_as_Lum_GrPixelConfig];
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.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
grayRedInfo.fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
- grayRedInfo.fFormatType = kNormalizedFixedPoint_FormatType;
if (textureRedSupport) {
fConfigTable[kGray_8_GrPixelConfig] = grayRedInfo;
@@ -2447,7 +2460,6 @@
ConfigInfo& rgbaF32Info = fConfigTable[kRGBA_float_GrPixelConfig];
rgbaF32Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
rgbaF32Info.fFormats.fExternalType = GR_GL_FLOAT;
- rgbaF32Info.fFormatType = kFloat_FormatType;
GrGLenum redHalfExternalType;
if (GR_IS_GR_GL(standard) ||
@@ -2458,7 +2470,6 @@
}
ConfigInfo& redHalf = fConfigTable[kAlpha_half_as_Red_GrPixelConfig];
redHalf.fFormats.fExternalType = redHalfExternalType;
- redHalf.fFormatType = kFloat_FormatType;
redHalf.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
redHalf.fRGBAReadSwizzle = GrSwizzle("000r");
fConfigTable[kAlpha_half_GrPixelConfig] = redHalf;
@@ -2471,7 +2482,6 @@
} else {
fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
}
- fConfigTable[kRGBA_half_GrPixelConfig].fFormatType = kFloat_FormatType;
// kRGBA_half_Clamped is just distinguished by clamps added to the shader. At the API level,
// it's identical to kRGBA_half.
@@ -2487,7 +2497,6 @@
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage]
= 0;
fConfigTable[kRGB_ETC1_GrPixelConfig].fFormats.fExternalType = 0;
- fConfigTable[kRGB_ETC1_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
// 16 bit formats
{
@@ -2496,7 +2505,6 @@
r16Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RED;
r16Info.fFormats.fExternalType = GR_GL_UNSIGNED_SHORT;
- r16Info.fFormatType = kNormalizedFixedPoint_FormatType;
}
{
@@ -2504,7 +2512,6 @@
rg1616Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RG;
rg1616Info.fFormats.fExternalType = GR_GL_UNSIGNED_SHORT;
- rg1616Info.fFormatType = kNormalizedFixedPoint_FormatType;
}
// Experimental (for Y416)
@@ -2513,7 +2520,6 @@
rgba16161616Info.fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_RGBA;
rgba16161616Info.fFormats.fExternalType = GR_GL_UNSIGNED_SHORT;
- rgba16161616Info.fFormatType = kNormalizedFixedPoint_FormatType;
}
}
@@ -2527,7 +2533,6 @@
} else {
rgHalf.fFormats.fExternalType = GR_GL_HALF_FLOAT_OES;
}
- rgHalf.fFormatType = kFloat_FormatType;
}
for (int i = 0; i < kGrPixelConfigCnt; ++i) {
@@ -3291,30 +3296,35 @@
return SurfaceReadPixelsSupport::kSupported;
}
-GrCaps::SupportedRead GrGLCaps::supportedReadPixelsColorType(GrPixelConfig srcPixelConfig,
- const GrBackendFormat& srcFormat,
- GrColorType dstColorType) const {
+GrCaps::SupportedRead GrGLCaps::supportedReadPixelsColorType(
+ GrColorType srcColorType, GrPixelConfig srcPixelConfig,
+ const GrBackendFormat& srcBackendFormat, GrColorType dstColorType) const {
// For now, we mostly report the read back format that is required by the ES spec without
// checking for implementation allowed formats or consider laxer rules in non-ES GL. TODO: Relax
// this as makes sense to increase performance and correctness.
- const GrGLenum* glFormat = srcFormat.getGLFormat();
+ const GrGLenum* glFormat = srcBackendFormat.getGLFormat();
if (!glFormat) {
return {GrSwizzle{}, GrColorType::kUnknown};
}
+ GrGLFormat srcFormat = GrGLBackendFormatToGLFormat(srcBackendFormat);
+
auto swizzle = fConfigTable[srcPixelConfig].fRGBAReadSwizzle;
- switch (fConfigTable[srcPixelConfig].fFormatType) {
- case kNormalizedFixedPoint_FormatType:
- if (kRGB_888X_GrPixelConfig == srcPixelConfig && *glFormat == GR_GL_RGBA8 &&
+ switch (this->getFormatInfo(srcFormat).fFormatType) {
+ case FormatType::kUnknown:
+ return {GrSwizzle{}, GrColorType::kUnknown};
+ case FormatType::kNormalizedFixedPoint:
+ if (srcColorType == GrColorType::kRGB_888x && srcFormat == GrGLFormat::kRGBA8 &&
GrColorTypeHasAlpha(dstColorType)) {
// This can skip an unnecessary conversion.
return {swizzle, GrColorType::kRGB_888x};
- } else if (kSRGBA_8888_GrPixelConfig == srcPixelConfig) {
+ } else if (srcFormat == GrGLFormat::kSRGB8_ALPHA8) {
return {swizzle, GrColorType::kRGBA_8888_SRGB};
}
return {swizzle, GrColorType::kRGBA_8888};
- case kFloat_FormatType:
+ case FormatType::kFloat:
return {swizzle, GrColorType::kRGBA_F32};
}
+ SkUNREACHABLE;
return {GrSwizzle{}, GrColorType::kUnknown};
}
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 64c95aa..40afa9f 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -346,7 +346,7 @@
bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
- SupportedRead supportedReadPixelsColorType(GrPixelConfig, const GrBackendFormat&,
+ SupportedRead supportedReadPixelsColorType(GrColorType, GrPixelConfig, const GrBackendFormat&,
GrColorType) const override;
bool isCoreProfile() const { return fIsCoreProfile; }
@@ -569,12 +569,6 @@
uint32_t fBlitFramebufferFlags;
- /** Number type of the components (with out considering number of bits.) */
- enum FormatType {
- kNormalizedFixedPoint_FormatType,
- kFloat_FormatType,
- };
-
struct ReadPixelsFormat {
ReadPixelsFormat() : fFormat(0), fType(0) {}
GrGLenum fFormat;
@@ -600,8 +594,6 @@
struct ConfigInfo {
ConfigFormats fFormats;
- FormatType fFormatType;
-
// On ES contexts there are restrictions on type type/format that may be used for
// ReadPixels. One is implicitly specified by the current FBO's format. The other is
// queryable. This stores the queried option (lazily).
@@ -616,6 +608,13 @@
ConfigInfo fConfigTable[kGrPixelConfigCnt];
+ /** Number type of the components (with out considering number of bits.) */
+ enum class FormatType {
+ kUnknown,
+ kNormalizedFixedPoint,
+ kFloat,
+ };
+
// ColorTypeInfo for a specific format
struct ColorTypeInfo {
ColorTypeInfo(GrColorType colorType, uint32_t flags)
@@ -652,6 +651,8 @@
};
uint32_t fFlags = 0;
+ FormatType fFormatType = FormatType::kUnknown;
+
// Both compressed and uncompressed formats have base internal formats.
GrGLenum fBaseInternalFormat = 0;
diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp
index 85c8c51..96a7f8c 100644
--- a/tests/GrTestingBackendTextureUploadTest.cpp
+++ b/tests/GrTestingBackendTextureUploadTest.cpp
@@ -60,7 +60,7 @@
}
// skbug.com/9165
auto supportedRead =
- caps->supportedReadPixelsColorType(config, backendTex.getBackendFormat(), grCT);
+ caps->supportedReadPixelsColorType(grCT, config, backendTex.getBackendFormat(), grCT);
if (supportedRead.fColorType != grCT || supportedRead.fSwizzle != GrSwizzle("rgba")) {
return;
}
diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp
index 5d410dc..e11364e 100644
--- a/tests/TransferPixelsTest.cpp
+++ b/tests/TransferPixelsTest.cpp
@@ -42,18 +42,20 @@
}
}
-bool read_pixels_from_texture(GrTexture* texture, GrColorType colorType, char* dst) {
+bool read_pixels_from_texture(GrTexture* texture, GrColorType dstColorType, char* dst) {
auto* context = texture->getContext();
auto* gpu = context->priv().getGpu();
auto* caps = context->priv().caps();
int w = texture->width();
int h = texture->height();
- size_t rowBytes = GrColorTypeBytesPerPixel(colorType) * w;
+ size_t rowBytes = GrColorTypeBytesPerPixel(dstColorType) * w;
+
+ GrColorType srcCT = GrPixelConfigToColorType(texture->config());
GrCaps::SupportedRead supportedRead = caps->supportedReadPixelsColorType(
- texture->config(), texture->backendFormat(), colorType);
- if (supportedRead.fColorType != colorType || supportedRead.fSwizzle != GrSwizzle("rgba")) {
+ srcCT, texture->config(), texture->backendFormat(), dstColorType);
+ if (supportedRead.fColorType != dstColorType || supportedRead.fSwizzle != GrSwizzle("rgba")) {
size_t tmpRowBytes = GrColorTypeBytesPerPixel(supportedRead.fColorType) * w;
std::unique_ptr<char[]> tmpPixels(new char[tmpRowBytes * h]);
if (!gpu->readPixels(texture, 0, 0, w, h,
@@ -61,7 +63,7 @@
return false;
}
GrPixelInfo tmpInfo(supportedRead.fColorType, kPremul_SkAlphaType, nullptr, w, h);
- GrPixelInfo dstInfo(colorType, kPremul_SkAlphaType, nullptr, w, h);
+ GrPixelInfo dstInfo(dstColorType, kPremul_SkAlphaType, nullptr, w, h);
return GrConvertPixels(dstInfo, dst, rowBytes, tmpInfo, tmpPixels.get(), tmpRowBytes, false,
supportedRead.fSwizzle);
}
@@ -240,7 +242,8 @@
// Create the transfer buffer.
auto allowedRead =
- caps->supportedReadPixelsColorType(desc.fConfig, tex->backendFormat(), colorType);
+ caps->supportedReadPixelsColorType(colorType, desc.fConfig, tex->backendFormat(),
+ colorType);
GrPixelInfo readInfo(allowedRead.fColorType, kPremul_SkAlphaType, nullptr, kTextureWidth,
kTextureHeight);