Compare commits

..

No commits in common. "703c1a485ce14ba0798179316118e917880afbea" and "7c6966a9c45a8a53f37d3c64c3b7333634ea234c" have entirely different histories.

6 changed files with 28 additions and 50 deletions

View File

@ -41,6 +41,7 @@ namespace Kernel
virtual uint32_t height() const = 0; virtual uint32_t height() const = 0;
virtual uint32_t width() const = 0; virtual uint32_t width() const = 0;
void putchar(uint8_t ch);
virtual dev_t rdev() const final override { return m_rdev; } virtual dev_t rdev() const final override { return m_rdev; }
@ -59,13 +60,10 @@ namespace Kernel
TTY(mode_t mode, uid_t uid, gid_t gid); TTY(mode_t mode, uid_t uid, gid_t gid);
virtual void putchar_impl(uint8_t ch) = 0; virtual void putchar_impl(uint8_t ch) = 0;
virtual void update_cursor() {}
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override; virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override; virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
private: private:
void putchar(uint8_t ch);
void do_backspace(); void do_backspace();
protected: protected:

View File

@ -24,7 +24,6 @@ namespace Kernel
protected: protected:
virtual BAN::StringView name() const override { return m_name; } virtual BAN::StringView name() const override { return m_name; }
virtual void putchar_impl(uint8_t ch) override; virtual void putchar_impl(uint8_t ch) override;
void update_cursor() override;
private: private:
VirtualTTY(BAN::RefPtr<TerminalDriver>); VirtualTTY(BAN::RefPtr<TerminalDriver>);
@ -79,7 +78,6 @@ namespace Kernel
uint32_t m_saved_row { 0 }; uint32_t m_saved_row { 0 };
uint32_t m_saved_column { 0 }; uint32_t m_saved_column { 0 };
bool m_cursor_shown { true };
uint32_t m_row { 0 }; uint32_t m_row { 0 };
uint32_t m_column { 0 }; uint32_t m_column { 0 };
Cell* m_buffer { nullptr }; Cell* m_buffer { nullptr };

View File

@ -64,9 +64,7 @@ namespace Kernel
const uint32_t indices_per_block = blksize() / sizeof(uint32_t); const uint32_t indices_per_block = blksize() / sizeof(uint32_t);
uint32_t divisor = 1; const uint32_t divisor = (depth > 1) ? indices_per_block * (depth - 1) : 1;
for (uint32_t i = 1; i < depth; i++)
divisor *= indices_per_block;
const uint32_t next_block = block_buffer.span().as_span<uint32_t>()[(index / divisor) % indices_per_block]; const uint32_t next_block = block_buffer.span().as_span<uint32_t>()[(index / divisor) % indices_per_block];
if (next_block == 0) if (next_block == 0)

View File

@ -19,8 +19,6 @@ namespace Kernel
{ {
const uint8_t* glyph = m_font.has_glyph(ch) ? m_font.glyph(ch) : m_font.glyph('?'); const uint8_t* glyph = m_font.has_glyph(ch) ? m_font.glyph(ch) : m_font.glyph('?');
const bool update_cursor = m_cursor_shown && x == m_cursor_x && y == m_cursor_y;
x *= m_font.width(); x *= m_font.width();
y *= m_font.height(); y *= m_font.height();
@ -36,18 +34,17 @@ namespace Kernel
m_framebuffer_device->sync_pixels_rectangle(x, y, m_font.width(), m_font.height()); m_framebuffer_device->sync_pixels_rectangle(x, y, m_font.width(), m_font.height());
if (update_cursor) if (x == m_cursor_x && y == m_cursor_y)
{
read_cursor();
show_cursor(false); show_cursor(false);
}
} }
bool FramebufferTerminalDriver::scroll(Color color) bool FramebufferTerminalDriver::scroll(Color color)
{ {
if (m_cursor_shown)
show_cursor(true);
m_framebuffer_device->scroll(m_font.height(), color.rgb); m_framebuffer_device->scroll(m_font.height(), color.rgb);
m_framebuffer_device->sync_pixels_full(); m_framebuffer_device->sync_pixels_full();
if (m_cursor_shown)
show_cursor(false);
return true; return true;
} }
@ -65,21 +62,25 @@ namespace Kernel
void FramebufferTerminalDriver::read_cursor() void FramebufferTerminalDriver::read_cursor()
{ {
const uint32_t cursor_h = m_font.height() / 8; const uint32_t cursor_h = m_font.height() / 8;
const uint32_t cursor_w = m_font.width();
const uint32_t cursor_top = m_font.height() * 13 / 16; const uint32_t cursor_top = m_font.height() * 13 / 16;
const uint32_t x = m_cursor_x * m_font.width(); const uint32_t x = m_cursor_x * m_font.width();
const uint32_t y = m_cursor_y * m_font.height(); const uint32_t y = m_cursor_y * m_font.height();
for (uint32_t dy = 0; dy < cursor_h; dy++) for (uint32_t dy = 0; dy < cursor_h; dy++)
for (uint32_t dx = 0; dx < cursor_w; dx++) for (uint32_t dx = 0; dx < m_font.width(); dx++)
m_cursor_data[dy * cursor_w + dx] = m_framebuffer_device->get_pixel(x + dx, y + cursor_top + dy); m_cursor_data[dy * m_font.width() + dx] = m_framebuffer_device->get_pixel(x + dx, y + cursor_top + dy);
} }
void FramebufferTerminalDriver::show_cursor(bool use_data) void FramebufferTerminalDriver::show_cursor(bool use_data)
{ {
if (!use_data) const auto get_color =
read_cursor(); [this, use_data](uint32_t x, uint32_t y) -> uint32_t
{
if (!use_data)
return m_cursor_color.rgb;
return m_cursor_data[y * m_font.width() + x];
};
const uint32_t cursor_h = m_font.height() / 8; const uint32_t cursor_h = m_font.height() / 8;
const uint32_t cursor_w = m_font.width(); const uint32_t cursor_w = m_font.width();
@ -88,14 +89,6 @@ namespace Kernel
const uint32_t x = m_cursor_x * m_font.width(); const uint32_t x = m_cursor_x * m_font.width();
const uint32_t y = m_cursor_y * m_font.height(); const uint32_t y = m_cursor_y * m_font.height();
const auto get_color =
[&](uint32_t x, uint32_t y) -> uint32_t
{
if (!use_data)
return m_cursor_color.rgb;
return m_cursor_data[y * cursor_w + x];
};
for (uint32_t dy = 0; dy < cursor_h; dy++) for (uint32_t dy = 0; dy < cursor_h; dy++)
for (uint32_t dx = 0; dx < cursor_w; dx++) for (uint32_t dx = 0; dx < cursor_w; dx++)
m_framebuffer_device->set_pixel(x + dx, y + cursor_top + dy, get_color(dx, dy)); m_framebuffer_device->set_pixel(x + dx, y + cursor_top + dy, get_color(dx, dy));
@ -107,14 +100,20 @@ namespace Kernel
if (m_cursor_shown == shown) if (m_cursor_shown == shown)
return; return;
m_cursor_shown = shown; m_cursor_shown = shown;
show_cursor(!m_cursor_shown);
if (m_cursor_shown)
{
read_cursor();
show_cursor(false);
}
else
{
show_cursor(true);
}
} }
void FramebufferTerminalDriver::set_cursor_position(uint32_t x, uint32_t y) void FramebufferTerminalDriver::set_cursor_position(uint32_t x, uint32_t y)
{ {
if (x == m_cursor_x && y == m_cursor_y)
return;
if (!m_cursor_shown) if (!m_cursor_shown)
{ {
m_cursor_x = x; m_cursor_x = x;
@ -125,6 +124,7 @@ namespace Kernel
show_cursor(true); show_cursor(true);
m_cursor_x = x; m_cursor_x = x;
m_cursor_y = y; m_cursor_y = y;
read_cursor();
show_cursor(false); show_cursor(false);
} }

View File

@ -215,7 +215,6 @@ namespace Kernel
auto* ptr = reinterpret_cast<const uint8_t*>(ansi_c_str); auto* ptr = reinterpret_cast<const uint8_t*>(ansi_c_str);
while (*ptr) while (*ptr)
handle_input_byte(*ptr++); handle_input_byte(*ptr++);
update_cursor();
} }
} }
@ -359,7 +358,6 @@ namespace Kernel
SpinLockGuard _(m_write_lock); SpinLockGuard _(m_write_lock);
for (size_t i = 0; i < buffer.size(); i++) for (size_t i = 0; i < buffer.size(); i++)
putchar(buffer[i]); putchar(buffer[i]);
update_cursor();
return buffer.size(); return buffer.size();
} }
@ -368,7 +366,6 @@ namespace Kernel
ASSERT(s_tty); ASSERT(s_tty);
SpinLockGuard _(s_tty->m_write_lock); SpinLockGuard _(s_tty->m_write_lock);
s_tty->putchar(ch); s_tty->putchar(ch);
s_tty->update_cursor();
} }
bool TTY::is_initialized() bool TTY::is_initialized()

View File

@ -357,7 +357,7 @@ namespace Kernel
case 'l': case 'l':
if (m_ansi_state.question && m_ansi_state.nums[0] == 25) if (m_ansi_state.question && m_ansi_state.nums[0] == 25)
{ {
m_cursor_shown = (ch == 'h'); m_terminal_driver->set_cursor_shown(ch == 'h');
return reset_ansi(); return reset_ansi();
} }
reset_ansi(); reset_ansi();
@ -518,21 +518,8 @@ namespace Kernel
} }
putcodepoint(codepoint); putcodepoint(codepoint);
}
void VirtualTTY::update_cursor() m_terminal_driver->set_cursor_position(m_column, m_row);
{
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;
} }
} }