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

Side by Side Diff: src/effects/SkRRectsGaussianEdgeShader.cpp

Issue 2345203003: Improve join between the two RRects in SkRRectsGaussianEdgeShader (Closed)
Patch Set: Created 4 years, 3 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 | 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 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 "SkRRectsGaussianEdgeShader.h" 8 #include "SkRRectsGaussianEdgeShader.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 case kCircle_Mode: 119 case kCircle_Mode:
120 fragBuilder->codeAppendf("%s = clamp((%s.%c - length(delta))/%s, 0.0, 1.0);", 120 fragBuilder->codeAppendf("%s = clamp((%s.%c - length(delta))/%s, 0.0, 1.0);",
121 outputName, sizesName, indices[0], radN ame); 121 outputName, sizesName, indices[0], radN ame);
122 break; 122 break;
123 case kRect_Mode: 123 case kRect_Mode:
124 fragBuilder->codeAppendf( 124 fragBuilder->codeAppendf(
125 "vec2 rectDist = vec2(1.0 - clamp((%s.%c - abs(delta.x))/%s, 0.0, 1.0)," 125 "vec2 rectDist = vec2(1.0 - clamp((%s.%c - abs(delta.x))/%s, 0.0, 1.0),"
126 "1.0 - clamp((%s.%c - abs(delta.y))/%s, 0.0, 1.0));", 126 "1.0 - clamp((%s.%c - abs(delta.y))/%s, 0.0, 1.0));",
127 sizesName, indices[0], radName, 127 sizesName, indices[0], radName,
128 sizesName, indices[1], radName); 128 sizesName, indices[1], radName);
129 fragBuilder->codeAppendf("%s = 1.0 - length(rectDist);", outputN ame); 129 fragBuilder->codeAppendf("%s = clamp(1.0 - length(rectDist), 0.0 , 1.0);",
130 outputName);
130 break; 131 break;
131 case kSimpleCircular_Mode: 132 case kSimpleCircular_Mode:
132 // For the circular round rect we first compute the distance 133 // For the circular round rect we first compute the distance
133 // to the rect. Then we compute a multiplier that is 1 if the 134 // to the rect. Then we compute a multiplier that is 1 if the
134 // point is in one of the circular corners. We then compute the 135 // point is in one of the circular corners. We then compute the
135 // distance from the corner and then use the multiplier to mask 136 // distance from the corner and then use the multiplier to mask
136 // between the two distances. 137 // between the two distances.
137 fragBuilder->codeAppendf("float xDist = clamp((%s.%c - abs(delta .x))/%s," 138 fragBuilder->codeAppendf("float xDist = clamp((%s.%c - abs(delta .x))/%s,"
138 " 0.0, 1.0);", 139 " 0.0, 1.0);",
139 sizesName, indices[0], radName); 140 sizesName, indices[0], radName);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 radUniName, "firstDist", "xy"); 196 radUniName, "firstDist", "xy");
196 fragBuilder->codeAppend("}"); 197 fragBuilder->codeAppend("}");
197 198
198 fragBuilder->codeAppend("float secondDist;"); 199 fragBuilder->codeAppend("float secondDist;");
199 fragBuilder->codeAppend("{"); 200 fragBuilder->codeAppend("{");
200 this->emitModeCode(fp.secondMode(), fragBuilder, 201 this->emitModeCode(fp.secondMode(), fragBuilder,
201 positionsUniName, sizesUniName, radiiUniName, 202 positionsUniName, sizesUniName, radiiUniName,
202 radUniName, "secondDist", "zw"); 203 radUniName, "secondDist", "zw");
203 fragBuilder->codeAppend("}"); 204 fragBuilder->codeAppend("}");
204 205
205 fragBuilder->codeAppendf("float dist = %s * firstDist * secondDist;" , radUniName); 206 fragBuilder->codeAppend("vec2 distVec = vec2(1.0 - firstDist, 1.0 - secondDist);");
206 207
207 // Finally use the distance to apply the Gaussian edge 208 // Finally use the distance to apply the Gaussian edge
208 // TODO: we undo the multiply by the radius here - we should just sk ip both 209 fragBuilder->codeAppend("float factor = clamp(length(distVec), 0.0, 1.0);");
209 fragBuilder->codeAppendf("float factor = 1.0 - clamp(dist/%s, 0.0, 1 .0);", radUniName);
210 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01 8;"); 210 fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.01 8;");
211 fragBuilder->codeAppendf("%s = factor*%s;", 211 fragBuilder->codeAppendf("%s = factor*%s;",
212 args.fOutputColor, args.fInputColor); 212 args.fOutputColor, args.fInputColor);
213 } 213 }
214 214
215 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 215 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
216 GrProcessorKeyBuilder* b) { 216 GrProcessorKeyBuilder* b) {
217 const RRectsGaussianEdgeFP& fp = proc.cast<RRectsGaussianEdgeFP>(); 217 const RRectsGaussianEdgeFP& fp = proc.cast<RRectsGaussianEdgeFP>();
218 218
219 b->add32(fp.firstMode() | (fp.secondMode() << 4)); 219 b->add32(fp.firstMode() | (fp.secondMode() << 4));
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return sk_make_sp<SkRRectsGaussianEdgeShaderImpl>(first, second, radius); 420 return sk_make_sp<SkRRectsGaussianEdgeShaderImpl>(first, second, radius);
421 } 421 }
422 422
423 /////////////////////////////////////////////////////////////////////////////// 423 ///////////////////////////////////////////////////////////////////////////////
424 424
425 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkRRectsGaussianEdgeShader) 425 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkRRectsGaussianEdgeShader)
426 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRRectsGaussianEdgeShaderImpl) 426 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRRectsGaussianEdgeShaderImpl)
427 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 427 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
428 428
429 /////////////////////////////////////////////////////////////////////////////// 429 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698