From 72d9711e5dbecf710666f2121c86a2402c5a9944 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 28 Feb 2022 17:27:44 +0100 Subject: [PATCH] backends/drm: fix recording with direct scanout BUG: 450943 --- src/backends/drm/egl_gbm_layer.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/backends/drm/egl_gbm_layer.cpp b/src/backends/drm/egl_gbm_layer.cpp index 0938c73618..45b4a838ae 100644 --- a/src/backends/drm/egl_gbm_layer.cpp +++ b/src/backends/drm/egl_gbm_layer.cpp @@ -20,6 +20,7 @@ #include "surfaceitem_wayland.h" #include "kwineglimagetexture.h" #include "drm_backend.h" +#include "kwineglutils_p.h" #include "KWaylandServer/surface_interface.h" #include "KWaylandServer/linuxdmabufv1clientbuffer.h" @@ -241,20 +242,26 @@ bool EglGbmLayer::doesSwapchainFit(DumbSwapchain *swapchain) const QSharedPointer EglGbmLayer::texture() const { + const auto createImage = [this](GbmBuffer *gbmBuffer) { + EGLImageKHR image = eglCreateImageKHR(m_eglBackend->eglDisplay(), nullptr, EGL_NATIVE_PIXMAP_KHR, gbmBuffer->getBo(), nullptr); + if (image == EGL_NO_IMAGE_KHR) { + qCWarning(KWIN_DRM) << "Failed to record frame: Error creating EGLImageKHR - " << getEglErrorString(); + return QSharedPointer(nullptr); + } + return QSharedPointer::create(m_eglBackend->eglDisplay(), image, GL_RGBA8, m_displayDevice->sourceSize()); + }; + if (m_scanoutBuffer) { + return createImage(dynamic_cast(m_scanoutBuffer.data())); + } if (m_shadowBuffer) { return m_shadowBuffer->texture(); } - GbmBuffer *gbmBuffer = m_gbmSurface->currentBuffer().get(); + GbmBuffer *gbmBuffer = m_gbmSurface->currentBuffer().data(); if (!gbmBuffer) { qCWarning(KWIN_DRM) << "Failed to record frame: No gbm buffer!"; return nullptr; } - EGLImageKHR image = eglCreateImageKHR(m_eglBackend->eglDisplay(), nullptr, EGL_NATIVE_PIXMAP_KHR, gbmBuffer->getBo(), nullptr); - if (image == EGL_NO_IMAGE_KHR) { - qCWarning(KWIN_DRM) << "Failed to record frame: Error creating EGLImageKHR - " << glGetError(); - return nullptr; - } - return QSharedPointer::create(m_eglBackend->eglDisplay(), image, GL_RGBA8, m_displayDevice->sourceSize()); + return createImage(gbmBuffer); } QSharedPointer EglGbmLayer::importBuffer()