From 964d343903481062cc70354d0f35d7e96e640e94 Mon Sep 17 00:00:00 2001 From: DokiDokiPB <20497934+a1091150@users.noreply.github.com> Date: Thu, 31 Oct 2024 14:58:32 +0800 Subject: [PATCH] Fix memory region in framebuffer and pan display The width of a screen may be different to the virtual resolution. If the virtual screen size is set, `xoffset` and `yoffset` should be set as well. `FBIOPAN_DISPLAY` is used to update these setting. The same setting may not be applied on different hardware. --- backend/fbdev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/fbdev.c b/backend/fbdev.c index eb50cd1..f43d611 100644 --- a/backend/fbdev.c +++ b/backend/fbdev.c @@ -56,9 +56,8 @@ 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(uint32_t))); + off_t off = sizeof(uint32_t) * left + top * tx->fb_fix.line_length; + uint32_t *dest = (uint32_t *) ((uintptr_t) tx->fb_base + off); memcpy(dest, pixels, width * sizeof(uint32_t)); } @@ -105,6 +104,11 @@ static bool twin_fbdev_apply_config(twin_fbdev_t *tx) return false; } + /* Set if the xoffset and yoffset are changed */ + tx->fb_var.xoffset = 0; + tx->fb_var.yoffset = 0; + ioctl(tx->fb_fd, FBIOPAN_DISPLAY, &tx->fb_var); + /* Read changable information of the framebuffer again */ if (ioctl(tx->fb_fd, FBIOGET_VSCREENINFO, &tx->fb_var) < 0) { log_error("Failed to get framebuffer information");