diff options
author | 2016-02-25 13:37:28 -0800 | |
---|---|---|
committer | 2016-02-25 13:37:28 -0800 | |
commit | b976b2761f0bb651edb1e7fe3becc1889cfe3fc4 (patch) | |
tree | 6a2bcec031e92159e9e8b86906aa0cecc54c40f3 /src/effects | |
parent | 00fddebe56fabea67dcc08762805c1294eebf5bf (diff) |
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
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/gradients/Sk4fGradientBase.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/effects/gradients/Sk4fGradientBase.cpp b/src/effects/gradients/Sk4fGradientBase.cpp index 02b43fe08a..442916638b 100644 --- a/src/effects/gradients/Sk4fGradientBase.cpp +++ b/src/effects/gradients/Sk4fGradientBase.cpp @@ -207,8 +207,9 @@ GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB clamp_color, clamp_pos, componentScale); } else if (shader.fTileMode == SkShader::kMirror_TileMode) { + const int count = fIntervals.count(); // 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 SkScalar p0 = interval.fP0; const SkScalar p1 = interval.fP1; @@ -216,6 +217,19 @@ GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB Sk4f c = Sk4f::Load(interval.fC0.fVec) + dc * Sk4f(p1 - 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); |