From a1e868b822fc01956e7049a43155e2545e81092d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 26 Nov 2016 23:45:06 +0900 Subject: [PATCH] ui: Don't use 'image-rendering' CSS on Safari (#293) --- internal/ui/ui_js.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index adc4ce0e3..5b61354ab 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -18,6 +18,7 @@ package ui import ( "strconv" + "strings" "github.com/gopherjs/gopherjs/js" "github.com/hajimehoshi/ebiten/internal/opengl" @@ -287,6 +288,17 @@ func (u *userInterface) size() (width, height int) { return } +func isSafari() bool { + ua := js.Global.Get("navigator").Get("userAgent").String() + if !strings.Contains(ua, "Safari") { + return false + } + if strings.Contains(ua, "Chrome") { + return false + } + return true +} + func (u *userInterface) setScreenSize(width, height int, scale float64) bool { w, h := u.size() s := u.scale @@ -295,7 +307,8 @@ func (u *userInterface) setScreenSize(width, height int, scale float64) bool { } u.scale = scale // When the scale is an integer, let's rely on CSS crisp-edge/pixelated effect. - if scale == float64(int64(scale)) { + // Note that pixelated effect doesn't work for canvas on Safari. + if scale == float64(int64(scale)) && !isSafari() { u.deviceScale = 1 } else { u.deviceScale = devicePixelRatio()