| 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 #include <functional> | 10 #include <functional> |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // anonymous namespace | 120 } // anonymous namespace |
| 121 | 121 |
| 122 SkGradientShaderBase::GradientShaderBase4fContext:: | 122 SkGradientShaderBase::GradientShaderBase4fContext:: |
| 123 Interval::Interval(const Sk4f& c0, SkScalar p0, | 123 Interval::Interval(const Sk4f& c0, SkScalar p0, |
| 124 const Sk4f& c1, SkScalar p1) | 124 const Sk4f& c1, SkScalar p1) |
| 125 : fP0(p0) | 125 : fP0(p0) |
| 126 , fP1(p1) | 126 , fP1(p1) |
| 127 , fZeroRamp((c0 == c1).allTrue()) { | 127 , fZeroRamp((c0 == c1).allTrue()) { |
| 128 | |
| 129 SkASSERT(p0 != p1); | 128 SkASSERT(p0 != p1); |
| 130 // Either p0 or p1 can be (-)inf for synthetic clamp edge intervals. | 129 // Either p0 or p1 can be (-)inf for synthetic clamp edge intervals. |
| 131 SkASSERT(SkScalarIsFinite(p0) || SkScalarIsFinite(p1)); | 130 SkASSERT(SkScalarIsFinite(p0) || SkScalarIsFinite(p1)); |
| 132 | 131 |
| 133 const auto dp = p1 - p0; | 132 const auto dp = p1 - p0; |
| 134 | 133 |
| 135 // Clamp edge intervals are always zero-ramp. | 134 // Clamp edge intervals are always zero-ramp. |
| 136 SkASSERT(SkScalarIsFinite(dp) || fZeroRamp); | 135 SkASSERT(SkScalarIsFinite(dp) || fZeroRamp); |
| 137 const Sk4f dc = SkScalarIsFinite(dp) ? (c1 - c0) / dp : 0; | 136 const Sk4f dc = SkScalarIsFinite(dp) ? (c1 - c0) / dp : 0; |
| 138 | 137 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 void SkGradientShaderBase:: | 266 void SkGradientShaderBase:: |
| 268 GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad
er, | 267 GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad
er, |
| 269 const Sk4f& componentScale, bool rev
erse) { | 268 const Sk4f& componentScale, bool rev
erse) { |
| 270 const IntervalIterator iter(shader.fOrigColors, | 269 const IntervalIterator iter(shader.fOrigColors, |
| 271 shader.fOrigPos, | 270 shader.fOrigPos, |
| 272 shader.fColorCount, | 271 shader.fColorCount, |
| 273 reverse); | 272 reverse); |
| 274 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { | 273 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { |
| 275 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == 2 - p0); | 274 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == 2 - p0); |
| 276 | 275 |
| 277 fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale)
, | 276 const auto mirror_p0 = 2 - p0; |
| 278 2 - p0, | 277 const auto mirror_p1 = 2 - p1; |
| 279 pack_color(c1, fColorsArePremul, componentScale)
, | 278 // mirror_p1 & mirror_p1 may collapse for very small values - recheck to
avoid |
| 280 2 - p1); | 279 // triggering Interval asserts. |
| 280 if (mirror_p0 != mirror_p1) { |
| 281 fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentSc
ale), |
| 282 mirror_p0, |
| 283 pack_color(c1, fColorsArePremul, componentSc
ale), |
| 284 mirror_p1); |
| 285 } |
| 281 }); | 286 }); |
| 282 } | 287 } |
| 283 | 288 |
| 284 void SkGradientShaderBase:: | 289 void SkGradientShaderBase:: |
| 285 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ | 290 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ |
| 286 if (fColorsArePremul) { | 291 if (fColorsArePremul) { |
| 287 this->shadePremulSpan<DstType::L32, ApplyPremul::False>(x, y, dst, count
); | 292 this->shadePremulSpan<DstType::L32, ApplyPremul::False>(x, y, dst, count
); |
| 288 } else { | 293 } else { |
| 289 this->shadePremulSpan<DstType::L32, ApplyPremul::True>(x, y, dst, count)
; | 294 this->shadePremulSpan<DstType::L32, ApplyPremul::True>(x, y, dst, count)
; |
| 290 } | 295 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 fDc = DstTraits<dstType, premul>::load(i->fDc); | 440 fDc = DstTraits<dstType, premul>::load(i->fDc); |
| 436 } | 441 } |
| 437 | 442 |
| 438 const Interval* fFirstInterval; | 443 const Interval* fFirstInterval; |
| 439 const Interval* fLastInterval; | 444 const Interval* fLastInterval; |
| 440 const Interval* fInterval; | 445 const Interval* fInterval; |
| 441 SkScalar fPrevT; | 446 SkScalar fPrevT; |
| 442 Sk4f fCc; | 447 Sk4f fCc; |
| 443 Sk4f fDc; | 448 Sk4f fDc; |
| 444 }; | 449 }; |
| OLD | NEW |