Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
EmbeddedSvgIcon.h File Reference
#include <optional>
#include <span>
#include <vector>
#include "donner/svg/renderer/RendererInterface.h"
Include dependency graph for EmbeddedSvgIcon.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::editor::EmbeddedSvgIconRequest
 One embedded-SVG rasterization, for the batched atlas path. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

void donner::editor::ConfigureEmbeddedSvgIconRenderer (svg::RendererInterface &renderer)
 Use an editor-owned renderer for subsequent embedded-SVG rasterization.
void donner::editor::ResetEmbeddedSvgIconRenderer (const svg::RendererInterface &expectedRenderer)
 Stop using the configured renderer before its owner is destroyed.
std::optional< svg::RendererBitmapdonner::editor::RenderEmbeddedSvgIcon (std::span< const unsigned char > svgBytes, int outputSizePx)
 Render an embedded SVG icon resource into a tintable RGBA bitmap.
std::optional< svg::RendererBitmapdonner::editor::RenderEmbeddedSvgArtwork (std::span< const unsigned char > svgBytes, int outputSizePx)
 Render embedded SVG artwork while preserving its authored RGBA colors.
std::vector< std::optional< svg::RendererBitmap > > donner::editor::RenderEmbeddedSvgIconBatch (std::span< const EmbeddedSvgIconRequest > requests)
 Rasterize a set of embedded icons in one render pass and one GPU readback.
void donner::editor::PrewarmEmbeddedSvgIcons (std::span< const EmbeddedSvgIconRequest > requests)
 Rasterize a set of embedded icons up front so later single-icon calls are free.

Function Documentation

◆ ConfigureEmbeddedSvgIconRenderer()

void donner::editor::ConfigureEmbeddedSvgIconRenderer ( svg::RendererInterface & renderer)

Use an editor-owned renderer for subsequent embedded-SVG rasterization.

The editor calls this before its first UI frame so icon rendering reuses the already-created backend/device instead of creating a second headless device. The renderer must outlive the matching reset call.

◆ PrewarmEmbeddedSvgIcons()

void donner::editor::PrewarmEmbeddedSvgIcons ( std::span< const EmbeddedSvgIconRequest > requests)

Rasterize a set of embedded icons up front so later single-icon calls are free.

The editor's first UI frame draws every affordance icon it shows, and each one used to pay its own GPU readback while the frame was blocked on it. This collapses that into one batched readback before the frame starts: RenderEmbeddedSvgIcon and RenderEmbeddedSvgArtwork return the prewarmed bitmap for any request already rasterized here.

Requests that fail are simply not cached, so the matching single-icon call still falls back to its own rasterization.

Parameters
requestsIcons to rasterize and cache.

◆ RenderEmbeddedSvgArtwork()

std::optional< svg::RendererBitmap > donner::editor::RenderEmbeddedSvgArtwork ( std::span< const unsigned char > svgBytes,
int outputSizePx )
nodiscard

Render embedded SVG artwork while preserving its authored RGBA colors.

Use this for small multi-color assets such as the editor's black-core, white-halo tool icons. Single-color affordances should continue to use RenderEmbeddedSvgIcon so ImGui can tint their alpha mask.

Parameters
svgBytesEmbedded SVG source bytes.
outputSizePxSquare output bitmap size in device pixels.
Returns
Rendered artwork, or std::nullopt if parsing/rendering fails.

◆ RenderEmbeddedSvgIcon()

std::optional< svg::RendererBitmap > donner::editor::RenderEmbeddedSvgIcon ( std::span< const unsigned char > svgBytes,
int outputSizePx )
nodiscard

Render an embedded SVG icon resource into a tintable RGBA bitmap.

The source SVG is parsed and rasterized through Donner. The returned bitmap is normalized to a white premultiplied-alpha mask so callers can tint it with the current ImGui text color when displaying the resulting texture.

Parameters
svgBytesEmbedded SVG source bytes.
outputSizePxSquare output bitmap size in device pixels.
Returns
Rendered icon bitmap, or std::nullopt if parsing/rendering fails.

◆ RenderEmbeddedSvgIconBatch()

std::vector< std::optional< svg::RendererBitmap > > donner::editor::RenderEmbeddedSvgIconBatch ( std::span< const EmbeddedSvgIconRequest > requests)
nodiscard

Rasterize a set of embedded icons in one render pass and one GPU readback.

Icons are packed into a single atlas render target, drawn together, read back once, then sliced apart. Each slice is byte-identical to the bitmap the matching single-icon call would return, so this is purely a cost change: on a GPU backend a readback is an asynchronous buffer mapping whose latency is paid per call, and the per-icon path pays it once per icon.

Parameters
requestsIcons to rasterize.
Returns
One entry per request, in request order. Entries are std::nullopt for requests that failed to parse or render.

◆ ResetEmbeddedSvgIconRenderer()

void donner::editor::ResetEmbeddedSvgIconRenderer ( const svg::RendererInterface & expectedRenderer)

Stop using the configured renderer before its owner is destroyed.

The reset is ignored when another editor has since installed a different renderer, which keeps overlapping editor lifetimes safe.