OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkLinearGradient.h" | 8 #include "SkLinearGradient.h" |
9 | 9 |
10 static inline int repeat_bits(int x, const int bits) { | 10 static inline int repeat_bits(int x, const int bits) { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 unsigned fi = repeat_bits(fx >> SkGradientShaderBase::kCache16Shift, | 370 unsigned fi = repeat_bits(fx >> SkGradientShaderBase::kCache16Shift, |
371 SkGradientShaderBase::kCache16Bits); | 371 SkGradientShaderBase::kCache16Bits); |
372 SkASSERT(fi < SkGradientShaderBase::kCache16Count); | 372 SkASSERT(fi < SkGradientShaderBase::kCache16Count); |
373 fx += dx; | 373 fx += dx; |
374 *dstC++ = cache[toggle + fi]; | 374 *dstC++ = cache[toggle + fi]; |
375 toggle = next_dither_toggle16(toggle); | 375 toggle = next_dither_toggle16(toggle); |
376 } while (--count != 0); | 376 } while (--count != 0); |
377 } | 377 } |
378 } | 378 } |
379 | 379 |
| 380 static bool fixed_nearly_zero(SkFixed x) { |
| 381 return SkAbs32(x) < (SK_Fixed1 >> 12); |
| 382 } |
| 383 |
380 void SkLinearGradient::shadeSpan16(int x, int y, | 384 void SkLinearGradient::shadeSpan16(int x, int y, |
381 uint16_t* SK_RESTRICT dstC, int count) { | 385 uint16_t* SK_RESTRICT dstC, int count) { |
382 SkASSERT(count > 0); | 386 SkASSERT(count > 0); |
383 | 387 |
384 SkPoint srcPt; | 388 SkPoint srcPt; |
385 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 389 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
386 TileProc proc = fTileProc; | 390 TileProc proc = fTileProc; |
387 const uint16_t* SK_RESTRICT cache = this->getCache16(); | 391 const uint16_t* SK_RESTRICT cache = this->getCache16(); |
388 int toggle = init_dither_toggle16(x, y); | 392 int toggle = init_dither_toggle16(x, y); |
389 | 393 |
390 if (fDstToIndexClass != kPerspective_MatrixClass) { | 394 if (fDstToIndexClass != kPerspective_MatrixClass) { |
391 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, | 395 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, |
392 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); | 396 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
393 SkFixed dx, fx = SkScalarToFixed(srcPt.fX); | 397 SkFixed dx, fx = SkScalarToFixed(srcPt.fX); |
394 | 398 |
395 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { | 399 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
396 SkFixed dxStorage[1]; | 400 SkFixed dxStorage[1]; |
397 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), dxStorage, NULL); | 401 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), dxStorage, NULL); |
398 dx = dxStorage[0]; | 402 dx = dxStorage[0]; |
399 } else { | 403 } else { |
400 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); | 404 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
401 dx = SkScalarToFixed(fDstToIndex.getScaleX()); | 405 dx = SkScalarToFixed(fDstToIndex.getScaleX()); |
402 } | 406 } |
403 | 407 |
404 LinearShade16Proc shadeProc = shadeSpan16_linear_repeat; | 408 LinearShade16Proc shadeProc = shadeSpan16_linear_repeat; |
405 if (SkFixedNearlyZero(dx)) { | 409 if (fixed_nearly_zero(dx)) { |
406 shadeProc = shadeSpan16_linear_vertical; | 410 shadeProc = shadeSpan16_linear_vertical; |
407 } else if (SkShader::kClamp_TileMode == fTileMode) { | 411 } else if (SkShader::kClamp_TileMode == fTileMode) { |
408 shadeProc = shadeSpan16_linear_clamp; | 412 shadeProc = shadeSpan16_linear_clamp; |
409 } else if (SkShader::kMirror_TileMode == fTileMode) { | 413 } else if (SkShader::kMirror_TileMode == fTileMode) { |
410 shadeProc = shadeSpan16_linear_mirror; | 414 shadeProc = shadeSpan16_linear_mirror; |
411 } else { | 415 } else { |
412 SkASSERT(SkShader::kRepeat_TileMode == fTileMode); | 416 SkASSERT(SkShader::kRepeat_TileMode == fTileMode); |
413 } | 417 } |
414 (*shadeProc)(proc, dx, fx, dstC, cache, toggle, count); | 418 (*shadeProc)(proc, dx, fx, dstC, cache, toggle, count); |
415 } else { | 419 } else { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 str->append("SkLinearGradient ("); | 561 str->append("SkLinearGradient ("); |
558 | 562 |
559 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 563 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
560 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 564 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
561 | 565 |
562 this->INHERITED::toString(str); | 566 this->INHERITED::toString(str); |
563 | 567 |
564 str->append(")"); | 568 str->append(")"); |
565 } | 569 } |
566 #endif | 570 #endif |
OLD | NEW |