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

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

Issue 2383863002: Fix precision issues in SkRRectsGaussianEdgeShader.cpp (Closed)
Patch Set: Fix typo Created 4 years, 2 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const char* radName, 110 const char* radName,
111 const char* outputName, 111 const char* outputName,
112 const char indices[2]) { // how to access the params for the 2 rrects 112 const char indices[2]) { // how to access the params for the 2 rrects
113 113
114 // positive distance is towards the center of the circle 114 // positive distance is towards the center of the circle
115 fragBuilder->codeAppendf("vec2 delta = %s.xy - %s.%s;", 115 fragBuilder->codeAppendf("vec2 delta = %s.xy - %s.%s;",
116 fragBuilder->fragmentPosition(), posName, i ndices); 116 fragBuilder->fragmentPosition(), posName, i ndices);
117 117
118 switch (mode) { 118 switch (mode) {
119 case kCircle_Mode: 119 case kCircle_Mode:
120 fragBuilder->codeAppendf("%s = clamp((%s.%c - length(delta))/%s, 0.0, 1.0);", 120 // When a shadow circle gets large we can have some precision is sues if
121 // we do "length(delta)/radius". The scaleDist temporary cuts th e
122 // delta vector down a bit before invoking length.
123 fragBuilder->codeAppendf("float scaledDist = length(delta/%s);", radName);
124 fragBuilder->codeAppendf("%s = clamp((%s.%c/%s - scaledDist), 0. 0, 1.0);",
121 outputName, sizesName, indices[0], radN ame); 125 outputName, sizesName, indices[0], radN ame);
122 break; 126 break;
123 case kRect_Mode: 127 case kRect_Mode:
124 fragBuilder->codeAppendf( 128 fragBuilder->codeAppendf(
125 "vec2 rectDist = vec2(1.0 - clamp((%s.%c - abs(delta.x))/%s, 0.0, 1.0)," 129 "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));", 130 "1.0 - clamp((%s.%c - abs(delta.y))/%s, 0.0, 1.0));",
127 sizesName, indices[0], radName, 131 sizesName, indices[0], radName,
128 sizesName, indices[1], radName); 132 sizesName, indices[1], radName);
129 fragBuilder->codeAppendf("%s = clamp(1.0 - length(rectDist), 0.0 , 1.0);", 133 fragBuilder->codeAppendf("%s = clamp(1.0 - length(rectDist), 0.0 , 1.0);",
130 outputName); 134 outputName);
131 break; 135 break;
132 case kSimpleCircular_Mode: 136 case kSimpleCircular_Mode:
133 // For the circular round rect we first compute the distance 137 // For the circular round rect we first compute the distance
134 // to the rect. Then we compute a multiplier that is 1 if the 138 // to the rect. Then we compute a multiplier that is 1 if the
135 // point is in one of the circular corners. We then compute the 139 // point is in one of the circular corners. We then compute the
136 // distance from the corner and then use the multiplier to mask 140 // distance from the corner and then use the multiplier to mask
137 // between the two distances. 141 // between the two distances.
138 fragBuilder->codeAppendf("float xDist = clamp((%s.%c - abs(delta .x))/%s," 142 fragBuilder->codeAppendf("float xDist = clamp((%s.%c - abs(delta .x))/%s,"
139 " 0.0, 1.0);", 143 "0.0, 1.0);",
140 sizesName, indices[0], radName); 144 sizesName, indices[0], radName);
141 fragBuilder->codeAppendf("float yDist = clamp((%s.%c - abs(delta .y))/%s," 145 fragBuilder->codeAppendf("float yDist = clamp((%s.%c - abs(delta .y))/%s,"
142 "0.0, 1.0);", 146 "0.0, 1.0);",
143 sizesName, indices[1], radName); 147 sizesName, indices[1], radName);
144 fragBuilder->codeAppend("float rectDist = min(xDist, yDist);"); 148 fragBuilder->codeAppend("float rectDist = min(xDist, yDist);");
145 149
146 fragBuilder->codeAppendf("vec2 cornerCenter = %s.%s - %s.%s;", 150 fragBuilder->codeAppendf("vec2 cornerCenter = %s.%s - %s.%s;",
147 sizesName, indices, radiiName, indices) ; 151 sizesName, indices, radiiName, indices) ;
148 fragBuilder->codeAppend("delta = vec2(abs(delta.x) - cornerCente r.x," 152 fragBuilder->codeAppend("delta = vec2(abs(delta.x) - cornerCente r.x,"
149 "abs(delta.y) - cornerCente r.y);"); 153 "abs(delta.y) - cornerCente r.y);");
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return sk_make_sp<SkRRectsGaussianEdgeShaderImpl>(first, second, radius); 424 return sk_make_sp<SkRRectsGaussianEdgeShaderImpl>(first, second, radius);
421 } 425 }
422 426
423 /////////////////////////////////////////////////////////////////////////////// 427 ///////////////////////////////////////////////////////////////////////////////
424 428
425 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkRRectsGaussianEdgeShader) 429 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkRRectsGaussianEdgeShader)
426 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRRectsGaussianEdgeShaderImpl) 430 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRRectsGaussianEdgeShaderImpl)
427 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 431 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
428 432
429 /////////////////////////////////////////////////////////////////////////////// 433 ///////////////////////////////////////////////////////////////////////////////
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