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.
This commit is contained in:
Martin Gräßlin 2015-04-16 13:23:33 +02:00
parent 8278ae8487
commit 6d6c951402
2 changed files with 31 additions and 3 deletions

View file

@ -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)

View file

@ -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: