One per consumer, holding every shader preset for every family it names. More...
#include <PhosphorShaders/ShaderPresetStore.h>
Public Member Functions | |
| ShaderPresetStore (QObject *parent=nullptr) | |
| ~ShaderPresetStore () override | |
| ShaderPresetStore (const ShaderPresetStore &)=delete | |
| ShaderPresetStore & | operator= (const ShaderPresetStore &)=delete |
| void | load (const QString &root, const QList< ShaderFamily > &families={}) |
| Import any legacy overlay presets, then scan the named families. | |
| ShaderPresetRegistry & | registry () |
| The registry every consumer resolves through. | |
| const ShaderPresetRegistry & | registry () const |
| bool | publishes (ShaderFamily family) const |
Whether this store publishes family, i.e. | |
| bool | rescanNow (ShaderFamily family) |
Rescan family's directory synchronously, so the registry reflects the new state before this returns. | |
| QString | directoryFor (ShaderFamily family) const |
Where a new user preset for family belongs. | |
One per consumer, holding every shader preset for every family it names.
One per consumer rather than one per process, and that is a convention, not an invariant: nothing here refuses a second instance. Two would double the directory watchers and parse every preset file twice, which is wasteful rather than wrong, so the four consumers each keep exactly one.
The whole preset side of a consumer's wiring: the registry, one publisher per family, and the one-shot import of the pre-existing overlay preset files. Four consumers need all of this — the settings app, the daemon, the KWin effect and the shell — and none of them differs in how it sets it up, so it lives here rather than four times over.
A consumer names the families it actually resolves. The effect resolves animation, surface and pointer presets; the daemon resolves animation, surface and overlay; the shell resolves surface only, for its own chrome; the settings app shows all four. An unlisted family simply has no user presets, which is the registry's documented miss behaviour.
Pack-declared presets are NOT loaded here — they arrive from each family's pack registry, whose reload edge the consumer feeds through PhosphorShaders::seedPackPresets. That helper goes through setPackPresetsForFamily, which diffs the whole family and so retracts a pack that has gone; the per-pack setPackPresets overload cannot, which is why no production consumer uses it. This object owns the user side and the directory layout; it deliberately knows nothing about pack registries, which live in four different libraries.
There used to be a ShaderPresetLoader between this and PhosphorFsLoader::DirectoryLoader: a forwarder of four methods, owning a parse sink, with a destructor that retracted its whole family from the registry. Three separate teardown faults lived in the seam, including a use-after-free that crashed the daemon on every shutdown, and they had one shared cause — the invariant "a family has exactly one publisher" had no owner. The loader ASSUMED it (its retraction was whole-family, correct only under that assumption), the registry did not know about it, and this class was the only one positioned to enforce it and merely happened to.
So the publisher is now a slot in a fixed array here, one per family, and the invariant is a property of the data structure rather than of a check: a second publisher for a family is not something this class can be asked to build.
And the teardown retraction is GONE rather than relocated. It only ever existed because the loader could not see whether anyone else published for its family, and it only made sense while the registry outlived the loaders. The registry is now a by-value member destroyed with this store, so there is nothing to retract FOR — and emitting presetsChanged during teardown was itself a hazard, because a consumer's handler runs until ~QObject severs its connections, which is after its members are already destroyed. That removes the use-after-free with no QPointer anywhere in it, and without trading it for one in the consumer.
NOTE for a second store in one process: each carries its own registry, so two of them do not corrupt each other — they just pay for two sets of watchers and parse every saved preset twice. One per consumer is the intent.
GUI-thread only, like the registry it owns.
|
explicit |
|
override |
|
delete |
| QString PhosphorShaders::ShaderPresetStore::directoryFor | ( | ShaderFamily | family | ) | const |
Where a new user preset for family belongs.
| void PhosphorShaders::ShaderPresetStore::load | ( | const QString & | root, |
| const QList< ShaderFamily > & | families = {} ) |
Import any legacy overlay presets, then scan the named families.
Safe to call from every process that has one of these, and in any order: the migration derives its target ids from the old filenames, so two processes racing it agree on the result instead of importing twice.
A family already publishing is left exactly as it is, so a second call cannot produce two publishers for one family — and now cannot even be asked to, because the publisher IS the slot.
| root | The preset root, normally standardUserPresetRoot() of the app's preset subdirectory. Tests pass a temporary directory. Must be an absolute path — an empty or relative root would resolve against the process working directory, and is refused with a warning. |
| families | Which families to publish. Empty (the default) means all four. A consumer that resolves only some of them should name them: a publisher is not just one startup scan, it holds a QFileSystemWatcher and RE-PARSES every file in its directory each time the user saves a preset there. The compositor paid that on its own thread for the overlay family it cannot consult at all. |
|
delete |
| bool PhosphorShaders::ShaderPresetStore::publishes | ( | ShaderFamily | family | ) | const |
Whether this store publishes family, i.e.
whether load() was called and named it. False for every family before load().
A DIAGNOSTIC accessor, like setPackPresets above: no production caller reads it today, and the tests use it to assert which families a consumer's load() actually brought up. Stated here because a function with no caller otherwise reads as something the next audit should delete, and this one is cheap to keep — it is the only way to ask the question without inferring it from a rescan's return.
| ShaderPresetRegistry & PhosphorShaders::ShaderPresetStore::registry | ( | ) |
The registry every consumer resolves through.
| const ShaderPresetRegistry & PhosphorShaders::ShaderPresetStore::registry | ( | ) | const |
| bool PhosphorShaders::ShaderPresetStore::rescanNow | ( | ShaderFamily | family | ) |
Rescan family's directory synchronously, so the registry reflects the new state before this returns.
This is what the WRITE side wants: after saving a preset file the picker has to show it in the same turn rather than a debounce later, and the caller usually wants to select what it just saved.
family, so a caller that saved into a family it never loaded learns that rather than silently getting a stale list.