From 5340d729aaf81e2036d904fc58d7ffe86d748870 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 16 Aug 2023 16:33:33 +0200 Subject: [PATCH] backends/drm: move layers out of the pipeline state They're not actually supposed to be ever reverted, so having them in the state is just unnecessary overhead --- src/backends/drm/drm_pipeline.cpp | 18 +++++++++--------- src/backends/drm/drm_pipeline.h | 11 ++++++----- src/backends/drm/drm_pipeline_legacy.cpp | 10 +++++----- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/backends/drm/drm_pipeline.cpp b/src/backends/drm/drm_pipeline.cpp index e95e54811c..3592c09b8c 100644 --- a/src/backends/drm/drm_pipeline.cpp +++ b/src/backends/drm/drm_pipeline.cpp @@ -65,7 +65,7 @@ bool DrmPipeline::testScanout() if (gpu()->atomicModeSetting()) { return commitPipelines({this}, CommitMode::Test) == Error::None; } else { - if (m_pending.layer->currentBuffer()->buffer()->size() != m_pending.mode->size()) { + if (m_primaryLayer->currentBuffer()->buffer()->size() != m_pending.mode->size()) { // scaling isn't supported with the legacy API return false; } @@ -81,7 +81,7 @@ DrmPipeline::Error DrmPipeline::present() if (gpu()->atomicModeSetting()) { return commitPipelines({this}, CommitMode::Commit); } else { - if (m_pending.layer->hasDirectScanoutBuffer()) { + if (m_primaryLayer->hasDirectScanoutBuffer()) { // already presented return Error::None; } @@ -120,7 +120,7 @@ DrmPipeline::Error DrmPipeline::commitPipelinesAtomic(const QVectoractivePending()) { - if (!pipeline->m_pending.layer->checkTestBuffer()) { + if (!pipeline->m_primaryLayer->checkTestBuffer()) { qCWarning(KWIN_DRM) << "Checking test buffer failed for" << mode; return Error::TestBufferFailed; } @@ -231,7 +231,7 @@ bool DrmPipeline::prepareAtomicPresentation(DrmAtomicCommit *commit) return false; } - const auto fb = m_pending.layer->currentBuffer(); + const auto fb = m_primaryLayer->currentBuffer(); m_pending.crtc->primaryPlane()->set(commit, QPoint(0, 0), fb->buffer()->size(), centerBuffer(fb->buffer()->size(), m_pending.mode->size())); commit->addBuffer(m_pending.crtc->primaryPlane(), fb); @@ -453,7 +453,7 @@ QMap> DrmPipeline::cursorFormats() const bool DrmPipeline::pruneModifier() { - const DmaBufAttributes *dmabufAttributes = m_pending.layer->currentBuffer() ? m_pending.layer->currentBuffer()->buffer()->dmabufAttributes() : nullptr; + const DmaBufAttributes *dmabufAttributes = m_primaryLayer->currentBuffer() ? m_primaryLayer->currentBuffer()->buffer()->dmabufAttributes() : nullptr; if (!dmabufAttributes) { return false; } @@ -547,12 +547,12 @@ bool DrmPipeline::enabled() const DrmPipelineLayer *DrmPipeline::primaryLayer() const { - return m_pending.layer.get(); + return m_primaryLayer.get(); } DrmOverlayLayer *DrmPipeline::cursorLayer() const { - return m_pending.cursorLayer.get(); + return m_cursorLayer.get(); } DrmPlane::Transformations DrmPipeline::renderOrientation() const @@ -625,8 +625,8 @@ void DrmPipeline::setEnable(bool enable) void DrmPipeline::setLayers(const std::shared_ptr &primaryLayer, const std::shared_ptr &cursorLayer) { - m_pending.layer = primaryLayer; - m_pending.cursorLayer = cursorLayer; + m_primaryLayer = primaryLayer; + m_cursorLayer = cursorLayer; } void DrmPipeline::setRenderOrientation(DrmPlane::Transformations orientation) diff --git a/src/backends/drm/drm_pipeline.h b/src/backends/drm/drm_pipeline.h index e94583bc7f..6c574b9b70 100644 --- a/src/backends/drm/drm_pipeline.h +++ b/src/backends/drm/drm_pipeline.h @@ -98,13 +98,15 @@ public: void setOutput(DrmOutput *output); DrmOutput *output() const; + void setLayers(const std::shared_ptr &primaryLayer, const std::shared_ptr &cursorLayer); + DrmPipelineLayer *primaryLayer() const; + DrmOverlayLayer *cursorLayer() const; + DrmCrtc *crtc() const; std::shared_ptr mode() const; bool active() const; bool activePending() const; bool enabled() const; - DrmPipelineLayer *primaryLayer() const; - DrmOverlayLayer *cursorLayer() const; DrmPlane::Transformations renderOrientation() const; RenderLoopPrivate::SyncMode syncMode() const; uint32_t overscan() const; @@ -118,7 +120,6 @@ public: void setMode(const std::shared_ptr &mode); void setActive(bool active); void setEnable(bool enable); - void setLayers(const std::shared_ptr &primaryLayer, const std::shared_ptr &cursorLayer); void setRenderOrientation(DrmPlane::Transformations orientation); void setSyncMode(RenderLoopPrivate::SyncMode mode); void setOverscan(uint32_t overscan); @@ -189,8 +190,6 @@ private: double sdrBrightness = 200; ColorDescription colorDescription = ColorDescription::sRGB; - std::shared_ptr layer; - std::shared_ptr cursorLayer; QPoint cursorHotspot; // the transformation that buffers submitted to the pipeline should have @@ -204,6 +203,8 @@ private: State m_current; std::unique_ptr m_commitThread; + std::shared_ptr m_primaryLayer; + std::shared_ptr m_cursorLayer; }; } diff --git a/src/backends/drm/drm_pipeline_legacy.cpp b/src/backends/drm/drm_pipeline_legacy.cpp index 45147804df..a2d6c6e0cd 100644 --- a/src/backends/drm/drm_pipeline_legacy.cpp +++ b/src/backends/drm/drm_pipeline_legacy.cpp @@ -31,7 +31,7 @@ DrmPipeline::Error DrmPipeline::presentLegacy() return err; } } - const auto buffer = m_pending.layer->currentBuffer(); + const auto buffer = m_primaryLayer->currentBuffer(); uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT; if (m_pending.syncMode == RenderLoopPrivate::SyncMode::Async || m_pending.syncMode == RenderLoopPrivate::SyncMode::AdaptiveAsync) { flags |= DRM_MODE_PAGE_FLIP_ASYNC; @@ -54,10 +54,10 @@ void DrmPipeline::forceLegacyModeset() DrmPipeline::Error DrmPipeline::legacyModeset() { - if (!m_pending.layer->checkTestBuffer()) { + if (!m_primaryLayer->checkTestBuffer()) { return Error::TestBufferFailed; } - auto commit = std::make_unique(this, m_pending.layer->currentBuffer()); + auto commit = std::make_unique(this, m_primaryLayer->currentBuffer()); if (!commit->doModeset(m_connector, m_pending.mode.get())) { qCWarning(KWIN_DRM) << "Modeset failed!" << strerror(errno); return errnoToError(); @@ -155,8 +155,8 @@ bool DrmPipeline::setCursorLegacy() struct drm_mode_cursor2 arg = { .flags = DRM_MODE_CURSOR_BO | DRM_MODE_CURSOR_MOVE, .crtc_id = m_pending.crtc->id(), - .x = m_pending.cursorLayer->position().x(), - .y = m_pending.cursorLayer->position().y(), + .x = m_cursorLayer->position().x(), + .y = m_cursorLayer->position().y(), .width = (uint32_t)gpu()->cursorSize().width(), .height = (uint32_t)gpu()->cursorSize().height(), .handle = handle,