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 the fix for LRU state after scrolling #13784

Merged
1 commit merged into from
Aug 19, 2022
Merged
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
56 changes: 33 additions & 23 deletions src/renderer/atlas/AtlasEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <shader_ps.h>
#include <shader_vs.h>

#include "../base/FontCache.h"
#include "../../interactivity/win32/CustomWindowMessages.h"

// #### NOTE ####
Expand Down Expand Up @@ -192,42 +191,53 @@ try
const auto nothingInvalid = _api.invalidatedRows.x == _api.invalidatedRows.y;
const auto offset = static_cast<ptrdiff_t>(_api.scrollOffset) * _api.cellCount.x;
auto count = _r.cells.size();
ptrdiff_t srcOffset = 0;
ptrdiff_t dstOffset = 0;

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

const u16 endRow = _api.cellCount.y + _api.scrollOffset;
_api.invalidatedRows.x = nothingInvalid ? endRow : std::min<u16>(_api.invalidatedRows.x, endRow);
_api.invalidatedRows.y = _api.cellCount.y;

// scrollOffset/offset = -1
// +----------+ +----------+
// | | | xxxxxxxxx| + dst < beg
// | xxxxxxxxx| -> |xxxxxxx | + src | < beg - offset
// |xxxxxxx | | | | v
// +----------+ +----------+ v < end
{
const auto beg = _r.cells.begin();
const auto end = beg + count;
std::move(beg - offset, end, beg);
}
{
const auto beg = _r.cellGlyphMapping.begin();
const auto end = beg + count;
std::move(beg - offset, end, beg);
}
}
else
{
// Scroll down.
srcOffset = 0;
dstOffset = offset;
count -= offset;

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

{
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);
// scrollOffset/offset = 1
// +----------+ +----------+
// | xxxxxxxxx| | | + src < beg
// |xxxxxxx | -> | xxxxxxxxx| | ^
// | | |xxxxxxx | v | < end - offset
// +----------+ +----------+ + dst < end
{
const auto beg = _r.cells.begin();
const auto end = beg + count;
std::move_backward(beg, end - offset, end);
}
{
const auto beg = _r.cellGlyphMapping.begin();
const auto end = beg + count;
std::move_backward(beg, end - offset, end);
}
}
}
}
Expand Down