Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip DX invalidation if we've already scrolled an entire screen worth of height #6922

Merged
3 commits merged into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ IExplorer
IMap
IObject
IStorage
llabs
LCID
LSHIFT
NCHITTEST
Expand Down
46 changes: 35 additions & 11 deletions src/renderer/dx/DxRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ DxEngine::DxEngine() :
_invalidateFullRows{ true },
_invalidMap{},
_invalidScroll{},
_allInvalid{ false },
_firstFrame{ true },
_presentParams{ 0 },
_presentReady{ false },
Expand Down Expand Up @@ -847,6 +848,11 @@ void DxEngine::_InvalidateRectangle(const til::rectangle& rc)
_invalidMap.set(invalidate);
}

bool DxEngine::_IsAllInvalid() const noexcept
{
return std::llabs(_invalidScroll.y()) >= _invalidMap.size().height();
}

// Routine Description:
// - Invalidates a rectangle described in characters
// Arguments:
Expand All @@ -858,7 +864,10 @@ try
{
RETURN_HR_IF_NULL(E_INVALIDARG, psrRegion);

_InvalidateRectangle(Viewport::FromExclusive(*psrRegion).ToInclusive());
if (!_allInvalid)
{
_InvalidateRectangle(Viewport::FromExclusive(*psrRegion).ToInclusive());
}

return S_OK;
}
Expand All @@ -875,7 +884,10 @@ try
{
RETURN_HR_IF_NULL(E_INVALIDARG, pcoordCursor);

_InvalidateRectangle(til::rectangle{ *pcoordCursor, til::size{ 1, 1 } });
if (!_allInvalid)
{
_InvalidateRectangle(til::rectangle{ *pcoordCursor, til::size{ 1, 1 } });
}

return S_OK;
}
Expand All @@ -892,9 +904,12 @@ try
{
RETURN_HR_IF_NULL(E_INVALIDARG, prcDirtyClient);

// Dirty client is in pixels. Use divide specialization against glyph factor to make conversion
// to cells.
_InvalidateRectangle(til::rectangle{ *prcDirtyClient }.scale_down(_glyphCell));
if (!_allInvalid)
{
// Dirty client is in pixels. Use divide specialization against glyph factor to make conversion
// to cells.
_InvalidateRectangle(til::rectangle{ *prcDirtyClient }.scale_down(_glyphCell));
}

return S_OK;
}
Expand All @@ -908,9 +923,12 @@ CATCH_RETURN();
// - S_OK
[[nodiscard]] HRESULT DxEngine::InvalidateSelection(const std::vector<SMALL_RECT>& rectangles) noexcept
{
for (const auto& rect : rectangles)
if (!_allInvalid)
{
RETURN_IF_FAILED(Invalidate(&rect));
for (const auto& rect : rectangles)
{
RETURN_IF_FAILED(Invalidate(&rect));
}
}
return S_OK;
}
Expand All @@ -930,11 +948,15 @@ try

const til::point deltaCells{ *pcoordDelta };

if (deltaCells != til::point{ 0, 0 })
if (!_allInvalid)
{
// Shift the contents of the map and fill in revealed area.
_invalidMap.translate(deltaCells, true);
_invalidScroll += deltaCells;
if (deltaCells != til::point{ 0, 0 })
{
// Shift the contents of the map and fill in revealed area.
_invalidMap.translate(deltaCells, true);
_invalidScroll += deltaCells;
_allInvalid = _IsAllInvalid();
}
}

return S_OK;
Expand All @@ -951,6 +973,7 @@ CATCH_RETURN();
try
{
_invalidMap.set_all();
_allInvalid = true;

// Since everything is invalidated here, mark this as a "first frame", so
// that we won't use incremental drawing on it. The caller of this intended
Expand Down Expand Up @@ -1209,6 +1232,7 @@ try
}

_invalidMap.reset_all();
_allInvalid = false;

_invalidScroll = {};

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/dx/DxRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ namespace Microsoft::Console::Render
bool _invalidateFullRows;
til::bitmap _invalidMap;
til::point _invalidScroll;
bool _allInvalid;

bool _presentReady;
std::vector<RECT> _presentDirty;
Expand Down Expand Up @@ -271,6 +272,7 @@ namespace Microsoft::Console::Render
[[nodiscard]] til::size _GetClientSize() const;

void _InvalidateRectangle(const til::rectangle& rc);
bool _IsAllInvalid() const noexcept;

[[nodiscard]] D2D1_COLOR_F _ColorFFromColorRef(const COLORREF color) noexcept;

Expand Down