Kernel/Console: Factor out framebuffer offset and support glyph_spacing

This allows the 9px width of Cathode to be preserved without increasing
the bitmap size.
This commit is contained in:
MacDue 2022-06-08 11:15:30 +01:00 committed by Andreas Kling
parent adef79b793
commit 805a3d5b29
Notes: sideshowbarker 2024-07-17 10:54:57 +09:00
2 changed files with 26 additions and 14 deletions

View file

@ -219,9 +219,14 @@ void GenericFramebufferConsoleImpl::set_cursor(size_t x, size_t y)
show_cursor();
}
u32* GenericFramebufferConsoleImpl::framebuffer_offset(size_t x, size_t y)
{
return reinterpret_cast<u32*>(&framebuffer_data()[x * sizeof(u32) * (m_pixels_per_column + m_glyph_spacing) + y * m_pixels_per_row * framebuffer_pitch()]);
}
void GenericFramebufferConsoleImpl::hide_cursor()
{
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[m_x * sizeof(u32) * m_pixels_per_column + m_y * m_pixels_per_row * framebuffer_pitch()];
auto* offset_in_framebuffer = framebuffer_offset(m_x, m_y);
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch() * 15);
for (size_t current_x = 0; current_x < m_pixels_per_column; current_x++) {
offset_in_framebuffer[current_x] = m_cursor_overriden_pixels[current_x];
@ -230,7 +235,7 @@ void GenericFramebufferConsoleImpl::hide_cursor()
void GenericFramebufferConsoleImpl::show_cursor()
{
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[m_x * sizeof(u32) * m_pixels_per_column + m_y * m_pixels_per_row * framebuffer_pitch()];
auto* offset_in_framebuffer = framebuffer_offset(m_x, m_y);
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch() * 15);
for (size_t current_x = 0; current_x < m_pixels_per_column; current_x++) {
m_cursor_overriden_pixels[current_x] = offset_in_framebuffer[current_x];
@ -242,12 +247,12 @@ void GenericFramebufferConsoleImpl::clear(size_t x, size_t y, size_t length)
{
if (x == 0 && length == max_column()) {
// if we need to clear the entire row, just clean it with quick memset :)
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * m_pixels_per_column + y * m_pixels_per_row * framebuffer_pitch()];
auto* offset_in_framebuffer = framebuffer_offset(x, y);
for (size_t current_x = 0; current_x < m_pixels_per_row; current_x++) {
memset(offset_in_framebuffer, 0, framebuffer_pitch());
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
}
flush(0, m_pixels_per_row * y, m_pixels_per_column * length, 1);
flush(0, m_pixels_per_row * y, (m_pixels_per_column + m_glyph_spacing) * length, 1);
return;
}
for (size_t index = 0; index < length; index++) {
@ -257,23 +262,23 @@ void GenericFramebufferConsoleImpl::clear(size_t x, size_t y, size_t length)
if (y >= max_row())
y = 0;
}
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * m_pixels_per_column + y * m_pixels_per_row * framebuffer_pitch()];
auto* offset_in_framebuffer = framebuffer_offset(x, y);
for (size_t current_x = 0; current_x < m_pixels_per_row; current_x++) {
memset(offset_in_framebuffer, 0, m_pixels_per_column * sizeof(u32));
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
}
flush(m_pixels_per_column * x, m_pixels_per_row * y, m_pixels_per_column, m_pixels_per_row);
flush_glyph(x, y);
}
}
void GenericFramebufferConsoleImpl::clear_glyph(size_t x, size_t y)
{
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * m_pixels_per_column + y * m_pixels_per_row * framebuffer_pitch()];
auto* offset_in_framebuffer = framebuffer_offset(x, y);
for (size_t current_x = 0; current_x < m_pixels_per_row; current_x++) {
memset(offset_in_framebuffer, 0, m_pixels_per_column * sizeof(u32));
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
}
flush(m_pixels_per_column * x, m_pixels_per_row * y, m_pixels_per_column, m_pixels_per_row);
flush_glyph(x, y);
}
void GenericFramebufferConsoleImpl::enable()
@ -307,7 +312,7 @@ void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, Color bac
return;
}
clear_glyph(x, y);
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * m_pixels_per_column + y * m_pixels_per_row * framebuffer_pitch()];
auto* offset_in_framebuffer = framebuffer_offset(x, y);
size_t current_bitpixels = 0;
size_t current_bitpixel = 0;
auto bitmap = font_cathode_8x16[(int)ch];
@ -317,15 +322,14 @@ void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, Color bac
for (current_bitpixels = 0; current_bitpixels < m_pixels_per_row; current_bitpixels++) {
for (current_bitpixel = m_pixels_per_column; current_bitpixel > 0; current_bitpixel--) {
set = bitmap[current_bitpixels] & (1 << current_bitpixel);
if (set) {
if (set)
offset_in_framebuffer[m_pixels_per_column - current_bitpixel] = foreground_color;
} else {
else
offset_in_framebuffer[m_pixels_per_column - current_bitpixel] = background_color;
}
}
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
}
flush(m_pixels_per_column * x, m_pixels_per_row * y, m_pixels_per_column, m_pixels_per_row);
flush_glyph(x, y);
m_x = x + 1;
if (m_x >= max_column()) {
m_x = 0;
@ -335,6 +339,11 @@ void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, Color bac
}
}
void GenericFramebufferConsoleImpl::flush_glyph(size_t x, size_t y)
{
flush((m_pixels_per_column + m_glyph_spacing) * x, m_pixels_per_row * y, m_pixels_per_column + m_glyph_spacing, m_pixels_per_row);
}
void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, bool critical)
{
write(x, y, ch, m_default_background_color, m_default_foreground_color, critical);

View file

@ -18,7 +18,7 @@ public:
virtual size_t bytes_per_base_glyph() const override;
virtual size_t chars_per_line() const override;
virtual size_t max_column() const override { return m_width / m_pixels_per_column; }
virtual size_t max_column() const override { return m_width / (m_pixels_per_column + m_glyph_spacing); }
virtual size_t max_row() const override { return m_height / m_pixels_per_row; }
virtual bool is_hardware_paged_capable() const override { return false; }
@ -48,7 +48,10 @@ protected:
virtual u8* framebuffer_data() = 0;
size_t framebuffer_pitch() const { return m_pitch; }
virtual void clear_glyph(size_t x, size_t y);
u32* framebuffer_offset(size_t x, size_t y);
void flush_glyph(size_t x, size_t y);
size_t const m_glyph_spacing { 1 };
size_t const m_pixels_per_column { 8 };
size_t const m_pixels_per_row { 16 };