[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
This commit is contained in:
Roman Gilg 2019-08-28 14:23:55 +02:00
parent 77730f7fa7
commit b8c28c8a85
2 changed files with 11 additions and 6 deletions

View file

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

View file

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