pub struct PointerResampler { /* private fields */ }Expand description
Buffers raw pointer samples and emits frame-boundary-resampled events, one
independent lane per PointerId. See the module docs for the
interpolation/prediction contract; construct one per app handle and drive it
from the shell’s touch and frame paths.
A lane opens with its contact’s first sample and ends once its Up/Cancel
has been emitted. Each lane resamples exactly as a single-pointer resampler
would; the events of several lanes are merged back into arrival order.
Implementations§
Source§impl PointerResampler
impl PointerResampler
Sourcepub fn new() -> Self
pub fn new() -> Self
A resampler honoring the NO_RESAMPLE_VAR kill switch — what every
shell constructs. When the variable is set (compile-time --define or
runtime env, any non-"0" value), this is equivalent to
disabled.
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
A resampler that always delivers raw samples straight through — the
explicit disabled/kill-switch form (and a test seam bypassing the env
read). Mirrors Self::new’s behavior when NO_RESAMPLE_VAR is set.
Sourcepub fn with_enabled(enabled: bool) -> Self
pub fn with_enabled(enabled: bool) -> Self
Construct with an explicit enabled flag, bypassing the env read — the
test/advanced seam (mirrors crate::frame_gate::FrameGate::with_enabled).
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether resampling is active. false for a disabled
resampler or when the kill switch is engaged — in which case the shell
should deliver touches directly rather than buffering them here.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Whether any raw sample is still buffered, in any lane. The shell ORs
this into its frame-gate input (events_since_last_frame) so a frame
that could not yet drain a too-new sample still runs on the next tick —
the “pending buffered input never starves the gate” contract (see
docs/CODE_STANDARDS.md’s default-to-run rule).
Sourcepub fn push(&mut self, sample: RawPointerSample)
pub fn push(&mut self, sample: RawPointerSample)
Buffer one raw platform sample in its contact’s lane (a touch entry point calls this per contact). Each contact’s samples must be pushed in nondecreasing timestamp order (the natural arrival order of one pointer’s stream).
Sourcepub fn resample(
&mut self,
frame_time_nanos: u64,
out: &mut Vec<ResampledPointer>,
)
pub fn resample( &mut self, frame_time_nanos: u64, out: &mut Vec<ResampledPointer>, )
Drain the buffered samples up to this frame’s sample instant into out,
appending the resampled events — each tagged with its contact — that the
shell should feed into the tree this frame, in order. out is appended
to, not cleared — the caller owns/reuses the buffer.
frame_time_nanos is the frame’s sample query time in the shell’s chosen
monotonic domain (the same domain push stamped with).
On a disabled resampler every buffered sample is emitted verbatim in arrival order (direct delivery). On an enabled one, each lane independently:
- emits
Down/Up/Cancelwhose timestamp has reached the sample instant losslessly in order, each at its raw reported position; - coalesces a run of
Movesamples up to the sample instant into a singleMoveat the position interpolated atframe_time −SAMPLE_OFFSET_NANOS(or extrapolated within thePREDICTION_WINDOW_NANOSclamp when the finger has outrun its samples); - leaves samples still ahead of the sample instant buffered (see
has_pending).
The lanes’ events are then merged by the arrival order of the samples
they came from, so a second finger’s Down lands after the first
finger’s Down that preceded it. A lane whose Up/Cancel was emitted
and that has nothing left buffered is retired.