From 144ff6d275d6a4f3049bfd6165060b1574eb061b Mon Sep 17 00:00:00 2001 From: DokiDokiPB <20497934+a1091150@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:42:10 +0800 Subject: [PATCH] Fix memory region in framebuffer The size of the screen may be different to the virtual resolution. If the size is less than virtual resolution, it will draw multiple windows on display. Use `line_length` to calculate instead of the size of the screen. Changable information like virtual resoultion or setting different information on virtual terminal may not be applied on different hardware and driver. For example on VirtualBox, virtual resolution's width and height are 2048 and 2048, visible resolutions' are 800 and 600, and line length is 2048 * 4. Any setting from guest machine to these maybe ignored. --- backend/fbdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/fbdev.c b/backend/fbdev.c index d7fb08e..11c797e 100644 --- a/backend/fbdev.c +++ b/backend/fbdev.c @@ -56,9 +56,9 @@ static void _twin_fbdev_put_span(twin_coord_t left, return; twin_coord_t width = right - left; - off_t off = top * screen->width + left; - uint32_t *dest = - (uint32_t *) ((uintptr_t) tx->fb_base + (off * sizeof(*dest))); + uint32_t *dest; + off_t off = sizeof(*dest) * left + top * tx->fb_fix.line_length; + dest = (uint32_t *) ((uintptr_t) tx->fb_base + off); memcpy(dest, pixels, width * sizeof(*dest)); }