From 5eea6856fb279f19a24fcd37da40e3fb293f691d Mon Sep 17 00:00:00 2001 From: flamingcow Date: Sat, 1 Aug 2026 16:14:12 -0700 Subject: [PATCH] Cut the comments back to the genuinely subtle ones --- fb.go | 15 ++++------ harness/grab.go | 35 ++++++++-------------- main.go | 36 ++++++++-------------- render.go | 15 ++++------ text.go | 10 +++---- ui.go | 79 ++++++++++++++----------------------------------- 6 files changed, 63 insertions(+), 127 deletions(-) diff --git a/fb.go b/fb.go index 77fe8a0..d278fdb 100644 --- a/fb.go +++ b/fb.go @@ -10,11 +10,10 @@ import ( "golang.org/x/sys/unix" ) -// Drawing lands in a plain memory buffer and is blitted to a scanout buffer the -// display is not reading, which is then swapped in whole at a vertical blank. -// Writing into the live scanout buffer instead, as the fbdev interface invites, -// races the beam: the blit takes a few hundred microseconds, and whatever the -// display reads during it is part of one frame and part of the next. +// Drawing lands in memory and is blitted to a buffer the display is not +// reading, then swapped in whole at a vertical blank. Writing into the live +// scanout buffer instead, as fbdev invites, races the beam: the blit takes a +// few hundred microseconds and the display reads half of each frame. const ( drmIoctlBase = 0x64 @@ -239,7 +238,6 @@ func crtcFor(fd int, c drmModeGetConnector, crtcs []uint32) (uint32, error) { return 0, fmt.Errorf("connector %d has no usable crtc", c.connectorID) } -// The connector to drive and a crtc that can drive it. func findDisplay(fd int) (connID, crtcID uint32, err error) { crtcs, conns, err := cardResources(fd) if err != nil { @@ -507,9 +505,8 @@ func (fb *framebuffer) blend(x, y int, c rgb, cov uint8) { fb.back[o+3] = byte(v >> 24) } -// Copies into the scanout buffer furthest from being displayed and asks for it -// at the next blank. The copy cannot tear because nothing is displaying that -// buffer, and the swap cannot tear because the hardware does it between frames. +// The copy cannot tear because nothing is displaying that buffer, and the swap +// cannot tear because the hardware does it between frames. func (fb *framebuffer) flush() error { next := (fb.front + 1) % scanoutBuffers copy(fb.bufs[next].mem, fb.back) diff --git a/harness/grab.go b/harness/grab.go index 5d148e4..3e539a5 100644 --- a/harness/grab.go +++ b/harness/grab.go @@ -11,12 +11,10 @@ import ( "golang.org/x/sys/unix" ) -// cabletest drives the panel through drm and page flips between two scanout -// buffers of its own, so /dev/fb0 holds the kernel console and there is nothing -// in it worth reading. The buffer being displayed is reachable from out here -// though: GETCRTC names it, and root is allowed a handle to it without being -// drm master, so it can be mapped and read without the program that owns it -// having to cooperate or even notice. +// cabletest drives the panel through drm, so /dev/fb0 holds the kernel console +// and is not worth reading. The displayed buffer is reachable from out here +// instead: GETCRTC names it, and root is allowed a handle to it without being +// drm master, so it can be read without the owning process cooperating. const ( drmCardGlob = "/dev/dri/card*" @@ -95,8 +93,6 @@ type grabber struct { index int } -// The card and crtc actually putting something on a display, which is whichever -// one cabletest chose when it set its mode. func openGrabber() (*grabber, error) { paths, err := filepath.Glob(drmCardGlob) if err != nil { @@ -145,11 +141,9 @@ func activeCrtc(fd int) (uint32, int, error) { func (g *grabber) close() { unix.Close(g.fd) } -// Reading the buffer takes about as long as a frame, so where the read starts -// in the flip cycle is what decides whether it stays ahead of the writer. Woken -// at a blank, the buffer named next has just gone on screen, which leaves a -// whole frame plus however long cabletest spends drawing before anything -// touches it again. +// Reading a buffer takes about as long as a frame, so where the read starts in +// the flip cycle decides whether it stays ahead of the writer. Woken at a +// blank, the buffer GETCRTC then names has just gone on screen. func (g *grabber) waitVblank() error { v := drmWaitVblank{ typ: drmVblankRelative | uint32(g.index< 0 { w := int(float64(r.w-2*chipBorder) * math.Min(d.holdFrac, 1)) @@ -229,8 +207,8 @@ func (d *display) close() { d.fb.close() } -// y is the top of the line as read, so text and a bordered box placed the same -// distance apart are the same distance apart to look at. +// y is the top of the line as read, not the top of the cell, so text and a +// bordered box placed the same distance apart look it. func (d *display) centerIn(f *textFace, x, w, y int, s string, col rgb) int { f.draw(d.fb, x+(w-len([]rune(s))*f.cellW)/2, y-f.capTop, s, col) return y + f.lineH + pairGap @@ -252,9 +230,7 @@ func (d *display) statsH(vf *textFace, n int) int { return gridRows(n)*(d.statPairH(vf)+statRowGap) - statRowGap } -// Where cell i of n falls in the panel's grid. A last row that does not fill -// the grid is centred, so the odd one out balances the rows above rather than -// hanging off the left of them. +// A last row that does not fill the grid is centred. func gridCell(i, n, x, w int) (cx, cw int) { cw = (w - (gridCols-1)*chipGap) / gridCols inRow := min(n-(i/gridCols)*gridCols, gridCols) @@ -262,10 +238,8 @@ func gridCell(i, n, x, w int) (cx, cw int) { return cx, cw } -// A figure with its label directly underneath, two to a row. The gap between -// rows is wider than the one inside a pair, so which label belongs to which -// figure is a matter of spacing rather than of guessing. An empty value takes -// its space without drawing, so nothing below moves when it arrives. +// An empty value takes its space without drawing, so nothing below it moves +// when it arrives. func (d *display) stats(vf *textFace, x, w, y int, cells []statCell) int { for i, c := range cells { if c.value == "" { @@ -291,7 +265,6 @@ var errRows = []struct { func (d *display) chipH() int { return d.grid.lineH + 2*chipPadY } -// Taller by a line, since these carry the count under the kind. func (d *display) countChipH() int { return d.chipH() + d.gridB.lineH + pairGap } func (d *display) chipsH() int { @@ -302,24 +275,20 @@ func (d *display) countsH() int { return gridRows(len(errRows))*(d.countChipH()+chipGap) - chipGap } -// Shared by both panels so they are demonstrably the same object, one carrying -// a count and one not. +// Outlined by drawing the border colour and sinking a smaller well of +// background into it, so both curves get the same antialiasing. func (d *display) chipAt(i, x, w, y, h int, c rgb) (int, int, int) { cx, cw := gridCell(i, len(errRows), x, w) cy := y + (i/gridCols)*(h+chipGap) - // Outlined by drawing the border colour and then sinking a smaller well of - // background into it, so both curves get the same antialiasing. d.fb.roundRect(cx, cy, cw, h, chipRadius, c) d.fb.roundRect(cx+chipBorder, cy+chipBorder, cw-2*chipBorder, h-2*chipBorder, chipRadius-chipBorder, uiBg) return cx, cw, cy } -// The same kinds as errBlock, but answering whether rather than how many, and -// carrying their own labels so nothing has to be matched up across a row. Over -// a window this short a count is a number nobody can read before it changes; -// the only thing worth knowing at a glance is which kinds are happening now. +// Whether rather than how many: over a window this short a count changes faster +// than it can be read. func (d *display) errChips(x, w, y int, e errs) int { for i, r := range errRows { c := errColor(r.get(e)) @@ -340,8 +309,6 @@ func (d *display) errCounts(x, w, y int, e errs) int { return y + d.countsH() } -// Draws the frame and hands back the writable width inside it. Where the blocks -// sit within it was settled once at startup, since it never changes. func (d *display) panel(p rect, e errs) (int, int) { fill, edge := uiOKFill, uiOKEdge if e.total() > 0 {