aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu
diff options
context:
space:
mode:
authorGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-28 15:19:32 +0000
committerGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-28 15:19:32 +0000
commitc10a88825d119054a9f4e7b7af7a3f887e30ab6b (patch)
tree95adbf105cf13d71f94cb4bd4fd8905030e0651f /gpu
parent9ac4a89d35df3d581886a84df421161418707fd6 (diff)
Guard against 0 tolerance in curve subdivision.
git-svn-id: http://skia.googlecode.com/svn/trunk@1735 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu')
-rw-r--r--gpu/src/GrPathUtils.cpp49
-rw-r--r--gpu/src/GrPathUtils.h9
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