From 378472f8b28b8d7126da5f27c7cf1bd1de74886c Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 12 Mar 2024 00:43:55 +0100 Subject: [PATCH] pw: Improve fb allocation code. Don't set the video size using the data coming from xdp, instead use the data coming from pipewire, which is what matters. Also make sure setVideoSize is called before using the buffer rather than after. --- framebuffers/pipewire/pw_framebuffer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/framebuffers/pipewire/pw_framebuffer.cpp b/framebuffers/pipewire/pw_framebuffer.cpp index f0b718ea..bb6ea51d 100644 --- a/framebuffers/pipewire/pw_framebuffer.cpp +++ b/framebuffers/pipewire/pw_framebuffer.cpp @@ -334,7 +334,6 @@ void PWFrameBuffer::Private::handleRemoteDesktopStarted(quint32 code, const QVar isValid = false; return; } - setVideoSize(qdbus_cast(streams.first().map[QStringLiteral("size")].value())); } void PWFrameBuffer::Private::handleFrame(const PipeWireFrame &frame) @@ -348,17 +347,20 @@ void PWFrameBuffer::Private::handleFrame(const PipeWireFrame &frame) } if (frame.dataFrame) { - memcpy(q->fb, frame.dataFrame->data, frame.dataFrame->size.width() * frame.dataFrame->stride); + // FIXME: Assuming stride == width * 4, not sure to which extent this holds setVideoSize(frame.dataFrame->size); + memcpy(q->fb, frame.dataFrame->data, frame.dataFrame->size.width() * frame.dataFrame->stride); } else if (frame.dmabuf) { - QImage src((uchar*) q->fb, videoSize.width(), videoSize.height(), QImage::Format_RGB32); + // FIXME: Assuming stride == width * 4, not sure to which extent this holds + const QSize size = { frame.dmabuf->width, frame.dmabuf->height }; + setVideoSize(size); + QImage src(reinterpret_cast(q->fb), size.width(), size.height(), QImage::Format_RGB32); if (!m_dmabufHandler.downloadFrame(src, frame)) { stream->renegotiateModifierFailed(frame.format, frame.dmabuf->modifier); qCDebug(KRFB_FB_PIPEWIRE) << "Failed to download frame."; return; } - setVideoSize(src.size()); } else { qCDebug(KRFB_FB_PIPEWIRE) << "Unknown kind of frame"; }