|
|
Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
|
Backend-agnostic renderer that resolves to the active build backend (Skia or tiny-skia). More...
#include "donner/svg/renderer/Renderer.h"
Public Member Functions | |
| Renderer (bool verbose=false) | |
| Creates a renderer for the active backend. | |
| Renderer (std::shared_ptr< geode::GeodeDevice > device, bool verbose=false) | |
| Creates a renderer for the active backend using an externally-owned Geode device when the Geode backend is selected. | |
| ~Renderer () override | |
| Destructor. | |
| Renderer (Renderer &&) noexcept | |
| Move constructor. | |
| Renderer & | operator= (Renderer &&) noexcept |
| Move assignment operator. | |
| Renderer (const Renderer &)=delete | |
| Renderer & | operator= (const Renderer &)=delete |
| void | draw (SVGDocument &document) override |
| Draws the SVG document using the active backend. | |
| RendererBitmap | renderElementToBitmap (SVGElement element, Vector2i sizePx) |
| Rasterize a single SVGElement and its descendant subtree to an RGBA bitmap fitted into a target box. | |
| void | beginFrame (const RenderViewport &viewport) override |
| Begins a render pass for the given viewport. | |
| void | endFrame () override |
| Completes the current render pass. | |
| void | setTransform (const Transform2d &transform) override |
| Sets the absolute transform, replacing the current matrix. | |
| void | pushTransform (const Transform2d &transform) override |
| Pushes a relative transform. | |
| void | popTransform () override |
| Pops the most recent transform. | |
| void | pushClip (const ResolvedClip &clip) override |
| Pushes a clip rect or clip path. | |
| void | popClip () override |
| Pops the most recent clip. | |
| void | pushIsolatedLayer (double opacity, MixBlendMode blendMode) override |
| Pushes an isolated compositing layer. | |
| void | popIsolatedLayer () override |
| Pops the most recent isolated layer. | |
| void | pushFilterLayer (const components::FilterGraph &filterGraph, const std::optional< Box2d > &filterRegion) override |
| Pushes a filter layer. | |
| void | popFilterLayer () override |
| Pops the most recent filter layer. | |
| void | pushMask (const std::optional< Box2d > &maskBounds) override |
| Begins mask rendering. | |
| void | transitionMaskToContent () override |
| Switches from mask rendering to masked content rendering. | |
| void | popMask () override |
| Pops the current mask and composites the masked content. | |
| bool | beginPatternTile (const Box2d &tileRect, const Transform2d &targetFromPattern) override |
| Begins pattern tile recording. | |
| void | endPatternTile (bool forStroke) override |
| Ends pattern recording and stores the resulting pattern paint. | |
| void | setPaint (const PaintParams &paint) override |
| Sets the active paint parameters for subsequent draw calls. | |
| void | drawPath (const PathShape &path, const StrokeParams &stroke) override |
| Draws an arbitrary path. | |
| void | drawRect (const Box2d &rect, const StrokeParams &stroke) override |
| Draws an axis-aligned rectangle. | |
| void | drawEllipse (const Box2d &bounds, const StrokeParams &stroke) override |
| Draws an ellipse. | |
| void | drawImage (const ImageResource &image, const ImageParams ¶ms) override |
| Draws an image resource. | |
| void | drawBitmap (const RendererBitmap &bitmap, const ImageParams ¶ms) override |
| Draws a CPU-readable bitmap into the given target rectangle. | |
| bool | drawTextureSnapshot (const RendererTextureSnapshot &texture, const Box2d &targetRect, double opacity=1.0, bool pixelated=false) override |
| Draws a backend-owned texture snapshot when the active backend supports it. | |
| void | drawText (Registry ®istry, const components::ComputedTextComponent &text, const TextParams ¶ms) override |
| Draws shaped text. | |
| RendererBitmap | takeSnapshot () const override |
| Captures a CPU-readable snapshot of the current frame. | |
| std::shared_ptr< const RendererTextureSnapshot > | takeTextureSnapshot () override |
| Captures a backend-owned GPU texture snapshot when the active backend supports it. | |
| bool | requiresTextureSnapshotPresentation () const override |
| Returns true when this backend requires direct texture presentation. | |
| std::unique_ptr< RendererInterface > | createOffscreenInstance () const override |
| Creates an offscreen renderer of the active backend type. | |
| void | setDebugGeometryOverlay (bool enabled) override |
| Forwards RendererInterface::setDebugGeometryOverlay to the active backend (no-op for backends without a debug overlay). | |
| bool | debugGeometryOverlay () const override |
| Whether the active backend's geometry debug overlay is enabled. | |
| bool | save (const char *filename) |
| Saves the last rendered frame to a PNG file. | |
| int | width () const override |
| Returns the rendered width in pixels. | |
| int | height () const override |
| Returns the rendered height in pixels. | |
Backend-agnostic renderer that resolves to the active build backend (Skia or tiny-skia).
Typical usage:
The draw() method handles the full rendering pipeline internally: computing styles, building the render tree, and rasterizing. For frame-based rendering (e.g., in a viewer), use beginFrame() / endFrame() directly via the RendererInterface API.
|
explicit |
Creates a renderer for the active backend.
| verbose | If true, enables backend-specific verbose logging. |
|
explicit |
Creates a renderer for the active backend using an externally-owned Geode device when the Geode backend is selected.
Non-Geode backends ignore device and construct their normal backend.
| device | Shared Geode device. |
| verbose | If true, enables backend-specific verbose logging. |
|
overridevirtual |
Begins a render pass for the given viewport.
| viewport | The viewport dimensions for the render pass. |
Implements donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Begins pattern tile recording.
| tileRect | Tile bounds in pattern space. |
| targetFromPattern | Transform from pattern tile space to target space. |
Implements donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Creates an offscreen renderer of the active backend type.
Reimplemented from donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Whether the active backend's geometry debug overlay is enabled.
Reimplemented from donner::svg::RendererInterface.
|
overridevirtual |
Draws the SVG document using the active backend.
| document | The SVG document to render. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Draws a CPU-readable bitmap into the given target rectangle.
| bitmap | The bitmap to draw. |
| params | Image placement parameters. |
Reimplemented from donner::svg::RendererInterface.
|
overridevirtual |
Draws an ellipse.
| bounds | The ellipse bounds. |
| stroke | Stroke configuration for the ellipse. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Draws an image resource.
| image | The image resource to draw. |
| params | Image placement parameters. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Draws an arbitrary path.
| path | The path to draw. |
| stroke | Stroke configuration for the path. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Draws an axis-aligned rectangle.
| rect | The rectangle bounds. |
| stroke | Stroke configuration for the rectangle. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Draws shaped text.
| registry | ECS registry used for resolving paint references. |
| text | The shaped text runs. |
| params | Text styling parameters. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Draws a backend-owned texture snapshot when the active backend supports it.
Reimplemented from donner::svg::RendererInterface.
|
overridevirtual |
Completes the current render pass.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Ends pattern recording and stores the resulting pattern paint.
| forStroke | If true, store as stroke paint, otherwise fill paint. |
Implements donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Returns the rendered height in pixels.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pops the most recent clip.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pops the most recent filter layer.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pops the most recent isolated layer.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pops the current mask and composites the masked content.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pops the most recent transform.
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pushes a clip rect or clip path.
| clip | The resolved clip to apply. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pushes a filter layer.
| filterGraph | The filter graph to apply when the layer is popped. |
| filterRegion | Optional filter region bounds in user space. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pushes an isolated compositing layer.
| opacity | Group opacity applied when the layer is composited back. |
| blendMode | Mix-blend-mode applied when the layer is composited back. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Begins mask rendering.
| maskBounds | Optional mask bounds clip. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Pushes a relative transform.
| transform | The transform to compose with the current matrix. |
Implements donner::svg::RendererInterface.
|
nodiscard |
Rasterize a single SVGElement and its descendant subtree to an RGBA bitmap fitted into a target box.
This renders just the given element + its descendants through an isolated offscreen instance of this renderer, scaled and centered into sizePx with a transparent background. The requested size is a maximum thumbnail extent: the returned bitmap dimensions are computed from the element's nonzero- opacity painted geometry bounds and may be narrower or shorter than sizePx. Layers whose visible bounds cover the root SVG viewBox fit the canvas-visible bounds into the preview cell. The element's own paint and transform are honored. The bounds are clipped to the root SVG viewBox when present so thumbnails show the document-canvas-visible part of a layer; other ancestor clips and opacity are intentionally ignored so the preview shows the element's own artwork rather than how it happens to be clipped in context.
The element's owning document is prepared for rendering under write access for this isolated draw, then its pending render invalidation state is restored so previews do not consume dirty flags needed by another renderer.
| element | Element whose subtree should be rasterized. |
| sizePx | Maximum bitmap dimensions in device pixels. Both axes must be positive; otherwise an empty bitmap is returned. |
|
nodiscardoverridevirtual |
Returns true when this backend requires direct texture presentation.
Reimplemented from donner::svg::RendererInterface.
| bool donner::svg::Renderer::save | ( | const char * | filename | ) |
Saves the last rendered frame to a PNG file.
| filename | The output PNG filename. |
|
overridevirtual |
Forwards RendererInterface::setDebugGeometryOverlay to the active backend (no-op for backends without a debug overlay).
Reimplemented from donner::svg::RendererInterface.
|
overridevirtual |
Sets the active paint parameters for subsequent draw calls.
| paint | The resolved paint state. |
Implements donner::svg::RendererInterface.
|
overridevirtual |
Sets the absolute transform, replacing the current matrix.
| transform | The transform to apply. |
Implements donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Captures a CPU-readable snapshot of the current frame.
Implements donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Captures a backend-owned GPU texture snapshot when the active backend supports it.
Reimplemented from donner::svg::RendererInterface.
|
overridevirtual |
Switches from mask rendering to masked content rendering.
Implements donner::svg::RendererInterface.
|
nodiscardoverridevirtual |
Returns the rendered width in pixels.
Implements donner::svg::RendererInterface.