Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: src/effects/gradients/SkLinearGradient.cpp

Issue 1556993003: fix linear gradient assert, by explicitly clamping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/GradientTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkLinearGradient.cpp
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 298466c8a6500bdda29905a93dbbd7b24b4d5939..4f90c27c8c45980ca05ca545c8af9592abbdb8ba 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -668,12 +668,12 @@ void SkLinearGradient::LinearGradientContext::shade4_dx_clamp(SkPMColor dstC[],
}
fx += n * dx;
- count -= n;
- SkASSERT(count >= 0);
+ // fx should now outside of the p0..p1 interval. However, due to float precision loss,
+ // its possible that fx is slightly too small/large, so we clamp it.
if (dx_is_pos) {
- SkASSERT(0 == count || fx >= p1);
+ fx = SkTMax(fx, p1);
} else {
- SkASSERT(0 == count || fx <= p0);
+ fx = SkTMin(fx, p0);
}
ramp<apply_alpha>(dstC, n, c, dc, dither0, dither1);
@@ -683,6 +683,9 @@ void SkLinearGradient::LinearGradientContext::shade4_dx_clamp(SkPMColor dstC[],
if (n & 1) {
SkTSwap(dither0, dither1);
}
+
+ count -= n;
+ SkASSERT(count >= 0);
}
}
« no previous file with comments | « no previous file | tests/GradientTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698