Files
gio/app/internal/wm/egl_android.go
T
Elias Naur 0bdc2e0432 app,app/internal/wm: fold context MakeCurrent/ReleaseCurrent into Lock/Unlock
While here, make context Refresh useful and remove the redundant
MakeCurrent from the window loop.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-08-08 13:53:19 +02:00

58 lines
966 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
package wm
/*
#include <android/native_window_jni.h>
#include <EGL/egl.h>
*/
import "C"
import (
"unsafe"
"gioui.org/internal/egl"
)
type context struct {
win *window
*egl.Context
}
func (w *window) NewContext() (Context, error) {
ctx, err := egl.NewContext(nil)
if err != nil {
return nil, err
}
return &context{win: w, Context: ctx}, nil
}
func (c *context) Release() {
if c.Context != nil {
c.Context.Release()
c.Context = nil
}
}
func (c *context) Refresh() error {
c.Context.ReleaseSurface()
var (
win *C.ANativeWindow
width, height int
)
win, width, height = c.win.nativeWindow(c.Context.VisualID())
if win == nil {
return nil
}
eglSurf := egl.NativeWindowType(unsafe.Pointer(win))
return c.Context.CreateSurface(eglSurf, width, height)
}
func (c *context) Lock() error {
return c.Context.MakeCurrent()
}
func (c *context) Unlock() {
c.Context.ReleaseCurrent()
}