eglrefs

package
v0.34.8 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 0

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

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

func (r *Refs) Acquire() bool

Acquire takes one more reference and reports whether it did: false once the last reference was released.

func (*Refs) Alive

func (r *Refs) Alive() bool

Alive reports whether the last reference is still held.

func (*Refs) Release

func (r *Refs) Release() (last bool, err error)

Release drops one reference. last is true for the release that drops the count to zero; it marks the object dead in the same critical section, so no Acquire can succeed after it. A release of a dead object returns ErrNotAcquired.

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

func (r *Registry[K, V]) Acquire(display K) (V, error)

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.

func (*Registry[K, V]) Release

func (r *Registry[K, V]) Release(display K) error

Release counts one user of display less and terminates it when that was the last one, under the lock. A release without an acquire returns ErrNotAcquired and terminates nothing. A terminate error is returned; the display leaves the registry either way.

Jump to

Keyboard shortcuts

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