Files
gio/app/internal/wm/egl_windows.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

64 lines
1.1 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package wm
import (
"golang.org/x/sys/windows"
"gioui.org/internal/egl"
)
type glContext struct {
win *window
*egl.Context
}
func init() {
drivers = append(drivers, gpuAPI{
priority: 2,
initializer: func(w *window) (Context, error) {
disp := egl.NativeDisplayType(w.HDC())
ctx, err := egl.NewContext(disp)
if err != nil {
return nil, err
}
return &glContext{win: w, Context: ctx}, nil
},
})
}
func (c *glContext) Release() {
if c.Context != nil {
c.Context.Release()
c.Context = nil
}
}
func (c *glContext) Refresh() error {
return nil
}
func (c *glContext) MakeCurrent() error {
c.Context.ReleaseSurface()
var (
win windows.Handle
width, height int
)
c.win.w.Run(func() {
win, width, height = c.win.HWND()
})
eglSurf := egl.NativeWindowType(win)
if err := c.Context.CreateSurface(eglSurf, width, height); err != nil {
return err
}
if err := c.Context.MakeCurrent(); err != nil {
return err
}
c.Context.EnableVSync(true)
return nil
}
func (c *glContext) Lock() {}
func (c *glContext) Unlock() {}