From 31aa01131dac0366b59910c7dd458e505d29ebcf Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 13 Feb 2022 19:40:03 +0900 Subject: [PATCH] ebiten: refactoring: reduce call of ui.Get() --- internal/ui/context.go | 4 ++-- uicontext.go | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/ui/context.go b/internal/ui/context.go index 0954854e0..ae34992ac 100644 --- a/internal/ui/context.go +++ b/internal/ui/context.go @@ -27,7 +27,7 @@ import ( const DefaultTPS = 60 type Context interface { - UpdateOffscreen(outsideWidth, outsideHeight float64) (int, int) + UpdateOffscreen(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) UpdateFrame(updateCount int, screenScale float64, offsetX, offsetY float64) error } @@ -56,7 +56,7 @@ func (c *contextImpl) forceUpdateFrame(deviceScaleFactor float64) error { } func (c *contextImpl) updateFrameImpl(updateCount int, deviceScaleFactor float64) error { - ow, oh := c.context.UpdateOffscreen(c.outsideWidth, c.outsideHeight) + ow, oh := c.context.UpdateOffscreen(c.outsideWidth, c.outsideHeight, deviceScaleFactor) c.offscreenWidth = ow c.offscreenHeight = oh diff --git a/uicontext.go b/uicontext.go index 3bfabbb26..1ea3a19ce 100644 --- a/uicontext.go +++ b/uicontext.go @@ -42,15 +42,13 @@ func (c *uiContext) set(game Game) { c.game = game } -func (c *uiContext) UpdateOffscreen(outsideWidth, outsideHeight float64) (int, int) { - d := ui.Get().DeviceScaleFactor() - sw, sh := int(outsideWidth*d), int(outsideHeight*d) - +func (c *uiContext) UpdateOffscreen(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) { ow, oh := c.game.Layout(int(outsideWidth), int(outsideHeight)) if ow <= 0 || oh <= 0 { panic("ebiten: Layout must return positive numbers") } + sw, sh := int(outsideWidth*deviceScaleFactor), int(outsideHeight*deviceScaleFactor) if c.screen != nil { if w, h := c.screen.Size(); w != sw || h != sh { c.screen.Dispose() @@ -58,7 +56,7 @@ func (c *uiContext) UpdateOffscreen(outsideWidth, outsideHeight float64) (int, i } } if c.screen == nil { - c.screen = newScreenFramebufferImage(int(outsideWidth*d), int(outsideHeight*d)) + c.screen = newScreenFramebufferImage(sw, sh) } if c.offscreen != nil {