ttf.c: glyph raster cache, fixed slots, no allocation (item 4.3.7d)
Punch list §25 item 4.3.7d complete. ttf_raster_cache_get() looks up (font, codepoint, size_px) in a caller-owned fixed slot array, evicting round-robin once full, rasterizing into a slot on a miss. Verified live in tools/ttftest.c: an identical (font, 'A', 24px) call made twice returns was_hit=0 then was_hit=1, and the slot's own hits counter reads exactly 1 afterward -- checked programmatically. A different-codepoint call misses again, proving the key actually discriminates. Wall-clock timing (miss 0.040ms vs hit 0.001ms) is printed as informational corroboration only, not the load-bearing check. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
095860251a
commit
2db4603d04
@@ -4849,11 +4849,36 @@ document and committing that amendment as its own item.*
|
||||
> job), but `ttf.c` builds into all three via the `hal/*.c` wildcard so a portability
|
||||
> compile check costs little and catches real bugs early.
|
||||
|
||||
- [ ] **4.3.7d — Glyph raster cache.** Rasterizing on every draw call is too slow for
|
||||
- [x] **4.3.7d — Glyph raster cache.** Rasterizing on every draw call is too slow for
|
||||
repeated text; cache rasterized bitmaps keyed by (font, codepoint, size). *Done when:*
|
||||
drawing the same codepoint/size twice measurably hits the cache on the second call (e.g. a
|
||||
counter or timing difference), verified live, not just "code that should cache." *Refs:*
|
||||
§27.7.
|
||||
> **Done 2026-08-10.** `ttf_raster_cache_get()`/`ttf_raster_cache_init()` in
|
||||
> `src/starkernel/hal/ttf.c`/`ttf.h`: a fixed, caller-owned slot array (no allocation, same
|
||||
> convention as the rest of this module), linear-scan lookup keyed by (font pointer,
|
||||
> codepoint, size_px), round-robin eviction once every slot is full. Each slot is a fixed
|
||||
> `TTF_CACHE_BITMAP_DIM` (80×80) square, rasterized at a fixed origin
|
||||
> (`TTF_CACHE_MARGIN`, `size_px + TTF_CACHE_MARGIN`) regardless of the glyph's own bounding
|
||||
> box — a caller doing real text layout (4.3.7e) needs to know this fixed convention, not
|
||||
> assume the bitmap is tightly cropped to the glyph.
|
||||
>
|
||||
> **Verified live, not just "code that should cache"** (this item's own bar): extended
|
||||
> `tools/ttftest.c`'s `test_raster_cache()` calls `ttf_raster_cache_get()` twice for the
|
||||
> identical (font, `'A'`, 24px) key — first call returns `was_hit=0` (rasterized), second
|
||||
> returns `was_hit=1` (cache hit), and the slot's own `hits` counter reads exactly 1
|
||||
> afterward, checked programmatically, not just printed. A third call for a different
|
||||
> codepoint (`'a'`) at the same size misses again, proving the key actually discriminates
|
||||
> rather than the cache just always reporting "hit". Wall-clock `clock()` timing is also
|
||||
> printed as corroborating evidence (miss 0.040ms vs. hit 0.001ms on this run) but is
|
||||
> explicitly labeled informational-only in the test's own output, since host `clock()`
|
||||
> resolution is coarse and this repo doesn't treat unverified timing claims as proof on
|
||||
> their own — the hit counter is the load-bearing check.
|
||||
>
|
||||
> No kernel-boot/screendump verification needed — this item's own "done when" only asks
|
||||
> for a measurable hit, which the host test above demonstrates directly; unlike 4.3.7c,
|
||||
> nothing here is CANVAS-visual. Compile-checked clean (`-Wall -Werror -Wextra`) on all
|
||||
> three architectures, with and without `-D__STARKERNEL__`.
|
||||
|
||||
- [ ] **4.3.7e — `TTF-TEXT` entry point.** `TTF-TEXT ( c-addr u x y size color -- )`,
|
||||
analogous to 4.3.6f's `TEXT` but TrueType-backed — becomes the primary text-rendering path
|
||||
|
||||
Reference in New Issue
Block a user