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 "Sk4fLinearGradient.h" | 8 #include "Sk4fLinearGradient.h" |
9 #include "SkLinearGradient.h" | 9 #include "SkLinearGradient.h" |
10 | 10 |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 const float dither
[2]) { | 603 const float dither
[2]) { |
604 Sk4f dither0(dither[0]); | 604 Sk4f dither0(dither[0]); |
605 Sk4f dither1(dither[1]); | 605 Sk4f dither1(dither[1]); |
606 const Rec* rec = fRecs.begin(); | 606 const Rec* rec = fRecs.begin(); |
607 | 607 |
608 const Sk4f dx4 = Sk4f(dx); | 608 const Sk4f dx4 = Sk4f(dx); |
609 SkDEBUGCODE(SkPMColor* endDstC = dstC + count;) | 609 SkDEBUGCODE(SkPMColor* endDstC = dstC + count;) |
610 | 610 |
611 if (dx_is_pos) { | 611 if (dx_is_pos) { |
612 if (fx < 0) { | 612 if (fx < 0) { |
613 int n = SkTMin(SkFloatToIntFloor(-fx * invDx) + 1, count); | 613 // count is guaranteed to be positive, but the first arg may overflo
w int32 after |
| 614 // increment => casting to uint32 ensures correct clamping. |
| 615 int n = SkTMin<uint32_t>(SkFloatToIntFloor(-fx * invDx) + 1, count); |
| 616 SkASSERT(n > 0); |
614 fill<apply_alpha>(dstC, n, rec[0].fColor); | 617 fill<apply_alpha>(dstC, n, rec[0].fColor); |
615 count -= n; | 618 count -= n; |
616 dstC += n; | 619 dstC += n; |
617 fx += n * dx; | 620 fx += n * dx; |
618 SkASSERT(0 == count || fx >= 0); | 621 SkASSERT(0 == count || fx >= 0); |
619 if (n & 1) { | 622 if (n & 1) { |
620 SkTSwap(dither0, dither1); | 623 SkTSwap(dither0, dither1); |
621 } | 624 } |
622 } | 625 } |
623 } else { // dx < 0 | 626 } else { // dx < 0 |
624 if (fx > 1) { | 627 if (fx > 1) { |
625 int n = SkTMin(SkFloatToIntFloor((1 - fx) * invDx) + 1, count); | 628 // count is guaranteed to be positive, but the first arg may overflo
w int32 after |
| 629 // increment => casting to uint32 ensures correct clamping. |
| 630 int n = SkTMin<uint32_t>(SkFloatToIntFloor((1 - fx) * invDx) + 1, co
unt); |
| 631 SkASSERT(n > 0); |
626 fill<apply_alpha>(dstC, n, rec[fRecs.count() - 1].fColor); | 632 fill<apply_alpha>(dstC, n, rec[fRecs.count() - 1].fColor); |
627 count -= n; | 633 count -= n; |
628 dstC += n; | 634 dstC += n; |
629 fx += n * dx; | 635 fx += n * dx; |
630 SkASSERT(0 == count || fx <= 1); | 636 SkASSERT(0 == count || fx <= 1); |
631 if (n & 1) { | 637 if (n & 1) { |
632 SkTSwap(dither0, dither1); | 638 SkTSwap(dither0, dither1); |
633 } | 639 } |
634 } | 640 } |
635 } | 641 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe
r); | 752 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe
r); |
747 } | 753 } |
748 } else { | 754 } else { |
749 if (fApplyAlphaAfterInterp) { | 755 if (fApplyAlphaAfterInterp) { |
750 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); | 756 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe
r); |
751 } else { | 757 } else { |
752 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); | 758 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith
er); |
753 } | 759 } |
754 } | 760 } |
755 } | 761 } |
OLD | NEW |