mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
restorable: Add TestRestoreChain2
This commit is contained in:
parent
c0b1919020
commit
fc47d2843a
@ -110,6 +110,11 @@ func (i *Image) makeStale() {
|
||||
i.basePixels = nil
|
||||
i.drawImageHistory = nil
|
||||
i.stale = true
|
||||
|
||||
// Don't have to call makeStale recursively here.
|
||||
// Restoring is done after topological sorting is done.
|
||||
// If an image depends on another stale image, this means that
|
||||
// the former image can be restored from the latest state of the latter image.
|
||||
}
|
||||
|
||||
// ReplacePixels replaces the image pixels with the given pixels slice.
|
||||
|
@ -121,8 +121,6 @@ func (i *images) makeStaleIfDependingOnImpl(target *Image) {
|
||||
}
|
||||
i.lastTarget = target
|
||||
for img := range i.images {
|
||||
// TODO: This seems not enough: What if img becomes stale but what about
|
||||
// other images depend on img? (#357)
|
||||
img.makeStaleIfDependingOn(target)
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func TestRestoreChain(t *testing.T) {
|
||||
clr := color.RGBA{0x00, 0x00, 0x00, 0xff}
|
||||
fill(imgs[0], clr.R, clr.G, clr.B, clr.A)
|
||||
for i := 0; i < num-1; i++ {
|
||||
imgs[i+1].DrawImage(imgs[i], 0, 0, 1, 1, nil, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
|
||||
imgs[i+1].DrawImage(imgs[i], 0, 0, 1, 1, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
}
|
||||
if err := ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -134,6 +134,51 @@ func TestRestoreChain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreChain2(t *testing.T) {
|
||||
const num = 10
|
||||
imgs := []*Image{}
|
||||
for i := 0; i < num; i++ {
|
||||
img := NewImage(1, 1, false)
|
||||
fill(img, 0, 0, 0, 0)
|
||||
imgs = append(imgs, img)
|
||||
}
|
||||
defer func() {
|
||||
for _, img := range imgs {
|
||||
img.Dispose()
|
||||
}
|
||||
}()
|
||||
|
||||
clr0 := color.RGBA{0xff, 0x00, 0x00, 0xff}
|
||||
fill(imgs[0], clr0.R, clr0.G, clr0.B, clr0.A)
|
||||
clr7 := color.RGBA{0x00, 0xff, 0x00, 0xff}
|
||||
fill(imgs[7], clr7.R, clr7.G, clr7.B, clr7.A)
|
||||
clr8 := color.RGBA{0x00, 0x00, 0xff, 0xff}
|
||||
fill(imgs[8], clr8.R, clr8.G, clr8.B, clr8.A)
|
||||
|
||||
imgs[8].DrawImage(imgs[7], 0, 0, 1, 1, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
imgs[9].DrawImage(imgs[8], 0, 0, 1, 1, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
for i := 0; i < 7; i++ {
|
||||
imgs[i+1].DrawImage(imgs[i], 0, 0, 1, 1, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
||||
}
|
||||
|
||||
if err := ResolveStaleImages(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Restore(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, img := range imgs {
|
||||
want := clr0
|
||||
if i == 8 || i == 9 {
|
||||
want = clr7
|
||||
}
|
||||
got := byteSliceToColor(img.BasePixelsForTesting(), 0)
|
||||
if !sameColors(got, want, 1) {
|
||||
t.Errorf("%d: got %v, want %v", i, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreOverrideSource(t *testing.T) {
|
||||
img0 := NewImage(1, 1, false)
|
||||
fill(img0, 0, 0, 0, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user