Properly clean up DrmGpu

CCBUG: 433145
This commit is contained in:
Xaver Hugl 2021-02-19 12:59:43 +01:00
parent 6053bbd2d0
commit 79ccfaddf0
3 changed files with 28 additions and 24 deletions

View file

@ -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;
}
}

View file

@ -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 <xf86drmMode.h>
#include <libdrm/drm_mode.h>
#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

View file

@ -12,6 +12,7 @@
#include <qobject.h>
#include <QVector>
#include <QSocketNotifier>
#include <epoxy/egl.h>
@ -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<DrmPlane*> m_planes;