Stateless constructor for Surfaces. More...
#include <phosphor-layer/include/PhosphorLayer/SurfaceFactory.h>
Classes | |
| struct | Deps |
| Dependency bundle for SurfaceFactory. More... | |
Public Member Functions | |
| SurfaceFactory (Deps deps, QObject *parent=nullptr) | |
| ~SurfaceFactory () override | |
| Surface * | create (SurfaceConfig cfg, QObject *parent=nullptr) |
| Create a Surface from a config. | |
| template<typename T > | |
| T * | createAs (SurfaceConfig cfg, QObject *parent=nullptr) |
| Create a Surface subclass from a config. | |
| const Deps & | deps () const noexcept |
| std::optional< SurfaceDeps > | validateAndPrepareDeps (SurfaceConfig &cfg) |
| Run the factory's validation and produce a SurfaceDeps ready for Surface construction. | |
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.
|
explicit |
|
override |
| Surface * PhosphorLayer::SurfaceFactory::create | ( | SurfaceConfig | cfg, |
| QObject * | parent = nullptr |
||
| ) |
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 falsecfg.contentUrl and cfg.contentItem set (or both empty)cfg.screen == nullptr and the screen provider has no primarycfg.sharedEngine and engineProvider both set (mutually exclusive)cfg.role.isValid() returns false
|
inline |
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:
|
noexcept |
| std::optional< SurfaceDeps > PhosphorLayer::SurfaceFactory::validateAndPrepareDeps | ( | SurfaceConfig & | cfg | ) |
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.