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

Side by Side Diff: src/gpu/GrOvalRenderer.cpp

Issue 231093002: Do div-by-zero check for all gpus in ellipse/rr effects. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/gpu/effects/GrOvalEffect.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 2013 Google Inc. 2 * Copyright 2013 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 "GrOvalRenderer.h" 8 #include "GrOvalRenderer.h"
9 9
10 #include "GrEffect.h" 10 #include "GrEffect.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, & fsRadiiName); 223 builder->addVarying(kVec4f_GrSLType, "EllipseRadii", &vsRadiiName, & fsRadiiName);
224 const SkString* attr1Name = 224 const SkString* attr1Name =
225 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]); 225 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]);
226 builder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str ()); 226 builder->vsCodeAppendf("\t%s = %s;\n", vsRadiiName, attr1Name->c_str ());
227 227
228 // for outer curve 228 // for outer curve
229 builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset Name, fsRadiiName); 229 builder->fsCodeAppendf("\tvec2 scaledOffset = %s*%s.xy;\n", fsOffset Name, fsRadiiName);
230 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n"); 230 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n");
231 builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs RadiiName); 231 builder->fsCodeAppendf("\tvec2 grad = 2.0*scaledOffset*%s.xy;\n", fs RadiiName);
232 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n"); 232 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n");
233 // we need to clamp the length^2 of the gradiant vector to a non-zer o value, because 233 // avoid calling inversesqrt on zero.
234 // on the Nexus 4 the undefined result of inversesqrt(0) drops out a n entire tile 234 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n");
235 if (builder->ctxInfo().caps()->dropsTileOnZeroDivide()) {
236 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n");
237 }
238 builder->fsCodeAppend("\tfloat invlen = inversesqrt(grad_dot);\n"); 235 builder->fsCodeAppend("\tfloat invlen = inversesqrt(grad_dot);\n");
239 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0. 0, 1.0);\n"); 236 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen, 0. 0, 1.0);\n");
240 237
241 // for inner curve 238 // for inner curve
242 if (ellipseEffect.isStroked()) { 239 if (ellipseEffect.isStroked()) {
243 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN ame, fsRadiiName); 240 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN ame, fsRadiiName);
244 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset) - 1.0;\n"); 241 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset) - 1.0;\n");
245 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR adiiName); 242 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR adiiName);
246 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\ n"); 243 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\ n");
247 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0 , 1.0);\n"); 244 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0 , 1.0);\n");
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // for outer curve 369 // for outer curve
373 builder->fsCodeAppendf("\tvec2 scaledOffset = %s.xy;\n", fsOffsetNam e0); 370 builder->fsCodeAppendf("\tvec2 scaledOffset = %s.xy;\n", fsOffsetNam e0);
374 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n"); 371 builder->fsCodeAppend("\tfloat test = dot(scaledOffset, scaledOffset ) - 1.0;\n");
375 builder->fsCodeAppendf("\tvec2 duvdx = dFdx(%s);\n", fsOffsetName0); 372 builder->fsCodeAppendf("\tvec2 duvdx = dFdx(%s);\n", fsOffsetName0);
376 builder->fsCodeAppendf("\tvec2 duvdy = dFdy(%s);\n", fsOffsetName0); 373 builder->fsCodeAppendf("\tvec2 duvdy = dFdy(%s);\n", fsOffsetName0);
377 builder->fsCodeAppendf("\tvec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s .y*duvdx.y,\n" 374 builder->fsCodeAppendf("\tvec2 grad = vec2(2.0*%s.x*duvdx.x + 2.0*%s .y*duvdx.y,\n"
378 "\t 2.0*%s.x*duvdy.x + 2.0*%s .y*duvdy.y);\n", 375 "\t 2.0*%s.x*duvdy.x + 2.0*%s .y*duvdy.y);\n",
379 fsOffsetName0, fsOffsetName0, fsOffsetName0, fsOffsetName0); 376 fsOffsetName0, fsOffsetName0, fsOffsetName0, fsOffsetName0);
380 377
381 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n"); 378 builder->fsCodeAppend("\tfloat grad_dot = dot(grad, grad);\n");
382 // we need to clamp the length^2 of the gradiant vector to a non-zer o value, because 379 // avoid calling inversesqrt on zero.
383 // on the Nexus 4 the undefined result of inversesqrt(0) drops out a n entire tile 380 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n");
384 if (builder->ctxInfo().caps()->dropsTileOnZeroDivide()) {
385 builder->fsCodeAppend("\tgrad_dot = max(grad_dot, 1.0e-4);\n");
386 }
387 builder->fsCodeAppend("\tfloat invlen = inversesqrt(grad_dot);\n"); 381 builder->fsCodeAppend("\tfloat invlen = inversesqrt(grad_dot);\n");
388 if (kHairline == ellipseEffect.getMode()) { 382 if (kHairline == ellipseEffect.getMode()) {
389 // can probably do this with one step 383 // can probably do this with one step
390 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(1.0-test*invlen , 0.0, 1.0);\n"); 384 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(1.0-test*invlen , 0.0, 1.0);\n");
391 builder->fsCodeAppend("\tedgeAlpha *= clamp(1.0+test*invlen, 0.0 , 1.0);\n"); 385 builder->fsCodeAppend("\tedgeAlpha *= clamp(1.0+test*invlen, 0.0 , 1.0);\n");
392 } else { 386 } else {
393 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen , 0.0, 1.0);\n"); 387 builder->fsCodeAppend("\tfloat edgeAlpha = clamp(0.5-test*invlen , 0.0, 1.0);\n");
394 } 388 }
395 389
396 // for inner curve 390 // for inner curve
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 1134 }
1141 1135
1142 // drop out the middle quad if we're stroked 1136 // drop out the middle quad if we're stroked
1143 int indexCnt = isStroked ? SK_ARRAY_COUNT(gRRectIndices)-6 : SK_ARRAY_CO UNT(gRRectIndices); 1137 int indexCnt = isStroked ? SK_ARRAY_COUNT(gRRectIndices)-6 : SK_ARRAY_CO UNT(gRRectIndices);
1144 target->setIndexSourceToBuffer(indexBuffer); 1138 target->setIndexSourceToBuffer(indexBuffer);
1145 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds); 1139 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou nds);
1146 } 1140 }
1147 1141
1148 return true; 1142 return true;
1149 } 1143 }
OLDNEW
« no previous file with comments | « no previous file | src/gpu/effects/GrOvalEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698