backends/drm: move virtual outputs out of DrmGpu

They're not related to each other in any way
This commit is contained in:
Xaver Hugl 2024-07-03 00:35:38 +02:00
parent 0704319235
commit 8c97c4dd31
10 changed files with 31 additions and 69 deletions

View file

@ -15,10 +15,8 @@
namespace KWin
{
DrmAbstractOutput::DrmAbstractOutput(DrmGpu *gpu)
: Output(gpu->platform())
, m_renderLoop(std::make_unique<RenderLoop>(this))
, m_gpu(gpu)
DrmAbstractOutput::DrmAbstractOutput()
: m_renderLoop(std::make_unique<RenderLoop>(this))
{
}
@ -27,11 +25,6 @@ RenderLoop *DrmAbstractOutput::renderLoop() const
return m_renderLoop.get();
}
DrmGpu *DrmAbstractOutput::gpu() const
{
return m_gpu;
}
void DrmAbstractOutput::updateEnabled(bool enabled)
{
State next = m_state;

View file

@ -14,7 +14,6 @@ namespace KWin
{
class DrmBackend;
class DrmGpu;
class DrmOutputLayer;
class OutputFrame;
@ -22,10 +21,9 @@ class DrmAbstractOutput : public Output
{
Q_OBJECT
public:
DrmAbstractOutput(DrmGpu *gpu);
explicit DrmAbstractOutput();
RenderLoop *renderLoop() const override;
DrmGpu *gpu() const;
virtual bool present(const std::shared_ptr<OutputFrame> &frame) = 0;
virtual DrmOutputLayer *primaryLayer() const = 0;
@ -37,7 +35,6 @@ protected:
friend class DrmGpu;
std::unique_ptr<RenderLoop> m_renderLoop;
DrmGpu *const m_gpu;
};
}

View file

@ -15,6 +15,7 @@
#include "core/session.h"
#include "drm_egl_backend.h"
#include "drm_gpu.h"
#include "drm_layer.h"
#include "drm_logging.h"
#include "drm_output.h"
#include "drm_pipeline.h"
@ -296,9 +297,12 @@ void DrmBackend::sceneInitialized()
if (m_outputs.isEmpty()) {
updateOutputs();
} else {
for (const auto &gpu : std::as_const(m_gpus)) {
for (const auto &gpu : m_gpus) {
gpu->recreateSurfaces();
}
for (const auto &virt : std::as_const(m_virtualOutputs)) {
virt->recreateSurface();
}
}
}
@ -322,9 +326,11 @@ QString DrmBackend::supportInformation() const
Output *DrmBackend::createVirtualOutput(const QString &name, const QSize &size, double scale)
{
auto output = primaryGpu()->createVirtualOutput(name, size * scale, scale);
const auto ret = new DrmVirtualOutput(this, name, size, scale);
m_virtualOutputs.push_back(ret);
addOutput(ret);
Q_EMIT outputsQueried();
return output;
return ret;
}
void DrmBackend::removeVirtualOutput(Output *output)
@ -333,7 +339,7 @@ void DrmBackend::removeVirtualOutput(Output *output)
if (!virtualOutput) {
return;
}
primaryGpu()->removeVirtualOutput(virtualOutput);
removeOutput(virtualOutput);
Q_EMIT outputsQueried();
}
@ -397,11 +403,8 @@ bool DrmBackend::applyOutputChanges(const OutputConfiguration &config)
}
}
// only then apply changes to the virtual outputs
for (const auto &gpu : std::as_const(m_gpus)) {
const auto &outputs = gpu->virtualOutputs();
for (const auto &output : outputs) {
output->applyChanges(config);
}
for (const auto &output : std::as_const(m_virtualOutputs)) {
output->applyChanges(config);
}
return true;
}
@ -418,9 +421,12 @@ DrmRenderBackend *DrmBackend::renderBackend() const
void DrmBackend::releaseBuffers()
{
for (const auto &gpu : std::as_const(m_gpus)) {
for (const auto &gpu : m_gpus) {
gpu->releaseBuffers();
}
for (const auto &virt : std::as_const(m_virtualOutputs)) {
virt->primaryLayer()->releaseBuffers();
}
}
const std::vector<std::unique_ptr<DrmGpu>> &DrmBackend::gpus() const

View file

@ -93,6 +93,7 @@ private:
const QStringList m_explicitGpus;
std::vector<std::unique_ptr<DrmGpu>> m_gpus;
QList<DrmVirtualOutput *> m_virtualOutputs;
DrmRenderBackend *m_renderBackend = nullptr;
};

View file

@ -23,7 +23,6 @@
#include "drm_output.h"
#include "drm_pipeline.h"
#include "drm_plane.h"
#include "drm_virtual_output.h"
// system
#include <algorithm>
#include <errno.h>
@ -366,10 +365,6 @@ void DrmGpu::removeOutputs()
for (const auto &output : outputs) {
removeOutput(output);
}
const auto virtualOutputs = m_virtualOutputs;
for (const auto &output : virtualOutputs) {
removeVirtualOutput(output);
}
}
DrmPipeline::Error DrmGpu::checkCrtcAssignment(QList<DrmConnector *> connectors, const QList<DrmCrtc *> &crtcs)
@ -604,22 +599,6 @@ const QList<DrmPipeline *> DrmGpu::pipelines() const
return m_pipelines;
}
DrmVirtualOutput *DrmGpu::createVirtualOutput(const QString &name, const QSize &size, double scale)
{
auto output = new DrmVirtualOutput(name, this, size, scale);
m_virtualOutputs << output;
Q_EMIT outputAdded(output);
return output;
}
void DrmGpu::removeVirtualOutput(DrmVirtualOutput *output)
{
if (m_virtualOutputs.removeOne(output)) {
Q_EMIT outputRemoved(output);
output->unref();
}
}
std::unique_ptr<DrmLease> DrmGpu::leaseOutputs(const QList<DrmOutput *> &outputs)
{
QList<uint32_t> objects;
@ -647,11 +626,6 @@ std::unique_ptr<DrmLease> DrmGpu::leaseOutputs(const QList<DrmOutput *> &outputs
}
}
QList<DrmVirtualOutput *> DrmGpu::virtualOutputs() const
{
return m_virtualOutputs;
}
QList<DrmOutput *> DrmGpu::drmOutputs() const
{
return m_drmOutputs;
@ -835,9 +809,6 @@ void DrmGpu::releaseBuffers()
pipeline->primaryLayer()->releaseBuffers();
pipeline->cursorLayer()->releaseBuffers();
}
for (const auto &output : std::as_const(m_virtualOutputs)) {
output->primaryLayer()->releaseBuffers();
}
}
void DrmGpu::recreateSurfaces()
@ -846,9 +817,6 @@ void DrmGpu::recreateSurfaces()
pipeline->setLayers(m_platform->renderBackend()->createDrmPlaneLayer(pipeline, DrmPlane::TypeIndex::Primary), m_platform->renderBackend()->createDrmPlaneLayer(pipeline, DrmPlane::TypeIndex::Cursor));
pipeline->applyPendingChanges();
}
for (const auto &output : std::as_const(m_virtualOutputs)) {
output->recreateSurface();
}
}
std::shared_ptr<DrmFramebuffer> DrmGpu::importBuffer(GraphicsBuffer *buffer, FileDescriptor &&readFence)

View file

@ -90,7 +90,6 @@ public:
clockid_t presentationClock() const;
QSize cursorSize() const;
QList<DrmVirtualOutput *> virtualOutputs() const;
QList<DrmOutput *> drmOutputs() const;
const QList<DrmPipeline *> pipelines() const;
@ -99,9 +98,6 @@ public:
bool updateOutputs();
void removeOutputs();
DrmVirtualOutput *createVirtualOutput(const QString &name, const QSize &size, double scale);
void removeVirtualOutput(DrmVirtualOutput *output);
DrmPipeline::Error testPendingConfiguration();
bool needsModeset() const;
bool maybeModeset(const std::shared_ptr<OutputFrame> &frame);
@ -156,7 +152,6 @@ private:
QList<DrmPipeline *> m_pipelines;
QList<DrmOutput *> m_drmOutputs;
QList<DrmVirtualOutput *> m_virtualOutputs;
std::unique_ptr<QSocketNotifier> m_socketNotifier;
QSize m_cursorSize;

View file

@ -38,7 +38,7 @@ namespace KWin
static const bool s_disableTripleBuffering = qEnvironmentVariableIntValue("KWIN_DRM_DISABLE_TRIPLE_BUFFERING") == 1;
DrmOutput::DrmOutput(const std::shared_ptr<DrmConnector> &conn)
: DrmAbstractOutput(conn->gpu())
: m_gpu(conn->gpu())
, m_pipeline(conn->pipeline())
, m_connector(conn)
{
@ -158,7 +158,7 @@ bool DrmOutput::setDrmDpmsMode(DpmsMode mode)
return true;
}
if (!active) {
gpu()->waitIdle();
m_gpu->waitIdle();
}
m_pipeline->setActive(active);
if (DrmPipeline::commitPipelines({m_pipeline}, active ? DrmPipeline::CommitMode::TestAllowModeset : DrmPipeline::CommitMode::CommitModeset) == DrmPipeline::Error::None) {
@ -242,7 +242,7 @@ Output::Capabilities DrmOutput::computeCapabilities() const
if (m_connector->vrrCapable.isValid() && m_connector->vrrCapable.value()) {
capabilities |= Capability::Vrr;
}
if (gpu()->asyncPageflipSupported()) {
if (m_gpu->asyncPageflipSupported()) {
capabilities |= Capability::Tearing;
}
if (m_connector->broadcastRGB.isValid()) {
@ -285,7 +285,7 @@ void DrmOutput::updateDpmsMode(DpmsMode dpmsMode)
bool DrmOutput::present(const std::shared_ptr<OutputFrame> &frame)
{
const bool needsModeset = gpu()->needsModeset();
const bool needsModeset = m_gpu->needsModeset();
bool success;
if (needsModeset) {
m_pipeline->setPresentationMode(PresentationMode::VSync);

View file

@ -35,7 +35,7 @@ class KWIN_EXPORT DrmOutput : public DrmAbstractOutput
{
Q_OBJECT
public:
DrmOutput(const std::shared_ptr<DrmConnector> &connector);
explicit DrmOutput(const std::shared_ptr<DrmConnector> &connector);
~DrmOutput() override;
DrmConnector *connector() const;
@ -76,6 +76,7 @@ private:
QList<std::shared_ptr<OutputMode>> getModes() const;
DrmGpu *const m_gpu;
DrmPipeline *m_pipeline;
const std::shared_ptr<DrmConnector> m_connector;

View file

@ -19,8 +19,8 @@
namespace KWin
{
DrmVirtualOutput::DrmVirtualOutput(const QString &name, DrmGpu *gpu, const QSize &size, qreal scale)
: DrmAbstractOutput(gpu)
DrmVirtualOutput::DrmVirtualOutput(DrmBackend *backend, const QString &name, const QSize &size, qreal scale)
: m_backend(backend)
, m_vsyncMonitor(SoftwareVsyncMonitor::create())
{
connect(m_vsyncMonitor.get(), &VsyncMonitor::vblankOccurred, this, &DrmVirtualOutput::vblank);
@ -81,7 +81,7 @@ DrmOutputLayer *DrmVirtualOutput::cursorLayer() const
void DrmVirtualOutput::recreateSurface()
{
m_layer = m_gpu->platform()->renderBackend()->createLayer(this);
m_layer = m_backend->renderBackend()->createLayer(this);
}
}

View file

@ -26,7 +26,7 @@ class DrmVirtualOutput : public DrmAbstractOutput
Q_OBJECT
public:
DrmVirtualOutput(const QString &name, DrmGpu *gpu, const QSize &size, qreal scale);
explicit DrmVirtualOutput(DrmBackend *backend, const QString &name, const QSize &size, qreal scale);
~DrmVirtualOutput() override;
bool present(const std::shared_ptr<OutputFrame> &frame) override;
@ -38,6 +38,7 @@ private:
void vblank(std::chrono::nanoseconds timestamp);
void setDpmsMode(DpmsMode mode) override;
DrmBackend *const m_backend;
std::shared_ptr<DrmOutputLayer> m_layer;
std::shared_ptr<OutputFrame> m_frame;