From 829954165260aecb89c36af95e85e71372cbaa5b Mon Sep 17 00:00:00 2001 From: Philip Falkner Date: Tue, 13 Feb 2007 23:28:36 +0000 Subject: [PATCH] Add build checks for XComposite, XDamage, XRender, OpenGL, and XShm. KWin should now build and run with/without any or all of the above. svn path=/branches/work/kwin_composite/; revision=633387 --- CMakeLists.txt | 15 +++++++++++---- composite.cpp | 32 +++++++++++++++++++++++--------- effects.cpp | 4 ++++ effects/showfps.cpp | 8 ++++++++ events.cpp | 4 ++++ glutils.cpp | 11 +++++++++++ glutils.h | 5 +++++ glutils_funcs.cpp | 3 +++ glutils_funcs.h | 3 +++ scene_opengl.cpp | 14 ++++++++++++++ scene_opengl.h | 8 ++++++++ 11 files changed, 94 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19e5b2b989..20f21a93fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,11 +66,16 @@ set(kwin_KDEINIT_SRCS effects/zoom.cpp effects/test_input.cpp effects/presentwindows.cpp - effects/wavywindows.cpp effects/minimizeanimation.cpp effects/desktopchangeslide.cpp ) +if(HAVE_OPENGL) + set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} + effects/wavywindows.cpp + ) +endif(HAVE_OPENGL) + qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.xml workspace.h KWinInternal::Workspace ) kde4_automoc(kwin ${kwin_KDEINIT_SRCS}) @@ -79,9 +84,11 @@ kde4_automoc(kwin ${kwin_KDEINIT_SRCS}) kde4_add_kdeinit_executable( kwin ${kwin_KDEINIT_SRCS}) target_link_libraries(kdeinit_kwin ${KDE4_KDEUI_LIBS} kdecorations ${X11_LIBRARIES} ${QT_QT3SUPPORT_LIBRARY} ) -target_link_libraries(kdeinit_kwin -lGL) -# -ldl used by OpenGL code -target_link_libraries(kdeinit_kwin -ldl) +if(OPENGL_FOUND) + target_link_libraries(kdeinit_kwin ${OPENGL_gl_LIBRARY}) + # -ldl used by OpenGL code + target_link_libraries(kdeinit_kwin -ldl) +endif(OPENGL_FOUND) if (X11_Xrandr_FOUND) target_link_libraries(kdeinit_kwin ${X11_Xrandr_LIB}) endif (X11_Xrandr_FOUND) diff --git a/composite.cpp b/composite.cpp index f5da1fa586..126fb325b5 100644 --- a/composite.cpp +++ b/composite.cpp @@ -49,9 +49,9 @@ namespace KWinInternal // Workspace //**************************************** -#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) void Workspace::setupCompositing() { +#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) if( !options->useTranslucency ) return; if( !Extensions::compositeAvailable() || !Extensions::damageAvailable()) @@ -70,13 +70,20 @@ void Workspace::setupCompositing() { case 'B': scene = new SceneBasic( this ); + kDebug( 1212 ) << "X compositing" << endl; break; +#ifdef HAVE_XRENDER case 'X': scene = new SceneXrender( this ); + kDebug( 1212 ) << "XRender compositing" << endl; break; +#endif +#ifdef HAVE_OPENGL case 'O': scene = new SceneOpenGL( this ); + kDebug( 1212 ) << "OpenGL compositing" << endl; break; +#endif default: kDebug( 1212 ) << "No compositing" << endl; return; @@ -112,12 +119,6 @@ void Workspace::setupCompositing() compositeTimer.start( compositeRate ); lastCompositePaint.start(); XCompositeRedirectSubwindows( display(), rootWindow(), CompositeRedirectManual ); - if( dynamic_cast< SceneOpenGL* >( scene )) - kDebug( 1212 ) << "OpenGL compositing" << endl; - else if( dynamic_cast< SceneXrender* >( scene )) - kDebug( 1212 ) << "XRender compositing" << endl; - else if( dynamic_cast< SceneBasic* >( scene )) - kDebug( 1212 ) << "X compositing" << endl; new EffectsHandler(); // sets also the 'effects' pointer addRepaintFull(); foreach( Client* c, clients ) @@ -134,10 +135,12 @@ void Workspace::setupCompositing() scene->windowAdded( c ); delete popup; // force re-creation of the Alt+F3 popup (opacity option) popup = NULL; +#endif } void Workspace::finishCompositing() { +#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) if( scene == NULL ) return; delete cm_selection; @@ -176,6 +179,7 @@ void Workspace::finishCompositing() } delete popup; // force re-creation of the Alt+F3 popup (opacity option) popup = NULL; +#endif } void Workspace::lostCMSelection() @@ -207,6 +211,7 @@ void Workspace::addRepaintFull() void Workspace::performCompositing() { +#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) // The event loop apparently tries to fire a QTimer as often as possible, even // at the expense of not processing many X events. This means that the composite // repaints can seriously impact performance of everything else, therefore throttle @@ -258,6 +263,7 @@ void Workspace::performCompositing() compositeTimer.start( compositeRate - paintTime ); } lastCompositePaint.start(); +#endif } bool Workspace::windowRepaintsPending() const @@ -320,6 +326,7 @@ void Workspace::destroyOverlay() void Toplevel::setupCompositing() { +#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) if( !compositing()) return; if( damage_handle != None ) @@ -328,10 +335,12 @@ void Toplevel::setupCompositing() damage_region = QRegion( 0, 0, width(), height()); effect_window = new EffectWindow(); effect_window->setWindow( this ); +#endif } void Toplevel::finishCompositing() { +#if defined( HAVE_XCOMPOSITE ) && defined( HAVE_XDAMAGE ) if( damage_handle == None ) return; if( effect_window->window() == this ) // otherwise it's already passed to Deleted, don't free data @@ -344,6 +353,7 @@ void Toplevel::finishCompositing() damage_region = QRegion(); repaints_region = QRegion(); effect_window = NULL; +#endif } void Toplevel::discardWindowPixmap() @@ -357,10 +367,15 @@ void Toplevel::discardWindowPixmap() Pixmap Toplevel::createWindowPixmap() const { +#ifdef HAVE_XCOMPOSITE assert( compositing()); return XCompositeNameWindowPixmap( display(), frameId()); +#else + return None; +#endif } +#ifdef HAVE_XDAMAGE void Toplevel::damageNotifyEvent( XDamageNotifyEvent* e ) { addDamage( e->area.x, e->area.y, e->area.width, e->area.height ); @@ -379,6 +394,7 @@ void Toplevel::damageNotifyEvent( XDamageNotifyEvent* e ) break; } } +#endif void Toplevel::addDamage( const QRect& r ) { @@ -434,6 +450,4 @@ void Toplevel::resetRepaints( const QRect& r ) repaints_region -= r; } -#endif - } // namespace diff --git a/effects.cpp b/effects.cpp index 801591428b..7c004feff6 100644 --- a/effects.cpp +++ b/effects.cpp @@ -28,7 +28,9 @@ License. See the file "COPYING" for the exact licensing terms. #include "effects/shakymove.h" #include "effects/shiftworkspaceup.h" #include "effects/showfps.h" +#ifdef HAVE_OPENGL #include "effects/wavywindows.h" +#endif #include "effects/zoom.h" #include "effects/test_input.h" @@ -129,7 +131,9 @@ EffectsHandler::EffectsHandler() registerEffect("ShowFps", new GenericEffectFactory); registerEffect("Zoom", new GenericEffectFactory); registerEffect("PresentWindows", new GenericEffectFactory); +#ifdef HAVE_OPENGL registerEffect("WavyWindows", new GenericEffectFactory); +#endif registerEffect("MinimizeAnimation", new GenericEffectFactory); registerEffect("Howto", new GenericEffectFactory); registerEffect("MakeTransparent", new GenericEffectFactory); diff --git a/effects/showfps.cpp b/effects/showfps.cpp index 5dbd0671b5..325441b434 100644 --- a/effects/showfps.cpp +++ b/effects/showfps.cpp @@ -16,7 +16,9 @@ License. See the file "COPYING" for the exact licensing terms. #include #include +#ifdef HAVE_OPENGL #include +#endif namespace KWinInternal { @@ -73,12 +75,14 @@ void ShowFpsEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ++fps; // count all frames in the last second if( fps > MAX_TIME ) fps = MAX_TIME; // keep it the same height +#ifdef HAVE_OPENGL if( dynamic_cast< SceneOpenGL* >( scene )) { paintGL( fps ); glFinish(); // make sure all rendering is done } else +#endif { paintX( fps ); XSync( display(), False ); // make sure all rendering is done @@ -87,6 +91,7 @@ void ShowFpsEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data void ShowFpsEffect::paintGL( int fps ) { +#ifdef HAVE_OPENGL int x = this->x; int y = this->y; glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); @@ -141,6 +146,7 @@ void ShowFpsEffect::paintGL( int fps ) } glEnd(); glPopAttrib(); +#endif } /* @@ -150,6 +156,7 @@ void ShowFpsEffect::paintGL( int fps ) */ void ShowFpsEffect::paintX( int fps ) { +#ifdef HAVE_XRENDER Pixmap pixmap = XCreatePixmap( display(), rootWindow(), NUM_PAINTS + FPS_WIDTH, MAX_TIME, 32 ); XRenderPictFormat* format = XRenderFindStandardFormat( display(), PictStandardARGB32 ); Picture p = XRenderCreatePicture( display(), pixmap, format, 0, NULL ); @@ -209,6 +216,7 @@ void ShowFpsEffect::paintX( int fps ) XRenderComposite( display(), alpha != 1.0 ? PictOpOver : PictOpSrc, p, None, static_cast< SceneXrender* >( scene )->bufferPicture(), 0, 0, 0, 0, x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME ); XRenderFreePicture( display(), p ); +#endif } void ShowFpsEffect::postPaintScreen() diff --git a/events.cpp b/events.cpp index 966c448c1c..a503891c28 100644 --- a/events.cpp +++ b/events.cpp @@ -701,8 +701,10 @@ bool Client::windowEvent( XEvent* e ) } if( e->xany.window == frameId()) { +#ifdef HAVE_XDAMAGE if( e->type == Extensions::damageNotifyEvent()) damageNotifyEvent( reinterpret_cast< XDamageNotifyEvent* >( e )); +#endif } break; } @@ -1636,8 +1638,10 @@ bool Unmanaged::windowEvent( XEvent* e ) if( scene != NULL ) scene->windowGeometryShapeChanged( this ); } +#ifdef HAVE_XDAMAGE if( e->type == Extensions::damageNotifyEvent()) damageNotifyEvent( reinterpret_cast< XDamageNotifyEvent* >( e )); +#endif break; } } diff --git a/glutils.cpp b/glutils.cpp index f7141d19c9..14353bab9e 100644 --- a/glutils.cpp +++ b/glutils.cpp @@ -33,6 +33,7 @@ int glTextureUnitsCount; // Functions void initGLX() { +#ifdef HAVE_OPENGL // Get GLX version int major, minor; glXQueryVersion( display(), &major, &minor ); @@ -42,10 +43,14 @@ void initGLX() display(), DefaultScreen( display()))).split(" "); glxResolveFunctions(); +#else + glXVersion = MAKE_GL_VERSION( 0, 0, 0 ); +#endif } void initGL() { +#ifdef HAVE_OPENGL // Get OpenGL version QString glversionstring = QString((const char*)glGetString(GL_VERSION)); QStringList glversioninfo = glversionstring.left(glversionstring.indexOf(' ')).split('.'); @@ -56,6 +61,9 @@ void initGL() // handle OpenGL extensions functions glResolveFunctions(); +#else + glVersion = MAKE_GL_VERSION( 0, 0, 0 ); +#endif } bool hasGLVersion(int major, int minor, int release) @@ -74,6 +82,7 @@ bool hasGLExtension(const QString& extension) } +#ifdef HAVE_OPENGL GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile) { @@ -273,4 +282,6 @@ bool GLShader::setAttribute(const QString& name, float value) return (location >= 0); } +#endif + } // namespace diff --git a/glutils.h b/glutils.h index 6758f3ca65..4797ae4bdd 100644 --- a/glutils.h +++ b/glutils.h @@ -16,8 +16,10 @@ License. See the file "COPYING" for the exact licensing terms. #include +#ifdef HAVE_OPENGL #include #include +#endif #include "glutils_funcs.h" @@ -48,6 +50,7 @@ bool hasGLExtension(const QString& extension); inline bool isPowerOfTwo( int x ) { return (( x & ( x - 1 )) == 0 ); } +#ifdef HAVE_OPENGL class GLShader { @@ -76,6 +79,8 @@ class GLShader QHash< QString, int >* mVariableLocations; }; +#endif + } // namespace #endif diff --git a/glutils_funcs.cpp b/glutils_funcs.cpp index fc4edee28e..cc97791413 100644 --- a/glutils_funcs.cpp +++ b/glutils_funcs.cpp @@ -22,6 +22,8 @@ License. See the file "COPYING" for the exact licensing terms. if( !function ) \ function = (function ## _func)getProcAddress( #backup ); +#ifdef HAVE_OPENGL + namespace KWinInternal { @@ -213,3 +215,4 @@ void glResolveFunctions() } // namespace +#endif diff --git a/glutils_funcs.h b/glutils_funcs.h index e89573e3bd..7f884f41e0 100644 --- a/glutils_funcs.h +++ b/glutils_funcs.h @@ -11,6 +11,8 @@ License. See the file "COPYING" for the exact licensing terms. #ifndef KWIN_GLUTILS_FUNCS_H #define KWIN_GLUTILS_FUNCS_H +#ifdef HAVE_OPENGL + namespace KWinInternal { @@ -164,3 +166,4 @@ extern glGetAttribLocation_func glGetAttribLocation; #endif +#endif diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 0b1b115b29..caceb6fb85 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -67,6 +67,8 @@ Sources and other compositing managers: #include #include +#ifdef HAVE_OPENGL + namespace KWinInternal { @@ -93,7 +95,9 @@ bool SceneOpenGL::supports_npot_textures; bool SceneOpenGL::supports_fbo; bool SceneOpenGL::supports_saturation; bool SceneOpenGL::shm_mode; +#ifdef HAVE_XSHM XShmSegmentInfo SceneOpenGL::shm; +#endif // detect OpenGL error (add to various places in code to pinpoint the place) @@ -226,6 +230,7 @@ bool SceneOpenGL::initTfp() bool SceneOpenGL::initShm() { +#ifdef HAVE_XSHM int major, minor; Bool pixmaps; if( !XShmQueryVersion( display(), &major, &minor, &pixmaps ) || !pixmaps ) @@ -260,13 +265,18 @@ bool SceneOpenGL::initShm() return false; } return true; +#else + return false; +#endif } void SceneOpenGL::cleanupShm() { +#ifdef HAVE_XSHM shmdt( shm.shmaddr ); #ifndef __linux__ shmctl( shm.shmid, IPC_RMID, 0 ); +#endif #endif } @@ -902,6 +912,7 @@ void SceneOpenGL::Window::bindTexture() glXWaitX(); if( shm_mode ) { // non-tfp case, copy pixmap contents to a texture +#ifdef HAVE_XSHM findTextureTarget(); if( texture == None ) { @@ -941,6 +952,7 @@ void SceneOpenGL::Window::bindTexture() texture_y_inverted = true; texture_can_use_mipmaps = true; toplevel->resetDamage( toplevel->rect()); +#endif } else if( tfp_mode ) { // tfp mode, simply bind the pixmap to texture @@ -1370,3 +1382,5 @@ void SceneOpenGL::Window::restoreRenderStates( int mask, WindowPaintData data ) } } // namespace + +#endif diff --git a/scene_opengl.h b/scene_opengl.h index ebf9d6c839..458e4a427c 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -15,7 +15,11 @@ License. See the file "COPYING" for the exact licensing terms. #include "glutils.h" +#ifdef HAVE_OPENGL + +#ifdef HAVE_XSHM #include +#endif namespace KWinInternal { @@ -76,7 +80,9 @@ class SceneOpenGL static bool supports_fbo; static bool supports_saturation; QMap< Toplevel*, Window > windows; +#ifdef HAVE_XSHM static XShmSegmentInfo shm; +#endif }; class SceneOpenGL::Window @@ -160,3 +166,5 @@ class SceneOpenGL::Window } // namespace #endif + +#endif