Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorAnimationShaders::AnimationShaderRegistry Class Reference

Registry of available animation shader transition effects. More...

#include <phosphor-animation/include/PhosphorAnimation/AnimationShaderRegistry.h>

Inheritance diagram for PhosphorAnimationShaders::AnimationShaderRegistry:
[legend]

Signals

void effectsChanged ()
 

Public Member Functions

 AnimationShaderRegistry (QObject *parent=nullptr)
 
 ~AnimationShaderRegistry () override
 
QList< AnimationShaderEffectavailableEffects () const
 
AnimationShaderEffect effect (const QString &id) const
 
bool hasEffect (const QString &id) const
 
QStringList effectIds () const
 
QVariantMap translateAnimationParams (const QString &effectId, const QVariantMap &friendlyParams) const
 Translate a friendly parameter map into the canonical slot keys consumed by both runtimes that drive animation shaders.
 
- Public Member Functions inherited from PhosphorFsLoader::MetadataPackRegistryBase
 ~MetadataPackRegistryBase () override
 
void addSearchPath (const QString &path, LiveReload liveReload=LiveReload::On)
 Add a single search-path directory.
 
void addSearchPaths (const QStringList &paths, LiveReload liveReload=LiveReload::On, RegistrationOrder order=RegistrationOrder::LowestPriorityFirst)
 Add multiple search-path directories in one shot.
 
QStringList searchPaths () const
 Currently-registered search paths in registration order.
 
void setUserPath (const QString &path)
 Mark path as the user-data root for isUser classification on discovered packs.
 
void refresh ()
 Synchronous rescan — re-walks every search path on the calling stack, replaces the strategy's pack map, and fires the consumer's content-changed signal if the strategy reports a signature change.
 

Static Public Member Functions

static QVariantMap translateAnimationParams (const AnimationShaderEffect &effect, const QVariantMap &friendlyParams)
 Static counterpart for callers that already hold the resolved AnimationShaderEffect (e.g.
 

Protected Member Functions

void onUserPathChanged (const QString &path) override
 Hook invoked from setUserPath when the path actually changes.
 
- Protected Member Functions inherited from PhosphorFsLoader::MetadataPackRegistryBase
 MetadataPackRegistryBase (const QLoggingCategory &logCat, std::unique_ptr< IScanStrategy > strategy, QObject *parent=nullptr)
 Construct the base, taking ownership of strategy.
 
IScanStrategystrategy () const
 Strategy accessor for subclasses.
 
WatchedDirectorySetwatcher () const
 Watcher accessor for subclasses that need direct ops not covered by the base API (e.g.
 

Detailed Description

Registry of available animation shader transition effects.

Discovers shader packs from configured search paths. Each pack is a subdirectory containing a metadata.json describing the effect plus the shader source files it references.

Directory layout

<search-path>/
dissolve/
metadata.json ← { "id": "dissolve", "fragmentShader": "effect.frag", ... }
effect.frag
slide/
metadata.json
effect.frag
AnimationShaderEffect effect(const QString &id) const

The subdirectory name is decorative — the id field in metadata.json is the registry key. This matches PhosphorShaders::ShaderRegistry's convention for zone shaders.

Search paths and live reload

Search-path management (addSearchPath, addSearchPaths, searchPaths, setUserPath, refresh) is inherited from PhosphorFsLoader::MetadataPackRegistryBase. The first addSearchPath[s] call with LiveReload::On (the default) installs a QFileSystemWatcher with the standard 50 ms debounce, parent-watch promotion for missing user-data dirs, per-file watches re-armed on every rescan, and rescan-during-rescan race protection. Forbidden roots ($HOME, /, XDG data/config/cache/temp/runtime, Documents, Downloads) are refused.

effectsChanged is gated on a SHA-1 signature change inside the strategy — emits exactly when the discovered set or any payload fingerprint actually differs from the previous scan, including any metadata.json field edit (the strategy mixes the metadata file's size+mtime into the per-rescan signature).

Thread safety

GUI-thread only for both reads and mutations. The pack map lives inside the strategy and is rebuilt on the GUI thread inside the rescan; the public lookup methods read it without synchronisation.

searchPaths() is the one exception: it returns a by-value snapshot of an implicitly-shared QStringList, so a GUI-thread caller can snapshot it and propagate the result to worker threads. Calling it from a worker thread concurrently with a GUI-thread mutation is a data race; snapshot on the GUI thread first.

Constructor & Destructor Documentation

◆ AnimationShaderRegistry()

PhosphorAnimationShaders::AnimationShaderRegistry::AnimationShaderRegistry ( QObject *  parent = nullptr)
explicit

◆ ~AnimationShaderRegistry()

PhosphorAnimationShaders::AnimationShaderRegistry::~AnimationShaderRegistry ( )
override

Member Function Documentation

◆ availableEffects()

QList< AnimationShaderEffect > PhosphorAnimationShaders::AnimationShaderRegistry::availableEffects ( ) const

◆ effect()

AnimationShaderEffect PhosphorAnimationShaders::AnimationShaderRegistry::effect ( const QString &  id) const

◆ effectIds()

QStringList PhosphorAnimationShaders::AnimationShaderRegistry::effectIds ( ) const

◆ effectsChanged

void PhosphorAnimationShaders::AnimationShaderRegistry::effectsChanged ( )
signal

◆ hasEffect()

bool PhosphorAnimationShaders::AnimationShaderRegistry::hasEffect ( const QString &  id) const

◆ onUserPathChanged()

void PhosphorAnimationShaders::AnimationShaderRegistry::onUserPathChanged ( const QString &  path)
overrideprotectedvirtual

Hook invoked from setUserPath when the path actually changes.

Subclass forwards the new value into the typed strategy (m_strategy->setUserPath(path)). The base then triggers a rescan if any directories are registered.

Implements PhosphorFsLoader::MetadataPackRegistryBase.

◆ translateAnimationParams() [1/2]

static QVariantMap PhosphorAnimationShaders::AnimationShaderRegistry::translateAnimationParams ( const AnimationShaderEffect effect,
const QVariantMap &  friendlyParams 
)
static

Static counterpart for callers that already hold the resolved AnimationShaderEffect (e.g.

the kwin-effect's per-frame translation). Same slot-allocation contract as the registry-keyed overload.

◆ translateAnimationParams() [2/2]

QVariantMap PhosphorAnimationShaders::AnimationShaderRegistry::translateAnimationParams ( const QString &  effectId,
const QVariantMap &  friendlyParams 
) const

Translate a friendly parameter map into the canonical slot keys consumed by both runtimes that drive animation shaders.

Two independent allocators advance in metadata declaration order:

• Float / int / bool parameters fill customParams<N>_<x|y|z|w> — the first declared param lands in customParams1_x, the second in customParams1_y, …, the fifth in customParams2_x, up to 32 slots (AnimationShaderContract::kMaxParameterSlots).

• Color parameters fill customColor<N> — the first declared color lands in customColor1, the second in customColor2, up to 16 slots (AnimationShaderContract::kMaxCustomColors). Color values are coerced to QColor at this boundary — anything QColor::QColor(QString) accepts is accepted here too (the common cases are "#rgb", "#rrggbb", and "#aarrggbb" with alpha FIRST per Qt's convention; the parser also recognises higher-bit-depth "#rrrgggbbb" / "#rrrrggggbbbb", SVG colour names like "red", and the "transparent" keyword) — alongside QColor instances. Everything else falls back to the declared default, then Qt::transparent. CSS-style "#rrggbbaa" (alpha LAST, 9 chars) is NOT accepted — any 9-char hex string is ambiguous between Qt-form and CSS-form, so a rewrite would silently corrupt configs that already use Qt's order; settings UI / config writers MUST emit Qt-form.

The two allocators advance independently — a color parameter does NOT consume a customParams sub-slot, so a [color, float] declaration produces customColor1 + customParams1_x, not customColor1 + customParams1_y.

Bool values become 0.0 or 1.0. Missing float keys fall back to the metadata-declared default, then to 0.0. Unknown parameter ids in friendlyParams are silently ignored. Slot-budget overflows log a warning and drop the offending parameter.

Returns an empty map when effectId resolves to no registered effect or when the effect declares no parameters.


The documentation for this class was generated from the following file: