From 7782cb6853e32615c26e622589c5d425ab0ff096 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 5 Jun 2023 13:24:23 +0300 Subject: [PATCH] core: Add GraphicsBufferOptions::software The software flag indicates whether the graphics buffer allocator needs to allocate a buffer suitable for software rendering. Its intended usage is to allow the gbm allocator to allocate both dmabuf and dumb buffers. --- src/backends/virtual/virtual_qpainter_backend.cpp | 1 + src/backends/wayland/wayland_qpainter_backend.cpp | 1 + src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp | 1 + src/core/gbmgraphicsbufferallocator.cpp | 4 ++++ src/core/graphicsbufferallocator.h | 3 +++ src/core/shmgraphicsbufferallocator.cpp | 3 +++ 6 files changed, 13 insertions(+) diff --git a/src/backends/virtual/virtual_qpainter_backend.cpp b/src/backends/virtual/virtual_qpainter_backend.cpp index ff8af606c3..8dd4cedc9f 100644 --- a/src/backends/virtual/virtual_qpainter_backend.cpp +++ b/src/backends/virtual/virtual_qpainter_backend.cpp @@ -80,6 +80,7 @@ std::shared_ptr VirtualQPainterSwapchain::acquire() ShmGraphicsBuffer *buffer = m_allocator->allocate(GraphicsBufferOptions{ .size = m_size, .format = m_format, + .software = true, }); if (!buffer) { qCDebug(KWIN_VIRTUAL) << "Did not get a new Buffer from Shm Pool"; diff --git a/src/backends/wayland/wayland_qpainter_backend.cpp b/src/backends/wayland/wayland_qpainter_backend.cpp index d9c1ab1ae0..d87af62560 100644 --- a/src/backends/wayland/wayland_qpainter_backend.cpp +++ b/src/backends/wayland/wayland_qpainter_backend.cpp @@ -84,6 +84,7 @@ std::shared_ptr WaylandQPainterSwapchain::acquire() ShmGraphicsBuffer *buffer = m_allocator->allocate(GraphicsBufferOptions{ .size = m_size, .format = m_format, + .software = true, }); if (!buffer) { qCDebug(KWIN_WAYLAND_BACKEND) << "Did not get a new Buffer from Shm Pool"; diff --git a/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp b/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp index bf968260b0..29ce502eb4 100644 --- a/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_qpainter_backend.cpp @@ -91,6 +91,7 @@ std::shared_ptr X11WindowedQPainterLayerSwapchai ShmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(GraphicsBufferOptions{ .size = m_size, .format = m_format, + .software = true, }); if (!graphicsBuffer) { qCWarning(KWIN_X11WINDOWED) << "Failed to allocate a shared memory graphics buffer"; diff --git a/src/core/gbmgraphicsbufferallocator.cpp b/src/core/gbmgraphicsbufferallocator.cpp index da49668286..57a4ef6360 100644 --- a/src/core/gbmgraphicsbufferallocator.cpp +++ b/src/core/gbmgraphicsbufferallocator.cpp @@ -24,6 +24,10 @@ GbmGraphicsBufferAllocator::~GbmGraphicsBufferAllocator() GbmGraphicsBuffer *GbmGraphicsBufferAllocator::allocate(const GraphicsBufferOptions &options) { + if (options.software) { + return nullptr; + } + if (!options.modifiers.isEmpty() && !(options.modifiers.size() == 1 && options.modifiers.first() == DRM_FORMAT_MOD_INVALID)) { gbm_bo *bo = gbm_bo_create_with_modifiers(m_gbmDevice, options.size.width(), diff --git a/src/core/graphicsbufferallocator.h b/src/core/graphicsbufferallocator.h index 89865ebb7b..cb0564190e 100644 --- a/src/core/graphicsbufferallocator.h +++ b/src/core/graphicsbufferallocator.h @@ -29,6 +29,9 @@ struct GraphicsBufferOptions /// An optional list of modifiers, see DRM_FORMAT_MOD_*. QVector modifiers; + + /// Whether the graphics buffer should be suitable for software rendering. + bool software = false; }; class KWIN_EXPORT GraphicsBufferAllocator diff --git a/src/core/shmgraphicsbufferallocator.cpp b/src/core/shmgraphicsbufferallocator.cpp index d710b25cd2..2c1256973d 100644 --- a/src/core/shmgraphicsbufferallocator.cpp +++ b/src/core/shmgraphicsbufferallocator.cpp @@ -38,6 +38,9 @@ const ShmAttributes *ShmGraphicsBuffer::shmAttributes() const ShmGraphicsBuffer *ShmGraphicsBufferAllocator::allocate(const GraphicsBufferOptions &options) { + if (!options.software) { + return nullptr; + } if (!options.modifiers.isEmpty()) { return nullptr; }