From 23640ec38fd56a6ad7a09d2d2ce2ddd1481d5f37 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 12 Aug 2021 15:21:37 +0200 Subject: [PATCH] app,app/internal/wm: create contexts on the main thread Instead of handing the internal/wm driver a method to run code on the (blocked) main thread, just run the necessary driver methods on the main thread. Signed-off-by: Elias Naur --- app/internal/wm/gl_macos.go | 6 +----- app/internal/wm/window.go | 4 ---- app/window.go | 8 +++----- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/app/internal/wm/gl_macos.go b/app/internal/wm/gl_macos.go index cecf5baf..c18d0d42 100644 --- a/app/internal/wm/gl_macos.go +++ b/app/internal/wm/gl_macos.go @@ -40,11 +40,7 @@ func newContext(w *window) (*context, error) { if ctx == 0 { return nil, errors.New("gl: failed to create NSOpenGLContext") } - // [NSOpenGLContext setView] must run on the main thread. Fortunately, - // newContext is only called during a [NSView draw] on the main thread. - w.w.Run(func() { - C.gio_setContextView(ctx, view) - }) + C.gio_setContextView(ctx, view) c := &context{ ctx: ctx, view: view, diff --git a/app/internal/wm/window.go b/app/internal/wm/window.go index 7c602361..da30a8fb 100644 --- a/app/internal/wm/window.go +++ b/app/internal/wm/window.go @@ -60,10 +60,6 @@ type FrameEvent struct { type Callbacks interface { SetDriver(d Driver) Event(e event.Event) - // Func runs a function during an Event. This is required for platforms - // that require coordination between the rendering goroutine and the system - // main thread. - Run(f func()) } type Context interface { diff --git a/app/window.go b/app/window.go index 293d8cea..07345ff3 100644 --- a/app/window.go +++ b/app/window.go @@ -145,7 +145,9 @@ func (w *Window) validateAndProcess(driver wm.Driver, frameStart time.Time, size if w.loop == nil && !w.nocontext { var err error if w.ctx == nil { - w.ctx, err = driver.NewContext() + w.driverRun(func(_ wm.Driver) { + w.ctx, err = driver.NewContext() + }) if err != nil { return err } @@ -395,10 +397,6 @@ loop: } } -func (c *callbacks) Run(f func()) { - c.w.Run(f) -} - func (w *Window) waitAck() { // Send a dummy event; when it gets through we // know the application has processed the previous event.