From 42566c6c9aeae76f4bbfa10c11de4c1991941bf2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 13 Nov 2022 15:18:44 +0900 Subject: [PATCH] internal/graphicsdriver/opengl: refactoring: remove SetCanvas --- internal/graphicsdriver/opengl/graphics_js.go | 8 ++------ internal/ui/ui_js.go | 15 ++++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/internal/graphicsdriver/opengl/graphics_js.go b/internal/graphicsdriver/opengl/graphics_js.go index 1f748449a..d8971ff70 100644 --- a/internal/graphicsdriver/opengl/graphics_js.go +++ b/internal/graphicsdriver/opengl/graphics_js.go @@ -18,11 +18,7 @@ import ( "syscall/js" ) -func (g *Graphics) init(_ any) error { - // Do nothing. +func (g *Graphics) init(canvas any) error { + g.context.canvas = canvas.(js.Value) return nil } - -func (g *Graphics) SetCanvas(canvas js.Value) { - g.context.canvas = canvas -} diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 76afc5bc8..f2e951eb5 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -26,15 +26,17 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/hooks" ) -type graphicsDriverCreatorImpl struct{} +type graphicsDriverCreatorImpl struct { + canvas js.Value +} func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) { graphics, err := g.newOpenGL() return graphics, GraphicsLibraryOpenGL, err } -func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) { - return opengl.NewGraphics(nil) +func (g *graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) { + return opengl.NewGraphics(g.canvas) } func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) { @@ -645,14 +647,13 @@ func (u *userInterfaceImpl) Run(game Game) error { } } u.running = true - g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}) + g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{ + canvas: canvas, + }) if err != nil { return err } u.graphicsDriver = g - if g, ok := u.graphicsDriver.(interface{ SetCanvas(js.Value) }); ok { - g.SetCanvas(canvas) - } return <-u.loop(game) }