Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: src/effects/gradients/SkLinearGradient.cpp

Issue 1556993003: fix linear gradient assert, by explicitly clamping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/GradientTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const float kInv255Float = 1.0f / 255; 10 static const float kInv255Float = 1.0f / 255;
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 const Sk4f dc = diffc * dx4 * Sk4f(scale); 661 const Sk4f dc = diffc * dx4 * Sk4f(scale);
662 662
663 int n; 663 int n;
664 if (dx_is_pos) { 664 if (dx_is_pos) {
665 n = SkTMin((int)((p1 - fx) * invDx) + 1, count); 665 n = SkTMin((int)((p1 - fx) * invDx) + 1, count);
666 } else { 666 } else {
667 n = SkTMin((int)((p0 - fx) * invDx) + 1, count); 667 n = SkTMin((int)((p0 - fx) * invDx) + 1, count);
668 } 668 }
669 669
670 fx += n * dx; 670 fx += n * dx;
671 count -= n; 671 // fx should now outside of the p0..p1 interval. However, due to float p recision loss,
672 SkASSERT(count >= 0); 672 // its possible that fx is slightly too small/large, so we clamp it.
673 if (dx_is_pos) { 673 if (dx_is_pos) {
674 SkASSERT(0 == count || fx >= p1); 674 fx = SkTMax(fx, p1);
675 } else { 675 } else {
676 SkASSERT(0 == count || fx <= p0); 676 fx = SkTMin(fx, p0);
677 } 677 }
678 678
679 ramp<apply_alpha>(dstC, n, c, dc, dither0, dither1); 679 ramp<apply_alpha>(dstC, n, c, dc, dither0, dither1);
680 dstC += n; 680 dstC += n;
681 SkASSERT(dstC <= endDstC); 681 SkASSERT(dstC <= endDstC);
682 682
683 if (n & 1) { 683 if (n & 1) {
684 SkTSwap(dither0, dither1); 684 SkTSwap(dither0, dither1);
685 } 685 }
686
687 count -= n;
688 SkASSERT(count >= 0);
686 } 689 }
687 } 690 }
688 691
689 void SkLinearGradient::LinearGradientContext::shade4_clamp(int x, int y, SkPMCol or dstC[], 692 void SkLinearGradient::LinearGradientContext::shade4_clamp(int x, int y, SkPMCol or dstC[],
690 int count) { 693 int count) {
691 SkASSERT(count > 0); 694 SkASSERT(count > 0);
692 SkASSERT(kLinear_MatrixClass == fDstToIndexClass); 695 SkASSERT(kLinear_MatrixClass == fDstToIndexClass);
693 696
694 SkPoint srcPt; 697 SkPoint srcPt;
695 fDstToIndexProc(fDstToIndex, x + SK_ScalarHalf, y + SK_ScalarHalf, &srcPt); 698 fDstToIndexProc(fDstToIndex, x + SK_ScalarHalf, y + SK_ScalarHalf, &srcPt);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 } 736 }
734 } else { 737 } else {
735 if (fApplyAlphaAfterInterp) { 738 if (fApplyAlphaAfterInterp) {
736 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r); 739 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r);
737 } else { 740 } else {
738 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er); 741 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er);
739 } 742 }
740 } 743 }
741 } 744 }
742 745
OLDNEW
« no previous file with comments | « no previous file | tests/GradientTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698