impl 4f version for tricolor shader

Bug: skia:
Change-Id: I43f456aa115ce71a5d1acd9bc94984248a88319a
Reviewed-on: https://skia-review.googlesource.com/15540
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2017-05-04 23:40:01 -04:00 committed by Skia Commit-Bot
parent 7633477b64
commit 4c6e4103a2

View File

@ -1696,6 +1696,7 @@ public:
TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&);
~TriColorShaderContext() override;
void shadeSpan(int x, int y, SkPMColor dstC[], int count) override;
void shadeSpan4f(int x, int y, SkPM4f dstC[], int count) override;
private:
bool setup(const SkPoint pts[], const SkColor colors[], int, int, int);
@ -1704,6 +1705,7 @@ public:
SkPMColor fColors[3];
bool fSetup;
SkPM4f fC0, fC10, fC20, fDC;
typedef SkShader::Context INHERITED;
};
@ -1765,6 +1767,22 @@ bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const S
}
// TODO replace INV(m) * INV(ctm) with INV(ctm * m)
fDstToUnit.setConcat(im, ctmInv);
fC0 = SkPM4f::FromPMColor(fColors[0]);
Sk4f alpha(this->getPaintAlpha() * (1.0f / 255)),
c0 = fC0.to4f() * alpha,
c1 = SkPM4f::FromPMColor(fColors[1]).to4f() * alpha,
c2 = SkPM4f::FromPMColor(fColors[2]).to4f() * alpha,
dx(fDstToUnit.getScaleX()),
dy(fDstToUnit.getSkewY());
Sk4f c10 = c1 - c0,
c20 = c2 - c0;
fDC = SkPM4f::From4f(dx * c10 + dy * c20);
fC10 = SkPM4f::From4f(c10);
fC20 = SkPM4f::From4f(c20);
return true;
}
@ -1831,6 +1849,30 @@ void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor
}
}
void SkTriColorShader::TriColorShaderContext::shadeSpan4f(int x, int y, SkPM4f dstC[], int count) {
SkTriColorShader* parent = static_cast<SkTriColorShader*>(const_cast<SkShader*>(&fShader));
TriColorShaderData* set = parent->takeSetupData();
if (set) {
fSetup = setup(set->pts, set->colors, set->state->f0, set->state->f1, set->state->f2);
}
if (!fSetup) {
// Invalid matrices. Not checked before so no need to assert.
return;
}
SkPoint src;
fDstToUnit.mapXY(SkIntToScalar(x) + 0.5, SkIntToScalar(y) + 0.5, &src);
Sk4f c = fC0.to4f() + src.fX * fC10.to4f() + src.fY * fC20.to4f(),
dc = fDC.to4f();
for (int i = 0; i < count; i++) {
c.store(dstC[i].fVec);
c += dc;
}
}
#ifndef SK_IGNORE_TO_STRING
void SkTriColorShader::toString(SkString* str) const {
str->append("SkTriColorShader: (");