From c76ce28065ac7afbe7aede047dd3d3ac60a1db83 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 28 Dec 2018 02:18:38 +0900 Subject: [PATCH] Revert "ui: Bug fix: SetVsyncEnabled before Run didn't work on macOS" This reverts commit 042b30a516a9ced07a8e3508ec396872a00bdf1a. --- internal/graphicsdriver/metal/driver.go | 11 ++------ internal/mainthread/mainthread.go | 37 +------------------------ internal/ui/ui_glfw.go | 1 + 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/internal/graphicsdriver/metal/driver.go b/internal/graphicsdriver/metal/driver.go index 52fc150e3..2ec154cad 100644 --- a/internal/graphicsdriver/metal/driver.go +++ b/internal/graphicsdriver/metal/driver.go @@ -233,11 +233,10 @@ type Driver struct { src *Image dst *Image - vsync bool maxImageSize int } -var theDriver = Driver{vsync: true} +var theDriver Driver func Get() *Driver { return &theDriver @@ -396,7 +395,7 @@ func (d *Driver) Reset() error { // MTLPixelFormatBGRA10_XR_sRGB. d.ml.SetPixelFormat(mtl.PixelFormatBGRA8UNorm) d.ml.SetMaximumDrawableCount(3) - d.ml.SetDisplaySyncEnabled(d.vsync) + d.ml.SetDisplaySyncEnabled(true) replaces := map[string]string{ "{{.FilterNearest}}": fmt.Sprintf("%d", graphics.FilterNearest), @@ -571,11 +570,7 @@ func (d *Driver) ResetSource() { } func (d *Driver) SetVsyncEnabled(enabled bool) { - mainthread.Run(func() error { - d.ml.SetDisplaySyncEnabled(enabled) - d.vsync = enabled - return nil - }) + d.ml.SetDisplaySyncEnabled(enabled) } func (d *Driver) VDirection() graphicsdriver.VDirection { diff --git a/internal/mainthread/mainthread.go b/internal/mainthread/mainthread.go index 30a50f62f..0648904a6 100644 --- a/internal/mainthread/mainthread.go +++ b/internal/mainthread/mainthread.go @@ -14,39 +14,16 @@ package mainthread -import ( - "runtime" - "sync" -) - -var ( - funcs chan func() - running bool - - m sync.Mutex -) - -func init() { - runtime.LockOSThread() -} +var funcs = make(chan func()) // Loop starts the main-thread loop. // // Loop must be called on the main thread. func Loop(ch <-chan error) error { - m.Lock() - funcs = make(chan func()) - m.Unlock() for { select { case f := <-funcs: - m.Lock() - running = true - m.Unlock() f() - m.Lock() - running = false - m.Unlock() case err := <-ch: // ch returns a value not only when an error occur but also it is closed. return err @@ -55,19 +32,7 @@ func Loop(ch <-chan error) error { } // Run calls f on the main thread. -// -// Run can be called even before Loop is called. -// -// Run can be called recursively: Run can be called from the function that are called via Run. func Run(f func() error) error { - // Even if funcs is nil, Run is called from the main thread (e.g. init) - m.Lock() - now := funcs == nil || running - m.Unlock() - if now { - return f() - } - ch := make(chan struct{}) var err error funcs <- func() { diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index f8669b1e8..b7966de29 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -76,6 +76,7 @@ var ( ) func init() { + runtime.LockOSThread() hideConsoleWindowOnWindows() if err := initialize(); err != nil { panic(err)