plugins/screencast: send frame callbacks if the window is otherwise invisible
If we don't send frame callbacks, the application might stop rendering or throttle to single digit fps. BUG: 464217
This commit is contained in:
parent
7c58f169e0
commit
b89009f9e1
4 changed files with 63 additions and 3 deletions
|
@ -18,7 +18,6 @@
|
||||||
#include "scene/itemrenderer.h"
|
#include "scene/itemrenderer.h"
|
||||||
#include "scene/windowitem.h"
|
#include "scene/windowitem.h"
|
||||||
#include "scene/workspacescene.h"
|
#include "scene/workspacescene.h"
|
||||||
#include "window.h"
|
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
@ -26,6 +25,7 @@ namespace KWin
|
||||||
WindowScreenCastSource::WindowScreenCastSource(Window *window, QObject *parent)
|
WindowScreenCastSource::WindowScreenCastSource(Window *window, QObject *parent)
|
||||||
: ScreenCastSource(parent)
|
: ScreenCastSource(parent)
|
||||||
, m_window(window)
|
, m_window(window)
|
||||||
|
, m_offscreenRef(window)
|
||||||
{
|
{
|
||||||
connect(m_window, &Window::windowClosed, this, &ScreenCastSource::closed);
|
connect(m_window, &Window::windowClosed, this, &ScreenCastSource::closed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "screencastsource.h"
|
#include "screencastsource.h"
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
class Window;
|
|
||||||
|
|
||||||
class WindowScreenCastSource : public ScreenCastSource
|
class WindowScreenCastSource : public ScreenCastSource
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -31,6 +31,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<Window> m_window;
|
QPointer<Window> m_window;
|
||||||
|
WindowOffscreenRenderRef m_offscreenRef;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace KWin
|
} // namespace KWin
|
||||||
|
|
|
@ -119,6 +119,7 @@ Window::Window()
|
||||||
connect(Workspace::self()->applicationMenu(), &ApplicationMenu::applicationMenuEnabledChanged, this, [this] {
|
connect(Workspace::self()->applicationMenu(), &ApplicationMenu::applicationMenuEnabledChanged, this, [this] {
|
||||||
Q_EMIT hasApplicationMenuChanged(hasApplicationMenu());
|
Q_EMIT hasApplicationMenuChanged(hasApplicationMenu());
|
||||||
});
|
});
|
||||||
|
connect(&m_offscreenFramecallbackTimer, &QTimer::timeout, this, &Window::maybeSendFrameCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
|
@ -4537,6 +4538,45 @@ bool Window::isLockScreenOverlay() const
|
||||||
return m_lockScreenOverlay;
|
return m_lockScreenOverlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::refOffscreenRendering()
|
||||||
|
{
|
||||||
|
if (m_offscreenRenderCount == 0) {
|
||||||
|
m_offscreenFramecallbackTimer.start(1'000'000 / output()->refreshRate());
|
||||||
|
}
|
||||||
|
m_offscreenRenderCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::unrefOffscreenRendering()
|
||||||
|
{
|
||||||
|
Q_ASSERT(m_offscreenRenderCount);
|
||||||
|
m_offscreenRenderCount--;
|
||||||
|
if (m_offscreenRenderCount == 0) {
|
||||||
|
m_offscreenFramecallbackTimer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::maybeSendFrameCallback()
|
||||||
|
{
|
||||||
|
if (m_surface && !m_windowItem->isVisible()) {
|
||||||
|
m_surface->frameRendered(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
|
||||||
|
// update refresh rate, it might have changed
|
||||||
|
m_offscreenFramecallbackTimer.start(1'000'000 / output()->refreshRate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowOffscreenRenderRef::WindowOffscreenRenderRef(Window *window)
|
||||||
|
: m_window(window)
|
||||||
|
{
|
||||||
|
window->refOffscreenRendering();
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowOffscreenRenderRef::~WindowOffscreenRenderRef()
|
||||||
|
{
|
||||||
|
if (m_window) {
|
||||||
|
m_window->unrefOffscreenRendering();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace KWin
|
} // namespace KWin
|
||||||
|
|
||||||
#include "moc_window.cpp"
|
#include "moc_window.cpp"
|
||||||
|
|
19
src/window.h
19
src/window.h
|
@ -27,6 +27,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
|
#include <QTimer>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
@ -1429,6 +1430,9 @@ public:
|
||||||
|
|
||||||
void setTile(Tile *tile);
|
void setTile(Tile *tile);
|
||||||
|
|
||||||
|
void refOffscreenRendering();
|
||||||
|
void unrefOffscreenRendering();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual void closeWindow() = 0;
|
virtual void closeWindow() = 0;
|
||||||
|
|
||||||
|
@ -1913,6 +1917,8 @@ private Q_SLOTS:
|
||||||
void shadeUnhover();
|
void shadeUnhover();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void maybeSendFrameCallback();
|
||||||
|
|
||||||
// when adding new data members, check also copyToDeleted()
|
// when adding new data members, check also copyToDeleted()
|
||||||
QUuid m_internalId;
|
QUuid m_internalId;
|
||||||
Xcb::Window m_client;
|
Xcb::Window m_client;
|
||||||
|
@ -2029,6 +2035,8 @@ private:
|
||||||
WindowRules m_rules;
|
WindowRules m_rules;
|
||||||
quint32 m_lastUsageSerial = 0;
|
quint32 m_lastUsageSerial = 0;
|
||||||
bool m_lockScreenOverlay = false;
|
bool m_lockScreenOverlay = false;
|
||||||
|
uint32_t m_offscreenRenderCount = 0;
|
||||||
|
QTimer m_offscreenFramecallbackTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2375,6 +2383,17 @@ inline void Window::setPendingMoveResizeMode(MoveResizeMode mode)
|
||||||
|
|
||||||
KWIN_EXPORT QDebug operator<<(QDebug debug, const Window *window);
|
KWIN_EXPORT QDebug operator<<(QDebug debug, const Window *window);
|
||||||
|
|
||||||
|
class KWIN_EXPORT WindowOffscreenRenderRef
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowOffscreenRenderRef(Window *window);
|
||||||
|
WindowOffscreenRenderRef() = default;
|
||||||
|
~WindowOffscreenRenderRef();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer<Window> m_window;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace KWin
|
} // namespace KWin
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(KWin::Window *)
|
Q_DECLARE_METATYPE(KWin::Window *)
|
||||||
|
|
Loading…
Reference in a new issue