[server] Cache current mode

Summary:
Instead of looping over all modes for retrieving current mode data copy it
to a separate variable.

Test Plan:
KWin auto tests pass and KScreen in Wayland nested session shows correct
information.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, kde-frameworks-devel

Tags: #frameworks

Maniphest Tasks: T11459

Differential Revision: https://phabricator.kde.org/D23493
This commit is contained in:
Roman Gilg 2019-08-27 15:31:25 +02:00
parent 18ec7ff484
commit 77730f7fa7

View file

@ -73,6 +73,7 @@ public:
Transform transform = Transform::Normal;
ColorCurves colorCurves;
QList<Mode> modes;
Mode currentMode;
QList<ResourceData> resources;
QByteArray edid;
@ -161,15 +162,11 @@ OutputDeviceInterface::~OutputDeviceInterface() = default;
QSize OutputDeviceInterface::pixelSize() const
{
Q_D();
auto it = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
}
);
if (it == d->modes.end()) {
if (d->currentMode.id == -1) {
return QSize();
}
return (*it).size;
return d->currentMode.size;
}
OutputDeviceInterface *OutputDeviceInterface::get(wl_resource* native)
@ -180,15 +177,11 @@ OutputDeviceInterface *OutputDeviceInterface::get(wl_resource* native)
int OutputDeviceInterface::refreshRate() const
{
Q_D();
auto it = std::find_if(d->modes.begin(), d->modes.end(),
[](const Mode &mode) {
return mode.flags.testFlag(ModeFlag::Current);
}
);
if (it == d->modes.end()) {
if (d->currentMode.id == -1) {
return 60000;
}
return (*it).refreshRate;
return d->currentMode.refreshRate;
}
void OutputDeviceInterface::addMode(Mode &mode)
@ -230,9 +223,10 @@ void OutputDeviceInterface::addMode(Mode &mode)
mode.id == mode_it.id;
}
);
auto emitChanges = [this,mode] {
auto emitChanges = [this, d, mode] {
emit modesChanged();
if (mode.flags.testFlag(ModeFlag::Current)) {
d->currentMode = mode;
emit refreshRateChanged(mode.refreshRate);
emit pixelSizeChanged(mode.size);
emit currentModeChanged();
@ -283,6 +277,7 @@ void OutputDeviceInterface::setCurrentMode(const int modeId)
Q_ASSERT(existingModeIt != d->modes.end());
(*existingModeIt).flags |= ModeFlag::Current;
d->currentMode = *existingModeIt;
emit modesChanged();
emit refreshRateChanged((*existingModeIt).refreshRate);
emit pixelSizeChanged((*existingModeIt).size);