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)
|
2015-05-05 11:32:33 +00:00
|
|
|
: QObject()
|
|
|
|
, QPainterBackend()
|
|
|
|
, 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,
|
2015-05-05 11:32:33 +00:00
|
|
|
[this] (DrmOutput *o) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
delete (*it).buffer[0];
|
|
|
|
delete (*it).buffer[1];
|
|
|
|
m_outputs.erase(it);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmQPainterBackend::~DrmQPainterBackend()
|
|
|
|
{
|
|
|
|
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
|
|
|
delete (*it).buffer[0];
|
|
|
|
delete (*it).buffer[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmQPainterBackend::initOutput(DrmOutput *output)
|
|
|
|
{
|
|
|
|
Output o;
|
|
|
|
auto initBuffer = [&o, output, this] (int index) {
|
2020-10-05 21:05:55 +00:00
|
|
|
o.buffer[index] = m_gpu->createBuffer(output->pixelSize());
|
2020-07-10 02:30:24 +00:00
|
|
|
if (o.buffer[index]->map()) {
|
|
|
|
o.buffer[index]->image()->fill(Qt::black);
|
|
|
|
}
|
2015-05-05 11:32:33 +00:00
|
|
|
};
|
2017-10-21 13:16:41 +00:00
|
|
|
connect(output, &DrmOutput::modeChanged, this,
|
|
|
|
[output, this] {
|
|
|
|
auto it = std::find_if(m_outputs.begin(), m_outputs.end(),
|
|
|
|
[output] (const auto &o) {
|
|
|
|
return o.output == output;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it == m_outputs.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delete (*it).buffer[0];
|
|
|
|
delete (*it).buffer[1];
|
|
|
|
auto initBuffer = [it, output, this] (int index) {
|
2020-10-05 21:05:55 +00:00
|
|
|
it->buffer[index] = m_gpu->createBuffer(output->pixelSize());
|
2020-07-29 12:35:50 +00:00
|
|
|
if (it->buffer[index]->map()) {
|
2020-07-10 02:30:24 +00:00
|
|
|
it->buffer[index]->image()->fill(Qt::black);
|
|
|
|
}
|
2017-10-21 13:16:41 +00:00
|
|
|
};
|
|
|
|
initBuffer(0);
|
|
|
|
initBuffer(1);
|
|
|
|
}
|
|
|
|
);
|
2015-05-05 11:32:33 +00:00
|
|
|
initBuffer(0);
|
|
|
|
initBuffer(1);
|
|
|
|
o.output = output;
|
|
|
|
m_outputs << o;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage *DrmQPainterBackend::bufferForScreen(int screenId)
|
|
|
|
{
|
|
|
|
const Output &o = m_outputs.at(screenId);
|
|
|
|
return o.buffer[o.index]->image();
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:35:15 +00:00
|
|
|
bool DrmQPainterBackend::needsFullRepaint(int screenId) const
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
2020-11-09 13:35:15 +00:00
|
|
|
Q_UNUSED(screenId)
|
2015-05-05 11:32:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
void DrmQPainterBackend::beginFrame(int screenId)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
2020-11-09 13:35:15 +00:00
|
|
|
Output &rendererOutput = m_outputs[screenId];
|
|
|
|
rendererOutput.index = (rendererOutput.index + 1) % 2;
|
2015-05-05 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 14:31:26 +00:00
|
|
|
void DrmQPainterBackend::endFrame(int screenId, int mask, const QRegion &damage)
|
2015-05-05 11:32:33 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(mask)
|
|
|
|
Q_UNUSED(damage)
|
2020-11-09 13:35:15 +00:00
|
|
|
|
|
|
|
const Output &rendererOutput = m_outputs[screenId];
|
2020-11-29 11:24:38 +00:00
|
|
|
DrmOutput *drmOutput = rendererOutput.output;
|
|
|
|
|
|
|
|
if (!m_backend->present(rendererOutput.buffer[rendererOutput.index], drmOutput)) {
|
|
|
|
RenderLoopPrivate *renderLoopPrivate = RenderLoopPrivate::get(drmOutput->renderLoop());
|
|
|
|
renderLoopPrivate->notifyFrameFailed();
|
|
|
|
}
|
2015-05-05 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|