app: [Android] work around broken EGL surfaces on the emulator

The Android emulator creates a broken EGL surface if it is not created
on the same thread as the context is made current.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-08-29 20:11:11 +02:00
parent 07e1df3676
commit fd008f39af
+15 -8
View File
@@ -15,7 +15,9 @@ import (
) )
type androidContext struct { type androidContext struct {
win *window win *window
eglSurf egl.NativeWindowType
width, height int
*egl.Context *egl.Context
} }
@@ -36,19 +38,24 @@ func (c *androidContext) Release() {
func (c *androidContext) Refresh() error { func (c *androidContext) Refresh() error {
c.Context.ReleaseSurface() c.Context.ReleaseSurface()
var ( win, width, height := c.win.nativeWindow(c.Context.VisualID())
win *C.ANativeWindow
width, height int
)
win, width, height = c.win.nativeWindow(c.Context.VisualID())
if win == nil { if win == nil {
return nil return nil
} }
eglSurf := egl.NativeWindowType(unsafe.Pointer(win)) c.eglSurf = egl.NativeWindowType(unsafe.Pointer(win))
return c.Context.CreateSurface(eglSurf, width, height) c.width, c.height = width, height
return nil
} }
func (c *androidContext) Lock() error { func (c *androidContext) Lock() error {
// The Android emulator creates a broken surface if it is not
// created on the same thread as the context is made current.
if c.eglSurf != nil {
if err := c.Context.CreateSurface(c.eglSurf, c.width, c.height); err != nil {
return err
}
c.eglSurf = nil
}
return c.Context.MakeCurrent() return c.Context.MakeCurrent()
} }