From 0ef7d20fde25536eb97e989e5a15070f7f2126a0 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 30 Jan 2023 14:07:03 +0100 Subject: [PATCH] plugins/screencast: fix window recording while no scene rendering happens This affects direct scanout and when the window isn't triggering desktop repaints otherwise, like being minimized or on a different virtual desktop or activity --- src/plugins/screencast/screencastmanager.cpp | 18 ++++++++---------- src/plugins/screencast/screencaststream.cpp | 2 ++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/screencast/screencastmanager.cpp b/src/plugins/screencast/screencastmanager.cpp index 75bcd4a926..75a5d3e66a 100644 --- a/src/plugins/screencast/screencastmanager.cpp +++ b/src/plugins/screencast/screencastmanager.cpp @@ -62,7 +62,10 @@ public: : ScreenCastStream(new WindowScreenCastSource(window), parent) , m_window(window) { + m_timer.setInterval(0); + m_timer.setSingleShot(true); setObjectName(window->desktopFileName()); + connect(&m_timer, &QTimer::timeout, this, &WindowStream::bufferToStream); connect(this, &ScreenCastStream::startStreaming, this, &WindowStream::startFeeding); connect(this, &ScreenCastStream::stopStreaming, this, &WindowStream::stopFeeding); } @@ -70,33 +73,28 @@ public: private: void startFeeding() { - connect(Compositor::self()->scene(), &WorkspaceScene::frameRendered, this, &WindowStream::bufferToStream); - connect(m_window, &Window::damaged, this, &WindowStream::markDirty); markDirty(); - m_window->output()->renderLoop()->scheduleRepaint(); } void stopFeeding() { - disconnect(Compositor::self()->scene(), &WorkspaceScene::frameRendered, this, &WindowStream::bufferToStream); + disconnect(m_window, &Window::damaged, this, &WindowStream::markDirty); + m_timer.stop(); } void markDirty() { - m_dirty = true; + m_timer.start(); } void bufferToStream() { - if (m_dirty) { - recordFrame(QRegion(0, 0, m_window->width(), m_window->height())); - m_dirty = false; - } + recordFrame(QRegion(0, 0, m_window->width(), m_window->height())); } Window *m_window; - bool m_dirty = false; + QTimer m_timer; }; void ScreencastManager::streamWindow(KWaylandServer::ScreencastStreamV1Interface *waylandStream, diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index 0fb0989871..3b7d7054a5 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -19,6 +19,7 @@ #include "kwinglutils.h" #include "kwinscreencast_logging.h" #include "main.h" +#include "openglbackend.h" #include "pipewirecore.h" #include "scene/workspacescene.h" #include "screencastsource.h" @@ -378,6 +379,7 @@ void ScreenCastStream::stop() void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) { + static_cast(Compositor::self()->backend())->makeCurrent(); QRegion damagedRegion = _damagedRegion; Q_ASSERT(!m_stopped);