Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::svg::RenderSnapshotRecorder Class Referencefinal

RendererInterface implementation that records commands into a RenderSnapshot. More...

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

Inheritance diagram for donner::svg::RenderSnapshotRecorder:
[legend]

Public Member Functions

 RenderSnapshotRecorder (RenderSnapshot &snapshot, RendererInterface &offscreenFactory)
 Create a recorder.
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 pushMask (const std::optional< Box2d > &maskBounds, MaskType maskType) override
 Begins mask rendering with an explicit coverage mode.
void transitionMaskToContent () override
 Transitions from rendering mask content to rendering masked content.
void popMask () override
 Pops the mask layer stack, compositing the masked content.
bool 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.
RendererBitmap takeSnapshot () const override
 Captures a CPU-readable snapshot of the current frame buffer for testing or downstream consumers.
RendererFilterPreparationBudgetfilterPreparationBudget () override
 Shared driver-side filter preparation budget for this renderer family, when supported.
std::unique_ptr< RendererInterfacecreateOffscreenInstance () const override
 Creates an independent offscreen renderer instance of the same type as this one.
Public Member Functions inherited from donner::svg::RendererInterface
virtual void beginFrameResourceScope ()
 Begins one aggregate resource-budget scope around a controller-managed frame.
virtual void endFrameResourceScope ()
 Completes a scope opened by beginFrameResourceScope.
virtual void setPreserveTargetOnBeginFrame (bool preserve)
 Preserve the current render target when the next frame begins.
virtual void drawBitmap (const RendererBitmap &bitmap, const ImageParams &params)
 Draws a CPU bitmap (typically a compositor layer/segment raster) into the given target rectangle.
virtual bool drawTextureSnapshot (const RendererTextureSnapshot &texture, const Box2d &targetRect, double opacity=1.0, bool pixelated=false)
 Draws a backend-owned texture snapshot into the given target rectangle.
virtual RendererBitmap takeSnapshotInterruptibly (const std::function< bool()> &shouldCancel) const
 Captures a CPU-readable snapshot while allowing a low-priority caller to abort the readback.
virtual RendererReadbackStats consumeReadbackStats ()
 Consume readback diagnostics accumulated by this renderer backend.
virtual RendererResourceStats resourceStats () const
 Return resource-admission diagnostics for the current frame.
virtual void injectFilterLocalRasterAllocationFailureForTesting ()
 Cause the next local filter raster allocation to fail in a boundary test.
virtual std::shared_ptr< const RendererTextureSnapshottakeTextureSnapshot ()
 Captures the current frame buffer as a backend-owned GPU texture.
virtual const RendererTextureSnapshotborrowTextureSnapshot () UTILS_LIFETIME_BOUND
 Borrows the current backend-owned GPU texture for a synchronous presentation operation.
virtual bool requiresTextureSnapshotPresentation () const
 Returns true when presentation callers must use takeTextureSnapshot and must not fall back to CPU bitmap readback for normal frame handoff.
virtual void setOffscreenCreationHookForTesting (std::function< void()>)
 Install a zero-default hook entered from inside offscreen backend construction.
virtual std::uint64_t filterBudgetChunksForTesting () const
 Number of filter-budget command-buffer chunks submitted by this renderer family.
virtual void setDebugGeometryOverlay (bool)
 Enable or disable the backend's geometry debug overlay.
virtual bool debugGeometryOverlay () const
 Whether the backend's geometry debug overlay is enabled. Backends without an overlay always report false.

Detailed Description

RendererInterface implementation that records commands into a RenderSnapshot.

Constructor & Destructor Documentation

◆ RenderSnapshotRecorder()

donner::svg::RenderSnapshotRecorder::RenderSnapshotRecorder ( RenderSnapshot & snapshot,
RendererInterface & offscreenFactory )

Create a recorder.

Parameters
snapshotSnapshot receiving recorded commands.
offscreenFactoryBackend used only for creating offscreen renderers while capture prepares filters, masks, and sub-documents.

Member Function Documentation

◆ beginFrame()

void donner::svg::RenderSnapshotRecorder::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()

bool donner::svg::RenderSnapshotRecorder::beginPatternTile ( const Box2d & tileRect,
const Transform2d & targetFromPattern )
nodiscardoverridevirtual

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.
Returns
True when recording started. False rejects the tile without allocating resources.

Implements donner::svg::RendererInterface.

◆ createOffscreenInstance()

std::unique_ptr< RendererInterface > donner::svg::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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::RenderSnapshotRecorder::drawRect ( const Box2d & rect,
const StrokeParams & stroke )
overridevirtual

Convenience helper for drawing axis-aligned rectangles.

Implements donner::svg::RendererInterface.

◆ drawText()

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

Draws pre-shaped text with the provided paint parameters.

Implements donner::svg::RendererInterface.

◆ endFrame()

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

Completes the current render pass, flushing any pending work.

Implements donner::svg::RendererInterface.

◆ endPatternTile()

void donner::svg::RenderSnapshotRecorder::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.

◆ filterPreparationBudget()

RendererFilterPreparationBudget * donner::svg::RenderSnapshotRecorder::filterPreparationBudget ( )
nodiscardoverridevirtual

Shared driver-side filter preparation budget for this renderer family, when supported.

Reimplemented from donner::svg::RendererInterface.

◆ height()

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

Returns the rendered height in device pixels.

Implements donner::svg::RendererInterface.

◆ popClip()

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

Pops the most recent clip from the renderer stack.

Implements donner::svg::RendererInterface.

◆ popFilterLayer()

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

Pops the most recent filter layer.

Implements donner::svg::RendererInterface.

◆ popIsolatedLayer()

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

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

Implements donner::svg::RendererInterface.

◆ popMask()

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

Pops the mask layer stack, compositing the masked content.

Implements donner::svg::RendererInterface.

◆ popTransform()

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

Pops the most recent transform from the renderer stack.

Implements donner::svg::RendererInterface.

◆ pushClip()

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

Pushes a clip path/mask onto the renderer stack.

Implements donner::svg::RendererInterface.

◆ pushFilterLayer()

void donner::svg::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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() [1/2]

void donner::svg::RenderSnapshotRecorder::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.

This compatibility entry point begins a luminance mask. Existing embedders that implement this pure virtual remain source-compatible. Override the typed overload to support alpha masks.

Parameters
maskBoundsOptional clip rect for the mask region.

Implements donner::svg::RendererInterface.

◆ pushMask() [2/2]

void donner::svg::RenderSnapshotRecorder::pushMask ( const std::optional< Box2d > & maskBounds,
MaskType maskType )
overridevirtual

Begins mask rendering with an explicit coverage mode.

Appended after the legacy virtual surface to preserve existing vtable slot order. The default compatibility implementation delegates to the one-argument luminance entry point. Backends that support MaskType::Alpha override this overload.

Parameters
maskBoundsOptional clip rect for the mask region.
maskTypeWhether mask coverage comes from luminance or alpha.

Reimplemented from donner::svg::RendererInterface.

◆ pushTransform()

void donner::svg::RenderSnapshotRecorder::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::RenderSnapshotRecorder::setPaint ( const PaintParams & paint)
overridevirtual

Sets the active paint parameters used by subsequent draw calls.

Implements donner::svg::RendererInterface.

◆ setTransform()

void donner::svg::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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::RenderSnapshotRecorder::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: