Handle non-finite quads in attemptQuadOptimization
Bug: chromium:977315
Change-Id: Ia5b734f5c0f0806af0f096de5add880a777c5c25
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222793
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/geometry/GrQuad.h b/src/gpu/geometry/GrQuad.h
index 9a080f3..ea3cdec 100644
--- a/src/gpu/geometry/GrQuad.h
+++ b/src/gpu/geometry/GrQuad.h
@@ -100,6 +100,18 @@
return {min(x), min(y), max(x), max(y)};
}
+ bool isFinite() const {
+ // If any coordinate is infinity or NaN, then multiplying it with 0 will make accum NaN
+ float accum = 0;
+ for (int i = 0; i < 4; ++i) {
+ accum *= fX[i];
+ accum *= fY[i];
+ accum *= fW[i];
+ }
+ SkASSERT(0 == accum || SkScalarIsNaN(accum));
+ return !SkScalarIsNaN(accum);
+ }
+
float x(int i) const { return fX[i]; }
float y(int i) const { return fY[i]; }
float w(int i) const { return fW[i]; }
diff --git a/src/gpu/geometry/GrQuadUtils.cpp b/src/gpu/geometry/GrQuadUtils.cpp
index fce38d2..c4e86d7 100644
--- a/src/gpu/geometry/GrQuadUtils.cpp
+++ b/src/gpu/geometry/GrQuadUtils.cpp
@@ -198,6 +198,8 @@
bool CropToRect(const SkRect& cropRect, GrAA cropAA, GrQuadAAFlags* edgeFlags, GrQuad* quad,
GrQuad* local) {
+ SkASSERT(quad->isFinite());
+
if (quad->quadType() == GrQuad::Type::kAxisAligned) {
// crop_rect keeps the rectangles as rectangles, so there's no need to modify types
if (local) {
diff --git a/src/gpu/geometry/GrQuadUtils.h b/src/gpu/geometry/GrQuadUtils.h
index 5f6d283..53b53d2 100644
--- a/src/gpu/geometry/GrQuadUtils.h
+++ b/src/gpu/geometry/GrQuadUtils.h
@@ -25,7 +25,7 @@
* Crops quad to the provided device-space axis-aligned rectangle. If the intersection of this
* quad (projected) and cropRect results in a quadrilateral, this returns true. If not, this
* quad may be updated to be a smaller quad of the same type such that its intersection with
- * cropRect is visually the same.
+ * cropRect is visually the same. This function assumes that the 'quad' coordinates are finite.
*
* The provided edge flags are updated to reflect edges clipped by cropRect (toggling on or off
* based on cropAA policy). If provided, the local coordinates will be updated to reflect the