extimage

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT, Unlicense Imports: 7 Imported by: ? 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 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

View Source
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.

func (Caps) Match

func (c Caps) Match(d Desc) (Tuple, bool)

Match is the tuple d is drawn with: the zero-copy one if both paths list it.

type Color

type Color struct {
	Matrix Matrix
	Range  Range
}

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
)

func (Format) String

func (f Format) String() string

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 FrameOf

func FrameOf(refs []any) (*Frame, func(error))

FrameOf decodes an external image op's refs, for the renderer.

func NewFrame

func NewFrame(d Desc, release func()) (*Frame, error)

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

func (f *Frame) Desc() Desc

Desc is the frame's description. Its Planes are the frame's own copy: do not modify them.

func (*Frame) Drop

func (f *Frame) Drop()

Drop gives up a reference. The last Drop calls the producer's release, on the dropping goroutine; call it outside your own locks.

func (*Frame) Retain

func (f *Frame) Retain() *Frame

Retain takes a reference for a new holder and returns f.

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

func NewImageOp(f *Frame, report func(error)) ImageOp

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.

func (ImageOp) Add

func (i ImageOp) Add(o *op.Ops)

Add records the op.

func (ImageOp) Size

func (i ImageOp) Size() image.Point

Size is the frame's size in pixels.

type Kind

type Kind uint8

Kind is where a frame's pixels are.

const (
	// KindMemory: Planes' Data, in Go memory.
	KindMemory Kind = iota + 1
	// KindDMABuf: Linux dma-buf file descriptors, Planes' FD, Offset and Pitch, with Modifier.
	KindDMABuf
	// KindIOSurface: a macOS IOSurfaceRef.
	KindIOSurface
)

func (Kind) String

func (k Kind) String() string

type Matrix

type Matrix uint8

Matrix is a YUV frame's colour matrix.

const (
	MatrixBT709  Matrix = iota // HD; the zero value
	MatrixBT601                // SD
	MatrixBT2020               // UHD
)

type Path

type Path uint8

Path is how a tuple is drawn.

const (
	// PathZeroCopy: the device samples the frame's memory itself.
	PathZeroCopy Path = iota + 1
	// PathCPU: the CPU driver maps the frame and uploads it.
	PathCPU
)

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.

type Range

type Range uint8

Range is a YUV frame's quantisation range.

const (
	RangeLimited Range = iota // 16–235 (Y), 16–240 (CbCr); the zero value
	RangeFull                 // 0–255
)

type SourceID

type SourceID uint64

SourceID names a sequence of frames of one image, so successive frames can reuse a texture.

func NewSource

func NewSource() SourceID

NewSource returns a SourceID no other call in this process returns.

type Tuple

type Tuple struct {
	Kind     Kind
	Format   Format
	Modifier uint64 // KindDMABuf
	Path     Path
	MaxSize  image.Point // zero: no limit beyond the device's texture size
}

Tuple is one combination a window draws, as proven when its device was set up.

Jump to

Keyboard shortcuts

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