Documentation
¶
Overview ¶
Package capture defines the screen capture contract shared by the platform backends: DXGI Desktop Duplication on Windows, ScreenCaptureKit on macOS, and PipeWire or KMS on Linux.
Index ¶
Constants ¶
const ( FourccNV12 uint32 = 'N' | 'V'<<8 | '1'<<16 | '2'<<24 FourccP010 uint32 = 'P' | '0'<<8 | '1'<<16 | '0'<<24 FourccXRGB8888 uint32 = 'X' | 'R'<<8 | '2'<<16 | '4'<<24 FourccARGB8888 uint32 = 'A' | 'R'<<8 | '2'<<16 | '4'<<24 FourccXBGR8888 uint32 = 'X' | 'B'<<8 | '2'<<16 | '4'<<24 FourccABGR8888 uint32 = 'A' | 'B'<<8 | '2'<<16 | '4'<<24 )
DRM fourcc codes (drm_fourcc.h) of the layouts DMABuf carries.
const ( ModifierLinear uint64 = 0 ModifierInvalid uint64 = 1<<56 - 1 )
ModifierLinear is DRM_FORMAT_MOD_LINEAR; ModifierInvalid says the producer gave none, and the importer picks the driver's implicit one.
Variables ¶
var ErrAccessLost = errors.New("capture: access lost")
ErrAccessLost means the source must be reopened (mode change, secure desktop, fullscreen switch).
var ErrTimeout = errors.New("capture: no new frame")
ErrTimeout means no new image arrived in the wait window: the screen did not change. It is not a failure.
Functions ¶
This section is empty.
Types ¶
type DMABuf ¶ added in v0.2.0
type DMABuf struct {
Fourcc uint32
Modifier uint64
// Width and Height are the visible picture; the planes may be larger.
Width, Height int
Planes int
FDs [4]int32
Offsets [4]uint32
Pitches [4]uint32
CPU [4]unsafe.Pointer
// Memory says FDs are memfds holding the CPU planes, linear, which a
// Wayland compositor maps as wl_shm buffers.
Memory bool
// Serial tells pictures of one pool apart for a consumer that caches
// what it made of them; a producer changes it whenever the buffers
// behind the descriptor change.
Serial uint64
}
DMABuf is a picture on Linux: Frame.Surface, here and in package decode, points to one (see Handle and DMABufOf). Its producer owns it in a pool and keeps it, and its file descriptors, alive until the frame is released; consumers dup what they keep longer.
FDs hold the GPU buffer of each plane, which may be one object for all planes. CPU, when set, holds the same planes in memory, row by row at Pitches: a producer fills it when its consumer cannot import DMA-BUFs (an X11 window, a compositor drawing in software, a headless test). A picture can have CPU planes and no FDs at all.
func MemoryDMABuf ¶ added in v0.2.0
MemoryDMABuf describes planes in Go memory, rows at pitches, as a software source (a synthetic pattern, a test) hands them on. The caller keeps the descriptor, and so the planes, alive while frames point to it.
type Display ¶
type Display struct {
ID string
Name string
Adapter gpu.Adapter
// X and Y are the display's top-left corner on the desktop, in pixels
// (Windows; 0, 0 for the primary display).
X, Y int
Width int
Height int
Refresh float64
HDR bool
Primary bool
}
Display describes one capturable output.
type Frame ¶
type Frame struct {
Surface uintptr
Adapter gpu.LUID
Format Format
Width int
Height int
// Presented is when the compositor showed this image, on the monotonic
// clock of the platform (QPC on Windows, mach_absolute_time on macOS).
Presented time.Duration
// Acquired is when the source handed the frame to the caller, same clock.
Acquired time.Duration
// Dirty lists changed rectangles when the backend reports them; nil means
// the whole frame may have changed.
Dirty []Rect
}
Frame is a GPU surface owned by the source until Release is called on it. Surface is the platform handle: an ID3D11Texture2D* on Windows, a CVPixelBufferRef (IOSurface backed) on macOS.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cursor reads the host's system cursor: whether it shows, whether an app holds the mouse, and where it is.
|
Package cursor reads the host's system cursor: whether it shows, whether an app holds the mouse, and where it is. |
|
Package display lists the capturable displays of this machine and opens one with the platform's capture backend: DXGI Desktop Duplication on Windows, ScreenCaptureKit on macOS, and MIT-SHM or the desktop portal's PipeWire stream on Linux.
|
Package display lists the capturable displays of this machine and opens one with the platform's capture backend: DXGI Desktop Duplication on Windows, ScreenCaptureKit on macOS, and MIT-SHM or the desktop portal's PipeWire stream on Linux. |
|
Package dxgi captures a Windows display with DXGI Desktop Duplication.
|
Package dxgi captures a Windows display with DXGI Desktop Duplication. |
|
Package pipewire captures a Wayland desktop through the XDG desktop portal's ScreenCast interface: the portal asks the user which monitor to share (once, with a restore token after that) and hands over a PipeWire node, which a PipeWire stream (libpipewire-0.3, loaded with purego) consumes as DMA-BUFs or shared memory.
|
Package pipewire captures a Wayland desktop through the XDG desktop portal's ScreenCast interface: the portal asks the user which monitor to share (once, with a restore token after that) and hands over a PipeWire node, which a PipeWire stream (libpipewire-0.3, loaded with purego) consumes as DMA-BUFs or shared memory. |
|
Package sck captures a macOS display with ScreenCaptureKit through purego, with no cgo.
|
Package sck captures a macOS display with ScreenCaptureKit through purego, with no cgo. |
|
Package x11 captures an Xorg (or XWayland) screen with MIT-SHM: each frame is one XShmGetImage of a monitor's rectangle of the root window into shared memory, which the encoder reads in place.
|
Package x11 captures an Xorg (or XWayland) screen with MIT-SHM: each frame is one XShmGetImage of a monitor's rectangle of the root window into shared memory, which the encoder reads in place. |