Documentation
¶
Overview ¶
Package eglrefs holds the reference counting behind the GLES backend's EGL lifetimes (ADR-077): a process-wide registry of initialized EGL displays, and the reference count of one EGL context.
The package has no EGL dependency. The EGL calls are injected, so the counting is tested on every OS while the backend that wires it in builds on Linux only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotAcquired = errors.New("eglrefs: release without a matching acquire")
ErrNotAcquired reports a release with no matching acquire: a reference counting bug in the caller.
Functions ¶
This section is empty.
Types ¶
type Refs ¶
type Refs struct {
// contains filtered or unexported fields
}
Refs is the reference count of an object that dies once, with its last reference, and never comes back: an EGL context and the GL objects in it.
The zero value holds one reference, its creator's. Acquire adds one while the object is alive; Release drops one and reports the last. The lock guards the count only and is never held across work on the object, so bookkeeping never waits behind a GL call.
func (*Refs) Acquire ¶
Acquire takes one more reference and reports whether it did: false once the last reference was released.
type Registry ¶
type Registry[K comparable, V any] struct { // contains filtered or unexported fields }
Registry counts the users of each EGL display in the process, so that eglTerminate runs only when the last of them goes.
Every eglGetPlatformDisplay call for the same native display returns the same EGLDisplay, and eglTerminate on it invalidates every context and surface of that display for all its users. Rust wgpu-hal keeps the same count (DISPLAYS_REFERENCE_COUNT in wgpu-hal/src/gles/egl.rs, keyed by EGLDisplay). The count covers wgpu's own users only.
func NewRegistry ¶
func NewRegistry[K comparable, V any](initialize func(K) (V, error), terminate func(K) error) *Registry[K, V]
NewRegistry returns a Registry that calls initialize on every acquire and terminate on the last release of a display.
func (*Registry[K, V]) Acquire ¶
Acquire counts one more user of display and initializes it, returning what initialize returned (eglInitialize on an initialized display only reports its version). The lock is held across the call, so it cannot interleave with the terminate of the last release, as in Rust.
When initialize fails, the count is rolled back and nothing is terminated. Rust leaves the count incremented; rolling back keeps a display nobody initialized out of the registry.