Implements reportMemory() methods across SdCardFont, SdCardFontManager, and Section classes to track resident heap usage. Adds heap audit logging in EpubReaderActivity to attribute memory to fonts, framebuffer, section data, and other components for measurement-driven optimization.
54 lines
1.7 KiB
C++
54 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class GfxRenderer;
|
|
class SdCardFont;
|
|
struct SdCardFontFamilyInfo;
|
|
|
|
class SdCardFontManager {
|
|
public:
|
|
SdCardFontManager() = default;
|
|
~SdCardFontManager();
|
|
SdCardFontManager(const SdCardFontManager&) = delete;
|
|
SdCardFontManager& operator=(const SdCardFontManager&) = delete;
|
|
|
|
// Load the font file whose physical point size is closest to the reader
|
|
// fontSizeEnum (SMALL=12, MEDIUM=14, LARGE=16, EXTRA_LARGE=18). Only one
|
|
// .cpfont file is loaded; other sizes remain on disk. This keeps resident
|
|
// interval + kern/ligature tables to one size's worth of memory.
|
|
// Returns true on success.
|
|
bool loadFamily(const SdCardFontFamilyInfo& family, GfxRenderer& renderer, uint8_t fontSizeEnum);
|
|
|
|
// Unload everything, unregister from renderer.
|
|
void unloadAll(GfxRenderer& renderer);
|
|
|
|
// Look up the font ID for the loaded family. Returns 0 if nothing loaded
|
|
// or familyName doesn't match.
|
|
int getFontId(const std::string& familyName) const;
|
|
|
|
// Get name of currently loaded family (empty if none).
|
|
const std::string& currentFamilyName() const { return loadedFamilyName_; };
|
|
|
|
// Sum of loaded fonts' resident heap (see SdCardFont::reportMemory).
|
|
size_t reportMemory() const;
|
|
|
|
// Point size that was actually loaded.
|
|
// 0 if nothing loaded.
|
|
uint8_t currentPointSize() const { return loadedPointSize_; };
|
|
|
|
private:
|
|
struct LoadedFont {
|
|
SdCardFont* font; // heap-allocated, owned
|
|
int fontId;
|
|
uint8_t size;
|
|
};
|
|
static int computeFontId(uint32_t contentHash, const char* familyName, uint8_t pointSize);
|
|
|
|
std::string loadedFamilyName_;
|
|
uint8_t loadedPointSize_ = 0;
|
|
std::vector<LoadedFont> loaded_;
|
|
};
|