Stateless constructor for Surfaces.
More...
#include <PhosphorLayer/SurfaceFactory.h>
Stateless constructor for Surfaces.
Holds references to injected dependencies; each create() call produces one Surface that inherits those dependencies.
Single responsibility: turn a SurfaceConfig into a live Surface. For multi-screen patterns use ScreenSurfaceRegistry; for topology response use TopologyCoordinator. Those compose the factory but do not replace it.
◆ SurfaceFactory()
| PhosphorLayer::SurfaceFactory::SurfaceFactory |
( |
Deps | deps, |
|
|
QObject * | parent = nullptr ) |
|
explicit |
◆ ~SurfaceFactory()
| PhosphorLayer::SurfaceFactory::~SurfaceFactory |
( |
| ) |
|
|
override |
◆ create()
Create a Surface from a config.
The returned Surface is owned by parent (or by the factory if parent is nullptr). Failure modes all yield nullptr + a logged reason:
- deps.transport->isSupported() is false
- Both cfg.contentUrl and cfg.contentItem set (or both empty)
- cfg.screen == nullptr and the screen provider has no primary
- cfg.sharedEngine and engineProvider both set (mutually exclusive)
- cfg.contextProperties set together with cfg.contentItem, which was created in its caller's own context and cannot see them
- cfg.role.isValid() returns false
◆ createAs()
template<typename T>
| T * PhosphorLayer::SurfaceFactory::createAs |
( |
SurfaceConfig | cfg, |
|
|
QObject * | parent = nullptr ) |
|
inlinenodiscard |
Create a Surface subclass from a config.
Same validation as create() but instantiates T instead of Surface itself. T must derive from Surface and expose a constructor with the signature T(Surface::CtorToken, SurfaceConfig, SurfaceDeps, QObject*) — forwarding its CtorToken argument to the Surface base is the entire required pattern. The CtorToken is factory-only-constructible, so consumers cannot bypass this validation via direct new T(...) even when T exposes a public constructor.
Example:
public:
QObject* parent)
:
Surface(tok, std::move(cfg), std::move(
deps), parent) {}
};
auto* s = factory.createAs<PhosphorOverlaySurface>(std::move(cfg));
const Deps & deps() const noexcept
Opaque construction token — only SurfaceFactory can create instances of it.
Definition Surface.h:257
One layer-shell surface with a managed lifecycle.
Definition Surface.h:105
Immutable per-surface configuration passed to SurfaceFactory::create().
Definition SurfaceConfig.h:47
Bundle of dependencies the Surface inherits from the factory.
Definition Surface.h:42
◆ deps()
| const Deps & PhosphorLayer::SurfaceFactory::deps |
( |
| ) |
const |
|
noexcept |
◆ validateAndPrepareDeps()
Run the factory's validation and produce a SurfaceDeps ready for Surface construction.
Returns std::nullopt on any failure (all failures logged via qCWarning).
Exposed publicly because the createAs<T> template above must call it at the instantiation site. Consumers should prefer create() / createAs<T>() over this method directly — they handle the new-expression and parent-ownership wiring for you.
The documentation for this class was generated from the following file: