text stringlengths 0 1.47k |
|---|
fmt.Printf("best case above: %.1f frames/s\n", best) |
} |
return nil |
} |
// panelState is the pages as they were found and the page that was on show, so that whatever a mode |
// paints can be put back. |
// |
// The daemon skips rows it believes it has already drawn: it keeps a shadow of every page and compares |
// against it, so anything written to the framebuffer behind its back is treated as already on screen |
// and never corrected. Static content — a weather line, a date, the background under fixed text — is |
// then gone for good, because a row that never changes never differs from the shadow again. Nothing |
// short of a daemon restart puts it right, so every mode that writes has to leave what it found. |
// |
// The rescue environment is the one place this does not matter: there is no daemon to disagree with. |
type panelState struct { |
was uint32 |
backup []byte |
} |
// keepPanel copies the whole framebuffer out and remembers which page was on show. |
func keepPanel(mem []byte, line, panelH, pages int, v varInfo) *panelState { |
n := line * panelH * pages |
if n <= 0 || n > len(mem) { |
n = len(mem) |
} |
s := &panelState{was: v.Yoffset, backup: make([]byte, n)} |
copy(s.backup, mem[:n]) |
return s |
} |
// restore puts the pages back and pans to the page that was on show. |
func (s *panelState) restore(f *os.File, mem []byte, v varInfo) { |
copy(mem[:len(s.backup)], s.backup) |
v.Xoffset, v.Yoffset = 0, s.was |
if err := ioctl(f.Fd(), fbioPanDisplay, unsafe.Pointer(&v)); err != nil { |
fmt.Fprintf(os.Stderr, "fbprobe: putting the panel back: %v\n", err) |
return |
} |
fmt.Printf("panel put back: %d bytes restored and panned to yoffset %d\n", len(s.backup), s.was) |
} |
// dumpPanel writes the page the panel is showing, turned back the way it is composed so that it |
// reads as the thing somebody designed rather than as the panel's portrait rows. The pan offset is |
// the page on show, which is what makes this a picture of the glass and not of a buffer: page zero |
// is very often not what is up. |
func dumpPanel(mem []byte, v varInfo, line, panelW, panelH int, path string) error { |
pages := pageCount(v) |
page := 0 |
if panelH > 0 { |
page = int(v.Yoffset) / panelH |
} |
if page < 0 || page >= pages { |
page = 0 |
} |
base := page * panelH * line |
if base < 0 || base+panelH*line > len(mem) { |
return fmt.Errorf("page %d of %d is outside the mapping", page, pages) |
} |
// Landscape, the way it was drawn: landscape (x, y) is panel (panelW-1-y, x). |
w, h := panelH, panelW |
img := image.NewRGBA(image.Rect(0, 0, w, h)) |
for y := 0; y < h; y++ { |
for x := 0; x < w; x++ { |
off := base + x*line + (panelW-1-y)*4 |
word := binary.LittleEndian.Uint32(mem[off : off+4]) |
i := img.PixOffset(x, y) |
img.Pix[i+0] = byte(word >> v.Red[0]) |
img.Pix[i+1] = byte(word >> v.Green[0]) |
img.Pix[i+2] = byte(word >> v.Blue[0]) |
img.Pix[i+3] = byte(word >> v.Transp[0]) |
} |
} |
out, err := os.Create(path) |
if err != nil { |
return err |
} |
defer out.Close() |
if err := pngenc.Encode(out, img); err != nil { |
return err |
} |
fmt.Printf("wrote %s (%dx%d, page %d of %d at yoffset %d)\n", path, w, h, page, pages, v.Yoffset) |
return nil |
} |
// pageCount is how many pages the framebuffer holds. The driver keeps several so that a frame is |
// never seen half written, which is also why the pan offset is a page and not a guess. |
func pageCount(v varInfo) int { |
if v.Yres > 0 && v.YresVirtual > v.Yres { |
return int(v.YresVirtual / v.Yres) |
} |
return 1 |
} |
// pageOffsets names where a device's pages sit, for a line somebody has to read. |
func pageOffsets(pages, yres int) string { |
if pages < 2 { |
return "not at all (one page)" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.