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
This commit is contained in:
Martin Gräßlin 2011-07-20 22:10:03 +02:00
parent ff5707c91b
commit c3cf4482a3
6 changed files with 40 additions and 24 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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;

View file

@ -49,9 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef HAVE_XCOMPOSITE
#include <X11/extensions/Xcomposite.h>
#endif
#ifdef HAVE_OPENGL
#include <GL/glx.h>
#endif
#ifdef HAVE_XSYNC
#include <X11/extensions/sync.h>
#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)) {

View file

@ -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 ];

View file

@ -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 ||