From 913d242bd9834248bcc1106d37a9d6b107689e6a Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 6 Apr 2021 11:53:26 +0300 Subject: [PATCH] platforms/drm: Fix crash in EglGbmBackend::presentOnOutput() If the damage history is empty and EGL_KHR_partial_update is supported, kwin may crash. --- src/plugins/platforms/drm/egl_gbm_backend.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/drm/egl_gbm_backend.cpp b/src/plugins/platforms/drm/egl_gbm_backend.cpp index 32bcb7dd74..4926d59800 100644 --- a/src/plugins/platforms/drm/egl_gbm_backend.cpp +++ b/src/plugins/platforms/drm/egl_gbm_backend.cpp @@ -584,7 +584,7 @@ bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion output.buffer = QSharedPointer::create(m_gpu, output.directScanoutBuffer, output.bufferInterface); } else if (isPrimary()) { if (supportsSwapBuffersWithDamage()) { - QVector rects = regionToRects(output.damageHistory.constFirst(), output.output); + QVector rects = regionToRects(damagedRegion, output.output); if (!eglSwapBuffersWithDamageEXT(eglDisplay(), output.eglSurface, rects.data(), rects.count() / 4)) { qCCritical(KWIN_DRM, "eglSwapBuffersWithDamageEXT() failed: %x", eglGetError()); @@ -676,7 +676,8 @@ void EglGbmBackend::endFrame(int screenId, const QRegion &renderedRegion, renderFramebufferToSurface(output); - if (!presentOnOutput(output, damagedRegion)) { + const QRegion dirty = damagedRegion.intersected(output.output->geometry()); + if (!presentOnOutput(output, dirty)) { output.damageHistory.clear(); RenderLoopPrivate *renderLoopPrivate = RenderLoopPrivate::get(drmOutput->renderLoop()); renderLoopPrivate->notifyFrameFailed(); @@ -684,7 +685,6 @@ void EglGbmBackend::endFrame(int screenId, const QRegion &renderedRegion, } if (supportsBufferAge()) { - const QRegion dirty = damagedRegion.intersected(output.output->geometry()); if (output.damageHistory.count() > 10) { output.damageHistory.removeLast(); }