diff options
author | Mike Klein <mtklein@chromium.org> | 2017-05-10 14:04:04 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-10 19:04:09 +0000 |
commit | 77ced29102c8bc3b8c067e56504ad8411c1176a8 (patch) | |
tree | 7443d83d1b542ff4a85f45a398492acea2dc0785 | |
parent | 2814d9148671b8bdbf40a192dcbe485199fd3230 (diff) |
use SkColorSpaceXformer in SkShader appendStages() fallback
We've been transforming the gamut after running the legacy shader,
but now that we have SkColorSpaceXformer, we can transform the
legacy shader into the dst color space instead.
This should be both more correct and faster.
Change-Id: If017048874e6cce46837d3ecbd88dfde503fd03a
Reviewed-on: https://skia-review.googlesource.com/16373
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
-rw-r--r-- | src/core/SkShader.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 1c22dd975c..5f62947008 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -264,7 +264,7 @@ bool SkShader::appendStages(SkRasterPipeline* pipeline, } bool SkShader::onAppendStages(SkRasterPipeline* p, - SkColorSpace* cs, + SkColorSpace* dstCS, SkArenaAlloc* alloc, const SkMatrix& ctm, const SkPaint& paint, @@ -276,25 +276,25 @@ bool SkShader::onAppendStages(SkRasterPipeline* p, opaquePaint.writable()->setAlpha(SK_AlphaOPAQUE); } - ContextRec rec(*opaquePaint, ctm, localM, ContextRec::kPM4f_DstType, cs); - if (Context* ctx = this->makeContext(rec, alloc)) { - struct CallbackCtx : SkJumper_CallbackCtx { - Context* ctx; - }; - - auto cb = alloc->make<CallbackCtx>(); - cb->ctx = ctx; - cb->fn = [](SkJumper_CallbackCtx* self, int active_pixels) { - auto c = (CallbackCtx*)self; - int x = (int)c->rgba[0], - y = (int)c->rgba[1]; - c->ctx->shadeSpan4f(x,y, (SkPM4f*)c->rgba, active_pixels); - }; + ContextRec rec(*opaquePaint, ctm, localM, ContextRec::kPM4f_DstType, dstCS); + + struct CallbackCtx : SkJumper_CallbackCtx { + sk_sp<SkShader> shader; + Context* ctx; + }; + auto cb = alloc->make<CallbackCtx>(); + cb->shader = dstCS ? SkColorSpaceXformer::Make(sk_ref_sp(dstCS))->apply(this) + : sk_ref_sp(const_cast<SkShader*>(this)); + cb->ctx = cb->shader->makeContext(rec, alloc); + cb->fn = [](SkJumper_CallbackCtx* self, int active_pixels) { + auto c = (CallbackCtx*)self; + int x = (int)c->rgba[0], + y = (int)c->rgba[1]; + c->ctx->shadeSpan4f(x,y, (SkPM4f*)c->rgba, active_pixels); + }; + + if (cb->ctx) { p->append(SkRasterPipeline::callback, cb); - - // Legacy shaders aren't aware of color spaces. We can pretty - // safely assume they're in sRGB gamut. - append_gamut_transform(p, alloc, SkColorSpace::MakeSRGB().get(), cs); return true; } return false; |