From e4e0e70e35e9805ff3c3cea8422bb13af4618dd3 Mon Sep 17 00:00:00 2001 From: DokiDokiPB <20497934+a1091150@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:18:11 +0800 Subject: [PATCH] Fix memory region in framebuffer (#65) If screen size is less than virtual resolution, it will draw multiple screens on display. Use 'line_length' for calculation instead of screen size. Changeable information like virtual resolution or virtual terminal settings may not apply across different hardware and drivers. e.g., on VirtualBox, virtual resolution is 2048x2048, visible resolution is 800x600, and line length is 2048 * 4. Any settings from guest machine to these may be ignored. --- backend/fbdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/fbdev.c b/backend/fbdev.c index 210fa7b..e19b093 100644 --- a/backend/fbdev.c +++ b/backend/fbdev.c @@ -53,9 +53,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)); }