Use dma-bufs for screensharing only when client asks for it

epel9
Jan Grulich 4 years ago
parent 6fdc244579
commit b368c51222

@ -0,0 +1,55 @@
From caaabf84df3aaf96eb0fcccc8c17baefe97826b5 Mon Sep 17 00:00:00 2001
From: Jan Grulich <jgrulich@redhat.com>
Date: Wed, 5 May 2021 10:01:49 +0200
Subject: [PATCH] Screencast: use dma-bufs only when client explicitly asks for
it
---
src/plugins/screencast/pipewirestream.cpp | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/plugins/screencast/pipewirestream.cpp b/src/plugins/screencast/pipewirestream.cpp
index 8f9ed30e0..1e86f8b81 100644
--- a/src/plugins/screencast/pipewirestream.cpp
+++ b/src/plugins/screencast/pipewirestream.cpp
@@ -106,13 +106,16 @@ void PipeWireStream::onStreamParamChanged(void *data, uint32_t id, const struct
void PipeWireStream::onStreamAddBuffer(void *data, pw_buffer *buffer)
{
+ QSharedPointer<DmaBufTexture> dmabuf;
PipeWireStream *stream = static_cast<PipeWireStream *>(data);
struct spa_data *spa_data = buffer->buffer->datas;
spa_data->mapoffset = 0;
spa_data->flags = SPA_DATA_FLAG_READWRITE;
- QSharedPointer<DmaBufTexture> dmabuf(kwinApp()->platform()->createDmaBufTexture(stream->m_resolution));
+ if (spa_data[0].type != SPA_ID_INVALID && spa_data[0].type & (1 << SPA_DATA_DmaBuf))
+ dmabuf.reset(kwinApp()->platform()->createDmaBufTexture(stream->m_resolution));
+
if (dmabuf) {
spa_data->type = SPA_DATA_DmaBuf;
spa_data->fd = dmabuf->fd();
@@ -122,6 +125,11 @@ void PipeWireStream::onStreamAddBuffer(void *data, pw_buffer *buffer)
stream->m_dmabufDataForPwBuffer.insert(buffer, dmabuf);
#ifdef F_SEAL_SEAL //Disable memfd on systems that don't have it, like BSD < 12
} else {
+ if (!(spa_data[0].type & (1 << SPA_DATA_MemFd))) {
+ qCCritical(KWIN_SCREENCAST) << "memfd: Client doesn't support memfd buffer data type";
+ return;
+ }
+
const int bytesPerPixel = stream->m_hasAlpha ? 4 : 3;
const int stride = SPA_ROUND_UP_N (stream->m_resolution.width() * bytesPerPixel, 4);
spa_data->maxsize = stride * stream->m_resolution.height();
@@ -341,7 +349,7 @@ void PipeWireStream::recordFrame(GLTexture *frameTexture, const QRegion &damaged
const auto size = frameTexture->size();
spa_data->chunk->offset = 0;
- if (data) {
+ if (data || spa_data[0].type == SPA_DATA_MemFd) {
const int bpp = data && !m_hasAlpha ? 3 : 4;
const uint stride = SPA_ROUND_UP_N (size.width() * bpp, 4);
const uint bufferSize = stride * size.height();
--
GitLab

@ -17,7 +17,7 @@
Name: kwin
Version: 5.21.5
Release: 1%{?dist}
Release: 2%{?dist}
Summary: KDE Window manager
# all sources are effectively GPLv2+, except for:
@ -37,6 +37,7 @@ URL: https://userbase.kde.org/KWin
Source0: http://download.kde.org/%{stable}/plasma/%{version}/%{name}-%{version}.tar.xz
## upstream patches
Patch0: kwin-use-dmabufs-only-when-client-asks-for-it.patch
## proposed patches
@ -360,6 +361,9 @@ make test ARGS="--output-on-failure --timeout 10" -C %{_target_platform} ||:
%changelog
* Wed May 05 2021 Jan Grulich <jgrulich@redhat.com> - 5.21.5-2
- Use dma-bufs for screensharing only when client asks for it
* Tue May 04 2021 Jan Grulich <jgrulich@redhat.com> - 5.21.5-1
- 5.21.5

Loading…
Cancel
Save