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> |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 SkPMColor pack_color(SkColor c, bool premul) { | 14 Sk4f pack_color(SkColor c, bool premul, const Sk4f& component_scale) { |
15 return premul | 15 const SkColor4f c4f = SkColor4f::FromColor(c); |
16 ? SkPreMultiplyColor(c) | 16 const Sk4f pm4f = premul |
17 : SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), Sk
ColorGetB(c)); | 17 ? c4f.premul().to4f() |
| 18 : Sk4f{c4f.fR, c4f.fG, c4f.fB, c4f.fA}; |
| 19 |
| 20 return pm4f * component_scale; |
18 } | 21 } |
19 | 22 |
20 template<SkShader::TileMode> | 23 template<SkShader::TileMode> |
21 SkScalar tileProc(SkScalar t); | 24 SkScalar tileProc(SkScalar t); |
22 | 25 |
23 template<> | 26 template<> |
24 SkScalar tileProc<SkShader::kClamp_TileMode>(SkScalar t) { | 27 SkScalar tileProc<SkShader::kClamp_TileMode>(SkScalar t) { |
25 // synthetic clamp-mode edge intervals allow for a free-floating t: | 28 // synthetic clamp-mode edge intervals allow for a free-floating t: |
26 // [-inf..0)[0..1)[1..+inf) | 29 // [-inf..0)[0..1)[1..+inf) |
27 return t; | 30 return t; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 const SkScalar* fPos; | 113 const SkScalar* fPos; |
111 const int fCount; | 114 const int fCount; |
112 const SkScalar fFirstPos; | 115 const SkScalar fFirstPos; |
113 const int fBegin; | 116 const int fBegin; |
114 const int fAdvance; | 117 const int fAdvance; |
115 }; | 118 }; |
116 | 119 |
117 } // anonymous namespace | 120 } // anonymous namespace |
118 | 121 |
119 SkGradientShaderBase::GradientShaderBase4fContext:: | 122 SkGradientShaderBase::GradientShaderBase4fContext:: |
120 Interval::Interval(SkPMColor c0, SkScalar p0, | 123 Interval::Interval(const Sk4f& c0, SkScalar p0, |
121 SkPMColor c1, SkScalar p1, | 124 const Sk4f& c1, SkScalar p1) |
122 const Sk4f& componentScale) | |
123 : fP0(p0) | 125 : fP0(p0) |
124 , fP1(p1) | 126 , fP1(p1) |
125 , fZeroRamp(c0 == c1) { | 127 , fZeroRamp((c0 == c1).allTrue()) { |
| 128 |
126 SkASSERT(p0 != p1); | 129 SkASSERT(p0 != p1); |
| 130 const Sk4f dc = (c1 - c0) / (p1 - p0); |
127 | 131 |
128 const Sk4f c4f0 = SkPM4f::FromPMColor(c0).to4f() * componentScale; | 132 c0.store(&fC0.fVec); |
129 const Sk4f c4f1 = SkPM4f::FromPMColor(c1).to4f() * componentScale; | 133 dc.store(&fDc.fVec); |
130 const Sk4f dc4f = (c4f1 - c4f0) / (p1 - p0); | |
131 | |
132 c4f0.store(&fC0.fVec); | |
133 dc4f.store(&fDc.fVec); | |
134 } | 134 } |
135 | 135 |
136 SkGradientShaderBase:: | 136 SkGradientShaderBase:: |
137 GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB
ase& shader, | 137 GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB
ase& shader, |
138 const ContextRec& rec) | 138 const ContextRec& rec) |
139 : INHERITED(shader, rec) | 139 : INHERITED(shader, rec) |
140 , fFlags(this->INHERITED::getFlags()) | 140 , fFlags(this->INHERITED::getFlags()) |
141 #ifdef SK_SUPPORT_LEGACY_GRADIENT_DITHERING | 141 #ifdef SK_SUPPORT_LEGACY_GRADIENT_DITHERING |
142 , fDither(true) | 142 , fDither(true) |
143 #else | 143 #else |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 const Sk4f componentScale = fColorsArePremul | 209 const Sk4f componentScale = fColorsArePremul |
210 ? Sk4f(paintAlpha) | 210 ? Sk4f(paintAlpha) |
211 : Sk4f(1.0f, 1.0f, 1.0f, paintAlpha); | 211 : Sk4f(1.0f, 1.0f, 1.0f, paintAlpha); |
212 const int first_index = reverse ? shader.fColorCount - 1 : 0; | 212 const int first_index = reverse ? shader.fColorCount - 1 : 0; |
213 const int last_index = shader.fColorCount - 1 - first_index; | 213 const int last_index = shader.fColorCount - 1 - first_index; |
214 const SkScalar first_pos = reverse ? SK_Scalar1 : 0; | 214 const SkScalar first_pos = reverse ? SK_Scalar1 : 0; |
215 const SkScalar last_pos = SK_Scalar1 - first_pos; | 215 const SkScalar last_pos = SK_Scalar1 - first_pos; |
216 | 216 |
217 if (shader.fTileMode == SkShader::kClamp_TileMode) { | 217 if (shader.fTileMode == SkShader::kClamp_TileMode) { |
218 // synthetic edge interval: -/+inf .. P0 | 218 // synthetic edge interval: -/+inf .. P0 |
219 const SkPMColor clamp_color = pack_color(shader.fOrigColors[first_index]
, | 219 const Sk4f clamp_color = pack_color(shader.fOrigColors[first_index], |
220 fColorsArePremul); | 220 fColorsArePremul, componentScale); |
221 const SkScalar clamp_pos = reverse ? SK_ScalarMax : SK_ScalarMin; | 221 const SkScalar clamp_pos = reverse ? SK_ScalarMax : SK_ScalarMin; |
222 fIntervals.emplace_back(clamp_color, clamp_pos, | 222 fIntervals.emplace_back(clamp_color, clamp_pos, |
223 clamp_color, first_pos, | 223 clamp_color, first_pos); |
224 componentScale); | |
225 } else if (shader.fTileMode == SkShader::kMirror_TileMode && reverse) { | 224 } else if (shader.fTileMode == SkShader::kMirror_TileMode && reverse) { |
226 // synthetic mirror intervals injected before main intervals: (2 .. 1] | 225 // synthetic mirror intervals injected before main intervals: (2 .. 1] |
227 addMirrorIntervals(shader, componentScale, false); | 226 addMirrorIntervals(shader, componentScale, false); |
228 } | 227 } |
229 | 228 |
230 const IntervalIterator iter(shader.fOrigColors, | 229 const IntervalIterator iter(shader.fOrigColors, |
231 shader.fOrigPos, | 230 shader.fOrigPos, |
232 shader.fColorCount, | 231 shader.fColorCount, |
233 reverse); | 232 reverse); |
234 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { | 233 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { |
235 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == p0); | 234 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == p0); |
236 | 235 |
237 fIntervals.emplace_back(pack_color(c0, fColorsArePremul), | 236 fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale)
, |
238 p0, | 237 p0, |
239 pack_color(c1, fColorsArePremul), | 238 pack_color(c1, fColorsArePremul, componentScale)
, |
240 p1, | 239 p1); |
241 componentScale); | |
242 }); | 240 }); |
243 | 241 |
244 if (shader.fTileMode == SkShader::kClamp_TileMode) { | 242 if (shader.fTileMode == SkShader::kClamp_TileMode) { |
245 // synthetic edge interval: Pn .. +/-inf | 243 // synthetic edge interval: Pn .. +/-inf |
246 const SkPMColor clamp_color = | 244 const Sk4f clamp_color = pack_color(shader.fOrigColors[last_index], |
247 pack_color(shader.fOrigColors[last_index], fColorsArePremul); | 245 fColorsArePremul, componentScale); |
248 const SkScalar clamp_pos = reverse ? SK_ScalarMin : SK_ScalarMax; | 246 const SkScalar clamp_pos = reverse ? SK_ScalarMin : SK_ScalarMax; |
249 fIntervals.emplace_back(clamp_color, last_pos, | 247 fIntervals.emplace_back(clamp_color, last_pos, |
250 clamp_color, clamp_pos, | 248 clamp_color, clamp_pos); |
251 componentScale); | |
252 } else if (shader.fTileMode == SkShader::kMirror_TileMode && !reverse) { | 249 } else if (shader.fTileMode == SkShader::kMirror_TileMode && !reverse) { |
253 // synthetic mirror intervals injected after main intervals: [1 .. 2) | 250 // synthetic mirror intervals injected after main intervals: [1 .. 2) |
254 addMirrorIntervals(shader, componentScale, true); | 251 addMirrorIntervals(shader, componentScale, true); |
255 } | 252 } |
256 } | 253 } |
257 | 254 |
258 void SkGradientShaderBase:: | 255 void SkGradientShaderBase:: |
259 GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad
er, | 256 GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad
er, |
260 const Sk4f& componentScale, bool rev
erse) { | 257 const Sk4f& componentScale, bool rev
erse) { |
261 const IntervalIterator iter(shader.fOrigColors, | 258 const IntervalIterator iter(shader.fOrigColors, |
262 shader.fOrigPos, | 259 shader.fOrigPos, |
263 shader.fColorCount, | 260 shader.fColorCount, |
264 reverse); | 261 reverse); |
265 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { | 262 iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, S
kScalar p1) { |
266 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == 2 - p0); | 263 SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == 2 - p0); |
267 | 264 |
268 fIntervals.emplace_back(pack_color(c0, fColorsArePremul), | 265 fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale)
, |
269 2 - p0, | 266 2 - p0, |
270 pack_color(c1, fColorsArePremul), | 267 pack_color(c1, fColorsArePremul, componentScale)
, |
271 2 - p1, | 268 2 - p1); |
272 componentScale); | |
273 }); | 269 }); |
274 } | 270 } |
275 | 271 |
276 void SkGradientShaderBase:: | 272 void SkGradientShaderBase:: |
277 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ | 273 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ |
278 if (fColorsArePremul) { | 274 if (fColorsArePremul) { |
279 this->shadePremulSpan<DstType::L32, ApplyPremul::False>(x, y, dst, count
); | 275 this->shadePremulSpan<DstType::L32, ApplyPremul::False>(x, y, dst, count
); |
280 } else { | 276 } else { |
281 this->shadePremulSpan<DstType::L32, ApplyPremul::True>(x, y, dst, count)
; | 277 this->shadePremulSpan<DstType::L32, ApplyPremul::True>(x, y, dst, count)
; |
282 } | 278 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 fDc = DstTraits<dstType>::load(i->fDc); | 423 fDc = DstTraits<dstType>::load(i->fDc); |
428 } | 424 } |
429 | 425 |
430 const Interval* fFirstInterval; | 426 const Interval* fFirstInterval; |
431 const Interval* fLastInterval; | 427 const Interval* fLastInterval; |
432 const Interval* fInterval; | 428 const Interval* fInterval; |
433 SkScalar fPrevT; | 429 SkScalar fPrevT; |
434 Sk4f fCc; | 430 Sk4f fCc; |
435 Sk4f fDc; | 431 Sk4f fDc; |
436 }; | 432 }; |
OLD | NEW |