Add minimal allback buffer for future use
This commit is contained in:
@@ -147,6 +147,19 @@ const uint8_t* FontDecompressor::getBitmap(const EpdFontData* fontData, const Ep
|
||||
break; // Found the right slot but glyph wasn't in it; don't check other slots
|
||||
}
|
||||
|
||||
// Check fallback LRU cache
|
||||
for (uint8_t i = 0; i < FALLBACK_CACHE_SLOTS; i++) {
|
||||
if (_fallbackCache[i].fontData == fontData && _fallbackCache[i].glyphIndex == glyphIndex) {
|
||||
_fallbackCache[i].lastUsedTick = ++_fallbackTick;
|
||||
stats.cacheHits++;
|
||||
stats.fallbackCacheHits++;
|
||||
stats.getBitmapTimeUs += micros() - tStart;
|
||||
return _fallbackCache[i].buffer;
|
||||
}
|
||||
}
|
||||
|
||||
stats.fallbackCacheMisses++;
|
||||
|
||||
// Fallback: glyph wasn't in the page buffer — decompress its group transiently.
|
||||
// This is the rare path (prewarm should cover all glyphs on a normal page).
|
||||
uint16_t groupIndex = getGroupIndex(fontData, glyphIndex);
|
||||
@@ -181,11 +194,25 @@ const uint8_t* FontDecompressor::getBitmap(const EpdFontData* fontData, const Ep
|
||||
}
|
||||
|
||||
uint32_t alignedOff = getAlignedOffset(fontData, groupIndex, glyphIndex);
|
||||
compactSingleGlyph(&groupBuf[alignedOff], _hotGlyphBuf, glyph->width, glyph->height);
|
||||
|
||||
uint8_t lruIndex = 0;
|
||||
uint32_t oldestTick = UINT32_MAX;
|
||||
for (uint8_t i = 0; i < FALLBACK_CACHE_SLOTS; i++) {
|
||||
if (_fallbackCache[i].lastUsedTick < oldestTick) {
|
||||
oldestTick = _fallbackCache[i].lastUsedTick;
|
||||
lruIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
compactSingleGlyph(&groupBuf[alignedOff], _fallbackCache[lruIndex].buffer, glyph->width, glyph->height);
|
||||
free(groupBuf);
|
||||
|
||||
_fallbackCache[lruIndex].fontData = fontData;
|
||||
_fallbackCache[lruIndex].glyphIndex = glyphIndex;
|
||||
_fallbackCache[lruIndex].lastUsedTick = ++_fallbackTick;
|
||||
|
||||
stats.getBitmapTimeUs += micros() - tStart;
|
||||
return _hotGlyphBuf;
|
||||
return _fallbackCache[lruIndex].buffer;
|
||||
}
|
||||
|
||||
// --- Prewarm: pre-decompress glyph bitmaps for a page of text ---
|
||||
@@ -537,5 +564,12 @@ void FontDecompressor::logStats(const char* label) {
|
||||
LOG_DBG("FDC", "[%s] getBitmap: %lu calls, %luus total, %luus/call avg", label, stats.getBitmapCalls,
|
||||
stats.getBitmapTimeUs, stats.getBitmapTimeUs / stats.getBitmapCalls);
|
||||
}
|
||||
|
||||
uint32_t lruTotal = stats.fallbackCacheHits + stats.fallbackCacheMisses;
|
||||
if (lruTotal > 0) {
|
||||
LOG_DBG("FDC", "[%s] LRU Fallback: hits=%lu misses=%lu (%.1f%%)", label, stats.fallbackCacheHits,
|
||||
stats.fallbackCacheMisses, 100.0f * stats.fallbackCacheHits / lruTotal);
|
||||
}
|
||||
|
||||
resetStats();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user