diff options
author | elfmz <fenix1905@tut.by> | 2022-08-28 12:59:25 +0300 |
---|---|---|
committer | elfmz <fenix1905@tut.by> | 2022-08-28 12:59:25 +0300 |
commit | 890c4d6163b723434bd72afc57c51bfd98586d86 (patch) | |
tree | 87f98f90b76918279c475fa587787377972f89fc | |
parent | 1b132ecd847f435ba67a87b37a66a04991df1895 (diff) |
some more optimizations for unstable width lines
-rw-r--r-- | WinPort/src/Backend/TTY/TTYBackend.cpp | 54 | ||||
-rw-r--r-- | WinPort/src/Backend/TTY/TTYBackend.h | 1 |
2 files changed, 34 insertions, 21 deletions
diff --git a/WinPort/src/Backend/TTY/TTYBackend.cpp b/WinPort/src/Backend/TTY/TTYBackend.cpp index fc4af976..3919e175 100644 --- a/WinPort/src/Backend/TTY/TTYBackend.cpp +++ b/WinPort/src/Backend/TTY/TTYBackend.cpp @@ -420,12 +420,6 @@ void TTYBackend::DispatchOutput(TTYOutput &tty_out) const CHAR_INFO *cur_line = &_cur_output[y * _cur_width]; const CHAR_INFO *prev_line = &_prev_output[y * _prev_width]; - const auto UnstableWidth = [&](unsigned int x_) - { - return IsUnstableWidthCharCached(cur_line[x_].Char.UnicodeChar) - || IsUnstableWidthCharCached(prev_line[x_].Char.UnicodeChar); - }; - const auto ApproxWeight = [&](unsigned int x_) { return ((cur_line[x_].Char.UnicodeChar > 0x7f) ? 2 : 1); @@ -437,22 +431,45 @@ void TTYBackend::DispatchOutput(TTYOutput &tty_out) || cur_line[x_].Attributes != prev_line[x_].Attributes); }; + const auto WriteLineDebugColored = [&](const CHAR_INFO *line, unsigned int cnt, WORD attrs) + { +#if 0 // change to 1 to see affected lines as yellow/green on black + std::vector<CHAR_INFO> tmp_line(cnt); + for (unsigned int i = 0; i < cnt; ++i) { + tmp_line[i].Char.UnicodeChar = line[i].Char.UnicodeChar; + tmp_line[i].Attributes = attrs; + } + tty_out.WriteLine(tmp_line.data(), cnt); +#else + tty_out.WriteLine(line, cnt); +#endif + }; + + if (!_far2l_tty) { // If some characters at line 'special' - like fullwidth or diacric then need // to write whole line til the end to avoid artifacts on non-far2l terminals. // Also need to do same if previous line had such special characters as they // could wrap around to next (i.e. current) line. - bool unstable = false, modified = false; + bool unstable_cur = false, unstable_prev = false, modified = false; for (unsigned int x = 0; x < _cur_width; ++x) { - if (x + 1 < _cur_width && UnstableWidth(x)) { - unstable = true; + if (x + 1 < _cur_width) { + if (IsUnstableWidthCharCached(cur_line[x].Char.UnicodeChar)) { + unstable_cur = true; + } + if (IsUnstableWidthCharCached(prev_line[x].Char.UnicodeChar)) { + unstable_prev = true; + } } if (Modified(x)) { modified = true; } } - if (unstable && modified) { + if (!modified) { + continue; + } + if (unstable_cur) { bool prev_simple = false; for (unsigned int chunk_x = 0, x = 0; x <= _cur_width; ++x) { const bool cur_simple = (x < _cur_width) @@ -460,24 +477,19 @@ void TTYBackend::DispatchOutput(TTYOutput &tty_out) && (WCHAR_IS_PSEUDOGRAPHIC(prev_line[x].Char.UnicodeChar) || prev_line[x].Char.UnicodeChar < 0x7f); if (cur_simple != prev_simple || x == _cur_width) { tty_out.MoveCursorStrict(y + 1, chunk_x + 1); -#if 0 // change to 1 to see affected lines as green on black - std::vector<CHAR_INFO> tmp_line(x - chunk_x); - memcpy(tmp_line.data(), &cur_line[chunk_x], (x - chunk_x) * sizeof(CHAR_INFO)); - for (auto &ci : tmp_line) { - ci.Attributes = FOREGROUND_GREEN | FOREGROUND_INTENSITY; - } - tty_out.WriteLine(tmp_line.data(), x - chunk_x); -#else - tty_out.WriteLine(&cur_line[chunk_x], x - chunk_x); -#endif + WriteLineDebugColored(&cur_line[chunk_x], (x - chunk_x), + FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); prev_simple = cur_simple; chunk_x = x; } } continue; } - if (!modified) + if (unstable_prev) { + tty_out.MoveCursorStrict(y + 1, 1); + WriteLineDebugColored(cur_line, _cur_width, FOREGROUND_GREEN | FOREGROUND_INTENSITY); continue; + } } for (unsigned int x = 0, skipped_start = 0, skipped_weight = 0; x < _cur_width; ++x) { diff --git a/WinPort/src/Backend/TTY/TTYBackend.h b/WinPort/src/Backend/TTY/TTYBackend.h index cf0f70c6..e8918e6b 100644 --- a/WinPort/src/Backend/TTY/TTYBackend.h +++ b/WinPort/src/Backend/TTY/TTYBackend.h @@ -88,6 +88,7 @@ class TTYBackend : IConsoleOutputBackend, ITTYInputSpecialSequenceHandler, IFar2 ClipboardBackendSetter _clipboard_backend_setter; bool IsUnstableWidthCharCached(wchar_t c); + void WriteLineDebugColored(TTYOutput &tty_out, const CHAR_INFO *line, unsigned int cnt, WORD attrs); void DispatchTermResized(TTYOutput &tty_out); void DispatchOutput(TTYOutput &tty_out); |