Add some convexity checks to shadow code.
To address https://github.com/flutter/flutter/issues/11221.
Change-Id: I5ccd7f9eb2f3ee0d168aa4ca5474bfdfba14ca9c
Reviewed-on: https://skia-review.googlesource.com/24124
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/utils/SkInsetConvexPolygon.cpp b/src/utils/SkInsetConvexPolygon.cpp
index bb46942..fc40c8e 100755
--- a/src/utils/SkInsetConvexPolygon.cpp
+++ b/src/utils/SkInsetConvexPolygon.cpp
@@ -137,7 +137,6 @@
return true;
}
-#ifdef SK_DEBUG
static bool is_convex(const SkTDArray<SkPoint>& poly) {
if (poly.count() <= 3) {
return true;
@@ -161,7 +160,6 @@
return true;
}
-#endif
// The objective here is to inset all of the edges by the given distance, and then
// remove any invalid inset edges by detecting right-hand turns. In a ccw polygon,
@@ -198,6 +196,12 @@
SkAutoSTMalloc<64, EdgeData> edgeData(inputPolygonSize);
for (int i = 0; i < inputPolygonSize; ++i) {
int j = (i + 1) % inputPolygonSize;
+ int k = (i + 2) % inputPolygonSize;
+ // check for convexity just to be sure
+ if (compute_side(inputPolygonVerts[i], inputPolygonVerts[j],
+ inputPolygonVerts[k])*winding < 0) {
+ return false;
+ }
SkOffsetSegment(inputPolygonVerts[i], inputPolygonVerts[j],
insetDistanceFunc(i), insetDistanceFunc(j),
winding,
@@ -284,7 +288,6 @@
kCleanupTolerance)) {
insetPolygon->pop();
}
- SkASSERT(is_convex(*insetPolygon));
- return (insetPolygon->count() >= 3);
+ return (insetPolygon->count() >= 3 && is_convex(*insetPolygon));
}