2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-09-18 13:59:06 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2007-09-18 13:59:06 +00:00
|
|
|
|
|
|
|
#include "compositingprefs.h"
|
|
|
|
|
2012-12-21 14:11:31 +00:00
|
|
|
#include "xcbutils.h"
|
2010-12-03 21:13:43 +00:00
|
|
|
#include "kwinglplatform.h"
|
2007-09-18 13:59:06 +00:00
|
|
|
|
2011-04-03 19:59:57 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-09-18 13:59:06 +00:00
|
|
|
#include <kdebug.h>
|
2013-03-07 12:28:39 +00:00
|
|
|
#include <KDE/KGlobal>
|
2013-03-07 11:55:39 +00:00
|
|
|
#include <KDE/KLocalizedString>
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kdeversion.h>
|
2011-04-03 19:59:57 +00:00
|
|
|
#include <ksharedconfig.h>
|
2010-02-26 20:47:00 +00:00
|
|
|
#include <kstandarddirs.h>
|
|
|
|
|
|
|
|
#include <qprocess.h>
|
2007-09-18 13:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2013-05-24 12:50:17 +00:00
|
|
|
extern int screen_number; // main.cpp
|
|
|
|
extern bool is_multihead;
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
CompositingPrefs::CompositingPrefs()
|
2012-04-28 19:43:17 +00:00
|
|
|
: mEnableDirectRendering(true)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-10-17 15:37:14 +00:00
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
CompositingPrefs::~CompositingPrefs()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-09-18 13:59:06 +00:00
|
|
|
|
2011-04-03 19:59:57 +00:00
|
|
|
bool CompositingPrefs::openGlIsBroken()
|
|
|
|
{
|
2013-07-23 05:02:52 +00:00
|
|
|
const QString unsafeKey(QStringLiteral("OpenGLIsUnsafe") + (is_multihead ? QString::number(screen_number) : QString()));
|
2013-05-24 12:50:17 +00:00
|
|
|
return KConfigGroup(KGlobal::config(), "Compositing").readEntry(unsafeKey, false);
|
2011-04-03 19:59:57 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 16:34:08 +00:00
|
|
|
bool CompositingPrefs::compositingPossible()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-04-03 19:59:57 +00:00
|
|
|
// first off, check whether we figured that we'll crash on detection because of a buggy driver
|
2012-04-27 09:37:21 +00:00
|
|
|
KConfigGroup gl_workaround_group(KGlobal::config(), "Compositing");
|
2013-07-23 05:02:52 +00:00
|
|
|
const QString unsafeKey(QStringLiteral("OpenGLIsUnsafe") + (is_multihead ? QString::number(screen_number) : QString()));
|
|
|
|
if (gl_workaround_group.readEntry("Backend", "OpenGL") == QStringLiteral("OpenGL") &&
|
2013-05-24 12:50:17 +00:00
|
|
|
gl_workaround_group.readEntry(unsafeKey, false))
|
2011-04-03 19:59:57 +00:00
|
|
|
return false;
|
|
|
|
|
2012-12-21 14:11:31 +00:00
|
|
|
if (!Xcb::Extensions::self()->isCompositeAvailable()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "No composite extension available";
|
2007-09-26 16:34:08 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-12-21 14:11:31 +00:00
|
|
|
if (!Xcb::Extensions::self()->isDamageAvailable()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "No damage extension available";
|
2007-09-26 16:34:08 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-07-20 20:10:03 +00:00
|
|
|
if (hasGlx())
|
2007-12-17 14:14:53 +00:00
|
|
|
return true;
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2012-12-21 14:11:31 +00:00
|
|
|
if (Xcb::Extensions::self()->isRenderAvailable() && Xcb::Extensions::self()->isFixesAvailable())
|
2007-12-17 14:14:53 +00:00
|
|
|
return true;
|
2010-12-12 11:08:23 +00:00
|
|
|
#endif
|
|
|
|
#ifdef KWIN_HAVE_OPENGLES
|
|
|
|
return true;
|
2007-12-17 14:14:53 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
kDebug(1212) << "No OpenGL or XRender/XFixes support";
|
2007-12-17 14:14:53 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-09-26 16:34:08 +00:00
|
|
|
|
2007-11-12 16:32:25 +00:00
|
|
|
QString CompositingPrefs::compositingNotPossibleReason()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-04-03 19:59:57 +00:00
|
|
|
// first off, check whether we figured that we'll crash on detection because of a buggy driver
|
2012-04-27 09:37:21 +00:00
|
|
|
KConfigGroup gl_workaround_group(KGlobal::config(), "Compositing");
|
2013-07-23 05:02:52 +00:00
|
|
|
const QString unsafeKey(QStringLiteral("OpenGLIsUnsafe") + (is_multihead ? QString::number(screen_number) : QString()));
|
|
|
|
if (gl_workaround_group.readEntry("Backend", "OpenGL") == QStringLiteral("OpenGL") &&
|
2013-05-24 12:50:17 +00:00
|
|
|
gl_workaround_group.readEntry(unsafeKey, false))
|
2011-04-03 19:59:57 +00:00
|
|
|
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>");
|
|
|
|
|
2012-12-21 14:11:31 +00:00
|
|
|
if (!Xcb::Extensions::self()->isCompositeAvailable() || !Xcb::Extensions::self()->isDamageAvailable()) {
|
2007-11-12 16:32:25 +00:00
|
|
|
return i18n("Required X extensions (XComposite and XDamage) are not available.");
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-08-13 13:21:51 +00:00
|
|
|
#if !defined( KWIN_HAVE_XRENDER_COMPOSITING )
|
2011-07-20 20:10:03 +00:00
|
|
|
if (!hasGlx())
|
2011-01-30 14:34:42 +00:00
|
|
|
return i18n("GLX/OpenGL are not available and only OpenGL support is compiled.");
|
2008-01-08 11:26:52 +00:00
|
|
|
#else
|
2011-07-20 20:10:03 +00:00
|
|
|
if (!(hasGlx()
|
2012-12-21 14:11:31 +00:00
|
|
|
|| (Xcb::Extensions::self()->isRenderAvailable() && Xcb::Extensions::self()->isFixesAvailable()))) {
|
2011-01-30 14:34:42 +00:00
|
|
|
return i18n("GLX/OpenGL and XRender/XFixes are not available.");
|
|
|
|
}
|
2007-12-17 14:14:53 +00:00
|
|
|
#endif
|
2007-11-12 16:32:25 +00:00
|
|
|
return QString();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-11-12 16:32:25 +00:00
|
|
|
|
2011-07-20 20:10:03 +00:00
|
|
|
static bool s_glxDetected = false;
|
|
|
|
static bool s_hasGlx = false;
|
|
|
|
|
|
|
|
bool CompositingPrefs::hasGlx()
|
|
|
|
{
|
|
|
|
if (s_glxDetected) {
|
|
|
|
return s_hasGlx;
|
|
|
|
}
|
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
|
|
|
int event_base, error_base;
|
|
|
|
s_hasGlx = glXQueryExtension(display(), &event_base, &error_base);
|
|
|
|
#endif
|
|
|
|
s_glxDetected = true;
|
|
|
|
return s_hasGlx;
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
void CompositingPrefs::detect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-04-03 19:59:57 +00:00
|
|
|
if (!compositingPossible() || openGlIsBroken()) {
|
2007-09-26 16:34:08 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-09-26 16:34:08 +00:00
|
|
|
|
2012-04-29 06:24:54 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2010-02-26 20:47:00 +00:00
|
|
|
// HACK: This is needed for AIGLX
|
2011-07-26 05:55:20 +00:00
|
|
|
const bool forceIndirect = qstrcmp(qgetenv("LIBGL_ALWAYS_INDIRECT"), "1") == 0;
|
2013-05-15 11:47:27 +00:00
|
|
|
const bool forceEgl = qstrcmp(qgetenv("KWIN_OPENGL_INTERFACE"), "egl") == 0 ||
|
|
|
|
qstrcmp(qgetenv("KWIN_OPENGL_INTERFACE"), "egl_wayland") == 0;
|
2013-05-27 06:52:30 +00:00
|
|
|
if (!forceIndirect && !forceEgl && qstrcmp(qgetenv("KWIN_DIRECT_GL"), "1") != 0) {
|
2010-02-26 20:47:00 +00:00
|
|
|
// Start an external helper program that initializes GLX and returns
|
|
|
|
// 0 if we can use direct rendering, and 1 otherwise.
|
|
|
|
// The reason we have to use an external program is that after GLX
|
|
|
|
// has been initialized, it's too late to set the LIBGL_ALWAYS_INDIRECT
|
|
|
|
// environment variable.
|
|
|
|
// Direct rendering is preferred, since not all OpenGL extensions are
|
|
|
|
// available with indirect rendering.
|
2013-07-23 05:02:52 +00:00
|
|
|
const QString opengl_test = KStandardDirs::findExe(QStringLiteral("kwin_opengl_test"));
|
2011-07-26 05:55:20 +00:00
|
|
|
if (QProcess::execute(opengl_test) != 0) {
|
|
|
|
mEnableDirectRendering = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
setenv("LIBGL_ALWAYS_INDIRECT", "1", true);
|
2011-07-26 05:55:20 +00:00
|
|
|
} else {
|
|
|
|
mEnableDirectRendering = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mEnableDirectRendering = !forceIndirect;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-12-12 11:08:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
} // namespace
|
|
|
|
|