GrTessellator: set a cap on quadratic linearization.

Some pathological cases don't converge to a reasonable number of points
when using uniform linearization of quadratic points. Cap them to the
maximum which GrPathUtils supports.

Add reduced test case from crbug-762369.

BUG=762369

Change-Id: Icc744018e5c01a0e0fe2ec00613bdb25e49614e9
Reviewed-on: https://skia-review.googlesource.com/92721
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2018-01-09 11:49:08 -05:00 committed by Skia Commit-Bot
parent 9ff5dc9c9f
commit e40c3610e4
2 changed files with 14 additions and 2 deletions

View File

@ -711,10 +711,10 @@ void append_quadratic_to_contour(const SkPoint pts[3], SkScalar toleranceSqd, Ve
Sk2s ab = quad.fA * quad.fB;
SkScalar t = denom ? (-ab[0] - ab[1]) / denom : 0.0f;
int nPoints = 1;
SkScalar u;
SkScalar u = 1.0f;
// Test possible subdivision values only at the point of maximum curvature.
// If it passes the flatness metric there, it'll pass everywhere.
for (;;) {
while (nPoints < GrPathUtils::kMaxPointsPerCurve) {
u = 1.0f / nPoints;
if (quad_error_at(pts, t, u) < toleranceSqd) {
break;

View File

@ -428,6 +428,17 @@ static SkPath create_path_28() {
path.lineTo(-7.5952312625177475154e+21, -2.6819185100266674911e+24);
return path;
}
// A quad which generates a huge number of points (>2B) when uniformly
// linearized. This should not hang or OOM.
static SkPath create_path_29() {
SkPath path;
path.moveTo(10, 0);
path.lineTo(0, 0);
path.quadTo(10, 0, 0, 8315084722602508288);
return path;
}
static std::unique_ptr<GrFragmentProcessor> create_linear_gradient_processor(GrContext* ctx) {
SkPoint pts[2] = { {0, 0}, {1, 1} };
@ -519,5 +530,6 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) {
test_path(ctx, rtc.get(), create_path_26(), SkMatrix(), GrAAType::kCoverage);
test_path(ctx, rtc.get(), create_path_27(), SkMatrix(), GrAAType::kCoverage);
test_path(ctx, rtc.get(), create_path_28(), SkMatrix(), GrAAType::kCoverage);
test_path(ctx, rtc.get(), create_path_29());
}
#endif