Not all platforms present us with vsync as its means of communicating an appropriate time for composition.
Wayland, for example, provides what is known as a "frame callback". A frame-callback is a one-shot notification on a surface that you register when you commit/swap a buffer, which notifies you when you should get to work for this surface next. This frame-callback is not called consistently on vsync, but simply when and if the compositor wishes for you to render. It is, however, guaranteed to be called a time granting us the best chance of reaching the next surface sampling deadline (i.e. vblank).
This flow works like this:
- Render some content
- Configure callback on a surface
- Swap buffers
- On callback, go to #1
A huge difference here is that there are no "idle" events: There will be no callbacks unless you swap a buffer. This means that if no callback is requested, we must composite immediately, and we cannot postpone for next vsync. If we stop compositing, the only thing that will wake us up is if someone from the outside re-triggers us.
A solution to this is to create a higher-level abstraction, rather than relying on exposing hardware vsync as we try to do now. This also gives us a chance to remove oddities from the interface, such as the exposure of a "Display", and instead let that be implementation defined (for Wayland, for example, there is no "display", just you and an arbitrary rate of callbacks).
The abstraction proposed is a FrameSource, with a simple interface: RequestFrame(), called just before a swap to signal that we would like to be called in the future, PendingFrame() to see if we should composite immediately or wait for a future frame callback, and SetCallback(FrameObserver*), which sets the callback to be called.
For classical platforms, this is easily implemented as a wrapper around a VsyncSource, where Wayland will have a direct implementation. Other platforms where applicable can then slowly be ported.
Non-compositing will currently rely on existing Vsync implementations (and a software timer on Wayland), until a later date.