Kernel: Respect actual framebuffer pitch

Instead of winging it with "width * 4", use the actual pitch since it
may be different.

This makes the kernel text console show up in native 1368x768 on my
ThinkPad X250. :^)
This commit is contained in:
Andreas Kling 2022-03-01 17:15:47 +01:00
parent e65ff4b8d1
commit 884ebc42b1
Notes: sideshowbarker 2024-07-17 18:05:41 +09:00
2 changed files with 11 additions and 10 deletions

View file

@ -226,10 +226,10 @@ void GenericFramebufferConsoleImpl::clear(size_t x, size_t y, size_t length)
{ {
if (x == 0 && length == max_column()) { if (x == 0 && length == max_column()) {
// if we need to clear the entire row, just clean it with quick memset :) // if we need to clear the entire row, just clean it with quick memset :)
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * sizeof(u32) * width()]; auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * framebuffer_pitch()];
for (size_t current_x = 0; current_x < 8; current_x++) { for (size_t current_x = 0; current_x < 8; current_x++) {
memset(offset_in_framebuffer, 0, width() * sizeof(u32)); memset(offset_in_framebuffer, 0, framebuffer_pitch());
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + width() * 4); offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
} }
flush(0, 8 * y, 8 * length, 1); flush(0, 8 * y, 8 * length, 1);
return; return;
@ -241,10 +241,10 @@ void GenericFramebufferConsoleImpl::clear(size_t x, size_t y, size_t length)
if (y >= max_row()) if (y >= max_row())
y = 0; y = 0;
} }
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * sizeof(u32) * width()]; auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * framebuffer_pitch()];
for (size_t current_x = 0; current_x < 8; current_x++) { for (size_t current_x = 0; current_x < 8; current_x++) {
memset(offset_in_framebuffer, 0, 8 * sizeof(u32)); memset(offset_in_framebuffer, 0, 8 * sizeof(u32));
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + width() * sizeof(u32)); offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
} }
flush(8 * x, 8 * y, 8, 8); flush(8 * x, 8 * y, 8, 8);
} }
@ -252,17 +252,17 @@ void GenericFramebufferConsoleImpl::clear(size_t x, size_t y, size_t length)
void GenericFramebufferConsoleImpl::clear_glyph(size_t x, size_t y) void GenericFramebufferConsoleImpl::clear_glyph(size_t x, size_t y)
{ {
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * sizeof(u32) * width()]; auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * framebuffer_pitch()];
for (size_t current_x = 0; current_x < 8; current_x++) { for (size_t current_x = 0; current_x < 8; current_x++) {
memset(offset_in_framebuffer, 0, 8 * sizeof(u32)); memset(offset_in_framebuffer, 0, 8 * sizeof(u32));
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + width() * sizeof(u32)); offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
} }
flush(8 * x, 8 * y, 8, 8); flush(8 * x, 8 * y, 8, 8);
} }
void GenericFramebufferConsoleImpl::enable() void GenericFramebufferConsoleImpl::enable()
{ {
memset(framebuffer_data(), 0, height() * width() * sizeof(u32)); memset(framebuffer_data(), 0, height() * framebuffer_pitch());
m_enabled.store(true); m_enabled.store(true);
} }
@ -291,7 +291,7 @@ void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, Color bac
return; return;
} }
clear_glyph(x, y); clear_glyph(x, y);
auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * sizeof(u32) * width()]; auto* offset_in_framebuffer = (u32*)&framebuffer_data()[x * sizeof(u32) * 8 + y * 8 * framebuffer_pitch()];
int current_bitpixels = 0; int current_bitpixels = 0;
int current_bitpixel = 0; int current_bitpixel = 0;
auto bitmap = font8x8_basic[(int)ch]; auto bitmap = font8x8_basic[(int)ch];
@ -307,7 +307,7 @@ void GenericFramebufferConsoleImpl::write(size_t x, size_t y, char ch, Color bac
offset_in_framebuffer[current_bitpixel] = background_color; offset_in_framebuffer[current_bitpixel] = background_color;
} }
} }
offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + width() * 4); offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
} }
flush(8 * x, 8 * y, 8, 8); flush(8 * x, 8 * y, 8, 8);
m_x = x + 1; m_x = x + 1;

View file

@ -45,6 +45,7 @@ protected:
{ {
} }
virtual u8* framebuffer_data() = 0; virtual u8* framebuffer_data() = 0;
size_t framebuffer_pitch() const { return m_pitch; }
virtual void clear_glyph(size_t x, size_t y); virtual void clear_glyph(size_t x, size_t y);
size_t m_pitch; size_t m_pitch;
}; };