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

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

Issue 1974463002: Harden linear gradients (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: remove unneeded 1-color veto Created 4 years, 7 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 | « src/effects/gradients/SkGradientShader.cpp ('k') | no next file » | 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 "Sk4fLinearGradient.h" 8 #include "Sk4fLinearGradient.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // 92 //
93 static uint32_t SkSwizzle_Color_to_PMColor(SkColor c) { 93 static uint32_t SkSwizzle_Color_to_PMColor(SkColor c) {
94 return SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), S kColorGetB(c)); 94 return SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), S kColorGetB(c));
95 } 95 }
96 96
97 SkLinearGradient::LinearGradientContext::LinearGradientContext( 97 SkLinearGradient::LinearGradientContext::LinearGradientContext(
98 const SkLinearGradient& shader, const ContextRec& ctx) 98 const SkLinearGradient& shader, const ContextRec& ctx)
99 : INHERITED(shader, ctx) 99 : INHERITED(shader, ctx)
100 { 100 {
101 // setup for Sk4f 101 // setup for Sk4f
102 int count = shader.fColorCount; 102 const int count = shader.fColorCount;
103 SkASSERT(count > 1);
104
103 fRecs.setCount(count); 105 fRecs.setCount(count);
104 Rec* rec = fRecs.begin(); 106 Rec* rec = fRecs.begin();
105 if (shader.fOrigPos) { 107 if (shader.fOrigPos) {
106 rec[0].fPos = 0; 108 rec[0].fPos = 0;
107 SkDEBUGCODE(rec[0].fPosScale = SK_FloatNaN;) // should never get used 109 SkDEBUGCODE(rec[0].fPosScale = SK_FloatNaN;) // should never get used
108 for (int i = 1; i < count; ++i) { 110 for (int i = 1; i < count; ++i) {
109 rec[i].fPos = SkTPin(shader.fOrigPos[i], rec[i - 1].fPos, 1.0f); 111 rec[i].fPos = SkTPin(shader.fOrigPos[i], rec[i - 1].fPos, 1.0f);
110 float diff = rec[i].fPos - rec[i - 1].fPos; 112 float diff = rec[i].fPos - rec[i - 1].fPos;
111 if (diff > 0) { 113 if (diff > 0) {
112 rec[i].fPosScale = 1.0f / diff; 114 rec[i].fPosScale = 1.0f / diff;
113 } else { 115 } else {
114 rec[i].fPosScale = 0; 116 rec[i].fPosScale = 0;
115 } 117 }
116 } 118 }
117 rec[count - 1].fPos = 1; // overwrite the last value just to be sure we end at 1.0
118 } else { 119 } else {
119 // no pos specified, so we compute evenly spaced values 120 // no pos specified, so we compute evenly spaced values
120 const float scale = float(count - 1); 121 const float scale = float(count - 1);
121 float invScale = 1.0f / scale; 122 const float invScale = 1.0f / scale;
122 for (int i = 0; i < count; ++i) { 123 for (int i = 0; i < count; ++i) {
123 rec[i].fPos = i * invScale; 124 rec[i].fPos = i * invScale;
124 rec[i].fPosScale = scale; 125 rec[i].fPosScale = scale;
125 } 126 }
126 } 127 }
128 rec[count - 1].fPos = 1; // overwrite the last value just to be sure we e nd at 1.0
127 129
128 fApplyAlphaAfterInterp = true; 130 fApplyAlphaAfterInterp = true;
129 if ((shader.getGradFlags() & SkGradientShader::kInterpolateColorsInPremul_Fl ag) || 131 if ((shader.getGradFlags() & SkGradientShader::kInterpolateColorsInPremul_Fl ag) ||
130 shader.colorsAreOpaque()) 132 shader.colorsAreOpaque())
131 { 133 {
132 fApplyAlphaAfterInterp = false; 134 fApplyAlphaAfterInterp = false;
133 } 135 }
134 136
135 if (fApplyAlphaAfterInterp) { 137 if (fApplyAlphaAfterInterp) {
136 // Our fColor values are in PMColor order, but are still unpremultiplied , allowing us to 138 // Our fColor values are in PMColor order, but are still unpremultiplied , allowing us to
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r); 746 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r);
745 } 747 }
746 } else { 748 } else {
747 if (fApplyAlphaAfterInterp) { 749 if (fApplyAlphaAfterInterp) {
748 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r); 750 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r);
749 } else { 751 } else {
750 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er); 752 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er);
751 } 753 }
752 } 754 }
753 } 755 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698