From c3cf4482a376a91a98fadb96a486b23db2c8c872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 20 Jul 2011 22:10:03 +0200 Subject: [PATCH] Move GLX detection from kwinglobals to CompositingPrefs Removes the Extension::glxAvailable() from kwinglobals and implements the functionality in CompositingPrefs, where it is only needed. There used to be one additional check in scene_opengl_glx.cpp which is moved into composite.cpp before the OpenGL Scene is created. REVIEW: 102002 --- composite.cpp | 8 ++++++++ compositingprefs.cpp | 26 ++++++++++++++++++++++---- compositingprefs.h | 10 ++++++++++ libkwineffects/kwinglobals.cpp | 12 ------------ libkwineffects/kwinglobals.h | 4 ---- scene_opengl_glx.cpp | 4 ---- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/composite.cpp b/composite.cpp index b309bd9d38..d2c31c0219 100644 --- a/composite.cpp +++ b/composite.cpp @@ -122,6 +122,14 @@ void Workspace::setupCompositing() else { unsafeConfig.writeEntry("OpenGLIsUnsafe", true); unsafeConfig.sync(); +#ifndef KWIN_HAVE_OPENGLES + if (!CompositingPrefs::hasGlx()) { + unsafeConfig.writeEntry("OpenGLIsUnsafe", false); + unsafeConfig.sync(); + kDebug(1212) << "No glx extensions available"; + break; + } +#endif scene = new SceneOpenGL(this); diff --git a/compositingprefs.cpp b/compositingprefs.cpp index 025048e70d..cf3bc1436b 100644 --- a/compositingprefs.cpp +++ b/compositingprefs.cpp @@ -80,7 +80,7 @@ bool CompositingPrefs::compositingPossible() return false; } #ifdef KWIN_HAVE_OPENGL_COMPOSITING - if (Extensions::glxAvailable()) + if (hasGlx()) return true; #endif #ifdef KWIN_HAVE_XRENDER_COMPOSITING @@ -116,14 +116,14 @@ QString CompositingPrefs::compositingNotPossibleReason() return i18n("Required X extensions (XComposite and XDamage) are not available."); } #if defined( KWIN_HAVE_OPENGL_COMPOSITING ) && !defined( KWIN_HAVE_XRENDER_COMPOSITING ) - if (!Extensions::glxAvailable()) + if (!hasGlx()) return i18n("GLX/OpenGL are not available and only OpenGL support is compiled."); #elif !defined( KWIN_HAVE_OPENGL_COMPOSITING ) && defined( KWIN_HAVE_XRENDER_COMPOSITING ) if (!(Extensions::renderAvailable() && Extensions::fixesAvailable())) return i18n("XRender/XFixes extensions are not available and only XRender support" " is compiled."); #else - if (!(Extensions::glxAvailable() + if (!(hasGlx() || (Extensions::renderAvailable() && Extensions::fixesAvailable()))) { return i18n("GLX/OpenGL and XRender/XFixes are not available."); } @@ -135,6 +135,24 @@ QString CompositingPrefs::compositingNotPossibleReason() #endif } +static bool s_glxDetected = false; +static bool s_hasGlx = false; + +bool CompositingPrefs::hasGlx() +{ + if (s_glxDetected) { + return s_hasGlx; + } +#ifdef KWIN_HAVE_OPENGL_COMPOSITING +#ifndef KWIN_HAVE_OPENGLES + int event_base, error_base; + s_hasGlx = glXQueryExtension(display(), &event_base, &error_base); +#endif +#endif + s_glxDetected = true; + return s_hasGlx; +} + void CompositingPrefs::detect() { if (!compositingPossible() || openGlIsBroken()) { @@ -186,7 +204,7 @@ void CompositingPrefs::detect() if (QProcess::execute(opengl_test) != 0) setenv("LIBGL_ALWAYS_INDIRECT", "1", true); } - if (!Extensions::glxAvailable()) { + if (!hasGlx()) { kDebug(1212) << "No GLX available"; gl_workaround_config.writeEntry("OpenGLIsUnsafe", false); gl_workaround_config.sync(); diff --git a/compositingprefs.h b/compositingprefs.h index 4cfc0095ef..3ecb03b5ce 100644 --- a/compositingprefs.h +++ b/compositingprefs.h @@ -40,6 +40,16 @@ public: 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(); bool recommendCompositing() const; bool enableVSync() const { return mEnableVSync; diff --git a/libkwineffects/kwinglobals.cpp b/libkwineffects/kwinglobals.cpp index d126a7cc9a..4b719c34cb 100644 --- a/libkwineffects/kwinglobals.cpp +++ b/libkwineffects/kwinglobals.cpp @@ -49,9 +49,6 @@ along with this program. If not, see . #ifdef HAVE_XCOMPOSITE #include #endif -#ifdef HAVE_OPENGL -#include -#endif #ifdef HAVE_XSYNC #include #endif @@ -68,7 +65,6 @@ int Extensions::damage_event_base = 0; int Extensions::composite_version = 0; int Extensions::fixes_version = 0; int Extensions::render_version = 0; -bool Extensions::has_glx = false; bool Extensions::has_sync = false; int Extensions::sync_event_base = 0; bool Extensions::non_native_pixmaps = false; @@ -145,14 +141,6 @@ void Extensions::init() render_version = major * 0x10 + minor; addData("RENDER"); } -#endif - has_glx = false; -#ifdef HAVE_OPENGL -#ifndef KWIN_HAVE_OPENGLES - has_glx = glXQueryExtension(display(), &event_base, &error_base); - if (has_glx) - addData("GLX"); -#endif #endif #ifdef HAVE_XSYNC if (XSyncQueryExtension(display(), &sync_event_base, &error_base)) { diff --git a/libkwineffects/kwinglobals.h b/libkwineffects/kwinglobals.h index 2a4ea7196d..f34bdba5c5 100644 --- a/libkwineffects/kwinglobals.h +++ b/libkwineffects/kwinglobals.h @@ -165,9 +165,6 @@ public: return fixes_version > 0; } static bool fixesRegionAvailable(); - static bool glxAvailable() { - return has_glx; - } static bool syncAvailable() { return has_sync; } @@ -187,7 +184,6 @@ private: static int composite_version; static int render_version; static int fixes_version; - static bool has_glx; static bool has_sync; static int sync_event_base; static const char* data_extensions[ 32 ]; diff --git a/scene_opengl_glx.cpp b/scene_opengl_glx.cpp index f9358267e2..5eeb5c7406 100644 --- a/scene_opengl_glx.cpp +++ b/scene_opengl_glx.cpp @@ -39,10 +39,6 @@ SceneOpenGL::SceneOpenGL(Workspace* ws) : Scene(ws) , init_ok(false) { - if (!Extensions::glxAvailable()) { - kDebug(1212) << "No glx extensions available"; - return; // error - } initGLX(); // check for FBConfig support if (!hasGLExtension("GLX_SGIX_fbconfig") || !glXGetFBConfigAttrib || !glXGetFBConfigs ||