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 <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-05-07 12:43:19 -04:00 committed by Skia Commit-Bot
parent 93ca54e0ac
commit c683912173
2 changed files with 18 additions and 1 deletions

View File

@ -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;)

View File

@ -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;
}