From c30339cc82c5f9d175ee7ceabf0fb0e68f067a9e Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 29 Mar 2022 21:35:36 +0200 Subject: [PATCH] backends/drm: move texture creation for gbm buffers into GbmBuffer --- src/backends/drm/drm_buffer_gbm.cpp | 15 +++++++++++++++ src/backends/drm/drm_buffer_gbm.h | 3 +++ src/backends/drm/egl_gbm_layer.cpp | 20 +++++--------------- src/backends/drm/egl_gbm_layer.h | 3 ++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/backends/drm/drm_buffer_gbm.cpp b/src/backends/drm/drm_buffer_gbm.cpp index cf2fb31cc9..779508e222 100644 --- a/src/backends/drm/drm_buffer_gbm.cpp +++ b/src/backends/drm/drm_buffer_gbm.cpp @@ -11,6 +11,8 @@ #include "gbm_surface.h" #include "drm_gpu.h" +#include "kwineglimagetexture.h" +#include "kwineglutils_p.h" #include "logging.h" // system @@ -129,6 +131,19 @@ uint32_t GbmBuffer::stride() const return m_stride; } +QSharedPointer GbmBuffer::createTexture(EGLDisplay eglDisplay) const +{ + if (!m_bo) { + return nullptr; + } + EGLImageKHR image = eglCreateImageKHR(eglDisplay, nullptr, EGL_NATIVE_PIXMAP_KHR, m_bo, nullptr); + if (image == EGL_NO_IMAGE_KHR) { + qCWarning(KWIN_DRM) << "Failed to record frame: Error creating EGLImageKHR - " << getEglErrorString(); + return nullptr; + } + return QSharedPointer::create(eglDisplay, image, GL_RGBA8, QSize(gbm_bo_get_width(m_bo), gbm_bo_get_height(m_bo))); +} + DrmGbmBuffer::DrmGbmBuffer(DrmGpu *gpu, GbmSurface *surface, gbm_bo *bo) : DrmBuffer(gpu, gbm_bo_get_format(bo), gbm_bo_get_modifier(bo)) , GbmBuffer(surface, bo) diff --git a/src/backends/drm/drm_buffer_gbm.h b/src/backends/drm/drm_buffer_gbm.h index c6ee25c6d4..95d6240a74 100644 --- a/src/backends/drm/drm_buffer_gbm.h +++ b/src/backends/drm/drm_buffer_gbm.h @@ -13,6 +13,7 @@ #include "drm_buffer.h" #include +#include struct gbm_bo; @@ -26,6 +27,7 @@ namespace KWin { class GbmSurface; +class GLTexture; class GbmBuffer : public QObject { @@ -42,6 +44,7 @@ public: uint32_t stride() const; KWaylandServer::ClientBuffer *clientBuffer() const; gbm_bo *getBo() const; + QSharedPointer createTexture(EGLDisplay eglDisplay) const; protected: GbmSurface *m_surface = nullptr; diff --git a/src/backends/drm/egl_gbm_layer.cpp b/src/backends/drm/egl_gbm_layer.cpp index 1a894c4ba9..03d22f8b17 100644 --- a/src/backends/drm/egl_gbm_layer.cpp +++ b/src/backends/drm/egl_gbm_layer.cpp @@ -294,26 +294,16 @@ 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_pipeline->sourceSize()); - }; if (m_scanoutBuffer) { - return createImage(dynamic_cast(m_scanoutBuffer.data())); - } - if (m_shadowBuffer) { + return m_scanoutBuffer->createTexture(m_eglBackend->eglDisplay()); + } else if (m_shadowBuffer) { return m_shadowBuffer->texture(); - } - GbmBuffer *gbmBuffer = m_gbmSurface->currentBuffer().data(); - if (!gbmBuffer) { + } else if (GbmBuffer *gbmBuffer = m_gbmSurface->currentBuffer().data()) { + return gbmBuffer->createTexture(m_eglBackend->eglDisplay()); + } else { qCWarning(KWIN_DRM) << "Failed to record frame: No gbm buffer!"; return nullptr; } - return createImage(gbmBuffer); } QSharedPointer EglGbmLayer::importBuffer() diff --git a/src/backends/drm/egl_gbm_layer.h b/src/backends/drm/egl_gbm_layer.h index bf16e998a4..8bcf9899cb 100644 --- a/src/backends/drm/egl_gbm_layer.h +++ b/src/backends/drm/egl_gbm_layer.h @@ -29,6 +29,7 @@ class GbmSurface; class DumbSwapchain; class ShadowBuffer; class EglGbmBackend; +class DrmGbmBuffer; class EglGbmLayer : public DrmPipelineLayer { @@ -75,7 +76,7 @@ private: bool attemptedThisFrame = false; } m_scanoutCandidate; - QSharedPointer m_scanoutBuffer; + QSharedPointer m_scanoutBuffer; QSharedPointer m_currentBuffer; QRegion m_currentDamage; QSharedPointer m_gbmSurface;