Skip to content

Commit

Permalink
AtlasEngine: Improve debuggability (#17136)
Browse files Browse the repository at this point in the history
This is some test code and natvis fixes that I used to trace down
an issue during font rendering.
  • Loading branch information
lhecker committed Apr 26, 2024
1 parent 26900ca commit 8d67477
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
35 changes: 34 additions & 1 deletion src/renderer/atlas/BackendD3D.cpp
Expand Up @@ -1242,7 +1242,7 @@ BackendD3D::AtlasGlyphEntry* BackendD3D::_drawGlyph(const RenderingPayload& p, c
DWRITE_RENDERING_MODE renderingMode{};
DWRITE_GRID_FIT_MODE gridFitMode{};
THROW_IF_FAILED(fontFaceEntry.fontFace->GetRecommendedRenderingMode(
/* fontEmSize */ fontEmSize,
/* fontEmSize */ glyphRun.fontEmSize,
/* dpiX */ 1, // fontEmSize is already in pixel
/* dpiY */ 1, // fontEmSize is already in pixel
/* transform */ nullptr,
Expand Down Expand Up @@ -1294,6 +1294,39 @@ BackendD3D::AtlasGlyphEntry* BackendD3D::_drawGlyph(const RenderingPayload& p, c
// The buffer now contains a grayscale alpha mask.
#endif

// This code finds the local font file path. Useful for debugging as it
// gets you the font.ttf <> glyphIndex pair to uniquely identify glyphs.
#if 0
std::vector<std::wstring> paths;

UINT32 numberOfFiles;
THROW_IF_FAILED(fontFaceEntry.fontFace->GetFiles(&numberOfFiles, nullptr));
wil::com_ptr<IDWriteFontFile> fontFiles[8];
THROW_IF_FAILED(fontFaceEntry.fontFace->GetFiles(&numberOfFiles, fontFiles[0].addressof()));

for (UINT32 i = 0; i < numberOfFiles; ++i)
{
wil::com_ptr<IDWriteFontFileLoader> loader;
THROW_IF_FAILED(fontFiles[i]->GetLoader(loader.addressof()));

void const* fontFileReferenceKey;
UINT32 fontFileReferenceKeySize;
THROW_IF_FAILED(fontFiles[i]->GetReferenceKey(&fontFileReferenceKey, &fontFileReferenceKeySize));

if (const auto localLoader = loader.try_query<IDWriteLocalFontFileLoader>())
{
UINT32 filePathLength;
THROW_IF_FAILED(localLoader->GetFilePathLengthFromKey(fontFileReferenceKey, fontFileReferenceKeySize, &filePathLength));

filePathLength++;
std::wstring filePath(filePathLength, L'\0');
THROW_IF_FAILED(localLoader->GetFilePathFromKey(fontFileReferenceKey, fontFileReferenceKeySize, filePath.data(), filePathLength));

paths.emplace_back(std::move(filePath));
}
}
#endif

const int scale = row.lineRendition != LineRendition::SingleWidth;
D2D1_MATRIX_3X2_F transform = identityTransform;

Expand Down
22 changes: 9 additions & 13 deletions tools/ConsoleTypes.natvis
Expand Up @@ -124,7 +124,7 @@
</Type>

<Type Name="til::linear_flat_set&lt;*,*&gt;">
<DisplayString>{{ size={_load / $T2} }}</DisplayString>
<DisplayString>{{ size={_load / $T3} }}</DisplayString>
<Expand>
<ArrayItems>
<Size>_capacity</Size>
Expand Down Expand Up @@ -161,22 +161,18 @@
</Type>

<Type Name="Microsoft::Console::Render::Atlas::BackendD3D::AtlasGlyphEntry">
<DisplayString Condition="!_occupied">(empty)</DisplayString>
<DisplayString Condition="_occupied">{glyphIndex}</DisplayString>
</Type>

<Type Name="Microsoft::Console::Render::Atlas::BackendD3D::AtlasFontFaceEntryInner">
<DisplayString>{(void*)fontFace.m_ptr}, {lineRendition}</DisplayString>
<Expand>
<ExpandedItem>glyphs</ExpandedItem>
</Expand>
<DisplayString Condition="occupied == 0">(empty)</DisplayString>
<DisplayString Condition="occupied != 0">{glyphIndex}</DisplayString>
</Type>

<Type Name="Microsoft::Console::Render::Atlas::BackendD3D::AtlasFontFaceEntry">
<DisplayString Condition="!inner._Mypair._Myval2">(empty)</DisplayString>
<DisplayString Condition="inner._Mypair._Myval2">{*inner._Mypair._Myval2}</DisplayString>
<DisplayString Condition="!fontFace.m_ptr">(empty)</DisplayString>
<DisplayString Condition="fontFace.m_ptr">{*fontFace.m_ptr}</DisplayString>
<Expand>
<ExpandedItem>*inner._Mypair._Myval2</ExpandedItem>
<Item Name="Single Width" ExcludeView="simple">glyphs[0]</Item>
<Item Name="Double Width" ExcludeView="simple">glyphs[1]</Item>
<Item Name="Double Height Top" ExcludeView="simple">glyphs[2]</Item>
<Item Name="Double Height Bottom" ExcludeView="simple">glyphs[3]</Item>
</Expand>
</Type>
</AutoVisualizer>

0 comments on commit 8d67477

Please sign in to comment.