restorable: Refactoring

Reduces accesses to Image member from outside.
This commit is contained in:
Hajime Hoshi 2019-07-21 16:38:16 +09:00
parent 434802af6e
commit b348223297
3 changed files with 11 additions and 11 deletions

View File

@ -182,6 +182,11 @@ func (i *Image) IsInvalidated() bool {
//
// This is for testing usage.
func (i *Image) Dump(path string) error {
// Screen image cannot be dumped.
if i.screen {
return nil
}
path = strings.ReplaceAll(path, "*", fmt.Sprintf("%d", i.id))
f, err := os.Create(path)
if err != nil {

View File

@ -476,7 +476,11 @@ func (i *Image) hasDependency() bool {
// Restore restores *graphicscommand.Image from the pixels using its state.
func (i *Image) restore() error {
w, h := i.image.Size()
w, h := i.Size()
// Dispose the internal image after getting its size for safety.
i.image.Dispose()
if i.screen {
// The screen image should also be recreated because framebuffer might
// be changed.

View File

@ -95,10 +95,7 @@ func RestoreIfNeeded() error {
// This is for testing usage.
func DumpImages(dir string) error {
for img := range theImages.images {
if img.screen {
continue
}
if err := img.image.Dump(filepath.Join(dir, "*.png")); err != nil {
if err := img.Dump(filepath.Join(dir, "*.png")); err != nil {
return err
}
}
@ -154,12 +151,6 @@ func (i *images) restore() error {
panic("restorable: restore cannot be called when restoring is disabled")
}
// Dispose image explicitly
for img := range i.images {
img.image.Dispose()
// img.image can't be set nil here, or Size() panics when restoring.
}
// Let's do topological sort based on dependencies of drawing history.
// It is assured that there are not loops since cyclic drawing makes images stale.
type edge struct {