From 92726372f46162105ebea3b265d4e794c11281f0 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 7 Jun 2021 11:11:30 +0200 Subject: [PATCH] platforms/drm: simplify deleted output handling --- src/plugins/platforms/drm/drm_backend.cpp | 10 ++++++ src/plugins/platforms/drm/drm_backend.h | 1 + src/plugins/platforms/drm/drm_gpu.cpp | 27 ++++++++++++---- src/plugins/platforms/drm/drm_output.cpp | 39 +++++------------------ src/plugins/platforms/drm/drm_output.h | 3 -- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/plugins/platforms/drm/drm_backend.cpp b/src/plugins/platforms/drm/drm_backend.cpp index 0a9a102720..135072c820 100644 --- a/src/plugins/platforms/drm/drm_backend.cpp +++ b/src/plugins/platforms/drm/drm_backend.cpp @@ -687,4 +687,14 @@ DrmGpu *DrmBackend::findGpu(dev_t deviceId) const return nullptr; } +DrmGpu *DrmBackend::findGpuByFd(int fd) const +{ + for (DrmGpu *gpu : qAsConst(m_gpus)) { + if (gpu->fd() == fd) { + return gpu; + } + } + return nullptr; +} + } diff --git a/src/plugins/platforms/drm/drm_backend.h b/src/plugins/platforms/drm/drm_backend.h index f636e2542d..0e6d6df90d 100644 --- a/src/plugins/platforms/drm/drm_backend.h +++ b/src/plugins/platforms/drm/drm_backend.h @@ -64,6 +64,7 @@ public: DrmGpu *primaryGpu() const; DrmGpu *findGpu(dev_t deviceId) const; + DrmGpu *findGpuByFd(int fd) const; public Q_SLOTS: void turnOutputsOn(); diff --git a/src/plugins/platforms/drm/drm_gpu.cpp b/src/plugins/platforms/drm/drm_gpu.cpp index e080ad8653..bcb1ec38b3 100644 --- a/src/plugins/platforms/drm/drm_gpu.cpp +++ b/src/plugins/platforms/drm/drm_gpu.cpp @@ -17,6 +17,7 @@ #include "logging.h" #include "session.h" #include "renderloop_p.h" +#include "main.h" #if HAVE_GBM #include "egl_gbm_backend.h" @@ -390,7 +391,19 @@ static void pageFlipHandler(int fd, unsigned int frame, unsigned int sec, unsign Q_UNUSED(fd) Q_UNUSED(frame) + auto backend = dynamic_cast(kwinApp()->platform()); + if (!backend) { + return; + } + auto gpu = backend->findGpuByFd(fd); + if (!gpu) { + return; + } auto output = static_cast(data); + if (!gpu->outputs().contains(output)) { + // output already got deleted + return; + } // The static_cast<> here are for a 32-bit environment where // sizeof(time_t) == sizeof(unsigned int) == 4 . Putting @p sec @@ -426,13 +439,13 @@ void DrmGpu::removeOutput(DrmOutput *output) { m_outputs.removeOne(output); Q_EMIT outputRemoved(output); - output->teardown(); - output->m_crtc = nullptr; - m_connectors.removeOne(output->m_conn); - delete output->m_conn; - output->m_conn = nullptr; - if (output->m_primaryPlane) { - m_unusedPlanes << output->m_primaryPlane; + auto connector = output->m_conn; + auto primary = output->m_primaryPlane; + delete output; + m_connectors.removeOne(connector); + delete connector; + if (primary) { + m_unusedPlanes << primary; } } diff --git a/src/plugins/platforms/drm/drm_output.cpp b/src/plugins/platforms/drm/drm_output.cpp index 78d1f9dc00..ccb111f3db 100644 --- a/src/plugins/platforms/drm/drm_output.cpp +++ b/src/plugins/platforms/drm/drm_output.cpp @@ -49,21 +49,6 @@ DrmOutput::DrmOutput(DrmBackend *backend, DrmGpu *gpu) DrmOutput::~DrmOutput() { - Q_ASSERT(!m_pageFlipPending); - teardown(); -} - -RenderLoop *DrmOutput::renderLoop() const -{ - return m_renderLoop; -} - -void DrmOutput::teardown() -{ - if (m_deleted) { - return; - } - m_deleted = true; hideCursor(); m_crtc->blank(this); @@ -74,10 +59,14 @@ void DrmOutput::teardown() m_cursor[0].reset(nullptr); m_cursor[1].reset(nullptr); - if (!m_pageFlipPending) { - deleteLater(); - } //else will be deleted in the page flip handler - //this is needed so that the pageflipcallback handle isn't deleted + if (m_pageFlipPending) { + pageFlipped(); + } +} + +RenderLoop *DrmOutput::renderLoop() const +{ + return m_renderLoop; } bool DrmOutput::hideCursor() @@ -105,10 +94,6 @@ bool DrmOutput::showCursor(DrmDumbBuffer *c) bool DrmOutput::showCursor() { - if (m_deleted) { - return false; - } - const bool ret = showCursor(m_cursor[m_cursorIndex].data()); if (!ret) { qCDebug(KWIN_DRM) << "DrmOutput::showCursor(DrmDumbBuffer) failed"; @@ -141,9 +126,6 @@ static bool isCursorSpriteCompatible(const QImage *buffer, const QImage *sprite) bool DrmOutput::updateCursor() { - if (m_deleted) { - return false; - } const Cursor *cursor = Cursors::self()->currentCursor(); const QImage cursorImage = cursor->image(); if (cursorImage.isNull()) { @@ -526,11 +508,6 @@ void DrmOutput::pageFlipped() Q_ASSERT(m_pageFlipPending || !m_gpu->atomicModeSetting()); m_pageFlipPending = false; - if (m_deleted) { - deleteLater(); - return; - } - if (!m_crtc) { return; } diff --git a/src/plugins/platforms/drm/drm_output.h b/src/plugins/platforms/drm/drm_output.h index 24380519c1..3b02fac50a 100644 --- a/src/plugins/platforms/drm/drm_output.h +++ b/src/plugins/platforms/drm/drm_output.h @@ -42,8 +42,6 @@ public: RenderLoop *renderLoop() const override; - ///queues deleting the output after a page flip has completed. - void teardown(); bool showCursor(DrmDumbBuffer *buffer); bool showCursor(); bool hideCursor(); @@ -161,7 +159,6 @@ private: QScopedPointer m_cursor[2]; int m_cursorIndex = 0; bool m_hasNewCursor = false; - bool m_deleted = false; QTimer m_turnOffTimer; };