shareable: Remove InitializeGraphicsDriverState

This commit is contained in:
Hajime Hoshi 2019-08-25 17:28:59 +09:00
parent 3960a4bbdf
commit b53279b1e1
2 changed files with 10 additions and 20 deletions

View File

@ -145,6 +145,7 @@ var (
backendsM sync.Mutex
backendsOnce sync.Once
initOnce sync.Once
// theBackends is a set of actually shared images.
theBackends = []*backend{}
@ -583,12 +584,6 @@ func NewScreenFramebufferImage(width, height int) *Image {
return i
}
func InitializeGraphicsDriverState() error {
backendsM.Lock()
defer backendsM.Unlock()
return restorable.InitializeGraphicsDriverState()
}
func EndFrame() error {
backendsM.Lock()
restorable.ResolveStaleImages()
@ -613,6 +608,15 @@ func BeginFrame() error {
backendsM.Unlock()
}
}()
var err error
initOnce.Do(func() {
err = restorable.InitializeGraphicsDriverState()
})
if err != nil {
return err
}
return restorable.RestoreIfNeeded()
}

View File

@ -46,7 +46,6 @@ type uiContext struct {
screenWidth int
screenHeight int
screenScale float64
initialized bool
offsetX float64
offsetY float64
}
@ -75,25 +74,12 @@ func (c *uiContext) SetSize(screenWidth, screenHeight int, screenScale float64)
c.offsetY = py0
}
func (c *uiContext) initializeIfNeeded() error {
if !c.initialized {
if err := shareable.InitializeGraphicsDriverState(); err != nil {
return err
}
c.initialized = true
}
return nil
}
func (c *uiContext) Update(afterFrameUpdate func()) error {
tps := int(MaxTPS())
updateCount := clock.Update(tps)
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
if err := c.initializeIfNeeded(); err != nil {
return err
}
if err := shareable.BeginFrame(); err != nil {
return err
}