From b8c28c8a8585f3763f6c6efc05fdbf313e7013db Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Wed, 28 Aug 2019 14:23:55 +0200 Subject: [PATCH] [server] Use cached current mode more and assert validness Summary: We can use the cached current mode in one more case. Additionally make it more explicit what a valid mode is and when to add them. Test Plan: Relevant autotests pass. KWin Wayland nested and DRM session work. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D23535 --- src/wayland/server/outputdevice_interface.cpp | 10 ++++------ src/wayland/server/outputdevice_interface.h | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/wayland/server/outputdevice_interface.cpp b/src/wayland/server/outputdevice_interface.cpp index 4ae68ceafe..f600116853 100644 --- a/src/wayland/server/outputdevice_interface.cpp +++ b/src/wayland/server/outputdevice_interface.cpp @@ -136,12 +136,9 @@ OutputDeviceInterface::OutputDeviceInterface(Display *display, QObject *parent) Q_D(); connect(this, &OutputDeviceInterface::currentModeChanged, this, [this, d] { - auto currentModeIt = std::find_if(d->modes.constBegin(), d->modes.constEnd(), [](const Mode &mode) { return mode.flags.testFlag(ModeFlag::Current); }); - if (currentModeIt == d->modes.constEnd()) { - return; - } + Q_ASSERT(d->currentMode.id >= 0); for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { - d->sendMode((*it).resource, *currentModeIt); + d->sendMode((*it).resource, d->currentMode); d->sendDone(*it); } wl_display_flush_clients(*(d->display)); @@ -187,9 +184,10 @@ int OutputDeviceInterface::refreshRate() const void OutputDeviceInterface::addMode(Mode &mode) { Q_ASSERT(!isValid()); + Q_ASSERT(mode.id >= 0); + Q_ASSERT(mode.size.isValid()); Q_D(); - auto currentModeIt = std::find_if(d->modes.begin(), d->modes.end(), [](const Mode &mode) { return mode.flags.testFlag(ModeFlag::Current); diff --git a/src/wayland/server/outputdevice_interface.h b/src/wayland/server/outputdevice_interface.h index a9424cb671..2d20f0d8b3 100644 --- a/src/wayland/server/outputdevice_interface.h +++ b/src/wayland/server/outputdevice_interface.h @@ -132,6 +132,13 @@ public: void setSubPixel(SubPixel subPixel); void setTransform(Transform transform); void setColorCurves(const ColorCurves &colorCurves); + + /** + * Add an additional mode to this output device. This is only allowed before create() is called + * on the object. + * + * @param mode must have a valid size and non-negative id. + */ void addMode(Mode &mode); void setCurrentMode(const int modeId);