2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2014-07-22 11:11:19 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-07-22 11:11:19 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "decorationrenderer.h"
|
|
|
|
#include "decoratedclient.h"
|
2020-07-05 19:52:23 +00:00
|
|
|
#include "decorations/decorations_logging.h"
|
2014-07-23 07:20:28 +00:00
|
|
|
#include "deleted.h"
|
2017-10-30 13:27:48 +00:00
|
|
|
#include "abstract_client.h"
|
2017-11-01 17:54:21 +00:00
|
|
|
#include "screens.h"
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
#include <KDecoration2/Decoration>
|
|
|
|
#include <KDecoration2/DecoratedClient>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace Decoration
|
|
|
|
{
|
|
|
|
|
|
|
|
Renderer::Renderer(DecoratedClientImpl *client)
|
|
|
|
: QObject(client)
|
|
|
|
, m_client(client)
|
|
|
|
, m_imageSizesDirty(true)
|
|
|
|
{
|
2017-11-01 17:54:21 +00:00
|
|
|
auto markImageSizesDirty = [this]{
|
2020-01-26 13:08:52 +00:00
|
|
|
schedule(m_client->client()->rect());
|
2017-11-01 17:54:21 +00:00
|
|
|
m_imageSizesDirty = true;
|
|
|
|
};
|
|
|
|
connect(client->client(), &AbstractClient::screenScaleChanged, this, markImageSizesDirty);
|
2014-07-22 11:11:19 +00:00
|
|
|
connect(client->decoration(), &KDecoration2::Decoration::bordersChanged, this, markImageSizesDirty);
|
2020-01-26 13:08:52 +00:00
|
|
|
connect(client->decoratedClient(), &KDecoration2::DecoratedClient::sizeChanged, this, markImageSizesDirty);
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::~Renderer() = default;
|
|
|
|
|
|
|
|
void Renderer::schedule(const QRect &rect)
|
|
|
|
{
|
|
|
|
m_scheduled = m_scheduled.united(rect);
|
|
|
|
emit renderScheduled(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion Renderer::getScheduled()
|
|
|
|
{
|
|
|
|
QRegion region = m_scheduled;
|
|
|
|
m_scheduled = QRegion();
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage Renderer::renderToImage(const QRect &geo)
|
|
|
|
{
|
2014-07-23 07:20:28 +00:00
|
|
|
Q_ASSERT(m_client);
|
2017-11-01 17:54:21 +00:00
|
|
|
auto dpr = client()->client()->screenScale();
|
2020-07-05 19:52:23 +00:00
|
|
|
|
|
|
|
// Guess the pixel format of the X pixmap into which the QImage will be copied.
|
|
|
|
QImage::Format format;
|
|
|
|
const int depth = client()->client()->depth();
|
|
|
|
switch (depth) {
|
|
|
|
case 30:
|
|
|
|
format = QImage::Format_A2RGB30_Premultiplied;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
format = QImage::Format_ARGB32_Premultiplied;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qCCritical(KWIN_DECORATIONS) << "Unsupported client depth" << depth;
|
|
|
|
format = QImage::Format_ARGB32_Premultiplied;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
QImage image(geo.width() * dpr, geo.height() * dpr, format);
|
2017-11-01 17:54:21 +00:00
|
|
|
image.setDevicePixelRatio(dpr);
|
2014-07-22 11:11:19 +00:00
|
|
|
image.fill(Qt::transparent);
|
|
|
|
QPainter p(&image);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
2017-11-01 17:54:21 +00:00
|
|
|
p.setWindow(QRect(geo.topLeft(), geo.size() * dpr));
|
2014-07-22 11:11:19 +00:00
|
|
|
p.setClipRect(geo);
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
renderToPainter(&p, geo);
|
2014-07-22 11:11:19 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
[scene] Fix decoration texture bleeding
Summary:
Quite long time ago, window decorations were painted on real X11 windows.
The nicest thing about that approach is that we get both contents of the
client and the frame window at the same time. However, somewhere around
KDE 4.2 - 4.3 times, decoration rendering architecture had been changed
to what we have now.
I've mentioned the previous decoration rendering design because it didn't
have a problem that the new design has, namely the texture bleeding issue.
In the name of better performance, opengl scene puts all decoration parts
to an atlas. This is totally reasonable, however we must be super cautious
about things such as the GL_LINEAR filter.
The GL_LINEAR filter may need to sample a couple of neighboring texels
in order to produce the final texel value. However, since all decoration
parts now live in a single texture, we have to make sure that we don't
sample texels that belong to another decoration part.
This patch fixes the texture bleeding problem by padding each individual
decoration part in the atlas. There is another solution for this problem
though. We could render a window into an offscreen texture and then map
that texture on the transformed window geometry. This would work well and
we definitely need an offscreen rendering path in the opengl scene,
however it's not feasible at the moment since we need to break the window
quads API. Also, it would be great to have as less as possible stuff going
on between invocation of Scene::Window::performPaint() and getting the
corresponding pixel data on the screen.
There is a good chance that the new padding stuff may make you vomit. If
it does so, I'm all ears for the suggestions how to make the code more
nicer.
BUG: 257566
BUG: 360549
CCBUG: 412573
FIXED-IN: 5.18.0
Reviewers: #kwin
Subscribers: fredrik, kwin, fvogt
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D25611
2019-11-28 12:00:58 +00:00
|
|
|
void Renderer::renderToPainter(QPainter *painter, const QRect &rect)
|
|
|
|
{
|
|
|
|
client()->decoration()->paint(painter, rect);
|
|
|
|
}
|
|
|
|
|
2014-07-23 07:20:28 +00:00
|
|
|
void Renderer::reparent(Deleted *deleted)
|
|
|
|
{
|
|
|
|
setParent(deleted);
|
|
|
|
m_client = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
}
|