:: commit a06652f51198d34cf3254c62da593b91e6b19778

Mintsuki <mintsuki@protonmail.com> — 2026-03-30 17:38

parents: c443a62a12

Revert "lib/fb: Remove fb_clear()"

This reverts commit 75f777e7f030dc98e2ae060816ffd7dbd1a248a8.
diff --git a/common/drivers/gop.c b/common/drivers/gop.c
index 1aada7fa..a66e6ffe 100644
--- a/common/drivers/gop.c
+++ b/common/drivers/gop.c
@@ -178,6 +178,8 @@ static bool try_mode(struct fb_info *ret, EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
 
     ret->framebuffer_addr = gop->Mode->FrameBufferBase;
 
+    fb_clear(ret);
+
     return true;
 }
 
diff --git a/common/drivers/vbe.c b/common/drivers/vbe.c
index f9177c77..735d16bf 100644
--- a/common/drivers/vbe.c
+++ b/common/drivers/vbe.c
@@ -343,6 +343,8 @@ retry:
                 continue;
             }
 
+            fb_clear(ret);
+
             return true;
         }
     }
diff --git a/common/lib/fb.c b/common/lib/fb.c
index 8aa051af..38ec277d 100644
--- a/common/lib/fb.c
+++ b/common/lib/fb.c
@@ -34,6 +34,41 @@ void fb_init(struct fb_info **ret, size_t *_fbs_count,
     fb_fbs_count = *_fbs_count;
 }
 
+void fb_clear(struct fb_info *fb) {
+    for (size_t y = 0; y < fb->framebuffer_height; y++) {
+        switch (fb->framebuffer_bpp) {
+            case 32: {
+                uint32_t *fbp = (void *)(uintptr_t)fb->framebuffer_addr;
+                size_t row = (y * fb->framebuffer_pitch) / 4;
+                for (size_t x = 0; x < fb->framebuffer_width; x++) {
+                    fbp[row + x] = 0;
+                }
+                break;
+            }
+            case 16: {
+                uint16_t *fbp = (void *)(uintptr_t)fb->framebuffer_addr;
+                size_t row = (y * fb->framebuffer_pitch) / 2;
+                for (size_t x = 0; x < fb->framebuffer_width; x++) {
+                    fbp[row + x] = 0;
+                }
+                break;
+            }
+            default: {
+                uint8_t *fbp = (void *)(uintptr_t)fb->framebuffer_addr;
+                size_t row = y * fb->framebuffer_pitch;
+                size_t row_bytes = fb->framebuffer_width * (fb->framebuffer_bpp / 8);
+                for (size_t x = 0; x < row_bytes; x++) {
+                    fbp[row + x] = 0;
+                }
+                break;
+            }
+        }
+    }
+
+    fb_flush((volatile void *)(uintptr_t)fb->framebuffer_addr,
+             (size_t)fb->framebuffer_pitch * fb->framebuffer_height);
+}
+
 #if defined (__x86_64__) || defined (__i386__)
 static void fb_flush_x86(volatile void *base, size_t length) {
     static size_t clsz = 0;
diff --git a/common/lib/fb.h b/common/lib/fb.h
index 01e28839..b34c6e1a 100644
--- a/common/lib/fb.h
+++ b/common/lib/fb.h
@@ -38,6 +38,8 @@ extern size_t fb_fbs_count;
 void fb_init(struct fb_info **ret, size_t *_fbs_count,
              uint64_t target_width, uint64_t target_height, uint16_t target_bpp);
 
+void fb_clear(struct fb_info *fb);
+
 void fb_flush(volatile void *base, size_t length);
 
 #endif
tab: 248 wrap: offon