From 30e1e659086a482fc221510fce36bb779798b4f3 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 22 Jan 2016 14:11:00 +0100 Subject: [PATCH] Bug 1242044 - "layout/reftests/css-gradients/linear-zero-length-1 fails under Skia content". r=jmuizelaar --HG-- extra : rebase_source : ec250bf261aec9ffe6eb6c21ec87a2b01ae9e5a0 --- .../skia/src/effects/gradients/SkLinearGradient.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gfx/skia/skia/src/effects/gradients/SkLinearGradient.cpp b/gfx/skia/skia/src/effects/gradients/SkLinearGradient.cpp index 272d15ecdeb3..e5924b448d0e 100644 --- a/gfx/skia/skia/src/effects/gradients/SkLinearGradient.cpp +++ b/gfx/skia/skia/src/effects/gradients/SkLinearGradient.cpp @@ -122,7 +122,12 @@ SkLinearGradient::LinearGradientContext::LinearGradientContext( SkDEBUGCODE(rec[0].fPosScale = SK_FloatNaN;) // should never get used for (int i = 1; i < count; ++i) { rec[i].fPos = SkTPin(shader.fOrigPos[i], rec[i - 1].fPos, 1.0f); - rec[i].fPosScale = 1.0f / (rec[i].fPos - rec[i - 1].fPos); + float diff = rec[i].fPos - rec[i - 1].fPos; + if (diff > 0) { + rec[i].fPosScale = 1.0f / diff; + } else { + rec[i].fPosScale = 0; + } } rec[count - 1].fPos = 1; // overwrite the last value just to be sure we end at 1.0 } else { @@ -670,7 +675,7 @@ find_forward(const SkLinearGradient::LinearGradientContext::Rec rec[], float til SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); SkASSERT(rec[0].fPos <= rec[1].fPos); rec += 1; - while (rec->fPos < tiledX) { + while (rec->fPos < tiledX || rec->fPosScale == 0) { SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); SkASSERT(rec[0].fPos <= rec[1].fPos); @@ -686,7 +691,7 @@ find_backward(const SkLinearGradient::LinearGradientContext::Rec rec[], float ti SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); SkASSERT(rec[0].fPos <= rec[1].fPos); - while (tiledX < rec->fPos) { + while (tiledX < rec->fPos || rec[1].fPosScale == 0) { rec -= 1; SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1);