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

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

Issue 1974463002: Harden linear gradients (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: remove unneeded 1-color veto Created 4 years, 7 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 | « src/effects/gradients/SkGradientShader.cpp ('k') | 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 d9d323d59953f37be7f6f53fe72733c5271ca50a..1bdce39d985370c51e5dbcd3c9187c26518c3379 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -99,7 +99,9 @@ SkLinearGradient::LinearGradientContext::LinearGradientContext(
: INHERITED(shader, ctx)
{
// setup for Sk4f
- int count = shader.fColorCount;
+ const int count = shader.fColorCount;
+ SkASSERT(count > 1);
+
fRecs.setCount(count);
Rec* rec = fRecs.begin();
if (shader.fOrigPos) {
@@ -114,16 +116,16 @@ SkLinearGradient::LinearGradientContext::LinearGradientContext(
rec[i].fPosScale = 0;
}
}
- rec[count - 1].fPos = 1; // overwrite the last value just to be sure we end at 1.0
} else {
// no pos specified, so we compute evenly spaced values
const float scale = float(count - 1);
- float invScale = 1.0f / scale;
+ const float invScale = 1.0f / scale;
for (int i = 0; i < count; ++i) {
rec[i].fPos = i * invScale;
rec[i].fPosScale = scale;
}
}
+ rec[count - 1].fPos = 1; // overwrite the last value just to be sure we end at 1.0
fApplyAlphaAfterInterp = true;
if ((shader.getGradFlags() & SkGradientShader::kInterpolateColorsInPremul_Flag) ||
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698