Reference the AVFrame while the backing DMA-BUFs are used for scanout

This prevents tearing and other artifacts caused by the decoder
writing to a DMA-BUF that is currently being displayed.
This commit is contained in:
Cameron Gutman 2026-01-04 18:47:00 -06:00
commit 34881599f5
2 changed files with 76 additions and 44 deletions

View file

@ -1158,7 +1158,7 @@ void DrmRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
// Queue the plane flip with the new FB
//
// NB: This takes ownership of the FB and dumb buffer, even on failure
m_PropSetter.flipPlane(m_OverlayPlanes[type], fbId, dumbBuffer);
m_PropSetter.flipPlane(m_OverlayPlanes[type], fbId, dumbBuffer, nullptr);
SDL_FreeSurface(newSurface);
}
@ -1410,7 +1410,12 @@ void DrmRenderer::renderFrame(AVFrame* frame)
// Update the video plane
//
// NB: This takes ownership of fbId, even on failure
m_PropSetter.flipPlane(m_VideoPlane, fbId, 0);
//
// NB2: We reference the AVFrame (which also references the AVBuffers backing the frame itself
// and the opaque_ref which may store our DRM-PRIME mapping) for frames backed by DMA-BUFs in
// order to keep those from being reused by the decoder while they're still being scanned out.
m_PropSetter.flipPlane(m_VideoPlane, fbId, 0,
(m_DrmPrimeBackend || frame->format == AV_PIX_FMT_DRM_PRIME) ? frame : nullptr);
// Apply pending atomic transaction (if in atomic mode)
m_PropSetter.apply();