From 6d6c9514029e693a88c6fd0df810a944a9d74695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 16 Apr 2015 13:23:33 +0200 Subject: [PATCH] Set the drm mode again when stride changed compared to previous buffer Includes better error handling for when page flip failed. If it fails, we shouldn't set the current buffer as otherwise each new attempt to present a buffer will fail, too. --- drm_backend.cpp | 29 ++++++++++++++++++++++++++--- drm_backend.h | 5 +++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/drm_backend.cpp b/drm_backend.cpp index 0de5c4c89e..d1feb64e9f 100644 --- a/drm_backend.cpp +++ b/drm_backend.cpp @@ -432,8 +432,20 @@ bool DrmOutput::present(DrmBuffer *buffer) if (m_currentBuffer) { return false; } - m_currentBuffer = buffer; - return drmModePageFlip(m_backend->fd(), m_crtcId, buffer->bufferId(), DRM_MODE_PAGE_FLIP_EVENT, this) == 0; + if (m_lastStride != buffer->stride()) { + // need to set a new mode first + if (!setMode(buffer)) { + return false; + } + } + const bool ok = drmModePageFlip(m_backend->fd(), m_crtcId, buffer->bufferId(), DRM_MODE_PAGE_FLIP_EVENT, this) == 0; + if (ok) { + m_currentBuffer = buffer; + } else { + qWarning(KWIN_CORE) << "Page flip failed"; + buffer->releaseGbm(); + } + return ok; } void DrmOutput::pageFlipped() @@ -467,7 +479,18 @@ void DrmOutput::blank() m_blackBuffer->map(); m_blackBuffer->image()->fill(Qt::black); } - drmModeSetCrtc(m_backend->fd(), m_crtcId, m_blackBuffer->bufferId(), 0, 0, &m_connector, 1, &m_mode); + setMode(m_blackBuffer); +} + +bool DrmOutput::setMode(DrmBuffer *buffer) +{ + if (drmModeSetCrtc(m_backend->fd(), m_crtcId, buffer->bufferId(), 0, 0, &m_connector, 1, &m_mode) == 0) { + m_lastStride = buffer->stride(); + return true; + } else { + qCWarning(KWIN_CORE) << "Mode setting failed"; + return false; + } } DrmBuffer::DrmBuffer(DrmBackend *backend, const QSize &size) diff --git a/drm_backend.h b/drm_backend.h index d26c0235b1..6a6aea6441 100644 --- a/drm_backend.h +++ b/drm_backend.h @@ -103,11 +103,13 @@ private: friend class DrmBackend; DrmOutput(DrmBackend *backend); void cleanupBlackBuffer(); + bool setMode(DrmBuffer *buffer); DrmBackend *m_backend; QPoint m_globalPos; quint32 m_crtcId = 0; quint32 m_connector = 0; + quint32 m_lastStride = 0; drmModeModeInfo m_mode; DrmBuffer *m_currentBuffer = nullptr; DrmBuffer *m_blackBuffer = nullptr; @@ -137,6 +139,9 @@ public: quint32 bufferId() const { return m_bufferId; } + quint32 stride() const { + return m_stride; + } void releaseGbm(); private: