diff --git a/internal/graphics/opengl/context_mobile.go b/internal/graphics/opengl/context_mobile.go index 5c24e5c3c..f39ba1a98 100644 --- a/internal/graphics/opengl/context_mobile.go +++ b/internal/graphics/opengl/context_mobile.go @@ -41,11 +41,9 @@ func (p Program) id() programID { } type context struct { - gl mgl.Context - worker mgl.Worker - initialized chan struct{} - screenFramebufferWidth int - screenFramebufferHeight int + gl mgl.Context + worker mgl.Worker + initialized chan struct{} } func NewContext() (*Context, error) { @@ -81,22 +79,11 @@ func NewContext() (*Context, error) { c.BlendFunc(CompositeModeSourceOver) f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING) c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)}) - // It is invalid to get the size of the deafult framebuffer. - if c.screenFramebuffer.Value != 0 { - width := c.gl.GetRenderbufferParameteri(mgl.RENDERBUFFER, mgl.RENDERBUFFER_WIDTH) - height := c.gl.GetRenderbufferParameteri(mgl.RENDERBUFFER, mgl.RENDERBUFFER_HEIGHT) - c.screenFramebufferWidth = width - c.screenFramebufferHeight = height - } close(c.initialized) }() return c, nil } -func (c *Context) ScreenFramebufferSize() (int, int) { - return c.screenFramebufferWidth, c.screenFramebufferHeight -} - func (c *Context) Resume() error { c.locationCache = newLocationCache() c.lastFramebuffer = invalidFramebuffer diff --git a/internal/ui/ui_android.go b/internal/ui/ui_android.go new file mode 100644 index 000000000..565c9a7a7 --- /dev/null +++ b/internal/ui/ui_android.go @@ -0,0 +1,19 @@ +// Copyright 2016 Hajime Hoshi +// +// 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 ui + +func deviceScale() int { + return 1 +} diff --git a/internal/ui/ui_ios.go b/internal/ui/ui_ios.go new file mode 100644 index 000000000..52a059e70 --- /dev/null +++ b/internal/ui/ui_ios.go @@ -0,0 +1,31 @@ +// Copyright 2016 Hajime Hoshi +// +// 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. + +// +build ios darwin,arm darwin,arm64 + +package ui + +// #cgo CFLAGS: -x objective-c +// #cgo LDFLAGS: -framework Foundation -framework UIKit +// +// #import +// +// static int devicePixelRatio() { +// return [[UIScreen mainScreen] scale]; +// } +import "C" + +func deviceScale() int { + return int(C.devicePixelRatio()) +} diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index e9d3d0ddf..378a89b72 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -74,11 +74,10 @@ loop: } type userInterface struct { - width int - height int - scale int - framebufferScale int - sizeChanged bool + width int + height int + scale int + sizeChanged bool } var ( @@ -147,17 +146,7 @@ func (u *userInterface) ScreenScale() int { } func (u *userInterface) actualScreenScale() int { - if u.framebufferScale == 0 { - width, _ := glContext.ScreenFramebufferSize() - if width == 0 { - // Android - u.framebufferScale = 1 - } else { - // iOS - u.framebufferScale = width / u.width - } - } - return u.scale * u.framebufferScale + return u.scale * deviceScale() } func UpdateTouches(touches []Touch) {