diff options
author | brianosman <brianosman@google.com> | 2016-06-06 13:10:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-06 13:10:58 -0700 |
commit | 982eb7f377a0c771345276558072deb2fcea0d3e (patch) | |
tree | 02ae878610160d6b6c91629424aaf895e5f17497 /src/core | |
parent | dc27a648d2ff23b2e96232c00c15976c46e1d48d (diff) |
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
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmapProcShader.cpp | 6 | ||||
-rw-r--r-- | src/core/SkBitmapProcShader.h | 3 | ||||
-rw-r--r-- | src/core/SkColorFilterShader.cpp | 12 | ||||
-rw-r--r-- | src/core/SkColorFilterShader.h | 3 | ||||
-rw-r--r-- | src/core/SkColorShader.cpp | 6 | ||||
-rw-r--r-- | src/core/SkColorShader.h | 6 | ||||
-rw-r--r-- | src/core/SkComposeShader.cpp | 18 | ||||
-rw-r--r-- | src/core/SkComposeShader.h | 3 | ||||
-rw-r--r-- | src/core/SkImageCacherator.cpp | 10 | ||||
-rw-r--r-- | src/core/SkImageCacherator.h | 5 | ||||
-rw-r--r-- | src/core/SkLightingShader.cpp | 18 | ||||
-rw-r--r-- | src/core/SkLocalMatrixShader.h | 9 | ||||
-rw-r--r-- | src/core/SkPictureShader.cpp | 10 | ||||
-rw-r--r-- | src/core/SkPictureShader.h | 3 | ||||
-rw-r--r-- | src/core/SkShader.cpp | 3 | ||||
-rw-r--r-- | src/core/SkSpecialImage.cpp | 9 |
16 files changed, 76 insertions, 48 deletions
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index f88729e305..e140f0feb0 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -412,7 +412,8 @@ void SkBitmapProcShader::toString(SkString* str) const { const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkMatrix& viewM, const SkMatrix* localMatrix, - SkFilterQuality filterQuality) const { + SkFilterQuality filterQuality, + SkSourceGammaTreatment gammaTreatment) const { SkMatrix matrix; matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); @@ -443,7 +444,8 @@ const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* co GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic); GrTextureParams params(tm, textureFilterMode); - SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, params)); + SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, params, + gammaTreatment)); if (!texture) { SkErrorInternals::SetError( kInternalError_SkError, diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h index f6492f1887..dbd82a7b8d 100644 --- a/src/core/SkBitmapProcShader.h +++ b/src/core/SkBitmapProcShader.h @@ -26,7 +26,8 @@ public: #if SK_SUPPORT_GPU const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, - const SkMatrix*, SkFilterQuality) const override; + const SkMatrix*, SkFilterQuality, + SkSourceGammaTreatment) const override; #endif protected: diff --git a/src/core/SkColorFilterShader.cpp b/src/core/SkColorFilterShader.cpp index 500ead4f74..4ab232aa38 100644 --- a/src/core/SkColorFilterShader.cpp +++ b/src/core/SkColorFilterShader.cpp @@ -98,13 +98,15 @@ void SkColorFilterShader::FilterShaderContext::shadeSpan4f(int x, int y, SkPM4f ///////////////////////////////////////////////////////////////////// const GrFragmentProcessor* SkColorFilterShader::asFragmentProcessor( - GrContext* context, - const SkMatrix& viewM, - const SkMatrix* localMatrix, - SkFilterQuality fq) const { + GrContext* context, + const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality fq, + SkSourceGammaTreatment gammaTreatment) const { SkAutoTUnref<const GrFragmentProcessor> fp1(fShader->asFragmentProcessor(context, viewM, - localMatrix, fq)); + localMatrix, fq, + gammaTreatment)); if (!fp1.get()) { return nullptr; } diff --git a/src/core/SkColorFilterShader.h b/src/core/SkColorFilterShader.h index e42d06c667..01a03f8200 100644 --- a/src/core/SkColorFilterShader.h +++ b/src/core/SkColorFilterShader.h @@ -19,7 +19,8 @@ public: const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, const SkMatrix* localMatrix, - SkFilterQuality) const override; + SkFilterQuality, + SkSourceGammaTreatment) const override; #endif class FilterShaderContext : public SkShader::Context { diff --git a/src/core/SkColorShader.cpp b/src/core/SkColorShader.cpp index f399eaaa57..2c7ee8bf34 100644 --- a/src/core/SkColorShader.cpp +++ b/src/core/SkColorShader.cpp @@ -91,7 +91,8 @@ SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const { #include "effects/GrConstColorProcessor.h" const GrFragmentProcessor* SkColorShader::asFragmentProcessor(GrContext*, const SkMatrix&, const SkMatrix*, - SkFilterQuality) const { + SkFilterQuality, + SkSourceGammaTreatment) const { GrColor color = SkColorToPremulGrColor(fColor); return GrConstColorProcessor::Create(color, GrConstColorProcessor::kModulateA_InputMode); } @@ -218,7 +219,8 @@ SkShader::GradientType SkColor4Shader::asAGradient(GradientInfo* info) const { #include "effects/GrConstColorProcessor.h" const GrFragmentProcessor* SkColor4Shader::asFragmentProcessor(GrContext*, const SkMatrix&, const SkMatrix*, - SkFilterQuality) const { + SkFilterQuality, + SkSourceGammaTreatment) const { // TODO: how to communicate color4f to Gr GrColor color = SkColorToPremulGrColor(fCachedByteColor); return GrConstColorProcessor::Create(color, GrConstColorProcessor::kModulateA_InputMode); diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h index f7e609498b..841974204a 100644 --- a/src/core/SkColorShader.h +++ b/src/core/SkColorShader.h @@ -50,7 +50,8 @@ public: #if SK_SUPPORT_GPU const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, - const SkMatrix*, SkFilterQuality) const override; + const SkMatrix*, SkFilterQuality, + SkSourceGammaTreatment) const override; #endif SK_TO_STRING_OVERRIDE() @@ -104,7 +105,8 @@ public: #if SK_SUPPORT_GPU const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, - const SkMatrix*, SkFilterQuality) const override; + const SkMatrix*, SkFilterQuality, + SkSourceGammaTreatment) const override; #endif SK_TO_STRING_OVERRIDE() diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp index 46b7724944..13569f1b48 100644 --- a/src/core/SkComposeShader.cpp +++ b/src/core/SkComposeShader.cpp @@ -183,10 +183,12 @@ void SkComposeShader::ComposeShaderContext::shadeSpan(int x, int y, SkPMColor re ///////////////////////////////////////////////////////////////////// -const GrFragmentProcessor* SkComposeShader::asFragmentProcessor(GrContext* context, - const SkMatrix& viewM, - const SkMatrix* localMatrix, - SkFilterQuality fq) const { +const GrFragmentProcessor* SkComposeShader::asFragmentProcessor( + GrContext* context, + const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality fq, + SkSourceGammaTreatment gammaTreatment) const { // Fragment processor will only support SkXfermode::Mode modes currently. SkXfermode::Mode mode; if (!(SkXfermode::AsMode(fMode, &mode))) { @@ -199,19 +201,19 @@ const GrFragmentProcessor* SkComposeShader::asFragmentProcessor(GrContext* conte GrConstColorProcessor::kIgnore_InputMode); break; case SkXfermode::kSrc_Mode: - return fShaderB->asFragmentProcessor(context, viewM, localMatrix, fq); + return fShaderB->asFragmentProcessor(context, viewM, localMatrix, fq, gammaTreatment); break; case SkXfermode::kDst_Mode: - return fShaderA->asFragmentProcessor(context, viewM, localMatrix, fq); + return fShaderA->asFragmentProcessor(context, viewM, localMatrix, fq, gammaTreatment); break; default: SkAutoTUnref<const GrFragmentProcessor> fpA(fShaderA->asFragmentProcessor(context, - viewM, localMatrix, fq)); + viewM, localMatrix, fq, gammaTreatment)); if (!fpA.get()) { return nullptr; } SkAutoTUnref<const GrFragmentProcessor> fpB(fShaderB->asFragmentProcessor(context, - viewM, localMatrix, fq)); + viewM, localMatrix, fq, gammaTreatment)); if (!fpB.get()) { return nullptr; } diff --git a/src/core/SkComposeShader.h b/src/core/SkComposeShader.h index 4d561faac7..ed89b88e88 100644 --- a/src/core/SkComposeShader.h +++ b/src/core/SkComposeShader.h @@ -38,7 +38,8 @@ public: const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, const SkMatrix* localMatrix, - SkFilterQuality) const override; + SkFilterQuality, + SkSourceGammaTreatment) const override; #endif class ComposeShaderContext : public SkShader::Context { diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index 4a8521743d..b4101f15c7 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -249,7 +249,8 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { */ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key, const SkImage* client, SkImage::CachingHint chint, - bool willBeMipped) { + bool willBeMipped, + SkSourceGammaTreatment gammaTreatment) { // Values representing the various texture lock paths we can take. Used for logging the path // taken to a histogram. enum LockTexturePath { @@ -315,7 +316,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key if (this->tryLockAsBitmap(&bitmap, client, chint)) { GrTexture* tex = nullptr; if (willBeMipped) { - tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap); + tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap, gammaTreatment); } if (!tex) { tex = GrUploadBitmapToTexture(ctx, bitmap); @@ -334,17 +335,20 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key /////////////////////////////////////////////////////////////////////////////////////////////////// GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams& params, + SkSourceGammaTreatment gammaTreatment, const SkImage* client, SkImage::CachingHint chint) { if (!ctx) { return nullptr; } - return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params); + return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, + gammaTreatment); } #else GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams&, + SkSourceGammaTreatment gammaTreatment, const SkImage* client, SkImage::CachingHint) { return nullptr; } diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h index 7e146182c7..3be69a5785 100644 --- a/src/core/SkImageCacherator.h +++ b/src/core/SkImageCacherator.h @@ -48,7 +48,8 @@ public: * * The caller is responsible for calling texture->unref() when they are done. */ - GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, const SkImage* client, + GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, + SkSourceGammaTreatment gammaTreatment, const SkImage* client, SkImage::CachingHint = SkImage::kAllow_CachingHint); /** @@ -75,7 +76,7 @@ private: // Returns the texture. If the cacherator is generating the texture and wants to cache it, // it should use the passed in key (if the key is valid). GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* client, - SkImage::CachingHint, bool willBeMipped); + SkImage::CachingHint, bool willBeMipped, SkSourceGammaTreatment); #endif class ScopedGenerator { diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp index d011712fea..542d0f3e67 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -75,7 +75,8 @@ public: const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, const SkMatrix* localMatrix, - SkFilterQuality) const override; + SkFilterQuality, + SkSourceGammaTreatment) const override; #endif class LightingShaderContext : public SkShader::Context { @@ -350,10 +351,11 @@ static bool make_mat(const SkBitmap& bm, } const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( - GrContext* context, - const SkMatrix& viewM, - const SkMatrix* localMatrix, - SkFilterQuality filterQuality) const { + GrContext* context, + const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality filterQuality, + SkSourceGammaTreatment gammaTreatment) const { // we assume diffuse and normal maps have same width and height // TODO: support different sizes SkASSERT(fDiffuseMap.width() == fNormalMap.width() && @@ -386,7 +388,8 @@ const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( // TODO: support other tile modes GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, - fDiffuseMap, diffParams)); + fDiffuseMap, diffParams, + gammaTreatment)); if (!diffuseTexture) { SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bitmap to texture."); return nullptr; @@ -394,7 +397,8 @@ const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( GrTextureParams normParams(kClamp_TileMode, normFilterMode); SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, - fNormalMap, normParams)); + fNormalMap, normParams, + gammaTreatment)); if (!normalTexture) { SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bitmap to texture."); return nullptr; diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h index 8edea40d05..3d590e43e6 100644 --- a/src/core/SkLocalMatrixShader.h +++ b/src/core/SkLocalMatrixShader.h @@ -24,14 +24,15 @@ public: } #if SK_SUPPORT_GPU - const GrFragmentProcessor* asFragmentProcessor(GrContext* context, const SkMatrix& viewM, - const SkMatrix* localMatrix, - SkFilterQuality fq) const override { + const GrFragmentProcessor* asFragmentProcessor( + GrContext* context, const SkMatrix& viewM, + const SkMatrix* localMatrix, SkFilterQuality fq, + SkSourceGammaTreatment gammaTreatment) const override { SkMatrix tmp = this->getLocalMatrix(); if (localMatrix) { tmp.preConcat(*localMatrix); } - return fProxyShader->asFragmentProcessor(context, viewM, &tmp, fq); + return fProxyShader->asFragmentProcessor(context, viewM, &tmp, fq, gammaTreatment); } #endif diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index b6f4d02a55..a880db3536 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -319,10 +319,10 @@ void SkPictureShader::toString(SkString* str) const { #if SK_SUPPORT_GPU const GrFragmentProcessor* SkPictureShader::asFragmentProcessor( - GrContext* context, - const SkMatrix& viewM, - const SkMatrix* localMatrix, - SkFilterQuality fq) const { + GrContext* context, const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality fq, + SkSourceGammaTreatment gammaTreatment) const { int maxTextureSize = 0; if (context) { maxTextureSize = context->caps()->maxTextureSize(); @@ -331,6 +331,6 @@ const GrFragmentProcessor* SkPictureShader::asFragmentProcessor( if (!bitmapShader) { return nullptr; } - return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq); + return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq, gammaTreatment); } #endif diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h index 95289680b0..01a66ec6ea 100644 --- a/src/core/SkPictureShader.h +++ b/src/core/SkPictureShader.h @@ -31,7 +31,8 @@ public: const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, const SkMatrix*, - SkFilterQuality) const override; + SkFilterQuality, + SkSourceGammaTreatment) const override; #endif protected: diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 1b729ea9a8..2ec3b0b661 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -221,7 +221,8 @@ SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { } const GrFragmentProcessor* SkShader::asFragmentProcessor(GrContext*, const SkMatrix&, - const SkMatrix*, SkFilterQuality) const { + const SkMatrix*, SkFilterQuality, + SkSourceGammaTreatment) const { return nullptr; } diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 420b3f1e23..081b2a5b76 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -84,7 +84,8 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) { sk_sp<GrTexture> resultTex(GrRefCachedBitmapTexture(context, bmp, - GrTextureParams::ClampNoFilter())); + GrTextureParams::ClampNoFilter(), + SkSourceGammaTreatment::kRespect)); if (!resultTex) { return nullptr; } @@ -226,7 +227,8 @@ public: #if SK_SUPPORT_GPU sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { return sk_sp<GrTexture>(as_IB(fImage)->asTextureRef(context, - GrTextureParams::ClampNoFilter())); + GrTextureParams::ClampNoFilter(), + SkSourceGammaTreatment::kRespect)); } #endif @@ -368,7 +370,8 @@ public: if (context) { return sk_ref_sp(GrRefCachedBitmapTexture(context, fBitmap, - GrTextureParams::ClampNoFilter())); + GrTextureParams::ClampNoFilter(), + SkSourceGammaTreatment::kRespect)); } return nullptr; |