aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLGpu.cpp
diff options
context:
space:
mode:
authorGravatar brianosman <brianosman@google.com>2016-03-21 06:55:37 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-21 06:55:37 -0700
commita6359365887048ef055196de75591311d7a015f0 (patch)
tree03d964f0818dc7ba10cba8a6d0c7f919c45b0804 /src/gpu/gl/GrGLGpu.cpp
parentf8ee67edb8e5fed34bf4d5208bce89ea8be1ac1e (diff)
sRGB support in Ganesh. Several pieces:
sRGB support now also requires GL_EXT_texture_sRGB_decode, which allows us to disable sRGB -> Linear conversion when reading textures. This gives us an easy way to support "legacy" L32 mode. We disable decoding based on the pixel config of the render target. Textures can override that behavior (specifically for format-conversion draws where we want that behavior). Added sBGRA pixel config, which is not-really-a-format. It's just sRGBA internally, and the external format is BGR order, so TexImage calls will swizzle correctly. This lets us interact with sRGB raster surfaces on BGR platforms. Devices without sRGB support behave like they always have: conversion from color type and profile type ignores sRGB and always returns linear pixel configs. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1789663002 Review URL: https://codereview.chromium.org/1789663002
Diffstat (limited to 'src/gpu/gl/GrGLGpu.cpp')
-rw-r--r--src/gpu/gl/GrGLGpu.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 76cb1a068a..62baf79002 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -898,6 +898,7 @@ static inline GrGLint config_alignment(GrPixelConfig config) {
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
+ case kSBGRA_8888_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
return 4;
default:
@@ -2100,13 +2101,15 @@ bool GrGLGpu::flushGLState(const GrPipeline& pipeline, const GrPrimitiveProcesso
SkSTArray<8, const GrTextureAccess*> textureAccesses;
program->setData(primProc, pipeline, &textureAccesses);
+ GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
+ bool allowSRGB = GrAllowSRGBForDestinationPixelConfig(glRT->config());
+
int numTextureAccesses = textureAccesses.count();
for (int i = 0; i < numTextureAccesses; i++) {
- this->bindTexture(i, textureAccesses[i]->getParams(),
+ this->bindTexture(i, textureAccesses[i]->getParams(), allowSRGB,
static_cast<GrGLTexture*>(textureAccesses[i]->getTexture()));
}
- GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget());
this->flushStencil(pipeline.getStencil());
this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->origin());
this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStencil().isDisabled());
@@ -2607,6 +2610,16 @@ bool GrGLGpu::onGetReadPixelsInfo(GrSurface* srcSurface, int width, int height,
tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
tempDrawInfo->fReadConfig = kRGBA_8888_GrPixelConfig;
ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
+ } else if (readConfig == kSBGRA_8888_GrPixelConfig &&
+ this->glCaps().isConfigRenderable(kSRGBA_8888_GrPixelConfig, false) &&
+ this->readPixelsSupported(kSRGBA_8888_GrPixelConfig, kSRGBA_8888_GrPixelConfig)) {
+ // We're trying to read sBGRA but it's not supported. If sRGBA is renderable and
+ // we can read it back, then do a swizzling draw to a sRGBA and read it back (which
+ // will effectively be sBGRA).
+ tempDrawInfo->fTempSurfaceDesc.fConfig = kSRGBA_8888_GrPixelConfig;
+ tempDrawInfo->fSwizzle = GrSwizzle::BGRA();
+ tempDrawInfo->fReadConfig = kSRGBA_8888_GrPixelConfig;
+ ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
} else if (readConfig == kAlpha_8_GrPixelConfig) {
// onReadPixels implements a fallback for cases where we are want to read kAlpha_8,
// it's unsupported, but 32bit RGBA reads are supported.
@@ -3311,7 +3324,8 @@ static void get_tex_param_swizzle(GrPixelConfig config,
}
}
-void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture) {
+void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, bool dstConfigAllowsSRGB,
+ GrGLTexture* texture) {
SkASSERT(texture);
#ifdef SK_DEBUG
@@ -3347,6 +3361,19 @@ void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
bool setAll = timestamp < this->getResetTimestamp();
GrGLTexture::TexParams newTexParams;
+ if (this->caps()->srgbSupport()) {
+ // By default, the decision to allow SRGB decode is based on the destination config.
+ // A texture can override that by specifying a value in GrTextureParams.
+ newTexParams.fSRGBDecode =
+ (dstConfigAllowsSRGB || GrTextureParams::kForceAllowSRGB_SRGBMode == params.srgbMode())
+ ? GR_GL_DECODE_EXT : GR_GL_SKIP_DECODE_EXT;
+
+ if (setAll || newTexParams.fSRGBDecode != oldTexParams.fSRGBDecode) {
+ this->setTextureUnit(unitIdx);
+ GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SRGB_DECODE_EXT, newTexParams.fSRGBDecode));
+ }
+ }
+
static GrGLenum glMinFilterModes[] = {
GR_GL_NEAREST,
GR_GL_LINEAR,
@@ -4014,7 +4041,7 @@ void GrGLGpu::copySurfaceAsDraw(GrSurface* dst,
GrGLTexture* srcTex = static_cast<GrGLTexture*>(src->asTexture());
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
- this->bindTexture(0, params, srcTex);
+ this->bindTexture(0, params, true, srcTex);
GrGLIRect dstVP;
this->bindSurfaceFBOForCopy(dst, GR_GL_FRAMEBUFFER, &dstVP, kDst_TempFBOTarget);