From e40c3610e4b713eb652491b8524dd1d4db117c5a Mon Sep 17 00:00:00 2001 From: Stephen White Date: Tue, 9 Jan 2018 11:49:08 -0500 Subject: [PATCH] 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 Commit-Queue: Stephen White --- src/gpu/GrTessellator.cpp | 4 ++-- tests/TessellatingPathRendererTests.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp index 3eb92a6479..888c7de445 100644 --- a/src/gpu/GrTessellator.cpp +++ b/src/gpu/GrTessellator.cpp @@ -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; diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp index 02db8d8a58..dfbb0045a6 100644 --- a/tests/TessellatingPathRendererTests.cpp +++ b/tests/TessellatingPathRendererTests.cpp @@ -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 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