Hello community,

here is the log from the commit of package kwin5 for openSUSE:Factory checked 
in at 2016-10-28 12:26:56
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/kwin5 (Old)
 and      /work/SRC/openSUSE:Factory/.kwin5.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "kwin5"

Changes:
--------
--- /work/SRC/openSUSE:Factory/kwin5/kwin5.changes      2016-10-22 
13:08:16.000000000 +0200
+++ /work/SRC/openSUSE:Factory/.kwin5.new/kwin5.changes 2016-10-28 
12:26:57.000000000 +0200
@@ -1,0 +2,13 @@
+Mon Oct 24 15:36:48 UTC 2016 - [email protected]
+
+- Add 0001-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch,
+  0002-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch,
+  0003-Remove-most-overhead-caused-by-the-freeze-detection-.patch,
+  0004-Do-a-count-down-of-framesToTestForSafety.patch,
+  0005-Use-only-one-timer-to-detect-freezes-and-other-optim.patch,
+  0006-Test-3-frames-for-freezes-by-default.patch and
+  0007-Only-call-PostLastGuardedFrame-when-OpenGLCompositin.patch
+  to detect freezes caused by broken nouveau opengl drivers and
+  recover from that situation (boo#1003402, boo#1005323)
+
+-------------------------------------------------------------------

New:
----
  0001-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch
  0002-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch
  0003-Remove-most-overhead-caused-by-the-freeze-detection-.patch
  0004-Do-a-count-down-of-framesToTestForSafety.patch
  0005-Use-only-one-timer-to-detect-freezes-and-other-optim.patch
  0006-Test-3-frames-for-freezes-by-default.patch
  0007-Only-call-PostLastGuardedFrame-when-OpenGLCompositin.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ kwin5.spec ++++++
--- /var/tmp/diff_new_pack.99vgpT/_old  2016-10-28 12:26:58.000000000 +0200
+++ /var/tmp/diff_new_pack.99vgpT/_new  2016-10-28 12:26:58.000000000 +0200
@@ -27,6 +27,20 @@
 Group:          System/GUI/KDE
 Url:            http://www.kde.org
 Source:         
http://download.kde.org/stable/plasma/%{version}/kwin-%{version}.tar.xz
+# PATCH-FIX-UPSTREAM 
0001-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch boo#1005323 -- 
Adds a thread to detect kwin freezing and recover from it
+Patch0:         0001-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch
+# PATCH-FIX-UPSTREAM 
0002-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch boo#1005323 -- 
Adds a thread to detect kwin freezing and recover from it
+Patch1:         0002-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch
+# PATCH-FIX-UPSTREAM 
0003-Remove-most-overhead-caused-by-the-freeze-detection-.patch boo#1005323 -- 
Use only one thread for all frames
+Patch2:         0003-Remove-most-overhead-caused-by-the-freeze-detection-.patch
+# PATCH-FIX-UPSTREAM 0004-Do-a-count-down-of-framesToTestForSafety.patch 
boo#1005323 -- Do a countdown instead of counting up
+Patch3:         0004-Do-a-count-down-of-framesToTestForSafety.patch
+# PATCH-FIX-UPSTREAM 
0005-Use-only-one-timer-to-detect-freezes-and-other-optim.patch boo#1005323 -- 
Use only one timer 
+Patch4:         0005-Use-only-one-timer-to-detect-freezes-and-other-optim.patch
+# PATCH-FIX-UPSTREAM 0006-Test-3-frames-for-freezes-by-default.patch 
boo#1005323 -- Test only 3 frames by default, which is enough to detect freezes
+Patch5:         0006-Test-3-frames-for-freezes-by-default.patch
+# PATCH-FIX-UPSTREAM 
0007-Only-call-PostLastGuardedFrame-when-OpenGLCompositin.patch boo#1005323 -- 
Only call PostLastGuardedFrame when OpenGLCompositing is set
+Patch6:         0007-Only-call-PostLastGuardedFrame-when-OpenGLCompositin.patch
 BuildRequires:  extra-cmake-modules >= 0.0.11
 BuildRequires:  fdupes
 BuildRequires:  kf5-filesystem
@@ -137,6 +151,13 @@
 
 %prep
 %setup -q -n kwin-%{version}
+%patch0 -p1
+%patch1 -p1
+%patch2 -p1
+%patch3 -p1
+%patch4 -p1
+%patch5 -p1
+%patch6 -p1
 
 %build
   %cmake_kf5 -d build -- -DCMAKE_INSTALL_LOCALEDIR=%{_kf5_localedir}

++++++ 0001-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch ++++++
>From 572b7b40205f3cf31b43250ad31497ee90133590 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= <[email protected]>
Date: Fri, 21 Oct 2016 14:21:29 +0200
Subject: [PATCH 1/4] [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.

Reviewers: #kwin, davidedmundson, #plasma

Reviewed By: davidedmundson, #plasma

Subscribers: davidedmundson, plasma-devel, kwin

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D3127
---
 composite.cpp                                     | 11 ++++++++++-
 composite.h                                       |  1 +
 platform.h                                        |  4 +++-
 plugins/platforms/x11/standalone/x11_platform.cpp | 22 ++++++++++++++++++++++
 plugins/platforms/x11/standalone/x11_platform.h   |  2 ++
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/composite.cpp b/composite.cpp
index 7290440..c3ae50e 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -207,7 +207,6 @@ void Compositor::slotCompositingOptionsInitialized()
 
             m_scene = SceneOpenGL::createScene(this);
 
-            // TODO: Add 30 second delay to protect against screen freezes as 
well
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostInit);
 
             if (m_scene && !m_scene->initFailed()) {
@@ -294,6 +293,7 @@ void Compositor::startupWithWorkspace()
         return;
     }
     Q_ASSERT(m_scene);
+    m_firstFrame = true;
     connect(workspace(), &Workspace::destroyed, this, [this] { 
compositeTimer.stop(); });
     claimCompositorSelection();
     m_xrrRefreshRate = KWin::currentRefreshRate();
@@ -734,7 +734,16 @@ void Compositor::performCompositing()
     // clear all repaints, so that post-pass can add repaints for the next 
repaint
     repaints_region = QRegion();
 
+    if (m_firstFrame && (m_scene->compositingType() & OpenGLCompositing)) {
+        
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFirstFrame);
+    }
     m_timeSinceLastVBlank = m_scene->paint(repaints, windows);
+    if (m_firstFrame) {
+        if (m_scene->compositingType() & OpenGLCompositing) {
+            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFirstFrame);
+        }
+        m_firstFrame = false;
+    }
     m_timeSinceStart += m_timeSinceLastVBlank;
 
     if (waylandServer()) {
diff --git a/composite.h b/composite.h
index a1690e2..5412628 100644
--- a/composite.h
+++ b/composite.h
@@ -239,6 +239,7 @@ private:
     Scene *m_scene;
     bool m_bufferSwapPending;
     bool m_composeAtSwapCompletion;
+    bool m_firstFrame = true;
 
     KWIN_SINGLETON_VARIABLE(Compositor, s_compositor)
 };
diff --git a/platform.h b/platform.h
index 3991f5f..f1b8688 100644
--- a/platform.h
+++ b/platform.h
@@ -142,7 +142,9 @@ public:
     virtual bool openGLCompositingIsBroken() const;
     enum class OpenGLSafePoint {
         PreInit,
-        PostInit
+        PostInit,
+        PreFirstFrame,
+        PostFirstFrame
     };
     /**
      * This method is invoked before and after creating the OpenGL rendering 
Scene.
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp 
b/plugins/platforms/x11/standalone/x11_platform.cpp
index 8212d1e..1cd73a5 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -37,6 +37,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <KConfigGroup>
 #include <KLocalizedString>
 
+#include <QThread>
 #include <QOpenGLContext>
 #include <QX11Info>
 
@@ -199,9 +200,30 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
     auto group = KConfigGroup(kwinApp()->config(), "Compositing");
     switch (safePoint) {
     case OpenGLSafePoint::PreInit:
+    case OpenGLSafePoint::PreFirstFrame:
+        Q_ASSERT(m_openGLFreezeProtectionThread == nullptr);
+        m_openGLFreezeProtectionThread = new QThread(this);
+        m_openGLFreezeProtectionThread->start();
+        m_openGLFreezeProtection = new QTimer;
+        m_openGLFreezeProtection->setInterval(15000);
+        m_openGLFreezeProtection->setSingleShot(true);
+        m_openGLFreezeProtection->start();
+        m_openGLFreezeProtection->moveToThread(m_openGLFreezeProtectionThread);
+        connect(m_openGLFreezeProtection, &QTimer::timeout, 
m_openGLFreezeProtection,
+            [] {
+                qFatal("Freeze in OpenGL initialization detected");
+            }, Qt::DirectConnection);
+
         group.writeEntry(unsafeKey, true);
         break;
     case OpenGLSafePoint::PostInit:
+    case OpenGLSafePoint::PostFirstFrame:
+        m_openGLFreezeProtection->deleteLater();
+        m_openGLFreezeProtectionThread->quit();
+        m_openGLFreezeProtectionThread->wait();
+        delete m_openGLFreezeProtectionThread;
+        m_openGLFreezeProtectionThread = nullptr;
+        m_openGLFreezeProtection = nullptr;
         group.writeEntry(unsafeKey, false);
         break;
     }
diff --git a/plugins/platforms/x11/standalone/x11_platform.h 
b/plugins/platforms/x11/standalone/x11_platform.h
index e3a670e..b90b759 100644
--- a/plugins/platforms/x11/standalone/x11_platform.h
+++ b/plugins/platforms/x11/standalone/x11_platform.h
@@ -62,6 +62,8 @@ private:
     static bool hasGlx();
 
     XInputIntegration *m_xinputIntegration = nullptr;
+    QThread *m_openGLFreezeProtectionThread = nullptr;
+    QTimer *m_openGLFreezeProtection = nullptr;
 
 };
 
-- 
2.10.1

++++++ 0002-platformx-x11-Add-a-freeze-protection-against-OpenGL.patch ++++++
>From ee42322059cd772c38f9cbd33be69ae6316ccbce Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <[email protected]>
Date: Fri, 21 Oct 2016 21:06:47 +0200
Subject: [PATCH 2/4] [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: #kwin, #plasma, davidedmundson

Subscribers: kwin, plasma-devel, davidedmundson

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D3132
---
 composite.cpp                                     | 14 ++++++++------
 composite.h                                       |  3 ++-
 platform.h                                        |  4 ++--
 plugins/platforms/x11/standalone/x11_platform.cpp |  4 ++--
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/composite.cpp b/composite.cpp
index c3ae50e..a425a5f 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -135,6 +135,9 @@ Compositor::Compositor(QObject* workspace)
         }
     );
 
+    if (qEnvironmentVariableIsSet("KWIN_MAX_FRAMES_TESTED"))
+       m_maxFramesTestedForSafety = 
qEnvironmentVariableIntValue("KWIN_MAX_FRAMES_TESTED");
+
     // register DBus
     new CompositorDBusInterface(this);
 }
@@ -293,7 +296,6 @@ void Compositor::startupWithWorkspace()
         return;
     }
     Q_ASSERT(m_scene);
-    m_firstFrame = true;
     connect(workspace(), &Workspace::destroyed, this, [this] { 
compositeTimer.stop(); });
     claimCompositorSelection();
     m_xrrRefreshRate = KWin::currentRefreshRate();
@@ -734,15 +736,15 @@ void Compositor::performCompositing()
     // clear all repaints, so that post-pass can add repaints for the next 
repaint
     repaints_region = QRegion();
 
-    if (m_firstFrame && (m_scene->compositingType() & OpenGLCompositing)) {
-        
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFirstFrame);
+    if (m_frameCount < m_maxFramesTestedForSafety && 
(m_scene->compositingType() & OpenGLCompositing)) {
+        
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFrame);
     }
     m_timeSinceLastVBlank = m_scene->paint(repaints, windows);
-    if (m_firstFrame) {
+    if (m_frameCount < m_maxFramesTestedForSafety) {
         if (m_scene->compositingType() & OpenGLCompositing) {
-            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFirstFrame);
+            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFrame);
         }
-        m_firstFrame = false;
+        m_frameCount++;
     }
     m_timeSinceStart += m_timeSinceLastVBlank;
 
diff --git a/composite.h b/composite.h
index 5412628..c6effe0 100644
--- a/composite.h
+++ b/composite.h
@@ -239,7 +239,8 @@ private:
     Scene *m_scene;
     bool m_bufferSwapPending;
     bool m_composeAtSwapCompletion;
-    bool m_firstFrame = true;
+    int m_frameCount = 0;
+    int m_maxFramesTestedForSafety = 30;
 
     KWIN_SINGLETON_VARIABLE(Compositor, s_compositor)
 };
diff --git a/platform.h b/platform.h
index f1b8688..727ef70 100644
--- a/platform.h
+++ b/platform.h
@@ -143,8 +143,8 @@ public:
     enum class OpenGLSafePoint {
         PreInit,
         PostInit,
-        PreFirstFrame,
-        PostFirstFrame
+        PreFrame,
+        PostFrame
     };
     /**
      * This method is invoked before and after creating the OpenGL rendering 
Scene.
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp 
b/plugins/platforms/x11/standalone/x11_platform.cpp
index 1cd73a5..12c0395 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -200,7 +200,7 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
     auto group = KConfigGroup(kwinApp()->config(), "Compositing");
     switch (safePoint) {
     case OpenGLSafePoint::PreInit:
-    case OpenGLSafePoint::PreFirstFrame:
+    case OpenGLSafePoint::PreFrame:
         Q_ASSERT(m_openGLFreezeProtectionThread == nullptr);
         m_openGLFreezeProtectionThread = new QThread(this);
         m_openGLFreezeProtectionThread->start();
@@ -217,7 +217,7 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
         group.writeEntry(unsafeKey, true);
         break;
     case OpenGLSafePoint::PostInit:
-    case OpenGLSafePoint::PostFirstFrame:
+    case OpenGLSafePoint::PostFrame:
         m_openGLFreezeProtection->deleteLater();
         m_openGLFreezeProtectionThread->quit();
         m_openGLFreezeProtectionThread->wait();
-- 
2.10.1

++++++ 0003-Remove-most-overhead-caused-by-the-freeze-detection-.patch ++++++
>From 14d993610e36418baa42436dc9606d9217cba590 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <[email protected]>
Date: Sun, 23 Oct 2016 12:19:38 +0200
Subject: [PATCH 3/4] Remove most overhead caused by the freeze-detection
 thread

I separated (Pre/Post)Init and (Pre/Post)Frame code in x11_platform
so now *Init "detects" crashes and *Frame detects freezes.

Also, now Pre/PostFrame can be called many times in a row since
PostFrame doesn't remove the thread but just deletes the timer
and PreFrame reuses the thread if it was already created.

I added OpenGLSafePoint::PostLastFrame which is called after the last
PostFrame safe point, and really removes the thread (also will delete
the timer if it wasn't deleted earlier)

Also, for freeze detection there's no need to write
OpenGLIsUnsafe=true in PreFrame and correct it in PostFrame since
kwin doesn't crash and I guess it's not nice to write twice to the
config file in every frame, even if it's just the first n frames and
the operating system will probably cache those writes. So I moved the
code to only set OpenGLIsUnsafe=true when a freeze is detected.
---
 composite.cpp                                     |  5 ++++
 platform.h                                        |  3 ++-
 plugins/platforms/x11/standalone/x11_platform.cpp | 30 +++++++++++++++++------
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/composite.cpp b/composite.cpp
index a425a5f..37cd54d 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -207,9 +207,11 @@ void Compositor::slotCompositingOptionsInitialized()
             qCWarning(KWIN_CORE) << "KWin has detected that your OpenGL 
library is unsafe to use";
         else {
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreInit);
+            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFrame);
 
             m_scene = SceneOpenGL::createScene(this);
 
+            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastFrame);
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostInit);
 
             if (m_scene && !m_scene->initFailed()) {
@@ -745,6 +747,9 @@ void Compositor::performCompositing()
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFrame);
         }
         m_frameCount++;
+       if (m_frameCount >= m_maxFramesTestedForSafety) {
+            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastFrame);
+        }
     }
     m_timeSinceStart += m_timeSinceLastVBlank;
 
diff --git a/platform.h b/platform.h
index 727ef70..83e41bb 100644
--- a/platform.h
+++ b/platform.h
@@ -144,7 +144,8 @@ public:
         PreInit,
         PostInit,
         PreFrame,
-        PostFrame
+        PostFrame,
+        PostLastFrame
     };
     /**
      * This method is invoked before and after creating the OpenGL rendering 
Scene.
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp 
b/plugins/platforms/x11/standalone/x11_platform.cpp
index 12c0395..39652c2 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -200,10 +200,18 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
     auto group = KConfigGroup(kwinApp()->config(), "Compositing");
     switch (safePoint) {
     case OpenGLSafePoint::PreInit:
+        group.writeEntry(unsafeKey, true);
+        break;
+    case OpenGLSafePoint::PostInit:
+        group.writeEntry(unsafeKey, false);
+        break;
     case OpenGLSafePoint::PreFrame:
-        Q_ASSERT(m_openGLFreezeProtectionThread == nullptr);
-        m_openGLFreezeProtectionThread = new QThread(this);
-        m_openGLFreezeProtectionThread->start();
+        if (m_openGLFreezeProtectionThread == nullptr) {
+            m_openGLFreezeProtectionThread = new QThread(this);
+            m_openGLFreezeProtectionThread->setObjectName("FreezeDetector");
+            m_openGLFreezeProtectionThread->start();
+       }
+        Q_ASSERT(m_openGLFreezeProtection == nullptr);
         m_openGLFreezeProtection = new QTimer;
         m_openGLFreezeProtection->setInterval(15000);
         m_openGLFreezeProtection->setSingleShot(true);
@@ -211,20 +219,26 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
         m_openGLFreezeProtection->moveToThread(m_openGLFreezeProtectionThread);
         connect(m_openGLFreezeProtection, &QTimer::timeout, 
m_openGLFreezeProtection,
             [] {
+                const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + 
(kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : 
QString()));
+                auto group = KConfigGroup(kwinApp()->config(), "Compositing");
+                group.writeEntry(unsafeKey, true);
+                group.sync();
                 qFatal("Freeze in OpenGL initialization detected");
             }, Qt::DirectConnection);
-
-        group.writeEntry(unsafeKey, true);
         break;
-    case OpenGLSafePoint::PostInit:
     case OpenGLSafePoint::PostFrame:
         m_openGLFreezeProtection->deleteLater();
+        m_openGLFreezeProtection = nullptr;
+        break;
+    case OpenGLSafePoint::PostLastFrame:
+        if (m_openGLFreezeProtection) {
+            m_openGLFreezeProtection->deleteLater();
+            m_openGLFreezeProtection = nullptr;
+        };
         m_openGLFreezeProtectionThread->quit();
         m_openGLFreezeProtectionThread->wait();
         delete m_openGLFreezeProtectionThread;
         m_openGLFreezeProtectionThread = nullptr;
-        m_openGLFreezeProtection = nullptr;
-        group.writeEntry(unsafeKey, false);
         break;
     }
     group.sync();
-- 
2.10.1

++++++ 0004-Do-a-count-down-of-framesToTestForSafety.patch ++++++
>From 8e49998eb3677cf0b25bf652ba13ab86bf18b9bc Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <[email protected]>
Date: Mon, 24 Oct 2016 09:39:55 +0200
Subject: [PATCH 4/4] Do a count down of framesToTestForSafety

Use one variable instead of two and do a count down from
m_framesToTestForSafety to 0
---
 composite.cpp | 10 +++++-----
 composite.h   |  3 +--
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/composite.cpp b/composite.cpp
index 37cd54d..0abf531 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -136,7 +136,7 @@ Compositor::Compositor(QObject* workspace)
     );
 
     if (qEnvironmentVariableIsSet("KWIN_MAX_FRAMES_TESTED"))
-       m_maxFramesTestedForSafety = 
qEnvironmentVariableIntValue("KWIN_MAX_FRAMES_TESTED");
+       m_framesToTestForSafety = 
qEnvironmentVariableIntValue("KWIN_MAX_FRAMES_TESTED");
 
     // register DBus
     new CompositorDBusInterface(this);
@@ -738,16 +738,16 @@ void Compositor::performCompositing()
     // clear all repaints, so that post-pass can add repaints for the next 
repaint
     repaints_region = QRegion();
 
-    if (m_frameCount < m_maxFramesTestedForSafety && 
(m_scene->compositingType() & OpenGLCompositing)) {
+    if (m_framesToTestForSafety > 0 && (m_scene->compositingType() & 
OpenGLCompositing)) {
         
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFrame);
     }
     m_timeSinceLastVBlank = m_scene->paint(repaints, windows);
-    if (m_frameCount < m_maxFramesTestedForSafety) {
+    if (m_framesToTestForSafety > 0) {
         if (m_scene->compositingType() & OpenGLCompositing) {
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFrame);
         }
-        m_frameCount++;
-       if (m_frameCount >= m_maxFramesTestedForSafety) {
+        m_framesToTestForSafety--;
+       if (m_framesToTestForSafety == 0) {
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastFrame);
         }
     }
diff --git a/composite.h b/composite.h
index c6effe0..c439148 100644
--- a/composite.h
+++ b/composite.h
@@ -239,8 +239,7 @@ private:
     Scene *m_scene;
     bool m_bufferSwapPending;
     bool m_composeAtSwapCompletion;
-    int m_frameCount = 0;
-    int m_maxFramesTestedForSafety = 30;
+    int m_framesToTestForSafety = 30;
 
     KWIN_SINGLETON_VARIABLE(Compositor, s_compositor)
 };
-- 
2.10.1

++++++ 0005-Use-only-one-timer-to-detect-freezes-and-other-optim.patch ++++++
>From 8f5dbeba06ce05d6474f369a95a1a9d1f814a06f Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <[email protected]>
Date: Mon, 24 Oct 2016 16:45:04 +0200
Subject: [PATCH 5/7] Use only one timer to detect freezes and other
 optimizations

stop/restart the same timer instead of creating a new one for each frame
tested for freezes. Merged PreInit with PreFrame and PostInit with
PostFrame so there's no need to call both before/after init, which
didn't make sense contextually. Also moved group.sync() so
PreFrame/PostFrame don't call it continuously. Finally, also renamed
PostLastFrame to PostLastGuardedFrame
---
 composite.cpp                                     |  4 +-
 platform.h                                        |  2 +-
 plugins/platforms/x11/standalone/x11_platform.cpp | 55 ++++++++++++-----------
 3 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/composite.cpp b/composite.cpp
index 0abf531..573e7a6 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -207,11 +207,9 @@ void Compositor::slotCompositingOptionsInitialized()
             qCWarning(KWIN_CORE) << "KWin has detected that your OpenGL 
library is unsafe to use";
         else {
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreInit);
-            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreFrame);
 
             m_scene = SceneOpenGL::createScene(this);
 
-            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastFrame);
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostInit);
 
             if (m_scene && !m_scene->initFailed()) {
@@ -748,7 +746,7 @@ void Compositor::performCompositing()
         }
         m_framesToTestForSafety--;
        if (m_framesToTestForSafety == 0) {
-            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastFrame);
+            
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastGuardedFrame);
         }
     }
     m_timeSinceStart += m_timeSinceLastVBlank;
diff --git a/platform.h b/platform.h
index 83e41bb..de0b3bf 100644
--- a/platform.h
+++ b/platform.h
@@ -145,7 +145,7 @@ public:
         PostInit,
         PreFrame,
         PostFrame,
-        PostLastFrame
+        PostLastGuardedFrame
     };
     /**
      * This method is invoked before and after creating the OpenGL rendering 
Scene.
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp 
b/plugins/platforms/x11/standalone/x11_platform.cpp
index 39652c2..88b37ea 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -201,47 +201,50 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
     switch (safePoint) {
     case OpenGLSafePoint::PreInit:
         group.writeEntry(unsafeKey, true);
-        break;
-    case OpenGLSafePoint::PostInit:
-        group.writeEntry(unsafeKey, false);
-        break;
+        group.sync();
+        // Deliberately continue with PreFrame
     case OpenGLSafePoint::PreFrame:
         if (m_openGLFreezeProtectionThread == nullptr) {
+            Q_ASSERT(m_openGLFreezeProtection == nullptr);
             m_openGLFreezeProtectionThread = new QThread(this);
             m_openGLFreezeProtectionThread->setObjectName("FreezeDetector");
             m_openGLFreezeProtectionThread->start();
-       }
-        Q_ASSERT(m_openGLFreezeProtection == nullptr);
-        m_openGLFreezeProtection = new QTimer;
-        m_openGLFreezeProtection->setInterval(15000);
-        m_openGLFreezeProtection->setSingleShot(true);
-        m_openGLFreezeProtection->start();
-        m_openGLFreezeProtection->moveToThread(m_openGLFreezeProtectionThread);
-        connect(m_openGLFreezeProtection, &QTimer::timeout, 
m_openGLFreezeProtection,
-            [] {
-                const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + 
(kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : 
QString()));
-                auto group = KConfigGroup(kwinApp()->config(), "Compositing");
-                group.writeEntry(unsafeKey, true);
-                group.sync();
-                qFatal("Freeze in OpenGL initialization detected");
-            }, Qt::DirectConnection);
+            m_openGLFreezeProtection = new QTimer;
+            m_openGLFreezeProtection->setInterval(15000);
+            m_openGLFreezeProtection->setSingleShot(true);
+            m_openGLFreezeProtection->start();
+            
m_openGLFreezeProtection->moveToThread(m_openGLFreezeProtectionThread);
+            connect(m_openGLFreezeProtection, &QTimer::timeout, 
m_openGLFreezeProtection,
+                [] {
+                    const QString unsafeKey(QLatin1String("OpenGLIsUnsafe") + 
(kwinApp()->isX11MultiHead() ? QString::number(kwinApp()->x11ScreenNumber()) : 
QString()));
+                    auto group = KConfigGroup(kwinApp()->config(), 
"Compositing");
+                    group.writeEntry(unsafeKey, true);
+                    group.sync();
+                    qFatal("Freeze in OpenGL initialization detected");
+                }, Qt::DirectConnection);
+        }
+        else
+        {
+            Q_ASSERT(m_openGLFreezeProtection);
+            QMetaObject::invokeMethod(m_openGLFreezeProtection, "start", 
Qt::QueuedConnection);
+        }
         break;
+    case OpenGLSafePoint::PostInit:
+        group.writeEntry(unsafeKey, false);
+        group.sync();
+        // Deliberately continue with PostFrame
     case OpenGLSafePoint::PostFrame:
+        QMetaObject::invokeMethod(m_openGLFreezeProtection, "stop", 
Qt::QueuedConnection);
+        break;
+    case OpenGLSafePoint::PostLastGuardedFrame:
         m_openGLFreezeProtection->deleteLater();
         m_openGLFreezeProtection = nullptr;
-        break;
-    case OpenGLSafePoint::PostLastFrame:
-        if (m_openGLFreezeProtection) {
-            m_openGLFreezeProtection->deleteLater();
-            m_openGLFreezeProtection = nullptr;
-        };
         m_openGLFreezeProtectionThread->quit();
         m_openGLFreezeProtectionThread->wait();
         delete m_openGLFreezeProtectionThread;
         m_openGLFreezeProtectionThread = nullptr;
         break;
     }
-    group.sync();
 }
 
 }
-- 
2.10.1

++++++ 0006-Test-3-frames-for-freezes-by-default.patch ++++++
>From 550184274e79a832a8179b349b9b139066b5b946 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <[email protected]>
Date: Mon, 24 Oct 2016 16:47:50 +0200
Subject: [PATCH 6/7] Test 3 frames for freezes by default

I tested on a system with nouveau and testing for 3 frames seems to be
enough to detect the freeze. Note that this can be changed with
the environment variable KWIN_MAX_FRAMES_TESTED
---
 composite.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/composite.h b/composite.h
index c439148..a7aee56 100644
--- a/composite.h
+++ b/composite.h
@@ -239,7 +239,7 @@ private:
     Scene *m_scene;
     bool m_bufferSwapPending;
     bool m_composeAtSwapCompletion;
-    int m_framesToTestForSafety = 30;
+    int m_framesToTestForSafety = 3;
 
     KWIN_SINGLETON_VARIABLE(Compositor, s_compositor)
 };
-- 
2.10.1

++++++ 0007-Only-call-PostLastGuardedFrame-when-OpenGLCompositin.patch ++++++
>From 9b51560ca83bd9790c633f3a90019b88c45d8fe0 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <[email protected]>
Date: Mon, 24 Oct 2016 17:14:32 +0200
Subject: [PATCH 7/7] Only call PostLastGuardedFrame when OpenGLCompositing is
 set

And a small coding style change in bracets
---
 composite.cpp                                     | 4 ++--
 plugins/platforms/x11/standalone/x11_platform.cpp | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/composite.cpp b/composite.cpp
index 573e7a6..41b948e 100644
--- a/composite.cpp
+++ b/composite.cpp
@@ -745,9 +745,9 @@ void Compositor::performCompositing()
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostFrame);
         }
         m_framesToTestForSafety--;
-       if (m_framesToTestForSafety == 0) {
+        if (m_framesToTestForSafety == 0 && (m_scene->compositingType() & 
OpenGLCompositing)) {
             
kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostLastGuardedFrame);
-        }
+        }
     }
     m_timeSinceStart += m_timeSinceLastVBlank;
 
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp 
b/plugins/platforms/x11/standalone/x11_platform.cpp
index 88b37ea..05bdd39 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -222,9 +222,7 @@ void 
X11StandalonePlatform::createOpenGLSafePoint(OpenGLSafePoint safePoint)
                     group.sync();
                     qFatal("Freeze in OpenGL initialization detected");
                 }, Qt::DirectConnection);
-        }
-        else
-        {
+        } else {
             Q_ASSERT(m_openGLFreezeProtection);
             QMetaObject::invokeMethod(m_openGLFreezeProtection, "start", 
Qt::QueuedConnection);
         }
-- 
2.10.1


Reply via email to