From 79ccfaddf074f5e72bc9cb5f0bce2b7666328244 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Fri, 19 Feb 2021 12:59:43 +0100 Subject: [PATCH] Properly clean up DrmGpu CCBUG: 433145 --- src/plugins/platforms/drm/drm_backend.cpp | 30 ++++++----------------- src/plugins/platforms/drm/drm_gpu.cpp | 20 ++++++++++++++- src/plugins/platforms/drm/drm_gpu.h | 2 ++ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/plugins/platforms/drm/drm_backend.cpp b/src/plugins/platforms/drm/drm_backend.cpp index 5aad830e86..fc497379f0 100644 --- a/src/plugins/platforms/drm/drm_backend.cpp +++ b/src/plugins/platforms/drm/drm_backend.cpp @@ -57,8 +57,6 @@ #define DRM_CAP_CURSOR_HEIGHT 0x9 #endif -#define KWIN_DRM_EVENT_CONTEXT_VERSION 2 - namespace KWin { @@ -287,31 +285,17 @@ void DrmBackend::openDrm() } drmModeFreeResources(resources); - m_active = true; - QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); - connect(notifier, &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 = pageFlipHandler; - drmHandleEvent(fd, &e); - } - ); DrmGpu *gpu = new DrmGpu(this, devNode, fd, device->sysNum()); - connect(gpu, &DrmGpu::outputAdded, this, &DrmBackend::addOutput); - connect(gpu, &DrmGpu::outputRemoved, this, &DrmBackend::removeOutput); - if (gpu->useEglStreams()) { - // TODO this needs to be removed once EglStreamBackend supports multi-gpu operation - if (gpu_index == 0) { - m_gpus.append(gpu); + if (!gpu->useEglStreams() || gpu_index == 0) { + m_gpus.append(gpu); + m_active = true; + connect(gpu, &DrmGpu::outputAdded, this, &DrmBackend::addOutput); + connect(gpu, &DrmGpu::outputRemoved, this, &DrmBackend::removeOutput); + if (gpu->useEglStreams()) { break; } } else { - m_gpus.append(gpu); + delete gpu; } } diff --git a/src/plugins/platforms/drm/drm_gpu.cpp b/src/plugins/platforms/drm/drm_gpu.cpp index afcd2303d9..e90db90b6d 100644 --- a/src/plugins/platforms/drm/drm_gpu.cpp +++ b/src/plugins/platforms/drm/drm_gpu.cpp @@ -15,6 +15,7 @@ #include "drm_object_crtc.h" #include "abstract_egl_backend.h" #include "logging.h" +#include "logind.h" #if HAVE_GBM #include "egl_gbm_backend.h" @@ -29,6 +30,8 @@ #include #include +#define KWIN_DRM_EVENT_CONTEXT_VERSION 2 + namespace KWin { @@ -60,6 +63,20 @@ DrmGpu::DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, int drmId) : m_b m_useEglStreams = strstr(version->name, "nvidia-drm"); 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); + } + ); } DrmGpu::~DrmGpu() @@ -73,7 +90,8 @@ DrmGpu::~DrmGpu() qDeleteAll(m_crtcs); qDeleteAll(m_connectors); qDeleteAll(m_planes); - close(m_fd); + delete m_socketNotifier; + LogindIntegration::self()->releaseDevice(m_fd); } clockid_t DrmGpu::presentationClock() const diff --git a/src/plugins/platforms/drm/drm_gpu.h b/src/plugins/platforms/drm/drm_gpu.h index d9de4167a1..33bcadebd2 100644 --- a/src/plugins/platforms/drm/drm_gpu.h +++ b/src/plugins/platforms/drm/drm_gpu.h @@ -12,6 +12,7 @@ #include #include +#include #include @@ -132,6 +133,7 @@ private: gbm_device* m_gbmDevice; EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; clockid_t m_presentationClock; + QSocketNotifier *m_socketNotifier = nullptr; // all planes: primarys, cursors and overlays QVector m_planes;