Improve the curve tessellation subdivision of the path renderers.
The stencil-and-cover and tessellating path renderers currently
tessellate curves to linear segments to within one screen space pixel.
This is fairly poor accuracy, as can be seen from the strokecircle GM:
there are noticeable rotating bumps on the circles.
Improving the tolerance to 0.25 pixel eliminates the bumps, and
approximates the 16x supersampling of the raster path.
This does have a performance hit: 3-6% on desktop on
the IE chalkboard demo, ~1% on Nexus 7 2013.
Note: this will require rebaselining a number of GPU and MSAA images
in Skia, but nothing in Chrome (yet).
BUG=skia:3731
Review URL: https://codereview.chromium.org/1072273007
diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp
index 531b5e5..65daa7c 100644
--- a/src/gpu/GrDefaultPathRenderer.cpp
+++ b/src/gpu/GrDefaultPathRenderer.cpp
@@ -658,7 +658,7 @@
}
}
- SkScalar tol = SK_Scalar1;
+ SkScalar tol = GrPathUtils::kDefaultTolerance;
SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds());
SkRect devBounds;
diff --git a/src/gpu/GrPathUtils.h b/src/gpu/GrPathUtils.h
index c15fd7a..250b0a2 100644
--- a/src/gpu/GrPathUtils.h
+++ b/src/gpu/GrPathUtils.h
@@ -168,5 +168,12 @@
// If you transform the points the lines will also need to be transformed. This can be done
// by mapping the lines with the inverse-transpose of the matrix used to map the points.
void getCubicKLM(const SkPoint p[4], SkScalar klm[9]);
+
+ // When tessellating curved paths into linear segments, this defines the maximum distance
+ // in screen space which a segment may deviate from the mathmatically correct value.
+ // Above this value, the segment will be subdivided.
+ // This value was chosen to approximate the supersampling accuracy of the raster path (16
+ // samples, or one quarter pixel).
+ static const SkScalar kDefaultTolerance = SkDoubleToScalar(0.25);
};
#endif
diff --git a/src/gpu/GrTessellatingPathRenderer.cpp b/src/gpu/GrTessellatingPathRenderer.cpp
index c80b693..1c1663d 100644
--- a/src/gpu/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/GrTessellatingPathRenderer.cpp
@@ -1392,7 +1392,8 @@
c.sweep_lt = sweep_lt_vert;
c.sweep_gt = sweep_gt_vert;
}
- SkScalar tol = GrPathUtils::scaleToleranceToSrc(SK_Scalar1, fViewMatrix, pathBounds);
+ SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance;
+ SkScalar tol = GrPathUtils::scaleToleranceToSrc(screenSpaceTol, fViewMatrix, pathBounds);
int contourCnt;
int maxPts = GrPathUtils::worstCasePointCount(fPath, &contourCnt, tol);
if (maxPts <= 0) {