Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 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"

Classes

struct  SecurityStats
 Optional diagnostics for structured fuzzers and embedders auditing rejected preparation. More...

Public Member Functions

 RendererDriver (RendererInterface &renderer, bool verbose=false, SecurityStats *securityStats=nullptr)
 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 draw (SVGDocument &document, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas)
 Render the given SVGDocument into viewport after applying surfaceFromCanvas to every canvas-space draw command.
bool drawInterruptibly (SVGDocument &document, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas, const std::function< bool()> &shouldCancel)
 Prepare and render a document while polling shouldCancel between rendered entities.
RenderSnapshot captureRenderSnapshot (SVGDocument &document)
 Capture an immutable render snapshot from the given SVGDocument.
void draw (const RenderSnapshot &snapshot)
 Replay an already-captured render snapshot into 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.
bool drawEntityRangeInterruptibly (Registry &registry, Entity firstEntity, Entity lastEntity, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas, const std::function< bool()> &shouldCancel)
 Render a prepared entity range while polling shouldCancel between shapes.
void drawEntityRangeIntoCurrentFrame (Registry &registry, Entity firstEntity, Entity lastEntity, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas)
 Render a range of entities into the renderer's already-active frame.
void drawDocumentIntoCurrentFrame (SVGDocument &document, const RenderViewport &viewport, const Transform2d &surfaceFromCanvas)
 Prepare and draw a whole document into the renderer's already-open frame, using the same main-entity selection as drawInterruptibly (traversal order, offscreen feImage shadow entities excluded).
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.

Static Public Attributes

static constexpr std::size_t kMaximumPreparedFilterGraphs
 Aggregate limits for frame-wide filter graph preparation and feImage snapshots.
static constexpr std::size_t kMaximumPreparedFilterNodes
static constexpr std::uint64_t kMaximumPreparedFilterImageBytes
static constexpr std::uint64_t kMaximumPreparedFilterMaterializationBytes
static constexpr std::uint64_t kMaximumPreparedFilterPayloadBytes
static constexpr std::size_t kMaximumPreparedFilterShadowEntities

Detailed Description

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


Class Documentation

◆ donner::svg::RendererDriver::SecurityStats

struct donner::svg::RendererDriver::SecurityStats

Optional diagnostics for structured fuzzers and embedders auditing rejected preparation.

Class Members
bool clipGeometryCopyRejected = false
size_t clipGeometryPathsPreflighted = 0
size_t filterPreparationAttempts = 0
bool filterPreparationRejected = false
size_t preparedFilterGraphs = 0
uint64_t preparedFilterImageBytes = 0
uint64_t preparedFilterMaterializationBytes = 0
size_t preparedFilterNodes = 0
uint64_t preparedFilterPayloadBytes = 0
size_t preparedFilterShadowEntities = 0

Constructor & Destructor Documentation

◆ RendererDriver()

donner::svg::RendererDriver::RendererDriver ( RendererInterface & renderer,
bool verbose = false,
SecurityStats * securityStats = nullptr )
explicit

Create a renderer driver that will forward traversal output to the given backend implementation.

Parameters
rendererBackend receiving prepared draw calls.
verboseWhether to emit diagnostic warnings.
securityStatsOptional preparation diagnostics destination.

Member Function Documentation

◆ captureRenderSnapshot()

RenderSnapshot donner::svg::RendererDriver::captureRenderSnapshot ( SVGDocument & document)
nodiscard

Capture an immutable render snapshot from the given SVGDocument.

Snapshot capture prepares the live render tree under document access, then records backend-agnostic draw commands that can be replayed after access is released.

Parameters
documentDocument to snapshot.

◆ 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".

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

◆ draw() [1/2]

void donner::svg::RendererDriver::draw ( const RenderSnapshot & snapshot)

Replay an already-captured render snapshot into the configured backend.

Parameters
snapshotSnapshot to render.

◆ draw() [2/2]

void donner::svg::RendererDriver::draw ( SVGDocument & document,
const RenderViewport & viewport,
const Transform2d & surfaceFromCanvas )

Render the given SVGDocument into viewport after applying surfaceFromCanvas to every canvas-space draw command.

This is used by editor-style camera rendering: SVG layout can still use the document's semantic full canvas, while the backend only allocates the visible output surface.

Parameters
documentDocument to render.
viewportOutput viewport for the backend frame.
surfaceFromCanvasTransform from document canvas coordinates to the output surface.

◆ drawDocumentIntoCurrentFrame()

void donner::svg::RendererDriver::drawDocumentIntoCurrentFrame ( SVGDocument & document,
const RenderViewport & viewport,
const Transform2d & surfaceFromCanvas )

Prepare and draw a whole document into the renderer's already-open frame, using the same main-entity selection as drawInterruptibly (traversal order, offscreen feImage shadow entities excluded).

Use this instead of deriving an entity range by hand: a range computed from a different ordering can cross drawEntityRange's first/last walk and unbalance layer bookkeeping.

The caller owns beginFrame/endFrame and holds the document's write access.

Parameters
documentDocument to draw; prepared for rendering by this call.
viewportViewport for the active render pass.
surfaceFromCanvasTransform that maps canvas coords to the active render surface.

◆ 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").

◆ drawEntityRangeInterruptibly()

bool donner::svg::RendererDriver::drawEntityRangeInterruptibly ( Registry & registry,
Entity firstEntity,
Entity lastEntity,
const RenderViewport & viewport,
const Transform2d & surfaceFromCanvas,
const std::function< bool()> & shouldCancel )
nodiscard

Render a prepared entity range while polling shouldCancel between shapes.

The renderer frame is always balanced and ended before this method returns. A cancelled partial frame is safe to discard, which lets editor workers release their document guard without waiting for an entire complex compositor segment to finish.

Returns
True when the complete range was rendered, false when cancellation stopped traversal.

◆ drawEntityRangeIntoCurrentFrame()

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

Render a range of entities into the renderer's already-active frame.

This is the current-frame form of drawEntityRange: the caller owns RendererInterface::beginFrame() / endFrame(), and this method only emits the entity-range draw commands. It is used by the compositor when an immediate-mode span should be drawn directly into the composition render target instead of first being rasterized into an offscreen tile.

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 active render pass.
surfaceFromCanvasTransform that maps canvas coords to the active render surface.

◆ drawInterruptibly()

bool donner::svg::RendererDriver::drawInterruptibly ( SVGDocument & document,
const RenderViewport & viewport,
const Transform2d & surfaceFromCanvas,
const std::function< bool()> & shouldCancel )
nodiscard

Prepare and render a document while polling shouldCancel between rendered entities.

The document write guard and renderer frame are always balanced before this method returns. A cancelled partial frame is safe for a background worker to discard.

Returns
True when the complete document rendered, false when cancellation stopped work.

Member Data Documentation

◆ kMaximumPreparedFilterGraphs

std::size_t donner::svg::RendererDriver::kMaximumPreparedFilterGraphs
staticconstexpr
Initial value:
=
RendererFilterPreparationBudget::kMaximumGraphs

Aggregate limits for frame-wide filter graph preparation and feImage snapshots.

◆ kMaximumPreparedFilterImageBytes

std::uint64_t donner::svg::RendererDriver::kMaximumPreparedFilterImageBytes
staticconstexpr
Initial value:
=
RendererFilterPreparationBudget::kMaximumImageBytes

◆ kMaximumPreparedFilterMaterializationBytes

std::uint64_t donner::svg::RendererDriver::kMaximumPreparedFilterMaterializationBytes
staticconstexpr
Initial value:
=
RendererFilterPreparationBudget::kMaximumMaterializationBytes

◆ kMaximumPreparedFilterNodes

std::size_t donner::svg::RendererDriver::kMaximumPreparedFilterNodes
staticconstexpr
Initial value:
=
RendererFilterPreparationBudget::kMaximumNodes

◆ kMaximumPreparedFilterPayloadBytes

std::uint64_t donner::svg::RendererDriver::kMaximumPreparedFilterPayloadBytes
staticconstexpr
Initial value:
=
RendererFilterPreparationBudget::kMaximumPayloadBytes

◆ kMaximumPreparedFilterShadowEntities

std::size_t donner::svg::RendererDriver::kMaximumPreparedFilterShadowEntities
staticconstexpr
Initial value:
=
RendererFilterPreparationBudget::kMaximumShadowEntities

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