diff options
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/src/GrPathUtils.cpp | 49 | ||||
-rw-r--r-- | gpu/src/GrPathUtils.h | 9 |
2 files changed, 42 insertions, 16 deletions
diff --git a/gpu/src/GrPathUtils.cpp b/gpu/src/GrPathUtils.cpp index e7c404c006..e78bc54abf 100644 --- a/gpu/src/GrPathUtils.cpp +++ b/gpu/src/GrPathUtils.cpp @@ -18,11 +18,17 @@ #include "GrPoint.h" static const int MAX_POINTS_PER_CURVE = 1 << 10; +const GrScalar GrPathUtils::gMinCurveTol (GrFloatToScalar(0.0001f)); uint32_t GrPathUtils::quadraticPointCount(const GrPoint points[], - GrScalar tol) { + GrScalar tol) { + if (tol < gMinCurveTol) { + tol == gMinCurveTol; + } + GrAssert(tol > 0); + GrScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); - if (d < tol) { + if (d <= tol) { return 1; } else { // Each time we subdivide, d should be cut in 4. So we need to @@ -42,11 +48,11 @@ uint32_t GrPathUtils::quadraticPointCount(const GrPoint points[], } uint32_t GrPathUtils::generateQuadraticPoints(const GrPoint& p0, - const GrPoint& p1, - const GrPoint& p2, - GrScalar tolSqd, - GrPoint** points, - uint32_t pointsLeft) { + const GrPoint& p1, + const GrPoint& p2, + GrScalar tolSqd, + GrPoint** points, + uint32_t pointsLeft) { if (pointsLeft < 2 || (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) { (*points)[0] = p2; @@ -68,10 +74,16 @@ uint32_t GrPathUtils::generateQuadraticPoints(const GrPoint& p0, uint32_t GrPathUtils::cubicPointCount(const GrPoint points[], GrScalar tol) { - GrScalar d = GrMax(points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), - points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); + if (tol < gMinCurveTol) { + tol == gMinCurveTol; + } + GrAssert(tol > 0); + + GrScalar d = GrMax( + points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), + points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); d = SkScalarSqrt(d); - if (d < tol) { + if (d <= tol) { return 1; } else { int temp = SkScalarCeil(SkScalarSqrt(SkScalarDiv(d, tol))); @@ -87,12 +99,12 @@ uint32_t GrPathUtils::cubicPointCount(const GrPoint points[], } uint32_t GrPathUtils::generateCubicPoints(const GrPoint& p0, - const GrPoint& p1, - const GrPoint& p2, - const GrPoint& p3, - GrScalar tolSqd, - GrPoint** points, - uint32_t pointsLeft) { + const GrPoint& p1, + const GrPoint& p2, + const GrPoint& p3, + GrScalar tolSqd, + GrPoint** points, + uint32_t pointsLeft) { if (pointsLeft < 2 || (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd && p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) { @@ -118,6 +130,11 @@ uint32_t GrPathUtils::generateCubicPoints(const GrPoint& p0, int GrPathUtils::worstCasePointCount(const GrPath& path, int* subpaths, GrScalar tol) { + if (tol < gMinCurveTol) { + tol == gMinCurveTol; + } + GrAssert(tol > 0); + int pointCount = 0; *subpaths = 1; diff --git a/gpu/src/GrPathUtils.h b/gpu/src/GrPathUtils.h index 9755db6bc5..80fee0a6e1 100644 --- a/gpu/src/GrPathUtils.h +++ b/gpu/src/GrPathUtils.h @@ -26,9 +26,13 @@ */ class GrPathUtils : public GrNoncopyable { public: + /// Since we divide by tol if we're computing exact worst-case bounds, + /// very small tolerances will be increased to gMinCurveTol. static int worstCasePointCount(const GrPath&, int* subpaths, GrScalar tol); + /// Since we divide by tol if we're computing exact worst-case bounds, + /// very small tolerances will be increased to gMinCurveTol. static uint32_t quadraticPointCount(const GrPoint points[], GrScalar tol); static uint32_t generateQuadraticPoints(const GrPoint& p0, const GrPoint& p1, @@ -36,6 +40,8 @@ public: GrScalar tolSqd, GrPoint** points, uint32_t pointsLeft); + /// Since we divide by tol if we're computing exact worst-case bounds, + /// very small tolerances will be increased to gMinCurveTol. static uint32_t cubicPointCount(const GrPoint points[], GrScalar tol); static uint32_t generateCubicPoints(const GrPoint& p0, const GrPoint& p1, @@ -44,5 +50,8 @@ public: GrScalar tolSqd, GrPoint** points, uint32_t pointsLeft); + +private: + static const GrScalar gMinCurveTol; }; #endif |