internal/graphicsdriver/metal, internal/graphicsdriver/opengl: change the return type to pointers

On second thought, returning pointers is more natural. Handling
nil is a caller's responsibility.
This commit is contained in:
Hajime Hoshi 2022-03-24 13:20:36 +09:00
parent 7bb7e45522
commit eeb5687b73
9 changed files with 43 additions and 19 deletions

View File

@ -367,7 +367,7 @@ func init() {
var theGraphics Graphics var theGraphics Graphics
func Get() graphicsdriver.Graphics { func Get() *Graphics {
if !isMetalAvailable { if !isMetalAvailable {
return nil return nil
} }

View File

@ -24,7 +24,7 @@ import (
var theGraphics Graphics var theGraphics Graphics
func Get() graphicsdriver.Graphics { func Get() *Graphics {
return &theGraphics return &theGraphics
} }

View File

@ -24,11 +24,14 @@ type graphicsDriverGetterImpl struct {
} }
func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics { func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get() return g.getOpenGL()
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {

View File

@ -27,12 +27,15 @@ import (
type graphicsDriverGetterImpl struct{} type graphicsDriverGetterImpl struct{}
func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics { func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get() return g.getOpenGL()
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {

View File

@ -242,11 +242,17 @@ func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
return metal.Get() if m := metal.Get(); m != nil {
return m
}
return nil
} }
// clearVideoModeScaleCache must be called from the main thread. // clearVideoModeScaleCache must be called from the main thread.

View File

@ -33,12 +33,15 @@ import (
type graphicsDriverGetterImpl struct{} type graphicsDriverGetterImpl struct{}
func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics { func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get() return g.getOpenGL()
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {

View File

@ -31,12 +31,15 @@ import (
type graphicsDriverGetterImpl struct{} type graphicsDriverGetterImpl struct{}
func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics { func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get() return g.getOpenGL()
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {

View File

@ -35,7 +35,10 @@ func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (g *graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (g *graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {

View File

@ -27,12 +27,15 @@ import (
type graphicsDriverGetterImpl struct{} type graphicsDriverGetterImpl struct{}
func (*graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics { func (g *graphicsDriverGetterImpl) getAuto() graphicsdriver.Graphics {
return opengl.Get() return g.getOpenGL()
} }
func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getOpenGL() graphicsdriver.Graphics {
return opengl.Get() if g := opengl.Get(); g != nil {
return g
}
return nil
} }
func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics { func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {