restorable: Bug fix: dummyImage must be restored first

Fixes #791
This commit is contained in:
Hajime Hoshi 2019-01-21 00:36:37 +09:00
parent 4d05baf97c
commit eeb8fea778
2 changed files with 16 additions and 7 deletions

View File

@ -55,6 +55,9 @@ 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
@ -62,6 +65,7 @@ var dummyImage *Image
func init() {
dummyImage = &Image{
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)

View File

@ -164,15 +164,23 @@ func (i *images) restore() error {
}
images := map[*Image]struct{}{}
for i := range i.images {
if !i.priority {
images[i] = struct{}{}
}
}
edges := map[edge]struct{}{}
for t := range images {
for s := range t.dependingImages() {
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