Files
gio/app/internal/wm/egl_android.go
T
Elias Naur 0e592f8bc6 app,app/internal/wm: [macOS] refresh context on display change
The NSViewGlobalFrameDidChangeNotification notification is documented to
be fired every time [NSOpenGLContext update] needs to be called.
However, the notification fails to fire on my setup when a window is
moved to a display with a different pixel scale, which leads to
incorrectly sized output.

This change gets rid of the notification and updates the context before
every frame.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-06-12 20:07:52 +02:00

68 lines
1.2 KiB
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 {
return nil
}
func (c *context) MakeCurrent() error {
c.Context.ReleaseSurface()
var (
win *C.ANativeWindow
width, height int
)
// Run on main thread. Deadlock is avoided because MakeCurrent is only
// called during a FrameEvent.
c.win.callbacks.Run(func() {
win, width, height = c.win.nativeWindow(c.Context.VisualID())
})
if win == nil {
return nil
}
eglSurf := egl.NativeWindowType(unsafe.Pointer(win))
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
return err
}
if err := c.Context.MakeCurrent(); err != nil {
return err
}
return nil
}
func (c *context) Lock() {}
func (c *context) Unlock() {}