stream

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT, MIT, Unlicense Imports: 3 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 stream is the state shared by paint.Stream (producer and layout) and the GPU renderer (consumer). giokit patch.

Index

Constants

View Source
const (
	ImportUnknown     = iota // no DMA-BUF frame drawn yet
	ImportSupported          // DMA-BUF frames are drawn without a copy
	ImportUnsupported        // this renderer cannot import: send CPU frames
)

Import states, reported by the renderer.

Variables

This section is empty.

Functions

This section is empty.

Types

type DMABuf

type DMABuf struct {
	// ID identifies the buffer across frames: a producer cycling through a
	// fixed set of buffers reuses IDs, and the renderer reuses its import.
	// It must change whenever the buffer behind it does.
	ID            uint64
	FD            int
	Offset, Pitch uint32
	Fourcc        uint32
	Modifier      uint64
	Width, Height int
}

DMABuf describes a single-plane image in GPU memory (Linux DMA-BUF).

type Frame

type Frame struct {
	Img     *image.RGBA
	DMA     *DMABuf
	Release func() // called once the stream no longer needs the frame; may be nil
}

Frame is one image submitted to a stream: CPU pixels or a DMA-BUF.

type Stream

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

Stream holds the newest frame. The renderer uploads (or imports) it into a texture it keeps per stream, and only when Seq has moved on.

Imported frames are sampled for as long as they are on screen, so a renderer holds the frame it has bound: such a frame is released when the last renderer holding it lets go, not when a newer frame replaces it. Several renderers (one per window) may draw the same stream; holds are counted, and each Hold must be balanced by one Unhold of the same sequence number.

A frame's Release function runs exactly once, without the stream's lock held, on the goroutine that ends the stream's need for the frame: the producer's in Submit or Close, or a renderer's in Use or Unhold. It must therefore be safe to call from any goroutine and should not block.

The zero Stream is empty and ready to use.

func (*Stream) Close

func (s *Stream) Close()

Close empties the stream for good: the current frame is released (once no renderer holds it) and later frames are refused. Frames still held are released when their renderers Unhold them, which happens at the latest when a renderer drops the stream's texture after a frame that does not draw it. Close may be called more than once and from any goroutine.

func (*Stream) ImportState

func (s *Stream) ImportState() int

ImportState reports whether the renderer imports DMA-BUF frames.

func (*Stream) SetImportState

func (s *Stream) SetImportState(v int)

SetImportState records the renderer's capability.

func (*Stream) Size

func (s *Stream) Size() image.Point

Size is the current frame's size.

func (*Stream) Submit

func (s *Stream) Submit(f Frame) bool

Submit makes f the current frame and releases the previous one unless a renderer holds it. It waits for an upload in progress, so a released frame is never mid-copy. Submitting an empty Frame releases the current frame and leaves the stream drawing nothing.

After Close, Submit releases f immediately and reports false; otherwise it reports true.

func (*Stream) Unhold

func (s *Stream) Unhold(seq uint64)

Unhold is Use.Unhold outside a Use: for a renderer dropping its texture.

func (*Stream) Use

func (s *Stream) Use(fn func(u *Use))

Use calls fn with the current frame and its sequence number, holding the stream's lock so the frame cannot be released during fn. Inside fn, the renderer may Hold the current frame and Unhold one it held before. Frames whose last hold ends in fn are released after the lock is dropped.

type Use

type Use struct {
	Frame Frame
	Seq   uint64
	// contains filtered or unexported fields
}

Use is the renderer's view of the stream during Stream.Use. It is valid only inside the function passed to Use.

func (*Use) Hold

func (u *Use) Hold()

Hold keeps the current frame from being released until a matching Unhold. Each renderer holds a given frame at most once.

func (*Use) Unhold

func (u *Use) Unhold(seq uint64)

Unhold ends one hold of the frame with sequence number seq. When its last hold ends, the frame is released (after Use returns) unless it is still the current frame. Unholding a frame that is not held does nothing.

Jump to

Keyboard shortcuts

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