Fix radii calculation code to handle large radii.
BUG=472147
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1569403002
Review URL: https://codereview.chromium.org/1569403002
diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp
index 364a297..e9aa449 100644
--- a/tests/DrawPathTest.cpp
+++ b/tests/DrawPathTest.cpp
@@ -313,6 +313,39 @@
REPORTER_ASSERT(reporter, filteredPath.isEmpty());
}
+// http://crbug.com/472147
+// This is a simplified version from the bug. RRect radii not properly scaled.
+static void test_crbug_472147_simple(skiatest::Reporter* reporter) {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
+ SkCanvas* canvas = surface->getCanvas();
+ SkPaint p;
+ SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f);
+ SkVector radii[4] = {
+ { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0f }
+ };
+ SkRRect rr;
+ rr.setRectRadii(r, radii);
+ canvas->drawRRect(rr, p);
+}
+
+// http://crbug.com/472147
+// RRect radii not properly scaled.
+static void test_crbug_472147_actual(skiatest::Reporter* reporter) {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
+ SkCanvas* canvas = surface->getCanvas();
+ SkPaint p;
+ SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f);
+ SkVector radii[4] = {
+ { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0f }
+ };
+ SkRRect rr;
+ rr.setRectRadii(r, radii);
+ canvas->clipRRect(rr, SkRegion::kIntersect_Op, false);
+
+ SkRect r2 = SkRect::MakeLTRB(0, 33, 1102, 33554464);
+ canvas->drawRect(r2, p);
+}
+
DEF_TEST(DrawPath, reporter) {
test_giantaa();
test_bug533();
@@ -325,6 +358,8 @@
if (false) test_crbug131181();
test_infinite_dash(reporter);
test_crbug_165432(reporter);
+ test_crbug_472147_simple(reporter);
+ test_crbug_472147_actual(reporter);
test_big_aa_rect(reporter);
test_halfway();
}
diff --git a/tests/ScaleToSidesTest.cpp b/tests/ScaleToSidesTest.cpp
new file mode 100644
index 0000000..60e82be
--- /dev/null
+++ b/tests/ScaleToSidesTest.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkScaleToSides.h"
+
+#include <cfloat>
+#include "Test.h"
+
+DEF_TEST(ScaleToSides, reporter) {
+ float interestingValues[] = {
+ 0.0f,
+ 0.5f,
+ 1.0f,
+ 2.0f,
+ 3.0f,
+ 33.0f,
+ 33554430.0f,
+ 33554431.0f,
+ 33554464.0f,
+ 333333332.0f,
+ 333333333.0f,
+ 333333334.0f,
+ FLT_MAX,
+ FLT_EPSILON,
+ FLT_MIN
+ };
+
+ int numInterestingValues = (int)SK_ARRAY_COUNT(interestingValues);
+
+ for (int i = 0; i < numInterestingValues; i++) {
+ for (int j = 0; j < numInterestingValues; j++) {
+ for (int k = 0; k < numInterestingValues; k++) {
+ float radius1 = interestingValues[i];
+ float radius2 = interestingValues[j];
+ float width = interestingValues[k];
+ if (width > 0.0f) {
+ double scale = (double)width / ((double)radius1 + (double)radius2);
+ if (scale < 1.0) {
+ ScaleToSides::AdjustRadii(width, scale, &radius1, &radius2);
+ }
+ }
+ }
+ }
+ }
+}