mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
app/internal/window: [macOS] don't call Cococa from non-main thread
Only the synchronous draws from the main thread may involve changing width, height and scale. Introduce cached window.width and window.height fields and limits updates to main-thread draws. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -48,10 +48,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type window struct {
|
type window struct {
|
||||||
view C.CFTypeRef
|
view C.CFTypeRef
|
||||||
w Callbacks
|
w Callbacks
|
||||||
stage system.Stage
|
stage system.Stage
|
||||||
scale float32
|
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.
|
||||||
@@ -203,6 +204,8 @@ 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)
|
||||||
|
w.scale = float32(C.gio_getViewBackingScale(w.view))
|
||||||
|
w.width, w.height = float32(C.gio_viewWidth(w.view)), float32(C.gio_viewHeight(w.view))
|
||||||
w.draw(true)
|
w.draw(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,8 +216,7 @@ func gio_onFocus(view C.CFTypeRef, focus C.BOOL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw(sync bool) {
|
func (w *window) draw(sync bool) {
|
||||||
w.scale = float32(C.gio_getViewBackingScale(w.view))
|
wf, hf := w.width, w.height
|
||||||
wf, hf := float32(C.gio_viewWidth(w.view)), float32(C.gio_viewHeight(w.view))
|
|
||||||
if wf == 0 || hf == 0 {
|
if wf == 0 || hf == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user