From c683912173bbb777984d8626378edcecc7fbb482 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Thu, 7 May 2020 12:43:19 -0400 Subject: [PATCH] Improve thin horiz/vertical dashed lines by not forcing width to 1. It looks like a bug slipped in quite a while back here: https://codereview.chromium.org/1092793006/diff/30002/src/gpu/effects/GrDashingEffect.cpp where a width snapping that was supposed to apply to non-AA lines was changed to apply to AA lines. Adds GM that tests < 1 pixel wide dashed horiz/vertical lines. The lines look better with the change but are still a little too thick, depending on the subpixel offset. BUG: chromium:1049028 Change-Id: I45734f5ef55548b62c188d9f55d3150c00059eed Reviewed-on: https://skia-review.googlesource.com/c/skia/+/288628 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- gm/dashing.cpp | 17 +++++++++++++++++ src/gpu/ops/GrDashOp.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gm/dashing.cpp b/gm/dashing.cpp index 8c7a082951..fac79fd12c 100644 --- a/gm/dashing.cpp +++ b/gm/dashing.cpp @@ -585,6 +585,23 @@ DEF_SIMPLE_GM(dash_line_zero_off_interval, canvas, 160, 330) { } } +DEF_SIMPLE_GM(thin_aa_dash_lines, canvas, 110, 110) { + SkPaint paint; + static constexpr SkScalar kIntervals[] = {10, 5}; + paint.setPathEffect(SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 0.f)); + paint.setAntiAlias(true); + paint.setStrokeWidth(0.25f); + // substep moves the subpixel offset every iteration. + static constexpr SkScalar kSubstep = 0.05f; + // We will draw a grid of horiz/vertical lines that pass through each other's off intervals. + static constexpr SkScalar kStep = kIntervals[0] + kIntervals[1]; + canvas->translate(kIntervals[1], kIntervals[1]); + for (SkScalar x = -.5f*kIntervals[1]; x < 105; x += (kStep + kSubstep)) { + canvas->drawLine({x, 0}, {x, 100}, paint); + canvas->drawLine({0, x}, {100, x}, paint); + } +} + ////////////////////////////////////////////////////////////////////////////// DEF_GM(return new DashingGM;) diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp index 56f83ca5f4..09ec677584 100644 --- a/src/gpu/ops/GrDashOp.cpp +++ b/src/gpu/ops/GrDashOp.cpp @@ -513,7 +513,7 @@ private: SkScalar devPhase = draw.fPhase * args.fParallelScale; SkScalar strokeWidth = args.fSrcStrokeWidth * args.fPerpendicularScale; - if ((strokeWidth < 1.f && useAA) || 0.f == strokeWidth) { + if ((strokeWidth < 1.f && !useAA) || 0.f == strokeWidth) { strokeWidth = 1.f; }