Scale the result of TightBounds when path was inverse-scaled
authorFredrik Söderquist <fs@opera.com>
Wed, 4 Jan 2017 12:31:47 +0000 (13:31 +0100)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 4 Jan 2017 13:47:24 +0000 (13:47 +0000)
When the path was "large" (as defined by ScaleFactor(...)), the computed
bounds would not be adjusted to the correct space. Make sure to scale
the result in those cases.

BUG=chromium:678162

Change-Id: Ia2eb94050c4620286e9abb69976dbc0202ecc307
Reviewed-on: https://skia-review.googlesource.com/6501
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Cary Clark <caryclark@google.com>

src/pathops/SkPathOpsTightBounds.cpp
tests/PathOpsTightBoundsTest.cpp

index d748ff5..f379c9e 100644 (file)
@@ -75,6 +75,10 @@ bool TightBounds(const SkPath& path, SkRect* result) {
     while ((current = current->next())) {
         bounds.add(current->bounds());
     }
+    if (scaleFactor > SK_Scalar1) {
+        bounds.set(bounds.left() * scaleFactor, bounds.top() * scaleFactor,
+                   bounds.right() * scaleFactor, bounds.bottom() * scaleFactor);
+    }
     *result = bounds;
     if (!moveBounds.isEmpty()) {
         result->join(moveBounds);
index 8fd0fdb..a2e7bca 100644 (file)
@@ -188,3 +188,14 @@ DEF_TEST(PathOpsTightBoundsIllBehaved, reporter) {
     REPORTER_ASSERT(reporter, bounds != tight);
 }
 
+DEF_TEST(PathOpsTightBoundsIllBehavedScaled, reporter) {
+    SkPath path;
+    path.moveTo(0, 0);
+    path.quadTo(1048578, 1048577, 1048576, 1048576);
+    const SkRect& bounds = path.getBounds();
+    SkRect tight;
+    REPORTER_ASSERT(reporter, TightBounds(path, &tight));
+    REPORTER_ASSERT(reporter, bounds != tight);
+    REPORTER_ASSERT(reporter, tight.right() == 1048576);
+    REPORTER_ASSERT(reporter, tight.bottom() == 1048576);
+}