Kernel: Optimize VTTY cursor rendering
cursor is now only updated once after all consecutive `putchar`s are handled.
This commit is contained in:
@@ -215,6 +215,7 @@ namespace Kernel
|
||||
auto* ptr = reinterpret_cast<const uint8_t*>(ansi_c_str);
|
||||
while (*ptr)
|
||||
handle_input_byte(*ptr++);
|
||||
update_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +359,7 @@ namespace Kernel
|
||||
SpinLockGuard _(m_write_lock);
|
||||
for (size_t i = 0; i < buffer.size(); i++)
|
||||
putchar(buffer[i]);
|
||||
update_cursor();
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
@@ -366,6 +368,7 @@ namespace Kernel
|
||||
ASSERT(s_tty);
|
||||
SpinLockGuard _(s_tty->m_write_lock);
|
||||
s_tty->putchar(ch);
|
||||
s_tty->update_cursor();
|
||||
}
|
||||
|
||||
bool TTY::is_initialized()
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace Kernel
|
||||
case 'l':
|
||||
if (m_ansi_state.question && m_ansi_state.nums[0] == 25)
|
||||
{
|
||||
m_terminal_driver->set_cursor_shown(ch == 'h');
|
||||
m_cursor_shown = (ch == 'h');
|
||||
return reset_ansi();
|
||||
}
|
||||
reset_ansi();
|
||||
@@ -518,8 +518,21 @@ namespace Kernel
|
||||
}
|
||||
|
||||
putcodepoint(codepoint);
|
||||
}
|
||||
|
||||
m_terminal_driver->set_cursor_position(m_column, m_row);
|
||||
void VirtualTTY::update_cursor()
|
||||
{
|
||||
static bool last_shown = !m_cursor_shown;
|
||||
if (m_cursor_shown != last_shown)
|
||||
m_terminal_driver->set_cursor_shown(m_cursor_shown);
|
||||
last_shown = m_cursor_shown;
|
||||
|
||||
static uint32_t last_column = -1;
|
||||
static uint32_t last_row = -1;
|
||||
if (last_column != m_column || last_row != m_row)
|
||||
m_terminal_driver->set_cursor_position(m_column, m_row);
|
||||
last_column = m_column;
|
||||
last_row = m_row;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user