Files
ppsspp/Common/Render/Text/Font.h
T
Henrik RydgårdandClaude Opus 5.5 02b688e4f3 TextDrawer: Cache wrapped text, hash the string caches
MeasureString was slow mostly because of wrapping: DrawStringRect and
MeasureStringRect re-ran the word wrapper every frame, and it measures
every prefix of every word. Wrapped strings are now cached. The caches
are unordered_maps with an xxhash of the key, and lookups reuse a key
buffer so a hit doesn't allocate. UIContext also skips switching fonts
when measuring in the current style. In a Mac debug build, 200 cached
measures go from 0.26 to 0.06 ms and 10 wrapped paragraphs from 2.1 to
0.01 ms per frame.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 10:11:42 +02:00

47 lines
1.1 KiB
C++

#pragma once
#include <string>
#include <string_view>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Render/TextureAtlas.h"
#include "Common/Data/Hash/Hash.h"
// NOTE: Make sure the java flags match.
enum class FontStyleFlags : u8 {
Default = 0,
Bold = 1,
Light = 2,
Italic = 16,
Underline = 32, // Future use.
Strikethrough = 64, // Future use.
};
ENUM_CLASS_BITOPS(FontStyleFlags);
enum class FontFamily : u8 {
SansSerif = 1,
Fixed = 2,
};
struct FontStyle {
FontStyle() {}
constexpr FontStyle(FontFamily _family, int size, FontStyleFlags _flags) : family(_family), sizePts(size), flags(_flags) {}
u16 sizePts = 0;
FontFamily family = FontFamily::SansSerif;
FontStyleFlags flags = FontStyleFlags::Default;
};
inline constexpr bool operator==(const FontStyle &a, const FontStyle &b) {
return a.family == b.family && a.sizePts == b.sizePts && a.flags == b.flags;
}
inline constexpr bool operator<(const FontStyle &a, const FontStyle &b) {
if (a.family != b.family)
return a.family < b.family;
if (a.sizePts != b.sizePts)
return a.sizePts < b.sizePts;
return a.flags < b.flags;
}