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

Stateless constructor for Surfaces. More...

#include <phosphor-layer/include/PhosphorLayer/SurfaceFactory.h>

Inheritance diagram for PhosphorLayer::SurfaceFactory:
[legend]

Classes

struct  Deps
 Dependency bundle for SurfaceFactory. More...
 

Public Member Functions

 SurfaceFactory (Deps deps, QObject *parent=nullptr)
 
 ~SurfaceFactory () override
 
Surfacecreate (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 Depsdeps () const noexcept
 
std::optional< SurfaceDepsvalidateAndPrepareDeps (SurfaceConfig &cfg)
 Run the factory's validation and produce a SurfaceDeps ready for Surface construction.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SurfaceFactory()

PhosphorLayer::SurfaceFactory::SurfaceFactory ( Deps  deps,
QObject *  parent = nullptr 
)
explicit

◆ ~SurfaceFactory()

PhosphorLayer::SurfaceFactory::~SurfaceFactory ( )
override

Member Function Documentation

◆ create()

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 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.role.isValid() returns false

◆ createAs()

template<typename T >
T * PhosphorLayer::SurfaceFactory::createAs ( SurfaceConfig  cfg,
QObject *  parent = nullptr 
)
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:

class PzOverlaySurface : public PhosphorLayer::Surface {
public:
PzOverlaySurface(Surface::CtorToken tok,
QObject* parent)
: Surface(tok, std::move(cfg), std::move(deps), parent) {}
};
auto* s = factory.createAs<PzOverlaySurface>(std::move(cfg));
Opaque construction token — only SurfaceFactory can create instances of it.
Definition Surface.h:222
One layer-shell surface with a managed lifecycle.
Definition Surface.h:99
Immutable per-surface configuration passed to SurfaceFactory::create().
Definition SurfaceConfig.h:46
Bundle of dependencies the Surface inherits from the factory.
Definition Surface.h:42

◆ deps()

const Deps & PhosphorLayer::SurfaceFactory::deps ( ) const
noexcept

◆ validateAndPrepareDeps()

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.


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