diff --git a/plugins/platforms/drm/drm_backend.cpp b/plugins/platforms/drm/drm_backend.cpp
index fd0240f80b..1d840d2dcc 100644
--- a/plugins/platforms/drm/drm_backend.cpp
+++ b/plugins/platforms/drm/drm_backend.cpp
@@ -30,6 +30,7 @@ along with this program. If not, see .
#include "wayland_server.h"
#if HAVE_GBM
#include "egl_gbm_backend.h"
+#include
#endif
// KWayland
#include
@@ -73,6 +74,11 @@ DrmBackend::DrmBackend(QObject *parent)
DrmBackend::~DrmBackend()
{
+#if HAVE_GBM
+ if (m_gbmDevice) {
+ gbm_device_destroy(m_gbmDevice);
+ }
+#endif
if (m_fd >= 0) {
// wait for pageflips
while (m_pageFlipsPending != 0) {
diff --git a/plugins/platforms/drm/drm_backend.h b/plugins/platforms/drm/drm_backend.h
index 3837f0adf6..0a731691eb 100644
--- a/plugins/platforms/drm/drm_backend.h
+++ b/plugins/platforms/drm/drm_backend.h
@@ -33,6 +33,7 @@ along with this program. If not, see .
#include
struct gbm_bo;
+struct gbm_device;
struct gbm_surface;
namespace KWayland
@@ -89,6 +90,13 @@ public:
void outputWentOff();
void checkOutputsAreOn();
+ void setGbmDevice(gbm_device *device) {
+ m_gbmDevice = device;
+ }
+ gbm_device *gbmDevice() const {
+ return m_gbmDevice;
+ }
+
public Q_SLOTS:
void turnOutputsOn();
@@ -129,6 +137,7 @@ private:
QVector m_buffers;
QScopedPointer m_dpmsFilter;
KWayland::Server::OutputManagementInterface *m_outputManagement = nullptr;
+ gbm_device *m_gbmDevice = nullptr;
};
diff --git a/plugins/platforms/drm/egl_gbm_backend.cpp b/plugins/platforms/drm/egl_gbm_backend.cpp
index 15a64d7320..9ed4c03cdc 100644
--- a/plugins/platforms/drm/egl_gbm_backend.cpp
+++ b/plugins/platforms/drm/egl_gbm_backend.cpp
@@ -64,9 +64,6 @@ EglGbmBackend::~EglGbmBackend()
{
// TODO: cleanup front buffer?
cleanup();
- if (m_device) {
- gbm_device_destroy(m_device);
- }
}
void EglGbmBackend::cleanupSurfaces()
@@ -101,13 +98,14 @@ bool EglGbmBackend::initializeEgl()
return false;
}
- m_device = gbm_create_device(m_backend->fd());
- if (!m_device) {
+ auto device = gbm_create_device(m_backend->fd());
+ if (!device) {
setFailed("Could not create gbm device");
return false;
}
+ m_backend->setGbmDevice(device);
- display = eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, m_device, nullptr);
+ display = eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_MESA, device, nullptr);
}
if (display == EGL_NO_DISPLAY)
@@ -158,7 +156,7 @@ void EglGbmBackend::createOutput(DrmOutput *drmOutput)
{
Output o;
o.output = drmOutput;
- o.gbmSurface = gbm_surface_create(m_device, drmOutput->size().width(), drmOutput->size().height(),
+ o.gbmSurface = gbm_surface_create(m_backend->gbmDevice(), drmOutput->size().width(), drmOutput->size().height(),
GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
if (!o.gbmSurface) {
qCCritical(KWIN_DRM) << "Create gbm surface failed";
diff --git a/plugins/platforms/drm/egl_gbm_backend.h b/plugins/platforms/drm/egl_gbm_backend.h
index 6051cf59a4..f43a75c0d8 100644
--- a/plugins/platforms/drm/egl_gbm_backend.h
+++ b/plugins/platforms/drm/egl_gbm_backend.h
@@ -22,7 +22,6 @@ along with this program. If not, see .
#include "abstract_egl_backend.h"
#include "scene_opengl.h"
-struct gbm_device;
struct gbm_surface;
namespace KWin
@@ -74,7 +73,6 @@ private:
void cleanupOutput(const Output &output);
void createOutput(DrmOutput *output);
DrmBackend *m_backend;
- gbm_device *m_device = nullptr;
QVector