summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-11-02 17:04:54 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-11-02 17:04:54 +0100
commit1d55939c7ca0e80555a24b240ff68d5bdbb48b4a (patch)
tree523742dbbcedc854d5099759ab10afa99cdc2ce4
parentcc234ff4304d3a60dc2163f77a4214ecdbd88d5c (diff)
downloadUXP-1d55939c7ca0e80555a24b240ff68d5bdbb48b4a.tar
UXP-1d55939c7ca0e80555a24b240ff68d5bdbb48b4a.tar.gz
UXP-1d55939c7ca0e80555a24b240ff68d5bdbb48b4a.tar.lz
UXP-1d55939c7ca0e80555a24b240ff68d5bdbb48b4a.tar.xz
UXP-1d55939c7ca0e80555a24b240ff68d5bdbb48b4a.zip
Backport some upstream Skia patches.
Backport of: https://skia.googlesource.com/skia/+/1e259cda4fb7f12e98dd611bd651f40ebef2d14a https://skia.googlesource.com/skia/+/73be50da2a1fe8944f2623a511fda1957eed708a
-rw-r--r--gfx/skia/skia/src/core/SkGeometry.cpp32
-rw-r--r--gfx/skia/skia/src/core/SkRRect.cpp18
2 files changed, 38 insertions, 12 deletions
diff --git a/gfx/skia/skia/src/core/SkGeometry.cpp b/gfx/skia/skia/src/core/SkGeometry.cpp
index 58b45140e..9af6eb774 100644
--- a/gfx/skia/skia/src/core/SkGeometry.cpp
+++ b/gfx/skia/skia/src/core/SkGeometry.cpp
@@ -62,6 +62,15 @@ static int valid_unit_divide(SkScalar numer, SkScalar denom, SkScalar* ratio) {
return 1;
}
+// Just returns its argument, but makes it easy to set a break-point to know when
+// SkFindUnitQuadRoots is going to return 0 (an error).
+static int return_check_zero(int value) {
+ if (value == 0) {
+ return 0;
+ }
+ return value;
+}
+
/** From Numerical Recipes in C.
Q = -1/2 (B + sign(B) sqrt[B*B - 4*A*C])
@@ -72,22 +81,21 @@ int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]) {
SkASSERT(roots);
if (A == 0) {
- return valid_unit_divide(-C, B, roots);
+ return return_check_zero(valid_unit_divide(-C, B, roots));
}
SkScalar* r = roots;
- SkScalar R = B*B - 4*A*C;
- if (R < 0 || !SkScalarIsFinite(R)) { // complex roots
- // if R is infinite, it's possible that it may still produce
- // useful results if the operation was repeated in doubles
- // the flipside is determining if the more precise answer
- // isn't useful because surrounding machinery (e.g., subtracting
- // the axis offset from C) already discards the extra precision
- // more investigation and unit tests required...
- return 0;
+ // use doubles so we don't overflow temporarily trying to compute R
+ double dr = (double)B * B - 4 * (double)A * C;
+ if (dr < 0) {
+ return return_check_zero(0);
+ }
+ dr = sqrt(dr);
+ SkScalar R = SkDoubleToScalar(dr);
+ if (!SkScalarIsFinite(R)) {
+ return return_check_zero(0);
}
- R = SkScalarSqrt(R);
SkScalar Q = (B < 0) ? -(B-R)/2 : -(B+R)/2;
r += valid_unit_divide(Q, A, r);
@@ -98,7 +106,7 @@ int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2]) {
else if (roots[0] == roots[1]) // nearly-equal?
r -= 1; // skip the double root
}
- return (int)(r - roots);
+ return return_check_zero((int)(r - roots));
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/gfx/skia/skia/src/core/SkRRect.cpp b/gfx/skia/skia/src/core/SkRRect.cpp
index 1188989cd..f4308debe 100644
--- a/gfx/skia/skia/src/core/SkRRect.cpp
+++ b/gfx/skia/skia/src/core/SkRRect.cpp
@@ -161,6 +161,19 @@ void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
this->scaleRadii();
}
+// 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() {
// Proportionally scale down all radii to fit. Find the minimum ratio
@@ -183,6 +196,11 @@ void SkRRect::scaleRadii() {
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);