nativewindow

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 1 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 nativewindow is the hand-over point between a platform canvas that owns a native window (an Android ANativeWindow) and the OpenGL ES presenter that draws into it (gl.NewPresenterAndroid).

The window itself cannot be the presenter's target: Android replaces it whenever the app comes back from the background, a covered page is shown again or the Surface is recreated. So the canvas creates one Holder per GPU canvas and gives the presenter its Handle (platform.CanvasNativeWindow.UseNativeWindow); the canvas stores the current window in it and the presenter reads it on every present.

The presenter binds an EGL window surface to the window. An Android window can be connected to one producer at a time, and it must be let go before surfaceDestroyed returns, so the canvas tells the Holder synchronously before it gives a window up (ClearWindow, SetWindow with another window, Close) or locks it for a CPU frame (UseCPU): the Holder calls its User's DetachWindow first, which destroys the EGL surface.

Every method runs on the platform's main thread (Android's Looper thread: the canvas's JNI callbacks and the frames uihost draws there). The package is plain Go, with no platform code, so both sides can import it and it is tested on any host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Holder

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

Holder holds the current native window of one canvas. The zero value is not usable: create holders with New.

func Lookup

func Lookup(handle uintptr) *Holder

Lookup returns the live holder of handle, or nil (unknown, or closed).

func New

func New() *Holder

New creates a holder without a window and registers it.

func (*Holder) CPU

func (h *Holder) CPU() bool

CPU reports whether the current window was locked for a CPU frame.

func (*Holder) ClearWindow

func (h *Holder) ClearWindow()

ClearWindow forgets the window, detaching the user first (Android's surfaceDestroyed: call it before releasing the window).

func (*Holder) Close

func (h *Holder) Close()

Close detaches the user, forgets the window and unregisters the holder: Lookup no longer finds it and every method does nothing. Idempotent.

func (*Holder) Closed

func (h *Holder) Closed() bool

Closed reports whether Close was called.

func (*Holder) Handle

func (h *Holder) Handle() uintptr

Handle returns the holder's handle (never 0).

func (*Holder) SetUser

func (h *Holder) SetUser(u User)

SetUser sets the user DetachWindow is called on (nil: none). It does not call the previous user.

func (*Holder) SetWindow

func (h *Holder) SetWindow(win uintptr, w, hgt int)

SetWindow records the current window win (not 0) and its buffer size in device pixels. A different window than before detaches the user from the old one first and starts a new generation (the next present makes a new EGL surface); the same window only updates the size.

func (*Holder) UseCPU

func (h *Holder) UseCPU() bool

UseCPU is called before the canvas locks the window for a CPU frame. It detaches the user and marks the window as CPU-drawn: Android connects a locked window to the CPU until the Surface is destroyed, so no EGL surface can attach to it again. It reports whether a user was attached (the GPU was drawing into this window).

func (*Holder) Window

func (h *Holder) Window() (win uintptr, w, hgt int, gen uint64)

Window returns the current window (0: none), its buffer size and its generation, which changes whenever the window is replaced or cleared.

type User

type User interface {
	// DetachWindow releases everything bound to the current window (the
	// EGL surface) before it returns: the window is about to go away or
	// to be drawn by the CPU. The Holder's window is still the old one
	// while it runs. Main thread.
	DetachWindow()
}

User is the side drawing into a Holder's window (the presenter).

Jump to

Keyboard shortcuts

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