Skip to content

Commit

Permalink
AtlasEngine: Implement remaining underlines and builtin glyphs for D2D (
Browse files Browse the repository at this point in the history
#17278)

This implements builtin glyphs for our Direct2D renderer, as well as
dashed and curly underlines. With this in place the only two features
it doesn't support are inverted cursors and VT soft fonts.
This allows us to remove the `_hack*` members introduced in a6a0e44.

The implementation of dashed underlines is trivial, while curly
underlines use quadratic bezier curves. Caching the curve as a sprite
is possible, however I feel like that can be done in the future.

Builtin glyphs on the other hand require a cache, because otherwise
filling the entire viewport with shaded glyphs would result in poor
performance. This is why it's built on top of `ID2D1SpriteBatch`.
Unfortunately the API causes an eager flush of other pending graphics
instructions, which is why there's still a decent perf hit.

Finally, as a little extra, this fixes the rounded powerline glyph
shapes being slightly cut off. The fix is to simply don't round the
position and radius of the ellipsis/semi-circle.

Closes #17224

## Validation Steps Performed
* RenderingTests.exe updated ✅
* All supported builtin glyphs look sorta right at different sizes ✅
  • Loading branch information
lhecker committed May 16, 2024
1 parent 183a895 commit 3486111
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 160 deletions.
14 changes: 3 additions & 11 deletions src/renderer/atlas/AtlasEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ try
_handleSettingsUpdate();
}

if (ATLAS_DEBUG_DISABLE_PARTIAL_INVALIDATION || _hackTriggerRedrawAll)
if constexpr (ATLAS_DEBUG_DISABLE_PARTIAL_INVALIDATION)
{
_hackTriggerRedrawAll = false;
_api.invalidatedRows = invalidatedRowsAll;
_api.scrollOffset = 0;
}
Expand Down Expand Up @@ -703,8 +702,6 @@ void AtlasEngine::_recreateFontDependentResources()
_api.textFormatAxes[i] = { fontAxisValues.data(), fontAxisValues.size() };
}
}

_hackWantsBuiltinGlyphs = _p.s->font->builtinGlyphs && !_hackIsBackendD2D;
}

void AtlasEngine::_recreateCellCountDependentResources()
Expand Down Expand Up @@ -765,18 +762,13 @@ void AtlasEngine::_flushBufferLine()
// This would seriously blow us up otherwise.
Expects(_api.bufferLineColumn.size() == _api.bufferLine.size() + 1);

const auto builtinGlyphs = _p.s->font->builtinGlyphs;
const auto beg = _api.bufferLine.data();
const auto len = _api.bufferLine.size();
size_t segmentBeg = 0;
size_t segmentEnd = 0;
bool custom = false;

if (!_hackWantsBuiltinGlyphs)
{
_mapRegularText(0, len);
return;
}

while (segmentBeg < len)
{
segmentEnd = segmentBeg;
Expand All @@ -789,7 +781,7 @@ void AtlasEngine::_flushBufferLine()
codepoint = til::combine_surrogates(codepoint, beg[i++]);
}

const auto c = BuiltinGlyphs::IsBuiltinGlyph(codepoint) || BuiltinGlyphs::IsSoftFontChar(codepoint);
const auto c = (builtinGlyphs && BuiltinGlyphs::IsBuiltinGlyph(codepoint)) || BuiltinGlyphs::IsSoftFontChar(codepoint);
if (custom != c)
{
break;
Expand Down
12 changes: 0 additions & 12 deletions src/renderer/atlas/AtlasEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ namespace Microsoft::Console::Render::Atlas
std::unique_ptr<IBackend> _b;
RenderingPayload _p;

// _p.s->font->builtinGlyphs is the setting which decides whether we should map box drawing glyphs to
// our own builtin versions. There's just one problem: BackendD2D doesn't have this functionality.
// But since AtlasEngine shapes the text before it's handed to the backends, it would need to know
// whether BackendD2D is in use, before BackendD2D even exists. These two flags solve the issue
// by triggering a complete, immediate redraw whenever the backend type changes.
//
// The proper solution is to move text shaping into the backends.
// Someone just needs to write a generic "TextBuffer to DWRITE_GLYPH_RUN" function.
bool _hackIsBackendD2D = false;
bool _hackWantsBuiltinGlyphs = true;
bool _hackTriggerRedrawAll = false;

struct ApiState
{
GenerationalSettings s = DirtyGenerationalSettings();
Expand Down
8 changes: 1 addition & 7 deletions src/renderer/atlas/AtlasEngine.r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CATCH_RETURN()

[[nodiscard]] bool AtlasEngine::RequiresContinuousRedraw() noexcept
{
return ATLAS_DEBUG_CONTINUOUS_REDRAW || (_b && _b->RequiresContinuousRedraw()) || _hackTriggerRedrawAll;
return ATLAS_DEBUG_CONTINUOUS_REDRAW || (_b && _b->RequiresContinuousRedraw());
}

void AtlasEngine::WaitUntilCanRender() noexcept
Expand Down Expand Up @@ -282,21 +282,15 @@ void AtlasEngine::_recreateBackend()
{
case GraphicsAPI::Direct2D:
_b = std::make_unique<BackendD2D>();
_hackIsBackendD2D = true;
break;
default:
_b = std::make_unique<BackendD3D>(_p);
_hackIsBackendD2D = false;
break;
}

// This ensures that the backends redraw their entire viewports whenever a new swap chain is created,
// EVEN IF we got called when no actual settings changed (i.e. rendering failure, etc.).
_p.MarkAllAsDirty();

const auto hackWantsBuiltinGlyphs = _p.s->font->builtinGlyphs && !_hackIsBackendD2D;
_hackTriggerRedrawAll = _hackWantsBuiltinGlyphs != hackWantsBuiltinGlyphs;
_hackWantsBuiltinGlyphs = hackWantsBuiltinGlyphs;
}

void AtlasEngine::_handleSwapChainUpdate()
Expand Down

0 comments on commit 3486111

Please sign in to comment.