diff --git a/internal/devicescale/devicescale.go b/internal/devicescale/devicescale.go index 87d5e4188..470663834 100644 --- a/internal/devicescale/devicescale.go +++ b/internal/devicescale/devicescale.go @@ -22,10 +22,6 @@ var ( m sync.Mutex ) -func Get() float64 { - return GetAt(0, 0) -} - func GetAt(x, y int) float64 { m.Lock() defer m.Unlock() diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 849f03c47..b37333095 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -495,6 +495,21 @@ func SetWindowDecorated(decorated bool) { // return nil } +func DeviceScaleFactor() float64 { + f := 0.0 + u := currentUI + if !u.isRunning() { + return devicescale.GetAt(currentMonitor().GetPos()) + } + + _ = u.runOnMainThread(func() error { + m := u.currentMonitor() + f = devicescale.GetAt(m.GetPos()) + return nil + }) + return f +} + func Run(width, height int, scale float64, title string, g GraphicsContext, mainloop bool) error { u := currentUI // GLContext must be created before setting the screen size, which requires diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index dbba8c3ff..760d559d6 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -84,7 +84,7 @@ func getDeviceScale() float64 { defer deviceScaleM.Unlock() if deviceScaleVal == 0 { - deviceScaleVal = devicescale.Get() + deviceScaleVal = devicescale.GetAt(0, 0) } return deviceScaleVal } diff --git a/run.go b/run.go index 261bce8ef..02a9da1cc 100644 --- a/run.go +++ b/run.go @@ -23,7 +23,6 @@ import ( "sync/atomic" "github.com/hajimehoshi/ebiten/internal/clock" - "github.com/hajimehoshi/ebiten/internal/devicescale" "github.com/hajimehoshi/ebiten/internal/png" "github.com/hajimehoshi/ebiten/internal/shareable" "github.com/hajimehoshi/ebiten/internal/ui" @@ -528,7 +527,7 @@ func SetWindowIcon(iconImages []image.Image) { // // DeviceScaleFactor is concurrent-safe. func DeviceScaleFactor() float64 { - return devicescale.Get() + return ui.DeviceScaleFactor() } // IsVsyncEnabled returns a boolean value indicating whether