From 688ded2ee6c3472986eec2122830667378697577 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Tue, 7 Feb 2017 11:57:27 -0500 Subject: [PATCH] Add a blend-wrong mode to SkRasterPipelineBlitter. This keeps correct linear blending as the only option exericsed, but it should be easy to see how to turn on blend-wrong mode. Change-Id: I7d87ef8ed00e8990107bd36b826f8d229d930400 Reviewed-on: https://skia-review.googlesource.com/8125 Reviewed-by: Brian Osman Reviewed-by: Matt Sarett Commit-Queue: Mike Klein --- src/core/SkBlitter.cpp | 2 +- src/core/SkCoreBlitters.h | 2 +- src/core/SkRasterPipelineBlitter.cpp | 24 +++++++++++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index a386904..ec519bd 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -847,7 +847,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, return alloc->make(device, *paint); } - if (SkBlitter* blitter = SkCreateRasterPipelineBlitter(device, *paint, matrix, alloc)) { + if (SkBlitter* blitter = SkCreateRasterPipelineBlitter(device, *paint, matrix, alloc, true)) { return blitter; } diff --git a/src/core/SkCoreBlitters.h b/src/core/SkCoreBlitters.h index 63ddda9..42366cc 100644 --- a/src/core/SkCoreBlitters.h +++ b/src/core/SkCoreBlitters.h @@ -205,6 +205,6 @@ SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint, // Returns nullptr if no SkRasterPipeline blitter can be constructed for this paint. SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, const SkMatrix& ctm, - SkArenaAlloc*); + SkArenaAlloc*, bool blendCorrectly); #endif diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp index 1a00009..80e6344 100644 --- a/src/core/SkRasterPipelineBlitter.cpp +++ b/src/core/SkRasterPipelineBlitter.cpp @@ -21,12 +21,13 @@ class SkRasterPipelineBlitter : public SkBlitter { public: static SkBlitter* Create(const SkPixmap&, const SkPaint&, const SkMatrix& ctm, - SkArenaAlloc*); + SkArenaAlloc*, bool blendCorrectly); - SkRasterPipelineBlitter(SkPixmap dst, SkBlendMode blend, SkPM4f paintColor) + SkRasterPipelineBlitter(SkPixmap dst, SkBlendMode blend, SkPM4f paintColor, bool blendCorrectly) : fDst(dst) , fBlend(blend) , fPaintColor(paintColor) + , fBlendCorrectly(blendCorrectly) {} void blitH (int x, int y, int w) override; @@ -47,6 +48,7 @@ private: SkBlendMode fBlend; SkPM4f fPaintColor; SkRasterPipeline fShader; + bool fBlendCorrectly; // These functions are compiled lazily when first used. std::function fBlitH = nullptr, @@ -71,8 +73,9 @@ private: SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, const SkPaint& paint, const SkMatrix& ctm, - SkArenaAlloc* alloc) { - return SkRasterPipelineBlitter::Create(dst, paint, ctm, alloc); + SkArenaAlloc* alloc, + bool blendCorrectly) { + return SkRasterPipelineBlitter::Create(dst, paint, ctm, alloc, blendCorrectly); } static bool supported(const SkImageInfo& info) { @@ -88,11 +91,13 @@ static bool supported(const SkImageInfo& info) { SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, const SkPaint& paint, const SkMatrix& ctm, - SkArenaAlloc* alloc) { + SkArenaAlloc* alloc, + bool blendCorrectly) { auto blitter = alloc->make( dst, paint.getBlendMode(), - SkPM4f_from_SkColor(paint.getColor(), dst.colorSpace())); + SkPM4f_from_SkColor(paint.getColor(), dst.colorSpace()), + blendCorrectly); SkBlendMode* blend = &blitter->fBlend; @@ -126,6 +131,11 @@ SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, pipeline->append(SkRasterPipeline::constant_color, paintColor); } + // Some people want the rest of the pipeline to operate on sRGB encoded color channels... + if (!blendCorrectly && dst.info().gammaCloseToSRGB()) { + pipeline->append(SkRasterPipeline::to_srgb); + } + if (colorFilter) { if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fArena, is_opaque)) { @@ -201,7 +211,7 @@ void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const { } void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { - if (fDst.info().gammaCloseToSRGB()) { + if (fBlendCorrectly && fDst.info().gammaCloseToSRGB()) { p->append(SkRasterPipeline::to_srgb); } if (fDst.info().colorType() == kBGRA_8888_SkColorType) { -- 2.7.4