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
This commit is contained in:
Xaver Hugl 2023-01-30 14:07:03 +01:00
parent 92439c511b
commit 0ef7d20fde
2 changed files with 10 additions and 10 deletions

View file

@ -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,

View file

@ -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<OpenGLBackend *>(Compositor::self()->backend())->makeCurrent();
QRegion damagedRegion = _damagedRegion;
Q_ASSERT(!m_stopped);