Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::svg::components::ExternalUseStyleRetention Class Reference

Keeps a document referenced by external <use> elements styled for the occurrences that draw it, instead of restyling the whole document for every occurrence on every frame. More...

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

Static Public Member Functions

static void PrepareOccurrence (Registry &registry)
 Prepare the referenced document's styles for the occurrence installed in its ExternalUseStyleContext.
static void PrepareInstance (Registry &registry)
 Once the occurrence's instance layout is in place, schedule an instance rebuild when the render tree was last built for a different occurrence: another root, paint, or viewport the <use> establishes for a <symbol> or <svg>.
static void ScheduleFullRestyle (Registry &registry)
 Schedule a restyle of every element and a full render-tree rebuild of the document.
static bool RestoreOtherSubtreesIfReadingOutside (Registry &registry)
 After the render tree is instantiated for the installed occurrence, restore every other retained subtree to the document's own styles if drawing the occurrence may read any element outside its own subtree: a paint server, clip path, mask, marker, filter, instantiated element, inherited paint server, or a feImage, textPath or mpath target.
static void FinishOccurrence (Registry &registry)
 End the installed occurrence's draw, before its context is removed.
static void RestoreStandalone (Registry &registry)
 Restyle every subtree an occurrence styled and drop the occurrence's rendering instances and context paint, so the document renders and reads with its own styles.
static void RestoreStandaloneForRead (Registry &registry)
 Before a public read of computed or derived state (styles, stops, text metrics, layout transforms, shape geometry and bounds, rendering instances): if an occurrence styled the document, restore it with RestoreStandalone and prepare its render tree again, since restoring drops layout state that reads expect the preparation to have computed.
static bool IsOccurrenceStyled (const Registry &registry, Entity entity)
 Whether entity's computed style currently reflects an occurrence rather than its document.
static bool HasOccurrenceState (const Registry &registry)
 Whether any occurrence state is retained, so the document's rendering instances may reflect an occurrence.

Static Public Attributes

static constexpr std::size_t kMaximumRetainedSubtrees = 32
 Most referenced subtrees kept styled for their occurrence; the least recently drawn beyond this is restyled for the document itself.

Detailed Description

Keeps a document referenced by external <use> elements styled for the occurrences that draw it, instead of restyling the whole document for every occurrence on every frame.

An occurrence's inherited style only reaches the subtree of the element it references, so each referenced subtree stays styled for the inputs it was last drawn with: the element, the host's computed style for the <use>, and its fill and stroke. A draw with the same inputs reuses the subtree's computed state; changed inputs restyle only that subtree. The state lives in the referenced document's registry context.

Only occurrences whose fill and stroke are none or a solid color are retained; one painted with a gradient or pattern reference is restyled for every draw and restored afterwards, so no state outliving a draw refers to the host document. Public reads of the document's own styles and rendering restore it with RestoreStandalone first.

Member Function Documentation

◆ FinishOccurrence()

void donner::svg::components::ExternalUseStyleRetention::FinishOccurrence ( Registry & registry)
static

End the installed occurrence's draw, before its context is removed.

Restores the occurrence's subtree and drops its rendering instances when it must not be retained: its paint refers to the host, or its restyle hit a style resource limit.

Parameters
registryReferenced document's registry, with its occurrence context installed.

◆ HasOccurrenceState()

bool donner::svg::components::ExternalUseStyleRetention::HasOccurrenceState ( const Registry & registry)
static

Whether any occurrence state is retained, so the document's rendering instances may reflect an occurrence.

Parameters
registryDocument registry.

◆ IsOccurrenceStyled()

bool donner::svg::components::ExternalUseStyleRetention::IsOccurrenceStyled ( const Registry & registry,
Entity entity )
static

Whether entity's computed style currently reflects an occurrence rather than its document.

Parameters
registryDocument registry.
entityElement to test.

◆ PrepareInstance()

void donner::svg::components::ExternalUseStyleRetention::PrepareInstance ( Registry & registry)
static

Once the occurrence's instance layout is in place, schedule an instance rebuild when the render tree was last built for a different occurrence: another root, paint, or viewport the <use> establishes for a <symbol> or <svg>.

A full rebuild is scheduled instead when the subtree holds a <use> whose shadow tree a rebuild for another root left uninstantiated.

Parameters
registryReferenced document's registry, with its occurrence context installed.

◆ PrepareOccurrence()

void donner::svg::components::ExternalUseStyleRetention::PrepareOccurrence ( Registry & registry)
static

Prepare the referenced document's styles for the occurrence installed in its ExternalUseStyleContext.

Restyles the referenced subtree only when its retained inputs differ, first restoring any retained ancestor subtree to the document's own styles.

Parameters
registryReferenced document's registry, with its occurrence context installed.

◆ RestoreOtherSubtreesIfReadingOutside()

bool donner::svg::components::ExternalUseStyleRetention::RestoreOtherSubtreesIfReadingOutside ( Registry & registry)
static

After the render tree is instantiated for the installed occurrence, restore every other retained subtree to the document's own styles if drawing the occurrence may read any element outside its own subtree: a paint server, clip path, mask, marker, filter, instantiated element, inherited paint server, or a feImage, textPath or mpath target.

What such an element pulls in can reach any other subtree, so a self-contained subtree is the only one drawn next to retained subtrees.

Parameters
registryReferenced document's registry, with its occurrence context installed.
Returns
True if a subtree was restored, in which case the caller instantiates the render tree again before drawing.

◆ RestoreStandalone()

void donner::svg::components::ExternalUseStyleRetention::RestoreStandalone ( Registry & registry)
static

Restyle every subtree an occurrence styled and drop the occurrence's rendering instances and context paint, so the document renders and reads with its own styles.

Render-tree instantiation calls this before preparing a document without an occurrence.

Parameters
registryDocument registry.

◆ RestoreStandaloneForRead()

void donner::svg::components::ExternalUseStyleRetention::RestoreStandaloneForRead ( Registry & registry)
static

Before a public read of computed or derived state (styles, stops, text metrics, layout transforms, shape geometry and bounds, rendering instances): if an occurrence styled the document, restore it with RestoreStandalone and prepare its render tree again, since restoring drops layout state that reads expect the preparation to have computed.

Call under write access. A read-only accessor that cannot restore reports no value for occurrence-derived state instead.

Parameters
registryDocument registry.

◆ ScheduleFullRestyle()

void donner::svg::components::ExternalUseStyleRetention::ScheduleFullRestyle ( Registry & registry)
static

Schedule a restyle of every element and a full render-tree rebuild of the document.

With an occurrence installed, forget the saved inputs of every other retained subtree, since that restyle runs under the installed occurrence alone.

Parameters
registryReferenced document's registry.

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