2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-04-08 07:51:06 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-04-08 07:51:06 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-04-08 07:51:06 +00:00
|
|
|
#include "x11_platform.h"
|
2016-08-16 13:31:14 +00:00
|
|
|
#include "x11cursor.h"
|
2016-04-15 11:47:56 +00:00
|
|
|
#include "edge.h"
|
2016-11-15 09:22:56 +00:00
|
|
|
#include "windowselector.h"
|
2020-12-05 15:54:19 +00:00
|
|
|
#include "x11xrenderbackend.h"
|
2016-08-16 13:31:14 +00:00
|
|
|
#include <config-kwin.h>
|
2016-04-12 13:03:07 +00:00
|
|
|
#include <kwinconfig.h>
|
|
|
|
#if HAVE_EPOXY_GLX
|
|
|
|
#include "glxbackend.h"
|
|
|
|
#endif
|
2016-08-16 13:31:14 +00:00
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
#include "xinputintegration.h"
|
|
|
|
#endif
|
2017-08-21 06:53:56 +00:00
|
|
|
#include "abstract_client.h"
|
2017-09-23 18:21:26 +00:00
|
|
|
#include "effects_x11.h"
|
2016-04-12 13:03:07 +00:00
|
|
|
#include "eglonxbackend.h"
|
2016-08-16 13:31:14 +00:00
|
|
|
#include "keyboard_input.h"
|
2016-05-10 08:14:53 +00:00
|
|
|
#include "logging.h"
|
2016-04-08 08:32:37 +00:00
|
|
|
#include "screens_xrandr.h"
|
2017-08-19 08:58:05 +00:00
|
|
|
#include "screenedges_filter.h"
|
2016-04-12 13:03:07 +00:00
|
|
|
#include "options.h"
|
2017-08-07 15:54:56 +00:00
|
|
|
#include "overlaywindow_x11.h"
|
2017-08-21 09:59:52 +00:00
|
|
|
#include "non_composited_outline.h"
|
2017-08-21 06:53:56 +00:00
|
|
|
#include "workspace.h"
|
2017-08-20 20:15:21 +00:00
|
|
|
#include "x11_decoration_renderer.h"
|
2019-06-13 09:36:07 +00:00
|
|
|
#include "x11_output.h"
|
|
|
|
#include "xcbutils.h"
|
2016-04-08 07:51:06 +00:00
|
|
|
|
2017-09-10 14:03:11 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
|
|
|
|
2016-05-09 15:32:43 +00:00
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KLocalizedString>
|
Don't use the global KConfig object on the OpenGL freeze detection thread
Summary:
This is meant to address Bug 372114. The problem here is that the KConfig
object (and its derivatives), that the freeze detection thread needs to
record the freeze, are not thread safe. When it happens that the main
thread is in fact not frozen, it is possible that the two stomp on each
other's KConfig object.
The solution applied here is to use the KSharedConfig::openConfig
function, which is thread safe, on the freeze detection thread. As was
mentioned by Martin Flöser in the discussion, the thread needs to obey
the name of the main config file of KWin, which can change in the future.
As a secondary issue, this patch also turns off KCrash reporting for
aborts due to a freeze being detected. IMO it is not very user friendly
to still show a crash report to the user, even after this bug is fixed,
for the deliberate SIGABRT. Maybe a less intrusive notification could be
used to tell the user why effects are suddenly disabled?
I've been using kwin with this change for several weeks now and it makes
the restarts of kwin due to freezes unobtrusive. However, most (I would
say almost all) of these freezes are actually instances where the system
is being slow after eg. screen resolution is changed.
BUG: 372114
FIXED-IN: 5.11.3
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: ngraham, graesslin, anthonyfieroni, cfeck, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D8356
2017-11-05 09:24:56 +00:00
|
|
|
#include <KCrash>
|
2016-05-09 15:32:43 +00:00
|
|
|
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
#include <QThread>
|
2016-05-09 15:32:43 +00:00
|
|
|
#include <QOpenGLContext>
|
2016-04-08 07:51:06 +00:00
|
|
|
#include <QX11Info>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
X11StandalonePlatform::X11StandalonePlatform(QObject *parent)
|
|
|
|
: Platform(parent)
|
2016-11-11 08:59:46 +00:00
|
|
|
, m_x11Display(QX11Info::display())
|
2016-04-08 07:51:06 +00:00
|
|
|
{
|
2016-08-16 13:31:14 +00:00
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
if (!qEnvironmentVariableIsSet("KWIN_NO_XI2")) {
|
2016-11-11 08:59:46 +00:00
|
|
|
m_xinputIntegration = new XInputIntegration(m_x11Display, this);
|
2016-08-16 13:31:14 +00:00
|
|
|
m_xinputIntegration->init();
|
|
|
|
if (!m_xinputIntegration->hasXinput()) {
|
|
|
|
delete m_xinputIntegration;
|
|
|
|
m_xinputIntegration = nullptr;
|
|
|
|
} else {
|
|
|
|
connect(kwinApp(), &Application::workspaceCreated, m_xinputIntegration, &XInputIntegration::startListening);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
|
|
|
|
setSupportsGammaControl(true);
|
2020-11-09 12:19:15 +00:00
|
|
|
setPerScreenRenderingEnabled(false);
|
2016-04-08 07:51:06 +00:00
|
|
|
}
|
|
|
|
|
2017-07-16 15:58:25 +00:00
|
|
|
X11StandalonePlatform::~X11StandalonePlatform()
|
|
|
|
{
|
|
|
|
if (m_openGLFreezeProtectionThread) {
|
|
|
|
m_openGLFreezeProtectionThread->quit();
|
|
|
|
m_openGLFreezeProtectionThread->wait();
|
|
|
|
delete m_openGLFreezeProtectionThread;
|
|
|
|
}
|
2020-12-02 12:12:56 +00:00
|
|
|
if (sceneEglDisplay() != EGL_NO_DISPLAY) {
|
|
|
|
eglTerminate(sceneEglDisplay());
|
|
|
|
}
|
2017-11-01 15:45:18 +00:00
|
|
|
if (isReady()) {
|
|
|
|
XRenderUtils::cleanup();
|
|
|
|
}
|
2017-07-16 15:58:25 +00:00
|
|
|
}
|
2016-04-08 07:51:06 +00:00
|
|
|
|
|
|
|
void X11StandalonePlatform::init()
|
|
|
|
{
|
|
|
|
if (!QX11Info::isPlatformX11()) {
|
|
|
|
emit initFailed();
|
|
|
|
return;
|
|
|
|
}
|
2017-09-10 14:03:11 +00:00
|
|
|
XRenderUtils::init(kwinApp()->x11Connection(), kwinApp()->x11RootWindow());
|
2016-04-08 07:51:06 +00:00
|
|
|
setReady(true);
|
|
|
|
emit screensQueried();
|
|
|
|
}
|
|
|
|
|
2016-04-08 08:32:37 +00:00
|
|
|
Screens *X11StandalonePlatform::createScreens(QObject *parent)
|
|
|
|
{
|
2019-06-13 09:36:07 +00:00
|
|
|
return new XRandRScreens(this, parent);
|
2016-04-08 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:03:07 +00:00
|
|
|
OpenGLBackend *X11StandalonePlatform::createOpenGLBackend()
|
|
|
|
{
|
|
|
|
switch (options->glPlatformInterface()) {
|
|
|
|
#if HAVE_EPOXY_GLX
|
|
|
|
case GlxPlatformInterface:
|
2016-05-10 08:14:53 +00:00
|
|
|
if (hasGlx()) {
|
2016-11-11 08:59:46 +00:00
|
|
|
return new GlxBackend(m_x11Display);
|
2016-05-10 08:14:53 +00:00
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_X11STANDALONE) << "Glx not available, trying EGL instead.";
|
|
|
|
// no break, needs fall-through
|
2017-07-27 18:46:44 +00:00
|
|
|
Q_FALLTHROUGH();
|
2016-05-10 08:14:53 +00:00
|
|
|
}
|
2016-04-12 13:03:07 +00:00
|
|
|
#endif
|
|
|
|
case EglPlatformInterface:
|
2016-11-11 08:59:46 +00:00
|
|
|
return new EglOnXBackend(m_x11Display);
|
2016-04-12 13:03:07 +00:00
|
|
|
default:
|
|
|
|
// no backend available
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-05 15:54:19 +00:00
|
|
|
XRenderBackend *X11StandalonePlatform::createXRenderBackend()
|
|
|
|
{
|
|
|
|
return new X11XRenderBackend(this);
|
|
|
|
}
|
|
|
|
|
2016-04-15 11:47:56 +00:00
|
|
|
Edge *X11StandalonePlatform::createScreenEdge(ScreenEdges *edges)
|
|
|
|
{
|
2017-08-19 08:58:05 +00:00
|
|
|
if (m_screenEdgesFilter.isNull()) {
|
|
|
|
m_screenEdgesFilter.reset(new ScreenEdgesFilter);
|
|
|
|
}
|
2016-04-15 11:47:56 +00:00
|
|
|
return new WindowBasedEdge(edges);
|
|
|
|
}
|
|
|
|
|
2016-08-15 10:00:03 +00:00
|
|
|
void X11StandalonePlatform::createPlatformCursor(QObject *parent)
|
|
|
|
{
|
2016-08-16 13:31:14 +00:00
|
|
|
auto c = new X11Cursor(parent, m_xinputIntegration != nullptr);
|
|
|
|
#if HAVE_X11_XINPUT
|
|
|
|
if (m_xinputIntegration) {
|
|
|
|
m_xinputIntegration->setCursor(c);
|
|
|
|
// we know we have xkb already
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2019-01-04 17:38:47 +00:00
|
|
|
xkb->setConfig(kwinApp()->kxkbConfig());
|
2016-08-16 13:31:14 +00:00
|
|
|
xkb->reconfigure();
|
|
|
|
}
|
|
|
|
#endif
|
2016-08-15 10:00:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 14:41:37 +00:00
|
|
|
bool X11StandalonePlatform::requiresCompositing() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:32:43 +00:00
|
|
|
bool X11StandalonePlatform::openGLCompositingIsBroken() const
|
|
|
|
{
|
|
|
|
const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : QString()));
|
|
|
|
return KConfigGroup(kwinApp()->config(), "Compositing").readEntry(unsafeKey, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString X11StandalonePlatform::compositingNotPossibleReason() const
|
|
|
|
{
|
|
|
|
// first off, check whether we figured that we'll crash on detection because of a buggy driver
|
|
|
|
KConfigGroup gl_workaround_group(kwinApp()->config(), "Compositing");
|
|
|
|
const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : QString()));
|
|
|
|
if (gl_workaround_group.readEntry("Backend", "OpenGL") == QLatin1String("OpenGL") &&
|
|
|
|
gl_workaround_group.readEntry(unsafeKey, false))
|
|
|
|
return i18n("<b>OpenGL compositing (the default) has crashed KWin in the past.</b><br>"
|
|
|
|
"This was most likely due to a driver bug."
|
|
|
|
"<p>If you think that you have meanwhile upgraded to a stable driver,<br>"
|
|
|
|
"you can reset this protection but <b>be aware that this might result in an immediate crash!</b></p>"
|
|
|
|
"<p>Alternatively, you might want to use the XRender backend instead.</p>");
|
|
|
|
|
|
|
|
if (!Xcb::Extensions::self()->isCompositeAvailable() || !Xcb::Extensions::self()->isDamageAvailable()) {
|
|
|
|
return i18n("Required X extensions (XComposite and XDamage) are not available.");
|
|
|
|
}
|
|
|
|
#if !defined( KWIN_HAVE_XRENDER_COMPOSITING )
|
|
|
|
if (!hasGlx())
|
|
|
|
return i18n("GLX/OpenGL are not available and only OpenGL support is compiled.");
|
|
|
|
#else
|
|
|
|
if (!(hasGlx()
|
|
|
|
|| (Xcb::Extensions::self()->isRenderAvailable() && Xcb::Extensions::self()->isFixesAvailable()))) {
|
|
|
|
return i18n("GLX/OpenGL and XRender/XFixes are not available.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool X11StandalonePlatform::compositingPossible() const
|
|
|
|
{
|
|
|
|
// first off, check whether we figured that we'll crash on detection because of a buggy driver
|
|
|
|
KConfigGroup gl_workaround_group(kwinApp()->config(), "Compositing");
|
|
|
|
const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : QString()));
|
|
|
|
if (gl_workaround_group.readEntry("Backend", "OpenGL") == QLatin1String("OpenGL") &&
|
|
|
|
gl_workaround_group.readEntry(unsafeKey, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!Xcb::Extensions::self()->isCompositeAvailable()) {
|
2020-11-28 13:58:43 +00:00
|
|
|
qCDebug(KWIN_X11STANDALONE) << "No composite extension available";
|
2016-05-09 15:32:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!Xcb::Extensions::self()->isDamageAvailable()) {
|
2020-11-28 13:58:43 +00:00
|
|
|
qCDebug(KWIN_X11STANDALONE) << "No damage extension available";
|
2016-05-09 15:32:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (hasGlx())
|
|
|
|
return true;
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
if (Xcb::Extensions::self()->isRenderAvailable() && Xcb::Extensions::self()->isFixesAvailable())
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
|
|
|
|
return true;
|
|
|
|
} else if (qstrcmp(qgetenv("KWIN_COMPOSE"), "O2ES") == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-28 13:58:43 +00:00
|
|
|
qCDebug(KWIN_X11STANDALONE) << "No OpenGL or XRender/XFixes support";
|
2016-05-09 15:32:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool X11StandalonePlatform::hasGlx()
|
|
|
|
{
|
|
|
|
return Xcb::Extensions::self()->hasGlx();
|
|
|
|
}
|
2016-05-09 14:41:37 +00:00
|
|
|
|
2016-05-10 08:34:09 +00:00
|
|
|
void X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
|
|
|
|
{
|
|
|
|
const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : QString()));
|
|
|
|
auto group = KConfigGroup(kwinApp()->config(), "Compositing");
|
|
|
|
switch (safePoint) {
|
|
|
|
case OpenGLSafePoint::PreInit:
|
|
|
|
group.writeEntry(unsafeKey, true);
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
group.sync();
|
|
|
|
// Deliberately continue with PreFrame
|
2017-07-27 18:46:44 +00:00
|
|
|
Q_FALLTHROUGH();
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
case OpenGLSafePoint::PreFrame:
|
|
|
|
if (m_openGLFreezeProtectionThread == nullptr) {
|
|
|
|
Q_ASSERT(m_openGLFreezeProtection == nullptr);
|
|
|
|
m_openGLFreezeProtectionThread = new QThread(this);
|
|
|
|
m_openGLFreezeProtectionThread->setObjectName("FreezeDetector");
|
|
|
|
m_openGLFreezeProtectionThread->start();
|
|
|
|
m_openGLFreezeProtection = new QTimer;
|
|
|
|
m_openGLFreezeProtection->setInterval(15000);
|
|
|
|
m_openGLFreezeProtection->setSingleShot(true);
|
|
|
|
m_openGLFreezeProtection->start();
|
Don't use the global KConfig object on the OpenGL freeze detection thread
Summary:
This is meant to address Bug 372114. The problem here is that the KConfig
object (and its derivatives), that the freeze detection thread needs to
record the freeze, are not thread safe. When it happens that the main
thread is in fact not frozen, it is possible that the two stomp on each
other's KConfig object.
The solution applied here is to use the KSharedConfig::openConfig
function, which is thread safe, on the freeze detection thread. As was
mentioned by Martin Flöser in the discussion, the thread needs to obey
the name of the main config file of KWin, which can change in the future.
As a secondary issue, this patch also turns off KCrash reporting for
aborts due to a freeze being detected. IMO it is not very user friendly
to still show a crash report to the user, even after this bug is fixed,
for the deliberate SIGABRT. Maybe a less intrusive notification could be
used to tell the user why effects are suddenly disabled?
I've been using kwin with this change for several weeks now and it makes
the restarts of kwin due to freezes unobtrusive. However, most (I would
say almost all) of these freezes are actually instances where the system
is being slow after eg. screen resolution is changed.
BUG: 372114
FIXED-IN: 5.11.3
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: ngraham, graesslin, anthonyfieroni, cfeck, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D8356
2017-11-05 09:24:56 +00:00
|
|
|
const QString configName = kwinApp()->config()->name();
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
m_openGLFreezeProtection->moveToThread(m_openGLFreezeProtectionThread);
|
|
|
|
connect(m_openGLFreezeProtection, &QTimer::timeout, m_openGLFreezeProtection,
|
Don't use the global KConfig object on the OpenGL freeze detection thread
Summary:
This is meant to address Bug 372114. The problem here is that the KConfig
object (and its derivatives), that the freeze detection thread needs to
record the freeze, are not thread safe. When it happens that the main
thread is in fact not frozen, it is possible that the two stomp on each
other's KConfig object.
The solution applied here is to use the KSharedConfig::openConfig
function, which is thread safe, on the freeze detection thread. As was
mentioned by Martin Flöser in the discussion, the thread needs to obey
the name of the main config file of KWin, which can change in the future.
As a secondary issue, this patch also turns off KCrash reporting for
aborts due to a freeze being detected. IMO it is not very user friendly
to still show a crash report to the user, even after this bug is fixed,
for the deliberate SIGABRT. Maybe a less intrusive notification could be
used to tell the user why effects are suddenly disabled?
I've been using kwin with this change for several weeks now and it makes
the restarts of kwin due to freezes unobtrusive. However, most (I would
say almost all) of these freezes are actually instances where the system
is being slow after eg. screen resolution is changed.
BUG: 372114
FIXED-IN: 5.11.3
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: ngraham, graesslin, anthonyfieroni, cfeck, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D8356
2017-11-05 09:24:56 +00:00
|
|
|
[configName] {
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : QString()));
|
Don't use the global KConfig object on the OpenGL freeze detection thread
Summary:
This is meant to address Bug 372114. The problem here is that the KConfig
object (and its derivatives), that the freeze detection thread needs to
record the freeze, are not thread safe. When it happens that the main
thread is in fact not frozen, it is possible that the two stomp on each
other's KConfig object.
The solution applied here is to use the KSharedConfig::openConfig
function, which is thread safe, on the freeze detection thread. As was
mentioned by Martin Flöser in the discussion, the thread needs to obey
the name of the main config file of KWin, which can change in the future.
As a secondary issue, this patch also turns off KCrash reporting for
aborts due to a freeze being detected. IMO it is not very user friendly
to still show a crash report to the user, even after this bug is fixed,
for the deliberate SIGABRT. Maybe a less intrusive notification could be
used to tell the user why effects are suddenly disabled?
I've been using kwin with this change for several weeks now and it makes
the restarts of kwin due to freezes unobtrusive. However, most (I would
say almost all) of these freezes are actually instances where the system
is being slow after eg. screen resolution is changed.
BUG: 372114
FIXED-IN: 5.11.3
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: ngraham, graesslin, anthonyfieroni, cfeck, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D8356
2017-11-05 09:24:56 +00:00
|
|
|
auto group = KConfigGroup(KSharedConfig::openConfig(configName), "Compositing");
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
group.writeEntry(unsafeKey, true);
|
|
|
|
group.sync();
|
Don't use the global KConfig object on the OpenGL freeze detection thread
Summary:
This is meant to address Bug 372114. The problem here is that the KConfig
object (and its derivatives), that the freeze detection thread needs to
record the freeze, are not thread safe. When it happens that the main
thread is in fact not frozen, it is possible that the two stomp on each
other's KConfig object.
The solution applied here is to use the KSharedConfig::openConfig
function, which is thread safe, on the freeze detection thread. As was
mentioned by Martin Flöser in the discussion, the thread needs to obey
the name of the main config file of KWin, which can change in the future.
As a secondary issue, this patch also turns off KCrash reporting for
aborts due to a freeze being detected. IMO it is not very user friendly
to still show a crash report to the user, even after this bug is fixed,
for the deliberate SIGABRT. Maybe a less intrusive notification could be
used to tell the user why effects are suddenly disabled?
I've been using kwin with this change for several weeks now and it makes
the restarts of kwin due to freezes unobtrusive. However, most (I would
say almost all) of these freezes are actually instances where the system
is being slow after eg. screen resolution is changed.
BUG: 372114
FIXED-IN: 5.11.3
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: ngraham, graesslin, anthonyfieroni, cfeck, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D8356
2017-11-05 09:24:56 +00:00
|
|
|
KCrash::setDrKonqiEnabled(false);
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
qFatal("Freeze in OpenGL initialization detected");
|
|
|
|
}, Qt::DirectConnection);
|
|
|
|
} else {
|
|
|
|
Q_ASSERT(m_openGLFreezeProtection);
|
|
|
|
QMetaObject::invokeMethod(m_openGLFreezeProtection, "start", Qt::QueuedConnection);
|
|
|
|
}
|
2016-05-10 08:34:09 +00:00
|
|
|
break;
|
|
|
|
case OpenGLSafePoint::PostInit:
|
|
|
|
group.writeEntry(unsafeKey, false);
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
group.sync();
|
|
|
|
// Deliberately continue with PostFrame
|
2017-07-27 18:46:44 +00:00
|
|
|
Q_FALLTHROUGH();
|
[platformx/x11] Add a freeze protection against OpenGL
Summary:
With nouveau driver it can happen that KWin gets frozen when first trying
to render with OpenGL. This results in a freeze of the complete desktop
as the compositor is non functional.
Our OpenGL breakage detection is only able to detect crashes, but not
freezes. This change improves it by also added a freeze protection.
In the PreInit stage a thread is started with a QTimer of 15 sec. If the
timer fires, qFatal is triggered to terminate KWin. This can only happen
if the creation of the OpenGL compositor takes longer than said 15 sec.
In the PostInit stage the timer gets deleted and the thread stopeed
again.
Thus if a freeze is detected the OpenGL unsafe protection is written into
the config. KWin aborts and gets restarted by DrKonqui. The new KWin
instance will no longer try to activate the freezing OpenGL as the
protection is set.
If KWin doesn't freeze the protection is removed from the config as
we are used to.
Check for freezes for the first n frames, not just the first
This patch changes the freeze detection code to detect freezes in the
first 30 frames (by default, users can change that with the
KWIN_MAX_FRAMES_TESTED environment variable). This detects
successfully the freezes associated to nouveau drivers
in https://bugzilla.suse.com/show_bug.cgi?id=1005323
Reviewers: davidedmundson, #plasma, #kwin, graesslin
Reviewed By: #plasma, #kwin, graesslin
Subscribers: luebking, graesslin, kwin, plasma-devel, davidedmundson
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D3132
2016-10-24 15:14:32 +00:00
|
|
|
case OpenGLSafePoint::PostFrame:
|
|
|
|
QMetaObject::invokeMethod(m_openGLFreezeProtection, "stop", Qt::QueuedConnection);
|
|
|
|
break;
|
|
|
|
case OpenGLSafePoint::PostLastGuardedFrame:
|
|
|
|
m_openGLFreezeProtection->deleteLater();
|
|
|
|
m_openGLFreezeProtection = nullptr;
|
|
|
|
m_openGLFreezeProtectionThread->quit();
|
|
|
|
m_openGLFreezeProtectionThread->wait();
|
|
|
|
delete m_openGLFreezeProtectionThread;
|
|
|
|
m_openGLFreezeProtectionThread = nullptr;
|
2016-05-10 08:34:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:12:21 +00:00
|
|
|
PlatformCursorImage X11StandalonePlatform::cursorImage() const
|
|
|
|
{
|
|
|
|
auto c = kwinApp()->x11Connection();
|
|
|
|
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t, QScopedPointerPodDeleter> cursor(
|
|
|
|
xcb_xfixes_get_cursor_image_reply(c,
|
|
|
|
xcb_xfixes_get_cursor_image_unchecked(c),
|
|
|
|
nullptr));
|
|
|
|
if (cursor.isNull()) {
|
|
|
|
return PlatformCursorImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage qcursorimg((uchar *) xcb_xfixes_get_cursor_image_cursor_image(cursor.data()), cursor->width, cursor->height,
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
// deep copy of image as the data is going to be freed
|
|
|
|
return PlatformCursorImage(qcursorimg.copy(), QPoint(cursor->xhot, cursor->yhot));
|
|
|
|
}
|
|
|
|
|
2016-10-20 08:21:54 +00:00
|
|
|
void X11StandalonePlatform::doHideCursor()
|
|
|
|
{
|
|
|
|
xcb_xfixes_hide_cursor(kwinApp()->x11Connection(), kwinApp()->x11RootWindow());
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11StandalonePlatform::doShowCursor()
|
|
|
|
{
|
|
|
|
xcb_xfixes_show_cursor(kwinApp()->x11Connection(), kwinApp()->x11RootWindow());
|
|
|
|
}
|
|
|
|
|
2016-11-15 09:22:56 +00:00
|
|
|
void X11StandalonePlatform::startInteractiveWindowSelection(std::function<void(KWin::Toplevel*)> callback, const QByteArray &cursorName)
|
|
|
|
{
|
|
|
|
if (m_windowSelector.isNull()) {
|
|
|
|
m_windowSelector.reset(new WindowSelector);
|
|
|
|
}
|
|
|
|
m_windowSelector->start(callback, cursorName);
|
|
|
|
}
|
|
|
|
|
2018-02-04 17:01:30 +00:00
|
|
|
void X11StandalonePlatform::startInteractivePositionSelection(std::function<void (const QPoint &)> callback)
|
|
|
|
{
|
|
|
|
if (m_windowSelector.isNull()) {
|
|
|
|
m_windowSelector.reset(new WindowSelector);
|
|
|
|
}
|
|
|
|
m_windowSelector->start(callback);
|
|
|
|
}
|
|
|
|
|
2017-01-17 06:12:44 +00:00
|
|
|
void X11StandalonePlatform::setupActionForGlobalAccel(QAction *action)
|
|
|
|
{
|
|
|
|
connect(action, &QAction::triggered, kwinApp(), [action] {
|
|
|
|
QVariant timestamp = action->property("org.kde.kglobalaccel.activationTimestamp");
|
|
|
|
bool ok = false;
|
|
|
|
const quint32 t = timestamp.toULongLong(&ok);
|
|
|
|
if (ok) {
|
|
|
|
kwinApp()->setX11Time(t);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-07 15:54:56 +00:00
|
|
|
OverlayWindow *X11StandalonePlatform::createOverlayWindow()
|
|
|
|
{
|
|
|
|
return new OverlayWindowX11();
|
|
|
|
}
|
|
|
|
|
2017-08-21 09:59:52 +00:00
|
|
|
OutlineVisual *X11StandalonePlatform::createOutline(Outline *outline)
|
|
|
|
{
|
|
|
|
// first try composited Outline
|
|
|
|
auto ret = Platform::createOutline(outline);
|
|
|
|
if (!ret) {
|
|
|
|
ret = new NonCompositedOutlineVisual(outline);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2017-08-24 14:53:40 +00:00
|
|
|
|
2017-08-20 20:15:21 +00:00
|
|
|
Decoration::Renderer *X11StandalonePlatform::createDecorationRenderer(Decoration::DecoratedClientImpl *client)
|
|
|
|
{
|
|
|
|
auto renderer = Platform::createDecorationRenderer(client);
|
|
|
|
if (!renderer) {
|
|
|
|
renderer = new Decoration::X11Renderer(client);
|
|
|
|
}
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
2017-08-21 06:53:56 +00:00
|
|
|
void X11StandalonePlatform::invertScreen()
|
|
|
|
{
|
|
|
|
using namespace Xcb::RandR;
|
|
|
|
bool succeeded = false;
|
|
|
|
|
|
|
|
if (Xcb::Extensions::self()->isRandrAvailable()) {
|
|
|
|
const auto active_client = workspace()->activeClient();
|
|
|
|
ScreenResources res((active_client && active_client->window() != XCB_WINDOW_NONE) ? active_client->window() : rootWindow());
|
|
|
|
|
|
|
|
if (!res.isNull()) {
|
|
|
|
for (int j = 0; j < res->num_crtcs; ++j) {
|
|
|
|
auto crtc = res.crtcs()[j];
|
|
|
|
CrtcGamma gamma(crtc);
|
|
|
|
if (gamma.isNull()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (gamma->size) {
|
2020-11-28 13:58:43 +00:00
|
|
|
qCDebug(KWIN_X11STANDALONE) << "inverting screen using xcb_randr_set_crtc_gamma";
|
2017-08-21 06:53:56 +00:00
|
|
|
const int half = gamma->size / 2 + 1;
|
|
|
|
|
|
|
|
uint16_t *red = gamma.red();
|
|
|
|
uint16_t *green = gamma.green();
|
|
|
|
uint16_t *blue = gamma.blue();
|
|
|
|
for (int i = 0; i < half; ++i) {
|
|
|
|
auto invert = [&gamma, i](uint16_t *ramp) {
|
|
|
|
qSwap(ramp[i], ramp[gamma->size - 1 - i]);
|
|
|
|
};
|
|
|
|
invert(red);
|
|
|
|
invert(green);
|
|
|
|
invert(blue);
|
|
|
|
}
|
|
|
|
xcb_randr_set_crtc_gamma(connection(), crtc, gamma->size, red, green, blue);
|
|
|
|
succeeded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!succeeded) {
|
|
|
|
Platform::invertScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-23 18:21:26 +00:00
|
|
|
void X11StandalonePlatform::createEffectsHandler(Compositor *compositor, Scene *scene)
|
|
|
|
{
|
|
|
|
new EffectsHandlerImplX11(compositor, scene);
|
|
|
|
}
|
|
|
|
|
2017-10-15 20:24:49 +00:00
|
|
|
QVector<CompositingType> X11StandalonePlatform::supportedCompositors() const
|
|
|
|
{
|
|
|
|
QVector<CompositingType> compositors;
|
|
|
|
#if HAVE_EPOXY_GLX
|
|
|
|
compositors << OpenGLCompositing;
|
|
|
|
#endif
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
compositors << XRenderCompositing;
|
|
|
|
#endif
|
|
|
|
compositors << NoCompositing;
|
|
|
|
return compositors;
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
void X11StandalonePlatform::initOutputs()
|
|
|
|
{
|
|
|
|
doUpdateOutputs<Xcb::RandR::ScreenResources>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11StandalonePlatform::updateOutputs()
|
|
|
|
{
|
|
|
|
doUpdateOutputs<Xcb::RandR::CurrentResources>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void X11StandalonePlatform::doUpdateOutputs()
|
|
|
|
{
|
|
|
|
auto fallback = [this]() {
|
|
|
|
auto *o = new X11Output(this);
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
o->setGammaRampSize(0);
|
2020-11-28 12:34:05 +00:00
|
|
|
o->setRefreshRate(60000);
|
2019-06-13 09:36:07 +00:00
|
|
|
o->setName(QStringLiteral("Xinerama"));
|
|
|
|
m_outputs << o;
|
2020-12-02 18:10:51 +00:00
|
|
|
emit outputAdded(o);
|
2019-06-13 09:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: instead of resetting all outputs, check if new output is added/removed
|
|
|
|
// or still available and leave still available outputs in m_outputs
|
|
|
|
// untouched (like in DRM backend)
|
2020-12-02 18:10:51 +00:00
|
|
|
while (!m_outputs.isEmpty()) {
|
|
|
|
X11Output *output = m_outputs.takeLast();
|
|
|
|
emit outputRemoved(output);
|
|
|
|
delete output;
|
|
|
|
}
|
2019-06-13 09:36:07 +00:00
|
|
|
|
|
|
|
if (!Xcb::Extensions::self()->isRandrAvailable()) {
|
|
|
|
fallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
T resources(rootWindow());
|
|
|
|
if (resources.isNull()) {
|
|
|
|
fallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xcb_randr_crtc_t *crtcs = resources.crtcs();
|
|
|
|
xcb_randr_mode_info_t *modes = resources.modes();
|
|
|
|
|
|
|
|
QVector<Xcb::RandR::CrtcInfo> infos(resources->num_crtcs);
|
|
|
|
for (int i = 0; i < resources->num_crtcs; ++i) {
|
|
|
|
infos[i] = Xcb::RandR::CrtcInfo(crtcs[i], resources->config_timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < resources->num_crtcs; ++i) {
|
|
|
|
Xcb::RandR::CrtcInfo info(infos.at(i));
|
|
|
|
|
|
|
|
xcb_randr_output_t *outputs = info.outputs();
|
|
|
|
QVector<Xcb::RandR::OutputInfo> outputInfos(outputs ? resources->num_outputs : 0);
|
|
|
|
if (outputs) {
|
|
|
|
for (int i = 0; i < resources->num_outputs; ++i) {
|
|
|
|
outputInfos[i] = Xcb::RandR::OutputInfo(outputs[i], resources->config_timestamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float refreshRate = -1.0f;
|
|
|
|
for (int j = 0; j < resources->num_modes; ++j) {
|
|
|
|
if (info->mode == modes[j].id) {
|
|
|
|
if (modes[j].htotal != 0 && modes[j].vtotal != 0) { // BUG 313996
|
|
|
|
// refresh rate calculation - WTF was wikipedia 1998 when I needed it?
|
|
|
|
int dotclock = modes[j].dot_clock,
|
|
|
|
vtotal = modes[j].vtotal;
|
|
|
|
if (modes[j].mode_flags & XCB_RANDR_MODE_FLAG_INTERLACE)
|
|
|
|
dotclock *= 2;
|
|
|
|
if (modes[j].mode_flags & XCB_RANDR_MODE_FLAG_DOUBLE_SCAN)
|
|
|
|
vtotal *= 2;
|
|
|
|
refreshRate = dotclock/float(modes[j].htotal*vtotal);
|
|
|
|
}
|
|
|
|
break; // found mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QRect geo = info.rect();
|
|
|
|
if (geo.isValid()) {
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
xcb_randr_crtc_t crtc = crtcs[i];
|
|
|
|
|
|
|
|
// TODO: Perhaps the output has to save the inherited gamma ramp and
|
|
|
|
// restore it during tear down. Currently neither standalone x11 nor
|
|
|
|
// drm platform do this.
|
|
|
|
Xcb::RandR::CrtcGamma gamma(crtc);
|
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
auto *o = new X11Output(this);
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
o->setCrtc(crtc);
|
|
|
|
o->setGammaRampSize(gamma.isNull() ? 0 : gamma->size);
|
2019-06-13 09:36:07 +00:00
|
|
|
o->setGeometry(geo);
|
2019-08-19 14:28:27 +00:00
|
|
|
o->setRefreshRate(refreshRate * 1000);
|
2019-06-13 09:36:07 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < info->num_outputs; ++j) {
|
|
|
|
Xcb::RandR::OutputInfo outputInfo(outputInfos.at(j));
|
2020-06-17 07:49:55 +00:00
|
|
|
if (outputInfo->crtc != crtc) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QSize physicalSize(outputInfo->mm_width, outputInfo->mm_height);
|
|
|
|
switch (info->rotation) {
|
|
|
|
case XCB_RANDR_ROTATION_ROTATE_0:
|
|
|
|
case XCB_RANDR_ROTATION_ROTATE_180:
|
|
|
|
break;
|
|
|
|
case XCB_RANDR_ROTATION_ROTATE_90:
|
|
|
|
case XCB_RANDR_ROTATION_ROTATE_270:
|
|
|
|
physicalSize.transpose();
|
|
|
|
break;
|
|
|
|
case XCB_RANDR_ROTATION_REFLECT_X:
|
|
|
|
case XCB_RANDR_ROTATION_REFLECT_Y:
|
2019-06-13 09:36:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-06-17 07:49:55 +00:00
|
|
|
o->setName(outputInfo.name());
|
|
|
|
o->setPhysicalSize(physicalSize);
|
|
|
|
break;
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
2020-06-17 07:49:55 +00:00
|
|
|
|
2019-06-13 09:36:07 +00:00
|
|
|
m_outputs << o;
|
2020-12-02 18:10:51 +00:00
|
|
|
emit outputAdded(o);
|
2019-06-13 09:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_outputs.isEmpty()) {
|
|
|
|
fallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Outputs X11StandalonePlatform::outputs() const
|
|
|
|
{
|
|
|
|
return m_outputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
Outputs X11StandalonePlatform::enabledOutputs() const
|
|
|
|
{
|
|
|
|
return m_outputs;
|
|
|
|
}
|
|
|
|
|
2016-04-08 07:51:06 +00:00
|
|
|
}
|