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
This commit is contained in:
Luboš Luňák 2007-10-23 13:41:59 +00:00
parent 76a9bdcc85
commit b33ce330ca
4 changed files with 155 additions and 1 deletions

View file

@ -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 )

101
effects/showpaint.cpp Normal file
View file

@ -0,0 +1,101 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
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 <config-X11.h>
#ifdef HAVE_OPENGL
#include <GL/gl.h>
#endif
#ifdef HAVE_XRENDER
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#endif
#include <math.h>
#include <qcolor.h>
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

16
effects/showpaint.desktop Normal file
View file

@ -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

35
effects/showpaint.h Normal file
View file

@ -0,0 +1,35 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
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 <kwineffects.h>
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