Disable the DRM master hooks when EGLFS isn't used

This commit is contained in:
Cameron Gutman
2026-02-05 22:36:31 -06:00
parent f6a9e7694a
commit 0a2b134d49
4 changed files with 31 additions and 1 deletions

View File

@@ -317,6 +317,7 @@ libdrm {
linux {
!disable-masterhooks {
message(Master hooks enabled)
DEFINES += HAVE_DRM_MASTER_HOOKS
SOURCES += masterhook.c masterhook_internal.c
LIBS += -ldl -pthread
}

View File

@@ -85,6 +85,10 @@ static QAtomicInteger<uint64_t> s_LogBytesWritten = 0;
static QFile* s_LoggerFile;
#endif
#ifdef HAVE_DRM_MASTER_HOOKS
extern "C" bool g_DisableDrmHooks;
#endif
class LoggerTask : public QRunnable
{
public:
@@ -789,6 +793,11 @@ int main(int argc, char *argv[])
}
#endif
#ifdef HAVE_DRM_MASTER_HOOKS
// Only use the Qt-SDL DRM master interoperability hooks if Qt is using KMS
g_DisableDrmHooks = QGuiApplication::platformName() != "eglfs";
#endif
#ifdef STEAM_LINK
// Qt 5.9 from the Steam Link SDK is not able to load any fonts
// since the Steam Link doesn't include any of the ones it looks

View File

@@ -28,6 +28,9 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
// Used to turn off the hooks when Qt is not using EGLFS
bool g_DisableDrmHooks = false;
// We require SDL 2.0.15+ to hook because it supports sharing
// the DRM FD with our code. This avoids having multiple DRM FDs
// in flight at the same time which would significantly complicate
@@ -90,6 +93,10 @@ int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
// Lookup the real libdrm function pointers if we haven't yet
pthread_once(&s_InitDrmFunctions, lookupRealDrmFunctions);
if (g_DisableDrmHooks) {
return fn_drmModeSetCrtc(fd, crtcId, bufferId, x, y, connectors, count, mode);
}
// Grab the first DRM Master FD that makes it in here. This will be the Qt
// EGLFS backend's DRM FD, on which we will call drmDropMaster() later.
if (g_QtDrmMasterFd == -1 && drmIsMaster(fd)) {
@@ -128,7 +135,7 @@ int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id, uint32_t flags, vo
// Call into the real thing
int err = fn_drmModePageFlip(fd, crtc_id, fb_id, flags, user_data);
if (err == -EACCES && fd == g_QtDrmMasterFd) {
if (!g_DisableDrmHooks && err == -EACCES && fd == g_QtDrmMasterFd) {
// If SDL took master from us, try to grab it back temporarily
int oldMasterFd = takeMasterFromSdlFd();
drmSetMaster(fd);
@@ -148,6 +155,10 @@ int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req,
// Lookup the real libdrm function pointers if we haven't yet
pthread_once(&s_InitDrmFunctions, lookupRealDrmFunctions);
if (g_DisableDrmHooks) {
return fn_drmModeAtomicCommit(fd, req, flags, user_data);
}
// Grab the first DRM Master FD that makes it in here. This will be the Qt
// EGLFS backend's DRM FD, on which we will call drmDropMaster() later.
if (g_QtDrmMasterFd == -1 && drmIsMaster(fd)) {
@@ -210,6 +221,10 @@ int close(int fd)
// Lookup the real libc functions if we haven't yet
pthread_once(&s_InitLibCFunctions, lookupRealLibCFunctions);
if (g_DisableDrmHooks) {
return fn_close(fd);
}
// Remove this entry from the SDL FD table
bool lastSdlFd = removeSdlFd(fd);

View File

@@ -31,6 +31,7 @@
extern int g_QtDrmMasterFd;
extern struct stat g_DrmMasterStat;
extern bool g_DisableDrmHooks;
#define MAX_SDL_FD_COUNT 8
int g_SdlDrmMasterFds[MAX_SDL_FD_COUNT];
@@ -114,6 +115,10 @@ int openHook(typeof(open) *real_open, typeof(close) *real_close, const char *pat
fd = real_open(pathname, flags);
}
if (g_DisableDrmHooks) {
return fd;
}
// If the file was successfully opened and we have a DRM master FD,
// check if the FD we just opened is a DRM device.
if (fd >= 0 && g_QtDrmMasterFd != -1) {