From e179fb697de576920e2ee071fa121a0b9aed81bf Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 19 Feb 2021 15:00:49 +0200 Subject: [PATCH] platforms/drm: Refactor event dispatching code There are a couple of reasons not to use the lambda: * It is unnecessary. The DrmGpu has the DRM file descriptor * If a crash occurs somewhere in the lambda, the backtrace will be hard to read * Instead of processing events in the destructor of the DrmBackend class, we should keep dispatching events without involving QCoreApplication::processEvents() until all page flips are completed. --- src/plugins/platforms/drm/drm_gpu.cpp | 26 ++++++++++++-------------- src/plugins/platforms/drm/drm_gpu.h | 1 + 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/plugins/platforms/drm/drm_gpu.cpp b/src/plugins/platforms/drm/drm_gpu.cpp index e90db90b6d..0fb59e9e09 100644 --- a/src/plugins/platforms/drm/drm_gpu.cpp +++ b/src/plugins/platforms/drm/drm_gpu.cpp @@ -30,8 +30,6 @@ #include #include -#define KWIN_DRM_EVENT_CONTEXT_VERSION 2 - namespace KWin { @@ -65,18 +63,7 @@ DrmGpu::DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, int drmId) : m_b m_deleteBufferAfterPageFlip = !m_useEglStreams; m_socketNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); - connect(m_socketNotifier, &QSocketNotifier::activated, this, - [fd] { - if (!LogindIntegration::self()->isActiveSession()) { - return; - } - drmEventContext e; - memset(&e, 0, sizeof e); - e.version = KWIN_DRM_EVENT_CONTEXT_VERSION; - e.page_flip_handler = DrmBackend::pageFlipHandler; - drmHandleEvent(fd, &e); - } - ); + connect(m_socketNotifier, &QSocketNotifier::activated, this, &DrmGpu::dispatchEvents); } DrmGpu::~DrmGpu() @@ -327,4 +314,15 @@ DrmPlane *DrmGpu::getCompatiblePlane(DrmPlane::TypeIndex typeIndex, DrmCrtc *crt return nullptr; } +void DrmGpu::dispatchEvents() +{ + if (!LogindIntegration::self()->isActiveSession()) { + return; + } + drmEventContext context = {}; + context.version = 2; + context.page_flip_handler = DrmBackend::pageFlipHandler; + drmHandleEvent(m_fd, &context); +} + } diff --git a/src/plugins/platforms/drm/drm_gpu.h b/src/plugins/platforms/drm/drm_gpu.h index 33bcadebd2..dd8130fe09 100644 --- a/src/plugins/platforms/drm/drm_gpu.h +++ b/src/plugins/platforms/drm/drm_gpu.h @@ -117,6 +117,7 @@ protected: bool updateOutputs(); private: + void dispatchEvents(); DrmPlane *getCompatiblePlane(DrmPlane::TypeIndex typeIndex, DrmCrtc *crtc); DrmOutput *findOutput(quint32 connector);