From b33ce330ca4fd58a1fe229c567f599223842185e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Tue, 23 Oct 2007 13:41:59 +0000 Subject: [PATCH] Another testing effect - show where painting is taking place. Quite interesting, even for uses outside of KWin. svn path=/trunk/KDE/kdebase/workspace/; revision=728502 --- effects/CMakeLists.txt | 4 +- effects/showpaint.cpp | 101 ++++++++++++++++++++++++++++++++++++++ effects/showpaint.desktop | 16 ++++++ effects/showpaint.h | 35 +++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 effects/showpaint.cpp create mode 100644 effects/showpaint.desktop create mode 100644 effects/showpaint.h diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index b187624b03..7fe559e275 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -113,13 +113,15 @@ if(OPENGL_FOUND) DESTINATION ${DATA_INSTALL_DIR}/kwin ) endif(OPENGL_FOUND) -# showfps - need both xrender and opengl +# showfps, showpaint - need both xrender and opengl if( OPENGL_FOUND AND X11_Xrender_FOUND ) SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} showfps.cpp + showpaint.cpp ) install( FILES showfps.desktop + showpaint.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) endif( OPENGL_FOUND AND X11_Xrender_FOUND ) diff --git a/effects/showpaint.cpp b/effects/showpaint.cpp new file mode 100644 index 0000000000..043e530641 --- /dev/null +++ b/effects/showpaint.cpp @@ -0,0 +1,101 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#include "showpaint.h" + +#include + +#ifdef HAVE_OPENGL +#include +#endif +#ifdef HAVE_XRENDER +#include +#include +#endif + +#include + +#include + +namespace KWin +{ + +KWIN_EFFECT( showpaint, ShowPaintEffect ) + +static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, + Qt::yellow, Qt::gray }; + +ShowPaintEffect::ShowPaintEffect() + : color_index( 0 ) + { + } + +void ShowPaintEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) + { + painted = QRegion(); + effects->paintScreen( mask, region, data ); +#ifdef HAVE_OPENGL + if( effects->compositingType() == OpenGLCompositing) + paintGL(); +#endif +#ifdef HAVE_XRENDER + if( effects->compositingType() == XRenderCompositing) + paintXrender(); +#endif + if( ++color_index == sizeof( colors ) / sizeof( colors[ 0 ] )) + color_index = 0; + } + +void ShowPaintEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) + { + painted |= region; + effects->paintWindow( w, mask, region, data ); + } + +// TODO I think we need some kind of generic paintRect() +void ShowPaintEffect::paintGL() + { +#ifdef HAVE_OPENGL + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + float alpha = 0.2; + const QColor& color = colors[ color_index ]; + glColor4f( color.red() / 255., color.green() / 255., color.blue() / 255., alpha ); + glBegin( GL_QUADS ); + foreach( QRect r, painted.rects()) + { + glVertex2i( r.x(), r.y()); + glVertex2i( r.x() + r.width(), r.y()); + glVertex2i( r.x() + r.width(), r.y() + r.height()); + glVertex2i( r.x(), r.y() + r.height()); + } + glEnd(); + glPopAttrib(); +#endif + } + +void ShowPaintEffect::paintXrender() + { +#ifdef HAVE_XRENDER + XRenderColor col; + int alpha = 0.2; + const QColor& color = colors[ color_index ]; + col.alpha = int( alpha * 0xffff ); + col.red = int( alpha * 0xffff * color.red() / 255 ); + col.green = int( alpha * 0xffff * color.green() / 255 ); + col.blue= int( alpha * 0xffff * color.blue() / 255 ); + foreach( QRect r, painted.rects()) + XRenderFillRectangle( display(), PictOpOver, effects->xrenderBufferPicture(), + &col, r.x(), r.y(), r.width(), r.height()); +#endif + } + +} // namespace diff --git a/effects/showpaint.desktop b/effects/showpaint.desktop new file mode 100644 index 0000000000..eb01923f9d --- /dev/null +++ b/effects/showpaint.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Show Paint +Comment=Shows areas painted by KWin + +Type=Service +ServiceTypes=KWin/Effect +X-KDE-PluginInfo-Author=Luboš Luňák +X-KDE-PluginInfo-Email=l.lunak@kde.org +X-KDE-PluginInfo-Name=kwin4_effect_showpaint +X-KDE-PluginInfo-Version=0.1.0 +X-KDE-PluginInfo-Category=Misc +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/showpaint.h b/effects/showpaint.h new file mode 100644 index 0000000000..4c821d49a1 --- /dev/null +++ b/effects/showpaint.h @@ -0,0 +1,35 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Lubos Lunak + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_SHOWPAINT_H +#define KWIN_SHOWPAINT_H + +#include + +namespace KWin +{ + +class ShowPaintEffect + : public Effect + { + public: + ShowPaintEffect(); + virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); + virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); + private: + void paintGL(); + void paintXrender(); + QRegion painted; // what's painted in one pass + int color_index; + }; + +} // namespace + +#endif