fb

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: MIT Imports: 10 Imported by: 0

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestImage

func NewTestImage(width, height int) *image.RGBA

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

func NewTestDevice(width, height, bpp int, rotate bool) *Device

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

func Open(dev string, rotate bool) (*Device, error)

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

func (fb *Device) BackBuffer() *image.RGBA

BackBuffer returns the non-active buffer for rendering.

func (*Device) Blit

func (fb *Device) Blit(img *image.RGBA)

Blit copies img to the framebuffer. Deprecated: use BackBuffer and Flip instead.

func (*Device) Close

func (fb *Device) Close()

Close unmaps the framebuffer memory.

func (*Device) Data

func (fb *Device) Data() []byte

Data returns the raw framebuffer bytes. Used by tests to inspect output.

func (*Device) Flip added in v1.1.0

func (fb *Device) Flip()

Flip copies the back buffer to the hardware framebuffer.

func (*Device) Height

func (fb *Device) Height() int

Height returns the display height in pixels.

func (*Device) Width

func (fb *Device) Width() int

Width returns the display width in pixels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL