add more spacing
[personal-kdebase.git] / workspace / kwin / effects / showpaint.cpp
blob3a623c9b03991eff86ef38a8d6d2de7b9ca7f53f
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "showpaint.h"
23 #include <kwinconfig.h>
25 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
26 #include <GL/gl.h>
27 #endif
28 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
29 #include <X11/Xlib.h>
30 #include <X11/extensions/Xrender.h>
31 #endif
33 #include <math.h>
35 #include <qcolor.h>
37 namespace KWin
40 KWIN_EFFECT( showpaint, ShowPaintEffect )
42 static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta,
43 Qt::yellow, Qt::gray };
45 ShowPaintEffect::ShowPaintEffect()
46 : color_index( 0 )
50 void ShowPaintEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
52 painted = QRegion();
53 effects->paintScreen( mask, region, data );
54 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
55 if( effects->compositingType() == OpenGLCompositing)
56 paintGL();
57 #endif
58 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
59 if( effects->compositingType() == XRenderCompositing)
60 paintXrender();
61 #endif
62 if( ++color_index == sizeof( colors ) / sizeof( colors[ 0 ] ))
63 color_index = 0;
66 void ShowPaintEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
68 painted |= region;
69 effects->paintWindow( w, mask, region, data );
72 // TODO I think we need some kind of generic paintRect()
73 void ShowPaintEffect::paintGL()
75 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
76 glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
77 glEnable( GL_BLEND );
78 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
79 float alpha = 0.2;
80 const QColor& color = colors[ color_index ];
81 glColor4f( color.red() / 255., color.green() / 255., color.blue() / 255., alpha );
82 glBegin( GL_QUADS );
83 foreach( const QRect &r, painted.rects())
85 glVertex2i( r.x(), r.y());
86 glVertex2i( r.x() + r.width(), r.y());
87 glVertex2i( r.x() + r.width(), r.y() + r.height());
88 glVertex2i( r.x(), r.y() + r.height());
90 glEnd();
91 glPopAttrib();
92 #endif
95 void ShowPaintEffect::paintXrender()
97 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
98 XRenderColor col;
99 float alpha = 0.2;
100 const QColor& color = colors[ color_index ];
101 col.alpha = int( alpha * 0xffff );
102 col.red = int( alpha * 0xffff * color.red() / 255 );
103 col.green = int( alpha * 0xffff * color.green() / 255 );
104 col.blue= int( alpha * 0xffff * color.blue() / 255 );
105 foreach( const QRect &r, painted.rects())
106 XRenderFillRectangle( display(), PictOpOver, effects->xrenderBufferPicture(),
107 &col, r.x(), r.y(), r.width(), r.height());
108 #endif
111 } // namespace