From c68f7f13f3ded93a4234520f1b6454531dcad32c Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 10 Nov 2021 12:41:57 +0100 Subject: [PATCH] backends/drm,wayland: require gbm The ifdefs for have_gbm obfuscate the code unnecessarily - the drm backend is not a great experience with qpainter, so in practice noone should ship it without gbm anyways. --- CMakeLists.txt | 3 +- src/backends/drm/CMakeLists.txt | 19 ++++-------- src/backends/drm/drm_backend.cpp | 17 ++--------- src/backends/drm/drm_gpu.cpp | 9 +----- src/backends/drm/drm_pipeline.cpp | 37 +++++++++--------------- src/backends/drm/egl_multi_backend.cpp | 4 --- src/backends/wayland/CMakeLists.txt | 10 ++----- src/backends/wayland/wayland_backend.cpp | 8 ++--- src/backends/wayland/wayland_backend.h | 2 +- src/config-kwin.h.cmake | 1 - src/workspace.cpp | 6 ---- 11 files changed, 30 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d17adb89c..455f51f664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,8 +222,7 @@ find_package(Libdrm 2.4.62) set_package_properties(Libdrm PROPERTIES TYPE REQUIRED PURPOSE "Required for drm output on Wayland.") find_package(gbm) -set_package_properties(gbm PROPERTIES TYPE OPTIONAL PURPOSE "Required for egl output of drm backend.") -set(HAVE_GBM ${gbm_FOUND}) +set_package_properties(gbm PROPERTIES TYPE REQUIRED PURPOSE "Required for egl output of drm backend.") if (${gbm_VERSION} GREATER_EQUAL 21.1) set(HAVE_GBM_BO_GET_FD_FOR_PLANE 1) else() diff --git a/src/backends/drm/CMakeLists.txt b/src/backends/drm/CMakeLists.txt index 35ff2f2999..df92fe1f1a 100644 --- a/src/backends/drm/CMakeLists.txt +++ b/src/backends/drm/CMakeLists.txt @@ -19,24 +19,15 @@ set(DRM_SOURCES drm_abstract_output.cpp drm_virtual_output.cpp drm_lease_output.cpp + egl_gbm_backend.cpp + drm_buffer_gbm.cpp + gbm_surface.cpp + gbm_dmabuf.cpp ) -if (HAVE_GBM) - set(DRM_SOURCES ${DRM_SOURCES} - egl_gbm_backend.cpp - drm_buffer_gbm.cpp - gbm_surface.cpp - gbm_dmabuf.cpp - ) -endif() - add_library(KWinWaylandDrmBackend MODULE ${DRM_SOURCES}) set_target_properties(KWinWaylandDrmBackend PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/org.kde.kwin.waylandbackends/") -target_link_libraries(KWinWaylandDrmBackend kwin Libdrm::Libdrm) - -if (HAVE_GBM) - target_link_libraries(KWinWaylandDrmBackend gbm::gbm) -endif() +target_link_libraries(KWinWaylandDrmBackend kwin Libdrm::Libdrm gbm::gbm) install( TARGETS diff --git a/src/backends/drm/drm_backend.cpp b/src/backends/drm/drm_backend.cpp index b3a2e479d2..745bde5bb9 100644 --- a/src/backends/drm/drm_backend.cpp +++ b/src/backends/drm/drm_backend.cpp @@ -27,11 +27,8 @@ #include "drm_pipeline.h" #include "drm_virtual_output.h" #include "waylandoutputconfig.h" -#if HAVE_GBM #include "egl_gbm_backend.h" -#include #include "gbm_dmabuf.h" -#endif // KF5 #include #include @@ -48,6 +45,7 @@ #include #include // drm +#include #include #include @@ -588,7 +586,6 @@ QPainterBackend *DrmBackend::createQPainterBackend() OpenGLBackend *DrmBackend::createOpenGLBackend() { -#if HAVE_GBM auto primaryBackend = new EglGbmBackend(this, m_gpus.at(0)); AbstractEglBackend::setPrimaryBackend(primaryBackend); EglMultiBackend *backend = new EglMultiBackend(this, primaryBackend); @@ -596,9 +593,6 @@ OpenGLBackend *DrmBackend::createOpenGLBackend() backend->addGpu(m_gpus[i]); } return backend; -#else - return Platform::createOpenGLBackend(); -#endif } void DrmBackend::sceneInitialized() @@ -611,11 +605,7 @@ QVector DrmBackend::supportedCompositors() const if (selectedCompositor() != NoCompositing) { return {selectedCompositor()}; } -#if HAVE_GBM return QVector{OpenGLCompositing, QPainterCompositing}; -#else - return QVector{QPainterCompositing}; -#endif } QString DrmBackend::supportInformation() const @@ -650,13 +640,12 @@ void DrmBackend::removeVirtualOutput(AbstractOutput *output) DmaBufTexture *DrmBackend::createDmaBufTexture(const QSize &size) { -#if HAVE_GBM if (primaryGpu()->eglBackend() && primaryGpu()->gbmDevice()) { primaryGpu()->eglBackend()->makeCurrent(); return GbmDmaBuf::createBuffer(size, primaryGpu()->gbmDevice()); + } else { + return nullptr; } -#endif - return nullptr; } DrmGpu *DrmBackend::primaryGpu() const diff --git a/src/backends/drm/drm_gpu.cpp b/src/backends/drm/drm_gpu.cpp index 7eac50fd85..7a54048ad4 100644 --- a/src/backends/drm/drm_gpu.cpp +++ b/src/backends/drm/drm_gpu.cpp @@ -22,12 +22,8 @@ #include "drm_virtual_output.h" #include "wayland_server.h" #include "drm_lease_output.h" - -#if HAVE_GBM #include "egl_gbm_backend.h" -#include #include "gbm_dmabuf.h" -#endif // system #include #include @@ -35,6 +31,7 @@ #include #include // drm +#include #include #include #include @@ -80,9 +77,7 @@ DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t device // find out if this GPU is using the NVidia proprietary driver DrmScopedPointer version(drmGetVersion(fd)); m_isNVidia = strstr(version->name, "nvidia-drm"); -#if HAVE_GBM m_gbmDevice = gbm_create_device(m_fd); -#endif m_socketNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this); connect(m_socketNotifier, &QSocketNotifier::activated, this, &DrmGpu::dispatchEvents); @@ -142,11 +137,9 @@ DrmGpu::~DrmGpu() qDeleteAll(m_connectors); qDeleteAll(m_planes); delete m_socketNotifier; -#if HAVE_GBM if (m_gbmDevice) { gbm_device_destroy(m_gbmDevice); } -#endif m_platform->session()->closeRestricted(m_fd); } diff --git a/src/backends/drm/drm_pipeline.cpp b/src/backends/drm/drm_pipeline.cpp index 8eda772ee4..665767289a 100644 --- a/src/backends/drm/drm_pipeline.cpp +++ b/src/backends/drm/drm_pipeline.cpp @@ -21,14 +21,10 @@ #include "session.h" #include "drm_output.h" #include "drm_backend.h" - -#if HAVE_GBM -#include - #include "egl_gbm_backend.h" #include "drm_buffer_gbm.h" -#endif +#include #include namespace KWin @@ -62,13 +58,9 @@ bool DrmPipeline::present(const QSharedPointer &buffer) return false; } m_primaryBuffer = buffer; - bool directScanout = false; -#if HAVE_GBM + auto buf = dynamic_cast(buffer.data()); // with direct scanout disallow modesets, calling presentFailed() and logging warnings - if (auto buf = dynamic_cast(buffer.data()); buf && buf->clientBuffer()) { - directScanout = true; - } -#endif + bool directScanout = buf && buf->clientBuffer(); if (gpu()->needsModeset()) { if (directScanout) { return false; @@ -302,19 +294,18 @@ bool DrmPipeline::checkTestBuffer() checkBuffer(pending.crtc->current()); } // if we don't have a fitting buffer already, get or create one - if (buffer) { -#if HAVE_GBM - } else if (backend && m_output) { - buffer = backend->renderTestFrame(m_output); - } else if (backend && gpu()->gbmDevice()) { - gbm_bo *bo = gbm_bo_create(gpu()->gbmDevice(), sourceSize().width(), sourceSize().height(), GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); - if (!bo) { - return false; + if (!buffer) { + if (backend && m_output) { + buffer = backend->renderTestFrame(m_output); + } else if (backend && gpu()->gbmDevice()) { + gbm_bo *bo = gbm_bo_create(gpu()->gbmDevice(), sourceSize().width(), sourceSize().height(), GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + if (!bo) { + return false; + } + buffer = QSharedPointer::create(gpu(), bo, nullptr); + } else { + buffer = QSharedPointer::create(gpu(), sourceSize()); } - buffer = QSharedPointer::create(gpu(), bo, nullptr); -#endif - } else { - buffer = QSharedPointer::create(gpu(), sourceSize()); } if (buffer && buffer->bufferId()) { m_oldTestBuffer = m_primaryBuffer; diff --git a/src/backends/drm/egl_multi_backend.cpp b/src/backends/drm/egl_multi_backend.cpp index 234c1cd3de..6fd5d49d6f 100644 --- a/src/backends/drm/egl_multi_backend.cpp +++ b/src/backends/drm/egl_multi_backend.cpp @@ -10,9 +10,7 @@ #include "egl_multi_backend.h" #include #include "logging.h" -#if HAVE_GBM #include "egl_gbm_backend.h" -#endif #include "drm_backend.h" #include "drm_gpu.h" @@ -112,13 +110,11 @@ bool EglMultiBackend::directScanoutAllowed(AbstractOutput *output) const void EglMultiBackend::addGpu(DrmGpu *gpu) { -#if HAVE_GBM AbstractEglDrmBackend *backend= new EglGbmBackend(m_platform, gpu); if (m_initialized) { backend->init(); } m_backends.append(backend); -#endif } void EglMultiBackend::removeGpu(DrmGpu *gpu) diff --git a/src/backends/wayland/CMakeLists.txt b/src/backends/wayland/CMakeLists.txt index 1194f09e6f..6ac6ee8341 100644 --- a/src/backends/wayland/CMakeLists.txt +++ b/src/backends/wayland/CMakeLists.txt @@ -6,10 +6,7 @@ set(WAYLAND_BACKEND_SOURCES ) if (HAVE_WAYLAND_EGL) - set(WAYLAND_BACKEND_SOURCES egl_wayland_backend.cpp ${WAYLAND_BACKEND_SOURCES}) - if (HAVE_GBM) - list(APPEND WAYLAND_BACKEND_SOURCES ../drm/gbm_dmabuf.cpp) - endif() + set(WAYLAND_BACKEND_SOURCES egl_wayland_backend.cpp ${WAYLAND_BACKEND_SOURCES} ../drm/gbm_dmabuf.cpp) endif() add_library(KWinWaylandWaylandBackend MODULE ${WAYLAND_BACKEND_SOURCES}) @@ -17,10 +14,7 @@ set_target_properties(KWinWaylandWaylandBackend PROPERTIES LIBRARY_OUTPUT_DIRECT target_link_libraries(KWinWaylandWaylandBackend kwin KF5::WaylandClient) if (HAVE_WAYLAND_EGL) - target_link_libraries(KWinWaylandWaylandBackend Wayland::Egl) - if (HAVE_GBM) - target_link_libraries(KWinWaylandWaylandBackend gbm::gbm) - endif() + target_link_libraries(KWinWaylandWaylandBackend Wayland::Egl gbm::gbm) endif() install( diff --git a/src/backends/wayland/wayland_backend.cpp b/src/backends/wayland/wayland_backend.cpp index b795778a9e..339afb3997 100644 --- a/src/backends/wayland/wayland_backend.cpp +++ b/src/backends/wayland/wayland_backend.cpp @@ -12,11 +12,9 @@ #if HAVE_WAYLAND_EGL #include "egl_wayland_backend.h" -#if HAVE_GBM #include "../drm/gbm_dmabuf.h" #include #endif -#endif #include "logging.h" #include "renderloop_p.h" #include "scene_qpainter_wayland_backend.h" @@ -586,7 +584,7 @@ WaylandBackend::WaylandBackend(QObject *parent) connect(this, &WaylandBackend::connectionFailed, qApp, &QCoreApplication::quit); -#if HAVE_GBM && HAVE_WAYLAND_EGL +#if HAVE_WAYLAND_EGL char const *drm_render_node = "/dev/dri/renderD128"; m_drmFileDescriptor = open(drm_render_node, O_RDWR); if (m_drmFileDescriptor < 0) { @@ -627,7 +625,7 @@ WaylandBackend::~WaylandBackend() m_connectionThread->quit(); m_connectionThread->wait(); m_connectionThreadObject->deleteLater(); -#if HAVE_GBM && HAVE_WAYLAND_EGL +#if HAVE_WAYLAND_EGL gbm_device_destroy(m_gbmDevice); close(m_drmFileDescriptor); #endif @@ -1016,7 +1014,7 @@ void WaylandBackend::addConfiguredOutput(WaylandOutput *output) DmaBufTexture *WaylandBackend::createDmaBufTexture(const QSize& size) { -#if HAVE_GBM && HAVE_WAYLAND_EGL +#if HAVE_WAYLAND_EGL return GbmDmaBuf::createBuffer(size, m_gbmDevice); #else return nullptr; diff --git a/src/backends/wayland/wayland_backend.h b/src/backends/wayland/wayland_backend.h index 995c293d83..efbaf62fe0 100644 --- a/src/backends/wayland/wayland_backend.h +++ b/src/backends/wayland/wayland_backend.h @@ -322,7 +322,7 @@ private: KWayland::Client::ServerSideDecorationManager *m_ssdManager = nullptr; KWayland::Client::ServerSideDecorationManager *ssdManager(); int m_nextId = 0; -#if HAVE_GBM && HAVE_WAYLAND_EGL +#if HAVE_WAYLAND_EGL int m_drmFileDescriptor = 0; gbm_device *m_gbmDevice; #endif diff --git a/src/config-kwin.h.cmake b/src/config-kwin.h.cmake index 8a893a01d2..2dd1e5dbff 100644 --- a/src/config-kwin.h.cmake +++ b/src/config-kwin.h.cmake @@ -14,7 +14,6 @@ #define KWIN_XCLIPBOARD_SYNC_BIN "${CMAKE_INSTALL_FULL_LIBEXECDIR}/org_kde_kwin_xclipboard_syncer" #cmakedefine01 HAVE_X11_XCB #cmakedefine01 HAVE_X11_XINPUT -#cmakedefine01 HAVE_GBM #cmakedefine01 HAVE_GBM_BO_GET_FD_FOR_PLANE #cmakedefine01 HAVE_WAYLAND_EGL #cmakedefine01 HAVE_SYS_PRCTL_H diff --git a/src/workspace.cpp b/src/workspace.cpp index 5b198477d3..368515191a 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -1496,12 +1496,6 @@ QString Workspace::supportInformation() const support.append(yes); #else support.append(no); -#endif - support.append(QStringLiteral("HAVE_GBM: ")); -#if HAVE_GBM - support.append(yes); -#else - support.append(no); #endif support.append(QStringLiteral("HAVE_X11_XCB: ")); #if HAVE_X11_XCB