Pass the correct renderer to EGLImageFactory

We should be using the EGL renderer's colorspace and color range
rather than the backend renderer's for fallbacks. The former is
what actually gets passed to the host PC during stream init.
This commit is contained in:
Cameron Gutman
2026-08-06 00:29:53 -05:00
parent c1623ff44e
commit 7cf8b46c79
8 changed files with 28 additions and 18 deletions
+3 -5
View File
@@ -163,9 +163,6 @@ DrmRenderer::DrmRenderer(AVHWDeviceType hwDeviceType, IFFmpegRenderer *backendRe
m_OutputRect{},
m_SwFrameMapper(this),
m_CurrentSwFrameIdx(0)
#ifdef HAVE_EGL
, m_EglImageFactory(this)
#endif
{
SDL_zero(m_SwFrame);
}
@@ -2100,9 +2097,10 @@ AVPixelFormat DrmRenderer::getEGLImagePixelFormat() {
return AV_PIX_FMT_DRM_PRIME;
}
bool DrmRenderer::initializeEGL(EGLDisplay display,
bool DrmRenderer::initializeEGL(IFFmpegRenderer* eglRenderer,
EGLDisplay display,
const EGLExtensions &ext) {
return m_EglImageFactory.initializeEGL(display, ext);
return m_EglImageFactory.initializeEGL(eglRenderer, display, ext);
}
ssize_t DrmRenderer::exportEGLImages(AVFrame *frame, EGLDisplay dpy,
+1 -1
View File
@@ -776,7 +776,7 @@ public:
#ifdef HAVE_EGL
virtual bool canExportEGL() override;
virtual AVPixelFormat getEGLImagePixelFormat() override;
virtual bool initializeEGL(EGLDisplay dpy, const EGLExtensions &ext) override;
virtual bool initializeEGL(IFFmpegRenderer* eglRenderer, EGLDisplay dpy, const EGLExtensions &ext) override;
virtual ssize_t exportEGLImages(AVFrame *frame, EGLDisplay dpy, EGLImage images[EGL_MAX_PLANES]) override;
#endif
@@ -24,8 +24,8 @@
#define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8')
#endif
EglImageFactory::EglImageFactory(IFFmpegRenderer* renderer) :
m_Renderer(renderer),
EglImageFactory::EglImageFactory() :
m_Renderer(nullptr),
m_EGLExtDmaBuf(false),
m_eglCreateImage(nullptr),
m_eglDestroyImage(nullptr),
@@ -36,9 +36,16 @@ EglImageFactory::EglImageFactory(IFFmpegRenderer* renderer) :
{
}
bool EglImageFactory::initializeEGL(EGLDisplay,
bool EglImageFactory::initializeEGL(IFFmpegRenderer* eglRenderer,
EGLDisplay,
const EGLExtensions &ext)
{
// The EGL renderer is guaranteed to be alive for any calls to this factory,
// since it's the one that calls exportEGLImages() on the backend renderer.
SDL_assert(eglRenderer->getRendererType() == IFFmpegRenderer::RendererType::EGL);
SDL_assert(!m_Renderer);
m_Renderer = eglRenderer;
if (!ext.isSupported("EGL_EXT_image_dma_buf_import")) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"DRM-EGL: DMABUF unsupported");
@@ -75,6 +82,8 @@ void EglImageFactory::resetCache()
ssize_t EglImageFactory::exportDRMImages(AVFrame* frame, EGLDisplay dpy, EGLImage images[EGL_MAX_PLANES])
{
SDL_assert(m_Renderer);
SDL_assert(frame->format == AV_PIX_FMT_DRM_PRIME);
AVDRMFrameDescriptor* drmFrame = (AVDRMFrameDescriptor*)frame->data[0];
@@ -264,6 +273,8 @@ ssize_t EglImageFactory::exportDRMImages(AVFrame* frame, EGLDisplay dpy, EGLImag
ssize_t EglImageFactory::exportVAImages(AVFrame *frame, uint32_t exportFlags, EGLDisplay dpy, EGLImage images[EGL_MAX_PLANES])
{
SDL_assert(m_Renderer);
SDL_assert(frame->format == AV_PIX_FMT_VAAPI);
auto hwFrameCtx = (AVHWFramesContext*)frame->hw_frames_ctx->data;
AVVAAPIDeviceContext* vaDeviceContext = (AVVAAPIDeviceContext*)hwFrameCtx->device_ctx->hwctx;
@@ -41,8 +41,8 @@ class EglImageFactory
};
public:
EglImageFactory(IFFmpegRenderer* renderer);
bool initializeEGL(EGLDisplay, const EGLExtensions &ext);
EglImageFactory();
bool initializeEGL(IFFmpegRenderer* eglRenderer, EGLDisplay, const EGLExtensions &ext);
void resetCache();
#ifdef HAVE_DRM
@@ -523,7 +523,7 @@ bool EGLRenderer::initialize(PDECODER_PARAMETERS params)
return false;
}
if (!m_Backend->initializeEGL(m_EGLDisplay, eglExtensions))
if (!m_Backend->initializeEGL(this, m_EGLDisplay, eglExtensions))
return false;
if (!(m_glEGLImageTargetTexture2DOES = (typeof(m_glEGLImageTargetTexture2DOES))eglGetProcAddress("glEGLImageTargetTexture2DOES"))) {
@@ -508,7 +508,8 @@ public:
return AV_PIX_FMT_NONE;
}
virtual bool initializeEGL(EGLDisplay,
virtual bool initializeEGL(IFFmpegRenderer*,
EGLDisplay,
const EGLExtensions &) {
return false;
}
@@ -26,8 +26,7 @@ VAAPIRenderer::VAAPIRenderer(int decoderSelectionPass)
m_RequiresExplicitPixelFormat(false),
m_OverlayMutex(nullptr)
#ifdef HAVE_EGL
, m_EglExportType(EglExportType::Unknown),
m_EglImageFactory(this)
, m_EglExportType(EglExportType::Unknown)
#endif
{
#ifdef HAVE_LIBVA_X11
@@ -1082,11 +1081,12 @@ AVPixelFormat VAAPIRenderer::getEGLImagePixelFormat() {
}
bool
VAAPIRenderer::initializeEGL(EGLDisplay dpy,
VAAPIRenderer::initializeEGL(IFFmpegRenderer* eglRenderer,
EGLDisplay dpy,
const EGLExtensions &ext) {
VADRMPRIMESurfaceDescriptor descriptor;
if (!m_EglImageFactory.initializeEGL(dpy, ext)) {
if (!m_EglImageFactory.initializeEGL(eglRenderer, dpy, ext)) {
return false;
}
+1 -1
View File
@@ -72,7 +72,7 @@ public:
#ifdef HAVE_EGL
virtual bool canExportEGL() override;
virtual AVPixelFormat getEGLImagePixelFormat() override;
virtual bool initializeEGL(EGLDisplay dpy, const EGLExtensions &ext) override;
virtual bool initializeEGL(IFFmpegRenderer* eglRenderer, EGLDisplay dpy, const EGLExtensions &ext) override;
virtual ssize_t exportEGLImages(AVFrame *frame, EGLDisplay dpy, EGLImage images[EGL_MAX_PLANES]) override;
#endif