[PATCH] virtio-gpu: fix inverted mouse cursor

Benno Fünstück posted 1 patch 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260409144639.3610-1-benno.fuenfstueck@neodyme.io
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, "Michael S. Tsirkin" <mst@redhat.com>
hw/display/virtio-gpu-gl.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
[PATCH] virtio-gpu: fix inverted mouse cursor
Posted by Benno Fünstück 2 days ago
From: Benno Fünfstück <benno.fuenfstueck@neodyme.io>

When using virtio-gpu-gl, if the guest uses hardware mouse cursor acceleration then the mouse cursor can end up being a resource with the flag Y_0_TOP set. In this case, we need to make sure to flip the cursor data such that display clients render it correctly.

For example, this fixes mouse cursor rendering for wlroots-based window managers (like Sway) in Linux guests.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2315
Signed-off-by: Benno Fünfstück <benno.fuenfstueck@neodyme.io>
---
 hw/display/virtio-gpu-gl.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index 2b7a41c466..4562d3405e 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -33,6 +33,9 @@ static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
     VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
     uint32_t width, height;
     uint32_t pixels, *data;
+    bool y_0_top = true;
+    int ret;
+    struct virgl_renderer_resource_info info;
 
     if (gl->renderer_state != RS_INITED) {
         return;
@@ -49,8 +52,23 @@ static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
         return;
     }
 
+    memset(&info, 0, sizeof(info));
+    ret = virgl_renderer_resource_get_info(resource_id, &info);
+    if (ret == 0) {
+        y_0_top = info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
+    }
+
     pixels = s->current_cursor->width * s->current_cursor->height;
-    memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t));
+    if (y_0_top) {
+        memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t));
+    } else {
+        uint32_t *dst = s->current_cursor->data;
+        for (uint32_t y = 0; y < height; y++) {
+            memcpy(dst + y * width,
+                   data + (height - 1 - y) * width,
+                   width * sizeof(uint32_t));
+        }
+    }
     free(data);
 }
 
-- 
2.50.1 (Apple Git-155)


-- 
Neodyme AG
Sitz der Gesellschaft / Address: Dirnismaning 55 | Halle 13 | 
85748 Garching b.München
Postanschrift: ​Rosenthaler Straße 72a | ​10119 
Berlin

Registergericht / Registry court: München, HRB 269168
Vorstand / 
Management Board: Thomas Lambertz | Tobias Madl
Aufsichtsratsvorsitzender / 
Chairman of the Supervisory Board: Hendrik Hofstadt
Re: [PATCH] virtio-gpu: fix inverted mouse cursor
Posted by Akihiko Odaki 4 hours ago
On 2026/04/09 23:46, Benno Fünstück wrote:
> From: Benno Fünfstück <benno.fuenfstueck@neodyme.io>
> 
> When using virtio-gpu-gl, if the guest uses hardware mouse cursor acceleration then the mouse cursor can end up being a resource with the flag Y_0_TOP set. In this case, we need to make sure to flip the cursor data such that display clients render it correctly.
> 
> For example, this fixes mouse cursor rendering for wlroots-based window managers (like Sway) in Linux guests.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2315
> Signed-off-by: Benno Fünfstück <benno.fuenfstueck@neodyme.io>

Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Regards,
Akihiko Odaki