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

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

Issue 1619413002: skip zero-length linear gradient intervals to make new code more consistent with older table-based … (Closed) Base URL: https://skia.googlesource.com/skia@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 | no next file » | 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 4f90c27c8c45980ca05ca545c8af9592abbdb8ba..8c74427bac152705750eaae05b9d29b05950522f 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -100,7 +100,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 {
@@ -483,7 +488,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);
@@ -499,7 +504,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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698