Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
paragraph_cache.hpp File Reference

Process-wide cache of laid-out SkParagraphs for SkiaCanvas text. More...

Go to the source code of this file.

Detailed Description

Process-wide cache of laid-out SkParagraphs for SkiaCanvas text.

Every fill_text / stroke_text that goes through SkParagraph shapes and lays out its run, and a Label paints its text on every frame, so a static panel re-shapes every label on every paint. The canvas is constructed per frame, which is why the cache is process-wide rather than per canvas.

The key is everything the paragraph build reads: the text, the resolved family stack, the primary typeface, size, weight, slant, letter spacing, direction, OpenType features, and font_registration_generation(). A font registration therefore makes every earlier entry unreachable, and the next lookup drops them. The paragraph is laid out at infinite width with left alignment and no strut or decoration, so wrap width, text-align and line height are not inputs; the caller aligns the run.

The fill or stroke paint is not part of the key. A cached paragraph is built without a foreground paint and drawn through a painter that applies the caller's paint to each glyph run, so one entry serves every colour, gradient, shadow and filter the same text is drawn with. Updating a paragraph's foreground paint in place would not work: SkParagraph caches its text blobs, with their paints, on the first paint.

Bounded by entry count and by an estimate of each entry's CPU heap footprint (the GPU text-blob cache keeps its own budget). Eviction is a segmented LRU: a new entry starts on probation and is protected once it is looked up again, and probation is evicted first. Text that changes every frame, such as a meter readout, therefore cycles through probation without pushing out the labels that are repainted unchanged.

Windows can paint on different threads, so the map is guarded by a mutex and every use of an entry holds that entry's own mutex: SkParagraph mutates itself while painting and in queries. Entries are destroyed outside the map lock.