Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: src/gpu/gl/GrGLCaps.cpp

Issue 1789663002: sRGB support in Ganesh. Several pieces: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Ensure sBGRA is unsupported on ES 2.0. Fix CreateRenderTarget. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/gl/GrGLCaps.cpp
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 5baed59f14de1cb501d766144c8343e2f14beef0..a4f4fe75152db6a7561008d9e5429de7b4c6f33f 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -1397,27 +1397,31 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
}
fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
- // We only enable srgb support if both textures and FBOs support srgb.
- bool srgbSupport = false;
+ // We only enable srgb support if both textures and FBOs support srgb,
+ // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
if (kGL_GrGLStandard == standard) {
if (ctxInfo.version() >= GR_GL_VER(3,0)) {
- srgbSupport = true;
+ fSRGBSupport = true;
} else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
- srgbSupport = true;
+ fSRGBSupport = true;
}
}
// All the above srgb extensions support toggling srgb writes
- fSRGBWriteControl = srgbSupport;
+ fSRGBWriteControl = fSRGBSupport;
} else {
// See https://bug.skia.org/4148 for PowerVR issue.
- srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
+ fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
(ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT_sRGB"));
// ES through 3.1 requires EXT_srgb_write_control to support toggling
// sRGB writing for destinations.
fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
}
+ if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
+ // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
+ fSRGBSupport = false;
+ }
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
@@ -1426,7 +1430,7 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
GR_GL_RGBA;
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
- if (srgbSupport) {
+ if (fSRGBSupport) {
fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
allRenderFlags;
}
@@ -1435,6 +1439,26 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
}
fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
+ // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where
+ // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
+ // is in this format, for example).
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_SRGB_ALPHA;
+ 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] =
+ GR_GL_BGRA;
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE;
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType;
+ if (fSRGBSupport) {
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag |
+ allRenderFlags;
+ }
+ if (texStorageSupported) {
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag;
+ }
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
+
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB;
if (this->ES2CompatibilitySupport()) {
fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGB565;
@@ -1754,6 +1778,11 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_VER(2,0)) {
fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexImage_ExternalFormatUsage] =
GR_GL_SRGB_ALPHA;
+
+ // Additionally, because we had to "invent" sBGRA, there is no way to make it work
+ // in ES 2.0, because there is no <internalFormat> we can use. So just make that format
bsalomon 2016/03/11 23:16:20 Not true on ES 3.0+?
Brian Osman 2016/03/17 14:32:06 My reading of this is that it's allowed? ES2 force
+ // unsupported. (If we have no sRGB support at all, this will get overwritten below).
+ fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
}
// If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
@@ -1770,6 +1799,17 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
}
+ // HACK: Various GL implementations won't have sRGB support at all, particularly with our
+ // requirements. It's easy for sRGB data to leak in, though (via decoded PNGs, etc...).
+ // Thus, we employ a giant hack to ensure that any non-sRGB-capable device will continue
+ // to function as it always has, where everything is treated as linear. This isn't the
bsalomon 2016/03/11 23:16:20 Can we pass the caps to the ct/at/pt -> grpc conve
Brian Osman 2016/03/17 14:32:05 Done.
+ // best way to do this - code that does things like elevate to draw for conversion to/from
+ // sRGB will still make that decision, even though the formats are now identical.
+ if (!fSRGBSupport) {
+ fConfigTable[kSRGBA_8888_GrPixelConfig] = fConfigTable[kRGBA_8888_GrPixelConfig];
+ fConfigTable[kSBGRA_8888_GrPixelConfig] = fConfigTable[kBGRA_8888_GrPixelConfig];
+ }
+
// If we don't have texture swizzle support then the shader generator must insert the
// swizzle into shader code.
if (!this->textureSwizzleSupport()) {

Powered by Google App Engine
This is Rietveld 408576698