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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrGLCaps.h" 9 #include "GrGLCaps.h"
10 10
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= 1390 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |=
1391 ConfigInfo::kRenderableWithMSAA_Flag; 1391 ConfigInfo::kRenderableWithMSAA_Flag;
1392 } 1392 }
1393 } 1393 }
1394 } 1394 }
1395 if (texStorageSupported) { 1395 if (texStorageSupported) {
1396 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexS torage_Flag; 1396 fConfigTable[kBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexS torage_Flag;
1397 } 1397 }
1398 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); 1398 fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1399 1399
1400 // We only enable srgb support if both textures and FBOs support srgb. 1400 // We only enable srgb support if both textures and FBOs support srgb,
1401 bool srgbSupport = false; 1401 // *and* we can disable sRGB decode-on-read, to support "legacy" mode.
1402 if (kGL_GrGLStandard == standard) { 1402 if (kGL_GrGLStandard == standard) {
1403 if (ctxInfo.version() >= GR_GL_VER(3,0)) { 1403 if (ctxInfo.version() >= GR_GL_VER(3,0)) {
1404 srgbSupport = true; 1404 fSRGBSupport = true;
1405 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) { 1405 } else if (ctxInfo.hasExtension("GL_EXT_texture_sRGB")) {
1406 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") || 1406 if (ctxInfo.hasExtension("GL_ARB_framebuffer_sRGB") ||
1407 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) { 1407 ctxInfo.hasExtension("GL_EXT_framebuffer_sRGB")) {
1408 srgbSupport = true; 1408 fSRGBSupport = true;
1409 } 1409 }
1410 } 1410 }
1411 // All the above srgb extensions support toggling srgb writes 1411 // All the above srgb extensions support toggling srgb writes
1412 fSRGBWriteControl = srgbSupport; 1412 fSRGBWriteControl = fSRGBSupport;
1413 } else { 1413 } else {
1414 // See https://bug.skia.org/4148 for PowerVR issue. 1414 // See https://bug.skia.org/4148 for PowerVR issue.
1415 srgbSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() && 1415 fSRGBSupport = kPowerVRRogue_GrGLRenderer != ctxInfo.renderer() &&
1416 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT _sRGB")); 1416 (ctxInfo.version() >= GR_GL_VER(3,0) || ctxInfo.hasExtension("GL_EXT _sRGB"));
1417 // ES through 3.1 requires EXT_srgb_write_control to support toggling 1417 // ES through 3.1 requires EXT_srgb_write_control to support toggling
1418 // sRGB writing for destinations. 1418 // sRGB writing for destinations.
1419 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control"); 1419 fSRGBWriteControl = ctxInfo.hasExtension("GL_EXT_sRGB_write_control");
1420 } 1420 }
1421 if (!ctxInfo.hasExtension("GL_EXT_texture_sRGB_decode")) {
1422 // To support "legacy" L32 mode, we require the ability to turn off sRGB decode:
1423 fSRGBSupport = false;
1424 }
1421 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL _SRGB_ALPHA; 1425 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL _SRGB_ALPHA;
1422 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_G L_SRGB8_ALPHA8; 1426 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_G L_SRGB8_ALPHA8;
1423 // GL does not do srgb<->rgb conversions when transferring between cpu and g pu. Thus, the 1427 // GL does not do srgb<->rgb conversions when transferring between cpu and g pu. Thus, the
1424 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub] Image. 1428 // external format is GL_RGBA. See below for note about ES2.0 and glTex[Sub] Image.
1425 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_Exte rnalFormatUsage] = 1429 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_Exte rnalFormatUsage] =
1426 GR_GL_RGBA; 1430 GR_GL_RGBA;
1427 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIG NED_BYTE; 1431 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIG NED_BYTE;
1428 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_ FormatType; 1432 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_ FormatType;
1429 if (srgbSupport) { 1433 if (fSRGBSupport) {
1430 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureabl e_Flag | 1434 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureabl e_Flag |
1431 allRenderFlags; 1435 allRenderFlags;
1432 } 1436 }
1433 if (texStorageSupported) { 1437 if (texStorageSupported) {
1434 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTex Storage_Flag; 1438 fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTex Storage_Flag;
1435 } 1439 }
1436 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); 1440 fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1437 1441
1442 // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platfo rms where
1443 // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows
1444 // is in this format, for example).
1445 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL _SRGB_ALPHA;
1446 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_G L_SRGB8_ALPHA8;
1447 // GL does not do srgb<->rgb conversions when transferring between cpu and g pu. Thus, the
1448 // external format is GL_BGRA.
1449 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kOther_Exte rnalFormatUsage] =
1450 GR_GL_BGRA;
1451 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIG NED_BYTE;
1452 fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_ FormatType;
1453 if (fSRGBSupport) {
1454 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureabl e_Flag |
1455 allRenderFlags;
1456 }
1457 if (texStorageSupported) {
1458 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTex Storage_Flag;
1459 }
1460 fConfigTable[kSBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA();
1461
1438 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RG B; 1462 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RG B;
1439 if (this->ES2CompatibilitySupport()) { 1463 if (this->ES2CompatibilitySupport()) {
1440 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_RGB565; 1464 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_RGB565;
1441 } else { 1465 } else {
1442 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_RGB5; 1466 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fSizedInternalFormat = GR_ GL_RGB5;
1443 } 1467 }
1444 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_Externa lFormatUsage] = 1468 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalFormat[kOther_Externa lFormatUsage] =
1445 GR_GL_RGB; 1469 GR_GL_RGB;
1446 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED _SHORT_5_6_5; 1470 fConfigTable[kRGB_565_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED _SHORT_5_6_5;
1447 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_For matType; 1471 fConfigTable[kRGB_565_GrPixelConfig].fFormatType = kNormalizedFixedPoint_For matType;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 fConfigTable[i].fFormats.fSizedInternalFormat : 1771 fConfigTable[i].fFormats.fSizedInternalFormat :
1748 fConfigTable[i].fFormats.fBaseInternalFormat; 1772 fConfigTable[i].fFormats.fBaseInternalFormat;
1749 } 1773 }
1750 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the < format> 1774 // OpenGL ES 2.0 + GL_EXT_sRGB allows GL_SRGB_ALPHA to be specified as the < format>
1751 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match. 1775 // param to Tex(Sub)Image. ES 2.0 requires the <internalFormat> and <format> params to match.
1752 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param. 1776 // Thus, on ES 2.0 we will use GL_SRGB_ALPHA as the <format> param.
1753 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage. 1777 // On OpenGL and ES 3.0+ GL_SRGB_ALPHA does not work for the <format> param to glTexImage.
1754 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_V ER(2,0)) { 1778 if (ctxInfo.standard() == kGLES_GrGLStandard && ctxInfo.version() == GR_GL_V ER(2,0)) {
1755 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexIma ge_ExternalFormatUsage] = 1779 fConfigTable[kSRGBA_8888_GrPixelConfig].fFormats.fExternalFormat[kTexIma ge_ExternalFormatUsage] =
1756 GR_GL_SRGB_ALPHA; 1780 GR_GL_SRGB_ALPHA;
1781
1782 // Additionally, because we had to "invent" sBGRA, there is no way to ma ke it work
1783 // in ES 2.0, because there is no <internalFormat> we can use. So just m ake 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
1784 // unsupported. (If we have no sRGB support at all, this will get overwr itten below).
1785 fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = 0;
1757 } 1786 }
1758 1787
1759 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image 1788 // If BGRA is supported as an internal format it must always be specified to glTex[Sub]Image
1760 // as a base format. 1789 // as a base format.
1761 // GL_EXT_texture_format_BGRA8888: 1790 // GL_EXT_texture_format_BGRA8888:
1762 // This extension GL_BGRA as an unsized internal format. However, it is written against ES 1791 // This extension GL_BGRA as an unsized internal format. However, it is written against ES
1763 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal 1792 // 2.0 and therefore doesn't define a value for GL_BGRA8 as ES 2.0 uses unsized internal
1764 // formats. 1793 // formats.
1765 // GL_APPLE_texture_format_BGRA8888: 1794 // GL_APPLE_texture_format_BGRA8888:
1766 // ES 2.0: the extension makes BGRA an external format but not an intern al format. 1795 // ES 2.0: the extension makes BGRA an external format but not an intern al format.
1767 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid inter nal format for 1796 // ES 3.0: the extension explicitly states GL_BGRA8 is not a valid inter nal format for
1768 // glTexImage (just for glTexStorage). 1797 // glTexImage (just for glTexStorage).
1769 if (useSizedTexFormats && this->bgraIsInternalFormat()) { 1798 if (useSizedTexFormats && this->bgraIsInternalFormat()) {
1770 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA; 1799 fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA;
1771 } 1800 }
1772 1801
1802 // HACK: Various GL implementations won't have sRGB support at all, particul arly with our
1803 // requirements. It's easy for sRGB data to leak in, though (via decoded PNG s, etc...).
1804 // Thus, we employ a giant hack to ensure that any non-sRGB-capable device w ill continue
1805 // 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.
1806 // best way to do this - code that does things like elevate to draw for conv ersion to/from
1807 // sRGB will still make that decision, even though the formats are now ident ical.
1808 if (!fSRGBSupport) {
1809 fConfigTable[kSRGBA_8888_GrPixelConfig] = fConfigTable[kRGBA_8888_GrPixe lConfig];
1810 fConfigTable[kSBGRA_8888_GrPixelConfig] = fConfigTable[kBGRA_8888_GrPixe lConfig];
1811 }
1812
1773 // If we don't have texture swizzle support then the shader generator must i nsert the 1813 // If we don't have texture swizzle support then the shader generator must i nsert the
1774 // swizzle into shader code. 1814 // swizzle into shader code.
1775 if (!this->textureSwizzleSupport()) { 1815 if (!this->textureSwizzleSupport()) {
1776 for (int i = 0; i < kGrPixelConfigCnt; ++i) { 1816 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
1777 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle; 1817 glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle;
1778 } 1818 }
1779 } 1819 }
1780 1820
1781 // Shader output swizzles will default to RGBA. When we've use GL_RED instea d of GL_ALPHA to 1821 // Shader output swizzles will default to RGBA. When we've use GL_RED instea d of GL_ALPHA to
1782 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel 1822 // implement kAlpha_8_GrPixelConfig we need to swizzle the shader outputs so the alpha channel
(...skipping 19 matching lines...) Expand all
1802 for (int j = 0; j < kExternalFormatUsageCnt; ++j) { 1842 for (int j = 0; j < kExternalFormatUsageCnt; ++j) {
1803 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] != 1843 SkASSERT(defaultEntry.fFormats.fExternalFormat[j] !=
1804 fConfigTable[i].fFormats.fExternalFormat[j]); 1844 fConfigTable[i].fFormats.fExternalFormat[j]);
1805 } 1845 }
1806 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats .fExternalType); 1846 SkASSERT(defaultEntry.fFormats.fExternalType != fConfigTable[i].fFormats .fExternalType);
1807 } 1847 }
1808 #endif 1848 #endif
1809 } 1849 }
1810 1850
1811 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {} 1851 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698