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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 2 - p0, | 269 2 - p0, |
270 pack_color(c1, fColorsArePremul), | 270 pack_color(c1, fColorsArePremul), |
271 2 - p1, | 271 2 - p1, |
272 componentScale); | 272 componentScale); |
273 }); | 273 }); |
274 } | 274 } |
275 | 275 |
276 void SkGradientShaderBase:: | 276 void SkGradientShaderBase:: |
277 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ | 277 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ |
278 if (fColorsArePremul) { | 278 if (fColorsArePremul) { |
279 this->shadePremulSpan<SkPMColor, ApplyPremul::False>(x, y, dst, count); | 279 this->shadePremulSpan<DstType::L32, ApplyPremul::False>(x, y, dst, count
); |
280 } else { | 280 } else { |
281 this->shadePremulSpan<SkPMColor, ApplyPremul::True>(x, y, dst, count); | 281 this->shadePremulSpan<DstType::L32, ApplyPremul::True>(x, y, dst, count)
; |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 void SkGradientShaderBase:: | 285 void SkGradientShaderBase:: |
286 GradientShaderBase4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count)
{ | 286 GradientShaderBase4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count)
{ |
287 if (fColorsArePremul) { | 287 if (fColorsArePremul) { |
288 this->shadePremulSpan<SkPM4f, ApplyPremul::False>(x, y, dst, count); | 288 this->shadePremulSpan<DstType::F32, ApplyPremul::False>(x, y, dst, count
); |
289 } else { | 289 } else { |
290 this->shadePremulSpan<SkPM4f, ApplyPremul::True>(x, y, dst, count); | 290 this->shadePremulSpan<DstType::F32, ApplyPremul::True>(x, y, dst, count)
; |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 template<typename DstType, ApplyPremul premul> | 294 template<DstType dstType, ApplyPremul premul> |
295 void SkGradientShaderBase:: | 295 void SkGradientShaderBase:: |
296 GradientShaderBase4fContext::shadePremulSpan(int x, int y, | 296 GradientShaderBase4fContext::shadePremulSpan(int x, int y, |
297 DstType dst[], | 297 typename DstTraits<dstType, premul>
::Type dst[], |
298 int count) const { | 298 int count) const { |
299 const SkGradientShaderBase& shader = | 299 const SkGradientShaderBase& shader = |
300 static_cast<const SkGradientShaderBase&>(fShader); | 300 static_cast<const SkGradientShaderBase&>(fShader); |
301 | 301 |
302 switch (shader.fTileMode) { | 302 switch (shader.fTileMode) { |
303 case kClamp_TileMode: | 303 case kClamp_TileMode: |
304 this->shadeSpanInternal<DstType, | 304 this->shadeSpanInternal<dstType, |
305 premul, | 305 premul, |
306 kClamp_TileMode>(x, y, dst, count); | 306 kClamp_TileMode>(x, y, dst, count); |
307 break; | 307 break; |
308 case kRepeat_TileMode: | 308 case kRepeat_TileMode: |
309 this->shadeSpanInternal<DstType, | 309 this->shadeSpanInternal<dstType, |
310 premul, | 310 premul, |
311 kRepeat_TileMode>(x, y, dst, count); | 311 kRepeat_TileMode>(x, y, dst, count); |
312 break; | 312 break; |
313 case kMirror_TileMode: | 313 case kMirror_TileMode: |
314 this->shadeSpanInternal<DstType, | 314 this->shadeSpanInternal<dstType, |
315 premul, | 315 premul, |
316 kMirror_TileMode>(x, y, dst, count); | 316 kMirror_TileMode>(x, y, dst, count); |
317 break; | 317 break; |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 template<typename DstType, ApplyPremul premul, SkShader::TileMode tileMode> | 321 template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> |
322 void SkGradientShaderBase:: | 322 void SkGradientShaderBase:: |
323 GradientShaderBase4fContext::shadeSpanInternal(int x, int y, | 323 GradientShaderBase4fContext::shadeSpanInternal(int x, int y, |
324 DstType dst[], | 324 typename DstTraits<dstType, premu
l>::Type dst[], |
325 int count) const { | 325 int count) const { |
326 static const int kBufSize = 128; | 326 static const int kBufSize = 128; |
327 SkScalar ts[kBufSize]; | 327 SkScalar ts[kBufSize]; |
328 TSampler<DstType, tileMode> sampler(*this); | 328 TSampler<dstType, tileMode> sampler(*this); |
329 | 329 |
330 SkASSERT(count > 0); | 330 SkASSERT(count > 0); |
331 do { | 331 do { |
332 const int n = SkTMin(kBufSize, count); | 332 const int n = SkTMin(kBufSize, count); |
333 this->mapTs(x, y, ts, n); | 333 this->mapTs(x, y, ts, n); |
334 for (int i = 0; i < n; ++i) { | 334 for (int i = 0; i < n; ++i) { |
335 const Sk4f c = sampler.sample(ts[i]); | 335 const Sk4f c = sampler.sample(ts[i]); |
336 store<DstType, kLinear_SkColorProfileType, premul>(c, dst++); | 336 DstTraits<dstType, premul>::store(c, dst++); |
337 } | 337 } |
338 x += n; | 338 x += n; |
339 count -= n; | 339 count -= n; |
340 } while (count > 0); | 340 } while (count > 0); |
341 } | 341 } |
342 | 342 |
343 template<typename DstType, SkShader::TileMode tileMode> | 343 template<DstType dstType, SkShader::TileMode tileMode> |
344 class SkGradientShaderBase::GradientShaderBase4fContext::TSampler { | 344 class SkGradientShaderBase::GradientShaderBase4fContext::TSampler { |
345 public: | 345 public: |
346 TSampler(const GradientShaderBase4fContext& ctx) | 346 TSampler(const GradientShaderBase4fContext& ctx) |
347 : fFirstInterval(ctx.fIntervals.begin()) | 347 : fFirstInterval(ctx.fIntervals.begin()) |
348 , fLastInterval(ctx.fIntervals.end() - 1) | 348 , fLastInterval(ctx.fIntervals.end() - 1) |
349 , fInterval(nullptr) { | 349 , fInterval(nullptr) { |
350 SkASSERT(fLastInterval >= fFirstInterval); | 350 SkASSERT(fLastInterval >= fFirstInterval); |
351 } | 351 } |
352 | 352 |
353 Sk4f sample(SkScalar t) { | 353 Sk4f sample(SkScalar t) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 if (i < fFirstInterval) { | 416 if (i < fFirstInterval) { |
417 i = fLastInterval; | 417 i = fLastInterval; |
418 } | 418 } |
419 } while (tiled_t < i->fP0 || tiled_t >= i->fP1); | 419 } while (tiled_t < i->fP0 || tiled_t >= i->fP1); |
420 } | 420 } |
421 | 421 |
422 return i; | 422 return i; |
423 } | 423 } |
424 | 424 |
425 void loadIntervalData(const Interval* i) { | 425 void loadIntervalData(const Interval* i) { |
426 fCc = scale_for_dest<DstType, kLinear_SkColorProfileType>(dst_swizzle<Ds
tType>(i->fC0)); | 426 fCc = DstTraits<dstType>::load(i->fC0); |
427 fDc = scale_for_dest<DstType, kLinear_SkColorProfileType>(dst_swizzle<Ds
tType>(i->fDc)); | 427 fDc = DstTraits<dstType>::load(i->fDc); |
428 } | 428 } |
429 | 429 |
430 const Interval* fFirstInterval; | 430 const Interval* fFirstInterval; |
431 const Interval* fLastInterval; | 431 const Interval* fLastInterval; |
432 const Interval* fInterval; | 432 const Interval* fInterval; |
433 SkScalar fPrevT; | 433 SkScalar fPrevT; |
434 Sk4f fCc; | 434 Sk4f fCc; |
435 Sk4f fDc; | 435 Sk4f fDc; |
436 }; | 436 }; |
OLD | NEW |