flush to zero tiny radii
Bug: 850350
Change-Id: If1f8efdb02782d520195a6b66bd159628c89f811
Reviewed-on: https://skia-review.googlesource.com/137220
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Auto-Submit: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp
index 01e76d5..6a6b24b 100644
--- a/src/core/SkRRect.cpp
+++ b/src/core/SkRRect.cpp
@@ -173,8 +173,20 @@
return true;
}
-void SkRRect::scaleRadii(const SkRect& rect) {
+// If we can't distinguish one of the radii relative to the other, force it to zero so it
+// doesn't confuse us later. See crbug.com/850350
+//
+static void flush_to_zero(SkScalar& a, SkScalar& b) {
+ SkASSERT(a >= 0);
+ SkASSERT(b >= 0);
+ if (a + b == a) {
+ b = 0;
+ } else if (a + b == b) {
+ a = 0;
+ }
+}
+void SkRRect::scaleRadii(const SkRect& rect) {
// Proportionally scale down all radii to fit. Find the minimum ratio
// of a side and the radii on that side (for all four sides) and use
// that to scale down _all_ the radii. This algorithm is from the
@@ -195,6 +207,11 @@
scale = compute_min_scale(fRadii[2].fX, fRadii[3].fX, width, scale);
scale = compute_min_scale(fRadii[3].fY, fRadii[0].fY, height, scale);
+ flush_to_zero(fRadii[0].fX, fRadii[1].fX);
+ flush_to_zero(fRadii[1].fY, fRadii[2].fY);
+ flush_to_zero(fRadii[2].fX, fRadii[3].fX);
+ flush_to_zero(fRadii[3].fY, fRadii[0].fY);
+
if (scale < 1.0) {
SkScaleToSides::AdjustRadii(width, scale, &fRadii[0].fX, &fRadii[1].fX);
SkScaleToSides::AdjustRadii(height, scale, &fRadii[1].fY, &fRadii[2].fY);
diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp
index cdfb2b1..0b8872a 100644
--- a/tests/RegionTest.cpp
+++ b/tests/RegionTest.cpp
@@ -444,7 +444,7 @@
rgn.setPath(path, SkRegion(ir));
}
-DEF_TEST(rrect_region, reporter) {
+DEF_TEST(rrect_region_crbug_850350, reporter) {
SkMatrix m;
m.reset();
m[1] = 0.753662348f;
@@ -464,9 +464,6 @@
path.transform(m);
SkRegion rgn;
- if (false) {
- // this assserts in the debug build. see crbug.com/850350
- rgn.setPath(path, SkRegion{SkIRect{0, 0, 24, 24}});
- }
+ rgn.setPath(path, SkRegion{SkIRect{0, 0, 24, 24}});
}