From 104cad9911d55734988075e5244d5436cb27ec48 Mon Sep 17 00:00:00 2001 From: Mark Kendall Date: Mon, 27 Jan 2020 14:45:31 +0000 Subject: [PATCH] MythDisplay: Force the use of EGL for XCB when not using NVIDIA - as noted in the code, we want EGL for various video renderers but it must be forced before we do any Qt platform initialisation and it does not work with NVIDIA drivers (although NVIDIA drivers don't crash anymore!) - as we have no window, platform or OpenGL information at this stage, use EGL directly to check for NVIDIA. - if the vendor cannot be checked, default to not using EGL. --- mythtv/libs/libmythui/mythdisplay.cpp | 43 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/mythtv/libs/libmythui/mythdisplay.cpp b/mythtv/libs/libmythui/mythdisplay.cpp index 343702dd771..bf9b4c6d7a3 100644 --- a/mythtv/libs/libmythui/mythdisplay.cpp +++ b/mythtv/libs/libmythui/mythdisplay.cpp @@ -11,6 +11,7 @@ #include "mythcorecontext.h" #include "mythuihelper.h" #include "mythdisplay.h" +#include "mythegl.h" #include "mythmainwindow.h" #ifdef Q_OS_ANDROID @@ -1055,20 +1056,36 @@ void MythDisplay::ConfigureQtGUI(int SwapInterval) QApplication::setDesktopSettingsAware(false); #endif #if defined (Q_OS_LINUX) -#if defined (USING_VAAPI) || defined (USING_MMAL) - // When using VAAPI (linux/desktop only) we want to use EGL to ensure we + // We want to use EGL for VAAPI/MMAL/DRMPRIME rendering to ensure we // can use zero copy video buffers for the best performance (N.B. not tested - // on AMD desktops). For non-VAAPI users this should make no difference - on NVidia - // installations it has no effect. - // Likewise for MMAL (Raspberry Pi), we want EGL for zero copy direct rendering. - // This is the only way to force Qt to use EGL and must be done before any - // GUI is created. - // If problems are encountered, set the environment variable NO_EGL - - // Disabled this for now as it does actually break NVidia desktops - //if (qgetenv("NO_EGL").isEmpty()) - // setenv("QT_XCB_GL_INTEGRATION", "xcb_egl", 0); -#endif + // on AMD desktops). To force Qt to use EGL we must set 'QT_XCB_GL_INTEGRATION' + // to 'xcb_egl' and this must be done before any GUI is created. If the platform + // plugin is not xcb then this should have no effect. + // This does however break when using NVIDIA drivers - which do not support + // EGL like other drivers so we try to check the EGL vendor - and we currently + // have no need for EGL with NVIDIA (that may change however). + // NOTE force using EGL by setting MYTHTV_FORCE_EGL + // NOTE disable using EGL by setting MYTHTV_NO_EGL + // NOTE We have no Qt platform information, window/surface or logging when this is called. + if (qgetenv("MYTHTV_NO_EGL").isEmpty()) + { + bool force = !qgetenv("MYTHTV_FORCE_EGL").isEmpty(); + QString vendor = MythEGL::GetEGLVendor(); + if ((vendor == EGL_NO_VENDOR) && !force) + { + qInfo() << LOC + "Failed to check EGL vendor - will not request EGL."; + } + else if (vendor.contains("nvidia", Qt::CaseInsensitive) && !force) + { + qInfo() << LOC + QString("Not requesting EGL for vendor '%1'").arg(vendor); + } + else + { + qInfo() << LOC + "Requesting EGL"; + setenv("QT_XCB_GL_INTEGRATION", "xcb_egl", 0); + } + } + // This makes Xlib calls thread-safe which seems to be required for hardware // accelerated Flash playback to work without causing mythfrontend to abort. QApplication::setAttribute(Qt::AA_X11InitThreads);