Skip to main content

VsyncPacer

Trait VsyncPacer 

Source
pub trait VsyncPacer: Send {
    // Required methods
    fn set_active(&mut self, active: bool);
    fn is_active(&self) -> bool;

    // Provided methods
    fn on_tick_received(&self) { ... }
    fn nominal_interval_us(&self) -> Option<u32> { ... }
    fn next_deadline_us(
        &self,
        _last_frame_us: Option<u64>,
        _now_us: u64,
    ) -> Option<u64> { ... }
}
Expand description

Platform-pluggable vsync / frame pacing strategy.

Push-driven native pacers (CADisplayLink, CVDisplayLink, DwmFlush, browser requestAnimationFrame) return None from Self::next_deadline_us and deliver ticks via their platform event loop / wake callback while Self::is_active is true.

Timer / poll pacers (such as TimerVsyncPacer) return Some(deadline_us) from Self::next_deadline_us while active so the event loop can sleep until the next frame boundary (ControlFlow::WaitUntil) with 0% idle CPU.

Required Methods§

Source

fn set_active(&mut self, active: bool)

Starts (true) or pauses (false) frame delivery. Idle pacers MUST consume 0% CPU.

Source

fn is_active(&self) -> bool

Returns true while frame delivery is active.

Provided Methods§

Source

fn on_tick_received(&self)

Acknowledges receipt of a delivered vsync tick so push-driven pacers can clear their coalescing latch and emit the next frame tick.

Source

fn nominal_interval_us(&self) -> Option<u32>

Nominal frame interval in microseconds if known (e.g. 8_333 for 120 Hz ProMotion).

Source

fn next_deadline_us( &self, _last_frame_us: Option<u64>, _now_us: u64, ) -> Option<u64>

Optional next wake deadline in microseconds (now_us clock) for timer/poll pacers. Push-driven native pacers (CADisplayLink, DwmFlush, rAF) return None.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§