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.
|
|
|
|
|
2020-08-02 22:10:35 +00:00
|
|
|
SPDX-FileCopyrightText: 2007 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2010 Martin Gräßlin <mgraesslin@kde.org>
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2020-08-02 22:10:35 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
2007-11-27 19:40:25 +00:00
|
|
|
*********************************************************************/
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
#include "showpaint.h"
|
|
|
|
|
2010-12-07 20:50:43 +00:00
|
|
|
#include <kwinglutils.h>
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2013-01-29 08:25:14 +00:00
|
|
|
#include <xcb/render.h>
|
2007-10-23 13:41:59 +00:00
|
|
|
#endif
|
|
|
|
|
[effects/showpaint] Use a shortcut to toggle the effect
Summary:
The Show Paint effect is useful when debugging repaint regions issued by
effects. The only headache with it is necessity to enable/disable it.
Consider the following workflow:
* Do some change to an effect;
* Compile KWin (or the effect);
* Go to System Settings and enable the Show Paint effect;
* Test effect, check repaint regions, etc;
* Disable the Show Paint effect;
* Go to the step 1.
This workflow is really exhausting. Also, when testing repaints in a
nested compositor, things become quite messy.
Because purpose of this effect is to debug repaints (and because this
effect is not meant for daily usage), I think that's fine to change
how it's activated.
This patch improves the workflow by changing the way how this effect
gets activated. Instead of enabling/disabling it, one can just use a shortcut
to activate or deactivate the effect.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: broulik, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15703
2018-09-23 07:49:17 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
#include <QAction>
|
2013-06-21 12:23:36 +00:00
|
|
|
#include <QPainter>
|
2007-10-23 13:41:59 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2018-09-11 11:57:43 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
[effects/showpaint] Use a shortcut to toggle the effect
Summary:
The Show Paint effect is useful when debugging repaint regions issued by
effects. The only headache with it is necessity to enable/disable it.
Consider the following workflow:
* Do some change to an effect;
* Compile KWin (or the effect);
* Go to System Settings and enable the Show Paint effect;
* Test effect, check repaint regions, etc;
* Disable the Show Paint effect;
* Go to the step 1.
This workflow is really exhausting. Also, when testing repaints in a
nested compositor, things become quite messy.
Because purpose of this effect is to debug repaints (and because this
effect is not meant for daily usage), I think that's fine to change
how it's activated.
This patch improves the workflow by changing the way how this effect
gets activated. Instead of enabling/disabling it, one can just use a shortcut
to activate or deactivate the effect.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: broulik, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15703
2018-09-23 07:49:17 +00:00
|
|
|
ShowPaintEffect::ShowPaintEffect()
|
|
|
|
{
|
|
|
|
auto *toggleAction = new QAction(this);
|
|
|
|
toggleAction->setObjectName(QStringLiteral("Toggle"));
|
|
|
|
toggleAction->setText(i18n("Toggle Show Paint"));
|
|
|
|
KGlobalAccel::self()->setDefaultShortcut(toggleAction, {});
|
|
|
|
KGlobalAccel::self()->setShortcut(toggleAction, {});
|
|
|
|
effects->registerGlobalShortcut({}, toggleAction);
|
|
|
|
|
|
|
|
connect(toggleAction, &QAction::triggered, this, &ShowPaintEffect::toggle);
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void ShowPaintEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-09-11 11:57:43 +00:00
|
|
|
m_painted = QRegion();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintScreen(mask, region, data);
|
2018-09-11 11:57:43 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2015-11-26 15:25:00 +00:00
|
|
|
paintGL(data.projectionMatrix());
|
2018-09-11 11:57:43 +00:00
|
|
|
}
|
2007-12-17 14:14:53 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2018-09-11 11:57:43 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing) {
|
2007-10-23 13:41:59 +00:00
|
|
|
paintXrender();
|
2018-09-11 11:57:43 +00:00
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
#endif
|
2013-06-21 12:23:36 +00:00
|
|
|
if (effects->compositingType() == QPainterCompositing) {
|
|
|
|
paintQPainter();
|
|
|
|
}
|
2018-09-11 11:57:43 +00:00
|
|
|
if (++m_colorIndex == s_colors.count()) {
|
|
|
|
m_colorIndex = 0;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2018-09-11 11:57:43 +00:00
|
|
|
void ShowPaintEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-09-11 11:57:43 +00:00
|
|
|
m_painted |= region;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-10-23 13:41:59 +00:00
|
|
|
|
2015-11-26 15:25:00 +00:00
|
|
|
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);
|
2015-11-26 15:25:00 +00:00
|
|
|
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);
|
2018-09-11 11:57:43 +00:00
|
|
|
QColor color = s_colors[m_colorIndex];
|
|
|
|
color.setAlphaF(s_alpha);
|
2010-12-07 20:50:43 +00:00
|
|
|
vbo->setColor(color);
|
|
|
|
QVector<float> verts;
|
2018-09-11 11:57:43 +00:00
|
|
|
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();
|
|
|
|
}
|
2018-09-11 11:57:43 +00:00
|
|
|
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);
|
|
|
|
}
|
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
|
2013-01-29 08:25:14 +00:00
|
|
|
xcb_render_color_t col;
|
2018-09-11 11:57:43 +00:00
|
|
|
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;
|
2018-09-11 11:57:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_OVER, effects->xrenderBufferPicture(), col, rects.count(), rects.constData());
|
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
|
|
|
|
2013-06-21 12:23:36 +00:00
|
|
|
void ShowPaintEffect::paintQPainter()
|
|
|
|
{
|
2018-09-11 11:57:43 +00:00
|
|
|
QColor color = s_colors[m_colorIndex];
|
|
|
|
color.setAlphaF(s_alpha);
|
|
|
|
for (const QRect &r : m_painted) {
|
2013-06-21 12:23:36 +00:00
|
|
|
effects->scenePainter()->fillRect(r, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[effects/showpaint] Use a shortcut to toggle the effect
Summary:
The Show Paint effect is useful when debugging repaint regions issued by
effects. The only headache with it is necessity to enable/disable it.
Consider the following workflow:
* Do some change to an effect;
* Compile KWin (or the effect);
* Go to System Settings and enable the Show Paint effect;
* Test effect, check repaint regions, etc;
* Disable the Show Paint effect;
* Go to the step 1.
This workflow is really exhausting. Also, when testing repaints in a
nested compositor, things become quite messy.
Because purpose of this effect is to debug repaints (and because this
effect is not meant for daily usage), I think that's fine to change
how it's activated.
This patch improves the workflow by changing the way how this effect
gets activated. Instead of enabling/disabling it, one can just use a shortcut
to activate or deactivate the effect.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: broulik, davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D15703
2018-09-23 07:49:17 +00:00
|
|
|
bool ShowPaintEffect::isActive() const
|
|
|
|
{
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowPaintEffect::toggle()
|
|
|
|
{
|
|
|
|
m_active = !m_active;
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
2018-09-11 11:57:43 +00:00
|
|
|
} // namespace KWin
|