From 982eb7f377a0c771345276558072deb2fcea0d3e Mon Sep 17 00:00:00 2001 From: brianosman Date: Mon, 6 Jun 2016 13:10:58 -0700 Subject: Add new SkSourceGammaTreatment enum, used in situations like mipmap construction, where we need to know if we should respect (vs. ignore) the gamma encoding of sRGB tagged images. Plumb that extensively. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2037413002 Review-Url: https://codereview.chromium.org/2037413002 --- src/gpu/SkGpuDevice.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/gpu/SkGpuDevice.cpp') diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 406dedb0a7..81e955d702 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -80,21 +80,23 @@ public: AutoBitmapTexture(GrContext* context, const SkBitmap& bitmap, const GrTextureParams& params, + SkSourceGammaTreatment gammaTreatment, GrTexture** texture) { SkASSERT(texture); - *texture = this->set(context, bitmap, params); + *texture = this->set(context, bitmap, params, gammaTreatment); } GrTexture* set(GrContext* context, const SkBitmap& bitmap, - const GrTextureParams& params) { + const GrTextureParams& params, + SkSourceGammaTreatment gammaTreatment) { // Either get the texture directly from the bitmap, or else use the cache and // remember to unref it. if (GrTexture* bmpTexture = bitmap.getTexture()) { fTexture.reset(nullptr); return bmpTexture; } else { - fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params)); + fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params, gammaTreatment)); return fTexture.get(); } } @@ -260,7 +262,8 @@ void SkGpuDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitma GrTexture* texture; // draw sprite neither filters nor tiles. - AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &texture); + AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), + SkSourceGammaTreatment::kRespect, &texture); if (!texture) { return; } @@ -1165,7 +1168,9 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, bitmap.height() <= fContext->caps()->maxTileSize())); GrTexture* texture; - AutoBitmapTexture abt(fContext, bitmap, params, &texture); + SkSourceGammaTreatment gammaTreatment = this->surfaceProps().isGammaCorrect() + ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore; + AutoBitmapTexture abt(fContext, bitmap, params, gammaTreatment, &texture); if (nullptr == texture) { return; } @@ -1264,7 +1269,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, GrTexture* texture; // draw sprite neither filters nor tiles. - AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &texture); + AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), + SkSourceGammaTreatment::kRespect, &texture); if (!texture) { return; } @@ -1520,15 +1526,17 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc } static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_FilterMode; + bool gammaCorrect = this->surfaceProps().isGammaCorrect(); + SkSourceGammaTreatment gammaTreatment = gammaCorrect + ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore; SkAutoTUnref fp( producer->createFragmentProcessor(SkMatrix::I(), SkRect::MakeIWH(producer->width(), producer->height()), GrTextureProducer::kNo_FilterConstraint, true, - &kMode)); + &kMode, gammaTreatment)); GrPaint grPaint; if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, fp, - producer->isAlphaOnly(), - this->surfaceProps().isGammaCorrect(), &grPaint)) { + producer->isAlphaOnly(), gammaCorrect, &grPaint)) { return; } -- cgit v1.2.3