Gfx: Make text rendering with D2D more efficient by reusing layout

This commit is contained in:
Birunthan Mohanathas
2013-03-28 15:51:12 +02:00
parent 71a454f954
commit e5100d9a9f
3 changed files with 57 additions and 13 deletions

View File

@ -23,6 +23,7 @@ namespace Gfx {
TextFormatD2D::TextFormatD2D() :
m_TextFormat(),
m_TextLayout(),
m_InlineEllipsis()
{
}
@ -40,6 +41,12 @@ void TextFormatD2D::Dispose()
m_TextFormat = nullptr;
}
if (m_TextLayout)
{
m_TextLayout->Release();
m_TextLayout = nullptr;
}
if (m_InlineEllipsis)
{
m_InlineEllipsis->Release();
@ -47,6 +54,40 @@ void TextFormatD2D::Dispose()
}
}
void TextFormatD2D::CreateLayout(const WCHAR* str, UINT strLen, float maxW, float maxH)
{
bool strChanged = false;
if (strLen != m_LastString.length() ||
memcmp(str, m_LastString.c_str(), (strLen + 1) * sizeof(WCHAR)) != 0)
{
strChanged = true;
m_LastString.assign(str, strLen);
}
if (m_TextLayout && !strChanged)
{
if (maxW != m_TextLayout->GetMaxWidth())
{
m_TextLayout->SetMaxWidth(maxW);
}
if (maxH != m_TextLayout->GetMaxHeight())
{
m_TextLayout->SetMaxWidth(maxH);
}
}
else
{
if (m_TextLayout)
{
m_TextLayout->Release();
m_TextLayout = nullptr;
}
CanvasD2D::c_DW->CreateTextLayout(str, strLen, m_TextFormat, maxW, maxH, &m_TextLayout);
}
}
void TextFormatD2D::SetProperties(const WCHAR* fontFamily, int size, bool bold, bool italic, Gdiplus::PrivateFontCollection* fontCollection)
{
Dispose();