diff options
author | Mike Reed <reed@google.com> | 2017-05-12 13:07:46 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-12 17:49:22 +0000 |
commit | 273eeade448d9bd02a8da508c1fa88a9fbeec42e (patch) | |
tree | 9f109b9a7b5193ad384edb96265f3c0f2ab70bae /src | |
parent | 08aa88d280732386f4c56cbce6ae15f638805a1b (diff) |
implement 4f for composeshader
Bug: skia:
Change-Id: I7ad0077345f7589528c89cd84d252539a1df6614
Reviewed-on: https://skia-review.googlesource.com/16703
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkComposeShader.cpp | 30 | ||||
-rw-r--r-- | src/core/SkComposeShader.h | 1 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 8 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp index 9cb16addc6..ee0fe10c77 100644 --- a/src/core/SkComposeShader.cpp +++ b/src/core/SkComposeShader.cpp @@ -182,6 +182,36 @@ void SkComposeShader::ComposeShaderContext::shadeSpan(int x, int y, SkPMColor re } } +void SkComposeShader::ComposeShaderContext::shadeSpan4f(int x, int y, SkPM4f result[], int count) { + SkShader::Context* shaderContextA = fShaderContextA; + SkShader::Context* shaderContextB = fShaderContextB; + SkBlendMode mode = static_cast<const SkComposeShader&>(fShader).fMode; + unsigned alpha = this->getPaintAlpha(); + Sk4f scale(alpha * (1.0f / 255)); + + SkPM4f tmp[TMP_COLOR_COUNT]; + + SkXfermodeProc4f xfer = SkXfermode::GetProc4f(mode); + do { + int n = SkTMin(count, TMP_COLOR_COUNT); + + shaderContextA->shadeSpan4f(x, y, result, n); + shaderContextB->shadeSpan4f(x, y, tmp, n); + if (255 == alpha) { + for (int i = 0; i < n; ++i) { + result[i] = xfer(tmp[i], result[i]); + } + } else { + for (int i = 0; i < n; ++i) { + (xfer(tmp[i], result[i]).to4f() * scale).store(result + i); + } + } + result += n; + x += n; + count -= n; + } while (count > 0); +} + #if SK_SUPPORT_GPU #include "effects/GrConstColorProcessor.h" diff --git a/src/core/SkComposeShader.h b/src/core/SkComposeShader.h index be39393923..0204b76ce4 100644 --- a/src/core/SkComposeShader.h +++ b/src/core/SkComposeShader.h @@ -48,6 +48,7 @@ public: SkShader::Context* contextA, SkShader::Context* contextB); void shadeSpan(int x, int y, SkPMColor[], int count) override; + void shadeSpan4f(int x, int y, SkPM4f[], int count) override; private: SkShader::Context* fShaderContextA; diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 72ffffbe6c..cbb9d26d14 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -1891,10 +1891,14 @@ void SkTriColorShader::TriColorShaderContext::shadeSpan4f(int x, int y, SkPM4f d } Sk4f c = fM43.map(SkIntToScalar(x) + 0.5, SkIntToScalar(y) + 0.5), - dc = Sk4f::Load(&fM43.fMat[0]); + dc = Sk4f::Load(&fM43.fMat[0]), + zero(0.0f), + one(1.0f); for (int i = 0; i < count; i++) { - c.store(dstC[i].fVec); + // We don't expect to be wildly out of 0...1, but we pin just because of minor + // numerical imprecision. + Sk4f::Min(Sk4f::Max(c, zero), Sk4f::Min(c[3], one)).store(dstC + i); c += dc; } } |