Documentation
¶
Overview ¶
Package fb drives a Linux framebuffer device such as /dev/fb0 using a single ioctl and mmap — no external dependencies, no DRM master required.
When to use this package ¶
fb is the simpler of the two display backends. It works on any Linux system with a framebuffer driver and requires no special privileges beyond read/write access to /dev/fb0. It is used as a fallback when the [drm] package cannot acquire DRM master (e.g. a desktop display server is running, or the kernel driver does not support modesetting).
The trade-off is performance: Blit must convert each pixel from Go's RGBA layout to the hardware format (RGB565 or XRGB8888), and software rotation requires writing pixels in reverse order. On a Raspberry Pi 2 at 800×480 this costs ~53 ms per frame at 16 bpp. See the [drm] package for a 32× faster alternative when DRM/KMS is available.
Features used ¶
- FBIOGET_VSCREENINFO ioctl — queries display geometry (width, height, bits-per-pixel) and per-channel bit-field offsets (red, green, blue, transp), which vary between drivers and colour depths.
- mmap on the device fd — maps the framebuffer directly into process memory for zero-copy pixel writes.
- Bayer 4×4 ordered dithering (16 bpp only) — adds a position-dependent threshold before quantising 8-bit channels to 5/6 bits, spreading quantisation error across a 4×4 tile and reducing colour banding on anti-aliased text.
- Software 180° rotation — when enabled at Open time, pixels are written in reverse row and column order.
References ¶
- Kernel header: include/uapi/linux/fb.h
- Kernel docs: https://www.kernel.org/doc/html/latest/fb/api.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestImage ¶
NewTestImage returns an RGBA image filled with a non-trivial pattern (R=x, G=y, B=x+y, A=255). Used by tests in this package.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device represents an open framebuffer device.
func NewTestDevice ¶
NewTestDevice constructs a Device backed by an in-memory buffer for use in tests. bpp must be 16 or 32; bit-field offsets are set to the standard RGB565 or XRGB8888 layout.
func Open ¶
Open opens the framebuffer device at dev, queries its geometry and pixel format, and maps the framebuffer into memory. Returns an error if the device cannot be opened, the ioctl fails, the mmap fails, or the pixel depth is not 16 or 32 bpp.
func (*Device) BackBuffer ¶ added in v1.1.0
BackBuffer returns the non-active buffer for rendering.
func (*Device) Blit ¶
Blit copies img to the framebuffer. Deprecated: use BackBuffer and Flip instead.