| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Sk4fGradientBase.h" | 8 #include "Sk4fGradientBase.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 if (shader.fTileMode == SkShader::kClamp_TileMode) { | 201 if (shader.fTileMode == SkShader::kClamp_TileMode) { |
| 202 // synthetic edge interval: Pn .. +/-inf | 202 // synthetic edge interval: Pn .. +/-inf |
| 203 const SkPMColor clamp_color = | 203 const SkPMColor clamp_color = |
| 204 pack_color(shader.fOrigColors[last_index], fColorsArePremul); | 204 pack_color(shader.fOrigColors[last_index], fColorsArePremul); |
| 205 const SkScalar clamp_pos = dx_is_pos ? SK_ScalarMax : SK_ScalarMin; | 205 const SkScalar clamp_pos = dx_is_pos ? SK_ScalarMax : SK_ScalarMin; |
| 206 fIntervals.emplace_back(clamp_color, last_pos, | 206 fIntervals.emplace_back(clamp_color, last_pos, |
| 207 clamp_color, clamp_pos, | 207 clamp_color, clamp_pos, |
| 208 componentScale); | 208 componentScale); |
| 209 } else if (shader.fTileMode == SkShader::kMirror_TileMode) { | 209 } else if (shader.fTileMode == SkShader::kMirror_TileMode) { |
| 210 const int count = fIntervals.count(); |
| 210 // synthetic flipped intervals in [1 .. 2) | 211 // synthetic flipped intervals in [1 .. 2) |
| 211 for (int i = fIntervals.count() - 1; i >= 0; --i) { | 212 for (int i = count - 1; i >= 0; --i) { |
| 212 const Interval& interval = fIntervals[i]; | 213 const Interval& interval = fIntervals[i]; |
| 213 const SkScalar p0 = interval.fP0; | 214 const SkScalar p0 = interval.fP0; |
| 214 const SkScalar p1 = interval.fP1; | 215 const SkScalar p1 = interval.fP1; |
| 215 Sk4f dc = Sk4f::Load(interval.fDc.fVec); | 216 Sk4f dc = Sk4f::Load(interval.fDc.fVec); |
| 216 Sk4f c = Sk4f::Load(interval.fC0.fVec) + dc * Sk4f(p1 - p0); | 217 Sk4f c = Sk4f::Load(interval.fC0.fVec) + dc * Sk4f(p1 - p0); |
| 217 fIntervals.emplace_back(c, dc * Sk4f(-1), 2 - p1, 2 - p0); | 218 fIntervals.emplace_back(c, dc * Sk4f(-1), 2 - p1, 2 - p0); |
| 218 } | 219 } |
| 220 |
| 221 if (!dx_is_pos) { |
| 222 // When dx is negative, our initial invervals are in (1..0] order. |
| 223 // The loop above appends their flipped counterparts, pivoted in 2:
(1..0](2..1] |
| 224 // To achieve the expected monotonic interval order, we need to |
| 225 // swap the two halves: (2..1](1..0] |
| 226 // TODO: we can probably avoid this late swap with some additional l
ogic during |
| 227 // the initial interval buildup. |
| 228 SkASSERT(fIntervals.count() == count * 2) |
| 229 for (int i = 0; i < count; ++i) { |
| 230 SkTSwap(fIntervals[i], fIntervals[count + i]); |
| 231 } |
| 232 } |
| 219 } | 233 } |
| 220 | 234 |
| 221 SkASSERT(fIntervals.count() > 0); | 235 SkASSERT(fIntervals.count() > 0); |
| 222 fCachedInterval = fIntervals.begin(); | 236 fCachedInterval = fIntervals.begin(); |
| 223 } | 237 } |
| 224 | 238 |
| 225 const SkGradientShaderBase::GradientShaderBase4fContext::Interval* | 239 const SkGradientShaderBase::GradientShaderBase4fContext::Interval* |
| 226 SkGradientShaderBase:: | 240 SkGradientShaderBase:: |
| 227 GradientShaderBase4fContext::findInterval(SkScalar fx) const { | 241 GradientShaderBase4fContext::findInterval(SkScalar fx) const { |
| 228 SkASSERT(in_range(fx, fIntervals.front().fP0, fIntervals.back().fP1)); | 242 SkASSERT(in_range(fx, fIntervals.front().fP0, fIntervals.back().fP1)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 257 } else { | 271 } else { |
| 258 SkASSERT(in_range(fx, i->fP1, i1->fP1)); | 272 SkASSERT(in_range(fx, i->fP1, i1->fP1)); |
| 259 i0 = i + 1; | 273 i0 = i + 1; |
| 260 } | 274 } |
| 261 } | 275 } |
| 262 | 276 |
| 263 SkASSERT(in_range(fx, i0->fP0, i0->fP1)); | 277 SkASSERT(in_range(fx, i0->fP0, i0->fP1)); |
| 264 return i0; | 278 return i0; |
| 265 } | 279 } |
| 266 } | 280 } |
| OLD | NEW |