[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: Provide functionality of CompositingPrefs through Platform
From:       Martin_Gräßlin <mgraesslin () kde ! org>
Date:       2016-05-17 12:02:46
Message-ID: E1b2di2-00017S-OK () scm ! kde ! org
[Download RAW message or body]

Git commit d15d3a5ff12ca6a6e66ee8e087fd7a795ce3c25f by Martin Gräßlin.
Committed on 17/05/2016 at 11:59.
Pushed by graesslin into branch 'master'.

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

M  +0    -1    CMakeLists.txt
M  +2    -3    composite.cpp
D  +0    -129  compositingprefs.cpp
D  +0    -59   compositingprefs.h
M  +4    -4    dbusinterface.cpp
M  +0    -1    options.cpp
M  +15   -0    platform.cpp
M  +24   -0    platform.h
M  +75   -0    plugins/platforms/x11/standalone/x11_platform.cpp
M  +15   -0    plugins/platforms/x11/standalone/x11_platform.h

http://commits.kde.org/kwin/d15d3a5ff12ca6a6e66ee8e087fd7a795ce3c25f

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d963258..4d2c469 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 7b0a166..7716363 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -35,7 +35,6 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #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 ab7d16f..0000000
--- 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 <rivolaks@hot.ee>
-
-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 <http://www.gnu.org/licenses/>.
-*********************************************************************/
-
-#include "compositingprefs.h"
-
-#include "main.h"
-#include "xcbutils.h"
-#include "kwinglplatform.h"
-#include "utils.h"
-
-#include <kconfiggroup.h>
-#include <KLocalizedString>
-#include <ksharedconfig.h>
-
-#include <QDebug>
-#include <QOpenGLContext>
-#include <QStandardPaths>
-#include <qprocess.h>
-
-
-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("<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 CompositingPrefs::hasGlx()
-{
-    return Xcb::Extensions::self()->hasGlx();
-}
-
-} // namespace
-
diff --git a/compositingprefs.h b/compositingprefs.h
deleted file mode 100644
index 889ed8b..0000000
--- 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 <rivolaks@hot.ee>
-
-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 <http://www.gnu.org/licenses/>.
-*********************************************************************/
-
-#ifndef KWIN_COMPOSITINGPREFS_H
-#define KWIN_COMPOSITINGPREFS_H
-
-#include <QString>
-#include <QStringList>
-
-#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 99dd776..302355b 100644
--- a/dbusinterface.cpp
+++ b/dbusinterface.cpp
@@ -25,10 +25,10 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  // 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 9054cff..dbd957f 100644
--- a/options.cpp
+++ b/options.cpp
@@ -29,7 +29,6 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  
 #include <QProcess>
 
-#include "compositingprefs.h"
 #include "screens.h"
 #include "settings.h"
 #include "xcbutils.h"
diff --git a/platform.cpp b/platform.cpp
index 1273df8..736e384 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 0368742..b865afc 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 fa090a8..2698426 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 \
<http://www.gnu.org/licenses/>.  #include "screens_xrandr.h"
 #include "options.h"
 
+#include <KConfigGroup>
+#include <KLocalizedString>
+
+#include <QOpenGLContext>
 #include <QX11Info>
 
 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("<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()) {
+        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 949f804..dd6c71b 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();
 
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic