diff options
author | reed <reed@chromium.org> | 2015-11-22 13:00:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-22 13:00:04 -0800 |
commit | de3aac8cea8a7113f31591e6e02c51fe0ac45280 (patch) | |
tree | 29fbe1fc7f41d480e53121b00ee84518f8cfcf98 | |
parent | 70d1554d8ea08ddb887550f98b9cfd0afd395d65 (diff) |
use pinned value during lerp for vertical gradients
slight formatting clean up on associated gm
BUG=skia:
Review URL: https://codereview.chromium.org/1471543002
-rw-r--r-- | gm/gradients.cpp | 27 | ||||
-rw-r--r-- | src/effects/gradients/SkLinearGradient.cpp | 6 |
2 files changed, 19 insertions, 14 deletions
diff --git a/gm/gradients.cpp b/gm/gradients.cpp index 92e22eebef..9c4d6211b7 100644 --- a/gm/gradients.cpp +++ b/gm/gradients.cpp @@ -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(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(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(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; diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 013c1f1dde..bfa473c012 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -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 { |