From 8d67477a1a1b6d26669736057f4ef2f318400ac8 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Fri, 26 Apr 2024 13:20:21 +0200 Subject: [PATCH] AtlasEngine: Improve debuggability (#17136) This is some test code and natvis fixes that I used to trace down an issue during font rendering. --- src/renderer/atlas/BackendD3D.cpp | 35 ++++++++++++++++++++++++++++++- tools/ConsoleTypes.natvis | 22 ++++++++----------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/renderer/atlas/BackendD3D.cpp b/src/renderer/atlas/BackendD3D.cpp index d6fb766f336..43b636336ae 100644 --- a/src/renderer/atlas/BackendD3D.cpp +++ b/src/renderer/atlas/BackendD3D.cpp @@ -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, @@ -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 paths; + + UINT32 numberOfFiles; + THROW_IF_FAILED(fontFaceEntry.fontFace->GetFiles(&numberOfFiles, nullptr)); + wil::com_ptr fontFiles[8]; + THROW_IF_FAILED(fontFaceEntry.fontFace->GetFiles(&numberOfFiles, fontFiles[0].addressof())); + + for (UINT32 i = 0; i < numberOfFiles; ++i) + { + wil::com_ptr 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()) + { + 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; diff --git a/tools/ConsoleTypes.natvis b/tools/ConsoleTypes.natvis index fa1975e3e48..855fcad1fba 100644 --- a/tools/ConsoleTypes.natvis +++ b/tools/ConsoleTypes.natvis @@ -124,7 +124,7 @@ - {{ size={_load / $T2} }} + {{ size={_load / $T3} }} _capacity @@ -161,22 +161,18 @@ - (empty) - {glyphIndex} - - - - {(void*)fontFace.m_ptr}, {lineRendition} - - glyphs - + (empty) + {glyphIndex} - (empty) - {*inner._Mypair._Myval2} + (empty) + {*fontFace.m_ptr} - *inner._Mypair._Myval2 + glyphs[0] + glyphs[1] + glyphs[2] + glyphs[3]