aboutsummaryrefslogtreecommitdiff
path: root/docs/wiki/Development:-Redraw-Loop.md
diff options
context:
space:
mode:
authorKent Daleng <lolexplode@gmail.com>2025-08-17 16:05:41 +0200
committerGitHub <noreply@github.com>2025-08-17 17:05:41 +0300
commitdc93f1c1fd7b67e2da5af2ffada732b9ddeb2d6a (patch)
treea2f2938a7df17c196be7016dc5fe1fc9f75fb484 /docs/wiki/Development:-Redraw-Loop.md
parenta6febb86aa5af0df7bf2792ca027ef95a503d599 (diff)
downloadniri-dc93f1c1fd7b67e2da5af2ffada732b9ddeb2d6a.tar.gz
niri-dc93f1c1fd7b67e2da5af2ffada732b9ddeb2d6a.tar.bz2
niri-dc93f1c1fd7b67e2da5af2ffada732b9ddeb2d6a.zip
github wiki replacement / mkdocs-docs (#2147)
* Add wiki based on mkdocs * wording fixes * fix github bg color on narrow * Fix left sidebar section headers being bigger than pages * fix hover accent * fix list rendering on fractional layout * fix videos * fix automatic full links * remove redundant commented css * improve dark mode contrast * update pygments for better child node coloring * update logo * remove blank lines * add systemd language hint --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
Diffstat (limited to 'docs/wiki/Development:-Redraw-Loop.md')
-rw-r--r--docs/wiki/Development:-Redraw-Loop.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/wiki/Development:-Redraw-Loop.md b/docs/wiki/Development:-Redraw-Loop.md
new file mode 100644
index 00000000..7f3d1873
--- /dev/null
+++ b/docs/wiki/Development:-Redraw-Loop.md
@@ -0,0 +1,22 @@
+On 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.
+In niri we keep track of this via the `RedrawState` enum that you can find in an `OutputState`.
+
+Here's a diagram of state transitions for the `RedrawState` state machine:
+
+<picture>
+ <source media="(prefers-color-scheme: dark)" srcset="./img/RedrawState-dark.drawio.png">
+ <img alt="RedrawState state transition diagram" src="./img/RedrawState-light.drawio.png">
+</picture>
+
+`Idle` is the default state, when the output does not need to be repainted.
+Any operation that may cause the screen to update calls `queue_redraw()`, which moves the output to a `Queued` state.
+Then, at the end of an event loop dispatch, niri calls `redraw()` for every `Queued` output.
+
+If 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.
+However, if there's no damage, we do not return to `Idle` right away.
+Instead, we set a timer to fire roughly at when the next VBlank would occur, and transition to a `WaitingForEstimatedVBlank` state.
+
+This is necessary in order to throttle frame callbacks sent to applications to at most once per output refresh cycle.
+Without 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.
+
+Then, 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.