internal/processtest: improve test issue2815

WritePixels for 1x1 image is optimized at internal/ui, and Ebitengine
doesn't read pixels from GPU in this case. Enlarge the tested image,
and use DrawImage to ensure to invalidate the internal cache.

Updates #2815
This commit is contained in:
Hajime Hoshi 2023-10-20 02:43:47 +09:00
parent e80e981bf5
commit 39688dd27d
2 changed files with 10 additions and 6 deletions

View File

@ -37,14 +37,17 @@ func (g *Game) Update() error {
g.end0 = make(chan struct{}) g.end0 = make(chan struct{})
g.end1 = make(chan struct{}) g.end1 = make(chan struct{})
g.errCh = make(chan error) g.errCh = make(chan error)
img := ebiten.NewImage(1, 1) src := ebiten.NewImage(1, 2)
img.WritePixels([]byte{0xff, 0xff, 0xff, 0xff}) src.WritePixels([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})
img := ebiten.NewImage(1, 2)
go func() { go func() {
t := time.Tick(time.Microsecond) t := time.Tick(time.Microsecond)
loop: loop:
for { for {
select { select {
case <-t: case <-t:
// Call DrawImage every time in order to invalidate the internal pixels cache.
img.DrawImage(src, nil)
got := img.At(0, 0).(color.RGBA) got := img.At(0, 0).(color.RGBA)
want := color.RGBA{0xff, 0xff, 0xff, 0xff} want := color.RGBA{0xff, 0xff, 0xff, 0xff}
if got != want { if got != want {

View File

@ -130,15 +130,16 @@ func (u *UserInterface) readPixels(mipmap *mipmap.Mipmap, pixels []byte, region
if !ok { if !ok {
ch := make(chan error) ch := make(chan error)
u.context.appendDeferredFunc(func() { u.context.appendDeferredFunc(func() {
defer close(ch)
ok, err := mipmap.ReadPixels(u.graphicsDriver, pixels, region) ok, err := mipmap.ReadPixels(u.graphicsDriver, pixels, region)
if err != nil {
ch <- err
return
}
if !ok { if !ok {
// This never reaches since this function must be called in a frame. // This never reaches since this function must be called in a frame.
panic("ui: ReadPixels unexpectedly failed") panic("ui: ReadPixels unexpectedly failed")
} }
if err != nil {
ch <- err
}
close(ch)
}) })
// If this function is called from the game (Update/Draw) goroutine in between two frames, // If this function is called from the game (Update/Draw) goroutine in between two frames,