aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-11-03 12:11:38 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-03 16:45:44 +0000
commit3e20d023bfa6e534ee0abacdba225dd140ae471c (patch)
tree17ac5df9132b07a7dcfd86c8dd541556c7b21ac2 /src/shaders
parentc2d18f34de6fc7a07d1ea8dd4ef7840a2b412f14 (diff)
Enforce gradient color stop monotonicity in ctor
From the SVG 1.1 spec: Each gradient offset value is required to be equal to or greater than the previous gradient stop's offset value. If a given gradient stop's offset value is not equal to or greater than all previous offset values, then the offset value is adjusted to be equal to the largest of all previous offset values. Change-Id: I797369a1e14dc776ceb6478ac9fcdd4792e65562 Reviewed-on: https://skia-review.googlesource.com/67761 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/shaders')
-rw-r--r--src/shaders/gradients/Sk4fGradientBase.cpp7
-rw-r--r--src/shaders/gradients/SkGradientShader.cpp9
2 files changed, 7 insertions, 9 deletions
diff --git a/src/shaders/gradients/Sk4fGradientBase.cpp b/src/shaders/gradients/Sk4fGradientBase.cpp
index 42f30c4a5c..ee701bd57b 100644
--- a/src/shaders/gradients/Sk4fGradientBase.cpp
+++ b/src/shaders/gradients/Sk4fGradientBase.cpp
@@ -38,7 +38,6 @@ public:
}
const int end = fBegin + fAdvance * (fShader.fColorCount - 1);
- const SkScalar lastPos = 1 - fFirstPos;
int prev = fBegin;
SkScalar prevPos = fFirstPos;
@@ -46,11 +45,7 @@ public:
const int curr = prev + fAdvance;
SkASSERT(curr >= 0 && curr < fShader.fColorCount);
- // TODO: this sanitization should be done in SkGradientShaderBase
- const SkScalar currPos = (fAdvance > 0)
- ? SkTPin(fShader.fOrigPos[curr], prevPos, lastPos)
- : SkTPin(fShader.fOrigPos[curr], lastPos, prevPos);
-
+ const SkScalar currPos = fShader.fOrigPos[curr];
if (currPos != prevPos) {
SkASSERT((currPos - prevPos > 0) == (fAdvance > 0));
func(fShader.getXformedColor(prev, fDstCS), fShader.getXformedColor(curr, fDstCS),
diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp
index 03535ffd98..d2a3529132 100644
--- a/src/shaders/gradients/SkGradientShader.cpp
+++ b/src/shaders/gradients/SkGradientShader.cpp
@@ -179,14 +179,16 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
}
if (desc.fPos) {
+ SkScalar pos = 0;
SkScalar* origPosPtr = fOrigPos;
- *origPosPtr++ = 0; // force the first pos to 0
+ *origPosPtr++ = pos; // force the first pos to 0
int startIndex = dummyFirst ? 0 : 1;
int count = desc.fCount + dummyLast;
for (int i = startIndex; i < count; i++) {
- // force the last value to be 1.0
- *origPosPtr++ = (i == desc.fCount) ? 1 : SkScalarPin(desc.fPos[i], 0, 1);
+ // Pin the last value to 1.0, and make sure pos is monotonic.
+ pos = (i == desc.fCount) ? 1 : SkScalarPin(desc.fPos[i], pos, 1);
+ *origPosPtr++ = pos;
}
}
}
@@ -364,6 +366,7 @@ bool SkGradientShaderBase::onAppendStages(const StageRec& rec) const {
for (int i = firstStop; i < lastStop; i++) {
float t_r = fOrigPos[i + 1];
SkPM4f c_r = prepareColor(i + 1);
+ SkASSERT(t_l <= t_r);
if (t_l < t_r) {
init_stop_pos(ctx, stopCount, t_l, t_r, c_l, c_r);
stopCount += 1;