Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
DecorationProfile.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorSurface/phosphorsurface_export.h>
7
8// ShaderFamily is needed by VALUE in the withPresetsResolved signature below, so the
9// enum's own header comes in. The registry itself is only named as a reference in that
10// same declaration, so it is forward-declared instead, like the animation twin does.
12
13#include <QJsonObject>
14#include <QString>
15#include <QStringList>
16#include <QVariantMap>
17// For qWarning / qUtf8Printable in effectiveParameters() below. Named explicitly
18// rather than relied on through another Qt header: the unity build hides a missing
19// include, and the non-unity build is the only place it surfaces.
20#include <QMutex>
21#include <QSet>
22#include <QtGlobal>
23
24#include <algorithm>
25#include <optional>
26
27namespace PhosphorShaders {
29}
30
32
40inline constexpr int kMaxDecorationOuterPaddingPx = 128;
41
67class PHOSPHORSURFACE_EXPORT DecorationProfile
68{
69public:
73 std::optional<QStringList> chain;
74
79 std::optional<QVariantMap> parameters;
80
87 std::optional<QStringList> disabledPacks;
88
101 std::optional<QVariantMap> presetIds;
102
103 // ─────── Effective getters ───────
104
105 QStringList effectiveChain() const
106 {
107 return chain.value_or(QStringList());
108 }
109
117 QVariantMap storedParameters() const
118 {
119 return parameters.value_or(QVariantMap());
120 }
121
143 QVariantMap effectiveParameters() const
144 {
145 // ONCE per (pack, presetId). This getter is read from the compositor's decorate
146 // path and the shell's chain resolve, so an unflattened consumer would repeat the
147 // warning every frame it draws. The animation twin latches the same way, and for
148 // the reason the decoration parser nearby chose qCDebug: the level is right for a
149 // contract violation, the repetition is not.
150 if (presetIds) {
151 for (auto it = presetIds->constBegin(); it != presetIds->constEnd(); ++it) {
152 if (it.value().toString().isEmpty()) {
153 continue;
154 }
155 // Guarded: this getter is const on a value type whose class doc says it is not
156 // internally synchronized, and contains()+insert() on a shared QSet is not
157 // atomic (only the static's INITIALISATION is). The set is bounded by the
158 // user's own config, so growth is not the concern; a torn read is.
159 //
160 // The latch is process-wide, which is why no test asserts "warns exactly
161 // once": a slot doing that would pass or fail on slot ORDER within the
162 // binary. A test that wants to see the warning has to use a (pack, preset)
163 // pair no earlier slot has touched, which the key makes possible.
164 static QMutex latchMutex;
165 static QSet<QString> reported;
166 const QMutexLocker latchLock(&latchMutex);
167 const QString key = it.key() + QLatin1Char('\x1f') + it.value().toString();
168 if (!reported.contains(key)) {
169 reported.insert(key);
170 qWarning(
171 "PhosphorSurface: DecorationProfile::effectiveParameters() read on a profile whose preset "
172 "is NOT yet applied (pack=%s presetId=%s). The preset's values are missing from the result "
173 "and its declared range is unenforced — flatten with withPresetsResolved() after the tree "
174 "walk-up, never per node. Reported once per pack and preset.",
175 qUtf8Printable(it.key()), qUtf8Printable(it.value().toString()));
176 }
177 break;
178 }
179 }
180 return parameters.value_or(QVariantMap());
181 }
182 QStringList effectiveDisabledPacks() const
183 {
184 return disabledPacks.value_or(QStringList());
185 }
186 QVariantMap effectivePresetIds() const
187 {
188 return presetIds.value_or(QVariantMap());
189 }
190
197 QString presetIdFor(const QString& packId) const
198 {
199 return presetIds ? presetIds->value(packId).toString() : QString();
200 }
201
205 QStringList enabledChain() const
206 {
207 QStringList out = effectiveChain();
208 if (disabledPacks && !disabledPacks->isEmpty()) {
209 out.erase(std::remove_if(out.begin(), out.end(),
210 [this](const QString& id) {
211 return disabledPacks->contains(id);
212 }),
213 out.end());
214 }
215 return out;
216 }
217
219
220 // ─────── Serialization ───────
221
222 static constexpr auto JsonFieldChain = "chain";
223 static constexpr auto JsonFieldParameters = "parameters";
224 static constexpr auto JsonFieldDisabledPacks = "disabledPacks";
225 static constexpr auto JsonFieldPresetIds = "presetIds";
226
227 QJsonObject toJson() const;
228 static DecorationProfile fromJson(const QJsonObject& obj);
229
230 // ─────── Overlay ───────
231
234 static void overlay(DecorationProfile& dst, const DecorationProfile& src);
235
236 // ─────── Equality ───────
237
238 bool operator==(const DecorationProfile& other) const;
239 bool operator!=(const DecorationProfile& other) const
240 {
241 return !(*this == other);
242 }
243};
244
263PHOSPHORSURFACE_EXPORT DecorationProfile withPresetsResolved(const DecorationProfile& profile,
266
267} // namespace PhosphorSurfaceShaders
The one place a presetId on an assignment turns into parameters.
Definition ShaderPresetRegistry.h:51
Per-surface decoration shader-pack chain and its per-pack parameters.
Definition DecorationProfile.h:68
static constexpr auto JsonFieldDisabledPacks
Definition DecorationProfile.h:224
QString presetIdFor(const QString &packId) const
The preset chosen for packId, or an empty string when that layer uses none.
Definition DecorationProfile.h:197
std::optional< QStringList > disabledPacks
Pack ids from chain that are toggled OFF (the per-layer disable toggle — same semantics as a rule's e...
Definition DecorationProfile.h:87
bool operator!=(const DecorationProfile &other) const
Definition DecorationProfile.h:239
static DecorationProfile fromJson(const QJsonObject &obj)
QStringList effectiveDisabledPacks() const
Definition DecorationProfile.h:182
QVariantMap storedParameters() const
The stored per-pack parameter map, without judgement.
Definition DecorationProfile.h:117
static void overlay(DecorationProfile &dst, const DecorationProfile &src)
Overlay src onto dst: every engaged field in src replaces the corresponding field in dst.
static constexpr auto JsonFieldPresetIds
Definition DecorationProfile.h:225
std::optional< QVariantMap > presetIds
Per-pack preset selection.
Definition DecorationProfile.h:101
static constexpr auto JsonFieldChain
Definition DecorationProfile.h:222
QStringList effectiveChain() const
Definition DecorationProfile.h:105
DecorationProfile withDefaults() const
bool operator==(const DecorationProfile &other) const
QVariantMap effectivePresetIds() const
Definition DecorationProfile.h:186
QStringList enabledChain() const
The chain the RENDERERS consume: effectiveChain() minus the disabled packs.
Definition DecorationProfile.h:205
QVariantMap effectiveParameters() const
The parameter map a RENDERER should consume.
Definition DecorationProfile.h:143
std::optional< QVariantMap > parameters
Per-pack parameter overrides.
Definition DecorationProfile.h:79
static constexpr auto JsonFieldParameters
Definition DecorationProfile.h:223
std::optional< QStringList > chain
Ordered surface-pack ids, resolved by id from SurfaceShaderRegistry, e.g.
Definition DecorationProfile.h:73
Definition ShaderProfile.h:21
ShaderFamily
Which shader family a preset belongs to.
Definition ShaderPreset.h:28
Definition DecorationProfile.h:31
PHOSPHORSURFACE_EXPORT DecorationProfile withPresetsResolved(const DecorationProfile &profile, const PhosphorShaders::ShaderPresetRegistry &presets, PhosphorShaders::ShaderFamily family)
Flatten profile's per-pack preset references into its parameters.
constexpr int kMaxDecorationOuterPaddingPx
Hard cap on a decoration chain's outer padding, in device-independent px.
Definition DecorationProfile.h:40