Don't simplify shapes at all before trying the stroke tessellator
Bug: chromium:1172543
Bug: skia:11325
Change-Id: I96a6ca97c740f086871b1a41942ca3dd4d3586a9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/370649
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrSurfaceDrawContext.cpp b/src/gpu/GrSurfaceDrawContext.cpp
index 55f4f8f..a9c1d81 100644
--- a/src/gpu/GrSurfaceDrawContext.cpp
+++ b/src/gpu/GrSurfaceDrawContext.cpp
@@ -77,7 +77,7 @@
//////////////////////////////////////////////////////////////////////////////
-using SimplifyStroke = GrStyledShape::SimplifyStroke;
+using DoSimplify = GrStyledShape::DoSimplify;
class AutoCheckFlush {
public:
@@ -723,7 +723,7 @@
}
assert_alive(paint);
this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
- GrStyledShape(rect, *style, SimplifyStroke::kNo));
+ GrStyledShape(rect, *style, DoSimplify::kNo));
}
void GrSurfaceDrawContext::drawQuadSet(const GrClip* clip,
@@ -1017,7 +1017,7 @@
assert_alive(paint);
this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
- GrStyledShape(rrect, style, SimplifyStroke::kNo));
+ GrStyledShape(rrect, style, DoSimplify::kNo));
}
///////////////////////////////////////////////////////////////////////////////
@@ -1344,7 +1344,8 @@
path.addRRect(inner);
path.addRRect(outer);
path.setFillType(SkPathFillType::kEvenOdd);
- this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix, GrStyledShape(path));
+ this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
+ GrStyledShape(path, DoSimplify::kNo));
}
///////////////////////////////////////////////////////////////////////////////
@@ -1443,7 +1444,7 @@
assert_alive(paint);
this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
GrStyledShape(SkRRect::MakeOval(oval), SkPathDirection::kCW, 2,
- false, style, SimplifyStroke::kNo));
+ false, style, DoSimplify::kNo));
}
void GrSurfaceDrawContext::drawArc(const GrClip* clip,
@@ -1482,7 +1483,7 @@
}
this->drawShapeUsingPathRenderer(clip, std::move(paint), aa, viewMatrix,
GrStyledShape::MakeArc(oval, startAngle, sweepAngle, useCenter,
- style, SimplifyStroke::kNo));
+ style, DoSimplify::kNo));
}
void GrSurfaceDrawContext::drawImageLattice(const GrClip* clip,
@@ -1560,7 +1561,7 @@
SkDEBUGCODE(this->validate();)
GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceDrawContext", "drawPath", fContext);
- GrStyledShape shape(path, style, SimplifyStroke::kNo);
+ GrStyledShape shape(path, style, DoSimplify::kNo);
this->drawShape(clip, std::move(paint), aa, viewMatrix, std::move(shape));
}
@@ -1818,7 +1819,7 @@
if (!pr) {
// The shape isn't a stroke that can be drawn directly. Simplify if possible.
- shape.simplifyStroke();
+ shape.simplify();
if (shape.isEmpty() && !shape.inverseFilled()) {
return;
diff --git a/src/gpu/geometry/GrStyledShape.cpp b/src/gpu/geometry/GrStyledShape.cpp
index af38064..623f3c4 100644
--- a/src/gpu/geometry/GrStyledShape.cpp
+++ b/src/gpu/geometry/GrStyledShape.cpp
@@ -42,8 +42,7 @@
return false;
}
-GrStyledShape GrStyledShape::MakeFilled(const GrStyledShape& original, FillInversion inversion,
- SimplifyStroke simplifyStroke) {
+GrStyledShape GrStyledShape::MakeFilled(const GrStyledShape& original, FillInversion inversion) {
bool newIsInverted = is_inverted(original.fShape.inverted(), inversion);
if (original.style().isSimpleFill() && newIsInverted == original.fShape.inverted()) {
// By returning the original rather than falling through we can preserve any inherited style
@@ -64,7 +63,7 @@
// Going from a non-filled style to fill may allow additional simplifications (e.g.
// closing an open rect that wasn't closed in the original shape because it had
// stroke style).
- result.simplify(simplifyStroke);
+ result.simplify();
// The above simplify() call only sets simplified to true if its geometry was changed,
// since it already sees its style as a simple fill. Since the original style was not a
// simple fill, MakeFilled always simplifies.
@@ -306,11 +305,13 @@
GrStyledShape GrStyledShape::MakeArc(const SkRect& oval, SkScalar startAngleDegrees,
SkScalar sweepAngleDegrees, bool useCenter,
- const GrStyle& style, SimplifyStroke simplifyStroke) {
+ const GrStyle& style, DoSimplify doSimplify) {
GrStyledShape result;
result.fShape.setArc({oval.makeSorted(), startAngleDegrees, sweepAngleDegrees, useCenter});
result.fStyle = style;
- result.simplify(simplifyStroke);
+ if (doSimplify == DoSimplify::kYes) {
+ result.simplify();
+ }
return result;
}
@@ -417,7 +418,7 @@
} else if (parent.fShape.isPath() && !parent.fShape.path().isVolatile()) {
fInheritedPathForListeners.set(parent.fShape.path());
}
- this->simplify(SimplifyStroke::kYes);
+ this->simplify();
this->setInheritedKey(*parentForKey, apply, scale);
}
@@ -579,7 +580,7 @@
bool fInverted;
};
-void GrStyledShape::simplify(SimplifyStroke simplifyStroke) {
+void GrStyledShape::simplify() {
AutoRestoreInverseness ari(&fShape, fStyle);
unsigned simplifyFlags = 0;
@@ -621,11 +622,8 @@
// original path. This prevents attaching genID listeners to temporary paths created when
// drawing simple shapes.
fInheritedPathForListeners.reset();
-
- if (simplifyStroke == SimplifyStroke::kYes) {
- // Further simplifications to the shape based on the style
- this->simplifyStroke();
- }
+ // Further simplifications to the shape based on the style
+ this->simplifyStroke();
}
}
diff --git a/src/gpu/geometry/GrStyledShape.h b/src/gpu/geometry/GrStyledShape.h
index f527d4e..54e05d3 100644
--- a/src/gpu/geometry/GrStyledShape.h
+++ b/src/gpu/geometry/GrStyledShape.h
@@ -44,61 +44,69 @@
GrStyledShape() {}
- enum class SimplifyStroke : bool { kNo = false, kYes };
+ enum class DoSimplify : bool { kNo = false, kYes };
- explicit GrStyledShape(const SkPath& path)
- : GrStyledShape(path, GrStyle::SimpleFill(), SimplifyStroke::kNo) {}
+ explicit GrStyledShape(const SkPath& path, DoSimplify doSimplify = DoSimplify::kYes)
+ : GrStyledShape(path, GrStyle::SimpleFill(), doSimplify) {}
- explicit GrStyledShape(const SkRRect& rrect)
- : GrStyledShape(rrect, GrStyle::SimpleFill(), SimplifyStroke::kNo) {}
+ explicit GrStyledShape(const SkRRect& rrect, DoSimplify doSimplify = DoSimplify::kYes)
+ : GrStyledShape(rrect, GrStyle::SimpleFill(), doSimplify) {}
- explicit GrStyledShape(const SkRect& rect)
- : GrStyledShape(rect, GrStyle::SimpleFill(), SimplifyStroke::kNo) {}
+ explicit GrStyledShape(const SkRect& rect, DoSimplify doSimplify = DoSimplify::kYes)
+ : GrStyledShape(rect, GrStyle::SimpleFill(), doSimplify) {}
GrStyledShape(const SkPath& path, const SkPaint& paint,
- SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
- : GrStyledShape(path, GrStyle(paint), simplifyStroke) {}
+ DoSimplify doSimplify = DoSimplify::kYes)
+ : GrStyledShape(path, GrStyle(paint), doSimplify) {}
GrStyledShape(const SkRRect& rrect, const SkPaint& paint,
- SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
- : GrStyledShape(rrect, GrStyle(paint), simplifyStroke) {}
+ DoSimplify doSimplify = DoSimplify::kYes)
+ : GrStyledShape(rrect, GrStyle(paint), doSimplify) {}
GrStyledShape(const SkRect& rect, const SkPaint& paint,
- SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
- : GrStyledShape(rect, GrStyle(paint), simplifyStroke) {}
+ DoSimplify doSimplify = DoSimplify::kYes)
+ : GrStyledShape(rect, GrStyle(paint), doSimplify) {}
GrStyledShape(const SkPath& path, const GrStyle& style,
- SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
+ DoSimplify doSimplify = DoSimplify::kYes)
: fShape(path), fStyle(style) {
- this->simplify(simplifyStroke);
+ if (doSimplify == DoSimplify::kYes) {
+ this->simplify();
+ }
}
GrStyledShape(const SkRRect& rrect, const GrStyle& style,
- SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
+ DoSimplify doSimplify = DoSimplify::kYes)
: fShape(rrect), fStyle(style) {
- this->simplify(simplifyStroke);
+ if (doSimplify == DoSimplify::kYes) {
+ this->simplify();
+ }
}
GrStyledShape(const SkRRect& rrect, SkPathDirection dir, unsigned start, bool inverted,
- const GrStyle& style, SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
+ const GrStyle& style, DoSimplify doSimplify = DoSimplify::kYes)
: fShape(rrect)
, fStyle(style) {
fShape.setPathWindingParams(dir, start);
fShape.setInverted(inverted);
- this->simplify(simplifyStroke);
+ if (doSimplify == DoSimplify::kYes) {
+ this->simplify();
+ }
}
GrStyledShape(const SkRect& rect, const GrStyle& style,
- SimplifyStroke simplifyStroke = SimplifyStroke::kYes)
+ DoSimplify doSimplify = DoSimplify::kYes)
: fShape(rect), fStyle(style) {
- this->simplify(simplifyStroke);
+ if (doSimplify == DoSimplify::kYes) {
+ this->simplify();
+ }
}
GrStyledShape(const GrStyledShape&);
static GrStyledShape MakeArc(const SkRect& oval, SkScalar startAngleDegrees,
SkScalar sweepAngleDegrees, bool useCenter, const GrStyle& style,
- SimplifyStroke = SimplifyStroke::kYes);
+ DoSimplify = DoSimplify::kYes);
GrStyledShape& operator=(const GrStyledShape& that);
@@ -120,8 +128,7 @@
* made non-inverted since dashing ignores inverseness).
*/
static GrStyledShape MakeFilled(const GrStyledShape& original,
- FillInversion = FillInversion::kPreserve,
- SimplifyStroke = SimplifyStroke::kYes);
+ FillInversion = FillInversion::kPreserve);
const GrStyle& style() const { return fStyle; }
@@ -268,10 +275,11 @@
bool testingOnly_isNonVolatilePath() const;
/**
- * As an optional part of the simplification process, some shapes can have stroking trivially
- * evaluated and form a new geometry with just a fill.
+ * Similar to GrShape::simplify but also takes into account style and stroking, possibly
+ * applying the style explicitly to produce a new analytic shape with a simpler style.
+ * Unless "doSimplify" is kNo, this method gets called automatically during construction.
*/
- void simplifyStroke();
+ void simplify();
private:
/** Constructor used by the applyStyle() function */
@@ -284,11 +292,10 @@
void setInheritedKey(const GrStyledShape& parentShape, GrStyle::Apply, SkScalar scale);
/**
- * Similar to GrShape::simplify but also takes into account style and, optionally, stroking.
- * Some stroked shapes can be represented as a different filled primitive (e.g. a stroked line
- * becomes a filled round rect). When SimplifyStroke is kYes, such optimizations are permitted.
+ * As part of the simplification process, some shapes can have stroking trivially evaluated
+ * and form a new geometry with just a fill.
*/
- void simplify(SimplifyStroke);
+ void simplifyStroke();
/** Gets the path that gen id listeners should be added to. */
const SkPath* originalPathForListeners() const;