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
|
|
|
|
*/
|
2012-08-30 06:20:26 +00:00
|
|
|
#include "composite.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
#include <config-kwin.h>
|
|
|
|
|
2022-04-12 13:14:23 +00:00
|
|
|
#include "cursordelegate_opengl.h"
|
|
|
|
#include "cursordelegate_qpainter.h"
|
2014-06-02 06:51:28 +00:00
|
|
|
#include "dbusinterface.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "decorations/decoratedclient.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "deleted.h"
|
|
|
|
#include "effects.h"
|
2020-09-07 08:11:47 +00:00
|
|
|
#include "ftrace.h"
|
2019-08-26 07:44:04 +00:00
|
|
|
#include "internal_client.h"
|
2021-11-08 10:08:06 +00:00
|
|
|
#include "openglbackend.h"
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2022-02-04 18:38:37 +00:00
|
|
|
#include "outputlayer.h"
|
2011-07-06 09:58:23 +00:00
|
|
|
#include "overlaywindow.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "platform.h"
|
2021-11-08 10:08:06 +00:00
|
|
|
#include "qpainterbackend.h"
|
2022-02-04 18:38:37 +00:00
|
|
|
#include "renderlayer.h"
|
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
|
|
|
#include "renderloop.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "scene.h"
|
2021-11-08 10:08:06 +00:00
|
|
|
#include "scenes/opengl/scene_opengl.h"
|
|
|
|
#include "scenes/qpainter/scene_qpainter.h"
|
2014-11-25 07:40:23 +00:00
|
|
|
#include "screens.h"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
#include "surfaceitem_x11.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "unmanaged.h"
|
|
|
|
#include "useractions.h"
|
2022-01-18 08:35:52 +00:00
|
|
|
#include "utils/common.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "utils/xcbutils.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/surface_interface.h"
|
2015-03-23 13:29:07 +00:00
|
|
|
#include "wayland_server.h"
|
2019-06-22 10:00:56 +00:00
|
|
|
#include "workspace.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "x11client.h"
|
2021-06-11 11:11:57 +00:00
|
|
|
#include "x11syncmanager.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2021-11-08 19:48:24 +00:00
|
|
|
#include <kwinglplatform.h>
|
2017-09-08 20:30:18 +00:00
|
|
|
#include <kwingltexture.h>
|
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#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 <QDateTime>
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QQuickWindow>
|
|
|
|
#include <QTextStream>
|
|
|
|
#include <QTimerEvent>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QtConcurrentRun>
|
2019-06-22 10:00:56 +00:00
|
|
|
|
2012-12-11 20:21:35 +00:00
|
|
|
#include <xcb/composite.h>
|
2012-03-28 18:29:33 +00:00
|
|
|
#include <xcb/damage.h>
|
|
|
|
|
2019-06-22 10:00:56 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::X11Compositor::SuspendReason)
|
2013-01-09 15:03:54 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// See main.cpp:
|
|
|
|
extern int screen_number;
|
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
extern bool is_multihead;
|
2010-11-27 15:27:54 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
Compositor *Compositor::s_compositor = nullptr;
|
|
|
|
Compositor *Compositor::self()
|
|
|
|
{
|
|
|
|
return s_compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaylandCompositor *WaylandCompositor::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_compositor);
|
|
|
|
auto *compositor = new WaylandCompositor(parent);
|
|
|
|
s_compositor = compositor;
|
|
|
|
return compositor;
|
|
|
|
}
|
|
|
|
X11Compositor *X11Compositor::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_compositor);
|
|
|
|
auto *compositor = new X11Compositor(parent);
|
|
|
|
s_compositor = compositor;
|
|
|
|
return 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.
|
|
|
|
if (kwinApp()->platform()->isReady()) {
|
2019-08-07 17:33:20 +00:00
|
|
|
QTimer::singleShot(0, this, &Compositor::start);
|
2014-08-13 10:54:02 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
connect(
|
|
|
|
kwinApp()->platform(), &Platform::readyChanged, this, [this](bool ready) {
|
2016-04-15 09:19:12 +00:00
|
|
|
if (ready) {
|
2019-07-04 01:19:18 +00:00
|
|
|
start();
|
2016-04-15 09:19:12 +00:00
|
|
|
} else {
|
2019-07-04 01:19:18 +00:00
|
|
|
stop();
|
2016-04-15 09:19:12 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
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:
|
|
|
|
if (kwinApp()->platform()->openGLCompositingIsBroken()) {
|
|
|
|
qCWarning(KWIN_CORE) << "KWin has detected that your OpenGL library is unsafe to use";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreInit);
|
2022-01-26 22:19:31 +00:00
|
|
|
auto safePointScope = qScopeGuard([]() {
|
2021-11-08 10:08:06 +00:00
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostInit);
|
|
|
|
});
|
|
|
|
|
|
|
|
QScopedPointer<OpenGLBackend> backend(kwinApp()->platform()->createOpenGLBackend());
|
|
|
|
if (!backend) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!backend->isFailed()) {
|
|
|
|
backend->init();
|
|
|
|
}
|
|
|
|
if (backend->isFailed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer<Scene> scene(SceneOpenGL::createScene(backend.data(), this));
|
|
|
|
if (!scene || scene->initFailed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_backend = backend.take();
|
|
|
|
m_scene = scene.take();
|
|
|
|
|
2021-11-08 19:48:24 +00:00
|
|
|
// set strict binding
|
|
|
|
if (options->isGlStrictBindingFollowsDriver()) {
|
|
|
|
options->setGlStrictBinding(!GLPlatform::instance()->supports(LooseBinding));
|
|
|
|
}
|
|
|
|
|
2021-11-08 10:08:06 +00:00
|
|
|
qCDebug(KWIN_CORE) << "OpenGL compositing has been successfully initialized";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compositor::attemptQPainterCompositing()
|
|
|
|
{
|
|
|
|
QScopedPointer<QPainterBackend> backend(kwinApp()->platform()->createQPainterBackend());
|
|
|
|
if (!backend || backend->isFailed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QScopedPointer<Scene> scene(SceneQPainter::createScene(backend.data(), this));
|
|
|
|
if (!scene || scene->initFailed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_backend = backend.take();
|
|
|
|
m_scene = scene.take();
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-07-02 19:09:23 +00:00
|
|
|
options->reloadCompositingSettings(true);
|
2007-07-19 16:20:05 +00:00
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
initializeX11();
|
2014-04-14 07:19:43 +00:00
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
// There might still be a deleted around, needs to be cleared before
|
|
|
|
// creating the scene (BUG 333275).
|
2015-02-23 14:57:00 +00:00
|
|
|
if (Workspace::self()) {
|
|
|
|
while (!Workspace::self()->deletedList().isEmpty()) {
|
|
|
|
Workspace::self()->deletedList().first()->discard();
|
|
|
|
}
|
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
|
|
|
|
2017-10-18 19:56:13 +00:00
|
|
|
auto supportedCompositors = kwinApp()->platform()->supportedCompositors();
|
2019-08-08 12:34:22 +00:00
|
|
|
const auto userConfigIt = std::find(supportedCompositors.begin(), supportedCompositors.end(),
|
|
|
|
options->compositingMode());
|
|
|
|
|
2017-10-18 19:56:13 +00:00
|
|
|
if (userConfigIt != supportedCompositors.end()) {
|
|
|
|
supportedCompositors.erase(userConfigIt);
|
|
|
|
supportedCompositors.prepend(options->compositingMode());
|
|
|
|
} else {
|
2019-08-08 12:34:22 +00:00
|
|
|
qCWarning(KWIN_CORE)
|
2022-03-23 10:13:38 +00:00
|
|
|
<< "Configured compositor not supported by Platform. Falling back to defaults";
|
2017-10-18 19:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto type : qAsConst(supportedCompositors)) {
|
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;
|
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;
|
|
|
|
|
2021-10-18 10:00:32 +00:00
|
|
|
if (auto *con = kwinApp()->x11Connection()) {
|
|
|
|
xcb_composite_unredirect_subwindows(con, kwinApp()->x11RootWindow(),
|
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
if (m_selectionOwner) {
|
|
|
|
m_selectionOwner->setOwning(false);
|
|
|
|
m_selectionOwner->release();
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2017-10-18 19:56:13 +00:00
|
|
|
if (!supportedCompositors.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
|
|
|
|
2021-11-10 10:34:18 +00:00
|
|
|
kwinApp()->platform()->setSelectedCompositor(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
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
2017-11-05 10:07:04 +00:00
|
|
|
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
|
2022-03-21 16:22:55 +00:00
|
|
|
#else
|
|
|
|
QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
void Compositor::initializeX11()
|
2015-02-23 14:57:00 +00:00
|
|
|
{
|
2020-07-20 08:07:08 +00:00
|
|
|
xcb_connection_t *connection = kwinApp()->x11Connection();
|
|
|
|
if (!connection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-22 10:40:12 +00:00
|
|
|
if (!m_selectionOwner) {
|
2022-03-23 10:13:38 +00:00
|
|
|
char selection_name[100];
|
2015-02-23 14:57:00 +00:00
|
|
|
sprintf(selection_name, "_NET_WM_CM_S%d", Application::x11ScreenNumber());
|
2019-06-22 10:40:12 +00:00
|
|
|
m_selectionOwner = new CompositorSelectionOwner(selection_name);
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(m_selectionOwner, &CompositorSelectionOwner::lostOwnership,
|
|
|
|
this, &Compositor::stop);
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
if (!m_selectionOwner->owning()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Force claim ownership.
|
|
|
|
m_selectionOwner->claim(true);
|
2019-06-22 10:40:12 +00:00
|
|
|
m_selectionOwner->setOwning(true);
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
2020-07-20 08:07:08 +00:00
|
|
|
|
|
|
|
xcb_composite_redirect_subwindows(connection, kwinApp()->x11RootWindow(),
|
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
2015-02-23 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 08:07:08 +00:00
|
|
|
void Compositor::cleanupX11()
|
2017-08-24 08:43:38 +00:00
|
|
|
{
|
2020-07-20 08:07:08 +00:00
|
|
|
delete m_selectionOwner;
|
|
|
|
m_selectionOwner = nullptr;
|
2017-08-24 08:43:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 14:57:00 +00:00
|
|
|
void Compositor::startupWithWorkspace()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(kwinApp(), &Application::x11ConnectionChanged,
|
2020-07-20 08:07:08 +00:00
|
|
|
this, &Compositor::initializeX11, Qt::UniqueConnection);
|
|
|
|
connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed,
|
|
|
|
this, &Compositor::cleanupX11, Qt::UniqueConnection);
|
|
|
|
initializeX11();
|
|
|
|
|
2017-06-21 19:10:12 +00:00
|
|
|
Workspace::self()->markXStackingOrderAsDirty();
|
2015-02-23 14:57:00 +00:00
|
|
|
Q_ASSERT(m_scene);
|
2021-11-09 10:36:24 +00:00
|
|
|
m_scene->initialize();
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
const QVector<Output *> outputs = kwinApp()->platform()->enabledOutputs();
|
2022-02-04 18:38:37 +00:00
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
auto workspaceLayer = new RenderLayer(outputs.constFirst()->renderLoop());
|
|
|
|
workspaceLayer->setDelegate(new SceneDelegate(m_scene));
|
|
|
|
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-02-04 18:38:37 +00:00
|
|
|
connect(kwinApp()->platform(), &Platform::outputEnabled, this, &Compositor::addOutput);
|
|
|
|
connect(kwinApp()->platform(), &Platform::outputDisabled, 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;
|
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
for (X11Client *c : Workspace::self()->clientList()) {
|
2012-03-29 20:11:28 +00:00
|
|
|
c->setupCompositing();
|
2012-12-27 20:57:40 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
|
2012-03-29 20:11:28 +00:00
|
|
|
c->setupCompositing();
|
2012-12-27 20:57:40 +00:00
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
for (InternalClient *client : workspace()->internalClients()) {
|
|
|
|
client->setupCompositing();
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
|
|
|
if (auto *server = waylandServer()) {
|
|
|
|
const auto clients = server->clients();
|
2020-03-04 07:55:26 +00:00
|
|
|
for (AbstractClient *c : clients) {
|
2016-07-15 14:06:09 +00:00
|
|
|
c->setupCompositing();
|
|
|
|
}
|
|
|
|
}
|
2012-04-13 09:36:48 +00:00
|
|
|
|
2021-12-14 10:20:11 +00:00
|
|
|
// Sets also the 'effects' pointer.
|
|
|
|
kwinApp()->platform()->createEffectsHandler(this, m_scene);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
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());
|
|
|
|
workspaceLayer->setDelegate(new SceneDelegate(m_scene, 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) {
|
|
|
|
cursorLayer->setDelegate(new CursorDelegateOpenGL());
|
|
|
|
} else {
|
|
|
|
cursorLayer->setDelegate(new CursorDelegateQPainter());
|
|
|
|
}
|
2022-02-05 09:47:00 +00:00
|
|
|
cursorLayer->setParent(workspaceLayer);
|
|
|
|
cursorLayer->setSuperlayer(workspaceLayer);
|
|
|
|
|
2022-04-05 14:15:57 +00:00
|
|
|
auto updateCursorLayer = [output, cursorLayer]() {
|
2022-02-05 09:47:00 +00:00
|
|
|
const Cursor *cursor = Cursors::self()->currentCursor();
|
|
|
|
cursorLayer->setVisible(cursor->isOnOutput(output) && output->usesSoftwareCursor());
|
2022-04-05 14:15:57 +00:00
|
|
|
cursorLayer->setGeometry(output->mapFromGlobal(cursor->geometry()));
|
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);
|
|
|
|
connect(Cursors::self(), &Cursors::positionChanged, cursorLayer, updateCursorLayer);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-23 11:42:59 +00:00
|
|
|
void Compositor::scheduleRepaint()
|
2011-08-21 19:50:23 +00:00
|
|
|
{
|
2022-02-04 18:38:37 +00:00
|
|
|
for (auto it = m_superlayers.constBegin(); it != m_superlayers.constEnd(); ++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
|
|
|
it.key()->scheduleRepaint();
|
|
|
|
}
|
2011-08-21 19:50:23 +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()) {
|
2019-09-24 08:48:08 +00:00
|
|
|
for (X11Client *c : Workspace::self()->clientList()) {
|
2019-01-11 18:55:17 +00:00
|
|
|
m_scene->removeToplevel(c);
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
|
|
|
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
|
2019-01-11 18:55:17 +00:00
|
|
|
m_scene->removeToplevel(c);
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
for (InternalClient *client : workspace()->internalClients()) {
|
|
|
|
m_scene->removeToplevel(client);
|
|
|
|
}
|
2019-09-24 08:48:08 +00:00
|
|
|
for (X11Client *c : Workspace::self()->clientList()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
c->finishCompositing();
|
|
|
|
}
|
|
|
|
for (Unmanaged *c : Workspace::self()->unmanagedList()) {
|
|
|
|
c->finishCompositing();
|
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
for (InternalClient *client : workspace()->internalClients()) {
|
|
|
|
client->finishCompositing();
|
|
|
|
}
|
2019-12-02 17:36:13 +00:00
|
|
|
if (auto *con = kwinApp()->x11Connection()) {
|
|
|
|
xcb_composite_unredirect_subwindows(con, kwinApp()->x11RootWindow(),
|
|
|
|
XCB_COMPOSITE_REDIRECT_MANUAL);
|
|
|
|
}
|
2019-02-10 21:37:06 +00:00
|
|
|
while (!workspace()->deletedList().isEmpty()) {
|
|
|
|
workspace()->deletedList().first()->discard();
|
|
|
|
}
|
2015-05-27 07:12:07 +00:00
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2016-08-18 09:51:54 +00:00
|
|
|
if (waylandServer()) {
|
2021-08-22 11:59:17 +00:00
|
|
|
const QList<AbstractClient *> toRemoveTopLevel = waylandServer()->clients();
|
|
|
|
for (AbstractClient *c : toRemoveTopLevel) {
|
2019-01-11 18:55:17 +00:00
|
|
|
m_scene->removeToplevel(c);
|
2016-08-18 09:51:54 +00:00
|
|
|
}
|
2021-08-22 11:59:17 +00:00
|
|
|
const QList<AbstractClient *> toFinishCompositing = waylandServer()->clients();
|
|
|
|
for (AbstractClient *c : toFinishCompositing) {
|
2016-08-18 09:51:54 +00:00
|
|
|
c->finishCompositing();
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
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-02-04 18:38:37 +00:00
|
|
|
disconnect(kwinApp()->platform(), &Platform::outputEnabled, this, &Compositor::addOutput);
|
|
|
|
disconnect(kwinApp()->platform(), &Platform::outputDisabled, this, &Compositor::removeOutput);
|
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
|
|
|
|
2012-08-16 19:19:54 +00:00
|
|
|
delete m_scene;
|
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
|
|
|
m_scene = nullptr;
|
2019-07-04 01:19:18 +00:00
|
|
|
|
2021-11-08 10:08:06 +00:00
|
|
|
delete m_backend;
|
|
|
|
m_backend = nullptr;
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
delete m_selectionOwner;
|
|
|
|
m_selectionOwner = nullptr;
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
for (const xcb_atom_t &atom : qAsConst(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
|
|
|
{
|
2019-07-04 01:19:18 +00:00
|
|
|
// Reparse config. Config options will be reloaded by start()
|
2016-01-29 10:24:18 +00:00
|
|
|
kwinApp()->config()->reparseConfiguration();
|
2012-08-17 08:15:33 +00:00
|
|
|
|
2011-08-21 19:50:23 +00:00
|
|
|
// Restart compositing
|
2019-07-04 01:19:18 +00:00
|
|
|
stop();
|
|
|
|
start();
|
2012-08-17 08:15:33 +00:00
|
|
|
|
2019-07-04 01:19:18 +00:00
|
|
|
if (effects) { // start() may fail
|
2012-08-17 08:15:33 +00:00
|
|
|
effects->reconfigure();
|
|
|
|
}
|
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
|
|
|
|
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-04-06 14:36:22 +00:00
|
|
|
OutputLayer *outputLayer = 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];
|
|
|
|
prePaintPass(superLayer);
|
|
|
|
superLayer->setOutputLayer(outputLayer);
|
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
|
|
|
SurfaceItem *scanoutCandidate = superLayer->delegate()->scanoutCandidate();
|
2022-02-04 17:38:58 +00:00
|
|
|
renderLoop->setFullscreenSurface(scanoutCandidate);
|
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 17:38:58 +00:00
|
|
|
renderLoop->beginFrame();
|
|
|
|
bool directScanout = false;
|
|
|
|
if (scanoutCandidate) {
|
2022-02-04 18:38:37 +00:00
|
|
|
const auto sublayers = superLayer->sublayers();
|
|
|
|
const bool scanoutPossible = std::none_of(sublayers.begin(), sublayers.end(), [](RenderLayer *sublayer) {
|
|
|
|
return sublayer->isVisible();
|
|
|
|
});
|
|
|
|
if (scanoutPossible && !output->directScanoutInhibited()) {
|
2022-04-06 14:36:22 +00:00
|
|
|
directScanout = outputLayer->scanout(scanoutCandidate);
|
2022-01-13 15:11:04 +00:00
|
|
|
}
|
2015-02-24 10:50:01 +00:00
|
|
|
}
|
2022-02-04 18:38:37 +00:00
|
|
|
|
2022-04-06 12:09:26 +00:00
|
|
|
if (!directScanout) {
|
2022-02-16 17:13:57 +00:00
|
|
|
QRegion surfaceDamage = outputLayer->repaints();
|
2022-02-04 18:38:37 +00:00
|
|
|
outputLayer->resetRepaints();
|
2022-02-16 17:13:57 +00:00
|
|
|
preparePaintPass(superLayer, &surfaceDamage);
|
2022-02-04 18:38:37 +00:00
|
|
|
|
2022-04-12 08:16:27 +00:00
|
|
|
OutputLayerBeginFrameInfo beginInfo = outputLayer->beginFrame();
|
|
|
|
beginInfo.renderTarget.setDevicePixelRatio(output->scale());
|
|
|
|
|
|
|
|
const QRegion bufferDamage = surfaceDamage.united(beginInfo.repaint).intersected(superLayer->rect());
|
2022-04-06 14:36:22 +00:00
|
|
|
outputLayer->aboutToStartPainting(bufferDamage);
|
2022-02-16 17:13:57 +00:00
|
|
|
|
2022-04-12 08:16:27 +00:00
|
|
|
paintPass(superLayer, &beginInfo.renderTarget, bufferDamage);
|
2022-04-06 14:36:22 +00:00
|
|
|
outputLayer->endFrame(bufferDamage, surfaceDamage);
|
2022-02-04 17:38:58 +00:00
|
|
|
}
|
2022-04-06 12:09:26 +00:00
|
|
|
renderLoop->endFrame();
|
2022-02-04 17:38:58 +00:00
|
|
|
|
2022-02-04 18:38:37 +00:00
|
|
|
postPaintPass(superLayer);
|
2022-02-05 09:47:00 +00:00
|
|
|
|
2022-04-06 12:09:26 +00:00
|
|
|
m_backend->present(output);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:16:27 +00:00
|
|
|
void Compositor::paintPass(RenderLayer *layer, RenderTarget *target, const QRegion ®ion)
|
2022-02-04 18:38:37 +00:00
|
|
|
{
|
2022-04-12 08:16:27 +00:00
|
|
|
layer->delegate()->paint(target, region);
|
2022-02-04 18:38:37 +00:00
|
|
|
|
|
|
|
const auto sublayers = layer->sublayers();
|
|
|
|
for (RenderLayer *sublayer : sublayers) {
|
|
|
|
if (sublayer->isVisible()) {
|
2022-04-12 08:16:27 +00:00
|
|
|
paintPass(sublayer, target, 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
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
WaylandCompositor::WaylandCompositor(QObject *parent)
|
|
|
|
: Compositor(parent)
|
|
|
|
{
|
|
|
|
connect(kwinApp(), &Application::x11ConnectionAboutToBeDestroyed,
|
|
|
|
this, &WaylandCompositor::destroyCompositorSelection);
|
|
|
|
}
|
|
|
|
|
2021-06-12 08:03:19 +00:00
|
|
|
WaylandCompositor::~WaylandCompositor()
|
|
|
|
{
|
|
|
|
Q_EMIT aboutToDestroy();
|
|
|
|
stop(); // this can't be called in the destructor of Compositor
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
void WaylandCompositor::toggleCompositing()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
// For the shortcut. Not possible on Wayland because we always composite.
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaylandCompositor::start()
|
|
|
|
{
|
|
|
|
if (!Compositor::setupStart()) {
|
|
|
|
// Internal setup failed, abort.
|
|
|
|
return;
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
if (Workspace::self()) {
|
|
|
|
startupWithWorkspace();
|
|
|
|
} else {
|
2019-08-08 12:34:22 +00:00
|
|
|
connect(kwinApp(), &Application::workspaceCreated,
|
|
|
|
this, &WaylandCompositor::startupWithWorkspace);
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
X11Compositor::X11Compositor(QObject *parent)
|
|
|
|
: Compositor(parent)
|
|
|
|
, m_suspended(options->isUseCompositing() ? NoReasonSuspend : UserSuspend)
|
|
|
|
{
|
2021-04-04 11:45:44 +00:00
|
|
|
if (qEnvironmentVariableIsSet("KWIN_MAX_FRAMES_TESTED")) {
|
|
|
|
m_framesToTestForSafety = qEnvironmentVariableIntValue("KWIN_MAX_FRAMES_TESTED");
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
2021-06-12 08:03:19 +00:00
|
|
|
X11Compositor::~X11Compositor()
|
|
|
|
{
|
|
|
|
Q_EMIT aboutToDestroy();
|
|
|
|
stop(); // this can't be called in the destructor of Compositor
|
|
|
|
}
|
|
|
|
|
2021-06-11 11:11:57 +00:00
|
|
|
X11SyncManager *X11Compositor::syncManager() const
|
|
|
|
{
|
|
|
|
return m_syncManager.data();
|
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
void X11Compositor::toggleCompositing()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
if (m_suspended) {
|
|
|
|
// Direct user call; clear all bits.
|
2019-08-07 17:33:20 +00:00
|
|
|
resume(AllReasonSuspend);
|
2019-08-08 12:34:22 +00:00
|
|
|
} else {
|
|
|
|
// But only set the user one (sufficient to suspend).
|
2019-08-07 17:33:20 +00:00
|
|
|
suspend(UserSuspend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::reinitialize()
|
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
// Resume compositing if suspended.
|
2019-08-07 17:33:20 +00:00
|
|
|
m_suspended = NoReasonSuspend;
|
|
|
|
Compositor::reinitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::configChanged()
|
|
|
|
{
|
|
|
|
if (m_suspended) {
|
|
|
|
stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Compositor::configChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::suspend(X11Compositor::SuspendReason reason)
|
|
|
|
{
|
|
|
|
Q_ASSERT(reason != NoReasonSuspend);
|
|
|
|
m_suspended |= reason;
|
2019-08-08 12:34:22 +00:00
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
if (reason & ScriptSuspend) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// When disabled show a shortcut how the user can get back compositing.
|
|
|
|
const auto shortcuts = KGlobalAccel::self()->shortcut(
|
2022-03-23 10:13:38 +00:00
|
|
|
workspace()->findChild<QAction *>(QStringLiteral("Suspend Compositing")));
|
2019-08-07 17:33:20 +00:00
|
|
|
if (!shortcuts.isEmpty()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Display notification only if there is the shortcut.
|
|
|
|
const QString message =
|
2022-03-23 10:13:38 +00:00
|
|
|
i18n("Desktop effects have been suspended by another application.<br/>"
|
|
|
|
"You can resume using the '%1' shortcut.",
|
|
|
|
shortcuts.first().toString(QKeySequence::NativeText));
|
2022-02-25 09:38:26 +00:00
|
|
|
#if KWIN_BUILD_NOTIFICATIONS
|
2019-08-07 17:33:20 +00:00
|
|
|
KNotification::event(QStringLiteral("compositingsuspendeddbus"), message);
|
2022-02-25 09:38:26 +00:00
|
|
|
#endif
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::resume(X11Compositor::SuspendReason reason)
|
|
|
|
{
|
|
|
|
Q_ASSERT(reason != NoReasonSuspend);
|
|
|
|
m_suspended &= ~reason;
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::start()
|
|
|
|
{
|
|
|
|
if (m_suspended) {
|
|
|
|
QStringList reasons;
|
|
|
|
if (m_suspended & UserSuspend) {
|
|
|
|
reasons << QStringLiteral("Disabled by User");
|
|
|
|
}
|
|
|
|
if (m_suspended & BlockRuleSuspend) {
|
|
|
|
reasons << QStringLiteral("Disabled by Window");
|
|
|
|
}
|
|
|
|
if (m_suspended & ScriptSuspend) {
|
|
|
|
reasons << QStringLiteral("Disabled by Script");
|
|
|
|
}
|
2021-09-01 04:12:30 +00:00
|
|
|
qCInfo(KWIN_CORE) << "Compositing is suspended, reason:" << reasons;
|
2019-08-07 17:33:20 +00:00
|
|
|
return;
|
|
|
|
} else if (!kwinApp()->platform()->compositingPossible()) {
|
2021-09-01 04:12:30 +00:00
|
|
|
qCWarning(KWIN_CORE) << "Compositing is not possible";
|
2019-08-07 17:33:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Compositor::setupStart()) {
|
|
|
|
// Internal setup failed, abort.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
startupWithWorkspace();
|
2021-06-11 11:11:57 +00:00
|
|
|
m_syncManager.reset(X11SyncManager::create());
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11Compositor::stop()
|
|
|
|
{
|
|
|
|
m_syncManager.reset();
|
|
|
|
Compositor::stop();
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
2021-02-03 14:19:55 +00:00
|
|
|
|
|
|
|
void X11Compositor::composite(RenderLoop *renderLoop)
|
2019-08-07 17:33:20 +00:00
|
|
|
{
|
2021-11-11 09:48:43 +00:00
|
|
|
if (backend()->overlayWindow() && !isOverlayWindowVisible()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Return since nothing is visible.
|
|
|
|
return;
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
2021-02-03 14:19:55 +00:00
|
|
|
|
2022-04-18 07:42:11 +00:00
|
|
|
QList<AbstractClient *> windows = Workspace::self()->xStackingOrder();
|
2021-02-04 09:07:20 +00:00
|
|
|
QList<SurfaceItemX11 *> dirtyItems;
|
2021-02-03 14:19:55 +00:00
|
|
|
|
|
|
|
// Reset the damage state of each window and fetch the damage region
|
|
|
|
// without waiting for a reply
|
2022-04-18 07:42:11 +00:00
|
|
|
for (AbstractClient *window : qAsConst(windows)) {
|
2021-02-04 09:07:20 +00:00
|
|
|
SurfaceItemX11 *surfaceItem = static_cast<SurfaceItemX11 *>(window->surfaceItem());
|
|
|
|
if (surfaceItem->fetchDamage()) {
|
|
|
|
dirtyItems.append(surfaceItem);
|
2021-02-03 14:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
if (dirtyItems.count() > 0) {
|
2021-06-11 11:11:57 +00:00
|
|
|
if (m_syncManager) {
|
|
|
|
m_syncManager->triggerFence();
|
|
|
|
}
|
2021-02-04 09:07:20 +00:00
|
|
|
xcb_flush(kwinApp()->x11Connection());
|
2021-02-03 14:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the replies
|
2021-02-04 09:07:20 +00:00
|
|
|
for (SurfaceItemX11 *item : qAsConst(dirtyItems)) {
|
|
|
|
item->waitForDamage();
|
2021-02-03 14:19:55 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:34:18 +00:00
|
|
|
if (m_framesToTestForSafety > 0 && (backend()->compositingType() & OpenGLCompositing)) {
|
2021-04-04 11:45:44 +00:00
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFrame);
|
|
|
|
}
|
|
|
|
|
2021-02-03 14:19:55 +00:00
|
|
|
Compositor::composite(renderLoop);
|
2021-04-04 11:45:44 +00:00
|
|
|
|
2021-06-11 11:11:57 +00:00
|
|
|
if (m_syncManager) {
|
|
|
|
if (!m_syncManager->endFrame()) {
|
|
|
|
qCDebug(KWIN_CORE) << "Aborting explicit synchronization with the X command stream.";
|
|
|
|
qCDebug(KWIN_CORE) << "Future frames will be rendered unsynchronized.";
|
|
|
|
m_syncManager.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-04 11:45:44 +00:00
|
|
|
if (m_framesToTestForSafety > 0) {
|
2021-11-10 10:34:18 +00:00
|
|
|
if (backend()->compositingType() & OpenGLCompositing) {
|
2021-04-04 11:45:44 +00:00
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFrame);
|
|
|
|
}
|
|
|
|
m_framesToTestForSafety--;
|
2021-11-10 10:34:18 +00:00
|
|
|
if (m_framesToTestForSafety == 0 && (backend()->compositingType() & OpenGLCompositing)) {
|
2021-04-04 11:45:44 +00:00
|
|
|
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastGuardedFrame);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool X11Compositor::checkForOverlayWindow(WId w) const
|
2012-08-16 19:19:54 +00:00
|
|
|
{
|
2021-11-11 09:48:43 +00:00
|
|
|
if (!backend()) {
|
|
|
|
// No backend, so it cannot be the overlay window.
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-11 09:48:43 +00:00
|
|
|
if (!backend()->overlayWindow()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// No overlay window, it cannot be the overlay.
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-08 12:34:22 +00:00
|
|
|
// Compare the window ID's.
|
2021-11-11 09:48:43 +00:00
|
|
|
return w == backend()->overlayWindow()->window();
|
2012-08-16 19:19:54 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 17:33:20 +00:00
|
|
|
bool X11Compositor::isOverlayWindowVisible() const
|
2012-08-16 19:19:54 +00:00
|
|
|
{
|
2021-11-11 09:48:43 +00:00
|
|
|
if (!backend()) {
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-11 09:48:43 +00:00
|
|
|
if (!backend()->overlayWindow()) {
|
2012-08-16 19:19:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-11 09:48:43 +00:00
|
|
|
return backend()->overlayWindow()->isVisible();
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
void X11Compositor::updateClientCompositeBlocking(X11Client *c)
|
2019-08-07 17:33:20 +00:00
|
|
|
{
|
2019-08-08 12:34:22 +00:00
|
|
|
if (c) {
|
2019-08-07 17:33:20 +00:00
|
|
|
if (c->isBlockingCompositing()) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Do NOT attempt to call suspend(true) from within the eventchain!
|
2022-03-25 12:20:32 +00:00
|
|
|
if (!(m_suspended & BlockRuleSuspend)) {
|
2022-03-23 10:13:38 +00:00
|
|
|
QMetaObject::invokeMethod(
|
|
|
|
this, [this]() {
|
2019-09-26 15:09:16 +00:00
|
|
|
suspend(BlockRuleSuspend);
|
2022-03-23 10:13:38 +00:00
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
} else if (m_suspended & BlockRuleSuspend) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// If !c we just check if we can resume in case a blocking client was lost.
|
2019-09-26 15:09:16 +00:00
|
|
|
bool shouldResume = true;
|
2019-08-08 12:34:22 +00:00
|
|
|
|
Drop some custom list typedefs
Summary:
Qt has its own thing where a type might also have corresponding list
alias, e.g. QObject and QObjectList, QWidget and QWidgetList. I don't
know why Qt does that, maybe for some historical reasons, but what
matters is that we copy this pattern here in KWin. While this pattern
might be useful with some long list types, for example
QList<QWeakPointer<TabBoxClient>> TabBoxClientList
in general, it causes more harm than good. For example, we've got two
new client types, do we need corresponding list typedefs for them? If
no, why do we have ClientList and so on?
Another problem with these typedefs is that you need to include utils.h
header in order to use them. A better way to handle such things is to
just forward declare a client class (if that's possible) and use it
directly with QList or QVector. This way translation units don't get
"bloated" with utils.h stuff for no apparent reason.
So, in order to make code more consistent and easier to follow, this
change drops some of our custom typedefs. Namely ConstClientList,
ClientList, DeletedList, UnmanagedList, ToplevelList, and GroupList.
Test Plan: Compiles.
Reviewers: #kwin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24950
2019-10-16 09:11:04 +00:00
|
|
|
for (auto it = Workspace::self()->clientList().constBegin();
|
2019-08-08 12:34:22 +00:00
|
|
|
it != Workspace::self()->clientList().constEnd(); ++it) {
|
2019-08-07 17:33:20 +00:00
|
|
|
if ((*it)->isBlockingCompositing()) {
|
2019-09-26 15:09:16 +00:00
|
|
|
shouldResume = false;
|
2019-08-07 17:33:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-26 15:09:16 +00:00
|
|
|
if (shouldResume) {
|
2019-08-08 12:34:22 +00:00
|
|
|
// Do NOT attempt to call suspend(false) from within the eventchain!
|
2022-03-23 10:13:38 +00:00
|
|
|
QMetaObject::invokeMethod(
|
|
|
|
this, [this]() {
|
|
|
|
resume(BlockRuleSuspend);
|
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
2019-08-07 17:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-16 19:19:54 +00:00
|
|
|
}
|
|
|
|
|
[x11] Fix crash during tear down
Summary:
Any call made to a virtual method in constructor/destructor of a base
class won't go to a derived class because the base class may access
uninitialized or destroyed resources.
For example, let's consider the following two classes
class Base {
public:
Base() { foo()->bar(); }
virtual ~Base() { foo()->bar(); }
virtual Foo* foo() const { return nullptr; }
};
class Derived : public Base {
public:
Derived() : mFoo(new Foo) {}
~Derived() override { delete mFoo; }
Foo* foo() const override { return mFoo; }
private:
Foo* mFoo;
};
When an instance of Derived class is created, constructors will run in
the following order:
Base()
Derived()
It's not safe to dispatch foo() method call to Derived class because
constructor of Derived hasn't initialized yet mFoo.
Same story with destructors, they'll run in the following order:
~Derived()
~Base()
It's not safe to dispatch foo() method call in the destructor of Base
class to Derived class because mFoo was deleted.
So, what does that weird C++ behavior has something to do with KWin? Well,
recently Compositor class was split into two classes - WaylandCompositor,
and X11Compositor. Some functionality from X11 doesn't make sense on
Wayland. Therefore methods that implement that stuff were "purified," i.e.
they became pure virtual methods. Unfortunately, when Compositor tears
down it may call pure virtual methods on itself. Given that those calls
cannot be dispatched to X11Compositor or WaylandCompositor, the only
choice that C++ runtime has is to throw an exception.
The fix for this very delicate problem is very simple - do not call virtual
methods from constructors and the destructor. Avoid doing that if you can!
This change moves Compositor::updateClientCompositeBlocking to X11Compositor
so it longer has to be a virtual method. Also, it kind of doesn't make sense
to keep it in base Compositor class because compositing can be blocked only
on X11.
BUG: 411049
Test Plan: KWin no longer crashes when running kwin_x11 --replace command.
Reviewers: #kwin, romangg
Reviewed By: #kwin, romangg
Subscribers: anthonyfieroni, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23098
2019-08-30 16:28:50 +00:00
|
|
|
X11Compositor *X11Compositor::self()
|
|
|
|
{
|
|
|
|
return qobject_cast<X11Compositor *>(Compositor::self());
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:34:22 +00:00
|
|
|
}
|
2019-06-22 10:40:12 +00:00
|
|
|
|
|
|
|
// included for CompositorSelectionOwner
|
|
|
|
#include "composite.moc"
|