Fold the leftover formatters into the SI ones and stop reallocating the draw scratch

This commit is contained in:
flamingcow
2026-08-04 13:37:19 -07:00
parent f5a6420cfa
commit 2035d42734
7 changed files with 42 additions and 60 deletions
+24 -22
View File
@@ -32,13 +32,14 @@ type scanout struct {
// w and h are the logical canvas, which is portrait; pw and ph are the panel,
// which is landscape.
type framebuffer struct {
fd int
back []byte
w int
h int
pw int
ph int
stride int
fd int
back []byte
scratch []byte
w int
h int
pw int
ph int
stride int
bufs [scanoutBuffers]scanout
front int
@@ -252,6 +253,7 @@ func openFramebuffer() (*framebuffer, error) {
}
}
fb.back = make([]byte, fb.stride*fb.ph)
fb.scratch = make([]byte, fb.stride)
set := drm.ModeCrtc{
SetConnectorsPtr: uint64(uintptr(unsafe.Pointer(&fb.connID))),
@@ -316,15 +318,22 @@ type rgb struct {
func pixel(c rgb) uint32 { return drm.Pack(c.r, c.g, c.b) }
func (fb *framebuffer) fill(c rgb) {
// A run of one repeated pixel, reused between calls: a whole panel row is the
// longest anything here needs, and every draw is on the one render goroutine.
func (fb *framebuffer) pixelRun(n int, c rgb) []byte {
v := pixel(c)
row := make([]byte, fb.stride)
for x := 0; x+4 <= fb.stride; x += 4 {
row[x+0] = byte(v)
row[x+1] = byte(v >> 8)
row[x+2] = byte(v >> 16)
row[x+3] = byte(v >> 24)
s := fb.scratch[:n]
for i := 0; i+4 <= n; i += 4 {
s[i+0] = byte(v)
s[i+1] = byte(v >> 8)
s[i+2] = byte(v >> 16)
s[i+3] = byte(v >> 24)
}
return s
}
func (fb *framebuffer) fill(c rgb) {
row := fb.pixelRun(fb.stride, c)
for y := 0; y < fb.ph; y++ {
copy(fb.back[y*fb.stride:], row)
}
@@ -337,14 +346,7 @@ func (fb *framebuffer) rect(x0, y0, w, h int, c rgb) {
if x0 >= x1 || y0 >= y1 {
return
}
v := pixel(c)
span := make([]byte, (y1-y0)*4)
for i := 0; i+4 <= len(span); i += 4 {
span[i+0] = byte(v)
span[i+1] = byte(v >> 8)
span[i+2] = byte(v >> 16)
span[i+3] = byte(v >> 24)
}
span := fb.pixelRun((y1-y0)*4, c)
for x := x0; x < x1; x++ {
copy(fb.back[fb.offset(x, y1-1):], span)
}