2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-10-23 13:41:59 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
2010-12-07 20:50:43 +00:00
|
|
|
Copyright (C) 2010 Martin Gräßlin <kde@martin-graesslin.com>
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
#include "showpaint.h"
|
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kwinconfig.h>
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2010-12-07 20:50:43 +00:00
|
|
|
#include <kwinglutils.h>
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2007-10-23 13:41:59 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <qcolor.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(showpaint, ShowPaintEffect)
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
static QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta,
|
2011-01-30 14:34:42 +00:00
|
|
|
Qt::yellow, Qt::gray
|
|
|
|
};
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
ShowPaintEffect::ShowPaintEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: color_index(0)
|
|
|
|
{
|
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2010-12-07 20:50:43 +00:00
|
|
|
ShowPaintEffect::~ShowPaintEffect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
|
|
|
{
|
2007-10-23 13:41:59 +00:00
|
|
|
painted = QRegion();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintScreen(mask, region, data);
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing())
|
2007-10-23 13:41:59 +00:00
|
|
|
paintGL();
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing)
|
2007-10-23 13:41:59 +00:00
|
|
|
paintXrender();
|
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
if (++color_index == sizeof(colors) / sizeof(colors[ 0 ]))
|
2007-10-23 13:41:59 +00:00
|
|
|
color_index = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ShowPaintEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2007-10-23 13:41:59 +00:00
|
|
|
painted |= region;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
void ShowPaintEffect::paintGL()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-12-11 14:53:15 +00:00
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setUseColor(true);
|
2012-09-21 09:25:08 +00:00
|
|
|
ShaderBinder binder(ShaderManager::ColorShader);
|
2011-01-30 14:34:42 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2010-12-07 20:50:43 +00:00
|
|
|
QColor color = colors[ color_index ];
|
|
|
|
color.setAlphaF(0.2);
|
|
|
|
vbo->setColor(color);
|
|
|
|
QVector<float> verts;
|
2011-01-30 14:34:42 +00:00
|
|
|
verts.reserve(painted.rects().count() * 12);
|
|
|
|
foreach (const QRect & r, painted.rects()) {
|
2010-12-07 20:50:43 +00:00
|
|
|
verts << r.x() + r.width() << r.y();
|
|
|
|
verts << r.x() << r.y();
|
|
|
|
verts << r.x() << r.y() + r.height();
|
|
|
|
verts << r.x() << r.y() + r.height();
|
|
|
|
verts << r.x() + r.width() << r.y() + r.height();
|
|
|
|
verts << r.x() + r.width() << r.y();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
|
2010-12-07 20:50:43 +00:00
|
|
|
vbo->render(GL_TRIANGLES);
|
2011-01-30 14:34:42 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
void ShowPaintEffect::paintXrender()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2007-10-23 13:41:59 +00:00
|
|
|
XRenderColor col;
|
2008-06-28 11:30:52 +00:00
|
|
|
float alpha = 0.2;
|
2007-10-23 13:41:59 +00:00
|
|
|
const QColor& color = colors[ color_index ];
|
2011-01-30 14:34:42 +00:00
|
|
|
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 (const QRect & r, painted.rects())
|
|
|
|
XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
|
|
|
|
&col, r.x(), r.y(), r.width(), r.height());
|
2007-10-23 13:41:59 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
} // namespace
|