diff options
author | Mike Klein <mtklein@chromium.org> | 2017-12-11 09:59:47 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-11 15:40:38 +0000 |
commit | a7fa3377d24643d86117159f8a58d2ee66880a4d (patch) | |
tree | b9de6f1caf6d2305e040d4bdb9babf9d2431593c /src/shaders | |
parent | c34676349da62fe8db082dd1a911baa750fd5eca (diff) |
add experimental bilerp_clamp_8888 stage
It looks like we can specialize hot image shaders into their
own single stages for a good speedup on both x86 and ARM.
I've started here with bilerp_clamp_8888, and will
follow up with bgra and 565, and lowp versions of those,
and probably also the same for nearest neighbors.
All pixels are identical in GMs.
Change-Id: I2f6995767cd38053d670b8d0bfdb71b687803d70
Reviewed-on: https://skia-review.googlesource.com/82100
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/shaders')
-rw-r--r-- | src/shaders/SkImageShader.cpp | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index fff59c7bc3..5c97f1c594 100644 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -313,7 +313,7 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { p->append_matrix(alloc, matrix); auto gather = alloc->make<SkJumper_GatherCtx>(); - gather->pixels = pm.writable_addr(); // Don't worry, we won't write to it. + gather->pixels = pm.addr(); gather->stride = pm.rowBytesAsPixels(); gather->width = pm.width(); gather->height = pm.height(); @@ -325,6 +325,8 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { limit_y->scale = pm.height(); limit_y->invScale = 1.0f / pm.height(); + bool is_srgb = rec.fDstCS && (!info.colorSpace() || info.gammaCloseToSRGB()); + auto append_tiling_and_gather = [&] { switch (fTileModeX) { case kClamp_TileMode: /* The gather_xxx stage will clamp for us. */ break; @@ -346,11 +348,38 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::gather_f16, gather); break; default: SkASSERT(false); } - if (rec.fDstCS && (!info.colorSpace() || info.gammaCloseToSRGB())) { + if (is_srgb) { p->append_from_srgb(info.alphaType()); } }; + auto append_misc = [&] { + if (info.colorType() == kAlpha_8_SkColorType) { + p->append(SkRasterPipeline::set_rgb, &misc->paint_color); + } + if (info.colorType() == kAlpha_8_SkColorType || + info.alphaType() == kUnpremul_SkAlphaType) { + p->append(SkRasterPipeline::premul); + } + if (quality > kLow_SkFilterQuality) { + // Bicubic filtering naturally produces out of range values on both sides. + p->append(SkRasterPipeline::clamp_0); + p->append(SkRasterPipeline::clamp_a); + } + append_gamut_transform(p, alloc, info.colorSpace(), rec.fDstCS, kPremul_SkAlphaType); + return true; + }; + + if (quality == kLow_SkFilterQuality && + info.colorType() == kRGBA_8888_SkColorType && + fTileModeX == SkShader::kClamp_TileMode && + fTileModeY == SkShader::kClamp_TileMode && + !is_srgb) { + + p->append(SkRasterPipeline::bilerp_clamp_8888, gather); + return append_misc(); + } + SkJumper_SamplerCtx* sampler = nullptr; if (quality != kNone_SkFilterQuality) { sampler = alloc->make<SkJumper_SamplerCtx>(); @@ -366,6 +395,7 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { if (quality == kNone_SkFilterQuality) { append_tiling_and_gather(); + } else if (quality == kLow_SkFilterQuality) { p->append(SkRasterPipeline::save_xy, sampler); @@ -375,6 +405,7 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { sample(SkRasterPipeline::bilinear_px, SkRasterPipeline::bilinear_py); p->append(SkRasterPipeline::move_dst_src); + } else { p->append(SkRasterPipeline::save_xy, sampler); @@ -401,17 +432,5 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { p->append(SkRasterPipeline::move_dst_src); } - if (info.colorType() == kAlpha_8_SkColorType) { - p->append(SkRasterPipeline::set_rgb, &misc->paint_color); - } - if (info.colorType() == kAlpha_8_SkColorType || info.alphaType() == kUnpremul_SkAlphaType) { - p->append(SkRasterPipeline::premul); - } - if (quality > kLow_SkFilterQuality) { - // Bicubic filtering naturally produces out of range values on both sides. - p->append(SkRasterPipeline::clamp_0); - p->append(SkRasterPipeline::clamp_a); - } - append_gamut_transform(p, alloc, info.colorSpace(), rec.fDstCS, kPremul_SkAlphaType); - return true; + return append_misc(); } |