Skip to content

Commit

Permalink
Don't use canvas pool with the recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Aug 23, 2023
1 parent 8dde484 commit 5c6978b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/worker/caged/libretro/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ type Frontend struct {
// draw threads
th int

canvas *image.Canvas
Canvas *image.Canvas
DisableCanvasPool bool

done chan struct{}
log *logger.Logger
Expand Down Expand Up @@ -222,18 +223,18 @@ func (f *Frontend) handleVideo(data []byte, delta int64, fi nanoarch.FrameInfo)
}
// !to fix possible nil pointer dereference
// when the internal pool can be nil during first Get???
fr.Data = f.canvas.Draw(pixFmt, rot, fi.W, fi.H, fi.Packed, bpp, data, f.th)
fr.Data = f.Canvas.Draw(pixFmt, rot, fi.W, fi.H, fi.Packed, bpp, data, f.th)
fr.Duration = time.Duration(delta)
f.onVideo(fr)
f.canvas.Put(fr.Data)
f.Canvas.Put(fr.Data)
videoPool.Put(fr)
}

func (f *Frontend) Shutdown() {
f.log.Debug().Msgf("run loop cleanup")
f.mu.Lock()
f.nano.Shutdown()
f.canvas.Clear()
f.Canvas.Clear()
f.SetAudio(noAudio)
f.SetVideo(noVideo)
f.mu.Unlock()
Expand Down Expand Up @@ -305,7 +306,10 @@ func (f *Frontend) SetViewport(width int, height int, scale int) {
f.vw, f.vh = width, height
mw, mh := f.nano.GeometryMax()
size := mw * scale * mh * scale
f.canvas = image.NewCanvas(width, height, size)
f.Canvas = image.NewCanvas(width, height, size)
if f.DisableCanvasPool {
f.Canvas.SetEnabled(false)
}
f.mu.Unlock()
}
func (f *Frontend) SetVideo(ff func(*GameFrame)) { f.onVideo = ff }
Expand Down
4 changes: 4 additions & 0 deletions pkg/worker/coordinatorhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke
}
fe.SaveOnClose = true

if w.conf.Recording.Enabled {
fe.DisableCanvasPool = true
}

var nano libretro.Emulator = fe

if w.conf.Recording.Enabled {
Expand Down

0 comments on commit 5c6978b

Please sign in to comment.