core/outputconfig: store output properties with std::optional

This commit is contained in:
Xaver Hugl 2023-03-07 18:40:26 +01:00
parent 08bebd1c4a
commit 6b8e08dfa9
5 changed files with 44 additions and 45 deletions

View file

@ -404,18 +404,18 @@ bool DrmOutput::queueChanges(const OutputConfiguration &config)
static int envOnlySoftwareRotations = qEnvironmentVariableIntValue("KWIN_DRM_SW_ROTATIONS_ONLY", &valid) == 1 || !valid; static int envOnlySoftwareRotations = qEnvironmentVariableIntValue("KWIN_DRM_SW_ROTATIONS_ONLY", &valid) == 1 || !valid;
const auto props = config.constChangeSet(this); const auto props = config.constChangeSet(this);
const auto mode = props->mode.lock(); const auto mode = props->mode.value_or(currentMode()).lock();
if (!mode) { if (!mode) {
return false; return false;
} }
m_pipeline->setMode(std::static_pointer_cast<DrmConnectorMode>(mode)); m_pipeline->setMode(std::static_pointer_cast<DrmConnectorMode>(mode));
m_pipeline->setOverscan(props->overscan); m_pipeline->setOverscan(props->overscan.value_or(m_pipeline->overscan()));
m_pipeline->setRgbRange(props->rgbRange); m_pipeline->setRgbRange(props->rgbRange.value_or(m_pipeline->rgbRange()));
m_pipeline->setRenderOrientation(outputToPlaneTransform(props->transform)); m_pipeline->setRenderOrientation(outputToPlaneTransform(props->transform.value_or(transform())));
if (!envOnlySoftwareRotations && m_gpu->atomicModeSetting()) { if (!envOnlySoftwareRotations && m_gpu->atomicModeSetting()) {
m_pipeline->setBufferOrientation(m_pipeline->renderOrientation()); m_pipeline->setBufferOrientation(m_pipeline->renderOrientation());
} }
m_pipeline->setEnable(props->enabled); m_pipeline->setEnable(props->enabled.value_or(m_pipeline->enabled()));
return true; return true;
} }
@ -431,15 +431,15 @@ void DrmOutput::applyQueuedChanges(const OutputConfiguration &config)
State next = m_state; State next = m_state;
next.enabled = props->enabled && m_pipeline->crtc(); next.enabled = props->enabled && m_pipeline->crtc();
next.position = props->pos; next.position = props->pos.value_or(m_state.position);
next.scale = props->scale; next.scale = props->scale.value_or(m_state.scale);
next.transform = props->transform; next.transform = props->transform.value_or(m_state.transform);
next.currentMode = m_pipeline->mode(); next.currentMode = m_pipeline->mode();
next.overscan = m_pipeline->overscan(); next.overscan = m_pipeline->overscan();
next.rgbRange = m_pipeline->rgbRange(); next.rgbRange = m_pipeline->rgbRange();
setState(next); setState(next);
setVrrPolicy(props->vrrPolicy); setVrrPolicy(props->vrrPolicy.value_or(vrrPolicy()));
if (!isEnabled() && m_pipeline->needsModeset()) { if (!isEnabled() && m_pipeline->needsModeset()) {
m_gpu->maybeModeset(); m_gpu->maybeModeset();

View file

@ -225,14 +225,14 @@ void Output::applyChanges(const OutputConfiguration &config)
Q_EMIT aboutToChange(); Q_EMIT aboutToChange();
State next = m_state; State next = m_state;
next.enabled = props->enabled; next.enabled = props->enabled.value_or(m_state.enabled);
next.transform = props->transform; next.transform = props->transform.value_or(m_state.transform);
next.position = props->pos; next.position = props->pos.value_or(m_state.position);
next.scale = props->scale; next.scale = props->scale.value_or(m_state.scale);
next.rgbRange = props->rgbRange; next.rgbRange = props->rgbRange.value_or(m_state.rgbRange);
setState(next); setState(next);
setVrrPolicy(props->vrrPolicy); setVrrPolicy(props->vrrPolicy.value_or(vrrPolicy()));
Q_EMIT changed(); Q_EMIT changed();
} }

View file

@ -13,25 +13,15 @@ namespace KWin
std::shared_ptr<OutputChangeSet> OutputConfiguration::changeSet(Output *output) std::shared_ptr<OutputChangeSet> OutputConfiguration::changeSet(Output *output)
{ {
const auto ptr = constChangeSet(output); auto &ret = m_properties[output];
m_properties[output] = ptr; if (!ret) {
return ptr; ret = std::make_shared<OutputChangeSet>();
}
return ret;
} }
std::shared_ptr<OutputChangeSet> OutputConfiguration::constChangeSet(Output *output) const std::shared_ptr<OutputChangeSet> OutputConfiguration::constChangeSet(Output *output) const
{ {
if (!m_properties.contains(output)) {
auto props = std::make_shared<OutputChangeSet>();
props->enabled = output->isEnabled();
props->pos = output->geometry().topLeft();
props->scale = output->scale();
props->mode = output->currentMode();
props->transform = output->transform();
props->overscan = output->overscan();
props->rgbRange = output->rgbRange();
props->vrrPolicy = output->vrrPolicy();
return props;
}
return m_properties[output]; return m_properties[output];
} }
} }

View file

@ -21,14 +21,14 @@ namespace KWin
class KWIN_EXPORT OutputChangeSet class KWIN_EXPORT OutputChangeSet
{ {
public: public:
std::weak_ptr<OutputMode> mode; std::optional<std::weak_ptr<OutputMode>> mode;
bool enabled; std::optional<bool> enabled;
QPoint pos; std::optional<QPoint> pos;
float scale; std::optional<double> scale;
Output::Transform transform; std::optional<Output::Transform> transform;
uint32_t overscan; std::optional<uint32_t> overscan;
Output::RgbRange rgbRange; std::optional<Output::RgbRange> rgbRange;
RenderLoop::VrrPolicy vrrPolicy; std::optional<RenderLoop::VrrPolicy> vrrPolicy;
}; };
class KWIN_EXPORT OutputConfiguration class KWIN_EXPORT OutputConfiguration

View file

@ -145,7 +145,7 @@ enum Rotation {
Right = 8, Right = 8,
}; };
Output::Transform toDrmTransform(int rotation) Output::Transform toKWinTransform(int rotation)
{ {
switch (Rotation(rotation)) { switch (Rotation(rotation)) {
case None: case None:
@ -207,18 +207,27 @@ std::optional<std::pair<OutputConfiguration, QVector<Output *>>> readOutputConfi
} else { } else {
outputOrder.push_back(std::make_pair(0, output)); outputOrder.push_back(std::make_pair(0, output));
} }
const QJsonObject pos = outputInfo["pos"].toObject(); if (const QJsonObject pos = outputInfo["pos"].toObject(); !pos.isEmpty()) {
props->pos = QPoint(pos["x"].toInt(), pos["y"].toInt()); props->pos = QPoint(pos["x"].toInt(), pos["y"].toInt());
}
// settings that are independent of per output setups: // settings that are independent of per output setups:
const auto &globalInfo = globalOutputInfo ? globalOutputInfo.value() : outputInfo; const auto &globalInfo = globalOutputInfo ? globalOutputInfo.value() : outputInfo;
if (const QJsonValue scale = globalInfo["scale"]; !scale.isUndefined()) { if (const QJsonValue scale = globalInfo["scale"]; !scale.isUndefined()) {
props->scale = scale.toDouble(1.); props->scale = scale.toDouble(1.);
} }
props->transform = KScreenIntegration::toDrmTransform(globalInfo["rotation"].toInt()); if (const QJsonValue rotation = globalInfo["rotation"]; !rotation.isUndefined()) {
props->overscan = static_cast<uint32_t>(globalInfo["overscan"].toInt(props->overscan)); props->transform = KScreenIntegration::toKWinTransform(rotation.toInt());
props->vrrPolicy = static_cast<RenderLoop::VrrPolicy>(globalInfo["vrrpolicy"].toInt(static_cast<uint32_t>(props->vrrPolicy))); }
props->rgbRange = static_cast<Output::RgbRange>(globalInfo["rgbrange"].toInt(static_cast<uint32_t>(props->rgbRange))); if (const QJsonValue overscan = globalInfo["overscan"]; !overscan.isUndefined()) {
props->overscan = globalInfo["overscan"].toInt();
}
if (const QJsonValue vrrpolicy = globalInfo["vrrpolicy"]; !vrrpolicy.isUndefined()) {
props->vrrPolicy = static_cast<RenderLoop::VrrPolicy>(vrrpolicy.toInt());
}
if (const QJsonValue rgbrange = globalInfo["rgbrange"]; !rgbrange.isUndefined()) {
props->rgbRange = static_cast<Output::RgbRange>(rgbrange.toInt());
}
if (const QJsonObject modeInfo = globalInfo["mode"].toObject(); !modeInfo.isEmpty()) { if (const QJsonObject modeInfo = globalInfo["mode"].toObject(); !modeInfo.isEmpty()) {
if (auto mode = KScreenIntegration::parseMode(output, modeInfo)) { if (auto mode = KScreenIntegration::parseMode(output, modeInfo)) {