kms

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package kms lights every output of every DRM card on two linear XRGB8888 dumb buffers and flips frames to them with atomic commits, one per vblank, copying only what changed. It follows cards appearing and disappearing through kernel uevents, from a firmware framebuffer to the native driver.

Index

Constants

View Source
const BytesPerPixel = 4

BytesPerPixel is the size of a Frame's pixel.

Variables

View Source
var SystemPaths = Paths{Dev: "/dev/dri", Sysfs: "/sys/class/drm"}

SystemPaths are the kernel's: /dev/dri and /sys/class/drm.

Functions

func Blit

func Blit(dst, src Frame, r image.Rectangle, rot Rotation)

Blit copies rectangle r of the upright frame src into dst, turned by rot; dst is the scanout buffer, of size rot.View(src.Size) turned back.

Types

type Action

type Action uint8

Action is what a uevent reports happened to a device.

const (
	Other Action = iota
	Add
	Remove
	Change
)

The actions the splash follows; every other uevent action is Other.

type Card

type Card struct {
	// contains filtered or unexported fields
}

Card is one open DRM card and the outputs lit on it. The loop owns outputs, what it draws on, and the commit in req. Whatever probes or allocates, and with it crtcs, planes, built and retired, belongs to the card's worker: built are the outputs it holds buffers for and retired those the loop still has to stop drawing on.

func (*Card) Deactivate

func (c *Card) Deactivate() error

Deactivate drops DRM master and stops committing, leaving the last frame on screen for the next master.

func (*Card) Flipped

func (c *Card) Flipped(e drm.FlipEvent) error

Flipped hands the card a page-flip event read from its fd.

func (*Card) Name

func (c *Card) Name() string

Name is the card node's name, such as "card0".

func (*Card) Outputs

func (c *Card) Outputs() []*Output

Outputs are the card's lit outputs.

func (*Card) Reactivate

func (c *Card) Reactivate() error

Reactivate takes DRM master back and shows the splash again with a modeset, since the master in between may have changed the mode.

func (*Card) Release

func (c *Card) Release(retain bool) error

Release frees every output's buffers. With retain, the framebuffer on screen is closed with CLOSEFB so the frame outlives the process; an error wrapping drm.ErrNoCloseFB says the kernel could not keep it.

type Damage

type Damage struct {
	// contains filtered or unexported fields
}

Damage is the rectangles of a frame that changed, kept apart so that what lies between them is neither copied nor reported to the kernel. Rectangles never overlap; past the capacity the two that grow the least are merged.

func DamageOf

func DamageOf(rects ...image.Rectangle) Damage

DamageOf is the damage of rects.

func (*Damage) Add

func (d *Damage) Add(r image.Rectangle)

Add marks r as changed.

func (*Damage) Empty

func (d *Damage) Empty() bool

Empty says nothing changed.

func (*Damage) Intersect

func (d *Damage) Intersect(bounds image.Rectangle)

Intersect cuts the damage down to bounds.

func (*Damage) Merge

func (d *Damage) Merge(o *Damage)

Merge adds everything o marks.

func (*Damage) Rects

func (d *Damage) Rects() []image.Rectangle

Rects are the rectangles that changed.

type Display

type Display struct {
	// contains filtered or unexported fields
}

Display is every DRM card's outputs. It is not safe for concurrent use: one goroutine opens it, handles its events and draws, while a worker per card does whatever could keep that goroutine waiting.

func Open

func Open(paths Paths, log *slog.Logger) (*Display, error)

Open opens every card under paths and lights its outputs, then follows cards appearing and disappearing. A card that fails to open is logged and left out, unless another process is master of it, when it is tried again for a while; with none at all, Outputs is empty and the splash has no graphical output.

func (*Display) Close

func (d *Display) Close(retain bool) error

Close releases every card and stops following uevents. With retain, the frames on screen stay there after the process exits (see Card.Release).

func (*Display) Deactivate

func (d *Display) Deactivate() error

Deactivate drops DRM master on every card, leaving the frames on screen; cards that appear meanwhile are opened deactivated.

func (*Display) Events

func (d *Display) Events() <-chan Event

Events delivers what Handle applies.

func (*Display) Handle

func (d *Display) Handle(e Event) (bool, error)

Handle applies e and says whether Outputs changed: a flip lets its output show the next frame, a card that disappears is dropped at once, and what takes time, a card appearing or a hotplug, goes to the card's worker, whose result is another Event.

func (*Display) Outputs

func (d *Display) Outputs() []*Output

Outputs are every lit output, ordered by card and connector. The list is built once per change, and a change gives a new list.

func (*Display) Reactivate

func (d *Display) Reactivate() error

Reactivate takes DRM master back on every card and shows the splash again.

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event is something that happened to the display: a card's page flip, a uevent, something failing off the loop, or a card worker's result. Display.Handle applies it.

type FlipError

type FlipError struct {
	Output *Output
	Err    error
}

FlipError is a frame of Output that did not reach the display. The output keeps it, and its next Present sends it.

func (*FlipError) Error

func (e *FlipError) Error() string

func (*FlipError) Unwrap

func (e *FlipError) Unwrap() error

type Frame

type Frame struct {
	Pix    []byte
	Stride int
	Size   image.Point
}

Frame is 32-bit pixels in rows: little-endian ARGB8888 or XRGB8888, whose bytes are blue, green, red and alpha or padding.

type Output

type Output struct {
	// contains filtered or unexported fields
}

Output is one connector lit on a CRTC and its primary plane, drawn into an upright frame in memory and copied, turned, into two scanout buffers.

func (*Output) Frame

func (o *Output) Frame() Frame

Frame is the upright frame to draw into, kept between frames so that a redraw only touches what changed. Present shows it.

func (*Output) Name

func (o *Output) Name() string

Name is the connector's name, such as "eDP-1".

func (*Output) Present

func (o *Output) Present(damage Damage) error

Present shows the frame, of which only damage changed since the last Present. A frame presented while the previous one still waits for its vblank goes out on that vblank's flip event, so frames flip at most once per vblank.

func (*Output) Rotation

func (o *Output) Rotation() Rotation

Rotation is how the output's frame is turned onto its panel.

func (*Output) Scale

func (o *Output) Scale() int

Scale is the output's scale, 1 or 2.

type Paths

type Paths struct {
	Dev   string
	Sysfs string
}

Paths are where the display finds card nodes and their sysfs entries.

func (Paths) ClientsMustCloseBeforeRemoval

func (p Paths) ClientsMustCloseBeforeRemoval() (bool, error)

type Rotation

type Rotation uint8

Rotation is how a frame is turned on its way to a panel, so that a panel mounted sideways or upside down shows it upright.

const (
	Upright Rotation = iota
	UpsideDown
	Clockwise
	CounterClockwise
)

The rotations, following the connector's "panel orientation" as plymouth maps it: "Upside Down" turns the frame half way, "Left Side Up" counter clockwise and "Right Side Up" clockwise.

func (Rotation) Device

func (r Rotation) Device(view image.Point, v image.Rectangle) image.Rectangle

Device maps rectangle v of an upright frame of size view to the rectangle of the scanout buffer it lands on.

func (Rotation) String

func (r Rotation) String() string

func (Rotation) View

func (r Rotation) View(size image.Point) image.Point

View is the size of the upright frame shown on a scanout buffer of size.

type Scaler

type Scaler struct {
	// contains filtered or unexported fields
}

Scaler chooses each output's scale as plymouth does, except that once a firmware framebuffer forced a guess, the native driver's outputs keep the guessed value even when their mode differs, so the picture does not jump.

func (*Scaler) Scale

func (s *Scaler) Scale(size image.Point, mm [2]uint32, firmware bool) int

Scale is the scale of an output showing size pixels on a display of mm millimetres, as the connector reports it from EDID. A firmware framebuffer that does not know its display's size guesses from the resolution alone, and every later output takes the firmware's guess.

type Uevent

type Uevent struct {
	Action    Action
	DevPath   string
	Subsystem string
	DevName   string
	Hotplug   bool
}

Uevent is a kernel uevent about a device.

func ParseUevent

func ParseUevent(msg []byte) (Uevent, error)

ParseUevent reads one message from a NETLINK_KOBJECT_UEVENT socket: "ACTION@DEVPATH", then NUL-separated KEY=VALUE pairs. It fails on a message udev rebroadcasts, on a missing header and on an ACTION or DEVPATH pair that contradicts the header.

func (Uevent) Card

func (u Uevent) Card() (string, bool)

Card is the card node's name under /dev/dri, such as "card0", when the uevent is about a DRM card.

Jump to

Keyboard shortcuts

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