diff options
author | caryclark <caryclark@google.com> | 2016-08-23 09:41:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-23 09:41:00 -0700 |
commit | 3cebe24682ea8bea3bcab400ff1c79b8e0b12ff0 (patch) | |
tree | 35ba0cdb4abdd244c82f3006bcca22944fd14bac /src | |
parent | c966ef9f07eed89bd571e3f89f8eb86f73b9328f (diff) |
fix conic path fuzz
The test conic has a very large weight, so it reduces to a pair
of lines. Detect this case rather than subdividing the conic
so much that the answers are meaningless.
R=herb@google.com, reed@google.com
BUG=638223
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2268073004
Review-Url: https://codereview.chromium.org/2268073004
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkGeometry.cpp | 18 | ||||
-rw-r--r-- | src/core/SkGeometry.h | 4 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp index 7dd5359b7d..03a63b2bda 100644 --- a/src/core/SkGeometry.cpp +++ b/src/core/SkGeometry.cpp @@ -1170,10 +1170,24 @@ static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { int SkConic::chopIntoQuadsPOW2(SkPoint pts[], int pow2) const { SkASSERT(pow2 >= 0); + *pts = fPts[0]; + SkDEBUGCODE(SkPoint* endPts); + if (pow2 == kMaxConicToQuadPOW2) { // If an extreme weight generates many quads ... + SkConic dst[2]; + this->chop(dst); + // check to see if the first chop generates a pair of lines + if (dst[0].fPts[1] == dst[0].fPts[2] && dst[1].fPts[0] == dst[1].fPts[1]) { + pts[1] = pts[2] = pts[3] = dst[0].fPts[1]; // set ctrl == end to make lines + pts[4] = dst[1].fPts[2]; + pow2 = 1; + SkDEBUGCODE(endPts = &pts[5]); + goto commonFinitePtCheck; + } + } + SkDEBUGCODE(endPts = ) subdivide(*this, pts + 1, pow2); +commonFinitePtCheck: const int quadCount = 1 << pow2; const int ptCount = 2 * quadCount + 1; - *pts = fPts[0]; - SkDEBUGCODE(SkPoint* endPts =) subdivide(*this, pts + 1, pow2); SkASSERT(endPts - pts == ptCount); if (!SkPointsAreFinite(pts, ptCount)) { // if we generated a non-finite, pin ourselves to the middle of the hull, diff --git a/src/core/SkGeometry.h b/src/core/SkGeometry.h index 15f1e55195..74c9d89e3f 100644 --- a/src/core/SkGeometry.h +++ b/src/core/SkGeometry.h @@ -235,7 +235,7 @@ struct SkConic { * Chop this conic into N quads, stored continguously in pts[], where * N = 1 << pow2. The amount of storage needed is (1 + 2 * N) */ - int chopIntoQuadsPOW2(SkPoint pts[], int pow2) const; + int SK_WARN_UNUSED_RESULT chopIntoQuadsPOW2(SkPoint pts[], int pow2) const; bool findXExtrema(SkScalar* t) const; bool findYExtrema(SkScalar* t) const; @@ -384,7 +384,7 @@ public: int pow2 = conic.computeQuadPOW2(tol); fQuadCount = 1 << pow2; SkPoint* pts = fStorage.reset(1 + 2 * fQuadCount); - conic.chopIntoQuadsPOW2(pts, pow2); + fQuadCount = conic.chopIntoQuadsPOW2(pts, pow2); return pts; } |