mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
parent
4d05baf97c
commit
eeb8fea778
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user