From a8790debaab6c5e3b6a4a51d2cc91ae5aea9b2dd Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 24 Oct 2012 21:04:04 +0000 Subject: [PATCH] If a path is known to be nonfinite, don't forget that in our autobounds helper. "Once a non-finite, always a non-finite". Inspired by crbug/157157 Review URL: https://codereview.appspot.com/6764047 git-svn-id: http://skia.googlecode.com/svn/trunk@6087 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkPath.cpp | 4 +++- tests/PathTest.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 343350b..6d055f5 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -157,7 +157,9 @@ private: // returns true if we should proceed void init(SkPath* path) { fPath = path; - fDirty = SkToBool(path->fBoundsIsDirty); + // Mark the path's bounds as dirty if (1) they are, or (2) the path + // is non-finite, and therefore its bounds are not meaningful + fDirty = SkToBool(path->fBoundsIsDirty) || !path->fIsFinite; fDegenerate = is_degenerate(*path); fEmpty = path->isEmpty(); // Cannot use fRect for our bounds unless we know it is sorted diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index cfad5d6..d13f3f6 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -25,6 +25,27 @@ static SkSurface* new_surface(int w, int h) { return SkSurface::NewRaster(info, NULL); } +// Make sure we stay non-finite once we get there (unless we reset or rewind). +static void test_addrect_isfinite(skiatest::Reporter* reporter) { + SkPath path; + + path.addRect(SkRect::MakeWH(50, 100)); + REPORTER_ASSERT(reporter, path.isFinite()); + + path.moveTo(0, 0); + path.lineTo(SK_ScalarInfinity, 42); + REPORTER_ASSERT(reporter, !path.isFinite()); + + path.addRect(SkRect::MakeWH(50, 100)); + REPORTER_ASSERT(reporter, !path.isFinite()); + + path.reset(); + REPORTER_ASSERT(reporter, path.isFinite()); + + path.addRect(SkRect::MakeWH(50, 100)); + REPORTER_ASSERT(reporter, path.isFinite()); +} + // Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/ // which triggered an assert, from a tricky cubic. This test replicates that // example, so we can ensure that we handle it (in SkEdge.cpp), and don't @@ -1718,6 +1739,7 @@ static void TestPath(skiatest::Reporter* reporter) { test_tricky_cubic(reporter); test_arb_round_rect_is_convex(reporter); test_arb_zero_rad_round_rect_is_rect(reporter); + test_addrect_isfinite(reporter); } #include "TestClassDef.h" -- 2.7.4