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

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

Issue 2349153004: Harden LinearGradient4fContext (Closed)
Patch Set: Created 4 years, 3 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 | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/Sk4fLinearGradient.cpp
diff --git a/src/effects/gradients/Sk4fLinearGradient.cpp b/src/effects/gradients/Sk4fLinearGradient.cpp
index dc6e530a0c0896777c185b0ab2a1ff5c5be4cefb..cd1f770ef98306f20ac452b729e2950998b3eed1 100644
--- a/src/effects/gradients/Sk4fLinearGradient.cpp
+++ b/src/effects/gradients/Sk4fLinearGradient.cpp
@@ -100,12 +100,13 @@ SkScalar pinFx<SkShader::kMirror_TileMode>(SkScalar fx) {
return f < 0 ? f + 2 : f;
}
-// true when x is in [k1,k2)
+// true when x is in [k1,k2), or [k2, k1) when the interval is reversed.
+// TODO(fmalita): hoist the reversed interval check out of this helper.
bool in_range(SkScalar x, SkScalar k1, SkScalar k2) {
SkASSERT(k1 != k2);
return (k1 < k2)
- ? (x >= k1 && x < k2)
- : (x >= k2 && x < k1);
+ ? (x >= k1 && x < k2)
+ : (x > k2 && x <= k1);
}
} // anonymous namespace
@@ -116,7 +117,7 @@ LinearGradient4fContext::LinearGradient4fContext(const SkLinearGradient& shader,
: INHERITED(shader, rec) {
// Our fast path expects interval points to be monotonically increasing in x.
- const bool reverseIntervals = this->isFast() && fDstToPos.getScaleX() < 0;
+ const bool reverseIntervals = this->isFast() && signbit(fDstToPos.getScaleX());
this->buildIntervals(shader, rec, reverseIntervals);
SkASSERT(fIntervals.count() > 0);
@@ -290,6 +291,7 @@ public:
, fDx(dx)
, fIsVertical(is_vertical)
{
+ SkASSERT(fAdvX >= 0);
SkASSERT(firstInterval <= lastInterval);
SkASSERT(in_range(fx, i->fP0, i->fP1));
this->compute_interval_props(fx - i->fP0);
« no previous file with comments | « no previous file | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698