From d15d3a5ff12ca6a6e66ee8e087fd7a795ce3c25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 9 May 2016 17:32:43 +0200 Subject: [PATCH] Provide functionality of CompositingPrefs through Platform Summary: CompositingPrefs is only relevant for X11 standalone. It had some "hacks" to make it not block Compositing on Wayland. Thus it was in its current form not really useful. Now all the functionality is provided through Platform with a default implementation which is sensible for Wayland platforms. The X11 standalone platform implements the new methods with the Wayland checks removed. In addition all calls to CompositingPrefs now go through the platform directly and CompositingPrefs is completely dropped. Reviewers: #plasma Subscribers: plasma-devel Projects: #plasma Differential Revision: https://phabricator.kde.org/D1576 --- CMakeLists.txt | 1 - composite.cpp | 5 +- compositingprefs.cpp | 129 ------------------ compositingprefs.h | 59 -------- dbusinterface.cpp | 8 +- options.cpp | 1 - platform.cpp | 15 ++ platform.h | 24 ++++ .../platforms/x11/standalone/x11_platform.cpp | 75 ++++++++++ .../platforms/x11/standalone/x11_platform.h | 15 ++ 10 files changed, 135 insertions(+), 197 deletions(-) delete mode 100644 compositingprefs.cpp delete mode 100644 compositingprefs.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d9632589ce..4d2c469dc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,7 +388,6 @@ set(kwin_KDEINIT_SRCS deleted.cpp effects.cpp effectloader.cpp - compositingprefs.cpp virtualdesktops.cpp xcbutils.cpp x11eventfilter.cpp diff --git a/composite.cpp b/composite.cpp index 7b0a166f41..77163635de 100644 --- a/composite.cpp +++ b/composite.cpp @@ -35,7 +35,6 @@ along with this program. If not, see . #include "screens.h" #include "shadow.h" #include "useractions.h" -#include "compositingprefs.h" #include "xcbutils.h" #include "platform.h" #include "shell_client.h" @@ -170,7 +169,7 @@ void Compositor::setup() } qCDebug(KWIN_CORE) << "Compositing is suspended, reason:" << reasons; return; - } else if (!CompositingPrefs::compositingPossible()) { + } else if (!kwinApp()->platform()->compositingPossible()) { qCCritical(KWIN_CORE) << "Compositing is not possible"; return; } @@ -211,7 +210,7 @@ void Compositor::slotCompositingOptionsInitialized() else { unsafeConfig.writeEntry(openGLIsUnsafe, true); unsafeConfig.sync(); - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL && !kwinApp()->shouldUseWaylandForCompositing() && !CompositingPrefs::hasGlx()) { + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL && !kwinApp()->shouldUseWaylandForCompositing() && !Xcb::Extensions::self()->hasGlx()) { unsafeConfig.writeEntry(openGLIsUnsafe, false); unsafeConfig.sync(); qCDebug(KWIN_CORE) << "No glx extensions available"; diff --git a/compositingprefs.cpp b/compositingprefs.cpp deleted file mode 100644 index ab7d16fc18..0000000000 --- a/compositingprefs.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************** - KWin - the KDE window manager - This file is part of the KDE project. - -Copyright (C) 2007 Rivo Laks - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*********************************************************************/ - -#include "compositingprefs.h" - -#include "main.h" -#include "xcbutils.h" -#include "kwinglplatform.h" -#include "utils.h" - -#include -#include -#include - -#include -#include -#include -#include - - -namespace KWin -{ - -extern int screen_number; // main.cpp -extern bool is_multihead; - -CompositingPrefs::CompositingPrefs() -{ -} - -CompositingPrefs::~CompositingPrefs() -{ -} - -bool CompositingPrefs::openGlIsBroken() -{ - const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + (is_multihead ? QString::number(screen_number) : QString())); - return KConfigGroup(kwinApp()->config(), "Compositing").readEntry(unsafeKey, false); -} - -bool CompositingPrefs::compositingPossible() -{ - // 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") + (is_multihead ? QString::number(screen_number) : QString())); - if (gl_workaround_group.readEntry("Backend", "OpenGL") == QLatin1String("OpenGL") && - gl_workaround_group.readEntry(unsafeKey, false)) - return false; - - if (kwinApp()->shouldUseWaylandForCompositing()) { - // don't do X specific checks if we are not going to use X for compositing - return true; - } - - if (!Xcb::Extensions::self()->isCompositeAvailable()) { - qCDebug(KWIN_CORE) << "No composite extension available"; - return false; - } - if (!Xcb::Extensions::self()->isDamageAvailable()) { - qCDebug(KWIN_CORE) << "No damage extension available"; - 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; - } - qCDebug(KWIN_CORE) << "No OpenGL or XRender/XFixes support"; - return false; -} - -QString CompositingPrefs::compositingNotPossibleReason() -{ - // 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") + (is_multihead ? QString::number(screen_number) : QString())); - if (gl_workaround_group.readEntry("Backend", "OpenGL") == QLatin1String("OpenGL") && - gl_workaround_group.readEntry(unsafeKey, false)) - return i18n("OpenGL compositing (the default) has crashed KWin in the past.
" - "This was most likely due to a driver bug." - "

If you think that you have meanwhile upgraded to a stable driver,
" - "you can reset this protection but be aware that this might result in an immediate crash!

" - "

Alternatively, you might want to use the XRender backend instead.

"); - - 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 CompositingPrefs::hasGlx() -{ - return Xcb::Extensions::self()->hasGlx(); -} - -} // namespace - diff --git a/compositingprefs.h b/compositingprefs.h deleted file mode 100644 index 889ed8b978..0000000000 --- a/compositingprefs.h +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************** - KWin - the KDE window manager - This file is part of the KDE project. - -Copyright (C) 2007 Rivo Laks - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*********************************************************************/ - -#ifndef KWIN_COMPOSITINGPREFS_H -#define KWIN_COMPOSITINGPREFS_H - -#include -#include - -#include "kwinglutils.h" -#include "kwinglobals.h" - - -namespace KWin -{ - -class CompositingPrefs -{ -public: - CompositingPrefs(); - ~CompositingPrefs(); - - static bool compositingPossible(); - static QString compositingNotPossibleReason(); - static bool openGlIsBroken(); - /** - * Tests whether GLX is supported and returns @c true - * in case KWin is compiled with OpenGL support and GLX - * is available. - * - * If KWin is compiled with OpenGL ES or without OpenGL at - * all, @c false is returned. - * @returns @c true if GLX is available, @c false otherwise and if not build with OpenGL support. - **/ - static bool hasGlx(); -}; - -} - -#endif //KWIN_COMPOSITINGPREFS_H - - diff --git a/dbusinterface.cpp b/dbusinterface.cpp index 99dd7762be..302355bd9a 100644 --- a/dbusinterface.cpp +++ b/dbusinterface.cpp @@ -25,10 +25,10 @@ along with this program. If not, see . // kwin #include "atoms.h" #include "composite.h" -#include "compositingprefs.h" #include "debug_console.h" #include "main.h" #include "placement.h" +#include "platform.h" #include "kwinadaptor.h" #include "scene.h" #include "workspace.h" @@ -195,7 +195,7 @@ CompositorDBusInterface::CompositorDBusInterface(Compositor *parent) QString CompositorDBusInterface::compositingNotPossibleReason() const { - return CompositingPrefs::compositingNotPossibleReason(); + return kwinApp()->platform()->compositingNotPossibleReason(); } QString CompositorDBusInterface::compositingType() const @@ -227,12 +227,12 @@ bool CompositorDBusInterface::isActive() const bool CompositorDBusInterface::isCompositingPossible() const { - return CompositingPrefs::compositingPossible(); + return kwinApp()->platform()->compositingPossible(); } bool CompositorDBusInterface::isOpenGLBroken() const { - return CompositingPrefs::openGlIsBroken(); + return kwinApp()->platform()->openGLCompositingIsBroken(); } void CompositorDBusInterface::resume() diff --git a/options.cpp b/options.cpp index 9054cffde6..dbd957fedc 100644 --- a/options.cpp +++ b/options.cpp @@ -29,7 +29,6 @@ along with this program. If not, see . #include -#include "compositingprefs.h" #include "screens.h" #include "settings.h" #include "xcbutils.h" diff --git a/platform.cpp b/platform.cpp index 1273df848e..736e38446d 100644 --- a/platform.cpp +++ b/platform.cpp @@ -286,4 +286,19 @@ bool Platform::requiresCompositing() const return true; } +bool Platform::compositingPossible() const +{ + return true; +} + +QString Platform::compositingNotPossibleReason() const +{ + return QString(); +} + +bool Platform::openGLCompositingIsBroken() const +{ + return false; +} + } diff --git a/platform.h b/platform.h index 036874268e..b865afc866 100644 --- a/platform.h +++ b/platform.h @@ -100,6 +100,30 @@ public: * without compositing (e.g. rendering is done by the windowing system), re-implement this method. **/ virtual bool requiresCompositing() const; + /** + * Whether Compositing is possible in the Platform. + * Returning @c false in this method makes only sense if @link{requiresCompositing} returns @c false. + * + * The default implementation returns @c true. + * @see requiresCompositing + **/ + virtual bool compositingPossible() const; + /** + * Returns a user facing text explaining why compositing is not possible in case + * @link{compositingPossible} returns @c false. + * + * The default implementation returns an empty string. + * @see compositingPossible + **/ + virtual QString compositingNotPossibleReason() const; + /** + * Whether OpenGL compositing is broken. + * The Platform can implement this method if it is able to detect whether OpenGL compositing + * broke (e.g. triggered a crash in a previous run). + * + * Default implementation returns @c false. + **/ + virtual bool openGLCompositingIsBroken() const; bool usesSoftwareCursor() const { return m_softWareCursor; diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp b/plugins/platforms/x11/standalone/x11_platform.cpp index fa090a8865..269842612c 100644 --- a/plugins/platforms/x11/standalone/x11_platform.cpp +++ b/plugins/platforms/x11/standalone/x11_platform.cpp @@ -27,6 +27,10 @@ along with this program. If not, see . #include "screens_xrandr.h" #include "options.h" +#include +#include + +#include #include namespace KWin @@ -79,5 +83,76 @@ bool X11StandalonePlatform::requiresCompositing() const return false; } +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("OpenGL compositing (the default) has crashed KWin in the past.
" + "This was most likely due to a driver bug." + "

If you think that you have meanwhile upgraded to a stable driver,
" + "you can reset this protection but be aware that this might result in an immediate crash!

" + "

Alternatively, you might want to use the XRender backend instead.

"); + + 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()) { + qCDebug(KWIN_CORE) << "No composite extension available"; + return false; + } + if (!Xcb::Extensions::self()->isDamageAvailable()) { + qCDebug(KWIN_CORE) << "No damage extension available"; + 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; + } + qCDebug(KWIN_CORE) << "No OpenGL or XRender/XFixes support"; + return false; +} + +bool X11StandalonePlatform::hasGlx() +{ + return Xcb::Extensions::self()->hasGlx(); +} } diff --git a/plugins/platforms/x11/standalone/x11_platform.h b/plugins/platforms/x11/standalone/x11_platform.h index 949f804cab..dd6c71b6ba 100644 --- a/plugins/platforms/x11/standalone/x11_platform.h +++ b/plugins/platforms/x11/standalone/x11_platform.h @@ -42,6 +42,21 @@ public: OpenGLBackend *createOpenGLBackend() override; Edge *createScreenEdge(ScreenEdges *parent) override; bool requiresCompositing() const override; + bool compositingPossible() const override; + QString compositingNotPossibleReason() const override; + bool openGLCompositingIsBroken() const override; + +private: + /** + * Tests whether GLX is supported and returns @c true + * in case KWin is compiled with OpenGL support and GLX + * is available. + * + * If KWin is compiled with OpenGL ES or without OpenGL at + * all, @c false is returned. + * @returns @c true if GLX is available, @c false otherwise and if not build with OpenGL support. + **/ + static bool hasGlx(); };