From 6ab6d3124a910d934d7e1467c31c4e324649361d Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 2 Nov 2022 20:06:00 +0100 Subject: [PATCH] screencasting: Make sure we are reporting properly scaled damage values It should be in stream pixels rather than logical --- .../screencast/regionscreencastsource.h | 4 ++++ src/plugins/screencast/screencastmanager.cpp | 23 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/plugins/screencast/regionscreencastsource.h b/src/plugins/screencast/regionscreencastsource.h index d5ce6d0047..2cf0d61b2f 100644 --- a/src/plugins/screencast/regionscreencastsource.h +++ b/src/plugins/screencast/regionscreencastsource.h @@ -34,6 +34,10 @@ public: { return m_region; } + qreal scale() const + { + return m_scale; + } void updateOutput(Output *output); private: diff --git a/src/plugins/screencast/screencastmanager.cpp b/src/plugins/screencast/screencastmanager.cpp index 947311bee1..940aef9205 100644 --- a/src/plugins/screencast/screencastmanager.cpp +++ b/src/plugins/screencast/screencastmanager.cpp @@ -38,6 +38,23 @@ ScreencastManager::ScreencastManager() connect(m_screencast, &KWaylandServer::ScreencastV1Interface::regionScreencastRequested, this, &ScreencastManager::streamRegion); } +static QRegion scaleRegion(const QRegion &_region, qreal scale) +{ + if (scale == 1.) { + return _region; + } + + QRegion region; + for (auto it = _region.begin(), itEnd = _region.end(); it != itEnd; ++it) { + region += QRect(std::floor(it->x() * scale), + std::floor(it->y() * scale), + std::ceil(it->width() * scale), + std::ceil(it->height() * scale)); + } + + return region; +} + class WindowStream : public ScreenCastStream { public: @@ -136,9 +153,9 @@ void ScreencastManager::streamOutput(KWaylandServer::ScreencastStreamV1Interface auto stream = new ScreenCastStream(new OutputScreenCastSource(streamOutput), this); stream->setObjectName(streamOutput->name()); stream->setCursorMode(mode, streamOutput->scale(), streamOutput->geometry()); - auto bufferToStream = [stream](const QRegion &damagedRegion) { + auto bufferToStream = [stream, streamOutput](const QRegion &damagedRegion) { if (!damagedRegion.isEmpty()) { - stream->recordFrame(damagedRegion); + stream->recordFrame(scaleRegion(damagedRegion, streamOutput->scale())); } }; connect(stream, &ScreenCastStream::startStreaming, waylandStream, [streamOutput, stream, bufferToStream] { @@ -179,7 +196,7 @@ void ScreencastManager::streamRegion(KWaylandServer::ScreencastStreamV1Interface const QRect streamRegion = source->region(); const QRegion region = output->pixelSize() != output->modeSize() ? output->geometry() : damagedRegion; source->updateOutput(output); - stream->recordFrame(region.translated(-streamRegion.topLeft()).intersected(streamRegion)); + stream->recordFrame(scaleRegion(region.translated(-streamRegion.topLeft()).intersected(streamRegion), source->scale())); }; connect(output, &Output::outputChange, stream, bufferToStream); }