mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 07:57:29 +00:00
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>
This commit is contained in:
@@ -71,6 +71,10 @@ func (c *d3d11Context) Present() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *d3d11Context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *d3d11Context) MakeCurrent() error {
|
||||
var width, height int
|
||||
c.win.w.Run(func() {
|
||||
|
||||
@@ -34,6 +34,10 @@ func (c *context) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
var (
|
||||
|
||||
@@ -48,6 +48,10 @@ func (c *context) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
if c.eglWin != nil {
|
||||
|
||||
@@ -34,6 +34,10 @@ func (c *glContext) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *glContext) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *glContext) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
var (
|
||||
|
||||
@@ -31,6 +31,10 @@ func (c *x11Context) Release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *x11Context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *x11Context) MakeCurrent() error {
|
||||
c.Context.ReleaseSurface()
|
||||
win, width, height := c.win.window()
|
||||
|
||||
@@ -100,6 +100,10 @@ func (c *context) Lock() {}
|
||||
|
||||
func (c *context) Unlock() {}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
if C.gio_makeCurrent(c.ctx) == 0 {
|
||||
return errors.New("[EAGLContext setCurrentContext] failed")
|
||||
|
||||
@@ -54,6 +54,10 @@ func (c *context) Lock() {}
|
||||
|
||||
func (c *context) Unlock() {}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createGLContext(void);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_setContextView(CFTypeRef ctx, CFTypeRef view);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_makeCurrentContext(CFTypeRef ctx);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_updateContext(CFTypeRef ctx);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_flushContextBuffer(CFTypeRef ctx);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_clearCurrentContext(void);
|
||||
__attribute__ ((visibility ("hidden"))) void gio_lockContext(CFTypeRef ctxRef);
|
||||
@@ -74,6 +75,13 @@ func (c *context) Unlock() {
|
||||
C.gio_unlockContext(c.ctx)
|
||||
}
|
||||
|
||||
func (c *context) Refresh() error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
C.gio_updateContext(c.ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) MakeCurrent() error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
@@ -8,20 +8,6 @@
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include "_cgo_export.h"
|
||||
|
||||
@interface GioGLContext : NSOpenGLContext
|
||||
@end
|
||||
|
||||
@implementation GioGLContext
|
||||
- (void) notifyUpdate:(NSNotification*)notification {
|
||||
CGLLockContext([self CGLContextObj]);
|
||||
[self update];
|
||||
CGLUnlockContext([self CGLContextObj]);
|
||||
}
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
@end
|
||||
|
||||
CFTypeRef gio_createGLContext(void) {
|
||||
@autoreleasepool {
|
||||
NSOpenGLPixelFormatAttribute attr[] = {
|
||||
@@ -36,20 +22,16 @@ CFTypeRef gio_createGLContext(void) {
|
||||
};
|
||||
NSOpenGLPixelFormat *pixFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
|
||||
|
||||
GioGLContext *ctx = [[GioGLContext alloc] initWithFormat:pixFormat shareContext: nil];
|
||||
NSOpenGLContext *ctx = [[NSOpenGLContext alloc] initWithFormat:pixFormat shareContext: nil];
|
||||
return CFBridgingRetain(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
void gio_setContextView(CFTypeRef ctxRef, CFTypeRef viewRef) {
|
||||
GioGLContext *ctx = (__bridge GioGLContext *)ctxRef;
|
||||
NSOpenGLContext *ctx = (__bridge NSOpenGLContext *)ctxRef;
|
||||
NSView *view = (__bridge NSView *)viewRef;
|
||||
[view setWantsBestResolutionOpenGLSurface:YES];
|
||||
[ctx setView:view];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:ctx
|
||||
selector:@selector(notifyUpdate:)
|
||||
name:NSViewGlobalFrameDidChangeNotification
|
||||
object:view];
|
||||
}
|
||||
|
||||
void gio_clearCurrentContext(void) {
|
||||
@@ -58,6 +40,13 @@ void gio_clearCurrentContext(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void gio_updateContext(CFTypeRef ctxRef) {
|
||||
@autoreleasepool {
|
||||
NSOpenGLContext *ctx = (__bridge NSOpenGLContext *)ctxRef;
|
||||
[ctx update];
|
||||
}
|
||||
}
|
||||
|
||||
void gio_makeCurrentContext(CFTypeRef ctxRef) {
|
||||
@autoreleasepool {
|
||||
NSOpenGLContext *ctx = (__bridge NSOpenGLContext *)ctxRef;
|
||||
|
||||
@@ -6,9 +6,10 @@ package wm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gioui.org/io/key"
|
||||
"image/color"
|
||||
|
||||
"gioui.org/io/key"
|
||||
|
||||
"gioui.org/gpu"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/pointer"
|
||||
@@ -69,6 +70,7 @@ type Context interface {
|
||||
API() gpu.API
|
||||
Present() error
|
||||
MakeCurrent() error
|
||||
Refresh() error
|
||||
Release()
|
||||
Lock()
|
||||
Unlock()
|
||||
|
||||
Reference in New Issue
Block a user