Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::svg::RendererGeode Class Reference

Geode rendering backend — GPU-native via WebGPU + the Slug algorithm. More...

#include "donner/svg/renderer/RendererGeode.h"

Inheritance diagram for donner::svg::RendererGeode:
[legend]
Collaboration diagram for donner::svg::RendererGeode:
[legend]

Public Member Functions

 RendererGeode (bool verbose=false)
 Construct the renderer.
 RendererGeode (std::shared_ptr< geode::GeodeDevice > device, bool verbose=false)
 Construct the renderer with an externally-owned GeodeDevice.
 RendererGeode (const RendererGeode &)=delete
RendererGeodeoperator= (const RendererGeode &)=delete
 RendererGeode (RendererGeode &&) noexcept
 Move constructor.
RendererGeodeoperator= (RendererGeode &&) noexcept
 Move assignment operator.
void setTargetTexture (wgpu::Texture texture)
 Set a host-owned texture as the render target for subsequent frames.
void clearTargetTexture ()
 Clear a previously set target texture, reverting to internal offscreen targets allocated per-frame by beginFrame().
void draw (SVGDocument &document) override
 Renders the given SVG document.
int width () const override
 Returns the rendered width in device pixels.
int height () const override
 Returns the rendered height in device pixels.
void beginFrame (const RenderViewport &viewport) override
 Begins a render pass with the given viewport.
void endFrame () override
 Completes the current render pass, flushing any pending work.
void setTransform (const Transform2d &transform) override
 Sets the absolute transform on the renderer, replacing the current matrix.
void pushTransform (const Transform2d &transform) override
 Pushes a transform onto the renderer stack, composing with the current transform.
void popTransform () override
 Pops the most recent transform from the renderer stack.
void pushClip (const ResolvedClip &clip) override
 Pushes a clip path/mask onto the renderer stack.
void popClip () override
 Pops the most recent clip from the renderer stack.
void pushIsolatedLayer (double opacity, MixBlendMode blendMode) override
 Pushes an isolated compositing layer with the given opacity and blend mode.
void popIsolatedLayer () override
 Pops the most recent isolated layer, compositing it with the given opacity.
void pushFilterLayer (const components::FilterGraph &filterGraph, const std::optional< Box2d > &filterRegion) override
 Pushes a filter layer that applies the given filter graph to all content drawn within it.
void popFilterLayer () override
 Pops the most recent filter layer.
void pushMask (const std::optional< Box2d > &maskBounds) override
 Begins mask rendering.
void transitionMaskToContent () override
 Transitions from rendering mask content to rendering masked content.
void popMask () override
 Pops the mask layer stack, compositing the masked content.
void beginPatternTile (const Box2d &tileRect, const Transform2d &targetFromPattern) override
 Begins recording content into a pattern tile.
void endPatternTile (bool forStroke) override
 Ends pattern tile recording and sets the resulting tiled shader as the current fill or stroke paint.
void setPaint (const PaintParams &paint) override
 Sets the active paint parameters used by subsequent draw calls.
void drawPath (const PathShape &path, const StrokeParams &stroke) override
 Draws an arbitrary path using the current paint state.
void drawRect (const Box2d &rect, const StrokeParams &stroke) override
 Convenience helper for drawing axis-aligned rectangles.
void drawEllipse (const Box2d &bounds, const StrokeParams &stroke) override
 Convenience helper for drawing ellipses bounded by the provided box.
void drawImage (const ImageResource &image, const ImageParams &params) override
 Draws an image resource into the given target rectangle.
void drawText (Registry &registry, const components::ComputedTextComponent &text, const TextParams &params) override
 Draws pre-shaped text with the provided paint parameters.
std::unique_ptr< RendererInterfacecreateOffscreenInstance () const override
 Creates an independent offscreen renderer instance of the same type as this one.
RendererBitmap takeSnapshot () const override
 Captures a CPU-readable snapshot of the current frame buffer for testing or downstream consumers.
void enableTimestamps (bool enabled)
 Enable or disable GPU timestamp capture.
FrameTimings lastFrameTimings () const
 Returns per-frame instrumentation for the most recently completed beginFrameendFrame window.

Detailed Description

Geode rendering backend — GPU-native via WebGPU + the Slug algorithm.

RendererGeode implements RendererInterface by translating draw calls into the lower-level donner::geode::GeoEncoder API.

Construction modes

Mode Constructor Device ownership
Headless RendererGeode(verbose) Geode creates + owns device
Shared RendererGeode(shared_ptr<GeodeDevice>) Caller shares ownership

In all modes, Geode creates its own offscreen render target each frame unless a host-owned target is set via setTargetTexture().

Embedded rendering

Host applications that already own a WebGPU device can:

  1. Create a GeodeDevice from their existing device via GeodeDevice::CreateFromExternal(GeodeEmbedConfig{...}).
  2. Optionally call setTargetTexture() to render directly into a swap-chain texture or other host-owned surface.
  3. Call draw() or the beginFrame()/endFrame() lifecycle as usual.

If GeodeDevice::CreateHeadless() fails (no GPU available), all draw operations become no-ops and takeSnapshot() returns an empty bitmap.

Constructor & Destructor Documentation

◆ RendererGeode() [1/2]

donner::svg::RendererGeode::RendererGeode ( bool verbose = false)
explicit

Construct the renderer.

Creates a headless GeodeDevice immediately; if device creation fails, the renderer enters a "no-op" state and all subsequent draw calls do nothing.

Parameters
verboseIf true, emit warnings to stderr for unsupported features the first time they are encountered.

◆ RendererGeode() [2/2]

donner::svg::RendererGeode::RendererGeode ( std::shared_ptr< geode::GeodeDevice > device,
bool verbose = false )
explicit

Construct the renderer with an externally-owned GeodeDevice.

The caller retains shared ownership of the device; it must outlive every frame rendered through this renderer. This overload avoids creating a new WebGPU instance/adapter/device per renderer, which is important in test fixtures that construct thousands of short-lived renderers — Mesa llvmpipe (and some Intel ANV configurations) accumulate driver state across device creations and eventually deadlock.

Parameters
deviceShared device. Must not be null.
verboseIf true, emit warnings for unsupported features.

Member Function Documentation

◆ beginFrame()

void donner::svg::RendererGeode::beginFrame ( const RenderViewport & viewport)
overridevirtual

Begins a render pass with the given viewport.

Implementations may allocate or reset backend-specific frame resources here.

Implements donner::svg::RendererInterface.

◆ beginPatternTile()

void donner::svg::RendererGeode::beginPatternTile ( const Box2d & tileRect,
const Transform2d & targetFromPattern )
overridevirtual

Begins recording content into a pattern tile.

Content drawn between beginPatternTile and endPatternTile is captured as a repeating pattern.

Parameters
tileRectThe tile rectangle in pattern coordinate space.
targetFromPatternTransform from pattern tile space to target element space.

Implements donner::svg::RendererInterface.

◆ createOffscreenInstance()

std::unique_ptr< RendererInterface > donner::svg::RendererGeode::createOffscreenInstance ( ) const
nodiscardoverridevirtual

Creates an independent offscreen renderer instance of the same type as this one.

Used for rendering sub-documents into intermediate pixmaps when a backend needs an isolated offscreen pass (e.g., for feImage with SVG content). Returns nullptr if offscreen rendering is not supported.

Reimplemented from donner::svg::RendererInterface.

◆ draw()

void donner::svg::RendererGeode::draw ( SVGDocument & document)
overridevirtual

Renders the given SVG document.

Implementations prepare the document, traverse the render tree, and emit drawing commands.

Implements donner::svg::RendererInterface.

◆ drawEllipse()

void donner::svg::RendererGeode::drawEllipse ( const Box2d & bounds,
const StrokeParams & stroke )
overridevirtual

Convenience helper for drawing ellipses bounded by the provided box.

Implements donner::svg::RendererInterface.

◆ drawImage()

void donner::svg::RendererGeode::drawImage ( const ImageResource & image,
const ImageParams & params )
overridevirtual

Draws an image resource into the given target rectangle.

Implements donner::svg::RendererInterface.

◆ drawPath()

void donner::svg::RendererGeode::drawPath ( const PathShape & path,
const StrokeParams & stroke )
overridevirtual

Draws an arbitrary path using the current paint state.

Implements donner::svg::RendererInterface.

◆ drawRect()

void donner::svg::RendererGeode::drawRect ( const Box2d & rect,
const StrokeParams & stroke )
overridevirtual

Convenience helper for drawing axis-aligned rectangles.

Implements donner::svg::RendererInterface.

◆ drawText()

void donner::svg::RendererGeode::drawText ( Registry & registry,
const components::ComputedTextComponent & text,
const TextParams & params )
overridevirtual

Draws pre-shaped text with the provided paint parameters.

Implements donner::svg::RendererInterface.

◆ enableTimestamps()

void donner::svg::RendererGeode::enableTimestamps ( bool enabled)

Enable or disable GPU timestamp capture.

No-op today; reserved for future work (design doc 0030, "Future Work"). When wired up, this will drive the renderPassNs / totalGpuNs fields of lastFrameTimings(). Counters (the primary regression signal) are always on regardless of this flag.

◆ endFrame()

void donner::svg::RendererGeode::endFrame ( )
overridevirtual

Completes the current render pass, flushing any pending work.

Implements donner::svg::RendererInterface.

◆ endPatternTile()

void donner::svg::RendererGeode::endPatternTile ( bool forStroke)
overridevirtual

Ends pattern tile recording and sets the resulting tiled shader as the current fill or stroke paint.

Parameters
forStrokeIf true, set the pattern as the stroke paint; otherwise as the fill paint.

Implements donner::svg::RendererInterface.

◆ height()

int donner::svg::RendererGeode::height ( ) const
nodiscardoverridevirtual

Returns the rendered height in device pixels.

Implements donner::svg::RendererInterface.

◆ lastFrameTimings()

FrameTimings donner::svg::RendererGeode::lastFrameTimings ( ) const
nodiscard

Returns per-frame instrumentation for the most recently completed beginFrameendFrame window.

Valid after the first endFrame(); before then all fields are zero.

◆ popClip()

void donner::svg::RendererGeode::popClip ( )
overridevirtual

Pops the most recent clip from the renderer stack.

Implements donner::svg::RendererInterface.

◆ popFilterLayer()

void donner::svg::RendererGeode::popFilterLayer ( )
overridevirtual

Pops the most recent filter layer.

Implements donner::svg::RendererInterface.

◆ popIsolatedLayer()

void donner::svg::RendererGeode::popIsolatedLayer ( )
overridevirtual

Pops the most recent isolated layer, compositing it with the given opacity.

Implements donner::svg::RendererInterface.

◆ popMask()

void donner::svg::RendererGeode::popMask ( )
overridevirtual

Pops the mask layer stack, compositing the masked content.

Implements donner::svg::RendererInterface.

◆ popTransform()

void donner::svg::RendererGeode::popTransform ( )
overridevirtual

Pops the most recent transform from the renderer stack.

Implements donner::svg::RendererInterface.

◆ pushClip()

void donner::svg::RendererGeode::pushClip ( const ResolvedClip & clip)
overridevirtual

Pushes a clip path/mask onto the renderer stack.

Implements donner::svg::RendererInterface.

◆ pushFilterLayer()

void donner::svg::RendererGeode::pushFilterLayer ( const components::FilterGraph & filterGraph,
const std::optional< Box2d > & filterRegion )
overridevirtual

Pushes a filter layer that applies the given filter graph to all content drawn within it.

Parameters
filterGraphThe filter graph describing primitives and their connections.
filterRegionThe filter region bounds in local coordinates, used to clip the filter output. If nullopt, the filter operates on the full surface.

Implements donner::svg::RendererInterface.

◆ pushIsolatedLayer()

void donner::svg::RendererGeode::pushIsolatedLayer ( double opacity,
MixBlendMode blendMode )
overridevirtual

Pushes an isolated compositing layer with the given opacity and blend mode.

Content drawn between pushIsolatedLayer and popIsolatedLayer is composited as a group at the specified opacity using the specified blend mode.

Implements donner::svg::RendererInterface.

◆ pushMask()

void donner::svg::RendererGeode::pushMask ( const std::optional< Box2d > & maskBounds)
overridevirtual

Begins mask rendering.

The driver renders the mask content between pushMask and transitionMaskToContent, then renders the actual content between transitionMaskToContent and popMask.

Parameters
maskBoundsOptional clip rect for the mask region.

Implements donner::svg::RendererInterface.

◆ pushTransform()

void donner::svg::RendererGeode::pushTransform ( const Transform2d & transform)
overridevirtual

Pushes a transform onto the renderer stack, composing with the current transform.

Implements donner::svg::RendererInterface.

◆ setPaint()

void donner::svg::RendererGeode::setPaint ( const PaintParams & paint)
overridevirtual

Sets the active paint parameters used by subsequent draw calls.

Implements donner::svg::RendererInterface.

◆ setTargetTexture()

void donner::svg::RendererGeode::setTargetTexture ( wgpu::Texture texture)

Set a host-owned texture as the render target for subsequent frames.

When a target texture is set, beginFrame() renders into it instead of allocating an internal offscreen target. The texture must:

  • Have wgpu::TextureUsage::RenderAttachment set.
  • Match the texture format configured on the GeodeDevice (default: RGBA8Unorm).
  • Be at least as large as the viewport (in device pixels).

If the texture also has CopySrc usage, takeSnapshot() can read it back. If it lacks CopySrc, takeSnapshot() returns an empty bitmap.

The host retains ownership of the texture; it must remain valid from beginFrame() through endFrame(). Call clearTargetTexture() to revert to internal offscreen targets.

Parameters
textureHost-owned render target texture. Must not be null.

◆ setTransform()

void donner::svg::RendererGeode::setTransform ( const Transform2d & transform)
overridevirtual

Sets the absolute transform on the renderer, replacing the current matrix.

Unlike pushTransform, this does not interact with the save/restore stack.

Implements donner::svg::RendererInterface.

◆ takeSnapshot()

RendererBitmap donner::svg::RendererGeode::takeSnapshot ( ) const
nodiscardoverridevirtual

Captures a CPU-readable snapshot of the current frame buffer for testing or downstream consumers.

The snapshot must remain valid after the render pass completes.

Implements donner::svg::RendererInterface.

◆ transitionMaskToContent()

void donner::svg::RendererGeode::transitionMaskToContent ( )
overridevirtual

Transitions from rendering mask content to rendering masked content.

Must be called between pushMask and popMask.

Implements donner::svg::RendererInterface.

◆ width()

int donner::svg::RendererGeode::width ( ) const
nodiscardoverridevirtual

Returns the rendered width in device pixels.

Implements donner::svg::RendererInterface.


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