mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
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:
+15
-8
@@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user