diff --git a/internal/devicescale/impl_js.go b/internal/devicescale/impl_js.go deleted file mode 100644 index 3f7c3db0f..000000000 --- a/internal/devicescale/impl_js.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2018 The Ebiten Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package devicescale - -import ( - "syscall/js" -) - -func impl(x, y int) float64 { - window := js.Global().Get("window") - if !window.Truthy() { - return 1 - } - ratio := window.Get("devicePixelRatio").Float() - if ratio == 0 { - ratio = 1 - } - return ratio -} diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 23f19db7b..fe7104fe2 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -21,7 +21,6 @@ import ( "syscall/js" "time" - "github.com/hajimehoshi/ebiten/v2/internal/devicescale" "github.com/hajimehoshi/ebiten/v2/internal/file" "github.com/hajimehoshi/ebiten/v2/internal/gamepad" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" @@ -95,7 +94,7 @@ type userInterfaceImpl struct { onceUpdateCalled bool lastCaptureExitTime time.Time - lastDeviceScaleFactor float64 + deviceScaleFactor float64 err error @@ -280,7 +279,16 @@ func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) { } func (u *userInterfaceImpl) DeviceScaleFactor() float64 { - return devicescale.GetAt(0, 0) + if u.deviceScaleFactor != 0 { + return u.deviceScaleFactor + } + + ratio := window.Get("devicePixelRatio").Float() + if ratio == 0 { + ratio = 1 + } + u.deviceScaleFactor = ratio + return u.deviceScaleFactor } func (u *userInterfaceImpl) outsideSize() (float64, float64) { @@ -354,11 +362,13 @@ func (u *userInterfaceImpl) updateImpl(force bool) error { return err } - a := u.DeviceScaleFactor() - if u.lastDeviceScaleFactor != a { + if !u.onceUpdateCalled { u.updateScreenSize() } - u.lastDeviceScaleFactor = a + + // TODO: If DeviceScaleFactor changes, call updateScreenSize. + // Now there is not a good way to detect the change. + // See also https://crbug.com/123694. w, h := u.outsideSize() if force { @@ -401,7 +411,9 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error { return } if u.needsUpdate() { - u.onceUpdateCalled = true + defer func() { + u.onceUpdateCalled = true + }() u.renderingScheduled = false if err := u.update(); err != nil { close(reqStopAudioCh)