2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2023-08-31 12:23:42 +00:00
|
|
|
#include "compositor.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
#include <config-kwin.h>
|
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/outputlayer.h"
|
|
|
|
#include "core/renderlayer.h"
|
|
|
|
#include "core/renderloop.h"
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "dbusinterface.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "effects.h"
|
2020-09-07 08:11:47 +00:00
|
|
|
#include "ftrace.h"
|
2023-03-23 11:39:20 +00:00
|
|
|
#include "platformsupport/scenes/opengl/openglbackend.h"
|
|
|
|
#include "platformsupport/scenes/qpainter/qpainterbackend.h"
|
2023-05-11 07:11:43 +00:00
|
|
|
#include "scene/cursordelegate_opengl.h"
|
|
|
|
#include "scene/cursordelegate_qpainter.h"
|
2022-12-19 08:45:29 +00:00
|
|
|
#include "scene/cursorscene.h"
|
|
|
|
#include "scene/itemrenderer_opengl.h"
|
|
|
|
#include "scene/itemrenderer_qpainter.h"
|
2023-08-31 12:44:50 +00:00
|
|
|
#include "scene/surfaceitem.h"
|
2022-12-18 21:56:41 +00:00
|
|
|
#include "scene/workspacescene_opengl.h"
|
|
|
|
#include "scene/workspacescene_qpainter.h"
|
2022-01-18 08:35:52 +00:00
|
|
|
#include "utils/common.h"
|
2015-03-23 13:29:07 +00:00
|
|
|
#include "wayland_server.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "workspace.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2023-09-06 21:42:11 +00:00
|
|
|
#include "libkwineffects/glplatform.h"
|
2017-09-08 20:30:18 +00:00
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KLocalizedString>
|
2022-02-25 09:38:26 +00:00
|
|
|
#if KWIN_BUILD_NOTIFICATIONS
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KNotification>
|
2022-02-25 09:38:26 +00:00
|
|
|
#endif
|
2019-06-22 10:40:12 +00:00
|
|
|
#include <KSelectionOwner>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-06-22 10:00:56 +00:00
|
|
|
#include <QQuickWindow>
|
|
|
|
|
2012-12-11 20:21:35 +00:00
|
|
|
#include <xcb/composite.h>
|
2013-01-09 15:03:54 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
Compositor *Compositor::s_compositor = nullptr;
|
|
|
|
Compositor *Compositor::self()
|
|
|
|
{
|
|
|
|
return s_compositor;
|
|
|
|
}
|
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
class CompositorSelectionOwner : public KSelectionOwner
|
2013-04-26 15:11:37 +00:00
|
|
|
{
|
2019-06-22 10:40:12 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CompositorSelectionOwner(const char *selection)
|
2022-02-08 22:28:03 +00:00
|
|
|
: KSelectionOwner(selection, kwinApp()->x11Connection(), kwinApp()->x11RootWindow())
|
2019-06-22 10:40:12 +00:00
|
|
|
, m_owning(false)
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(this, &CompositorSelectionOwner::lostOwnership,
|
|
|
|
this, [this]() {
|
|
|
|
m_owning = false;
|
|
|
|
});
|
2019-06-22 10:40:12 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
bool owning() const
|
|
|
|
{
|
2019-06-22 10:40:12 +00:00
|
|
|
return m_owning;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
void setOwning(bool own)
|
|
|
|
{
|
2019-06-22 10:40:12 +00:00
|
|
|
m_owning = own;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
private:
|
|
|
|
bool m_owning;
|
|
|
|
};
|
2013-04-26 15:11:37 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
Compositor::Compositor(QObject *workspace)
|
2011-08-21 19:50:23 +00:00
|
|
|
: QObject(workspace)
|
|
|
|
{
|
2019-08-07 17:33:20 +00:00
|
|
|
connect(options, &Options::configChanged, this, &Compositor::configChanged);
|
2019-09-25 13:31:48 +00:00
|
|
|
connect(options, &Options::animationSpeedChanged, this, &Compositor::configChanged);
|
2019-07-02 22:57:53 +00:00
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// 2 sec which should be enough to restart the compositor.
|
2013-04-26 22:00:23 +00:00
|
|
|
static const int compositorLostMessageDelay = 2000;
|
|
|
|
|
|
|
|
m_releaseSelectionTimer.setSingleShot(true);
|
|
|
|
m_releaseSelectionTimer.setInterval(compositorLostMessageDelay);
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(&m_releaseSelectionTimer, &QTimer::timeout,
|
|
|
|
this, &Compositor::releaseCompositorSelection);
|
2013-04-26 22:00:23 +00:00
|
|
|
|
|
|
|
m_unusedSupportPropertyTimer.setInterval(compositorLostMessageDelay);
|
|
|
|
m_unusedSupportPropertyTimer.setSingleShot(true);
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(&m_unusedSupportPropertyTimer, &QTimer::timeout,
|
|
|
|
this, &Compositor::deleteUnusedSupportProperties);
|
2016-04-15 09:19:12 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
// Delay the call to start by one event cycle.
|
2016-04-15 09:19:12 +00:00
|
|
|
// The ctor of this class is invoked from the Workspace ctor, that means before
|
|
|
|
// Workspace is completely constructed, so calling Workspace::self() would result
|
|
|
|
// in undefined behavior. This is fixed by using a delayed invocation.
|
2022-11-11 08:46:19 +00:00
|
|
|
QTimer::singleShot(0, this, &Compositor::start);
|
2014-06-02 06:51:28 +00:00
|
|
|
|
|
|
|
// register DBus
|
|
|
|
new CompositorDBusInterface(this);
|
2020-09-07 08:11:47 +00:00
|
|
|
FTraceLogger::create();
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Compositor::~Compositor()
|
|
|
|
{
|
2013-04-26 22:00:23 +00:00
|
|
|
deleteUnusedSupportProperties();
|
2019-08-07 17:33:20 +00:00
|
|
|
destroyCompositorSelection();
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
s_compositor = nullptr;
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 10:08:06 +00:00
|
|
|
bool Compositor::attemptOpenGLCompositing()
|
|
|
|
{
|
|
|
|
// Some broken drivers crash on glXQuery() so to prevent constant KWin crashes:
|
2022-11-02 18:47:01 +00:00
|
|
|
if (openGLCompositingIsBroken()) {
|
2021-11-08 10:08:06 +00:00
|
|
|
qCWarning(KWIN_CORE) << "KWin has detected that your OpenGL library is unsafe to use";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-02 18:47:01 +00:00
|
|
|
createOpenGLSafePoint(OpenGLSafePoint::PreInit);
|
|
|
|
auto safePointScope = qScopeGuard([this]() {
|
|
|
|
createOpenGLSafePoint(OpenGLSafePoint::PostInit);
|
2021-11-08 10:08:06 +00:00
|
|
|
});
|
|
|
|
|
2022-11-05 10:43:41 +00:00
|
|
|
std::unique_ptr<OpenGLBackend> backend = kwinApp()->outputBackend()->createOpenGLBackend();
|
2021-11-08 10:08:06 +00:00
|
|
|
if (!backend) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!backend->isFailed()) {
|
|
|
|
backend->init();
|
|
|
|
}
|
|
|
|
if (backend->isFailed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-15 21:15:39 +00:00
|
|
|
const QByteArray forceEnv = qgetenv("KWIN_COMPOSE");
|
|
|
|
if (!forceEnv.isEmpty()) {
|
|
|
|
if (qstrcmp(forceEnv, "O2") == 0 || qstrcmp(forceEnv, "O2ES") == 0) {
|
|
|
|
qCDebug(KWIN_CORE) << "OpenGL 2 compositing enforced by environment variable";
|
|
|
|
} else {
|
|
|
|
// OpenGL 2 disabled by environment variable
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (GLPlatform::instance()->recommendedCompositor() < OpenGLCompositing) {
|
|
|
|
qCDebug(KWIN_CORE) << "Driver does not recommend OpenGL compositing";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only support the OpenGL 2+ shader API, not GL_ARB_shader_objects
|
|
|
|
if (!hasGLVersion(2, 0)) {
|
|
|
|
qCDebug(KWIN_CORE) << "OpenGL 2.0 is not supported";
|
2021-11-08 10:08:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-18 21:56:41 +00:00
|
|
|
m_scene = std::make_unique<WorkspaceSceneOpenGL>(backend.get());
|
2022-12-19 08:45:29 +00:00
|
|
|
m_cursorScene = std::make_unique<CursorScene>(std::make_unique<ItemRendererOpenGL>());
|
2022-06-22 10:33:32 +00:00
|
|
|
m_backend = std::move(backend);
|
2021-11-08 10:08:06 +00:00
|
|
|
|
2021-11-08 19:48:24 +00:00
|
|
|
// set strict binding
|
|
|
|
if (options->isGlStrictBindingFollowsDriver()) {
|
2023-08-03 11:02:59 +00:00
|
|
|
options->setGlStrictBinding(!GLPlatform::instance()->supports(GLFeature::LooseBinding));
|
2021-11-08 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2021-11-08 10:08:06 +00:00
|
|
|
qCDebug(KWIN_CORE) << "OpenGL compositing has been successfully initialized";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compositor::attemptQPainterCompositing()
|
|
|
|
{
|
2022-11-05 10:43:41 +00:00
|
|
|
std::unique_ptr<QPainterBackend> backend(kwinApp()->outputBackend()->createQPainterBackend());
|
2021-11-08 10:08:06 +00:00
|
|
|
if (!backend || backend->isFailed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-18 21:56:41 +00:00
|
|
|
m_scene = std::make_unique<WorkspaceSceneQPainter>(backend.get());
|
2022-12-19 08:45:29 +00:00
|
|
|
m_cursorScene = std::make_unique<CursorScene>(std::make_unique<ItemRendererQPainter>());
|
2022-06-22 10:33:32 +00:00
|
|
|
m_backend = std::move(backend);
|
2021-11-08 10:08:06 +00:00
|
|
|
|
|
|
|
qCDebug(KWIN_CORE) << "QPainter compositing has been successfully initialized";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
bool Compositor::setupStart()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-01-06 16:05:10 +00:00
|
|
|
if (kwinApp()->isTerminating()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Don't start while KWin is terminating. An event to restart might be lingering
|
|
|
|
// in the event queue due to graphics reset.
|
2019-08-07 17:33:20 +00:00
|
|
|
return false;
|
2019-01-06 16:05:10 +00:00
|
|
|
}
|
2019-07-04 01:19:18 +00:00
|
|
|
if (m_state != State::Off) {
|
2019-08-07 17:33:20 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2019-07-04 01:19:18 +00:00
|
|
|
m_state = State::Starting;
|
2011-02-27 22:39:32 +00:00
|
|
|
|
2023-09-19 12:30:45 +00:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
if (!m_selectionOwner) {
|
|
|
|
m_selectionOwner = std::make_unique<CompositorSelectionOwner>("_NET_WM_CM_S0");
|
|
|
|
connect(m_selectionOwner.get(), &CompositorSelectionOwner::lostOwnership, this, &Compositor::stop);
|
|
|
|
}
|
|
|
|
if (!m_selectionOwner->owning()) {
|
|
|
|
// Force claim ownership.
|
|
|
|
m_selectionOwner->claim(true);
|
|
|
|
m_selectionOwner->setOwning(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_composite_redirect_subwindows(kwinApp()->x11Connection(),
|
|
|
|
kwinApp()->x11RootWindow(),
|
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
|
|
|
}
|
2014-04-14 07:19:43 +00:00
|
|
|
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT aboutToToggleCompositing();
|
2019-02-20 13:09:37 +00:00
|
|
|
|
2022-11-05 10:43:41 +00:00
|
|
|
const QVector<CompositingType> availableCompositors = kwinApp()->outputBackend()->supportedCompositors();
|
2022-10-23 13:08:14 +00:00
|
|
|
QVector<CompositingType> candidateCompositors;
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2022-10-23 13:08:14 +00:00
|
|
|
// If compositing has been restarted, try to use the last used compositing type.
|
|
|
|
if (m_selectedCompositor != NoCompositing) {
|
|
|
|
candidateCompositors.append(m_selectedCompositor);
|
2017-10-18 19:56:13 +00:00
|
|
|
} else {
|
2022-10-23 13:08:14 +00:00
|
|
|
candidateCompositors = availableCompositors;
|
|
|
|
|
|
|
|
const auto userConfigIt = std::find(candidateCompositors.begin(), candidateCompositors.end(), options->compositingMode());
|
|
|
|
if (userConfigIt != candidateCompositors.end()) {
|
|
|
|
candidateCompositors.erase(userConfigIt);
|
|
|
|
candidateCompositors.prepend(options->compositingMode());
|
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_CORE) << "Configured compositor not supported by Platform. Falling back to defaults";
|
|
|
|
}
|
2017-10-18 19:56:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 19:02:23 +00:00
|
|
|
for (auto type : std::as_const(candidateCompositors)) {
|
2021-11-08 10:08:06 +00:00
|
|
|
bool stop = false;
|
2020-04-28 17:19:08 +00:00
|
|
|
switch (type) {
|
|
|
|
case OpenGLCompositing:
|
|
|
|
qCDebug(KWIN_CORE) << "Attempting to load the OpenGL scene";
|
2021-11-08 10:08:06 +00:00
|
|
|
stop = attemptOpenGLCompositing();
|
2020-04-28 17:19:08 +00:00
|
|
|
break;
|
|
|
|
case QPainterCompositing:
|
|
|
|
qCDebug(KWIN_CORE) << "Attempting to load the QPainter scene";
|
2021-11-08 10:08:06 +00:00
|
|
|
stop = attemptQPainterCompositing();
|
2020-04-28 17:19:08 +00:00
|
|
|
break;
|
|
|
|
case NoCompositing:
|
2021-07-05 08:53:26 +00:00
|
|
|
qCDebug(KWIN_CORE) << "Starting without compositing...";
|
2021-11-08 10:08:06 +00:00
|
|
|
stop = true;
|
2021-07-05 08:53:26 +00:00
|
|
|
break;
|
2020-04-28 17:19:08 +00:00
|
|
|
}
|
2021-11-08 10:08:06 +00:00
|
|
|
|
|
|
|
if (stop) {
|
|
|
|
break;
|
2023-06-07 15:27:53 +00:00
|
|
|
} else if (qEnvironmentVariableIsSet("KWIN_COMPOSE")) {
|
|
|
|
qCCritical(KWIN_CORE) << "Could not fulfill the requested compositing mode in KWIN_COMPOSE:" << type << ". Exiting.";
|
|
|
|
qApp->quit();
|
2017-08-10 16:13:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-10 10:10:34 +00:00
|
|
|
if (!m_backend) {
|
2019-07-04 01:19:18 +00:00
|
|
|
m_state = State::Off;
|
|
|
|
|
2023-09-19 12:30:45 +00:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
xcb_composite_unredirect_subwindows(kwinApp()->x11Connection(),
|
|
|
|
kwinApp()->x11RootWindow(),
|
2021-10-18 10:00:32 +00:00
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
2023-09-19 12:30:45 +00:00
|
|
|
if (m_selectionOwner) {
|
|
|
|
m_selectionOwner->setOwning(false);
|
|
|
|
m_selectionOwner->release();
|
|
|
|
}
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2022-10-23 13:08:14 +00:00
|
|
|
if (!availableCompositors.contains(NoCompositing)) {
|
2014-12-05 10:42:15 +00:00
|
|
|
qCCritical(KWIN_CORE) << "The used windowing system requires compositing";
|
|
|
|
qCCritical(KWIN_CORE) << "We are going to quit KWin now as it is broken";
|
2013-06-25 08:39:13 +00:00
|
|
|
qApp->quit();
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2017-11-05 10:07:04 +00:00
|
|
|
|
2022-10-23 13:08:14 +00:00
|
|
|
m_selectedCompositor = m_backend->compositingType();
|
2019-02-16 19:50:46 +00:00
|
|
|
|
2021-11-10 10:34:18 +00:00
|
|
|
if (!Workspace::self() && m_backend && m_backend->compositingType() == QPainterCompositing) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Force Software QtQuick on first startup with QPainter.
|
2022-03-21 16:22:55 +00:00
|
|
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
|
2017-11-05 10:07:04 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT sceneCreated();
|
2015-02-23 14:57:00 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
return true;
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::startupWithWorkspace()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_scene);
|
2021-11-09 10:36:24 +00:00
|
|
|
m_scene->initialize();
|
2022-12-19 08:45:29 +00:00
|
|
|
m_cursorScene->initialize();
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2022-07-11 10:41:15 +00:00
|
|
|
const QList<Output *> outputs = workspace()->outputs();
|
2022-02-04 18:38:37 +00:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
auto workspaceLayer = new RenderLayer(outputs.constFirst()->renderLoop());
|
2023-02-09 17:34:43 +00:00
|
|
|
workspaceLayer->setDelegate(std::make_unique<SceneDelegate>(m_scene.get(), nullptr));
|
2022-02-04 18:38:37 +00:00
|
|
|
workspaceLayer->setGeometry(workspace()->geometry());
|
2022-03-04 21:18:51 +00:00
|
|
|
connect(workspace(), &Workspace::geometryChanged, workspaceLayer, [workspaceLayer]() {
|
2022-02-04 18:38:37 +00:00
|
|
|
workspaceLayer->setGeometry(workspace()->geometry());
|
|
|
|
});
|
|
|
|
addSuperLayer(workspaceLayer);
|
|
|
|
} else {
|
2022-04-14 12:33:28 +00:00
|
|
|
for (Output *output : outputs) {
|
2022-02-04 18:38:37 +00:00
|
|
|
addOutput(output);
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
2022-07-11 10:41:15 +00:00
|
|
|
connect(workspace(), &Workspace::outputAdded, this, &Compositor::addOutput);
|
|
|
|
connect(workspace(), &Workspace::outputRemoved, this, &Compositor::removeOutput);
|
2020-01-09 17:18:22 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2021-06-10 05:54:39 +00:00
|
|
|
m_state = State::On;
|
|
|
|
|
2023-03-13 11:54:38 +00:00
|
|
|
const auto windows = workspace()->windows();
|
2023-03-02 15:02:09 +00:00
|
|
|
for (Window *window : windows) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->setupCompositing();
|
2012-12-27 20:57:40 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2021-12-14 10:20:11 +00:00
|
|
|
// Sets also the 'effects' pointer.
|
2022-11-05 10:14:59 +00:00
|
|
|
kwinApp()->createEffectsHandler(this, m_scene.get());
|
2021-12-14 10:20:11 +00:00
|
|
|
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT compositingToggled(true);
|
2012-09-01 07:10:56 +00:00
|
|
|
|
2012-10-14 10:18:35 +00:00
|
|
|
if (m_releaseSelectionTimer.isActive()) {
|
|
|
|
m_releaseSelectionTimer.stop();
|
|
|
|
}
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
Output *Compositor::findOutput(RenderLoop *loop) const
|
2022-02-05 13:20:17 +00:00
|
|
|
{
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2022-04-14 12:33:28 +00:00
|
|
|
for (Output *output : outputs) {
|
2022-02-05 13:20:17 +00:00
|
|
|
if (output->renderLoop() == loop) {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void Compositor::addOutput(Output *output)
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
{
|
2022-02-05 09:47:00 +00:00
|
|
|
Q_ASSERT(kwinApp()->operationMode() != Application::OperationModeX11);
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
auto workspaceLayer = new RenderLayer(output->renderLoop());
|
2022-12-20 01:23:21 +00:00
|
|
|
workspaceLayer->setDelegate(std::make_unique<SceneDelegate>(m_scene.get(), output));
|
2022-04-05 17:48:05 +00:00
|
|
|
workspaceLayer->setGeometry(output->rect());
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::geometryChanged, workspaceLayer, [output, workspaceLayer]() {
|
2022-04-05 17:48:05 +00:00
|
|
|
workspaceLayer->setGeometry(output->rect());
|
2022-02-04 18:38:37 +00:00
|
|
|
});
|
2022-02-05 09:47:00 +00:00
|
|
|
|
|
|
|
auto cursorLayer = new RenderLayer(output->renderLoop());
|
|
|
|
cursorLayer->setVisible(false);
|
2022-04-12 13:14:23 +00:00
|
|
|
if (m_backend->compositingType() == OpenGLCompositing) {
|
2023-02-09 17:34:43 +00:00
|
|
|
cursorLayer->setDelegate(std::make_unique<CursorDelegateOpenGL>(output));
|
2022-04-12 13:14:23 +00:00
|
|
|
} else {
|
2023-02-09 17:34:43 +00:00
|
|
|
cursorLayer->setDelegate(std::make_unique<CursorDelegateQPainter>(output));
|
2022-04-12 13:14:23 +00:00
|
|
|
}
|
2022-02-05 09:47:00 +00:00
|
|
|
cursorLayer->setParent(workspaceLayer);
|
|
|
|
cursorLayer->setSuperlayer(workspaceLayer);
|
|
|
|
|
2023-09-18 14:45:44 +00:00
|
|
|
static bool valid;
|
|
|
|
static const bool forceSoftwareCursor = qEnvironmentVariableIntValue("KWIN_FORCE_SW_CURSOR", &valid) == 1 && valid;
|
2023-08-24 21:11:58 +00:00
|
|
|
|
2023-09-18 14:45:44 +00:00
|
|
|
auto updateCursorLayer = [this, output, cursorLayer]() {
|
2022-02-05 09:47:00 +00:00
|
|
|
const Cursor *cursor = Cursors::self()->currentCursor();
|
2023-09-18 14:45:44 +00:00
|
|
|
const QRectF outputLocalRect = output->mapFromGlobal(cursor->geometry());
|
2023-08-24 21:11:58 +00:00
|
|
|
const auto outputLayer = m_backend->cursorLayer(output);
|
|
|
|
if (!cursor->isOnOutput(output)) {
|
|
|
|
if (outputLayer && outputLayer->isEnabled()) {
|
|
|
|
outputLayer->setEnabled(false);
|
|
|
|
output->updateCursorLayer();
|
|
|
|
}
|
2023-09-18 13:45:03 +00:00
|
|
|
cursorLayer->setVisible(false);
|
2023-09-18 14:45:44 +00:00
|
|
|
return true;
|
2023-08-24 21:11:58 +00:00
|
|
|
}
|
|
|
|
const auto renderHardwareCursor = [&]() {
|
|
|
|
if (!outputLayer || forceSoftwareCursor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QMatrix4x4 monitorMatrix = Output::logicalToNativeMatrix(output->rect(), output->scale(), output->transform());
|
2023-09-18 14:45:44 +00:00
|
|
|
QRectF nativeCursorRect = monitorMatrix.mapRect(outputLocalRect);
|
2023-08-24 21:11:58 +00:00
|
|
|
QSize bufferSize(std::ceil(nativeCursorRect.width()), std::ceil(nativeCursorRect.height()));
|
|
|
|
if (const auto fixedSize = outputLayer->fixedSize()) {
|
|
|
|
if (fixedSize->width() < bufferSize.width() || fixedSize->height() < bufferSize.height()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bufferSize = *fixedSize;
|
2023-09-18 14:45:44 +00:00
|
|
|
nativeCursorRect = monitorMatrix.mapRect(QRectF(outputLocalRect.topLeft(), QSizeF(bufferSize) / output->scale()));
|
2023-08-24 21:11:58 +00:00
|
|
|
}
|
|
|
|
outputLayer->setPosition(nativeCursorRect.topLeft());
|
2023-09-18 14:45:44 +00:00
|
|
|
outputLayer->setHotspot(Output::logicalToNativeMatrix(QRectF(QPointF(), QSizeF(bufferSize) / output->scale()), output->scale(), output->transform()).map(cursor->hotspot()));
|
2023-08-24 21:11:58 +00:00
|
|
|
outputLayer->setSize(bufferSize);
|
|
|
|
if (auto beginInfo = outputLayer->beginFrame()) {
|
|
|
|
const RenderTarget &renderTarget = beginInfo->renderTarget;
|
|
|
|
|
|
|
|
RenderLayer renderLayer(output->renderLoop());
|
|
|
|
renderLayer.setDelegate(std::make_unique<SceneDelegate>(m_cursorScene.get(), output));
|
|
|
|
renderLayer.setOutputLayer(outputLayer);
|
|
|
|
|
|
|
|
renderLayer.delegate()->prePaint();
|
|
|
|
renderLayer.delegate()->paint(renderTarget, infiniteRegion());
|
|
|
|
renderLayer.delegate()->postPaint();
|
|
|
|
|
|
|
|
if (!outputLayer->endFrame(infiniteRegion(), infiniteRegion())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outputLayer->setEnabled(true);
|
|
|
|
return output->updateCursorLayer();
|
|
|
|
};
|
|
|
|
if (renderHardwareCursor()) {
|
|
|
|
cursorLayer->setVisible(false);
|
2023-09-18 14:45:44 +00:00
|
|
|
return true;
|
2022-12-02 21:17:40 +00:00
|
|
|
} else {
|
2023-08-24 21:11:58 +00:00
|
|
|
if (outputLayer && outputLayer->isEnabled()) {
|
|
|
|
outputLayer->setEnabled(false);
|
|
|
|
output->updateCursorLayer();
|
|
|
|
}
|
|
|
|
cursorLayer->setVisible(cursor->isOnOutput(output));
|
2023-09-18 14:45:44 +00:00
|
|
|
cursorLayer->setGeometry(outputLocalRect);
|
2023-08-24 21:11:58 +00:00
|
|
|
cursorLayer->addRepaintFull();
|
2023-09-18 14:45:44 +00:00
|
|
|
return false;
|
2022-12-02 21:17:40 +00:00
|
|
|
}
|
|
|
|
};
|
2023-09-18 14:45:44 +00:00
|
|
|
auto moveCursorLayer = [this, output, cursorLayer, updateCursorLayer]() {
|
2022-12-02 21:17:40 +00:00
|
|
|
const Cursor *cursor = Cursors::self()->currentCursor();
|
2023-09-18 14:45:44 +00:00
|
|
|
const QRectF outputLocalRect = output->mapFromGlobal(cursor->geometry());
|
2023-08-24 21:11:58 +00:00
|
|
|
const auto outputLayer = m_backend->cursorLayer(output);
|
|
|
|
bool hardwareCursor = false;
|
2023-09-18 14:45:44 +00:00
|
|
|
if (outputLayer) {
|
|
|
|
if (outputLayer->isEnabled()) {
|
|
|
|
const QMatrix4x4 monitorMatrix = Output::logicalToNativeMatrix(output->rect(), output->scale(), output->transform());
|
|
|
|
const QRectF nativeCursorRect = monitorMatrix.mapRect(QRectF(outputLocalRect.topLeft(), outputLayer->size() / output->scale()));
|
|
|
|
outputLayer->setPosition(nativeCursorRect.topLeft());
|
|
|
|
hardwareCursor = output->updateCursorLayer();
|
|
|
|
} else if (!cursorLayer->isVisible() && !forceSoftwareCursor) {
|
|
|
|
// this is for the case that the cursor wasn't visible because it was on a different output before
|
|
|
|
hardwareCursor = updateCursorLayer();
|
|
|
|
}
|
2023-08-24 21:11:58 +00:00
|
|
|
}
|
|
|
|
cursorLayer->setVisible(cursor->isOnOutput(output) && !hardwareCursor);
|
2023-09-18 14:45:44 +00:00
|
|
|
cursorLayer->setGeometry(outputLocalRect);
|
2022-02-05 09:47:00 +00:00
|
|
|
cursorLayer->addRepaintFull();
|
|
|
|
};
|
|
|
|
updateCursorLayer();
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::geometryChanged, cursorLayer, updateCursorLayer);
|
2022-02-05 09:47:00 +00:00
|
|
|
connect(Cursors::self(), &Cursors::currentCursorChanged, cursorLayer, updateCursorLayer);
|
|
|
|
connect(Cursors::self(), &Cursors::hiddenChanged, cursorLayer, updateCursorLayer);
|
2022-12-02 21:17:40 +00:00
|
|
|
connect(Cursors::self(), &Cursors::positionChanged, cursorLayer, moveCursorLayer);
|
2022-02-05 09:47:00 +00:00
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
addSuperLayer(workspaceLayer);
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
void Compositor::removeOutput(Output *output)
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
removeSuperLayer(m_superlayers[output->renderLoop()]);
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
void Compositor::addSuperLayer(RenderLayer *layer)
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
m_superlayers.insert(layer->loop(), layer);
|
|
|
|
connect(layer->loop(), &RenderLoop::frameRequested, this, &Compositor::handleFrameRequested);
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
void Compositor::removeSuperLayer(RenderLayer *layer)
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
m_superlayers.remove(layer->loop());
|
|
|
|
disconnect(layer->loop(), &RenderLoop::frameRequested, this, &Compositor::handleFrameRequested);
|
|
|
|
delete layer;
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
void Compositor::stop()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
if (m_state == State::Off || m_state == State::Stopping) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2019-07-04 01:19:18 +00:00
|
|
|
}
|
|
|
|
m_state = State::Stopping;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT aboutToToggleCompositing();
|
2019-02-20 13:09:37 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
m_releaseSelectionTimer.start();
|
|
|
|
|
2018-12-01 16:23:37 +00:00
|
|
|
// Some effects might need access to effect windows when they are about to
|
|
|
|
// be destroyed, for example to unreference deleted windows, so we have to
|
|
|
|
// make sure that effect windows outlive effects.
|
|
|
|
delete effects;
|
|
|
|
effects = nullptr;
|
|
|
|
|
2015-05-27 07:12:07 +00:00
|
|
|
if (Workspace::self()) {
|
2023-03-13 11:54:38 +00:00
|
|
|
const auto windows = workspace()->windows();
|
2023-03-02 15:02:09 +00:00
|
|
|
for (Window *window : windows) {
|
2022-04-23 08:33:23 +00:00
|
|
|
window->finishCompositing();
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
2023-09-19 12:30:45 +00:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
xcb_composite_unredirect_subwindows(kwinApp()->x11Connection(),
|
|
|
|
kwinApp()->x11RootWindow(),
|
2019-12-02 17:36:13 +00:00
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
|
|
|
}
|
2022-07-11 10:41:15 +00:00
|
|
|
|
|
|
|
disconnect(workspace(), &Workspace::outputAdded, this, &Compositor::addOutput);
|
|
|
|
disconnect(workspace(), &Workspace::outputRemoved, this, &Compositor::removeOutput);
|
2015-05-27 07:12:07 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2023-03-21 17:27:43 +00:00
|
|
|
if (m_backend->compositingType() == OpenGLCompositing) {
|
|
|
|
// some layers need a context current for destruction
|
|
|
|
static_cast<OpenGLBackend *>(m_backend.get())->makeCurrent();
|
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
const auto superlayers = m_superlayers;
|
|
|
|
for (auto it = superlayers.begin(); it != superlayers.end(); ++it) {
|
|
|
|
removeSuperLayer(*it);
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:33:32 +00:00
|
|
|
m_scene.reset();
|
2022-12-19 08:45:29 +00:00
|
|
|
m_cursorScene.reset();
|
2022-06-22 10:33:32 +00:00
|
|
|
m_backend.reset();
|
2021-11-08 10:08:06 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
m_state = State::Off;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT compositingToggled(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
void Compositor::destroyCompositorSelection()
|
|
|
|
{
|
2022-07-05 11:43:25 +00:00
|
|
|
m_selectionOwner.reset();
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 10:18:35 +00:00
|
|
|
void Compositor::releaseCompositorSelection()
|
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
switch (m_state) {
|
|
|
|
case State::On:
|
|
|
|
// We are compositing at the moment. Don't release.
|
|
|
|
break;
|
|
|
|
case State::Off:
|
|
|
|
if (m_selectionOwner) {
|
|
|
|
qCDebug(KWIN_CORE) << "Releasing compositor selection";
|
|
|
|
m_selectionOwner->setOwning(false);
|
|
|
|
m_selectionOwner->release();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case State::Starting:
|
|
|
|
case State::Stopping:
|
|
|
|
// Still starting or shutting down the compositor. Starting might fail
|
|
|
|
// or after stopping a restart might follow. So test again later on.
|
2012-10-14 10:18:35 +00:00
|
|
|
m_releaseSelectionTimer.start();
|
2019-07-04 01:19:18 +00:00
|
|
|
break;
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2012-10-14 10:18:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 22:00:23 +00:00
|
|
|
void Compositor::keepSupportProperty(xcb_atom_t atom)
|
|
|
|
{
|
|
|
|
m_unusedSupportProperties.removeAll(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::removeSupportProperty(xcb_atom_t atom)
|
|
|
|
{
|
|
|
|
m_unusedSupportProperties << atom;
|
|
|
|
m_unusedSupportPropertyTimer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::deleteUnusedSupportProperties()
|
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
if (m_state == State::Starting || m_state == State::Stopping) {
|
|
|
|
// Currently still maybe restarting the compositor.
|
2013-04-26 22:00:23 +00:00
|
|
|
m_unusedSupportPropertyTimer.start();
|
|
|
|
return;
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
if (auto *con = kwinApp()->x11Connection()) {
|
2022-10-31 19:02:23 +00:00
|
|
|
for (const xcb_atom_t &atom : std::as_const(m_unusedSupportProperties)) {
|
2015-11-10 12:54:26 +00:00
|
|
|
// remove property from root window
|
2019-08-08 12:34:22 +00:00
|
|
|
xcb_delete_property(con, kwinApp()->x11RootWindow(), atom);
|
2015-11-10 12:54:26 +00:00
|
|
|
}
|
2019-09-05 07:55:31 +00:00
|
|
|
m_unusedSupportProperties.clear();
|
2013-04-26 22:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
void Compositor::configChanged()
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
2019-08-07 17:33:20 +00:00
|
|
|
reinitialize();
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 20:30:27 +00:00
|
|
|
void Compositor::reinitialize()
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
|
|
|
// Restart compositing
|
2019-07-04 01:19:18 +00:00
|
|
|
stop();
|
|
|
|
start();
|
2011-08-21 19:50:23 +00:00
|
|
|
}
|
|
|
|
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
void Compositor::handleFrameRequested(RenderLoop *renderLoop)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2021-04-29 06:07:45 +00:00
|
|
|
composite(renderLoop);
|
2021-02-03 14:19:55 +00:00
|
|
|
}
|
2015-08-31 11:54:50 +00:00
|
|
|
|
2023-02-14 15:05:00 +00:00
|
|
|
uint Compositor::outputFormat(Output *output)
|
|
|
|
{
|
|
|
|
OutputLayer *primaryLayer = m_backend->primaryLayer(output);
|
|
|
|
return primaryLayer->format();
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:14:25 +00:00
|
|
|
void Compositor::composite(RenderLoop *renderLoop)
|
|
|
|
{
|
2021-12-31 11:51:42 +00:00
|
|
|
if (m_backend->checkGraphicsReset()) {
|
|
|
|
qCDebug(KWIN_CORE) << "Graphics reset occurred";
|
2022-02-25 09:38:26 +00:00
|
|
|
#if KWIN_BUILD_NOTIFICATIONS
|
2021-12-31 11:51:42 +00:00
|
|
|
KNotification::event(QStringLiteral("graphicsreset"), i18n("Desktop effects were restarted due to a graphics reset"));
|
2022-02-25 09:38:26 +00:00
|
|
|
#endif
|
2021-12-31 11:51:42 +00:00
|
|
|
reinitialize();
|
|
|
|
return;
|
|
|
|
}
|
2021-07-28 15:14:25 +00:00
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
Output *output = findOutput(renderLoop);
|
2022-12-05 12:29:03 +00:00
|
|
|
OutputLayer *primaryLayer = m_backend->primaryLayer(output);
|
2022-02-05 13:20:17 +00:00
|
|
|
fTraceDuration("Paint (", output->name(), ")");
|
2021-07-28 15:14:25 +00:00
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
RenderLayer *superLayer = m_superlayers[renderLoop];
|
2022-12-05 12:29:03 +00:00
|
|
|
superLayer->setOutputLayer(primaryLayer);
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
renderLoop->prepareNewFrame();
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
if (superLayer->needsRepaint()) {
|
|
|
|
renderLoop->beginPaint();
|
|
|
|
prePaintPass(superLayer);
|
|
|
|
|
|
|
|
SurfaceItem *scanoutCandidate = superLayer->delegate()->scanoutCandidate();
|
|
|
|
renderLoop->setFullscreenSurface(scanoutCandidate);
|
|
|
|
output->setContentType(scanoutCandidate ? scanoutCandidate->contentType() : ContentType::None);
|
|
|
|
|
|
|
|
bool directScanout = false;
|
|
|
|
if (scanoutCandidate) {
|
|
|
|
const auto sublayers = superLayer->sublayers();
|
|
|
|
const bool scanoutPossible = std::none_of(sublayers.begin(), sublayers.end(), [](RenderLayer *sublayer) {
|
|
|
|
return sublayer->isVisible();
|
|
|
|
});
|
|
|
|
if (scanoutPossible && !output->directScanoutInhibited()) {
|
|
|
|
directScanout = primaryLayer->scanout(scanoutCandidate);
|
|
|
|
}
|
2022-01-13 15:11:04 +00:00
|
|
|
}
|
2022-02-04 18:38:37 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
if (!directScanout) {
|
|
|
|
QRegion surfaceDamage = primaryLayer->repaints();
|
|
|
|
primaryLayer->resetRepaints();
|
|
|
|
preparePaintPass(superLayer, &surfaceDamage);
|
2022-02-04 18:38:37 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
if (auto beginInfo = primaryLayer->beginFrame()) {
|
|
|
|
auto &[renderTarget, repaint] = beginInfo.value();
|
2022-04-12 08:16:27 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
const QRegion bufferDamage = surfaceDamage.united(repaint).intersected(superLayer->rect().toAlignedRect());
|
2022-02-16 17:13:57 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
paintPass(superLayer, renderTarget, bufferDamage);
|
|
|
|
primaryLayer->endFrame(bufferDamage, surfaceDamage);
|
|
|
|
}
|
2022-08-04 16:14:37 +00:00
|
|
|
}
|
2022-02-04 17:38:58 +00:00
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
postPaintPass(superLayer);
|
|
|
|
}
|
2022-02-05 09:47:00 +00:00
|
|
|
|
2022-04-06 12:09:26 +00:00
|
|
|
m_backend->present(output);
|
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
framePass(superLayer);
|
|
|
|
|
2022-02-05 09:47:00 +00:00
|
|
|
// TODO: Put it inside the cursor layer once the cursor layer can be backed by a real output layer.
|
|
|
|
if (waylandServer()) {
|
|
|
|
const std::chrono::milliseconds frameTime =
|
2022-03-23 10:13:38 +00:00
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(output->renderLoop()->lastPresentationTimestamp());
|
2022-02-05 09:47:00 +00:00
|
|
|
|
|
|
|
if (!Cursors::self()->isCursorHidden()) {
|
|
|
|
Cursor *cursor = Cursors::self()->currentCursor();
|
|
|
|
if (cursor->geometry().intersects(output->geometry())) {
|
|
|
|
cursor->markAsRendered(frameTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-04 18:38:37 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 12:44:07 +00:00
|
|
|
void Compositor::framePass(RenderLayer *layer)
|
|
|
|
{
|
|
|
|
layer->delegate()->frame();
|
|
|
|
const auto sublayers = layer->sublayers();
|
|
|
|
for (RenderLayer *sublayer : sublayers) {
|
|
|
|
framePass(sublayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
void Compositor::prePaintPass(RenderLayer *layer)
|
|
|
|
{
|
|
|
|
layer->delegate()->prePaint();
|
|
|
|
const auto sublayers = layer->sublayers();
|
|
|
|
for (RenderLayer *sublayer : sublayers) {
|
|
|
|
prePaintPass(sublayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::postPaintPass(RenderLayer *layer)
|
|
|
|
{
|
|
|
|
layer->delegate()->postPaint();
|
|
|
|
const auto sublayers = layer->sublayers();
|
|
|
|
for (RenderLayer *sublayer : sublayers) {
|
|
|
|
postPaintPass(sublayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::preparePaintPass(RenderLayer *layer, QRegion *repaint)
|
|
|
|
{
|
|
|
|
// TODO: Cull opaque region.
|
2022-02-16 17:13:57 +00:00
|
|
|
*repaint += layer->mapToGlobal(layer->repaints() + layer->delegate()->repaints());
|
2022-02-04 18:38:37 +00:00
|
|
|
layer->resetRepaints();
|
|
|
|
const auto sublayers = layer->sublayers();
|
|
|
|
for (RenderLayer *sublayer : sublayers) {
|
|
|
|
if (sublayer->isVisible()) {
|
|
|
|
preparePaintPass(sublayer, repaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 17:34:43 +00:00
|
|
|
void Compositor::paintPass(RenderLayer *layer, const RenderTarget &renderTarget, const QRegion ®ion)
|
2022-02-04 18:38:37 +00:00
|
|
|
{
|
2023-02-09 17:34:43 +00:00
|
|
|
layer->delegate()->paint(renderTarget, region);
|
2022-02-04 18:38:37 +00:00
|
|
|
|
|
|
|
const auto sublayers = layer->sublayers();
|
|
|
|
for (RenderLayer *sublayer : sublayers) {
|
|
|
|
if (sublayer->isVisible()) {
|
2023-02-09 17:34:43 +00:00
|
|
|
paintPass(sublayer, renderTarget, region);
|
2022-02-04 18:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-30 15:28:47 +00:00
|
|
|
|
2012-08-17 06:18:36 +00:00
|
|
|
bool Compositor::isActive()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
return m_state == State::On;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-08-15 11:09:07 +00:00
|
|
|
|
2022-11-02 18:47:01 +00:00
|
|
|
bool Compositor::compositingPossible() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Compositor::compositingNotPossibleReason() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compositor::openGLCompositingIsBroken() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositor::createOpenGLSafePoint(OpenGLSafePoint safePoint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-31 12:44:50 +00:00
|
|
|
} // namespace KWin
|
2019-06-22 10:40:12 +00:00
|
|
|
|
|
|
|
// included for CompositorSelectionOwner
|
2023-08-31 12:23:42 +00:00
|
|
|
#include "compositor.moc"
|
2023-07-05 06:30:14 +00:00
|
|
|
|
2023-08-31 12:23:42 +00:00
|
|
|
#include "moc_compositor.cpp"
|