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
This commit is contained in:
Roman Gilg 2019-08-28 20:54:37 +02:00
parent f7ff62e2e2
commit b3e7664d2c
8 changed files with 32 additions and 46 deletions

View file

@ -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,21 +165,19 @@ 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();
}
}
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<KWayland::Server::OutputDeviceInterface::Mode> &modes)
void AbstractWaylandOutput::initInterfaces(const QString &model, const QString &manufacturer,
const QByteArray &uuid, const QSize &physicalSize,
const QVector<DeviceInterface::Mode> &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

View file

@ -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,10 +104,8 @@ Q_SIGNALS:
void modeChanged();
protected:
void initWaylandOutputDevice(const QString &model,
const QString &manufacturer,
const QByteArray &uuid,
const QSize &physicalSize,
void initInterfaces(const QString &model, const QString &manufacturer,
const QByteArray &uuid, const QSize &physicalSize,
const QVector<KWayland::Server::OutputDeviceInterface::Mode> &modes);
QPointer<KWayland::Server::XdgOutputInterface> xdgOutput() const {
@ -152,6 +147,7 @@ protected:
private:
void createWaylandOutput();
void createXdgOutput();
bool isEnabled() const;
QPointer<KWayland::Server::OutputInterface> m_waylandOutput;
QPointer<KWayland::Server::XdgOutputInterface> m_xdgOutput;

View file

@ -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

View file

@ -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);

View file

@ -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");

View file

@ -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)

View file

@ -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());
}

View file

@ -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());