kwin/effects/showpaint/showpaint.cpp

127 lines
3.9 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2010 Martin Gräßlin <mgraesslin@kde.org>
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/>.
*********************************************************************/
#include "showpaint.h"
2010-12-07 20:50:43 +00:00
#include <kwinglutils.h>
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
2013-01-29 08:25:14 +00:00
#include <xcb/render.h>
#endif
#include <QPainter>
namespace KWin
{
static const qreal s_alpha = 0.2;
static const QVector<QColor> s_colors {
Qt::red,
Qt::green,
Qt::blue,
Qt::cyan,
Qt::magenta,
Qt::yellow,
Qt::gray
};
void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData &data)
2011-01-30 14:34:42 +00:00
{
m_painted = QRegion();
2011-01-30 14:34:42 +00:00
effects->paintScreen(mask, region, data);
if (effects->isOpenGLCompositing()) {
paintGL(data.projectionMatrix());
}
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
if (effects->compositingType() == XRenderCompositing) {
paintXrender();
}
#endif
if (effects->compositingType() == QPainterCompositing) {
paintQPainter();
}
if (++m_colorIndex == s_colors.count()) {
m_colorIndex = 0;
}
2011-01-30 14:34:42 +00:00
}
void ShowPaintEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
2011-01-30 14:34:42 +00:00
{
m_painted |= region;
2011-01-30 14:34:42 +00:00
effects->paintWindow(w, mask, region, data);
}
void ShowPaintEffect::paintGL(const QMatrix4x4 &projection)
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);
ShaderBinder binder(ShaderTrait::UniformColor);
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projection);
2011-01-30 14:34:42 +00:00
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
QColor color = s_colors[m_colorIndex];
color.setAlphaF(s_alpha);
2010-12-07 20:50:43 +00:00
vbo->setColor(color);
QVector<float> verts;
verts.reserve(m_painted.rectCount() * 12);
for (const QRect &r : m_painted) {
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();
}
vbo->setData(verts.count() / 2, 2, verts.data(), nullptr);
2010-12-07 20:50:43 +00:00
vbo->render(GL_TRIANGLES);
2011-01-30 14:34:42 +00:00
glDisable(GL_BLEND);
}
void ShowPaintEffect::paintXrender()
2011-01-30 14:34:42 +00:00
{
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
2013-01-29 08:25:14 +00:00
xcb_render_color_t col;
const QColor &color = s_colors[m_colorIndex];
col.alpha = int(s_alpha * 0xffff);
col.red = int(s_alpha * 0xffff * color.red() / 255);
col.green = int(s_alpha * 0xffff * color.green() / 255);
col.blue = int(s_alpha * 0xffff * color.blue() / 255);
2013-01-29 08:25:14 +00:00
QVector<xcb_rectangle_t> rects;
rects.reserve(m_painted.rectCount());
for (const QRect &r : m_painted) {
2013-01-29 08:25:14 +00:00
xcb_rectangle_t rect = {int16_t(r.x()), int16_t(r.y()), uint16_t(r.width()), uint16_t(r.height())};
rects << rect;
}
xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_OVER, effects->xrenderBufferPicture(), col, rects.count(), rects.constData());
#endif
2011-01-30 14:34:42 +00:00
}
void ShowPaintEffect::paintQPainter()
{
QColor color = s_colors[m_colorIndex];
color.setAlphaF(s_alpha);
for (const QRect &r : m_painted) {
effects->scenePainter()->fillRect(r, color);
}
}
} // namespace KWin