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

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

Issue 1692683003: Put back the 0.5 bias in the shader. Only adjust the radii for the geometry, not the radii constant… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 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 "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // for outer curve 290 // for outer curve
291 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(), 291 fragBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOff sets.fsIn(),
292 ellipseRadii.fsIn()); 292 ellipseRadii.fsIn());
293 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;"); 293 fragBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset ) - 1.0;");
294 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli pseRadii.fsIn()); 294 fragBuilder->codeAppendf("vec2 grad = 2.0*scaledOffset*%s.xy;", elli pseRadii.fsIn());
295 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);"); 295 fragBuilder->codeAppend("float grad_dot = dot(grad, grad);");
296 296
297 // avoid calling inversesqrt on zero. 297 // avoid calling inversesqrt on zero.
298 fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);"); 298 fragBuilder->codeAppend("grad_dot = max(grad_dot, 1.0e-4);");
299 fragBuilder->codeAppend("float invlen = inversesqrt(grad_dot);"); 299 fragBuilder->codeAppend("float invlen = inversesqrt(grad_dot);");
300 fragBuilder->codeAppend("float edgeAlpha = clamp(-test*invlen, 0.0, 1.0);"); 300 fragBuilder->codeAppend("float edgeAlpha = clamp(0.5-test*invlen, 0. 0, 1.0);");
301 301
302 // for inner curve 302 // for inner curve
303 if (ee.isStroked()) { 303 if (ee.isStroked()) {
304 fragBuilder->codeAppendf("scaledOffset = %s*%s.zw;", 304 fragBuilder->codeAppendf("scaledOffset = %s*%s.zw;",
305 ellipseOffsets.fsIn(), ellipseRadii.fsI n()); 305 ellipseOffsets.fsIn(), ellipseRadii.fsI n());
306 fragBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;"); 306 fragBuilder->codeAppend("test = dot(scaledOffset, scaledOffset) - 1.0;");
307 fragBuilder->codeAppendf("grad = 2.0*scaledOffset*%s.zw;", 307 fragBuilder->codeAppendf("grad = 2.0*scaledOffset*%s.zw;",
308 ellipseRadii.fsIn()); 308 ellipseRadii.fsIn());
309 fragBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));" ); 309 fragBuilder->codeAppend("invlen = inversesqrt(dot(grad, grad));" );
310 fragBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0 , 1.0);"); 310 fragBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0 , 1.0);");
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 innerYRadius = yRadius - scaledStroke.fY; 1074 innerYRadius = yRadius - scaledStroke.fY;
1075 } 1075 }
1076 1076
1077 xRadius += scaledStroke.fX; 1077 xRadius += scaledStroke.fX;
1078 yRadius += scaledStroke.fY; 1078 yRadius += scaledStroke.fY;
1079 } 1079 }
1080 1080
1081 // We've extended the outer x radius out half a pixel to antialias. 1081 // We've extended the outer x radius out half a pixel to antialias.
1082 // This will also expand the rect so all the pixels will be captured. 1082 // This will also expand the rect so all the pixels will be captured.
1083 // TODO: Consider if we should use sqrt(2)/2 instead 1083 // TODO: Consider if we should use sqrt(2)/2 instead
1084 xRadius += SK_ScalarHalf; 1084 SkScalar geoXRadius = xRadius + SK_ScalarHalf;
1085 yRadius += SK_ScalarHalf; 1085 SkScalar geoYRadius = yRadius + SK_ScalarHalf;
1086 1086
1087 EllipseBatch::Geometry geometry; 1087 EllipseBatch::Geometry geometry;
1088 geometry.fViewMatrix = viewMatrix; 1088 geometry.fViewMatrix = viewMatrix;
1089 geometry.fColor = color; 1089 geometry.fColor = color;
1090 geometry.fXRadius = xRadius; 1090 geometry.fXRadius = xRadius;
1091 geometry.fYRadius = yRadius; 1091 geometry.fYRadius = yRadius;
1092 geometry.fInnerXRadius = innerXRadius; 1092 geometry.fInnerXRadius = innerXRadius;
1093 geometry.fInnerYRadius = innerYRadius; 1093 geometry.fInnerYRadius = innerYRadius;
1094 geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; 1094 geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0;
1095 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad ius, 1095 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - geoXRadius, center.fY - g eoYRadius,
1096 center.fX + xRadius, center.fY + yRad ius); 1096 center.fX + geoXRadius, center.fY + g eoYRadius);
1097 1097
1098 return EllipseBatch::Create(geometry); 1098 return EllipseBatch::Create(geometry);
1099 } 1099 }
1100 1100
1101 bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, 1101 bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target,
1102 const GrPipelineBuilder& pipelineBuilder, 1102 const GrPipelineBuilder& pipelineBuilder,
1103 GrColor color, 1103 GrColor color,
1104 const SkMatrix& viewMatrix, 1104 const SkMatrix& viewMatrix,
1105 bool useCoverageAA, 1105 bool useCoverageAA,
1106 const SkRect& ellipse, 1106 const SkRect& ellipse,
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 } 2058 }
2059 2059
2060 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 2060 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
2061 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 2061 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
2062 GrColor color = GrRandomColor(random); 2062 GrColor color = GrRandomColor(random);
2063 const SkRRect& rrect = GrTest::TestRRectSimple(random); 2063 const SkRRect& rrect = GrTest::TestRRectSimple(random);
2064 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 2064 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
2065 } 2065 }
2066 2066
2067 #endif 2067 #endif
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