Skip to content

frameclock_wayland: add Wayland timing adapter crate - #39

Merged
waywardmonkeys merged 3 commits into
forest-rs:mainfrom
no-materials:frameclock-wayland
Jun 15, 2026
Merged

frameclock_wayland: add Wayland timing adapter crate#39
waywardmonkeys merged 3 commits into
forest-rs:mainfrom
no-materials:frameclock-wayland

Conversation

@no-materials

Copy link
Copy Markdown
Contributor

Add a frameclock_wayland crate following the frameclock_apple/frameclock_web adapter split: compositor-aligned clock reads (Clock, now, timebase), wp_presentation feedback facts (SubmissionId, PresentEvent, PresentEventQueue), and the frame-callback ticker state machine (TickerState, decoupled from the output registry by taking the target OutputId from the caller).

Purely additive: subduction_backend_wayland keeps its private copies until a follow-up migrates it and the examples. Present-hint estimation and a retained FrameDriver wrapper are likewise left to future implementation.

Introduce frameclock_wayland with the Wayland timing facts that previously
only lived inside subduction_backend_wayland: compositor-aligned clock
selection and reads (Clock, now, timebase), wp_presentation feedback facts
(SubmissionId, PresentEvent, PresentEventQueue, presented-timestamp
conversion), and the frame-callback ticker state machine (TickerState),
decoupled from the backend's output registry by taking the target OutputId
from the caller.

The backend keeps its private copies for now; migrating it and the examples
to this crate is left to future implementation, along with present-hint
estimation and a retained FrameDriver wrapper.
@waywardmonkeys

Copy link
Copy Markdown
Contributor

TickerState carries one global last_observed_actual_present.

frameclock_wayland/src/tick.rs:71 stores a single previous actual-present timestamp and propagates it into every next tick at frameclock_wayland/src/tick.rs:102. The existing backend does the same at subduction_backend_wayland/src/protocol.rs:346. That is acceptable for the current single-surface contract, but the new reusable crate should document that TickerState is one paced surface/output stream, or it should correlate actual present by SubmissionId.

Otherwise, feedback from an unrelated surface or output can become FrameTick::prev_actual_present for the next tick.

@waywardmonkeys

Copy link
Copy Markdown
Contributor

TickerState::mark_callback_requested should probably return Result or bool.

The backend wrapper currently guards this at subduction_backend_wayland/src/event_loop.rs:413, but the new public API in frameclock_wayland/src/tick.rs:130 only debug_assert!s and then sets callback_in_flight = true. If this crate is meant for hosts beyond subduction_backend_wayland, it should make double-request handling explicit.

TickerState keeps a single most-recent actual-present timestamp and stamps
it onto the next tick's prev_actual_present. Document that each instance
models one paced surface/output stream: create one per wl_surface, pass a
stable OutputId, and feed it only that surface's presentation feedback.
Hosts multiplexing several surfaces on one queue should keep a TickerState
per stream and correlate feedback by SubmissionId themselves.

This makes the single-surface contract explicit for reuse beyond
subduction_backend_wayland; SubmissionId-based correlation remains future
work in the present-hint/driver wrapper layer.
mark_callback_requested now returns bool instead of only debug-asserting:
true when the single in-flight callback slot was newly claimed, false when
a callback is already in flight (leaving state unchanged). Marked #[must_use]
so external hosts handle the rejected case instead of silently re-arming.

Update the crate docs and example to claim the slot before sending the
wl_surface.frame request, and add a test covering the rejected double
request. subduction_backend_wayland keeps its own ticker and external guard
until the backend is migrated to this crate.
@waywardmonkeys
waywardmonkeys merged commit b9cec54 into forest-rs:main Jun 15, 2026
15 checks passed
@no-materials
no-materials deleted the frameclock-wayland branch June 15, 2026 14:50
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.

2 participants