diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 36c392075..f0ea0901b 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -55,13 +55,17 @@ type Image struct { w2 int h2 int + + // priority indicates whether the image is restored in high priority when context-lost happens. + priority bool } var dummyImage *Image func init() { dummyImage = &Image{ - image: graphicscommand.NewImage(16, 16), + image: graphicscommand.NewImage(16, 16), + priority: true, } theImages.add(dummyImage) } @@ -98,11 +102,7 @@ func NewScreenFramebufferImage(width, height int) *Image { func (i *Image) clear() { // There are not 'drawImageHistoryItem's for this image and dummyImage. - // This means dummyImage might not be restored yet when this image is restored. - // However, that's ok since this image will be stale or have its updated pixel data soon, - // and this image can be restored without dummyImage. - // - // dummyImage should be restored later anyway. + // As dummyImage is a priority image, this is restored faster than other regular images. w, h := i.Size() sw, sh := dummyImage.Size() dw := graphics.NextPowerOf2Int(w) diff --git a/internal/restorable/images.go b/internal/restorable/images.go index 113a3df36..6b7df54bb 100644 --- a/internal/restorable/images.go +++ b/internal/restorable/images.go @@ -164,7 +164,9 @@ func (i *images) restore() error { } images := map[*Image]struct{}{} for i := range i.images { - images[i] = struct{}{} + if !i.priority { + images[i] = struct{}{} + } } edges := map[edge]struct{}{} for t := range images { @@ -172,7 +174,13 @@ func (i *images) restore() error { edges[edge{source: s, target: t}] = struct{}{} } } + sorted := []*Image{} + for i := range i.images { + if i.priority { + sorted = append(sorted, i) + } + } for len(images) > 0 { // current repesents images that have no incoming edges. current := map[*Image]struct{}{} @@ -198,6 +206,7 @@ func (i *images) restore() error { delete(edges, e) } } + for _, img := range sorted { if err := img.restore(); err != nil { return err