Forráskód Böngészése

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. :^)
Andreas Kling 3 éve
szülő
commit
884ebc42b1

+ 10 - 10
Kernel/Graphics/Console/GenericFramebufferConsole.cpp

@@ -226,10 +226,10 @@ 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) * 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++) {
-            memset(offset_in_framebuffer, 0, width() * sizeof(u32));
-            offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + width() * 4);
+            memset(offset_in_framebuffer, 0, framebuffer_pitch());
+            offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
         }
         flush(0, 8 * y, 8 * length, 1);
         return;
@@ -241,10 +241,10 @@ 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) * 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++) {
             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);
     }
@@ -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)
 {
-    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++) {
         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);
 }
 
 void GenericFramebufferConsoleImpl::enable()
 {
-    memset(framebuffer_data(), 0, height() * width() * sizeof(u32));
+    memset(framebuffer_data(), 0, height() * framebuffer_pitch());
     m_enabled.store(true);
 }
 
@@ -291,7 +291,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) * 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_bitpixel = 0;
     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 = (u32*)((u8*)offset_in_framebuffer + width() * 4);
+        offset_in_framebuffer = (u32*)((u8*)offset_in_framebuffer + framebuffer_pitch());
     }
     flush(8 * x, 8 * y, 8, 8);
     m_x = x + 1;

+ 1 - 0
Kernel/Graphics/Console/GenericFramebufferConsole.h

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