text
stringlengths
0
1.47k
pid := daemonPID()
if pid != "" {
fmt.Printf("note: the daemon (pid %s) is running; freeze it with 'kill -STOP %s' or these\n"+
"numbers are the two of you sharing the panel, not what one of you can do.\n", pid, pid)
}
if err := benchPresent(f, mem, v, int(fx.LineLength), int(v.Xres), int(v.Yres),
pageCount(v), *bench, *benchInterval, *benchFor, background(*fill), background(*fill2),
*benchEach); err != nil {
fatal("bench: %v", err)
}
return
}
// The panel is portrait (480 wide, 960 tall); the device is used landscape. Compose a 960x480
// landscape image and rotate it 90 degrees clockwise onto the panel.
w, h := int(v.Yres), int(v.Xres) // landscape canvas
bg := background(*fill)
img, clockAt, clockY, clockScale := compose(w, h, bg, *fill, *title, *lines)
// What this paints must be put back when it finishes. The daemon skips rows it believes it has
// already drawn (screen.go's shadow), so a page left as another program painted it stays that way —
// static text and all — until something on it moves, which for static text is never. This is also
// what the rescue environment does not need: there is no daemon running to disagree with.
kept := keepPanel(mem, int(fx.LineLength), int(v.Yres), pageCount(v), v)
defer kept.restore(f, mem, v)
paint := func() {
blit(mem, img, int(fx.LineLength), int(v.Xres), int(v.Yres), v)
v.Xoffset, v.Yoffset = 0, 0
if err := ioctl(f.Fd(), fbioPanDisplay, unsafe.Pointer(&v)); err != nil {
fmt.Fprintf(os.Stderr, "FBIOPAN_DISPLAY: %v\n", err)
}
}
paint()
fmt.Println("painted")
if *hold > 0 {
deadline := time.Now().Add(*hold)
for time.Now().Before(deadline) {
time.Sleep(time.Second)
if *fill == "" {
draw.Draw(img, clockAt, image.NewUniform(bg), image.Point{}, draw.Src)
text(img, time.Now().Format("15:04:05"), 40, clockY, clockScale, color.RGBA{0xe8, 0xdc, 0xc8, 0xff})
}
paint()
}
}
}
// blit writes the landscape image onto the portrait framebuffer, rotated 90 degrees clockwise:
// landscape (x, y) lands at panel (panelW-1-y, x). Pixel order follows the var info's offsets.
func blit(mem []byte, img *image.RGBA, line, panelW, panelH int, v varInfo) {
for y := 0; y < img.Rect.Dy(); y++ {
for x := 0; x < img.Rect.Dx(); x++ {
i := img.PixOffset(x, y)
r, g, b, a := img.Pix[i], img.Pix[i+1], img.Pix[i+2], img.Pix[i+3]
px, py := panelW-1-y, x
if px < 0 || px >= panelW || py < 0 || py >= panelH {
continue
}
off := py*line + px*4
var pixel uint32
pixel |= uint32(r) << v.Red[0]
pixel |= uint32(g) << v.Green[0]
pixel |= uint32(b) << v.Blue[0]
pixel |= uint32(a) << v.Transp[0]
binary.LittleEndian.PutUint32(mem[off:], pixel)
}
}
}
func frame(img *image.RGBA, r image.Rectangle, t int, c color.RGBA) {
u := image.NewUniform(c)
draw.Draw(img, image.Rect(r.Min.X, r.Min.Y, r.Max.X, r.Min.Y+t), u, image.Point{}, draw.Src)
draw.Draw(img, image.Rect(r.Min.X, r.Max.Y-t, r.Max.X, r.Max.Y), u, image.Point{}, draw.Src)
draw.Draw(img, image.Rect(r.Min.X, r.Min.Y, r.Min.X+t, r.Max.Y), u, image.Point{}, draw.Src)
draw.Draw(img, image.Rect(r.Max.X-t, r.Min.Y, r.Max.X, r.Max.Y), u, image.Point{}, draw.Src)
}
// text draws with the built-in 7x13 face, scaled up by an integer factor. Crude, and enough to
// read from across a desk; a real face comes with the display layer proper.
func text(img *image.RGBA, s string, x, y, scale int, c color.RGBA) {
small := image.NewRGBA(image.Rect(0, 0, 7*len(s)+2, 14))
d := &font.Drawer{Dst: small, Src: image.NewUniform(c), Face: basicfont.Face7x13, Dot: fixed.P(1, 11)}
d.DrawString(s)
for sy := 0; sy < small.Rect.Dy(); sy++ {
for sx := 0; sx < small.Rect.Dx(); sx++ {
if small.Pix[small.PixOffset(sx, sy)+3] == 0 {
continue
}
draw.Draw(img, image.Rect(x+sx*scale, y+sy*scale, x+(sx+1)*scale, y+(sy+1)*scale), image.NewUniform(c), image.Point{}, draw.Src)
}
}
}
// guardPanel puts the panel back if the process is interrupted. An interrupted run would otherwise
// leave the daemon's shadow disagreeing with the screen for good, which is the one outcome none of
// these modes may have. Best effort: on a signal anything already half written is left as it is, and
// the restore that matters is the one the mode does on its way out.
func guardPanel(kept *panelState, f *os.File, mem []byte, v varInfo) {