add conic support to hairlines
git-svn-id: http://skia.googlecode.com/svn/trunk/include@9493 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkGeometry.h b/core/SkGeometry.h
index 2c37fff..38cdf6e 100644
--- a/core/SkGeometry.h
+++ b/core/SkGeometry.h
@@ -251,4 +251,51 @@
void computeFastBounds(SkRect* bounds) const;
};
+#include "SkTemplates.h"
+
+/**
+ * Help class to allocate storage for approximating a conic with N quads.
+ */
+class SkAutoConicToQuads {
+public:
+ SkAutoConicToQuads() : fQuadCount(0) {}
+
+ /**
+ * Given a conic and a tolerance, return the array of points for the
+ * approximating quad(s). Call countQuads() to know the number of quads
+ * represented in these points.
+ *
+ * The quads are allocated to share end-points. e.g. if there are 4 quads,
+ * there will be 9 points allocated as follows
+ * quad[0] == pts[0..2]
+ * quad[1] == pts[2..4]
+ * quad[2] == pts[4..6]
+ * quad[3] == pts[6..8]
+ */
+ const SkPoint* computeQuads(const SkConic& conic, SkScalar tol) {
+ int pow2 = conic.computeQuadPOW2(tol);
+ fQuadCount = 1 << pow2;
+ SkPoint* pts = fStorage.reset(1 + 2 * fQuadCount);
+ conic.chopIntoQuadsPOW2(pts, pow2);
+ return pts;
+ }
+
+ const SkPoint* computeQuads(const SkPoint pts[3], SkScalar weight,
+ SkScalar tol) {
+ SkConic conic;
+ conic.set(pts, weight);
+ return computeQuads(conic, tol);
+ }
+
+ int countQuads() const { return fQuadCount; }
+
+private:
+ enum {
+ kQuadCount = 8, // should handle most conics
+ kPointCount = 1 + 2 * kQuadCount,
+ };
+ SkAutoSTMalloc<kPointCount, SkPoint> fStorage;
+ int fQuadCount; // #quads for current usage
+};
+
#endif
diff --git a/core/SkTemplates.h b/core/SkTemplates.h
index bbbed48..e8a8b61 100644
--- a/core/SkTemplates.h
+++ b/core/SkTemplates.h
@@ -366,7 +366,7 @@
}
// doesn't preserve contents
- void reset(size_t count) {
+ T* reset(size_t count) {
if (fPtr != fTStorage) {
sk_free(fPtr);
}
@@ -377,6 +377,7 @@
} else {
fPtr = NULL;
}
+ return fPtr;
}
T* get() const { return fPtr; }