use pinned value during lerp for vertical gradients

slight formatting clean up on associated gm

BUG=skia:

Review URL: https://codereview.chromium.org/1471543002
This commit is contained in:
reed 2015-11-22 13:00:04 -08:00 committed by Commit bot
parent 70d1554d8e
commit de3aac8cea
2 changed files with 18 additions and 13 deletions

View File

@ -610,19 +610,20 @@ protected:
SkPoint pts[2];
SkScalar pos[kStopCount];
} configs[] = {
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0.00001f, 0) } , { 0, 0.5f, 1 }},
{ { SkPoint::Make(9.99999f, 0), SkPoint::Make(10, 0) }, { 0, 0.5f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 0.00001f) }, { 0, 0.5f, 1 }},
{ { SkPoint::Make(0, 9.99999f), SkPoint::Make(0, 10) }, { 0, 0.5f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999999f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000000001f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0.00001f, 0) }, { 0, 0.5f, 1 }},
{ { SkPoint::Make(9.99999f, 0), SkPoint::Make(10, 0) }, { 0, 0.5f, 1 }},
{ { SkPoint::Make(0, 0), SkPoint::Make(0, 0.00001f) }, { 0, 0.5f, 1 }},
{ { SkPoint::Make(0, 9.99999f), SkPoint::Make(0, 10) }, { 0, 0.5f, 1 }},
};
SkPaint paint;

View File

@ -727,6 +727,9 @@ template <bool apply_alpha> void fill(SkPMColor dst[], int count, const Sk4f& c4
*/
static Sk4f lerp_color(float fx, const SkLinearGradient::LinearGradientContext::Rec* rec) {
SkASSERT(fx >= rec[0].fPos);
SkASSERT(fx <= rec[1].fPos);
const float p0 = rec[0].fPos;
const Sk4f c0 = rec[0].fColor;
const Sk4f c1 = rec[1].fColor;
@ -894,7 +897,8 @@ void SkLinearGradient::LinearGradientContext::shade4_clamp(int x, int y, SkPMCol
const float invDx = 1 / dx;
if (SkScalarNearlyZero(dx)) { // gradient is vertical
Sk4f c = lerp_color(fx, find_forward(fRecs.begin(), SkTPin(fx, 0.0f, 1.0f)));
const float pinFx = SkTPin(fx, 0.0f, 1.0f);
Sk4f c = lerp_color(pinFx, find_forward(fRecs.begin(), pinFx));
if (fApplyAlphaAfterInterp) {
fill<true>(dstC, count, c + dither0, c + dither1);
} else {