|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
Wraps an svg::SVGDocument and the editor's per-frame command queue. More...
#include "donner/editor/AsyncSVGDocument.h"
Classes | |
| struct | FlushResult |
Public Types | |
| enum class | ReplaceKind : uint8_t { FullReplace , Structural } |
| Outcome of setDocumentMaybeStructural. FullReplace means the new doc differs structurally from the current one (or there was no current one) and every consumer of the old entity space must treat their state as invalid — identical to setDocument's contract. Structural means the new doc has the same XML shape and element ids, and the entity remap carried via the next RenderRequest lets downstream consumers (the compositor) preserve their caches. | |
Public Member Functions | |
| AsyncSVGDocument (const AsyncSVGDocument &)=delete | |
| AsyncSVGDocument & | operator= (const AsyncSVGDocument &)=delete |
| AsyncSVGDocument (AsyncSVGDocument &&)=delete | |
| AsyncSVGDocument & | operator= (AsyncSVGDocument &&)=delete |
| void | setDocument (svg::SVGDocument document) |
| Replace the inner document. Clears any pending commands — they would reference now-invalid entities. Bumps the frame version. | |
| ReplaceKind | setDocumentMaybeStructural (svg::SVGDocument newDocument) |
| Like setDocument, but builds a structural entity remap against the current document first. If the remap is non-empty (trees match by tag name + id at every step), the replacement is tagged as Structural — the next RenderRequest carries the remap so the compositor can call remapAfterStructuralReplace instead of resetAllLayers(documentReplaced=true), preserving cached layer bitmaps and segments across the swap. If the trees differ (user edited the source pane to change shape, etc.) the remap is empty and we fall back to the standard setDocument path. | |
| std::unordered_map< Entity, Entity > | consumePendingStructuralRemap () |
| Take ownership of the pending structural remap produced by the most recent setDocumentMaybeStructural(Structural) call. Returns an empty map if the last replacement was a FullReplace or nothing has been replaced since the last consumption. Called by RenderCoordinator when assembling the next RenderRequest. | |
| bool | hasDocument () const |
| Whether a document has been loaded yet. | |
| svg::SVGDocument & | document () |
| Direct access to the inner document. UI thread only. The render thread should hold the snapshot returned by acquireRenderSnapshot() instead. | |
| const svg::SVGDocument & | document () const |
| void | applyMutation (EditorCommand command) |
| Push a command onto the per-frame queue. UI thread only. | |
| CommandQueue & | queue () |
| Direct access to the command queue. Tools push via applyMutation; this accessor exists for tests and for the main loop's flushFrame. | |
| bool | flushFrame () |
| Drain and apply any pending commands. Called once per frame at the start of the main loop. Returns true if any commands were applied (so the caller can decide whether to re-render). | |
| const FlushResult & | lastFlushResult () const |
| Metadata from the most recent flushFrame() call. | |
| std::uint64_t | documentGeneration () const |
| Generation counter bumped only when setDocument replaces the inner SVGDocument (e.g. ReplaceDocumentCommand on source-pane edits). The inner document's storage address is stable across a replacement (the optional lives inside this object), so pointer-identity is NOT a reliable "is this the same document" check — consumers that cache per-document state (like the compositor's activeHints_ backing an entity space) need this counter to know when to tear that state down. | |
| std::uint64_t | currentFrameVersion () const |
| Monotonic frame version counter. Bumped on every state change visible to the renderer (mutation flush or document replacement). The render thread polls this to detect updates without locking the document. | |
| bool | loadFromString (std::string_view svgBytes) |
| const std::optional< ParseDiagnostic > & | lastParseError () const |
| The diagnostic from the most recent failed loadFromString / ReplaceDocumentCommand. Cleared on every successful parse — so has_value() is the live "is the source pane currently invalid?" signal. | |
Wraps an svg::SVGDocument and the editor's per-frame command queue.
Lifetime: owned by EditorApp (one per editor session). All public methods must be called from the UI thread; the only thread-safe operation is currentFrameVersion() which the render thread can poll.
| struct donner::editor::AsyncSVGDocument::FlushResult |
|
inlinenodiscard |
Generation counter bumped only when setDocument replaces the inner SVGDocument (e.g. ReplaceDocumentCommand on source-pane edits). The inner document's storage address is stable across a replacement (the optional lives inside this object), so pointer-identity is NOT a reliable "is this the same document" check — consumers that cache per-document state (like the compositor's activeHints_ backing an entity space) need this counter to know when to tear that state down.
Distinct from frameVersion_: the frame counter bumps on every mutation (including every drag frame's SetTransformCommand), which would be catastrophic to treat as a document replacement.
| bool donner::editor::AsyncSVGDocument::flushFrame | ( | ) |
Drain and apply any pending commands. Called once per frame at the start of the main loop. Returns true if any commands were applied (so the caller can decide whether to re-render).
Bumps the frame version when commands are applied OR when the document itself was replaced via setDocument since the last flush.