Aperture Institute GLaDOS — an operating system in Rust, with a language model in the kernel
GLaDOS / Wiki / The Windows 3.1 desktop

The desktop

Icons, the Start menu and gradient title bars come from Windows 98. Bevels and dialogs that hug their content come from 3.1. The palette comes from the sign over the door.

Composed, then diffed

Every repaint draws everything: wallpaper, icons, and every window back to front, into a heap back buffer. Presenting then writes to the framebuffer only the row spans that differ from a shadow copy of what is already on screen.

Total repaint keeps the window manager obviously correct, because there is no incremental state to get wrong. The diff is why nothing flickers and why hover feedback on pointer motion is affordable at all. The console bypasses the next present through a direct rectangle flush so that shell output stays immediate, and both paths update the shadow, so they cannot disagree about what is on screen.

The window manager, and its one idea

Every layout the pointer hit-tests is the same function the paint pass draws from. A control that highlights in one place and activates in another is the class of bug that arrangement forbids by construction.

Everything the pointer does, a keystroke also does. That is not an accessibility gesture. Serial cannot inject mouse packets, so a control with no typed equivalent cannot be driven headlessly and therefore never gets tested.

Four lessons already paid for

Opening an application returns focus to the terminal. The desktop takes every key while a non-terminal window has focus, so an application that kept focus ate the next command line. Minesweeper consumed one a byte at a time and flagged a cell on the letter f.

Alt-Tab swaps the top two windows and does not rotate. Rotating made a second press land on a third window, and both scripts and habit need over-and-back to be two presses.

Relative pointer moves must stay within 255 per axis. Larger deltas set the overflow bit and the driver correctly discards the packet, so the pointer does not move at all, which reads as a dead drag rather than a clamped one.

The glyph is eight pixels tall and doubled for chrome, which makes the title bar 24 and the caption buttons twelve square. Choreographing clicks from remembered metrics instead of a press trace cost two full test cycles aimed forty pixels wide of the close box.

A measurement that overturned the plan

A survey of the renderer ranked several changes by expected benefit. The measured results disagreed with almost all of it.

The console turned out to be the dominant cost of a frame at 1,672 us of 2,376. The reason was that a blank cell rendered an eight by eight glyph like any other, writing sixty-four scaled pixels of background one at a time, under a background the desktop had just filled with a bulk span fill. About 1.2 million per-pixel stores a frame, nearly all of them writing the colour already there. Painting the background once and then only cells with something in them took the console to 592 us and the frame to 1,629 us, for identical output.

The survey had missed it because it was looking for per-cell dirty tracking, which the full repaint defeats. The redundancy was never in repainting unchanged cells. It was in painting nothing, pixel by pixel.

Damage-rectangle presenting was measured and declined. Comparing the buffers costs 264 us of a 1,629 us frame over 4 MB, which is already at memory bandwidth, and skipping rows requires knowing which rows changed while the draw pass repaints everything unconditionally. Two other changes were kept despite measuring flat, because they are strictly less work for identical output, and recorded because the survey had called one of them the single largest constant-factor loss.