diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,7 +388,6 @@ deleted.cpp effects.cpp effectloader.cpp - compositingprefs.cpp virtualdesktops.cpp xcbutils.cpp x11eventfilter.cpp diff --git a/composite.cpp b/composite.cpp --- a/composite.cpp +++ b/composite.cpp @@ -35,7 +35,6 @@ #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 @@ } 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 @@ 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.h b/compositingprefs.h deleted file mode 100644 --- 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/compositingprefs.cpp b/compositingprefs.cpp deleted file mode 100644 --- 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/dbusinterface.cpp b/dbusinterface.cpp --- a/dbusinterface.cpp +++ b/dbusinterface.cpp @@ -25,10 +25,10 @@ // 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 @@ QString CompositorDBusInterface::compositingNotPossibleReason() const { - return CompositingPrefs::compositingNotPossibleReason(); + return kwinApp()->platform()->compositingNotPossibleReason(); } QString CompositorDBusInterface::compositingType() const @@ -227,12 +227,12 @@ 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 --- a/options.cpp +++ b/options.cpp @@ -29,7 +29,6 @@ #include -#include "compositingprefs.h" #include "screens.h" #include "settings.h" #include "xcbutils.h" diff --git a/platform.h b/platform.h --- a/platform.h +++ b/platform.h @@ -100,6 +100,30 @@ * 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/platform.cpp b/platform.cpp --- a/platform.cpp +++ b/platform.cpp @@ -286,4 +286,19 @@ return true; } +bool Platform::compositingPossible() const +{ + return true; +} + +QString Platform::compositingNotPossibleReason() const +{ + return QString(); +} + +bool Platform::openGLCompositingIsBroken() const +{ + return false; +} + } diff --git a/plugins/platforms/x11/standalone/x11_platform.h b/plugins/platforms/x11/standalone/x11_platform.h --- a/plugins/platforms/x11/standalone/x11_platform.h +++ b/plugins/platforms/x11/standalone/x11_platform.h @@ -42,6 +42,21 @@ 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(); }; diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp b/plugins/platforms/x11/standalone/x11_platform.cpp --- a/plugins/platforms/x11/standalone/x11_platform.cpp +++ b/plugins/platforms/x11/standalone/x11_platform.cpp @@ -27,6 +27,10 @@ #include "screens_xrandr.h" #include "options.h" +#include +#include + +#include #include namespace KWin @@ -79,5 +83,76 @@ 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(); +} }