Layers
Source:
Layers.h
Layers¶
src/light/layers/Layers.h:18Inherits:
MoonModule
Top-level container for one or more Layer children.
Each child Layer renders independently into its own buffer using the shared Layouts instance for physical topology. Drivers composites the resulting buffers in container order (bottom→top) per each Layer's blendMode and opacity.
Why a container: multi-layer composition (alpha-blend, additive, layered overlays) needs a place to walk every layer in order so drivers can merge their buffers before consuming the result. With one child Layer this is a thin pass-through: [tick()] runs the child Layer's [tick()] in order; behaviour matches the single-Layer pipeline byte-for-byte (Drivers takes its single-layer fast path).
No buffer of its own: each Layer owns its buffer and the Drivers container owns the composited output. Layers wires the shared Layouts into every child so each can size its buffer. Two queries serve the Drivers compositor: activeLayer (the first enabled child, or a disabled one as fallback) answers physical dimensions and feeds the single-layer fast path, and forEachEnabledLayer walks the enabled children in container order (bottom→top) marking the bottom layer that clears the buffer. enabledLayerCount lets Drivers pick the fast path (one enabled layer → hand its buffer straight to the driver) versus the composite path (≥2 → blend into the output buffer).
Prior art: MoonLight's PhysicalLayer runs N VirtualLayers and composites their buffers into the display channel — same idea, different shape: Drivers (not Layers) does the compositing here (https://github.com/ewowi/MoonLight/blob/main/src/MoonLight).

Public Methods¶
virtual inline constchar * acceptsChildRoles() const override
: Comma-separated role names this module accepts as user-added children ("effect,modifier").
inline void setLayouts(Layouts * l)
: Wire the shared Layouts.
inline Layouts * layouts() const
virtual inline void prepare() override
: Re-wire children before they build their state, so a Layer added via the API (clear_children + add_module) gets the shared Layouts without anyone re-running main.cpp's setLayouts.
virtual inline void tick() override
: Role-filtered loop propagation: only tick children that are Layers.
inline Layer * activeLayer() const
: The first enabled Layer — Drivers reads it for physical dimensions (every layer composites into the same physical space, so any one answers width/height/depth).
inline Layer * firstEnabledLayer() const
: The first enabledLayer, or nullptr when none is enabled.
inline uint8_t enabledLayerCount() const
: Count of enabled Layer children — Drivers uses it to pick the single-layer fast path (==1) vs the composite path (>1), and to know if anything renders.
template<typenameFn> inline void forEachEnabledLayer(Fn cb) const
: Walk enabled Layers in container (composition) order — the order Drivers blends them, bottom (first) to top (last).