diff options
author | brianosman <brianosman@google.com> | 2016-05-05 12:24:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-05 12:24:31 -0700 |
commit | 2d1ee7936e3536e45c963db004e3b512bb415fd8 (patch) | |
tree | edefade2fbe8c19d10abae08f3a658f202bbb5c1 /src/gpu/GrContext.cpp | |
parent | d215a95882485026d176a81bf58871276b21c89c (diff) |
Added --deepColor option to SampleApp, triggers creation of a ten-bit/channel
buffer. (Only on Windows at the moment). Uses new effect to do the final
gamma adjustment
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1919993002
Review-Url: https://codereview.chromium.org/1919993002
Diffstat (limited to 'src/gpu/GrContext.cpp')
-rw-r--r-- | src/gpu/GrContext.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 31845f9d6d..3ea67c9f01 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -20,6 +20,7 @@ #include "batches/GrCopySurfaceBatch.h" #include "effects/GrConfigConversionEffect.h" +#include "effects/GrGammaEffect.h" #include "text/GrTextBlobCache.h" #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) @@ -529,6 +530,44 @@ bool GrContext::readSurfacePixels(GrSurface* src, return true; } +bool GrContext::applyGamma(GrRenderTarget* dst, GrTexture* src, SkScalar gamma){ + ASSERT_SINGLE_OWNER + RETURN_FALSE_IF_ABANDONED + ASSERT_OWNED_RESOURCE(dst); + ASSERT_OWNED_RESOURCE(src); + GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::applyGamma"); + + // Dimensions must match exactly. + if (dst->width() != src->width() || dst->height() != src->height()) { + return false; + } + + SkSurfaceProps props(SkSurfaceProps::kGammaCorrect_Flag, + SkSurfaceProps::kLegacyFontHost_InitType); + sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst), &props)); + if (!drawContext) { + return false; + } + + GrPaint paint; + if (SkScalarNearlyEqual(gamma, 1.0f)) { + paint.addColorTextureProcessor(src, GrCoordTransform::MakeDivByTextureWHMatrix(src)); + } else { + SkAutoTUnref<const GrFragmentProcessor> fp; + fp.reset(GrGammaEffect::Create(src, gamma)); + paint.addColorFragmentProcessor(fp); + } + paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); + paint.setGammaCorrect(true); + + SkRect rect; + src->getBoundsRect(&rect); + drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); + + this->flushSurfaceWrites(dst); + return true; +} + void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { ASSERT_SINGLE_OWNER RETURN_IF_ABANDONED |