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 ¶
- type Holder
- func (h *Holder) CPU() bool
- func (h *Holder) ClearWindow()
- func (h *Holder) Close()
- func (h *Holder) Closed() bool
- func (h *Holder) Handle() uintptr
- func (h *Holder) SetUser(u User)
- func (h *Holder) SetWindow(win uintptr, w, hgt int)
- func (h *Holder) UseCPU() bool
- func (h *Holder) Window() (win uintptr, w, hgt int, gen uint64)
- type User
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 (*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) SetUser ¶
SetUser sets the user DetachWindow is called on (nil: none). It does not call the previous user.
func (*Holder) SetWindow ¶
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 ¶
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).
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).