a07aae8282
Currently KWin is combining modesets with presentation, which causes problems when multiple monitors are used and crtcs need to be switched around, because taking away a CRTC from another output causes the driver to disable the other output. In order to avoid such problems, delay presentation until all pipelines are ready to present and then do a modeset with a single atomic commit. To process the resulting page flip events properly this commit also ports KWin to page_flip_handler2 and changes how the pageFlipped and notifyFrameFailed signals are processed.
86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
/*
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
#include "scene_qpainter_drm_backend.h"
|
|
#include "drm_backend.h"
|
|
#include "drm_output.h"
|
|
#include "drm_gpu.h"
|
|
#include "renderloop_p.h"
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu)
|
|
: QPainterBackend()
|
|
, m_backend(backend)
|
|
, m_gpu(gpu)
|
|
{
|
|
const auto outputs = m_backend->drmOutputs();
|
|
for (auto output: outputs) {
|
|
initOutput(output);
|
|
}
|
|
connect(m_gpu, &DrmGpu::outputEnabled, this, &DrmQPainterBackend::initOutput);
|
|
connect(m_gpu, &DrmGpu::outputDisabled, this,
|
|
[this] (DrmAbstractOutput *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;
|
|
}
|
|
m_outputs.erase(it);
|
|
}
|
|
);
|
|
}
|
|
|
|
void DrmQPainterBackend::initOutput(DrmAbstractOutput *output)
|
|
{
|
|
Output o;
|
|
o.swapchain = QSharedPointer<DumbSwapchain>::create(m_gpu, output->pixelSize());
|
|
o.output = output;
|
|
m_outputs.insert(output, o);
|
|
connect(output, &DrmOutput::currentModeChanged, this,
|
|
[output, this] {
|
|
auto &o = m_outputs[output];
|
|
o.swapchain = QSharedPointer<DumbSwapchain>::create(m_gpu, output->pixelSize());
|
|
o.damageJournal.setCapacity(o.swapchain->slotCount());
|
|
}
|
|
);
|
|
}
|
|
|
|
QImage *DrmQPainterBackend::bufferForScreen(AbstractOutput *output)
|
|
{
|
|
return m_outputs[output].swapchain->currentBuffer()->image();
|
|
}
|
|
|
|
QRegion DrmQPainterBackend::beginFrame(AbstractOutput *output)
|
|
{
|
|
Output *rendererOutput = &m_outputs[output];
|
|
|
|
int bufferAge;
|
|
rendererOutput->swapchain->acquireBuffer(&bufferAge);
|
|
|
|
return rendererOutput->damageJournal.accumulate(bufferAge, rendererOutput->output->geometry());
|
|
}
|
|
|
|
void DrmQPainterBackend::endFrame(AbstractOutput *output, const QRegion &damage)
|
|
{
|
|
Output &rendererOutput = m_outputs[output];
|
|
DrmAbstractOutput *drmOutput = rendererOutput.output;
|
|
|
|
QSharedPointer<DrmDumbBuffer> back = rendererOutput.swapchain->currentBuffer();
|
|
rendererOutput.swapchain->releaseBuffer(back);
|
|
|
|
drmOutput->present(back, drmOutput->geometry());
|
|
|
|
rendererOutput.damageJournal.add(damage);
|
|
}
|
|
|
|
}
|