Commit 145d8b9f authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Send only current wl_output mode

Non-current output modes were deprecated due to various reasons, e.g.
it's not possible to remove some nodes; two modes can have the same
resolution and the refresh rate but different flags, but wl_output.mode
fails to communicate that properly; the usefulness of non-current modes
is questionable. For more details, please refer to [1].

[1] https://gitlab.freedesktop.org/wayland/wayland/-/issues/92
parent 589e339d
Pipeline #56746 passed with stage
in 7 minutes and 30 seconds
......@@ -27,7 +27,7 @@ private Q_SLOTS:
void cleanup();
void testRegistry();
void testModeChanges();
void testModeChange();
void testScaleChange();
void testSubPixel_data();
......@@ -73,12 +73,7 @@ void TestWaylandOutput::init()
m_serverOutput = new OutputInterface(m_display, this);
QCOMPARE(m_serverOutput->pixelSize(), QSize());
QCOMPARE(m_serverOutput->refreshRate(), 60000);
m_serverOutput->addMode(QSize(800, 600), OutputInterface::ModeFlags(OutputInterface::ModeFlag::Preferred));
QCOMPARE(m_serverOutput->pixelSize(), QSize(800, 600));
m_serverOutput->addMode(QSize(1024, 768));
m_serverOutput->addMode(QSize(1280, 1024), OutputInterface::ModeFlags(), 90000);
QCOMPARE(m_serverOutput->pixelSize(), QSize(800, 600));
m_serverOutput->setCurrentMode(QSize(1024, 768));
m_serverOutput->setMode(QSize(1024, 768));
QCOMPARE(m_serverOutput->pixelSize(), QSize(1024, 768));
QCOMPARE(m_serverOutput->refreshRate(), 60000);
QCOMPARE(m_serverOutput->isDpmsSupported(), false);
......@@ -192,22 +187,8 @@ void TestWaylandOutput::testRegistry()
QCOMPARE(output.transform(), KWayland::Client::Output::Transform::Normal);
}
void TestWaylandOutput::testModeChanges()
void TestWaylandOutput::testModeChange()
{
// verify the server modes
using namespace KWaylandServer;
const auto serverModes = m_serverOutput->modes();
QCOMPARE(serverModes.count(), 3);
QCOMPARE(serverModes.at(0).size, QSize(800, 600));
QCOMPARE(serverModes.at(1).size, QSize(1024, 768));
QCOMPARE(serverModes.at(2).size, QSize(1280, 1024));
QCOMPARE(serverModes.at(0).refreshRate, 60000);
QCOMPARE(serverModes.at(1).refreshRate, 60000);
QCOMPARE(serverModes.at(2).refreshRate, 90000);
QCOMPARE(serverModes.at(0).flags, OutputInterface::ModeFlags(OutputInterface::ModeFlag::Preferred));
QCOMPARE(serverModes.at(1).flags, OutputInterface::ModeFlags(OutputInterface::ModeFlag::Current));
QCOMPARE(serverModes.at(2).flags, OutputInterface::ModeFlags());
using namespace KWayland::Client;
KWayland::Client::Registry registry;
QSignalSpy announced(&registry, &KWayland::Client::Registry::outputAnnounced);
......@@ -226,80 +207,26 @@ void TestWaylandOutput::testModeChanges()
output.setup(registry.bindOutput(announced.first().first().value<quint32>(), announced.first().last().value<quint32>()));
wl_display_flush(m_connection->display());
QVERIFY(outputChanged.wait());
QCOMPARE(modeAddedSpy.count(), 3);
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().size, QSize(800, 600));
QCOMPARE(modeAddedSpy.count(), 1);
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().size, QSize(1024, 768));
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Preferred));
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current));
QCOMPARE(modeAddedSpy.at(0).first().value<Output::Mode>().output, QPointer<Output>(&output));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().size, QSize(1280, 1024));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().refreshRate, 90000);
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::None));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().output, QPointer<Output>(&output));
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().size, QSize(1024, 768));
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current));
QCOMPARE(modeAddedSpy.at(2).first().value<Output::Mode>().output, QPointer<Output>(&output));
const QList<Output::Mode> &modes = output.modes();
QCOMPARE(modes.size(), 3);
QCOMPARE(modes.at(0), modeAddedSpy.at(0).first().value<Output::Mode>());
QCOMPARE(modes.at(1), modeAddedSpy.at(1).first().value<Output::Mode>());
QCOMPARE(modes.at(2), modeAddedSpy.at(2).first().value<Output::Mode>());
QCOMPARE(output.pixelSize(), QSize(1024, 768));
// change the current mode
outputChanged.clear();
QSignalSpy modeChangedSpy(&output, &KWayland::Client::Output::modeChanged);
QVERIFY(modeChangedSpy.isValid());
m_serverOutput->setCurrentMode(QSize(800, 600));
m_serverOutput->done();
QVERIFY(modeChangedSpy.wait());
if (modeChangedSpy.size() == 1) {
QVERIFY(modeChangedSpy.wait());
}
QCOMPARE(modeChangedSpy.size(), 2);
// the one which lost the current flag
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().size, QSize(1024, 768));
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().flags, Output::Mode::Flags());
// the one which got the current flag
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().size, QSize(800, 600));
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current | Output::Mode::Flag::Preferred));
QVERIFY(!outputChanged.isEmpty());
QCOMPARE(output.pixelSize(), QSize(800, 600));
const QList<Output::Mode> &modes2 = output.modes();
QCOMPARE(modes2.at(0).size, QSize(1280, 1024));
QCOMPARE(modes2.at(0).refreshRate, 90000);
QCOMPARE(modes2.at(0).flags, Output::Mode::Flag::None);
QCOMPARE(modes2.at(1).size, QSize(1024, 768));
QCOMPARE(modes2.at(1).refreshRate, 60000);
QCOMPARE(modes2.at(1).flags, Output::Mode::Flag::None);
QCOMPARE(modes2.at(2).size, QSize(800, 600));
QCOMPARE(modes2.at(2).refreshRate, 60000);
QCOMPARE(modes2.at(2).flags, Output::Mode::Flag::Current | Output::Mode::Flag::Preferred);
QCOMPARE(output.refreshRate(), 60000);
// change once more
outputChanged.clear();
modeChangedSpy.clear();
m_serverOutput->setCurrentMode(QSize(1280, 1024), 90000);
m_serverOutput->setMode(QSize(1280, 1024), 90000);
QCOMPARE(m_serverOutput->refreshRate(), 90000);
m_serverOutput->done();
QVERIFY(modeChangedSpy.wait());
if (modeChangedSpy.size() == 1) {
QVERIFY(modeChangedSpy.wait());
}
QCOMPARE(modeChangedSpy.size(), 2);
// the one which lost the current flag
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().size, QSize(800, 600));
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().refreshRate, 60000);
QCOMPARE(modeChangedSpy.first().first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Preferred));
// the one which got the current flag
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().size, QSize(1280, 1024));
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().refreshRate, 90000);
QCOMPARE(modeChangedSpy.last().first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current));
QVERIFY(!outputChanged.isEmpty());
QVERIFY(outputChanged.wait());
QCOMPARE(modeAddedSpy.count(), 2);
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().size, QSize(1280, 1024));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().refreshRate, 90000);
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().flags, Output::Mode::Flags(Output::Mode::Flag::Current));
QCOMPARE(modeAddedSpy.at(1).first().value<Output::Mode>().output, QPointer<Output>(&output));
QCOMPARE(output.pixelSize(), QSize(1280, 1024));
QCOMPARE(output.refreshRate(), 90000);
}
void TestWaylandOutput::testScaleChange()
......
......@@ -59,8 +59,7 @@ void TestXdgOutput::init()
QVERIFY(m_display->isRunning());
m_serverOutput = new OutputInterface(m_display, this);
m_serverOutput->addMode(QSize(1920, 1080), OutputInterface::ModeFlags(OutputInterface::ModeFlag::Preferred));
m_serverOutput->setCurrentMode(QSize(1920, 1080));
m_serverOutput->setMode(QSize(1920, 1080));
m_serverXdgOutputManager = new XdgOutputManagerV1Interface(m_display, this);
m_serverXdgOutput = m_serverXdgOutputManager->createXdgOutput(m_serverOutput, this);
......
......@@ -94,9 +94,9 @@ void XdgShellTest::init()
QVERIFY(m_display->isRunning());
m_display->createShm();
m_o1Interface = new OutputInterface(m_display, m_display);
m_o1Interface->addMode(QSize(1024, 768));
m_o1Interface->setMode(QSize(1024, 768));
m_o2Interface = new OutputInterface(m_display, m_display);
m_o2Interface->addMode(QSize(1024, 768));
m_o2Interface->setMode(QSize(1024, 768));
m_seatInterface = new SeatInterface(m_display, m_display);
m_seatInterface->setHasKeyboard(true);
m_seatInterface->setHasPointer(true);
......
......@@ -26,7 +26,7 @@ public:
void sendScale(Resource *resource);
void sendGeometry(Resource *resource);
void sendMode(Resource *resource, const OutputInterface::Mode &mode);
void sendMode(Resource *resource);
void sendDone(Resource *resource);
void broadcastGeometry();
......@@ -40,7 +40,7 @@ public:
int scale = 1;
OutputInterface::SubPixel subPixel = OutputInterface::SubPixel::Unknown;
OutputInterface::Transform transform = OutputInterface::Transform::Normal;
QList<OutputInterface::Mode> modes;
OutputInterface::Mode mode;
struct {
OutputInterface::DpmsMode mode = OutputInterface::DpmsMode::Off;
bool supported = false;
......@@ -58,18 +58,9 @@ OutputInterfacePrivate::OutputInterfacePrivate(Display *display, OutputInterface
{
}
void OutputInterfacePrivate::sendMode(Resource *resource, const OutputInterface::Mode &mode)
void OutputInterfacePrivate::sendMode(Resource *resource)
{
quint32 flags = 0;
if (mode.flags & OutputInterface::ModeFlag::Current) {
flags |= mode_current;
}
if (mode.flags & OutputInterface::ModeFlag::Preferred) {
flags |= mode_preferred;
}
send_mode(resource->handle, flags, mode.size.width(), mode.size.height(), mode.refreshRate);
send_mode(resource->handle, mode_current, mode.size.width(), mode.size.height(), mode.refreshRate);
}
void OutputInterfacePrivate::sendScale(Resource *resource)
......@@ -154,21 +145,7 @@ void OutputInterfacePrivate::output_release(Resource *resource)
void OutputInterfacePrivate::output_bind_resource(Resource *resource)
{
auto currentModeIt = modes.constEnd();
for (auto it = modes.constBegin(); it != modes.constEnd(); ++it) {
const OutputInterface::Mode &mode = *it;
if (mode.flags.testFlag(OutputInterface::ModeFlag::Current)) {
// needs to be sent as last mode
currentModeIt = it;
continue;
}
sendMode(resource, mode);
}
if (currentModeIt != modes.constEnd()) {
sendMode(resource, *currentModeIt);
}
sendMode(resource);
sendScale(resource);
sendGeometry(resource);
sendDone(resource);
......@@ -198,121 +175,40 @@ OutputInterface::~OutputInterface()
QSize OutputInterface::pixelSize() const
{
auto it = std::find_if(d->modes.constBegin(), d->modes.constEnd(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
}
);
if (it == d->modes.constEnd()) {
return QSize();
}
return (*it).size;
return d->mode.size;
}
int OutputInterface::refreshRate() const
{
auto it = std::find_if(d->modes.constBegin(), d->modes.constEnd(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
}
);
if (it == d->modes.constEnd()) {
return 60000;
}
return (*it).refreshRate;
return d->mode.refreshRate;
}
void OutputInterface::addMode(const QSize &size, OutputInterface::ModeFlags flags, int refreshRate)
OutputInterface::Mode OutputInterface::mode() const
{
auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
}
);
if (currentModeIt == d->modes.end() && !flags.testFlag(ModeFlag::Current)) {
// no mode with current flag - enforce
flags |= ModeFlag::Current;
}
if (currentModeIt != d->modes.end() && flags.testFlag(ModeFlag::Current)) {
// another mode has the current flag - remove
(*currentModeIt).flags &= ~uint(ModeFlag::Current);
}
return d->mode;
}
if (flags.testFlag(ModeFlag::Preferred)) {
// remove from existing Preferred mode
auto preferredIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Preferred);
}
);
if (preferredIt != d->modes.end()) {
(*preferredIt).flags &= ~uint(ModeFlag::Preferred);
}
void OutputInterface::setMode(const Mode &mode)
{
if (d->mode.size == mode.size && d->mode.refreshRate == mode.refreshRate) {
return;
}
auto modeIt = std::find_if(d->modes.begin(), d->modes.end(),
[size,refreshRate](const Mode &mode) {
return mode.size == size && mode.refreshRate == refreshRate;
}
);
if (modeIt != d->modes.end()) {
if ((*modeIt).flags == flags) {
// nothing to do
return;
}
(*modeIt).flags = flags;
} else {
Mode mode;
mode.size = size;
mode.refreshRate = refreshRate;
mode.flags = flags;
modeIt = d->modes.insert(d->modes.end(), mode);
}
d->mode = mode;
const auto outputResources = d->resourceMap();
for (OutputInterfacePrivate::Resource *resource : outputResources) {
d->sendMode(resource, *modeIt);
d->sendMode(resource);
}
emit modesChanged();
if (flags.testFlag(ModeFlag::Current)) {
emit refreshRateChanged(refreshRate);
emit pixelSizeChanged(size);
emit currentModeChanged();
}
emit modeChanged();
emit refreshRateChanged(mode.refreshRate);
emit pixelSizeChanged(mode.size);
}
void OutputInterface::setCurrentMode(const QSize &size, int refreshRate)
void OutputInterface::setMode(const QSize &size, int refreshRate)
{
auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
}
);
if (currentModeIt != d->modes.end()) {
// another mode has the current flag - remove
(*currentModeIt).flags &= ~uint(ModeFlag::Current);
}
auto existingModeIt = std::find_if(d->modes.begin(), d->modes.end(),
[size,refreshRate](const Mode &mode) {
return mode.size == size && mode.refreshRate == refreshRate;
}
);
Q_ASSERT(existingModeIt != d->modes.end());
(*existingModeIt).flags |= ModeFlag::Current;
const auto outputResources = d->resourceMap();
for (OutputInterfacePrivate::Resource *resource : outputResources) {
d->sendMode(resource, *existingModeIt);
}
emit modesChanged();
emit refreshRateChanged((*existingModeIt).refreshRate);
emit pixelSizeChanged((*existingModeIt).size);
emit currentModeChanged();
setMode({size, refreshRate});
}
QSize OutputInterface::physicalSize() const
......@@ -424,11 +320,6 @@ void OutputInterface::setTransform(Transform transform)
emit transformChanged(d->transform);
}
QList< OutputInterface::Mode > OutputInterface::modes() const
{
return d->modes;
}
void OutputInterface::setDpmsMode(OutputInterface::DpmsMode mode)
{
if (d->dpms.mode == mode) {
......
......@@ -54,15 +54,9 @@ public:
Flipped180,
Flipped270
};
enum class ModeFlag {
Current = 1,
Preferred = 2
};
Q_DECLARE_FLAGS(ModeFlags, ModeFlag)
struct Mode {
QSize size = QSize();
int refreshRate = 60000;
ModeFlags flags;
};
enum class DpmsMode {
On,
......@@ -83,7 +77,7 @@ public:
int scale() const;
SubPixel subPixel() const;
Transform transform() const;
QList<Mode> modes() const;
Mode mode() const;
bool isDpmsSupported() const;
DpmsMode dpmsMode() const;
......@@ -94,8 +88,8 @@ public:
void setScale(int scale);
void setSubPixel(SubPixel subPixel);
void setTransform(Transform transform);
void addMode(const QSize &size, ModeFlags flags = ModeFlags(), int refreshRate = 60000);
void setCurrentMode(const QSize &size, int refreshRate = 60000);
void setMode(const Mode &mode);
void setMode(const QSize &size, int refreshRate = 60000);
/**
* Sets whether Dpms is supported for this output.
......@@ -136,8 +130,7 @@ Q_SIGNALS:
void scaleChanged(int);
void subPixelChanged(SubPixel);
void transformChanged(Transform);
void modesChanged();
void currentModeChanged();
void modeChanged();
void dpmsModeChanged();
void dpmsSupportedChanged();
......@@ -159,7 +152,6 @@ private:
} // namespace KWaylandServer
Q_DECLARE_OPERATORS_FOR_FLAGS(KWaylandServer::OutputInterface::ModeFlags)
Q_DECLARE_METATYPE(KWaylandServer::OutputInterface::SubPixel)
Q_DECLARE_METATYPE(KWaylandServer::OutputInterface::Transform)
Q_DECLARE_METATYPE(KWaylandServer::OutputInterface::DpmsMode)
......@@ -250,7 +250,7 @@ int main(int argc, char **argv)
OutputInterface *output = new OutputInterface(&display, &display);
output->setPhysicalSize(QSize(269, 202));
const QSize windowSize(1024, 768);
output->addMode(windowSize);
output->setMode(windowSize);
SeatInterface *seat = new SeatInterface(&display);
seat->setHasKeyboard(true);
seat->setHasPointer(true);
......
......@@ -79,7 +79,7 @@ int main(int argc, char **argv)
new XdgShellInterface(&display, &display);
OutputInterface *output = new OutputInterface(&display, &display);
output->setPhysicalSize(QSize(10, 10));
output->addMode(QSize(1024, 768));
output->setMode(QSize(1024, 768));
// starts XWayland by forking and opening a pipe
const int pipe = startXServer();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment