| 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 #include "Sk4fGradientPriv.h" | |
| 10 | 9 |
| 11 #include <functional> | 10 #include <functional> |
| 12 | 11 |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 SkPMColor pack_color(SkColor c, bool premul) { | 14 SkPMColor pack_color(SkColor c, bool premul) { |
| 16 return premul | 15 return premul |
| 17 ? SkPreMultiplyColor(c) | 16 ? SkPreMultiplyColor(c) |
| 18 : SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), Sk
ColorGetB(c)); | 17 : SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), Sk
ColorGetB(c)); |
| 19 } | 18 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 2 - p0, | 269 2 - p0, |
| 271 pack_color(c1, fColorsArePremul), | 270 pack_color(c1, fColorsArePremul), |
| 272 2 - p1, | 271 2 - p1, |
| 273 componentScale); | 272 componentScale); |
| 274 }); | 273 }); |
| 275 } | 274 } |
| 276 | 275 |
| 277 void SkGradientShaderBase:: | 276 void SkGradientShaderBase:: |
| 278 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ | 277 GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count)
{ |
| 279 if (fColorsArePremul) { | 278 if (fColorsArePremul) { |
| 280 this->shadePremulSpan<SkPMColor, false>(x, y, dst, count); | 279 this->shadePremulSpan<SkPMColor, ApplyPremul::False>(x, y, dst, count); |
| 281 } else { | 280 } else { |
| 282 this->shadePremulSpan<SkPMColor, true>(x, y, dst, count); | 281 this->shadePremulSpan<SkPMColor, ApplyPremul::True>(x, y, dst, count); |
| 283 } | 282 } |
| 284 } | 283 } |
| 285 | 284 |
| 286 void SkGradientShaderBase:: | 285 void SkGradientShaderBase:: |
| 287 GradientShaderBase4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count)
{ | 286 GradientShaderBase4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count)
{ |
| 288 if (fColorsArePremul) { | 287 if (fColorsArePremul) { |
| 289 this->shadePremulSpan<SkPM4f, false>(x, y, dst, count); | 288 this->shadePremulSpan<SkPM4f, ApplyPremul::False>(x, y, dst, count); |
| 290 } else { | 289 } else { |
| 291 this->shadePremulSpan<SkPM4f, true>(x, y, dst, count); | 290 this->shadePremulSpan<SkPM4f, ApplyPremul::True>(x, y, dst, count); |
| 292 } | 291 } |
| 293 } | 292 } |
| 294 | 293 |
| 295 template<typename DstType, bool do_premul> | 294 template<typename DstType, ApplyPremul premul> |
| 296 void SkGradientShaderBase:: | 295 void SkGradientShaderBase:: |
| 297 GradientShaderBase4fContext::shadePremulSpan(int x, int y, | 296 GradientShaderBase4fContext::shadePremulSpan(int x, int y, |
| 298 DstType dst[], | 297 DstType dst[], |
| 299 int count) const { | 298 int count) const { |
| 300 const SkGradientShaderBase& shader = | 299 const SkGradientShaderBase& shader = |
| 301 static_cast<const SkGradientShaderBase&>(fShader); | 300 static_cast<const SkGradientShaderBase&>(fShader); |
| 302 | 301 |
| 303 switch (shader.fTileMode) { | 302 switch (shader.fTileMode) { |
| 304 case kClamp_TileMode: | 303 case kClamp_TileMode: |
| 305 this->shadeSpanInternal<DstType, | 304 this->shadeSpanInternal<DstType, |
| 306 do_premul, | 305 premul, |
| 307 kClamp_TileMode>(x, y, dst, count); | 306 kClamp_TileMode>(x, y, dst, count); |
| 308 break; | 307 break; |
| 309 case kRepeat_TileMode: | 308 case kRepeat_TileMode: |
| 310 this->shadeSpanInternal<DstType, | 309 this->shadeSpanInternal<DstType, |
| 311 do_premul, | 310 premul, |
| 312 kRepeat_TileMode>(x, y, dst, count); | 311 kRepeat_TileMode>(x, y, dst, count); |
| 313 break; | 312 break; |
| 314 case kMirror_TileMode: | 313 case kMirror_TileMode: |
| 315 this->shadeSpanInternal<DstType, | 314 this->shadeSpanInternal<DstType, |
| 316 do_premul, | 315 premul, |
| 317 kMirror_TileMode>(x, y, dst, count); | 316 kMirror_TileMode>(x, y, dst, count); |
| 318 break; | 317 break; |
| 319 } | 318 } |
| 320 } | 319 } |
| 321 | 320 |
| 322 template<typename DstType, bool do_premul, SkShader::TileMode tileMode> | 321 template<typename DstType, ApplyPremul premul, SkShader::TileMode tileMode> |
| 323 void SkGradientShaderBase:: | 322 void SkGradientShaderBase:: |
| 324 GradientShaderBase4fContext::shadeSpanInternal(int x, int y, | 323 GradientShaderBase4fContext::shadeSpanInternal(int x, int y, |
| 325 DstType dst[], | 324 DstType dst[], |
| 326 int count) const { | 325 int count) const { |
| 327 static const int kBufSize = 128; | 326 static const int kBufSize = 128; |
| 328 SkScalar ts[kBufSize]; | 327 SkScalar ts[kBufSize]; |
| 329 TSampler<DstType, tileMode> sampler(*this); | 328 TSampler<DstType, tileMode> sampler(*this); |
| 330 | 329 |
| 331 SkASSERT(count > 0); | 330 SkASSERT(count > 0); |
| 332 do { | 331 do { |
| 333 const int n = SkTMin(kBufSize, count); | 332 const int n = SkTMin(kBufSize, count); |
| 334 this->mapTs(x, y, ts, n); | 333 this->mapTs(x, y, ts, n); |
| 335 for (int i = 0; i < n; ++i) { | 334 for (int i = 0; i < n; ++i) { |
| 336 const Sk4f c = sampler.sample(ts[i]); | 335 const Sk4f c = sampler.sample(ts[i]); |
| 337 store<DstType, do_premul>(c, dst++); | 336 store<DstType, kLinear_SkColorProfileType, premul>(c, dst++); |
| 338 } | 337 } |
| 339 x += n; | 338 x += n; |
| 340 count -= n; | 339 count -= n; |
| 341 } while (count > 0); | 340 } while (count > 0); |
| 342 } | 341 } |
| 343 | 342 |
| 344 template<typename DstType, SkShader::TileMode tileMode> | 343 template<typename DstType, SkShader::TileMode tileMode> |
| 345 class SkGradientShaderBase::GradientShaderBase4fContext::TSampler { | 344 class SkGradientShaderBase::GradientShaderBase4fContext::TSampler { |
| 346 public: | 345 public: |
| 347 TSampler(const GradientShaderBase4fContext& ctx) | 346 TSampler(const GradientShaderBase4fContext& ctx) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (i < fFirstInterval) { | 416 if (i < fFirstInterval) { |
| 418 i = fLastInterval; | 417 i = fLastInterval; |
| 419 } | 418 } |
| 420 } while (tiled_t < i->fP0 || tiled_t >= i->fP1); | 419 } while (tiled_t < i->fP0 || tiled_t >= i->fP1); |
| 421 } | 420 } |
| 422 | 421 |
| 423 return i; | 422 return i; |
| 424 } | 423 } |
| 425 | 424 |
| 426 void loadIntervalData(const Interval* i) { | 425 void loadIntervalData(const Interval* i) { |
| 427 fCc = dst_swizzle<DstType>(i->fC0) * dst_component_scale<DstType>(); | 426 fCc = scale_for_dest<DstType, kLinear_SkColorProfileType>(dst_swizzle<Ds
tType>(i->fC0)); |
| 428 fDc = dst_swizzle<DstType>(i->fDc) * dst_component_scale<DstType>(); | 427 fDc = scale_for_dest<DstType, kLinear_SkColorProfileType>(dst_swizzle<Ds
tType>(i->fDc)); |
| 429 } | 428 } |
| 430 | 429 |
| 431 const Interval* fFirstInterval; | 430 const Interval* fFirstInterval; |
| 432 const Interval* fLastInterval; | 431 const Interval* fLastInterval; |
| 433 const Interval* fInterval; | 432 const Interval* fInterval; |
| 434 SkScalar fPrevT; | 433 SkScalar fPrevT; |
| 435 Sk4f fCc; | 434 Sk4f fCc; |
| 436 Sk4f fDc; | 435 Sk4f fDc; |
| 437 }; | 436 }; |
| OLD | NEW |