2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-10-02 08:44:29 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-10-02 08:44:29 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-10-02 08:44:29 +00:00
|
|
|
#include "scene_qpainter_virtual_backend.h"
|
|
|
|
#include "virtual_backend.h"
|
|
|
|
#include "cursor.h"
|
2016-11-07 23:46:50 +00:00
|
|
|
#include "screens.h"
|
2015-10-02 08:44:29 +00:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
VirtualQPainterBackend::VirtualQPainterBackend(VirtualBackend *backend)
|
|
|
|
: QPainterBackend()
|
|
|
|
, m_backend(backend)
|
|
|
|
{
|
2016-11-07 23:46:50 +00:00
|
|
|
connect(screens(), &Screens::changed, this, &VirtualQPainterBackend::createOutputs);
|
|
|
|
createOutputs();
|
2015-10-02 08:44:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VirtualQPainterBackend::~VirtualQPainterBackend() = default;
|
|
|
|
|
2016-11-07 23:46:50 +00:00
|
|
|
QImage *VirtualQPainterBackend::bufferForScreen(int screen)
|
|
|
|
{
|
|
|
|
return &m_backBuffers[screen];
|
2015-10-02 08:44:29 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 13:35:15 +00:00
|
|
|
bool VirtualQPainterBackend::needsFullRepaint(int screenId) const
|
2015-10-02 08:44:29 +00:00
|
|
|
{
|
2020-11-09 13:35:15 +00:00
|
|
|
Q_UNUSED(screenId)
|
2015-10-02 08:44:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:35:15 +00:00
|
|
|
void VirtualQPainterBackend::prepareRenderingFrame(int screenId)
|
2015-10-02 08:44:29 +00:00
|
|
|
{
|
2020-11-09 13:35:15 +00:00
|
|
|
Q_UNUSED(screenId)
|
2015-10-02 08:44:29 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 23:46:50 +00:00
|
|
|
void VirtualQPainterBackend::createOutputs()
|
2015-10-02 08:44:29 +00:00
|
|
|
{
|
2016-11-07 23:46:50 +00:00
|
|
|
m_backBuffers.clear();
|
|
|
|
for (int i = 0; i < screens()->count(); ++i) {
|
2016-11-07 23:46:50 +00:00
|
|
|
QImage buffer(screens()->size(i) * screens()->scale(i), QImage::Format_RGB32);
|
2016-11-07 23:46:50 +00:00
|
|
|
buffer.fill(Qt::black);
|
|
|
|
m_backBuffers << buffer;
|
2015-10-02 08:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:35:15 +00:00
|
|
|
void VirtualQPainterBackend::present(int screenId, int mask, const QRegion &damage)
|
2015-10-02 08:44:29 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(mask)
|
|
|
|
Q_UNUSED(damage)
|
2015-10-08 13:53:03 +00:00
|
|
|
if (m_backend->saveFrames()) {
|
2020-11-09 13:35:15 +00:00
|
|
|
m_backBuffers[screenId].save(QStringLiteral("%1/screen%2-%3.png").arg(m_backend->screenshotDirPath(), QString::number(screenId), QString::number(m_frameCounter++)));
|
2015-10-02 08:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 23:46:50 +00:00
|
|
|
bool VirtualQPainterBackend::perScreenRendering() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-02 08:44:29 +00:00
|
|
|
}
|