2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "backingstore.h"
|
2019-08-26 07:44:04 +00:00
|
|
|
#include "window.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
#include "internal_client.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace QPA
|
|
|
|
{
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
BackingStore::BackingStore(QWindow *window)
|
|
|
|
: QPlatformBackingStore(window)
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BackingStore::~BackingStore() = default;
|
|
|
|
|
|
|
|
QPaintDevice *BackingStore::paintDevice()
|
|
|
|
{
|
|
|
|
return &m_backBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackingStore::resize(const QSize &size, const QRegion &staticContents)
|
|
|
|
{
|
|
|
|
Q_UNUSED(staticContents)
|
2019-08-26 07:44:04 +00:00
|
|
|
|
|
|
|
if (m_backBuffer.size() == size) {
|
2015-08-14 14:52:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-26 07:44:04 +00:00
|
|
|
|
|
|
|
const QPlatformWindow *platformWindow = static_cast<QPlatformWindow *>(window()->handle());
|
|
|
|
const qreal devicePixelRatio = platformWindow->devicePixelRatio();
|
|
|
|
|
|
|
|
m_backBuffer = QImage(size * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
m_backBuffer.setDevicePixelRatio(devicePixelRatio);
|
|
|
|
|
|
|
|
m_frontBuffer = QImage(size * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
m_frontBuffer.setDevicePixelRatio(devicePixelRatio);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
static void blitImage(const QImage &source, QImage &target, const QRect &rect)
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
Q_ASSERT(source.format() == QImage::Format_ARGB32_Premultiplied);
|
|
|
|
Q_ASSERT(target.format() == QImage::Format_ARGB32_Premultiplied);
|
2019-01-11 22:48:04 +00:00
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
const int devicePixelRatio = target.devicePixelRatio();
|
|
|
|
|
|
|
|
const int x = rect.x() * devicePixelRatio;
|
|
|
|
const int y = rect.y() * devicePixelRatio;
|
|
|
|
const int width = rect.width() * devicePixelRatio;
|
|
|
|
const int height = rect.height() * devicePixelRatio;
|
|
|
|
|
|
|
|
for (int i = y; i < y + height; ++i) {
|
|
|
|
const uint32_t *in = reinterpret_cast<const uint32_t *>(source.scanLine(i));
|
|
|
|
uint32_t *out = reinterpret_cast<uint32_t *>(target.scanLine(i));
|
|
|
|
std::copy(in + x, in + x + width, out + x);
|
2017-07-06 17:07:01 +00:00
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
static void blitImage(const QImage &source, QImage &target, const QRegion ®ion)
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
for (const QRect &rect : region) {
|
|
|
|
blitImage(source, target, rect);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
void BackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset)
|
2019-01-11 22:48:04 +00:00
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
Q_UNUSED(offset)
|
|
|
|
|
|
|
|
Window *platformWindow = static_cast<Window *>(window->handle());
|
|
|
|
InternalClient *client = platformWindow->client();
|
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
blitImage(m_backBuffer, m_frontBuffer, region);
|
|
|
|
|
|
|
|
client->present(m_frontBuffer, region);
|
2019-01-11 22:48:04 +00:00
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
}
|