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>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "compositingprefs.h"
|
|
|
|
|
2007-09-26 16:34:08 +00:00
|
|
|
#include "kwinglobals.h"
|
2007-09-18 13:59:06 +00:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
2007-09-26 13:47:01 +00:00
|
|
|
#include <kxerrorhandler.h>
|
2007-09-18 13:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
CompositingPrefs::CompositingPrefs()
|
2007-10-17 15:37:14 +00:00
|
|
|
: mXgl( false )
|
|
|
|
, mEnableCompositing( false )
|
|
|
|
, mEnableVSync( true )
|
|
|
|
, mEnableDirectRendering( true )
|
|
|
|
, mStrictBinding( true )
|
2007-09-18 13:59:06 +00:00
|
|
|
{
|
|
|
|
}
|
2007-10-17 15:37:14 +00:00
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
CompositingPrefs::~CompositingPrefs()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-26 16:34:08 +00:00
|
|
|
bool CompositingPrefs::compositingPossible()
|
|
|
|
{
|
|
|
|
#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE )
|
|
|
|
Extensions::init();
|
|
|
|
if( !Extensions::compositeAvailable())
|
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "No composite extension available";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( !Extensions::damageAvailable())
|
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "No damage extension available";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
void CompositingPrefs::detect()
|
|
|
|
{
|
2007-09-26 16:34:08 +00:00
|
|
|
if( !compositingPossible())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
#ifdef HAVE_OPENGL
|
2007-09-27 19:04:18 +00:00
|
|
|
if( !Extensions::glxAvailable())
|
|
|
|
{
|
|
|
|
kDebug( 1212 ) << "No GLX available";
|
|
|
|
return;
|
|
|
|
}
|
2007-09-30 14:08:24 +00:00
|
|
|
int glxmajor, glxminor;
|
|
|
|
glXQueryVersion( display(), &glxmajor, &glxminor );
|
|
|
|
kDebug() << "glx version is " << glxmajor << "." << glxminor;
|
|
|
|
bool hasglx13 = ( glxmajor > 1 || ( glxmajor == 1 && glxminor >= 3 ));
|
2007-09-27 19:04:18 +00:00
|
|
|
|
2007-09-25 10:14:57 +00:00
|
|
|
// remember and later restore active context
|
|
|
|
GLXContext oldcontext = glXGetCurrentContext();
|
|
|
|
GLXDrawable olddrawable = glXGetCurrentDrawable();
|
2007-09-30 14:08:24 +00:00
|
|
|
GLXDrawable oldreaddrawable;
|
|
|
|
if( hasglx13 )
|
|
|
|
{
|
|
|
|
oldreaddrawable = glXGetCurrentReadDrawable();
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
if( createGLXContext() )
|
|
|
|
{
|
|
|
|
detectDriverAndVersion();
|
|
|
|
applyDriverSpecificOptions();
|
|
|
|
|
|
|
|
deleteGLXContext();
|
|
|
|
}
|
2007-09-25 10:14:57 +00:00
|
|
|
if( oldcontext != NULL )
|
2007-09-30 14:08:24 +00:00
|
|
|
{
|
|
|
|
if( hasglx13 )
|
|
|
|
{
|
|
|
|
glXMakeContextCurrent( display(), olddrawable, oldreaddrawable, oldcontext );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glXMakeCurrent( display(), olddrawable, oldcontext );
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 13:59:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompositingPrefs::createGLXContext()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_OPENGL
|
2007-09-26 13:47:01 +00:00
|
|
|
KXErrorHandler handler;
|
2007-09-18 13:59:06 +00:00
|
|
|
// Most of this code has been taken from glxinfo.c
|
|
|
|
QVector<int> attribs;
|
|
|
|
attribs << GLX_RGBA;
|
|
|
|
attribs << GLX_RED_SIZE << 1;
|
|
|
|
attribs << GLX_GREEN_SIZE << 1;
|
|
|
|
attribs << GLX_BLUE_SIZE << 1;
|
|
|
|
attribs << None;
|
|
|
|
|
|
|
|
int scrnum = 0; // correct?
|
|
|
|
XVisualInfo* visinfo = glXChooseVisual( display(), scrnum, attribs.data() );
|
|
|
|
if( !visinfo )
|
|
|
|
{
|
|
|
|
attribs.last() = GLX_DOUBLEBUFFER;
|
|
|
|
attribs << None;
|
|
|
|
visinfo = glXChooseVisual( display(), scrnum, attribs.data() );
|
|
|
|
if (!visinfo)
|
|
|
|
{
|
|
|
|
kError() << "Error: couldn't find RGB GLX visual";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mGLContext = glXCreateContext( display(), visinfo, NULL, True );
|
|
|
|
if ( !mGLContext )
|
|
|
|
{
|
|
|
|
kError() << "glXCreateContext failed";
|
|
|
|
XDestroyWindow( display(), mGLWindow );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
attr.background_pixel = 0;
|
|
|
|
attr.border_pixel = 0;
|
|
|
|
attr.colormap = XCreateColormap( display(), rootWindow(), visinfo->visual, AllocNone );
|
|
|
|
attr.event_mask = StructureNotifyMask | ExposureMask;
|
|
|
|
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
int width = 100, height = 100;
|
|
|
|
mGLWindow = XCreateWindow( display(), rootWindow(), 0, 0, width, height,
|
|
|
|
0, visinfo->depth, InputOutput,
|
|
|
|
visinfo->visual, mask, &attr );
|
|
|
|
|
2007-09-26 13:47:01 +00:00
|
|
|
return glXMakeCurrent( display(), mGLWindow, mGLContext ) && !handler.error( true );
|
2007-09-18 13:59:06 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositingPrefs::deleteGLXContext()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
glXDestroyContext( display(), mGLContext );
|
|
|
|
XDestroyWindow( display(), mGLWindow );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositingPrefs::detectDriverAndVersion()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_OPENGL
|
2007-09-27 13:59:58 +00:00
|
|
|
mGLVendor = QString((const char*)glGetString( GL_VENDOR ));
|
|
|
|
mGLRenderer = QString((const char*)glGetString( GL_RENDERER ));
|
|
|
|
mGLVersion = QString((const char*)glGetString( GL_VERSION ));
|
2007-10-17 15:37:14 +00:00
|
|
|
mXgl = detectXgl();
|
2007-09-27 13:59:58 +00:00
|
|
|
kDebug() << "GL vendor is" << mGLVendor;
|
|
|
|
kDebug() << "GL renderer is" << mGLRenderer;
|
|
|
|
kDebug() << "GL version is" << mGLVersion;
|
2007-10-17 15:37:14 +00:00
|
|
|
kDebug() << "XGL:" << ( mXgl ? "yes" : "no" );
|
2007-09-27 13:59:58 +00:00
|
|
|
|
|
|
|
if( mGLRenderer.contains( "Intel" ))
|
2007-10-17 15:37:14 +00:00
|
|
|
{
|
2007-09-18 13:59:06 +00:00
|
|
|
mDriver = "intel";
|
2007-09-27 13:59:58 +00:00
|
|
|
QStringList words = mGLRenderer.split(" ");
|
2007-09-18 13:59:06 +00:00
|
|
|
mVersion = Version( words[ words.count() - 2 ] );
|
2007-10-17 15:37:14 +00:00
|
|
|
}
|
2007-09-27 13:59:58 +00:00
|
|
|
else if( mGLVendor.contains( "NVIDIA" ))
|
2007-10-17 15:37:14 +00:00
|
|
|
{
|
2007-09-18 13:59:06 +00:00
|
|
|
mDriver = "nvidia";
|
2007-09-27 13:59:58 +00:00
|
|
|
QStringList words = mGLVersion.split(" ");
|
2007-09-18 13:59:06 +00:00
|
|
|
mVersion = Version( words[ words.count() - 1 ] );
|
2007-10-17 15:37:14 +00:00
|
|
|
}
|
2007-09-18 13:59:06 +00:00
|
|
|
else
|
2007-10-17 15:37:14 +00:00
|
|
|
{
|
2007-09-18 13:59:06 +00:00
|
|
|
mDriver = "unknown";
|
2007-10-17 15:37:14 +00:00
|
|
|
}
|
2007-09-18 13:59:06 +00:00
|
|
|
|
|
|
|
kDebug() << "Detected driver" << mDriver << ", version" << mVersion.join(".");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositingPrefs::applyDriverSpecificOptions()
|
|
|
|
{
|
2007-10-17 15:37:14 +00:00
|
|
|
if( mXgl )
|
|
|
|
{
|
|
|
|
kDebug() << "xgl, enabling";
|
|
|
|
mEnableCompositing = true;
|
|
|
|
mStrictBinding = false;
|
|
|
|
}
|
|
|
|
else if( mDriver == "intel")
|
2007-09-18 13:59:06 +00:00
|
|
|
{
|
2007-09-22 11:19:22 +00:00
|
|
|
kDebug() << "intel driver, disabling vsync, enabling direct";
|
|
|
|
mEnableVSync = false;
|
|
|
|
mEnableDirectRendering = true;
|
2007-09-27 13:59:58 +00:00
|
|
|
if( mVersion >= Version( "20061017" ) && mGLRenderer.contains( "945GM" ))
|
2007-09-18 13:59:06 +00:00
|
|
|
{
|
2007-09-27 13:59:58 +00:00
|
|
|
kDebug() << "intel >= 20061017 and whitelisted card, enabling compositing";
|
2007-09-18 13:59:06 +00:00
|
|
|
mEnableCompositing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( mDriver == "nvidia" )
|
|
|
|
{
|
2007-10-17 15:37:14 +00:00
|
|
|
mStrictBinding = false;
|
2007-10-23 12:07:39 +00:00
|
|
|
if( mVersion >= Version( "100.14.23" ))
|
|
|
|
{
|
|
|
|
kDebug() << "nvidia >= 100.14.23, enabling compositing";
|
|
|
|
mEnableCompositing = true;
|
|
|
|
}
|
|
|
|
else if( mVersion >= Version( "96.39" ))
|
2007-09-18 13:59:06 +00:00
|
|
|
{
|
2007-10-23 12:07:39 +00:00
|
|
|
kDebug() << "nvidia >= 96.39, enabling compositing, disabling vsync";
|
2007-09-18 13:59:06 +00:00
|
|
|
mEnableCompositing = true;
|
2007-10-23 12:07:39 +00:00
|
|
|
mEnableVSync = false;
|
2007-09-18 13:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-17 15:37:14 +00:00
|
|
|
bool CompositingPrefs::detectXgl()
|
|
|
|
{ // Xgl apparently uses only this specific X version
|
|
|
|
return VendorRelease(display()) == 70000001;
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:59:06 +00:00
|
|
|
CompositingPrefs::Version::Version( const QString& str ) :
|
|
|
|
QStringList()
|
|
|
|
{
|
|
|
|
QRegExp numrx( "(\\d+)|(\\D+)" );
|
|
|
|
int pos = 0;
|
|
|
|
while(( pos = numrx.indexIn( str, pos )) != -1 )
|
|
|
|
{
|
|
|
|
pos += numrx.matchedLength();
|
|
|
|
|
|
|
|
QString part = numrx.cap();
|
|
|
|
if( part == "." )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
append( part );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CompositingPrefs::Version::compare( const Version& v ) const
|
|
|
|
{
|
|
|
|
for( int i = 0; i < qMin( count(), v.count() ); i++ )
|
|
|
|
{
|
|
|
|
if( at( i )[ 0 ].isDigit() )
|
|
|
|
{
|
|
|
|
// This part of version string is numeric - compare numbers
|
|
|
|
int num = at( i ).toInt();
|
|
|
|
int vnum = v.at( i ).toInt();
|
|
|
|
if( num > vnum )
|
|
|
|
return 1;
|
|
|
|
else if( num < vnum )
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This part is string
|
|
|
|
if( at( i ) > v.at( i ))
|
|
|
|
return 1;
|
|
|
|
else if( at( i ) < v.at( i ))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( count() > v.count() )
|
|
|
|
return 1;
|
|
|
|
else if( count() < v.count() )
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|