From b3e7664d2cd2c8fb2335a1b218e2e4ee2f241ef6 Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Wed, 28 Aug 2019 20:54:37 +0200 Subject: [PATCH] Replace Wayland/XDG outputs checks with enablement checks Summary: Make it more explicit what the relation is between Wayland and XDG objects existing and enablement: The ouput is enabled if and only if Wayland and XDG output objects exist. We can simplify the code by replacing checks on the outputs with checking the current enablement value. Test Plan: Wayland nested and virtual backends. Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D23553 --- abstract_wayland_output.cpp | 41 ++++++++++--------- abstract_wayland_output.h | 12 ++---- plugins/platforms/drm/drm_output.cpp | 5 +-- plugins/platforms/fbdev/fb_backend.cpp | 4 +- .../hwcomposer/hwcomposer_backend.cpp | 3 +- plugins/platforms/virtual/virtual_output.cpp | 5 +-- plugins/platforms/wayland/wayland_output.cpp | 4 +- .../x11/windowed/x11windowed_output.cpp | 4 +- 8 files changed, 32 insertions(+), 46 deletions(-) diff --git a/abstract_wayland_output.cpp b/abstract_wayland_output.cpp index 4764d6b472..ee030ca8e1 100644 --- a/abstract_wayland_output.cpp +++ b/abstract_wayland_output.cpp @@ -79,10 +79,8 @@ void AbstractWaylandOutput::setGlobalPos(const QPoint &pos) { m_waylandOutputDevice->setGlobalPosition(pos); - if (m_waylandOutput) { + if (isEnabled()) { m_waylandOutput->setGlobalPosition(pos); - } - if (m_xdgOutput) { m_xdgOutput->setLogicalPosition(pos); m_xdgOutput->done(); } @@ -102,7 +100,7 @@ void AbstractWaylandOutput::setScale(qreal scale) { m_waylandOutputDevice->setScaleF(scale); - if (m_waylandOutput) { + if (isEnabled()) { // this is the scale that clients will ideally use for their buffers // this has to be an int which is fine @@ -110,8 +108,6 @@ void AbstractWaylandOutput::setScale(qreal scale) // or maybe even set this to 3 when we're scaling to 1.5 // don't treat this like it's chosen deliberately m_waylandOutput->setScale(std::ceil(scale)); - } - if (m_xdgOutput) { m_xdgOutput->setLogicalSize(pixelSize() / scale); m_xdgOutput->done(); } @@ -150,6 +146,13 @@ void AbstractWaylandOutput::applyChanges(const KWayland::Server::OutputChangeSet } } +using DeviceInterface = KWayland::Server::OutputDeviceInterface; + +bool AbstractWaylandOutput::isEnabled() const +{ + return m_waylandOutputDevice->enabled() == DeviceInterface::Enablement::Enabled; +} + void AbstractWaylandOutput::setEnabled(bool enable) { if (enable == isEnabled()) { @@ -162,20 +165,18 @@ void AbstractWaylandOutput::setEnabled(bool enable) updateDpms(KWayland::Server::OutputInterface::DpmsMode::Off); delete waylandOutput().data(); } - waylandOutputDevice()->setEnabled(enable ? KWayland::Server::OutputDeviceInterface::Enablement::Enabled : - KWayland::Server::OutputDeviceInterface::Enablement::Disabled); + waylandOutputDevice()->setEnabled(enable ? DeviceInterface::Enablement::Enabled : + DeviceInterface::Enablement::Disabled); } void AbstractWaylandOutput::setWaylandMode(const QSize &size, int refreshRate) { - if (m_waylandOutput.isNull()) { + if (!isEnabled()) { return; } m_waylandOutput->setCurrentMode(size, refreshRate); - if (m_xdgOutput) { - m_xdgOutput->setLogicalSize(pixelSize() / scale()); - m_xdgOutput->done(); - } + m_xdgOutput->setLogicalSize(pixelSize() / scale()); + m_xdgOutput->done(); } void AbstractWaylandOutput::createXdgOutput() @@ -207,10 +208,10 @@ void AbstractWaylandOutput::createWaylandOutput() */ for(const auto &mode: m_waylandOutputDevice->modes()) { KWayland::Server::OutputInterface::ModeFlags flags; - if (mode.flags & KWayland::Server::OutputDeviceInterface::ModeFlag::Current) { + if (mode.flags & DeviceInterface::ModeFlag::Current) { flags |= KWayland::Server::OutputInterface::ModeFlag::Current; } - if (mode.flags & KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred) { + if (mode.flags & DeviceInterface::ModeFlag::Preferred) { flags |= KWayland::Server::OutputInterface::ModeFlag::Preferred; } m_waylandOutput->addMode(mode.size, flags, mode.refreshRate); @@ -230,11 +231,9 @@ void AbstractWaylandOutput::createWaylandOutput() ); } -void AbstractWaylandOutput::initWaylandOutputDevice(const QString &model, - const QString &manufacturer, - const QByteArray &uuid, - const QSize &physicalSize, - const QVector &modes) +void AbstractWaylandOutput::initInterfaces(const QString &model, const QString &manufacturer, + const QByteArray &uuid, const QSize &physicalSize, + const QVector &modes) { Q_ASSERT(m_waylandOutputDevice.isNull()); m_waylandOutputDevice = waylandServer()->display()->createOutputDevice(); @@ -254,7 +253,9 @@ void AbstractWaylandOutput::initWaylandOutputDevice(const QString &model, qCDebug(KWIN_CORE).nospace() << "Adding mode " << ++i << ": " << mode.size << " [" << mode.refreshRate << "]"; m_waylandOutputDevice->addMode(mode); } + m_waylandOutputDevice->create(); + createWaylandOutput(); } QSize AbstractWaylandOutput::orientateSize(const QSize &size) const diff --git a/abstract_wayland_output.h b/abstract_wayland_output.h index 0c97ba3f9a..a3f96170fe 100644 --- a/abstract_wayland_output.h +++ b/abstract_wayland_output.h @@ -61,9 +61,6 @@ public: QString name() const override; QByteArray uuid() const override; - bool isEnabled() const { - return !m_waylandOutput.isNull(); - } QSize pixelSize() const; qreal scale() const override; @@ -107,11 +104,9 @@ Q_SIGNALS: void modeChanged(); protected: - void initWaylandOutputDevice(const QString &model, - const QString &manufacturer, - const QByteArray &uuid, - const QSize &physicalSize, - const QVector &modes); + void initInterfaces(const QString &model, const QString &manufacturer, + const QByteArray &uuid, const QSize &physicalSize, + const QVector &modes); QPointer xdgOutput() const { return m_xdgOutput; @@ -152,6 +147,7 @@ protected: private: void createWaylandOutput(); void createXdgOutput(); + bool isEnabled() const; QPointer m_waylandOutput; QPointer m_xdgOutput; diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index c9ebfe5d49..c3c22fb8a9 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -268,8 +268,7 @@ bool DrmOutput::init(drmModeConnector *connector) } initOutputDevice(connector); - - setEnabled(true); + updateDpms(KWayland::Server::OutputInterface::DpmsMode::On); return true; } @@ -343,7 +342,7 @@ void DrmOutput::initOutputDevice(drmModeConnector *connector) physicalSize = overwriteSize; } - initWaylandOutputDevice(model, manufacturer, m_uuid, physicalSize, modes); + initInterfaces(model, manufacturer, m_uuid, physicalSize, modes); } bool DrmOutput::isCurrentMode(const drmModeModeInfo *mode) const diff --git a/plugins/platforms/fbdev/fb_backend.cpp b/plugins/platforms/fbdev/fb_backend.cpp index 5760c040f3..dc0cfeba1d 100644 --- a/plugins/platforms/fbdev/fb_backend.cpp +++ b/plugins/platforms/fbdev/fb_backend.cpp @@ -44,8 +44,7 @@ void FramebufferOutput::init(const QSize &pixelSize, const QSize &physicalSize) mode.size = pixelSize; mode.flags = KWayland::Server::OutputDeviceInterface::ModeFlag::Current; mode.refreshRate = 60000; // TODO: get actual refresh rate of fb device? - AbstractWaylandOutput::initWaylandOutputDevice("model_TODO", "manufacturer_TODO", - "UUID_TODO", physicalSize, { mode }); + initInterfaces("model_TODO", "manufacturer_TODO", "UUID_TODO", physicalSize, { mode }); } FramebufferBackend::FramebufferBackend(QObject *parent) @@ -149,7 +148,6 @@ bool FramebufferBackend::handleScreenInfo() auto *output = new FramebufferOutput(this); output->init(QSize(varinfo.xres, varinfo.yres), QSize(varinfo.width, varinfo.height)); - output->setEnabled(true); m_outputs << output; m_id = QByteArray(fixinfo.id); diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp index cb730dbffb..da974803d4 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp @@ -522,9 +522,8 @@ HwcomposerOutput::HwcomposerOutput(hwc_composer_device_1_t *device) mode.flags = OutputDeviceInterface::ModeFlag::Current | OutputDeviceInterface::ModeFlag::Preferred; mode.refreshRate = (attr_values[4] == 0) ? 60000 : 10E11/attr_values[4]; - initWaylandOutputDevice(QString(), QString(), QByteArray(), physicalSize.toSize(), {mode}); + initInterfaces(QString(), QString(), QByteArray(), physicalSize.toSize(), {mode}); setInternal(true); - setEnabled(true); setDpmsSupported(true); const auto outputGroup = kwinApp()->config()->group("HWComposerOutputs").group("0"); diff --git a/plugins/platforms/virtual/virtual_output.cpp b/plugins/platforms/virtual/virtual_output.cpp index 1047d78ede..6b7f114961 100644 --- a/plugins/platforms/virtual/virtual_output.cpp +++ b/plugins/platforms/virtual/virtual_output.cpp @@ -39,11 +39,8 @@ void VirtualOutput::init(const QPoint &logicalPosition, const QSize &pixelSize) mode.size = pixelSize; mode.flags = KWayland::Server::OutputDeviceInterface::ModeFlag::Current; mode.refreshRate = 60000; // TODO - AbstractWaylandOutput::initWaylandOutputDevice("model_TODO", "manufacturer_TODO", - "UUID_TODO", pixelSize, { mode }); - setEnabled(true); + initInterfaces("model_TODO", "manufacturer_TODO", "UUID_TODO", pixelSize, { mode }); setGeometry(QRect(logicalPosition, pixelSize)); - setScale(1.); } void VirtualOutput::setGeometry(const QRect &geo) diff --git a/plugins/platforms/wayland/wayland_output.cpp b/plugins/platforms/wayland/wayland_output.cpp index f447ac94b2..7aae099c17 100644 --- a/plugins/platforms/wayland/wayland_output.cpp +++ b/plugins/platforms/wayland/wayland_output.cpp @@ -61,9 +61,7 @@ void WaylandOutput::init(const QPoint &logicalPosition, const QSize &pixelSize) mode.size = pixelSize; mode.flags = KWayland::Server::OutputDeviceInterface::ModeFlag::Current; mode.refreshRate = 60000; // TODO: can we get refresh rate data from Wayland host? - AbstractWaylandOutput::initWaylandOutputDevice("model_TODO", "manufacturer_TODO", - "UUID_TODO", pixelSize, { mode }); - setEnabled(true); + initInterfaces("model_TODO", "manufacturer_TODO", "UUID_TODO", pixelSize, { mode }); setGeometry(logicalPosition, pixelSize); setScale(backend()->initialOutputScale()); } diff --git a/plugins/platforms/x11/windowed/x11windowed_output.cpp b/plugins/platforms/x11/windowed/x11windowed_output.cpp index 27e914d471..4bd63dcc55 100644 --- a/plugins/platforms/x11/windowed/x11windowed_output.cpp +++ b/plugins/platforms/x11/windowed/x11windowed_output.cpp @@ -58,9 +58,7 @@ void X11WindowedOutput::init(const QPoint &logicalPosition, const QSize &pixelSi // Physicial size must be adjusted, such that QPA calculates correct sizes of // internal elements. const QSize physicalSize = pixelSize / 96.0 * 25.4 / m_backend->initialOutputScale(); - AbstractWaylandOutput::initWaylandOutputDevice("model_TODO", "manufacturer_TODO", - "UUID_TODO", physicalSize, { mode }); - setEnabled(true); + initInterfaces("model_TODO", "manufacturer_TODO", "UUID_TODO", physicalSize, { mode }); setGeometry(logicalPosition, pixelSize); setScale(m_backend->initialOutputScale());