restorable: Remove Images()

This commit is contained in:
Hajime Hoshi 2017-05-04 00:08:07 +09:00
parent 8b48d010ed
commit 951e5bccef
2 changed files with 16 additions and 8 deletions

View File

@ -161,11 +161,11 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int
if err := c.initializeIfNeeded(context); err != nil {
return err
}
if err := restorable.Images().ResolveStalePixels(context); err != nil {
if err := restorable.ResolveStalePixels(context); err != nil {
return err
}
for i := 0; i < updateCount; i++ {
restorable.Images().ClearVolatileImages()
restorable.ClearVolatileImages()
setRunningSlowly(i < updateCount-1)
if err := c.f(c.offscreen); err != nil {
return err
@ -186,7 +186,7 @@ func (c *graphicsContext) restore(context *opengl.Context) error {
if err := graphics.Reset(context); err != nil {
return err
}
if err := restorable.Images().Restore(context); err != nil {
if err := restorable.Restore(context); err != nil {
return err
}
c.invalidated = false

View File

@ -30,8 +30,16 @@ var theImages = &images{
images: map[*Image]struct{}{},
}
func Images() *images {
return theImages
func ResolveStalePixels(context *opengl.Context) error {
return theImages.resolveStalePixels(context)
}
func Restore(context *opengl.Context) error {
return theImages.restore(context)
}
func ClearVolatileImages() {
theImages.clearVolatileImages()
}
func (i *images) add(img *Image) {
@ -46,7 +54,7 @@ func (i *images) remove(img *Image) {
delete(i.images, img)
}
func (i *images) ResolveStalePixels(context *opengl.Context) error {
func (i *images) resolveStalePixels(context *opengl.Context) error {
i.m.Lock()
defer i.m.Unlock()
i.lastChecked = nil
@ -74,7 +82,7 @@ func (i *images) resetPixelsIfDependingOn(target *Image) {
}
}
func (i *images) Restore(context *opengl.Context) error {
func (i *images) restore(context *opengl.Context) error {
i.m.Lock()
defer i.m.Unlock()
// Framebuffers/textures cannot be disposed since framebuffers/textures that
@ -102,7 +110,7 @@ func (i *images) Restore(context *opengl.Context) error {
return nil
}
func (i *images) ClearVolatileImages() {
func (i *images) clearVolatileImages() {
i.m.Lock()
defer i.m.Unlock()
for img := range i.images {