Stop mapping all Unicode through CJK fonts and cut D2D working-set growth
Custom font fallback no longer covers the whole BMP/SIP, so Segoe UI Emoji can paint color glyphs again; CJK still prefers Noto Sans SC then YaHei. Drop GaussianBlur compatible targets during BeginDraw (they retained GPU memory as the candidate window grew), grow the composition swapchain in 64px steps without shrinking, and reuse Card chrome plus cached text formats instead of reallocating them every layout.
This commit is contained in:
1 parent
5421c1dd1b
commit
2ac86ea0e2
5 files changed
+152
-122
No files matched your search
+41
-10
@@ -178,20 +178,51 @@ ComPtr<IDWriteTextLayout> CreateCachedTextLayout(IDWriteFactory *factory, const
|
||||
}
|
||||
|
||||
ComPtr<IDWriteTextFormat> format;
|
||||
if (FAILED(factory->CreateTextFormat(fontFamily.c_str(), nullptr, fontWeight, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, fontSize, L"", format.GetAddressOf())))
|
||||
struct TextFormatKey
|
||||
{
|
||||
if (FAILED(factory->CreateTextFormat(UiFontFallbackFamily(), nullptr, fontWeight, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, fontSize, L"", format.GetAddressOf())))
|
||||
std::wstring family;
|
||||
float size = 0.0f;
|
||||
DWRITE_FONT_WEIGHT weight = DWRITE_FONT_WEIGHT_NORMAL;
|
||||
DWRITE_TEXT_ALIGNMENT textAlignment = DWRITE_TEXT_ALIGNMENT_LEADING;
|
||||
DWRITE_PARAGRAPH_ALIGNMENT paragraphAlignment = DWRITE_PARAGRAPH_ALIGNMENT_NEAR;
|
||||
DWRITE_WORD_WRAPPING wordWrapping = DWRITE_WORD_WRAPPING_NO_WRAP;
|
||||
ComPtr<IDWriteTextFormat> format;
|
||||
};
|
||||
static std::vector<TextFormatKey> formatCache;
|
||||
for (auto &entry : formatCache)
|
||||
{
|
||||
if (entry.family == fontFamily && entry.size == fontSize && entry.weight == fontWeight &&
|
||||
entry.textAlignment == textAlignment && entry.paragraphAlignment == paragraphAlignment &&
|
||||
entry.wordWrapping == wordWrapping && entry.format)
|
||||
{
|
||||
return layout;
|
||||
format = entry.format;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
format->SetTextAlignment(textAlignment);
|
||||
format->SetParagraphAlignment(paragraphAlignment);
|
||||
format->SetWordWrapping(wordWrapping);
|
||||
ApplyUiFontFallback(factory, format.Get());
|
||||
if (!format)
|
||||
{
|
||||
if (FAILED(factory->CreateTextFormat(fontFamily.c_str(), nullptr, fontWeight, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, fontSize, L"", format.GetAddressOf())))
|
||||
{
|
||||
if (FAILED(factory->CreateTextFormat(UiFontFallbackFamily(), nullptr, fontWeight, DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL, fontSize, L"", format.GetAddressOf())))
|
||||
{
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
format->SetTextAlignment(textAlignment);
|
||||
format->SetParagraphAlignment(paragraphAlignment);
|
||||
format->SetWordWrapping(wordWrapping);
|
||||
TextFormatKey entry;
|
||||
entry.family = fontFamily;
|
||||
entry.size = fontSize;
|
||||
entry.weight = fontWeight;
|
||||
entry.textAlignment = textAlignment;
|
||||
entry.paragraphAlignment = paragraphAlignment;
|
||||
entry.wordWrapping = wordWrapping;
|
||||
entry.format = format;
|
||||
formatCache.push_back(std::move(entry));
|
||||
}
|
||||
|
||||
if (FAILED(factory->CreateTextLayout(text.c_str(), static_cast<UINT32>(text.size()), format.Get(), width, height,
|
||||
layout.GetAddressOf())))
|
||||
|
||||
Reference in new issue
Block a user