Skip to content

fix(desktop): damage rect rounding + debug overlay scale (#195) - #201

Merged
kolkov merged 1 commit into
mainfrom
fix/damage-rects-195
Aug 2, 2026
Merged

fix(desktop): damage rect rounding + debug overlay scale (#195)#201
kolkov merged 1 commit into
mainfrom
fix/damage-rects-195

Conversation

@kolkov

@kolkov kolkov commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes findings 2 and 3 from #195 (damage rects: logical vs physical pixel mismatches).

Finding 2 (production): scissor rounding

trackBoundaryDamage used truncate+round-half-up-size formula. At fractional scales (1.25x, 1.5x, 1.75x), this under-covers by 1 physical pixel — stale LoadOpLoad seam. Fix: math.Floor/math.Ceil rounding via extracted physicalDamageRect helper.

Finding 3 (debug overlay): deviceScale²

debug_dirty.go pre-multiplied by scale before Fill/Stroke which applies deviceMatrix again = double scale. Fix: removed manual pre-multiplication, added Push/Identity/Pop state isolation.

Tests

  • 5 physicalDamageRect tests (1x, 2x, 1.5x discriminating, 1.25x, 1.75x)
  • 7 debug overlay pixel tests (headless gg.Context, analytic rasterizer)

Findings 1, 4, 5 from #195 are gg-side — tracked separately.

Test plan

  • go build ./... — pass
  • go test ./... -count=1 — 0 failures
  • golangci-lint run --timeout=5m — 0 issues

Finding 2: trackBoundaryDamage scissor rect used truncate(min) +
round-half-up(size), which under-covers by 1px at fractional device
scales (1.25x, 1.5x, 1.75x). Use Floor(min)/Ceil(max) independently,
matching gg's own Context.trackDamage rounding. Extracted into
physicalDamageRect helper for independent testing.

Finding 3: dirtyOverlay.draw pre-multiplied coordinates by DeviceScale
before passing to Fill/Stroke, which apply deviceMatrix again = double
scale (4x on 2x display). Removed pre-multiplication, added
Push/Identity/Pop state isolation, and border guard for degenerate
rects.

9 new tests covering fractional scales, paint state isolation, and
degenerate rects.
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
desktop/desktop.go 53.84% 5 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant