forked from joejulian/gio
45da52cee7
The app and app/internal/wm packages are tightly coupled, requiring quite a bit of forwarding types, values and constants from the internal package to export it. Further, no other package imports package wm. This change merges the two packages. While here, drop the pre-Go 1.14 SIGPIPE workaround. Signed-off-by: Elias Naur <mail@eliasnaur.com>
58 lines
1009 B
Go
58 lines
1009 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package app
|
|
|
|
/*
|
|
#include <android/native_window_jni.h>
|
|
#include <EGL/egl.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"gioui.org/internal/egl"
|
|
)
|
|
|
|
type androidContext struct {
|
|
win *window
|
|
*egl.Context
|
|
}
|
|
|
|
func (w *window) NewContext() (context, error) {
|
|
ctx, err := egl.NewContext(nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &androidContext{win: w, Context: ctx}, nil
|
|
}
|
|
|
|
func (c *androidContext) Release() {
|
|
if c.Context != nil {
|
|
c.Context.Release()
|
|
c.Context = nil
|
|
}
|
|
}
|
|
|
|
func (c *androidContext) 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 *androidContext) Lock() error {
|
|
return c.Context.MakeCurrent()
|
|
}
|
|
|
|
func (c *androidContext) Unlock() {
|
|
c.Context.ReleaseCurrent()
|
|
}
|