forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

Development:-Redraw-Loop.md22 lines, 1.7 KiBHistoryRawDownload
1On a TTY, only one frame can be submitted to an output at a time, and the compositor must wait until the output repaints (indicated by a VBlank) to be able to submit the next frame.
2In niri we keep track of this via the `RedrawState` enum that you can find in an `OutputState`.
3
4Here's a diagram of state transitions for the `RedrawState` state machine:
5
6<picture>
7 <source media="(prefers-color-scheme: dark)" srcset="./img/RedrawState-dark.drawio.png">
8 <img alt="RedrawState state transition diagram" src="./img/RedrawState-light.drawio.png">
9</picture>
10
11`Idle` is the default state, when the output does not need to be repainted.
12Any operation that may cause the screen to update calls `queue_redraw()`, which moves the output to a `Queued` state.
13Then, at the end of an event loop dispatch, niri calls `redraw()` for every `Queued` output.
14
15If the redraw causes damage (i.e. something on the output changed), we move into the `WaitingForVBlank` state, since we cannot redraw until we receive a VBlank event.
16However, if there's no damage, we do not return to `Idle` right away.
17Instead, we set a timer to fire roughly at when the next VBlank would occur, and transition to a `WaitingForEstimatedVBlank` state.
18
19This is necessary in order to throttle frame callbacks sent to applications to at most once per output refresh cycle.
20Without this throttling, applications can start continuously redrawing without damage (for instance, if the application window is partially off-screen, and it is only the off-screen part that changes), and eating a lot of CPU in the process.
21
22Then, either the estimated VBlank timer completes, and we go back to `Idle`, or maybe we call `queue_redraw()` once more and try to redraw again.