diff --git a/imageimpl.go b/imageimpl.go index 6aeba9d65..60ada258b 100644 --- a/imageimpl.go +++ b/imageimpl.go @@ -30,7 +30,6 @@ import ( type imageImpl struct { disposed bool restorable *restorable.Image - screen bool m sync.Mutex } @@ -82,7 +81,6 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) { } i := &imageImpl{ restorable: img, - screen: true, } runtime.SetFinalizer(i, (*imageImpl).Dispose) return i, nil @@ -215,13 +213,7 @@ func (i *imageImpl) restore(context *opengl.Context) error { if i.disposed { return nil } - if i.screen { - if err := i.restorable.RestoreAsScreen(); err != nil { - return err - } - return nil - } - if err := i.restorable.RestoreImage(context); err != nil { + if err := i.restorable.Restore(context); err != nil { return err } return nil diff --git a/internal/restorable/image.go b/internal/restorable/image.go index e0620e665..9927c8875 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -45,6 +45,7 @@ type Image struct { stale bool volatile bool + screen bool } func NewImage(width, height int, filter opengl.Filter, volatile bool) (*Image, error) { @@ -87,6 +88,7 @@ func NewScreenFramebufferImage(width, height int) (*Image, error) { width: width, height: height, volatile: true, + screen: true, }, nil } @@ -229,7 +231,21 @@ func (p *Image) HasDependency() bool { } // RestoreImage restores *graphics.Image from the pixels using its state. -func (p *Image) RestoreImage(context *opengl.Context) error { +func (p *Image) Restore(context *opengl.Context) error { + if p.screen { + // The screen image should also be recreated because framebuffer might + // be changed. + var err error + p.image, err = graphics.NewScreenFramebufferImage(p.width, p.height) + if err != nil { + return err + } + p.basePixels = nil + p.baseColor = color.RGBA{} + p.drawImageHistory = nil + p.stale = false + return nil + } if p.volatile { var err error p.image, err = graphics.NewImage(p.width, p.height, p.filter) @@ -284,18 +300,6 @@ func (p *Image) RestoreImage(context *opengl.Context) error { return nil } -func (p *Image) RestoreAsScreen() error { - // The screen image should also be recreated because framebuffer might - // be changed. - var err error - p.image, err = graphics.NewScreenFramebufferImage(p.width, p.height) - if err != nil { - return err - } - // TODO: Reset other values? - return nil -} - func (p *Image) Dispose() error { if err := p.image.Dispose(); err != nil { return err