Documentation
¶
Overview ¶
Package stream is the state shared by paint.Stream (producer and layout) and the GPU renderer (consumer). giokit patch.
Index ¶
Constants ¶
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 ¶
ImportState reports whether the renderer imports DMA-BUF frames.
func (*Stream) SetImportState ¶
SetImportState records the renderer's capability.
func (*Stream) Submit ¶
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) 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.