From 58fdb149a8e54905a1831d9b989f6ed68beec9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 10 Apr 2007 15:38:36 +0000 Subject: [PATCH] Convert ShowFps effect to plugins. svn path=/branches/work/kwin_composite/; revision=652275 --- effects.cpp | 60 +++++++++++++++++++++++++++-------------- effects.h | 4 +++ effects/CMakeLists.txt | 33 ++++++++++++++++++++--- effects/showfps.cpp | 36 +++++++++++++++---------- effects/showfps.desktop | 4 +++ effects/showfps.h | 4 +-- lib/kwineffects.h | 3 +++ lib/kwinglobals.h | 20 +++++++++++--- options.cpp | 19 ++++++++++++- options.h | 13 +++++++++ utils.h | 13 --------- 11 files changed, 152 insertions(+), 57 deletions(-) create mode 100644 effects/showfps.desktop diff --git a/effects.cpp b/effects.cpp index 697db4afa7..04289e9cb8 100644 --- a/effects.cpp +++ b/effects.cpp @@ -13,6 +13,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "deleted.h" #include "client.h" #include "group.h" +#include "scene_xrender.h" #include "workspace.h" #include "kdebug.h" @@ -134,38 +135,48 @@ int EffectsHandlerImpl::currentDesktop() const } int EffectsHandlerImpl::displayWidth() const -{ + { return KWin::displayWidth(); -} + } int EffectsHandlerImpl::displayHeight() const -{ + { return KWin::displayWidth(); -} + } QPoint EffectsHandlerImpl::cursorPos() const -{ + { return KWin::cursorPos(); -} + } EffectWindowList EffectsHandlerImpl::stackingOrder() const -{ + { ClientList list = Workspace::self()->stackingOrder(); EffectWindowList ret; foreach( Client* c, list ) ret.append( effectWindow( c )); return ret; -} + } void EffectsHandlerImpl::addRepaintFull() -{ + { Workspace::self()->addRepaintFull(); -} + } + +void EffectsHandlerImpl::addRepaint( const QRect& r ) + { + Workspace::self()->addRepaint( r ); + } + +void EffectsHandlerImpl::addRepaint( int x, int y, int w, int h ) + { + Workspace::self()->addRepaint( x, y, w, h ); + } QRect EffectsHandlerImpl::clientArea( clientAreaOption opt, const QPoint& p, int desktop ) const -{ + { return Workspace::self()->clientArea( opt, p, desktop ); -} + } Window EffectsHandlerImpl::createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ) { @@ -244,24 +255,33 @@ void EffectsHandlerImpl::checkInputWindowStacking() } void EffectsHandlerImpl::checkElectricBorder(const QPoint &pos, Time time) -{ + { Workspace::self()->checkElectricBorder( pos, time ); -} + } void EffectsHandlerImpl::reserveElectricBorder( ElectricBorder border ) -{ + { Workspace::self()->reserveElectricBorder( border ); -} + } void EffectsHandlerImpl::unreserveElectricBorder( ElectricBorder border ) -{ + { Workspace::self()->unreserveElectricBorder( border ); -} + } void EffectsHandlerImpl::reserveElectricBorderSwitching( bool reserve ) -{ + { Workspace::self()->reserveElectricBorderSwitching( reserve ); -} + } + +unsigned long EffectsHandlerImpl::xrenderBufferPicture() + { +#ifdef HAVE_XRENDER + if( SceneXrender* s = dynamic_cast< SceneXrender* >( scene )) + return s->bufferPicture(); +#endif + return None; + } //**************************************** // EffectWindowImpl diff --git a/effects.h b/effects.h index 1ac7a3227e..57714d4477 100644 --- a/effects.h +++ b/effects.h @@ -43,6 +43,8 @@ class EffectsHandlerImpl : public EffectsHandler virtual QPoint cursorPos() const; virtual EffectWindowList stackingOrder() const; virtual void addRepaintFull(); + virtual void addRepaint( const QRect& r ); + virtual void addRepaint( int x, int y, int w, int h ); virtual QRect clientArea( clientAreaOption opt, const QPoint& p, int desktop ) const; virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ); @@ -54,6 +56,8 @@ class EffectsHandlerImpl : public EffectsHandler virtual void reserveElectricBorder( ElectricBorder border ); virtual void unreserveElectricBorder( ElectricBorder border ); virtual void reserveElectricBorderSwitching( bool reserve ); + + virtual unsigned long xrenderBufferPicture(); }; class EffectWindowImpl : public EffectWindow diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 99c4cc6303..0d13d87b33 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -3,6 +3,12 @@ macro(KWIN4_ADD_EFFECT name) kde4_automoc(kwin4_effect_${name} ${ARGN}) kde4_add_plugin(kwin4_effect_${name} ${ARGN}) target_link_libraries(kwin4_effect_${name} kwineffects ${KDE4_KDEUI_LIBS}) + if(OPENGL_FOUND) + target_link_libraries(kwin4_effect_${name} ${OPENGL_gl_LIBRARY}) + endif(OPENGL_FOUND) + if (X11_Xrender_FOUND) + target_link_libraries(kwin4_effect_${name} ${X11_Xrender_LIB}) + endif (X11_Xrender_FOUND) install(TARGETS kwin4_effect_${name} DESTINATION ${PLUGIN_INSTALL_DIR}) endmacro(KWIN4_ADD_EFFECT) @@ -11,7 +17,28 @@ include_directories( ${CMAKE_SOURCE_DIR}/workspace/kwin/lib ) -KWIN4_ADD_EFFECT(builtins presentwindows.cpp shadow.cpp diminactive.cpp) +SET(kwin4_effect_builtins_sources + presentwindows.cpp + diminactive.cpp + ) -install( FILES presentwindows.desktop shadow.desktop diminactive.desktop - DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) +if(OPENGL_FOUND) +SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} + shadow.cpp + showfps.cpp + ) +install( FILES + shadow.desktop + showfps.desktop + DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) +endif(OPENGL_FOUND) + +if (X11_Xrender_FOUND) +endif (X11_Xrender_FOUND) + +KWIN4_ADD_EFFECT(builtins ${kwin4_effect_builtins_sources}) + +install( FILES + presentwindows.desktop + diminactive.desktop + DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) diff --git a/effects/showfps.cpp b/effects/showfps.cpp index 896b3d4a96..c4ba53ee3c 100644 --- a/effects/showfps.cpp +++ b/effects/showfps.cpp @@ -8,21 +8,26 @@ You can Freely distribute this program under the GNU General Public License. See the file "COPYING" for the exact licensing terms. ******************************************************************/ +#include + #include "showfps.h" -#include - -#include -#include -#include +#include +#include #ifdef HAVE_OPENGL #include #endif +#ifdef HAVE_XRENDER +#include +#include +#endif namespace KWin { +KWIN_EFFECT( ShowFps, ShowFpsEffect ) + const int FPS_WIDTH = 10; const int MAX_TIME = 100; @@ -38,9 +43,10 @@ ShowFpsEffect::ShowFpsEffect() i < MAX_FPS; ++i ) frames[ i ] = 0; - alpha = options->effectShowFpsAlpha; - x = options->effectShowFpsX; - y = options->effectShowFpsY; + KConfigGroup config( KGlobal::config(), "EffectShowFps" ); + alpha = config.readEntry( "Alpha", 0.5 ); + x = config.readEntry( "X", -10000 ); + y = config.readEntry( "Y", 0 ); if( x == -10000 ) // there's no -0 :( x = displayWidth() - NUM_PAINTS - FPS_WIDTH; else if ( x < 0 ) @@ -76,17 +82,19 @@ void ShowFpsEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data if( fps > MAX_TIME ) fps = MAX_TIME; // keep it the same height #ifdef HAVE_OPENGL - if( dynamic_cast< SceneOpenGL* >( scene )) + if( effects->compositingType() == OpenGLCompositing) { paintGL( fps ); glFinish(); // make sure all rendering is done } - else #endif +#ifdef HAVE_XRENDER + if( effects->compositingType() == XRenderCompositing) { - paintX( fps ); + paintXrender( fps ); XSync( display(), False ); // make sure all rendering is done } +#endif } void ShowFpsEffect::paintGL( int fps ) @@ -154,7 +162,7 @@ void ShowFpsEffect::paintGL( int fps ) - differenly specified rectangles (X: width/height, O: x2,y2) - XRender uses pre-multiplied alpha */ -void ShowFpsEffect::paintX( int fps ) +void ShowFpsEffect::paintXrender( int fps ) { #ifdef HAVE_XRENDER Pixmap pixmap = XCreatePixmap( display(), rootWindow(), NUM_PAINTS + FPS_WIDTH, MAX_TIME, 32 ); @@ -214,7 +222,7 @@ void ShowFpsEffect::paintX( int fps ) XRenderFillRectangle( display(), PictOpSrc, p, &col, FPS_WIDTH + NUM_PAINTS - i, MAX_TIME - value, 1, value ); } 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 ); + effects->xrenderBufferPicture(), 0, 0, 0, 0, x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME ); XRenderFreePicture( display(), p ); #endif } @@ -225,7 +233,7 @@ void ShowFpsEffect::postPaintScreen() paints[ paints_pos ] = t.elapsed(); if( ++paints_pos == NUM_PAINTS ) paints_pos = 0; - workspace()->addRepaint( x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME ); + effects->addRepaint( x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME ); } } // namespace diff --git a/effects/showfps.desktop b/effects/showfps.desktop new file mode 100644 index 0000000000..16cbfa95df --- /dev/null +++ b/effects/showfps.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=ShowFps +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/showfps.h b/effects/showfps.h index e621bd38fd..f1dc375afd 100644 --- a/effects/showfps.h +++ b/effects/showfps.h @@ -11,7 +11,7 @@ License. See the file "COPYING" for the exact licensing terms. #ifndef KWIN_SHOWFPS_H #define KWIN_SHOWFPS_H -#include +#include #include @@ -28,7 +28,7 @@ class ShowFpsEffect virtual void postPaintScreen(); private: void paintGL( int fps ); - void paintX( int fps ); + void paintXrender( int fps ); QTime t; enum { NUM_PAINTS = 100 }; // remember time needed to paint this many paints int paints[ NUM_PAINTS ]; // time needed to paint diff --git a/lib/kwineffects.h b/lib/kwineffects.h index c9a15d6402..6b2854d172 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -185,6 +185,8 @@ class KWIN_EXPORT EffectsHandler // Repaints the entire workspace virtual void addRepaintFull() = 0; + virtual void addRepaint( const QRect& r ) = 0; + virtual void addRepaint( int x, int y, int w, int h ) = 0; // internal (used by kwin core or compositing code) virtual void startPaint(); @@ -207,6 +209,7 @@ class KWIN_EXPORT EffectsHandler virtual bool borderActivated( ElectricBorder border ); CompositingType compositingType() const { return compositing_type; } + virtual unsigned long xrenderBufferPicture() = 0; //void registerEffect( const QString& name, EffectFactory* factory ); void loadEffect( const QString& name ); diff --git a/lib/kwinglobals.h b/lib/kwinglobals.h index 5f68baf4e2..9f87bcbe1f 100644 --- a/lib/kwinglobals.h +++ b/lib/kwinglobals.h @@ -98,24 +98,36 @@ class KWIN_EXPORT ScreenPaintData }; inline -Display* display() +KWIN_EXPORT Display* display() { return QX11Info::display(); } inline -int displayWidth() +KWIN_EXPORT Window rootWindow() + { + return QX11Info::appRootWindow(); + } + +inline +KWIN_EXPORT Window xTime() + { + return QX11Info::appTime(); + } + +inline +KWIN_EXPORT int displayWidth() { return XDisplayWidth( display(), DefaultScreen( display())); } inline -int displayHeight() +KWIN_EXPORT int displayHeight() { return XDisplayHeight( display(), DefaultScreen( display())); } -QPoint KWIN_EXPORT cursorPos(); +KWIN_EXPORT QPoint cursorPos(); } // namespace diff --git a/options.cpp b/options.cpp index 77846a0f37..cf31684827 100644 --- a/options.cpp +++ b/options.cpp @@ -174,8 +174,8 @@ unsigned long Options::updateSettings() CmdAllWheel = mouseWheelCommand(config.readEntry("CommandAllWheel","Nothing")); //translucency settings - TODO - useTranslucency = _config->group("Notification Messages").readEntry("UseTranslucency", false); config.changeGroup("Translucency"); + useTranslucency = config.readEntry("UseTranslucency", true); translucentActiveWindows = config.readEntry("TranslucentActiveWindows", false); activeWindowOpacity = uint((config.readEntry("ActiveWindowOpacity", 100)/100.0)*0xFFFFFFFF); translucentInactiveWindows = config.readEntry("TranslucentInactiveWindows", false); @@ -194,6 +194,23 @@ unsigned long Options::updateSettings() removeShadowsOnResize = config.readEntry("RemoveShadowsOnResize", true); onlyDecoTranslucent = config.readEntry("OnlyDecoTranslucent", false); + refreshRate = config.readEntry( "RefreshRate", 0 ); + smoothScale = qBound( -1, config.readEntry( "SmoothScale", -1 ), 2 ); + + QString glmode = config.readEntry("GLMode", "TFP" ).upper(); + if( glmode == "TFP" ) + glMode = GLTFP; + else if( glmode == "SHM" ) + glMode = GLSHM; + else + glMode = GLFallback; + glAlwaysRebind = config.readEntry("GLAlwaysRebind", false ); + glDirect = config.readEntry("GLDirect", true ); + glVSync = config.readEntry("GLVSync", true ); + + config.changeGroup( "Effects" ); + defaultEffects = config.readEntry( "Load", QStringList() << "ShowFps" << "Fade" ); + // Read button tooltip animation effect from kdeglobals // Since we want to allow users to enable window decoration tooltips // and not kstyle tooltips and vise-versa, we don't read the diff --git a/options.h b/options.h index 1e703aa338..96ae309f10 100644 --- a/options.h +++ b/options.h @@ -299,6 +299,19 @@ class Options : public KDecorationOptions uint inactiveWindowShadowSize; uint dockShadowSize; bool onlyDecoTranslucent; + + uint refreshRate; + int smoothScale; // 0 = no, 1 = yes when transformed, + // 2 = try trilinear when transformed; else 1, + // -1 = auto + + enum GLMode { GLTFP, GLSHM, GLFallback }; + GLMode glMode; + bool glAlwaysRebind; + bool glDirect; + bool glVSync; + + QStringList defaultEffects; private: WindowOperation OpTitlebarDblClick; diff --git a/utils.h b/utils.h index 1c16ba2df7..1d564c13ab 100644 --- a/utils.h +++ b/utils.h @@ -239,19 +239,6 @@ void grabXServer(); void ungrabXServer(); bool grabbedXServer(); -inline -Window rootWindow() - { - return QX11Info::appRootWindow(); - } - -inline -Window xTime() - { - return QX11Info::appTime(); - } - - class Scene; extern Scene* scene; inline bool compositing() { return scene != NULL; }