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

AtlasEngine: Fix LRU state after scrolling #13607

Merged
2 commits merged into from
Jul 27, 2022
Merged
Changes from 1 commit
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
28 changes: 18 additions & 10 deletions src/renderer/atlas/AtlasEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,15 @@ try
{
const auto nothingInvalid = _api.invalidatedRows.x == _api.invalidatedRows.y;
const auto offset = static_cast<ptrdiff_t>(_api.scrollOffset) * _api.cellCount.x;
const auto data = _r.cells.data();
auto count = _r.cells.size();
#pragma warning(suppress : 26494) // Variable 'dst' is uninitialized. Always initialize an object (type.5).
Cell* dst;
#pragma warning(suppress : 26494) // Variable 'src' is uninitialized. Always initialize an object (type.5).
Cell* src;
ptrdiff_t srcOffset = 0;
ptrdiff_t dstOffset = 0;

if (_api.scrollOffset < 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the whole screen (or more!) is scrolled at once?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 313 clamps the scrollOffset to the viewport height. That way it's impossible for us to subtract more from count than there are rows in the viewport.
In other words: If we scroll the entire viewport, we're left with a count of 0 and nothing gets moved (and all rows are marked as invalid).

{
// Scroll up (for instance when new text is being written at the end of the buffer).
dst = data;
src = data - offset;
srcOffset = -offset;
dstOffset = 0;
count += offset;

const u16 endRow = _api.cellCount.y + _api.scrollOffset;
Expand All @@ -339,15 +336,26 @@ try
else
{
// Scroll down.
dst = data + offset;
src = data;
srcOffset = 0;
dstOffset = offset;
count -= offset;

_api.invalidatedRows.x = 0;
_api.invalidatedRows.y = nothingInvalid ? _api.scrollOffset : std::max<u16>(_api.invalidatedRows.y, _api.scrollOffset);
}

memmove(dst, src, count * sizeof(Cell));
{
const auto beg = _r.cells.begin();
const auto src = beg + srcOffset;
const auto dst = beg + dstOffset;
std::move(src, src + count, dst);
}
{
const auto beg = _r.cellGlyphMapping.begin();
const auto src = beg + srcOffset;
const auto dst = beg + dstOffset;
std::move(src, src + count, dst);
}
}
}

Expand Down