Documentation
¶
Overview ¶
Package extimage draws pictures that live outside Go's image types: frames a decoder or another GPU device produced (a Linux DMA-BUF, a macOS IOSurface) and pixels an application edits in place. It is the fork's hardware contract, defined before any driver: a Frame describes one picture and its ownership, Caps says what a window can draw and how, and each GPU API imports frames behind one driver interface (gpu/internal/driver.ExternalImporter), the CPU path being one of those drivers.
Ownership: a Frame is immutable once made and carries one reference count. Every holder (an application's stream, a recorded op, each GPU texture-cache entry) takes a reference and drops it; the producer's release function runs exactly once, when the last is dropped, outside every lock of this package. A producer's file descriptors and surfaces are borrowed, never closed or released by the window.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("extimage: frame not in the window's caps")
ErrUnsupported reports a frame no tuple of the window's Caps matches.
Functions ¶
This section is empty.
Types ¶
type Caps ¶
type Caps struct {
// Gen changes when the device or the renderer changes; read Caps again then.
Gen uint64
// Driver is the device's importer: "vulkan", "metal", or "cpu" when there is none.
Driver string
// DeviceID is the GPU's identity (Vulkan's deviceUUID; Metal's registryID, in the first 8
// bytes), so a producer can render on the same GPU; zero for "cpu".
DeviceID [16]byte
Tuples []Tuple
}
Caps is what one window draws. A frame matching no tuple is refused, never handed to a driver that cannot take it.
type Color ¶
Color is a YUV frame's encoding; ignored for RGB formats. The zero value is BT.709, limited.
type Desc ¶
type Desc struct {
Kind Kind
Format Format
Color Color
Size image.Point
// Planes, for KindMemory and KindDMABuf: one per plane of Format.
Planes []Plane
// Modifier is the DRM format modifier of a KindDMABuf frame (0 is DRM_FORMAT_MOD_LINEAR).
Modifier uint64
// IOSurface is a KindIOSurface frame's IOSurfaceRef, borrowed: an importer that keeps it
// retains it.
IOSurface uintptr
// Source names the image this frame is a revision of; 0 for none.
Source SourceID
// Rev is this frame's revision of Source, strictly increasing. Base is the revision Dirty is
// relative to: Dirty covers every pixel that differs between revision Base and Rev, in frame
// pixels, empty meaning all of them. An importer whose texture for the Source is at revision
// Base exactly, with the same Size, Format, Color and device, may upload only Dirty; any
// other state uploads the whole frame. Only KindMemory frames honour it.
Rev, Base uint64
Dirty image.Rectangle
}
Desc describes a frame's memory. NewFrame copies it: a Frame never changes.
type Format ¶
type Format uint8
Format is a frame's pixel layout. The set is open: a new format is a new value plus the tuples a driver proves for it, and a frame in a format no driver lists is refused.
const ( // FormatRGBA8: one plane, 4 bytes a pixel, R G B A, sRGB. FormatRGBA8 Format = iota + 1 // FormatBGRA8: one plane, 4 bytes a pixel, B G R A, sRGB. FormatBGRA8 // FormatNV12: two planes, Y (1 byte a pixel) and interleaved CbCr (2 bytes per 2×2 pixels), // encoded as Desc.Color says. FormatNV12 )
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is one picture to draw: a Desc and its lease. It must be complete when made: no work that writes its memory may still be running.
func NewFrame ¶
NewFrame validates d and returns a frame holding one reference, the producer's: hand it to a stream (or an ImageOp writer that keeps a reference) and do not use it after. release runs exactly once, when the last reference is dropped; it must not block.
func (*Frame) Desc ¶
Desc is the frame's description. Its Planes are the frame's own copy: do not modify them.
type ImageOp ¶
type ImageOp struct {
Filter paint.ImageFilter
// contains filtered or unexported fields
}
ImageOp draws a Frame as paint.ImageOp draws an image: it sets the brush to the frame, in pixel units of its Size, for a following paint.PaintOp.
The op itself holds no reference. Its writer keeps the frame alive until the ops are handed to the window and its Frame call returns; the renderer takes its own reference while it imports the frame, and its texture cache holds one for as long as it keeps the texture.
func NewImageOp ¶
NewImageOp is the brush for f. report, if not nil, is told the outcome of each import: nil, or the error that kept the frame from being drawn. It is called on the window's GPU goroutine and must not block.
type Plane ¶
type Plane struct {
// Data is the plane's bytes, for KindMemory.
Data []byte
// FD is a dma-buf file descriptor, for KindDMABuf. It is borrowed: the window never closes
// it. An importer that needs its own duplicates it.
FD int
// Offset is where the plane starts in its memory, in bytes.
Offset uint32
// Pitch is the bytes from one row of the plane to the next.
Pitch uint32
}
Plane is one plane of a frame's pixels.