Repository navigation
text-freetype2: Evict old glyphs when the atlas is full - #196
Merged
Merged
Conversation
A FreeType 2 text source caches every glyph it has drawn in one 2048x2048 atlas and only empties it when the font or antialiasing changes. A source reading a file that keeps changing therefore fills the atlas, and from then on every new letter is skipped with only an "Out of space trying to render glyphs" warning in the log (upstream obsproject/obs-studio#11819, reported by iarspider). At the default 256 px size the standard ASCII set alone uses most of the atlas. Move the atlas packing out of cache_glyphs() into glyph-atlas.c, free of FreeType and graphics calls, and test it with fixed-size glyphs. The function keeps today's behaviour (stop at the first glyph that does not fit, never evict), so 2 of the 5 tests fail: - new_text_after_full_atlas_is_drawn - texts_keep_rotating_without_losing_letters Refs obs-rust#195. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When a glyph of the current text does not fit in the source's atlas, empty the atlas once and cache the current text again, so glyphs of earlier texts make room for it instead of new letters being skipped until the font changes (upstream obsproject/obs-studio#11819, reported by iarspider). An atlas that was already empty when the text arrived is not cleared again: a text with more glyphs than fit at its size still stops with the "Out of space" warning rather than looping. new_text_after_full_atlas_is_drawn and texts_keep_rotating_without_losing_letters now pass; 5 of 5 tests pass. Fixes obs-rust#195. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Local-Gate: v1 tree=5ec92a6bd2fce8c1720c3efcd0b61e134dc8d170 secs=106 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791695031,"gate":"rust/all/fmt","host":"linux-x86_64","key":"7a2b3cf7ebcdb5a8fbf224947731272211ca277dcd3072c193dcecf48875a9b0","lane":"lint","parents":["d94bdbd0f89e12315ecfdf7e140959c73eb5113e"],"secs":15,"stamp":"4791d58b61f8de2acd86c29caec45236","tree":"5ec92a6bd2fce8c1720c3efcd0b61e134dc8d170","v":1,"via":"run"} Ci-Attestation: {"at":1791695031,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"7a2b3cf7ebcdb5a8fbf224947731272211ca277dcd3072c193dcecf48875a9b0","lane":"lint","parents":["d94bdbd0f89e12315ecfdf7e140959c73eb5113e"],"secs":15,"stamp":"79cfd47fd161716d09fc1a738f9465ed","tree":"5ec92a6bd2fce8c1720c3efcd0b61e134dc8d170","v":1,"via":"run"} Ci-Attestation: {"at":1791695031,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8a24c8171e0fd3cce5f1a5116ef1b2d46335f2a140a61756c426464d6221ee24","lane":"rust-test","parents":["d94bdbd0f89e12315ecfdf7e140959c73eb5113e"],"secs":30,"stamp":"a4073f3b80f5d3fb156010b3fb975846","tree":"5ec92a6bd2fce8c1720c3efcd0b61e134dc8d170","v":1,"via":"run"} Ci-Attestation: {"at":1791695031,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"787348aaa3944da2e0a259d8b86a3f6671e73ead1bcfc15f57cc4bcef22fca4a","lane":"tier2-linux","parents":["d94bdbd0f89e12315ecfdf7e140959c73eb5113e"],"secs":60,"stamp":"6278b9d9aaca814d5377b2b629def250","tree":"5ec92a6bd2fce8c1720c3efcd0b61e134dc8d170","v":1,"via":"run"}
Member
|
Verified locally, rebased onto master and stamped. The new head is
Merging once CI is green. |
zackees
force-pushed
the
fix/195-freetype-glyph-atlas
branch
from
October 11, 2026 05:03
c39d022 to
f586019
Compare
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 18, 2026
get_font_path() read FC_INDEX with FcPatternGetInteger(match, FC_INDEX, 1, ...). The third argument is the position among the property's values, and a matched pattern has one index, at position 0. The call always failed, fc_index kept its default 0, and FT_New_Face() loaded the first face of the file (obsproject/obs-studio#11819). So any font that is not face 0 of its file rendered as face 0: Bold and the other named instances of a variable font (Adwaita Sans Bold is index 458752 in AdwaitaSans-Regular.ttf), and the faces of a .ttc collection (Noto Sans CJK SC is face 2 of NotoSansCJK-Regular.ttc; it rendered as the JP face 0). Port of the first commit of obsproject/obs-studio#13290 by reyohoho. The other two commits there (a larger glyph atlas, pre-cached Cyrillic) are covered here by obs-rust#196's atlas fix and are not part of this change. test_text_freetype2_face_index: 2 of 2. In the app, Adwaita Sans Bold now renders bold (513 -> 525 px wide, ink 0.185 -> 0.273 at 96 px), and Noto Sans CJK SC renders the SC glyphs instead of JP's. Fixes obs-rust#1409. Co-Authored-By: reyohoho <[email protected]>
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 18, 2026
get_font_path() read FC_INDEX with FcPatternGetInteger(match, FC_INDEX, 1, ...). The third argument is the position among the property's values, and a matched pattern has one index, at position 0. The call always failed, fc_index kept its default 0, and FT_New_Face() loaded the first face of the file (obsproject/obs-studio#11819). So any font that is not face 0 of its file rendered as face 0: Bold and the other named instances of a variable font (Adwaita Sans Bold is index 458752 in AdwaitaSans-Regular.ttf), and the faces of a .ttc collection (Noto Sans CJK SC is face 2 of NotoSansCJK-Regular.ttc; it rendered as the JP face 0). Port of the first commit of obsproject/obs-studio#13290 by reyohoho. The other two commits there (a larger glyph atlas, pre-cached Cyrillic) are covered here by obs-rust#196's atlas fix and are not part of this change. test_text_freetype2_face_index: 2 of 2. In the app, Adwaita Sans Bold now renders bold (513 -> 525 px wide, ink 0.185 -> 0.273 at 96 px), and Noto Sans CJK SC renders the SC glyphs instead of JP's. Fixes obs-rust#1409. Co-Authored-By: reyohoho <[email protected]>
vpacher
pushed a commit
to vpacher/obs-studio
that referenced
this pull request
Oct 18, 2026
…bs-rust#1411) * test/cmocka: Add failing test for a font that is not face 0 of its file The Text (FreeType 2) source on Linux loads the first face of a font file whatever face fontconfig matched (obsproject/obs-studio#11819). A face of a .ttc/.otc collection, such as Noto Sans CJK SC, TC or KR, or a named instance of a variable font, such as Adwaita Sans Bold, renders as face 0. test_text_freetype2_face_index points fontconfig at a directory that holds only text-collection.ttc, a two-face collection generated by test/cmocka/data/text-collection.py from synthetic outlines ("OBS Collection Fixture" Regular as face 0, Bold as face 1), and asks get_font_path() for each style. Fails 1 of 2: bold_resolves_to_face_1 ("Bold resolved to face 0 of .../text-collection.ttc (expected 1)"). Regular passes. Needs no display. Refs obs-rust#1409. * text-freetype2: Read the matched font's face index from fontconfig get_font_path() read FC_INDEX with FcPatternGetInteger(match, FC_INDEX, 1, ...). The third argument is the position among the property's values, and a matched pattern has one index, at position 0. The call always failed, fc_index kept its default 0, and FT_New_Face() loaded the first face of the file (obsproject/obs-studio#11819). So any font that is not face 0 of its file rendered as face 0: Bold and the other named instances of a variable font (Adwaita Sans Bold is index 458752 in AdwaitaSans-Regular.ttf), and the faces of a .ttc collection (Noto Sans CJK SC is face 2 of NotoSansCJK-Regular.ttc; it rendered as the JP face 0). Port of the first commit of obsproject/obs-studio#13290 by reyohoho. The other two commits there (a larger glyph atlas, pre-cached Cyrillic) are covered here by obs-rust#196's atlas fix and are not part of this change. test_text_freetype2_face_index: 2 of 2. In the app, Adwaita Sans Bold now renders bold (513 -> 525 px wide, ink 0.185 -> 0.273 at 96 px), and Noto Sans CJK SC renders the SC glyphs instead of JP's. Fixes obs-rust#1409. Co-Authored-By: reyohoho <[email protected]> --------- Co-authored-by: reyohoho <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A FreeType 2 text source whose text keeps changing, for example one reading a now-playing file, starts dropping letters after a while. Once that starts, every letter it has not drawn before is left out until the font or antialiasing setting is changed. With this change the source makes room for the new text, and every letter is drawn.
The cause: each source caches the glyphs it has drawn in a single 2048x2048 texture atlas. The atlas is only emptied when the font or antialiasing changes, never when the text changes. When a glyph doesn't fit,
cache_glyphs()logs "Out of space trying to render glyphs" and stops, andfill_vertex_buffer()skips every character that has no cached glyph. At the v2 source's default size of 256 px, the standard ASCII set the source caches up front already fills the atlas to y=1200 of 2048. A few dozen more letters (Cyrillic in the report, but any script works) fill the rest.test/cmocka: Add RED FreeType 2 glyph atlas tests: moves the atlas packing out ofcache_glyphs()intoglyph_atlas_cache()inplugins/text-freetype2/glyph-atlas.c, with no FreeType or graphics calls. FreeType rendering, storing a glyph and clearing the atlas are passed in as callbacks. The function keeps today's behaviour. It addstest_glyph_atlas, which packs fixed 10x10 glyphs into a 64x64 atlas. 2 of its 5 tests fail on this commit:new_text_after_full_atlas_is_drawn: "glyph U+041C of the current text was never cached"texts_keep_rotating_without_losing_letters: "glyph U+0419 of the current text was never cached"text-freetype2: Evict old glyphs when the atlas is full: when a glyph of the current text doesn't fit, the atlas is emptied once and the current text is cached again from the start. Emptying it frees the cached glyph records and zeroes the pixel buffer. An atlas that was already empty when the text arrived is not emptied again, so a single text with more glyphs than fit at its size still stops with the warning instead of looping. All 5 tests pass.Motivation and Context
Fixes #195 (upstream obsproject/obs-studio#11819, reported by iarspider)
Why this one: upstream confirmed it in February 2025, and there is still no upstream fix PR. It affects anyone with a text source whose text keeps changing, such as now-playing titles or chat logs. The default 256 px size makes it likely: replaying the reporter's 1055 titles in file order, the 17th already loses letters. Nothing on screen says why; the only sign is one warning line in the log.
How Has This Been Tested?
Automated (cmocka; no FreeType or graphics device needed):
text_that_fits_is_cached_onceatlas_holds_its_capacitynew_text_after_full_atlas_is_drawntexts_keep_rotating_without_losing_letterstext_larger_than_atlas_is_not_retried_foreverout_of_spaceand does not clear an atlas that started emptyI built and ran both commits on Arch Linux with FreeType 2.14.3. The rest of ctest (61 tests in all) passes on the GREEN commit, and
text-freetype2builds without warnings.Replay: a headless harness renders real glyphs with FreeType through
glyph_atlas_cache()in the same waycache_glyphs()does. It uses Liberation Sans, the default "Sans Serif" match here. It caches the standard glyph set first, then feeds the reporter'srecord_archive.txt(1055 titles, 136 distinct characters) one title at a time, and counts titles with at least one uncached letter:clang-format 22.1.3 and gersemi 0.25.0 (
./lint's C and CMake checks) pass on the changed files. The Rust steps of./lintand./unittestneedsoldr, which isn't installed here, and the Tier 2 Docker lane couldn't run without Docker access. This PR changes no Rust.Not tested:
Types of changes
Checklist:
🤖 Generated with Claude Code