Expand description
drmkit’s library-wide monotonic clock abstraction.
Port of src/time/clock.{hpp,cpp} from drm-cxx @ dc2915b.
Subsystems that animate, pace, or schedule take a &dyn Clock so
callers can:
- sync animation with an external presentation clock — a compositor that already tracks vblank/present timestamps hands the same time point to drmkit and to its own renderers;
- freeze or step time in tests without sleeping (see
ManualClock); - consolidate on a single clock as other timing-aware subsystems (page-flip pacing, input debouncing, animation cycles) land.
Callers who do not care get default_clock and never construct a clock.
§Why a raw nanosecond count and not std::time::Instant
Timestamp is a bare CLOCK_MONOTONIC nanosecond count, not an
Instant. Instant is opaque: it cannot be constructed from a value, so
it can express neither of the first two bullets above. The kernel hands
back page-flip and vblank timestamps as CLOCK_MONOTONIC — the whole point
of the abstraction is that a compositor can pass one of those straight in.
This is a deliberate deviation from the C++, which lifts
std::chrono::steady_clock’s time_since_epoch() onto its own tag.
steady_clock is CLOCK_MONOTONIC on glibc in practice, so the values
agree; naming CLOCK_MONOTONIC outright makes the contract explicit rather
than incidental.
Structs§
- Manual
Clock - A clock whose time only moves when the test moves it.
- Steady
Clock - Default implementation backed by
CLOCK_MONOTONIC. - Timestamp
- A point on the monotonic timeline, in nanoseconds since an unspecified
epoch (
CLOCK_MONOTONIC, i.e. system boot on Linux).
Traits§
- Clock
- A monotonic clock.
Functions§
- default_
clock - A process-wide
SteadyClock. The returned reference is valid for the lifetime of the program.