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>
6
Copyright (C) 2010 Martin Gräßlin <kde@martin-graesslin.com>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*********************************************************************/
22
#include "showpaint.h"
24
#include <kwinconfig.h>
26
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
27
#include <kwinglutils.h>
29
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
31
#include <X11/extensions/Xrender.h>
41
KWIN_EFFECT(showpaint, ShowPaintEffect)
43
static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta,
47
ShowPaintEffect::ShowPaintEffect()
52
ShowPaintEffect::~ShowPaintEffect()
56
void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
59
effects->paintScreen(mask, region, data);
60
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
61
if (effects->compositingType() == OpenGLCompositing)
64
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
65
if (effects->compositingType() == XRenderCompositing)
68
if (++color_index == sizeof(colors) / sizeof(colors[ 0 ]))
72
void ShowPaintEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
75
effects->paintWindow(w, mask, region, data);
78
void ShowPaintEffect::paintGL()
80
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
81
#ifndef KWIN_HAVE_OPENGLES
82
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
84
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
86
vbo->setUseColor(true);
87
if (ShaderManager::instance()->isValid()) {
88
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
91
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
92
QColor color = colors[ color_index ];
96
verts.reserve(painted.rects().count() * 12);
97
foreach (const QRect & r, painted.rects()) {
98
verts << r.x() + r.width() << r.y();
99
verts << r.x() << r.y();
100
verts << r.x() << r.y() + r.height();
101
verts << r.x() << r.y() + r.height();
102
verts << r.x() + r.width() << r.y() + r.height();
103
verts << r.x() + r.width() << r.y();
105
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
106
vbo->render(GL_TRIANGLES);
107
if (ShaderManager::instance()->isValid()) {
108
ShaderManager::instance()->popShader();
111
#ifndef KWIN_HAVE_OPENGLES
117
void ShowPaintEffect::paintXrender()
119
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
122
const QColor& color = colors[ color_index ];
123
col.alpha = int(alpha * 0xffff);
124
col.red = int(alpha * 0xffff * color.red() / 255);
125
col.green = int(alpha * 0xffff * color.green() / 255);
126
col.blue = int(alpha * 0xffff * color.blue() / 255);
127
foreach (const QRect & r, painted.rects())
128
XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
129
&col, r.x(), r.y(), r.width(), r.height());