diff options
author | Mike Klein <mtklein@chromium.org> | 2017-05-12 10:28:23 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-12 10:28:38 +0000 |
commit | df3a371c904c2e3e1d3d9201b7dfc0d080e5f12a (patch) | |
tree | 7fb2449ef82a5c671e2bf427a57b77fd79926fa3 /src/effects | |
parent | 41299bf2f03febf233a266ee2754e7da24a20359 (diff) |
Revert "Evenly space gradient stage."
This reverts commit 892501d09bc8608704362235c73a59bb23a386b3.
Reason for revert:
https://bugs.chromium.org/p/chromium/issues/detail?id=721682
:(
Original change's description:
> Evenly space gradient stage.
>
> This seems like an experiment at this point because I don't know how to do
> this kind of thing on arm.
>
>
> Numbers from Skylake...
> Before:
> ./out/Release/nanobench --config srgb \
> --match gradient_linear_clamp_3color gradient_linear_clamp_hicolor -q 19:48:13
> Timer overhead: 36.7ns
> ! -> high variance, ? -> moderate variance
> micros bench
> 439.92 ? gradient_linear_clamp_3color srgb
> 2697.60 gradient_linear_clamp_hicolor srgb
> 437.28 gradient_linear_clamp_3color_4f srgb
> 2700.50 gradient_linear_clamp_hicolor_4f srgb
>
>
> After:
> micros bench
> 382.35 gradient_linear_clamp_3color srgb
> 593.49 gradient_linear_clamp_hicolor srgb
> 382.36 gradient_linear_clamp_3color_4f srgb
> 565.60 gradient_linear_clamp_hicolor_4f srgb
>
>
> Numbers on my Mac Trashcan are about even; there is no
> speedup or slowdown between master and this change.
>
> Change-Id: I04402452e23c0888512362fd1d6d5436cea61719
> Reviewed-on: https://skia-review.googlesource.com/15960
> Commit-Queue: Herb Derby <herb@google.com>
> Reviewed-by: Mike Klein <mtklein@chromium.org>
>
TBR=mtklein@chromium.org,mtklein@google.com,herb@google.com,fmalita@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: Ic6a064c66686b6f238ca1417ba1abd9ce25de1b4
Reviewed-on: https://skia-review.googlesource.com/16660
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 89 |
1 files changed, 33 insertions, 56 deletions
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 9e2be467f0..6f9b404015 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include <algorithm> #include "Sk4fLinearGradient.h" #include "SkColorSpace_XYZ.h" #include "SkGradientShaderPriv.h" @@ -407,74 +406,51 @@ bool SkGradientShaderBase::onAppendStages(SkRasterPipeline* p, p->append(SkRasterPipeline::linear_gradient_2stops, f_and_b); } else { - if (fOrigPos == nullptr) { - // Handle evenly distributed stops. - struct Ctx { - size_t stopCount; - float* fs[4]; - float* bs[4]; - }; + struct Stop { float t; SkPM4f f, b; }; + struct Ctx { size_t n; Stop* stops; SkPM4f start; }; - auto* ctx = alloc->make<Ctx>(); - int stopCount = fColorCount; - float gapCount = stopCount - 1; + auto* ctx = alloc->make<Ctx>(); + ctx->start = prepareColor(0); - // In the evenly distributed case, fColorCount is the number of stops. There are no - // dummy entries. So, there are fColorCount - 1 FBs. - for (int i = 0; i < 4; i++) { + // For each stop we calculate a bias B and a scale factor F, such that + // for any t between stops n and n+1, the color we want is B[n] + F[n]*t. + auto init_stop = [](float t_l, float t_r, SkPM4f c_l, SkPM4f c_r, Stop *stop) { + auto F = SkPM4f::From4f((c_r.to4f() - c_l.to4f()) / (t_r - t_l)); + auto B = SkPM4f::From4f(c_l.to4f() - (F.to4f() * t_l)); + *stop = {t_l, F, B}; + }; - // Pad up to 8 in case we hit the AVX2 special case. - ctx->fs[i] = alloc->makeArray<float>(std::max(stopCount, 8)); - ctx->bs[i] = alloc->makeArray<float>(std::max(stopCount, 8)); - } + if (fOrigPos == nullptr) { + // Handle evenly distributed stops. + + float dt = 1.0f / (fColorCount - 1); + // In the evenly distributed case, fColorCount is the number of stops. There are no + // dummy entries. + auto* stopsArray = alloc->makeArrayDefault<Stop>(fColorCount); - auto add_stop = [&](int stop, SkPM4f Fs, SkPM4f Bs) { - (ctx->fs[0])[stop] = Fs.r(); - (ctx->fs[1])[stop] = Fs.g(); - (ctx->fs[2])[stop] = Fs.b(); - (ctx->fs[3])[stop] = Fs.a(); - (ctx->bs[0])[stop] = Bs.r(); - (ctx->bs[1])[stop] = Bs.g(); - (ctx->bs[2])[stop] = Bs.b(); - (ctx->bs[3])[stop] = Bs.a(); - }; - auto init_stop = [&](int stop, SkPM4f c_l, SkPM4f c_r) { - auto Fs = SkPM4f::From4f((c_r.to4f() - c_l.to4f()) * gapCount); - auto Bs = SkPM4f::From4f(c_l.to4f() - (Fs.to4f() * (stop / gapCount))); - add_stop(stop, Fs, Bs); - }; - - SkPM4f c_l = prepareColor(0); + float t_l = 0; + SkPM4f c_l = ctx->start; for (int i = 0; i < fColorCount - 1; i++) { + // Use multiply instead of accumulating error using repeated addition. + float t_r = (i + 1) * dt; SkPM4f c_r = prepareColor(i + 1); - init_stop(i, c_l, c_r); + init_stop(t_l, t_r, c_l, c_r, &stopsArray[i]); + + t_l = t_r; c_l = c_r; } - // Add the last stop. - add_stop(stopCount - 1, SkPM4f::FromPremulRGBA(0,0,0,0), c_l); + // Force the last stop. + stopsArray[fColorCount - 1].t = 1; + stopsArray[fColorCount - 1].f = SkPM4f::From4f(Sk4f{0}); + stopsArray[fColorCount - 1].b = prepareColor(fColorCount - 1); - ctx->stopCount = stopCount; - - p->append(SkRasterPipeline::evenly_spaced_linear_gradient, ctx); + ctx->n = fColorCount; + ctx->stops = stopsArray; } else { // Handle arbitrary stops. - struct Stop { float t; SkPM4f f, b; }; - struct Ctx { size_t n; Stop* stops; SkPM4f start; }; - - auto* ctx = alloc->make<Ctx>(); - ctx->start = prepareColor(0); - - // For each stop we calculate a bias B and a scale factor F, such that - // for any t between stops n and n+1, the color we want is B[n] + F[n]*t. - auto init_stop = [](float t_l, float t_r, SkPM4f c_l, SkPM4f c_r, Stop *stop) { - auto F = SkPM4f::From4f((c_r.to4f() - c_l.to4f()) / (t_r - t_l)); - auto B = SkPM4f::From4f(c_l.to4f() - (F.to4f() * t_l)); - *stop = {t_l, F, B}; - }; - // Remove the dummy stops inserted by SkGradientShaderBase::SkGradientShaderBase // because they are naturally handled by the search method. int firstStop; @@ -515,8 +491,9 @@ bool SkGradientShaderBase::onAppendStages(SkRasterPipeline* p, ctx->n = stopCount; ctx->stops = stopsArray; - p->append(SkRasterPipeline::linear_gradient, ctx); } + + p->append(SkRasterPipeline::linear_gradient, ctx); } if (!premulGrad && !this->colorsAreOpaque()) { |