Skip to content

perf(screenshot): Phase D — native server-side region crop - #3

Merged
slaveofcode merged 1 commit into
developfrom
feat/screenshot-phase-d-native-crop
Jul 21, 2026
Merged

perf(screenshot): Phase D — native server-side region crop#3
slaveofcode merged 1 commit into
developfrom
feat/screenshot-phase-d-native-crop

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

Summary

Completes the screenshot optimization plan. The in-tool region flow no longer ships a full-res PNG to JS to crop in canvas — it holds the frozen full frame in Rust and crops server-side, so only the small region crosses IPC.

Before → after

  • Before: capture frozen full-res PNG → raw IPC (10–30MB on 5K) → base64 → <img> decode → canvas crop.
  • After: capture_hold keeps the frozen frame in Rust; after selection crop_held crops with HiDPI scaling and returns just the region as PNG; release_held frees it on cancel. Memory bounded to one held frame.

Details

  • physical_crop_rect (logical→physical, clamped) is a pure fn with 6 unit tests (identity, 2× retina, edge-clamp, negative-origin, zero-dims, zero-logical fallback).
  • Screenshot.tsx loads the crop via createImageBitmap — no base64, no full-res decode.
  • Region button is Tauri-only, so no browser path changes.

Testing

  • cargo test → 19 passed (incl. the 6 new crop tests); JS → 385 passed.
  • Needs a macOS smoke test: crop pixel-accurate on HiDPI + correct on a secondary display; cancel frees the held frame.

Note

capture_hold/crop_held are macOS-only, consistent with the rest of desktop capture (Windows/Linux capture is still unimplemented).

🤖 Generated with Claude Code

…to JS)

The in-tool region flow captured the frozen full-res screen, shipped the whole
PNG to JS (10-30MB on a 5K display), base64'd it, decoded it, and cropped in a
canvas — even for a tiny region.

Now: capture_hold captures the frozen full frame once (while the main window is
hidden) and keeps it in Rust; after selection, crop_held crops server-side with
HiDPI scaling and returns only the small region as raw PNG bytes. release_held
frees it on cancel. Memory is bounded to one held frame (cleared on next capture).

physical_crop_rect (logical→physical, clamped) is a pure fn with 6 unit tests.
Screenshot.tsx loads the crop via createImageBitmap — no base64, no full-res
decode. Region button is Tauri-only so there's no browser path to preserve.

cargo test: 19 passed; JS: 385 passed. Manual test: crop is pixel-accurate on
HiDPI and correct on a secondary display.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013dqouzFP8vy9jaKhTDFj5H
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