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

Retained encodes and GPU residence of the shapes one text element paints outside the glyph cache's solid fills: placed glyph outlines filled with a gradient or a pattern, or with a solid along a text path; the joined stroke outlines of its glyphs; and its decoration lines and their strokes. More...

#include "donner/svg/renderer/geode/GeodeGlyphResidency.h"

Classes

struct  Shape
 One retained shape: its geometry key, encode and residence. More...

Public Types

using ShapeOwner = std::unique_ptr<Shape>
 Owner of one shape, so its address stays put while the owner vector grows. An ordinal whose draw could not be kept holds a null owner, so the shapes after it keep their own ordinals.

Public Member Functions

 GeodeTextShapeCache (const GeodeTextShapeCache &)=delete
GeodeTextShapeCache & operator= (const GeodeTextShapeCache &)=delete
 GeodeTextShapeCache (GeodeTextShapeCache &&) noexcept=default
GeodeTextShapeCache & operator= (GeodeTextShapeCache &&) noexcept=default
Shape * find (size_t index, const Path &path, FillRule rule, double tolerance)
 Shape index when it holds exactly path, rule and tolerance, else null.
Shape * store (size_t index, const Path &path, FillRule rule, double tolerance, EncodedPath &encoded, const std::shared_ptr< GeodeDocumentGeometryBudget > &budget, size_t maximumShapes)
 Keeps encoded as shape index, replacing whatever the shape held, and returns it.
void release (size_t index)
 Drops shape index and its charge, leaving its ordinal empty: a draw whose new geometry could not be kept does not keep the old geometry it replaced either.
void trim (size_t count)
 Drops the shapes from count on, which the element's last draw did not reach.
size_t size () const
 Number of ordinals held, empty ones included, until the next draw trims those it did not reach.
size_t keptShapes () const
 Number of ordinals that hold a kept shape.
uint64_t retainedBytes () const
 Bytes charged to the document's cache budget for this cache.

Public Attributes

uint64_t lastFrame = 0
 Device-scoped frame generation of the last draw that used these shapes; zero means never.

Static Public Attributes

static constexpr size_t kDefaultMaximumShapes = 4096
 Shapes one element keeps per device unless a test lowers it: more than the glyph occurrences of a long paragraph painted with a gradient or pattern, each with a stroke group.
static constexpr uint64_t kShapeOverheadBytes = sizeof(Shape)
 Bytes a shape retains besides its path and encode vectors.

Detailed Description

Retained encodes and GPU residence of the shapes one text element paints outside the glyph cache's solid fills: placed glyph outlines filled with a gradient or a pattern, or with a solid along a text path; the joined stroke outlines of its glyphs; and its decoration lines and their strokes.

These shapes are built in the element's own space every frame, so the draw that paints them is the same draw a per-frame encode would feed, and keeping them lets an unchanged frame encode, upload and bind nothing for them.

Shape i is the element's ith such draw in paint order. A draw reuses shape i only when the path it is about to paint, its fill rule and the encode tolerance are bitwise identical to what the shape holds; any difference replaces the shape, with fresh residence. Because the key is the geometry itself, no edit can leave a shape stale: an edit that changes what is painted changes the path, and an edit that only changes the paint reaches the draw's uniform as it does for any resident fill.

Bounded by the renderer's shape cap (kDefaultMaximumShapes) per element and device; draws past it, or one the document's cache budget refuses, encode for the frame as before, and a refused draw leaves its ordinal empty, so the shapes after it are still kept. Every shape's retained bytes (kShapeOverheadBytes plus its path and encode capacities) and the owner vector's capacity are charged to the document's cache budget, and its GPU geometry to the document's resident budget through the slab.

A shape is replaced or dropped only while no frame that has not submitted drew the element (lastFrame, a device-scoped generation, as for GeodeOccurrenceRecords). Its residence then returns through the slab's deferred free and bind-group retirement, which also covers an element destroyed while such a frame is open.


Class Documentation

◆ donner::geode::GeodeTextShapeCache::Shape

struct donner::geode::GeodeTextShapeCache::Shape

One retained shape: its geometry key, encode and residence.

Class Members
EncodedPath encoded Encode of path; its address is stable.
GeodeResidentGradientSlot gradientSlot Residence for gradient paint.
Path path Exact geometry the encode was built from.
uint64_t retainedBytes = 0 Bytes charged for this shape.
FillRule rule = FillRule::NonZero Fill rule the encode was built for.
GeodeResidentSlot slot Residence for solid and pattern paint.
uint64_t toleranceBits = 0 Raw bits of the encode tolerance.

Member Function Documentation

◆ find()

Shape * donner::geode::GeodeTextShapeCache::find ( size_t index,
const Path & path,
FillRule rule,
double tolerance )
inline

Shape index when it holds exactly path, rule and tolerance, else null.

Parameters
indexOrdinal of the draw within the element.
pathGeometry about to be painted.
ruleFill rule of the draw.
toleranceEncode tolerance of the draw.

◆ release()

void donner::geode::GeodeTextShapeCache::release ( size_t index)
inline

Drops shape index and its charge, leaving its ordinal empty: a draw whose new geometry could not be kept does not keep the old geometry it replaced either.

Parameters
indexOrdinal of the shape.

◆ store()

Shape * donner::geode::GeodeTextShapeCache::store ( size_t index,
const Path & path,
FillRule rule,
double tolerance,
EncodedPath & encoded,
const std::shared_ptr< GeodeDocumentGeometryBudget > & budget,
size_t maximumShapes )
inline

Keeps encoded as shape index, replacing whatever the shape held, and returns it.

Ordinals between the last held shape and index stay empty. Fails without consuming encoded when index is at or past maximumShapes, a size overflows, or budget refuses the charge.

Parameters
indexOrdinal of the draw within the element.
pathGeometry encoded was built from.
ruleFill rule of encoded.
toleranceEncode tolerance of encoded.
encodedEncode to keep; moved from only on success.
budgetDocument budget charged for the cache.
maximumShapesMost shapes this cache may hold.

◆ trim()

void donner::geode::GeodeTextShapeCache::trim ( size_t count)
inline

Drops the shapes from count on, which the element's last draw did not reach.

Parameters
countNumber of shapes to keep.

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