Skip to main content

Module vsync

Module vsync 

Source
Expand description

Pluggable vsync pacing seam (VsyncPacer) and zero-allocation portable pacers (TimerVsyncPacer, ManualVsyncPacer).

All timestamps and intervals use u64 / u32 microseconds so this module compiles cleanly on wasm32-unknown-unknown without std::time::Instant.

Production consumers implementing VsyncPacer ([INV:extension-point-has-consumers]):

  • packages/backends/skia-desktop (CADisplayLink/CVDisplayLink, DwmFlush, Wayland winit, timer fallback)
  • packages/backends/web-runtime (RafVsyncPacer over window.requestAnimationFrame)

Structs§

ManualVsyncHandle
Shared atomic control handle paired with ManualVsyncPacer for deterministic tests.
ManualVsyncPacer
Deterministic, zero-allocation push-driven VsyncPacer for unit and integration tests.
TimerVsyncPacer
Portable, zero-allocation refresh-rate timer pacer computing next_deadline_us in microseconds for event loops that sleep via WaitUntil.

Constants§

DEFAULT_REFRESH_RATE_MILLIHERTZ
Fallback display refresh rate when the OS/monitor does not report one (60 Hz = 60,000 mHz).
MAX_REFRESH_RATE_MILLIHERTZ
Maximum accepted refresh rate in millihertz (1000 Hz); higher values clamp here so interval_us_from_millihertz is strictly >= 1 microsecond.
MIN_REFRESH_RATE_MILLIHERTZ
Minimum accepted refresh rate in millihertz (1 Hz); lower values clamp to DEFAULT_REFRESH_RATE_MILLIHERTZ.

Traits§

VsyncPacer
Platform-pluggable vsync / frame pacing strategy.

Functions§

interval_us_from_millihertz
Converts a refresh rate in millihertz (e.g. 60_000 for 60 Hz, 120_000 for 120 Hz) into a nominal frame interval in microseconds (16_666 us for 60 Hz, 8_333 us for 120 Hz), guaranteed strictly >= 1.
sanitize_refresh_rate_millihertz
Clamps millihertz into a valid refresh rate (< 1_000 -> 60_000, > 1_000_000 -> 1_000_000).