mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
internal/ui: bug fix: DeviceScaleFactor should be initialized asap on Android
Closes #2913
This commit is contained in:
parent
5f08bbf01c
commit
40f3cbe1e3
@ -176,9 +176,6 @@ func (u *UserInterface) update() error {
|
||||
renderEndCh <- struct{}{}
|
||||
}()
|
||||
|
||||
// The device scale factor can be obtained after the main function starts, especially on Android.
|
||||
theMonitor.initDeviceScaleFactorIfNeeded()
|
||||
|
||||
w, h := u.outsideSize()
|
||||
if err := u.context.updateFrame(u.graphicsDriver, w, h, theMonitor.DeviceScaleFactor(), u); err != nil {
|
||||
return err
|
||||
@ -197,11 +194,11 @@ func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||
// SetOutsideSize is concurrent safe.
|
||||
func (u *UserInterface) SetOutsideSize(outsideWidth, outsideHeight float64) {
|
||||
u.m.Lock()
|
||||
defer u.m.Unlock()
|
||||
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
|
||||
u.outsideWidth = outsideWidth
|
||||
u.outsideHeight = outsideHeight
|
||||
}
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *UserInterface) CursorMode() CursorMode {
|
||||
@ -268,6 +265,7 @@ func (u *UserInterface) Window() Window {
|
||||
|
||||
type Monitor struct {
|
||||
deviceScaleFactor float64
|
||||
deviceScaleFactorOnce sync.Once
|
||||
|
||||
m sync.Mutex
|
||||
}
|
||||
@ -278,19 +276,16 @@ func (m *Monitor) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Monitor) initDeviceScaleFactorIfNeeded() {
|
||||
// Assume that the device scale factor never changes on mobiles.
|
||||
m.m.Lock()
|
||||
defer m.m.Unlock()
|
||||
if m.deviceScaleFactor != 0 {
|
||||
return
|
||||
}
|
||||
m.deviceScaleFactor = deviceScaleFactorImpl()
|
||||
}
|
||||
|
||||
func (m *Monitor) DeviceScaleFactor() float64 {
|
||||
m.m.Lock()
|
||||
defer m.m.Unlock()
|
||||
|
||||
// The device scale factor can be obtained after the main function starts, especially on Android.
|
||||
// Initialize this lazily.
|
||||
m.deviceScaleFactorOnce.Do(func() {
|
||||
// Assume that the device scale factor never changes on mobiles.
|
||||
m.deviceScaleFactor = deviceScaleFactorImpl()
|
||||
})
|
||||
return m.deviceScaleFactor
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user