mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
app/internal/window: [macOS] always draw synchronously
Asynchronous draws introduces flickering on resizes. Fixes #123 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -114,6 +114,11 @@ CFTypeRef gio_createGLView(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gio_setNeedsDisplay(CFTypeRef viewRef) {
|
||||||
|
NSOpenGLView *view = (__bridge NSOpenGLView *)viewRef;
|
||||||
|
[view setNeedsDisplay:YES];
|
||||||
|
}
|
||||||
|
|
||||||
CFTypeRef gio_contextForView(CFTypeRef viewRef) {
|
CFTypeRef gio_contextForView(CFTypeRef viewRef) {
|
||||||
NSOpenGLView *view = (__bridge NSOpenGLView *)viewRef;
|
NSOpenGLView *view = (__bridge NSOpenGLView *)viewRef;
|
||||||
return (__bridge CFTypeRef)view.openGLContext;
|
return (__bridge CFTypeRef)view.openGLContext;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ __attribute__ ((visibility ("hidden"))) CGFloat gio_viewHeight(CFTypeRef viewRef
|
|||||||
__attribute__ ((visibility ("hidden"))) CGFloat gio_getViewBackingScale(CFTypeRef viewRef);
|
__attribute__ ((visibility ("hidden"))) CGFloat gio_getViewBackingScale(CFTypeRef viewRef);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_readClipboard(void);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_readClipboard(void);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_writeClipboard(unichar *chars, NSUInteger length);
|
__attribute__ ((visibility ("hidden"))) void gio_writeClipboard(unichar *chars, NSUInteger length);
|
||||||
|
__attribute__ ((visibility ("hidden"))) void gio_setNeedsDisplay(CFTypeRef viewRef);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@@ -51,10 +52,7 @@ type window struct {
|
|||||||
stage system.Stage
|
stage system.Stage
|
||||||
displayLink *displayLink
|
displayLink *displayLink
|
||||||
|
|
||||||
// mu protect the following fields
|
scale float32
|
||||||
mu sync.Mutex
|
|
||||||
scale float32
|
|
||||||
width, height float32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// viewMap is the mapping from Cocoa NSViews to Go windows.
|
// viewMap is the mapping from Cocoa NSViews to Go windows.
|
||||||
@@ -193,13 +191,7 @@ func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy
|
|||||||
//export gio_onDraw
|
//export gio_onDraw
|
||||||
func gio_onDraw(view C.CFTypeRef) {
|
func gio_onDraw(view C.CFTypeRef) {
|
||||||
w := mustView(view)
|
w := mustView(view)
|
||||||
scale := float32(C.gio_getViewBackingScale(w.view))
|
w.draw()
|
||||||
width, height := float32(C.gio_viewWidth(w.view)), float32(C.gio_viewHeight(w.view))
|
|
||||||
w.mu.Lock()
|
|
||||||
w.scale = scale
|
|
||||||
w.width, w.height = width, height
|
|
||||||
w.mu.Unlock()
|
|
||||||
w.draw(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export gio_onFocus
|
//export gio_onFocus
|
||||||
@@ -214,16 +206,15 @@ func gio_onChangeScreen(view C.CFTypeRef, did uint64) {
|
|||||||
w.displayLink.SetDisplayID(did)
|
w.displayLink.SetDisplayID(did)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw(sync bool) {
|
func (w *window) draw() {
|
||||||
w.mu.Lock()
|
w.scale = float32(C.gio_getViewBackingScale(w.view))
|
||||||
wf, hf, scale := w.width, w.height, w.scale
|
wf, hf := float32(C.gio_viewWidth(w.view)), float32(C.gio_viewHeight(w.view))
|
||||||
w.mu.Unlock()
|
|
||||||
if wf == 0 || hf == 0 {
|
if wf == 0 || hf == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
width := int(wf*scale + .5)
|
width := int(wf*w.scale + .5)
|
||||||
height := int(hf*scale + .5)
|
height := int(hf*w.scale + .5)
|
||||||
cfg := configFor(scale)
|
cfg := configFor(w.scale)
|
||||||
cfg.now = time.Now()
|
cfg.now = time.Now()
|
||||||
w.setStage(system.StageRunning)
|
w.setStage(system.StageRunning)
|
||||||
w.w.Event(FrameEvent{
|
w.w.Event(FrameEvent{
|
||||||
@@ -234,7 +225,7 @@ func (w *window) draw(sync bool) {
|
|||||||
},
|
},
|
||||||
Config: &cfg,
|
Config: &cfg,
|
||||||
},
|
},
|
||||||
Sync: sync,
|
Sync: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +264,11 @@ func gio_onCreate(view C.CFTypeRef) {
|
|||||||
scale: scale,
|
scale: scale,
|
||||||
}
|
}
|
||||||
dl, err := NewDisplayLink(func() {
|
dl, err := NewDisplayLink(func() {
|
||||||
w.draw(false)
|
C.CFRetain(view)
|
||||||
|
runOnMain(func() {
|
||||||
|
defer C.CFRelease(view)
|
||||||
|
C.gio_setNeedsDisplay(view)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user