diff --git a/composite.cpp b/composite.cpp index a5b036bb66..b867be5d79 100644 --- a/composite.cpp +++ b/composite.cpp @@ -202,20 +202,15 @@ void Compositor::slotCompositingOptionsInitialized() qCDebug(KWIN_CORE) << "Initializing OpenGL compositing"; // Some broken drivers crash on glXQuery() so to prevent constant KWin crashes: - KSharedConfigPtr unsafeConfigPtr = kwinApp()->config(); - KConfigGroup unsafeConfig(unsafeConfigPtr, "Compositing"); - const QString openGLIsUnsafe = QLatin1String("OpenGLIsUnsafe") + (is_multihead ? QString::number(screen_number) : QString()); - if (unsafeConfig.readEntry(openGLIsUnsafe, false)) + if (kwinApp()->platform()->openGLCompositingIsBroken()) qCWarning(KWIN_CORE) << "KWin has detected that your OpenGL library is unsafe to use"; else { - unsafeConfig.writeEntry(openGLIsUnsafe, true); - unsafeConfig.sync(); + kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PreInit); m_scene = SceneOpenGL::createScene(this); // TODO: Add 30 second delay to protect against screen freezes as well - unsafeConfig.writeEntry(openGLIsUnsafe, false); - unsafeConfig.sync(); + kwinApp()->platform()->createOpenGLSafePoint(Platform::OpenGLSafePoint::PostInit); if (m_scene && !m_scene->initFailed()) { connect(static_cast<SceneOpenGL*>(m_scene), &SceneOpenGL::resetCompositing, this, &Compositor::restart); diff --git a/platform.cpp b/platform.cpp index 736e38446d..83d444f80c 100644 --- a/platform.cpp +++ b/platform.cpp @@ -301,4 +301,9 @@ bool Platform::openGLCompositingIsBroken() const return false; } +void Platform::createOpenGLSafePoint(OpenGLSafePoint safePoint) +{ + Q_UNUSED(safePoint) +} + } diff --git a/platform.h b/platform.h index b865afc866..9254d38932 100644 --- a/platform.h +++ b/platform.h @@ -122,8 +122,22 @@ public: * broke (e.g. triggered a crash in a previous run). * * Default implementation returns @c false. + * @see createOpenGLSafePoint **/ virtual bool openGLCompositingIsBroken() const; + enum class OpenGLSafePoint { + PreInit, + PostInit + }; + /** + * This method is invoked before and after creating the OpenGL rendering Scene. + * An implementing Platform can use it to detect crashes triggered by the OpenGL implementation. + * This can be used for @link{openGLCompositingIsBroken}. + * + * The default implementation does nothing. + * @see openGLCompositingIsBroken. + **/ + virtual void createOpenGLSafePoint(OpenGLSafePoint safePoint); 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 2e0195fc24..d0cf7ddac2 100644 --- a/plugins/platforms/x11/standalone/x11_platform.cpp +++ b/plugins/platforms/x11/standalone/x11_platform.cpp @@ -161,4 +161,19 @@ bool X11StandalonePlatform::hasGlx() return Xcb::Extensions::self()->hasGlx(); } +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); + break; + case OpenGLSafePoint::PostInit: + group.writeEntry(unsafeKey, false); + break; + } + group.sync(); +} + } diff --git a/plugins/platforms/x11/standalone/x11_platform.h b/plugins/platforms/x11/standalone/x11_platform.h index dd6c71b6ba..c0caa7b99f 100644 --- a/plugins/platforms/x11/standalone/x11_platform.h +++ b/plugins/platforms/x11/standalone/x11_platform.h @@ -45,6 +45,7 @@ public: bool compositingPossible() const override; QString compositingNotPossibleReason() const override; bool openGLCompositingIsBroken() const override; + void createOpenGLSafePoint(OpenGLSafePoint safePoint) override; private: /**