Skip to content

fix(web): draw replayed canvases pixel for pixel in nested scroll zoom - #631

Merged
houko merged 1 commit into
mainfrom
fix/canvas-zoom-ci
Nov 18, 2026
Merged

houko merged 1 commit into
mainfrom
fix/canvas-zoom-ci

Conversation

@houko

@houko houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Main's Test job has failed since fd6adf5, and every PR rebased onto it fails the same way:

✗ TestNestedZoomedCanvasIsSharp
    canvaszoom_test.go:105: zoom 3, capture 600x600: line has 6 black and 2 gray pixels, want 6 black and no gray
    canvaszoom_test.go:105: zoom 1, capture 600x600: line has 1 black and 2 gray pixels, want 2 black and no gray

Cause

#607 (sharp canvases under scroll zoom) and #610 (gallery and CI) each passed CI alone. #610's b1e0e82 starts the test browser with --force-device-scale-factor=2, so the browser now really composes at a device scale of 2 instead of only emulating it. Bisected on the Linux build host: b1c710a passes, b1e0e82 fails.

The replayed bitmap is right: in the zoom-3 case the canvas is 1800 × 1800 pixels for 900 CSS pixels at a ratio of 2, with no fractional offsets anywhere up the tree. The grey comes from Chrome filtering the canvas through the nested scale() transforms even when they add up to one pixel per pixel. With image-rendering: pixelated the same capture is sharp.

Fix

A canvas inside zoomed scroll contents is drawn with image-rendering: pixelated while its replayed bitmap is exactly as large as the screen shows it. A zoom puts those canvases back to smooth sampling right away, so CSS scaling during a pinch or animation still looks smooth, until the 120 ms replay sets them again. A canvas whose zoom is past the raster cap, or whose size at that scale is fractional, keeps smooth sampling. Canvases outside zoomed scroll views are not touched. docs/architecture/canvas.md says so.

Verification

On the Linux build host (headless Chrome, as in CI):

  • go test -run TestWebCanvasScrollZoom ./cmd/nsgo: fails on main with the error above, passes with this change (pixels 4/4, lifecycle 4/4).
  • go tool nsgo test -target web ./internal/platform/web: 17 passed, 1 skipped.
  • GOOS=js GOARCH=wasm go vet ./internal/platform/web passes.

Not checked on a real high-DPI browser outside headless Chrome.

Chrome filters a canvas through nested scale transforms even when they add up to one pixel per pixel, so a bitmap replayed at the exact screen scale still showed grey edges in TestNestedZoomedCanvasIsSharp once CI's browser ran at a real device scale factor of 2 (--force-device-scale-factor). The bitmap itself was right: 1800 × 1800 pixels for 900 CSS pixels at a ratio of 2. A canvas inside zoomed contents now uses image-rendering: pixelated while its bitmap matches the screen exactly, and returns to smooth sampling as soon as a zoom changes, until the next replay.
@github-actions github-actions Bot added documentation Improvements or additions to documentation Web size/S bug Something isn't working labels Nov 18, 2026
@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. CI is green apart from apple-simulator, which fails in TestSimulatorProcessResults on the simulator boot timeout every PR hits right now; #634 raises that limit. The test job, which runs TestWebCanvasScrollZoom and the full browser backend suite, passes here where it fails on main.

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

Labels

bug Something isn't working documentation Improvements or additions to documentation size/S Web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant