4f gradient negative-dx interval fixup for kMirror_TileMode
4f intervals are meant to be monotonically increasing in X. This means we invert the point order when dx < 0: [0...1) -> (1...0] For kMirror_TileMode, we also append a duplicate/flipped interval sequence and expand the range to 2: [0...1) -> [0...1)[1...2) When dx < 0, the current logic yields (1...0] -> (1...0](2...1] which violates the interval monotonicity. To achieve the proper order, we need to swap the two halves: (1...0] -> (1...0](2...1] -> (2...1](1...0] R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1735773003 Review URL: https://codereview.chromium.org/1735773003
This commit is contained in:
parent
00fddebe56
commit
b976b2761f
@ -207,8 +207,9 @@ GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB
|
|||||||
clamp_color, clamp_pos,
|
clamp_color, clamp_pos,
|
||||||
componentScale);
|
componentScale);
|
||||||
} else if (shader.fTileMode == SkShader::kMirror_TileMode) {
|
} else if (shader.fTileMode == SkShader::kMirror_TileMode) {
|
||||||
|
const int count = fIntervals.count();
|
||||||
// synthetic flipped intervals in [1 .. 2)
|
// synthetic flipped intervals in [1 .. 2)
|
||||||
for (int i = fIntervals.count() - 1; i >= 0; --i) {
|
for (int i = count - 1; i >= 0; --i) {
|
||||||
const Interval& interval = fIntervals[i];
|
const Interval& interval = fIntervals[i];
|
||||||
const SkScalar p0 = interval.fP0;
|
const SkScalar p0 = interval.fP0;
|
||||||
const SkScalar p1 = interval.fP1;
|
const SkScalar p1 = interval.fP1;
|
||||||
@ -216,6 +217,19 @@ GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB
|
|||||||
Sk4f c = Sk4f::Load(interval.fC0.fVec) + dc * Sk4f(p1 - p0);
|
Sk4f c = Sk4f::Load(interval.fC0.fVec) + dc * Sk4f(p1 - p0);
|
||||||
fIntervals.emplace_back(c, dc * Sk4f(-1), 2 - p1, 2 - p0);
|
fIntervals.emplace_back(c, dc * Sk4f(-1), 2 - p1, 2 - p0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dx_is_pos) {
|
||||||
|
// When dx is negative, our initial invervals are in (1..0] order.
|
||||||
|
// The loop above appends their flipped counterparts, pivoted in 2: (1..0](2..1]
|
||||||
|
// To achieve the expected monotonic interval order, we need to
|
||||||
|
// swap the two halves: (2..1](1..0]
|
||||||
|
// TODO: we can probably avoid this late swap with some additional logic during
|
||||||
|
// the initial interval buildup.
|
||||||
|
SkASSERT(fIntervals.count() == count * 2)
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
SkTSwap(fIntervals[i], fIntervals[count + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkASSERT(fIntervals.count() > 0);
|
SkASSERT(fIntervals.count() > 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user