aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkStroke.h
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2014-10-09 05:36:03 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-09 05:36:04 -0700
commitfeff7d2d7719f52c7ea52db156003e609002bf04 (patch)
tree556123b8794cb89b42bb2a37f8312d910175c728 /src/core/SkStroke.h
parent5867736b08d3689356b49f505bcf748c2194a0bc (diff)
Draw more accurate thick-stroked Beziers (disabled)
Draw thick-stroked Beziers by computing the outset quadratic, measuring the error, and subdividing until the error is within a predetermined limit. To try this CL out, change src/core/SkStroke.h:18 to #define QUAD_STROKE_APPROXIMATION 1 or from the command line: CPPFLAGS="-D QUAD_STROKE_APPROXIMATION=1" ./gyp_skia Here's what's in this CL: bench/BezierBench.cpp : a microbench for examining where the time is going gm/beziers.cpp : random Beziers with various thicknesses gm/smallarc.cpp : a distillation of bug skia:2769 samplecode/SampleRotateCircles.cpp : controls added for error, limit, width src/core/SkStroke.cpp : the new stroke implementation (disabled) tests/StrokerTest.cpp : a stroke torture test that checks normal and extreme values The new stroke algorithm has a tweakable parameter: stroker.setError(1); (SkStrokeRec.cpp:112) The stroke error is the allowable gap between the midpoint of the stroke quadratic and the center Bezier. As the projection from the quadratic approaches the endpoints, the error is decreased proportionally so that it is always inside the quadratic curve. An overview of how this works: - For a given T range of a Bezier, compute the perpendiculars and find the points outset and inset for some radius. - Construct tangents for the quadratic stroke. - If the tangent don't intersect between them (may happen with cubics), subdivide. - If the quadratic stroke end points are close (again, may happen with cubics), draw a line between them. - Compute the quadratic formed by the intersecting tangents. - If the midpoint of the quadratic is close to the midpoint of the Bezier perpendicular, return the quadratic. - If the end of the stroke at the Bezier midpoint doesn't intersect the quad's bounds, subdivide. - Find where the Bezier midpoint ray intersects the quadratic. - If the intersection is too close to the quad's endpoints, subdivide. - If the error is large proportional to the intersection's distance to the quad's endpoints, subdivide. BUG=skia:723,skia:2769 Review URL: https://codereview.chromium.org/558163005
Diffstat (limited to 'src/core/SkStroke.h')
-rw-r--r--src/core/SkStroke.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/SkStroke.h b/src/core/SkStroke.h
index a6a9f08331..cb329399a9 100644
--- a/src/core/SkStroke.h
+++ b/src/core/SkStroke.h
@@ -11,6 +11,19 @@
#include "SkPath.h"
#include "SkPoint.h"
#include "SkPaint.h"
+#include "SkStrokerPriv.h"
+
+// set to 1 to use experimental outset stroking with quads
+#ifndef QUAD_STROKE_APPROXIMATION
+#define QUAD_STROKE_APPROXIMATION 0
+#endif
+
+#if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
+extern bool gDebugStrokerErrorSet;
+extern SkScalar gDebugStrokerError;
+
+extern int gMaxRecursion[];
+#endif
/** \class SkStroke
SkStroke is the utility class that constructs paths by stroking
@@ -30,6 +43,9 @@ public:
SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; }
void setJoin(SkPaint::Join);
+#if QUAD_STROKE_APPROXIMATION
+ void setError(SkScalar);
+#endif
void setMiterLimit(SkScalar);
void setWidth(SkScalar);
@@ -46,6 +62,9 @@ public:
////////////////////////////////////////////////////////////////
private:
+#if QUAD_STROKE_APPROXIMATION
+ SkScalar fError;
+#endif
SkScalar fWidth, fMiterLimit;
uint8_t fCap, fJoin;
SkBool8 fDoFill;