Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c683912

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
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 <[email protected]> Commit-Queue: Brian Salomon <[email protected]>
1 parent 93ca54e commit c683912

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

gm/dashing.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,23 @@ DEF_SIMPLE_GM(dash_line_zero_off_interval, canvas, 160, 330) {
585585
}
586586
}
587587

588+
DEF_SIMPLE_GM(thin_aa_dash_lines, canvas, 110, 110) {
589+
SkPaint paint;
590+
static constexpr SkScalar kIntervals[] = {10, 5};
591+
paint.setPathEffect(SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 0.f));
592+
paint.setAntiAlias(true);
593+
paint.setStrokeWidth(0.25f);
594+
// substep moves the subpixel offset every iteration.
595+
static constexpr SkScalar kSubstep = 0.05f;
596+
// We will draw a grid of horiz/vertical lines that pass through each other's off intervals.
597+
static constexpr SkScalar kStep = kIntervals[0] + kIntervals[1];
598+
canvas->translate(kIntervals[1], kIntervals[1]);
599+
for (SkScalar x = -.5f*kIntervals[1]; x < 105; x += (kStep + kSubstep)) {
600+
canvas->drawLine({x, 0}, {x, 100}, paint);
601+
canvas->drawLine({0, x}, {100, x}, paint);
602+
}
603+
}
604+
588605
//////////////////////////////////////////////////////////////////////////////
589606

590607
DEF_GM(return new DashingGM;)

src/gpu/ops/GrDashOp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ class DashOp final : public GrMeshDrawOp {
513513
SkScalar devPhase = draw.fPhase * args.fParallelScale;
514514
SkScalar strokeWidth = args.fSrcStrokeWidth * args.fPerpendicularScale;
515515

516-
if ((strokeWidth < 1.f && useAA) || 0.f == strokeWidth) {
516+
if ((strokeWidth < 1.f && !useAA) || 0.f == strokeWidth) {
517517
strokeWidth = 1.f;
518518
}
519519

0 commit comments

Comments
 (0)