Move X11 specific logic from DecorationRenderer to X11DecorationRenderer

This commit is contained in:
Vlad Zahorodnii 2023-03-04 14:39:03 +02:00
parent f9b9ca8d1f
commit 3b12058135
3 changed files with 27 additions and 38 deletions

View file

@ -11,16 +11,12 @@
#include "decorations/decoratedclient.h"
#include "deleted.h"
#include "scene/workspacescene.h"
#include "utils/common.h"
#include "window.h"
#include <cmath>
#include <KDecoration2/DecoratedClient>
#include <KDecoration2/Decoration>
#include <QPainter>
namespace KWin
{
@ -87,38 +83,6 @@ void DecorationRenderer::setDevicePixelRatio(qreal dpr)
}
}
QImage DecorationRenderer::renderToImage(const QRect &geo)
{
Q_ASSERT(m_client);
// Guess the pixel format of the X pixmap into which the QImage will be copied.
QImage::Format format;
const int depth = client()->window()->depth();
switch (depth) {
case 30:
format = QImage::Format_A2RGB30_Premultiplied;
break;
case 24:
case 32:
format = QImage::Format_ARGB32_Premultiplied;
break;
default:
qCCritical(KWIN_CORE) << "Unsupported client depth" << depth;
format = QImage::Format_ARGB32_Premultiplied;
break;
};
QImage image(geo.width() * m_devicePixelRatio, geo.height() * m_devicePixelRatio, format);
image.setDevicePixelRatio(m_devicePixelRatio);
image.fill(Qt::transparent);
QPainter p(&image);
p.setRenderHint(QPainter::Antialiasing);
p.setWindow(QRect(geo.topLeft(), geo.size() * effectiveDevicePixelRatio()));
p.setClipRect(geo);
renderToPainter(&p, geo);
return image;
}
void DecorationRenderer::renderToPainter(QPainter *painter, const QRect &rect)
{
client()->decoration()->paint(painter, rect);

View file

@ -61,7 +61,6 @@ protected:
{
m_imageSizesDirty = false;
}
QImage renderToImage(const QRect &geo);
void renderToPainter(QPainter *painter, const QRect &rect);
private:

View file

@ -46,6 +46,7 @@
#include <QFile>
#include <QFileInfo>
#include <QMouseEvent>
#include <QPainter>
#include <QProcess>
// xcb
#include <xcb/xcb_icccm.h>
@ -194,7 +195,32 @@ void X11DecorationRenderer::render(const QRegion &region)
if (!geo.isValid()) {
return;
}
QImage image = renderToImage(geo);
// Guess the pixel format of the X pixmap into which the QImage will be copied.
QImage::Format format;
const int depth = client()->window()->depth();
switch (depth) {
case 30:
format = QImage::Format_A2RGB30_Premultiplied;
break;
case 24:
case 32:
format = QImage::Format_ARGB32_Premultiplied;
break;
default:
qCCritical(KWIN_CORE) << "Unsupported client depth" << depth;
format = QImage::Format_ARGB32_Premultiplied;
break;
};
QImage image(geo.width(), geo.height(), format);
image.fill(Qt::transparent);
QPainter p(&image);
p.setRenderHint(QPainter::Antialiasing);
p.setWindow(geo);
p.setClipRect(geo);
renderToPainter(&p, geo);
xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, client()->window()->frameId(), m_gc,
image.width(), image.height(), geo.x(), geo.y(), 0, client()->window()->depth(),
image.sizeInBytes(), image.constBits());