diff --git a/app/app.pro b/app/app.pro index 8efdf84f..9fb043dd 100644 --- a/app/app.pro +++ b/app/app.pro @@ -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 } diff --git a/app/main.cpp b/app/main.cpp index ab404ec5..d13af8f2 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -85,6 +85,10 @@ static QAtomicInteger 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 diff --git a/app/masterhook.c b/app/masterhook.c index 27a2583a..3d7cb835 100644 --- a/app/masterhook.c +++ b/app/masterhook.c @@ -28,6 +28,9 @@ #include #include +// 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); diff --git a/app/masterhook_internal.c b/app/masterhook_internal.c index ce7c1461..1c56fe2d 100644 --- a/app/masterhook_internal.c +++ b/app/masterhook_internal.c @@ -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) {