Files
gio/app/internal/wm/gl_js.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
import (
"errors"
"syscall/js"
"gioui.org/gpu"
"gioui.org/internal/gl"
)
type context struct {
ctx js.Value
cnv js.Value
}
func newContext(w *window) (*context, error) {
args := map[string]interface{}{
// Enable low latency rendering.
// See https://developers.google.com/web/updates/2019/05/desynchronized.
"desynchronized": true,
"preserveDrawingBuffer": true,
}
ctx := w.cnv.Call("getContext", "webgl2", args)
if ctx.IsNull() {
ctx = w.cnv.Call("getContext", "webgl", args)
}
if ctx.IsNull() {
return nil, errors.New("app: webgl is not supported")
}
c := &context{
ctx: ctx,
cnv: w.cnv,
}
return c, nil
}
func (c *context) API() gpu.API {
return gpu.OpenGL{Context: gl.Context(c.ctx)}
}
func (c *context) Release() {
}
func (c *context) Present() error {
if c.ctx.Call("isContextLost").Bool() {
return errors.New("context lost")
}
return nil
}
func (c *context) Lock() {}
func (c *context) Unlock() {}
func (c *context) Refresh() error {
return nil
}
func (c *context) MakeCurrent() error {
return nil
}
func (w *window) NewContext() (Context, error) {
return newContext(w)
}