Don't assume extended (check perspective)
Related to https://skia-review.googlesource.com/c/skia/+/436476
Change-Id: Ief81b5f1824b5dd7960e09a1a6df55bcf6b6dc45
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/436597
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/gm/patharcto.cpp b/gm/patharcto.cpp
index 985583b..8a7415b 100644
--- a/gm/patharcto.cpp
+++ b/gm/patharcto.cpp
@@ -67,7 +67,7 @@
return SkPath::Polygon(pts, count, isClosed);
}
-DEF_SIMPLE_GM(path_append_extend, canvas, 250, 400) {
+DEF_SIMPLE_GM(path_append_extend, canvas, 400, 400) {
const SkPoint p0[] = {
{ 10, 30 }, {30, 10}, {50, 30},
};
@@ -82,6 +82,12 @@
paint.setStrokeWidth(9);
paint.setAntiAlias(true);
+ // addPath() sometimes checks for perspective, so we want to test that
+ const SkScalar x = 0.0001f; // tiny amount of perspective
+ const SkMatrix perspective = SkMatrix::MakeAll(1, 0, 0,
+ 0, 1, 0,
+ x, 0, 1);
+
for (bool isClosed : {false, true}) {
for (auto proc : {old_school_polygon, new_school_polygon}) {
canvas->save();
@@ -101,9 +107,24 @@
canvas->translate(80, 0);
{
SkPath path = path0;
+ path.addPath(path1, perspective, SkPath::kAppend_AddPathMode);
+ canvas->drawPath(path, paint);
+ }
+
+ canvas->translate(80, 0);
+ {
+ SkPath path = path0;
path.addPath(path1, SkPath::kExtend_AddPathMode);
canvas->drawPath(path, paint);
}
+
+ canvas->translate(80, 0);
+ {
+ SkPath path = path0;
+ path.addPath(path1, perspective, SkPath::kExtend_AddPathMode);
+ canvas->drawPath(path, paint);
+ }
+
canvas->restore();
canvas->translate(0, 100);
}
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index f14e06e..a3cd17b 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -1397,8 +1397,7 @@
SkPoint mappedPts[3];
case SkPathVerb::kMove:
mapPtsProc(matrix, mappedPts, &pts[0], 1);
- if (firstVerb && !isEmpty()) {
- SkASSERT(mode == kExtend_AddPathMode);
+ if (firstVerb && mode == kExtend_AddPathMode && !isEmpty()) {
injectMoveToIfNeeded(); // In case last contour is closed
SkPoint lastPt;
// don't add lineTo if it is degenerate