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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 128 |
129 SkASSERT(p0 != p1); | 129 SkASSERT(p0 != p1); |
130 const Sk4f dc = (c1 - c0) / (p1 - p0); | 130 // Either p0 or p1 can be (-)inf for synthetic clamp edge intervals. |
| 131 SkASSERT(SkScalarIsFinite(p0) || SkScalarIsFinite(p1)); |
| 132 |
| 133 const auto dp = p1 - p0; |
| 134 |
| 135 // Clamp edge intervals are always zero-ramp. |
| 136 SkASSERT(SkScalarIsFinite(dp) || fZeroRamp); |
| 137 const Sk4f dc = SkScalarIsFinite(dp) ? (c1 - c0) / dp : 0; |
131 | 138 |
132 c0.store(&fC0.fVec); | 139 c0.store(&fC0.fVec); |
133 dc.store(&fDc.fVec); | 140 dc.store(&fDc.fVec); |
134 } | 141 } |
135 | 142 |
136 SkGradientShaderBase:: | 143 SkGradientShaderBase:: |
137 GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB
ase& shader, | 144 GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB
ase& shader, |
138 const ContextRec& rec) | 145 const ContextRec& rec) |
139 : INHERITED(shader, rec) | 146 : INHERITED(shader, rec) |
140 , fFlags(this->INHERITED::getFlags()) | 147 , fFlags(this->INHERITED::getFlags()) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 : Sk4f(1.0f, 1.0f, 1.0f, paintAlpha); | 223 : Sk4f(1.0f, 1.0f, 1.0f, paintAlpha); |
217 const int first_index = reverse ? shader.fColorCount - 1 : 0; | 224 const int first_index = reverse ? shader.fColorCount - 1 : 0; |
218 const int last_index = shader.fColorCount - 1 - first_index; | 225 const int last_index = shader.fColorCount - 1 - first_index; |
219 const SkScalar first_pos = reverse ? SK_Scalar1 : 0; | 226 const SkScalar first_pos = reverse ? SK_Scalar1 : 0; |
220 const SkScalar last_pos = SK_Scalar1 - first_pos; | 227 const SkScalar last_pos = SK_Scalar1 - first_pos; |
221 | 228 |
222 if (shader.fTileMode == SkShader::kClamp_TileMode) { | 229 if (shader.fTileMode == SkShader::kClamp_TileMode) { |
223 // synthetic edge interval: -/+inf .. P0 | 230 // synthetic edge interval: -/+inf .. P0 |
224 const Sk4f clamp_color = pack_color(shader.fOrigColors[first_index], | 231 const Sk4f clamp_color = pack_color(shader.fOrigColors[first_index], |
225 fColorsArePremul, componentScale); | 232 fColorsArePremul, componentScale); |
226 const SkScalar clamp_pos = reverse ? SK_ScalarMax : SK_ScalarMin; | 233 const SkScalar clamp_pos = reverse ? SK_ScalarInfinity : SK_ScalarNegati
veInfinity; |
227 fIntervals.emplace_back(clamp_color, clamp_pos, | 234 fIntervals.emplace_back(clamp_color, clamp_pos, |
228 clamp_color, first_pos); | 235 clamp_color, first_pos); |
229 } else if (shader.fTileMode == SkShader::kMirror_TileMode && reverse) { | 236 } else if (shader.fTileMode == SkShader::kMirror_TileMode && reverse) { |
230 // synthetic mirror intervals injected before main intervals: (2 .. 1] | 237 // synthetic mirror intervals injected before main intervals: (2 .. 1] |
231 addMirrorIntervals(shader, componentScale, false); | 238 addMirrorIntervals(shader, componentScale, false); |
232 } | 239 } |
233 | 240 |
234 const IntervalIterator iter(shader.fOrigColors, | 241 const IntervalIterator iter(shader.fOrigColors, |
235 shader.fOrigPos, | 242 shader.fOrigPos, |
236 shader.fColorCount, | 243 shader.fColorCount, |
237 reverse); | 244 reverse); |
238 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { | 245 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { |
239 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == p0); | 246 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == p0); |
240 | 247 |
241 fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale)
, | 248 fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale)
, |
242 p0, | 249 p0, |
243 pack_color(c1, fColorsArePremul, componentScale)
, | 250 pack_color(c1, fColorsArePremul, componentScale)
, |
244 p1); | 251 p1); |
245 }); | 252 }); |
246 | 253 |
247 if (shader.fTileMode == SkShader::kClamp_TileMode) { | 254 if (shader.fTileMode == SkShader::kClamp_TileMode) { |
248 // synthetic edge interval: Pn .. +/-inf | 255 // synthetic edge interval: Pn .. +/-inf |
249 const Sk4f clamp_color = pack_color(shader.fOrigColors[last_index], | 256 const Sk4f clamp_color = pack_color(shader.fOrigColors[last_index], |
250 fColorsArePremul, componentScale); | 257 fColorsArePremul, componentScale); |
251 const SkScalar clamp_pos = reverse ? SK_ScalarMin : SK_ScalarMax; | 258 const SkScalar clamp_pos = reverse ? SK_ScalarNegativeInfinity : SK_Scal
arInfinity; |
252 fIntervals.emplace_back(clamp_color, last_pos, | 259 fIntervals.emplace_back(clamp_color, last_pos, |
253 clamp_color, clamp_pos); | 260 clamp_color, clamp_pos); |
254 } else if (shader.fTileMode == SkShader::kMirror_TileMode && !reverse) { | 261 } else if (shader.fTileMode == SkShader::kMirror_TileMode && !reverse) { |
255 // synthetic mirror intervals injected after main intervals: [1 .. 2) | 262 // synthetic mirror intervals injected after main intervals: [1 .. 2) |
256 addMirrorIntervals(shader, componentScale, true); | 263 addMirrorIntervals(shader, componentScale, true); |
257 } | 264 } |
258 } | 265 } |
259 | 266 |
260 void SkGradientShaderBase:: | 267 void SkGradientShaderBase:: |
261 GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad
er, | 268 GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad
er, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 fDc = DstTraits<dstType, premul>::load(i->fDc); | 435 fDc = DstTraits<dstType, premul>::load(i->fDc); |
429 } | 436 } |
430 | 437 |
431 const Interval* fFirstInterval; | 438 const Interval* fFirstInterval; |
432 const Interval* fLastInterval; | 439 const Interval* fLastInterval; |
433 const Interval* fInterval; | 440 const Interval* fInterval; |
434 SkScalar fPrevT; | 441 SkScalar fPrevT; |
435 Sk4f fCc; | 442 Sk4f fCc; |
436 Sk4f fDc; | 443 Sk4f fDc; |
437 }; | 444 }; |
OLD | NEW |