2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-05-05 11:32:33 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2015-05-05 11:32:33 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-05-05 11:32:33 +00:00
|
|
|
#include "scene_qpainter_drm_backend.h"
|
|
|
|
#include "drm_backend.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "drm_output.h"
|
2020-10-05 21:05:55 +00:00
|
|
|
#include "drm_gpu.h"
|
2020-11-29 11:24:38 +00:00
|
|
|
#include "renderloop_p.h"
|
2015-05-05 11:32:33 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu)
|
2021-07-24 08:25:23 +00:00
|
|
|
: QPainterBackend()
|
2015-05-05 11:32:33 +00:00
|
|
|
, m_backend(backend)
|
2020-10-05 21:05:55 +00:00
|
|
|
, m_gpu(gpu)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
2018-03-28 23:27:21 +00:00
|
|
|
const auto outputs = m_backend->drmOutputs();
|
2015-05-05 11:32:33 +00:00
|
|
|
for (auto output: outputs) {
|
|
|
|
initOutput(output);
|
|
|
|
}
|
2021-01-27 17:29:56 +00:00
|
|
|
connect(m_gpu, &DrmGpu::outputEnabled, this, &DrmQPainterBackend::initOutput);
|
2020-10-05 21:05:55 +00:00
|
|
|
connect(m_gpu, &DrmGpu::outputDisabled, this,
|
2021-07-26 23:11:50 +00:00
|
|
|
[this] (DrmAbstractOutput *o) {
|
2015-05-05 11:32:33 +00:00
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[o] (const Output &output) {
|
|
|
|
return output.output == o;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_outputs.erase(it);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-26 23:11:50 +00:00
|
|
|
void DrmQPainterBackend::initOutput(DrmAbstractOutput *output)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
|
|
|
Output o;
|
2021-05-04 10:19:31 +00:00
|
|
|
o.swapchain = QSharedPointer<DumbSwapchain>::create(m_gpu, output->pixelSize());
|
|
|
|
o.output = output;
|
2021-08-24 20:55:42 +00:00
|
|
|
m_outputs.insert(output, o);
|
2021-07-21 10:11:21 +00:00
|
|
|
connect(output, &DrmOutput::currentModeChanged, this,
|
2017-10-21 13:16:41 +00:00
|
|
|
[output, this] {
|
2021-08-24 20:55:42 +00:00
|
|
|
auto &o = m_outputs[output];
|
|
|
|
o.swapchain = QSharedPointer<DumbSwapchain>::create(m_gpu, output->pixelSize());
|
|
|
|
o.damageJournal.setCapacity(o.swapchain->slotCount());
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
|
|
|
);
|
2015-05-05 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
QImage *DrmQPainterBackend::bufferForScreen(AbstractOutput *output)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
return m_outputs[output].swapchain->currentBuffer()->image();
|
2015-05-05 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:55:42 +00:00
|
|
|
QRegion DrmQPainterBackend::beginFrame(AbstractOutput *output)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
2021-08-24 20:55:42 +00:00
|
|
|
Output *rendererOutput = &m_outputs[output];
|
2021-07-24 09:08:30 +00:00
|
|
|
|
|
|
|
int bufferAge;
|
|
|
|
rendererOutput->swapchain->acquireBuffer(&bufferAge);
|
|
|
|
|
|
|
|
return rendererOutput->damageJournal.accumulate(bufferAge, rendererOutput->output->geometry());
|
2015-05-05 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 11:24:02 +00:00
|
|
|
void DrmQPainterBackend::endFrame(AbstractOutput *output, const QRegion &renderedRegion, const QRegion &damage)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
2021-11-11 11:24:02 +00:00
|
|
|
Q_UNUSED(renderedRegion)
|
2021-08-24 20:55:42 +00:00
|
|
|
Output &rendererOutput = m_outputs[output];
|
2021-07-26 23:11:50 +00:00
|
|
|
DrmAbstractOutput *drmOutput = rendererOutput.output;
|
2020-11-29 11:24:38 +00:00
|
|
|
|
2021-07-24 09:08:30 +00:00
|
|
|
QSharedPointer<DrmDumbBuffer> back = rendererOutput.swapchain->currentBuffer();
|
|
|
|
rendererOutput.swapchain->releaseBuffer(back);
|
|
|
|
|
2021-10-08 08:52:01 +00:00
|
|
|
drmOutput->present(back, drmOutput->geometry());
|
2021-07-24 09:08:30 +00:00
|
|
|
|
|
|
|
rendererOutput.damageJournal.add(damage);
|
2015-05-05 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|