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
28 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
30 #include <X11/extensions/Xrender.h>
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()
50 void ShowPaintEffect::paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
)
53 effects
->paintScreen( mask
, region
, data
);
54 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
55 if( effects
->compositingType() == OpenGLCompositing
)
58 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
59 if( effects
->compositingType() == XRenderCompositing
)
62 if( ++color_index
== sizeof( colors
) / sizeof( colors
[ 0 ] ))
66 void ShowPaintEffect::paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
)
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
);
78 glBlendFunc( GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
80 const QColor
& color
= colors
[ color_index
];
81 glColor4f( color
.red() / 255., color
.green() / 255., color
.blue() / 255., alpha
);
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());
95 void ShowPaintEffect::paintXrender()
97 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
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());