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

Backend-agnostic renderer driver that prepares documents for rendering and emits drawing commands through a RendererInterface implementation. More...

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

Public Member Functions

 RendererDriver (RendererInterface &renderer, bool verbose=false)
 Create a renderer driver that will forward traversal output to the given backend implementation.
void draw (SVGDocument &document)
 Render the given SVGDocument using the configured backend.
void drawEntityRange (Registry &registry, Entity firstEntity, Entity lastEntity, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas)
 Render a range of entities from an already-prepared document's render tree.
std::optional< Box2dcomputeEntityRangeBounds (Registry &registry, Entity firstEntity, Entity lastEntity, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas)
 Compute the canvas-space bounding box of every pixel a subsequent drawEntityRange(registry, firstEntity, lastEntity, viewport, baseTransform) call would write to.
RendererBitmap takeSnapshot () const
 Capture a snapshot from the underlying backend after rendering.

Detailed Description

Backend-agnostic renderer driver that prepares documents for rendering and emits drawing commands through a RendererInterface implementation.

Member Function Documentation

◆ computeEntityRangeBounds()

std::optional< Box2d > donner::svg::RendererDriver::computeEntityRangeBounds ( Registry & registry,
Entity firstEntity,
Entity lastEntity,
const RenderViewport & viewport,
const Transform2d & surfaceFromCanvas )
nodiscard

Compute the canvas-space bounding box of every pixel a subsequent drawEntityRange(registry, firstEntity, lastEntity, viewport, baseTransform) call would write to.

Runs the same entity traversal as drawEntityRange but with a bounds-accumulating visitor; no side effects on the renderer or registry.

The bounds include the effect of:

  • Per-entity transforms (including the base transform).
  • Filter regions (via computeFilterRegion; the filter's output rectangle is taken as the entity subtree's contribution).
  • Stroke widths on stroked paths (expanded by strokeWidth / 2 plus a miter margin).
  • Isolated layers — child bounds accumulate into the parent.
  • Clip-rects (intersect, shrink only).

Returns std::nullopt when:

  • The range is empty / renders nothing.
  • Any entity uses a bound-expander the visitor doesn't yet model precisely (text, markers, masks, patterns). Callers must treat nullopt as "fall back to full-canvas render", NOT as "empty segment". The design doc at docs/design_docs/0027-tight_bounded_ segments.md tracks which cases are pending.

Safe to call on a RendererDriver whose renderer holds persistent state — the traversal never invokes renderer methods.

◆ drawEntityRange()

void donner::svg::RendererDriver::drawEntityRange ( Registry & registry,
Entity firstEntity,
Entity lastEntity,
const RenderViewport & viewport,
const Transform2d & surfaceFromCanvas )

Render a range of entities from an already-prepared document's render tree.

The document must have been prepared via RendererUtils::prepareDocumentForRendering() before calling this method.

Parameters
registryThe registry containing the prepared render tree.
firstEntityFirst entity in the range to render (inclusive).
lastEntityLast entity in the range to render (inclusive).
viewportViewport for the render pass.
surfaceFromCanvasTransform that maps canvas coords to the render surface (Translate(-topLeft) for tight-bounded compositor segments, identity for full-canvas layers/segments). Named with destFromSource convention; composed with each entity's worldFromEntityTransform as worldFromEntityTransform * surfaceFromCanvas (donner's left-first operator*: "apply entity-to-canvas, then canvas-to-surface").

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