diff --git a/src/backends/wayland/wayland_backend.cpp b/src/backends/wayland/wayland_backend.cpp index fb440f6880..4586171c2c 100644 --- a/src/backends/wayland/wayland_backend.cpp +++ b/src/backends/wayland/wayland_backend.cpp @@ -8,6 +8,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "wayland_backend.h" +#include "core/drmdevice.h" #include "input.h" #include "wayland_display.h" #include "wayland_egl_backend.h" @@ -425,10 +426,6 @@ WaylandBackend::~WaylandBackend() m_seat.reset(); m_display.reset(); - - if (m_gbmDevice) { - gbm_device_destroy(m_gbmDevice); - } qCDebug(KWIN_WAYLAND_BACKEND) << "Destroyed Wayland display"; } @@ -440,10 +437,8 @@ bool WaylandBackend::initialize() } if (WaylandLinuxDmabufV1 *dmabuf = m_display->linuxDmabuf()) { - m_drmFileDescriptor = FileDescriptor(open(dmabuf->mainDevice(), O_RDWR | O_CLOEXEC)); - if (m_drmFileDescriptor.isValid()) { - m_gbmDevice = gbm_create_device(m_drmFileDescriptor.get()); - } else { + m_drmDevice = DrmDevice::open(dmabuf->mainDevice()); + if (!m_drmDevice) { qCWarning(KWIN_WAYLAND_BACKEND) << "Failed to open drm render node" << dmabuf->mainDevice(); } } @@ -560,7 +555,7 @@ void WaylandBackend::togglePointerLock() QList WaylandBackend::supportedCompositors() const { QList ret; - if (m_display->linuxDmabuf() && m_gbmDevice) { + if (m_display->linuxDmabuf() && m_drmDevice) { ret.append(OpenGLCompositing); } ret.append(QPainterCompositing); @@ -675,6 +670,11 @@ EglDisplay *WaylandBackend::sceneEglDisplayObject() const return m_eglDisplay.get(); } +DrmDevice *WaylandBackend::drmDevice() const +{ + return m_drmDevice.get(); +} + WaylandBuffer::WaylandBuffer(wl_buffer *handle, GraphicsBuffer *graphicsBuffer) : m_graphicsBuffer(graphicsBuffer) , m_handle(handle) diff --git a/src/backends/wayland/wayland_backend.h b/src/backends/wayland/wayland_backend.h index 057786e16d..23fc53a7d9 100644 --- a/src/backends/wayland/wayland_backend.h +++ b/src/backends/wayland/wayland_backend.h @@ -46,6 +46,7 @@ class Touch; namespace KWin { class GraphicsBuffer; +class DrmDevice; namespace Wayland { @@ -241,10 +242,7 @@ public: wl_buffer *importBuffer(GraphicsBuffer *graphicsBuffer); - gbm_device *gbmDevice() const - { - return m_gbmDevice; - } + DrmDevice *drmDevice() const; void setEglBackend(WaylandEglBackend *eglBackend) { @@ -267,8 +265,7 @@ private: WaylandEglBackend *m_eglBackend = nullptr; QList m_outputs; bool m_pointerLockRequested = false; - FileDescriptor m_drmFileDescriptor; - gbm_device *m_gbmDevice = nullptr; + std::unique_ptr m_drmDevice; std::unique_ptr m_eglDisplay; std::map> m_buffers; }; diff --git a/src/backends/wayland/wayland_egl_backend.cpp b/src/backends/wayland/wayland_egl_backend.cpp index 2e7de81827..133b9ec5ce 100644 --- a/src/backends/wayland/wayland_egl_backend.cpp +++ b/src/backends/wayland/wayland_egl_backend.cpp @@ -9,6 +9,7 @@ */ #include "wayland_egl_backend.h" +#include "core/drmdevice.h" #include "core/gbmgraphicsbufferallocator.h" #include "opengl/eglswapchain.h" #include "opengl/glrendertimequery.h" @@ -229,7 +230,6 @@ std::chrono::nanoseconds WaylandEglCursorLayer::queryRenderTime() const WaylandEglBackend::WaylandEglBackend(WaylandBackend *b) : AbstractEglBackend() , m_backend(b) - , m_allocator(std::make_unique(b->gbmDevice())) { connect(m_backend, &WaylandBackend::outputAdded, this, &WaylandEglBackend::createEglWaylandOutput); connect(m_backend, &WaylandBackend::outputRemoved, this, [this](Output *output) { @@ -251,7 +251,7 @@ WaylandBackend *WaylandEglBackend::backend() const GraphicsBufferAllocator *WaylandEglBackend::graphicsBufferAllocator() const { - return m_allocator.get(); + return m_backend->drmDevice()->allocator(); } void WaylandEglBackend::cleanupSurfaces() @@ -280,7 +280,7 @@ bool WaylandEglBackend::initializeEgl() } } - m_backend->setEglDisplay(EglDisplay::create(eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, m_backend->gbmDevice(), nullptr))); + m_backend->setEglDisplay(EglDisplay::create(eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, m_backend->drmDevice()->gbmDevice(), nullptr))); } auto display = m_backend->sceneEglDisplayObject(); diff --git a/src/backends/wayland/wayland_egl_backend.h b/src/backends/wayland/wayland_egl_backend.h index 4cee304253..fa2e89bea6 100644 --- a/src/backends/wayland/wayland_egl_backend.h +++ b/src/backends/wayland/wayland_egl_backend.h @@ -123,7 +123,6 @@ private: }; WaylandBackend *m_backend; - std::unique_ptr m_allocator; std::map m_outputs; };