Commit c333194bd3 for qemu.org
commit c333194bd3e51b893c306b9a3dce7ff7b8886fe8
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date: Fri Aug 21 11:44:46 2026 +0400
virtio-gpu: minor refactoring
Move disable_scanout() branch earlier, return early.
(scanout->resource_id is cleared there)
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 9ca7b946ac..439a6e1c1c 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -565,6 +565,8 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
+ struct virgl_renderer_resource_info info;
+ void *d3d_tex2d = NULL;
int ret;
VIRTIO_GPU_FILL_CMD(ss);
@@ -579,47 +581,46 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
}
g->parent_obj.enable = 1;
- if (ss.resource_id) {
- struct virgl_renderer_resource_info info;
- void *d3d_tex2d = NULL;
+ if (!ss.resource_id) {
+ virtio_gpu_disable_scanout(g, ss.scanout_id);
+ return;
+ }
#if VIRGL_VERSION_MAJOR >= 1
- struct virgl_renderer_resource_info_ext ext;
- memset(&ext, 0, sizeof(ext));
- ret = virgl_renderer_resource_get_info_ext(ss.resource_id, &ext);
- info = ext.base;
- d3d_tex2d = ext.d3d_tex2d;
+ struct virgl_renderer_resource_info_ext ext;
+ memset(&ext, 0, sizeof(ext));
+ ret = virgl_renderer_resource_get_info_ext(ss.resource_id, &ext);
+ info = ext.base;
+ d3d_tex2d = ext.d3d_tex2d;
#else
- memset(&info, 0, sizeof(info));
- ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
+ memset(&info, 0, sizeof(info));
+ ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
#endif
- if (ret) {
- qemu_log_mask(LOG_GUEST_ERROR,
- "%s: illegal resource specified %d\n",
- __func__, ss.resource_id);
- cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
- return;
- }
- if (!virtio_gpu_check_scanout_bounds(ss.scanout_id, ss.resource_id,
- info.width, info.height, &ss.r,
- &cmd->error)) {
- return;
- }
- virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id);
-
- qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con,
- ss.r.width, ss.r.height);
- virgl_renderer_force_ctx_0();
- qemu_console_gl_scanout_texture(
- g->parent_obj.scanout[ss.scanout_id].con, info.tex_id,
- info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
- info.width, info.height,
- ss.r.x, ss.r.y, ss.r.width, ss.r.height,
- d3d_tex2d);
- } else {
- virtio_gpu_disable_scanout(g, ss.scanout_id);
+ if (ret) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: illegal resource specified %d\n",
+ __func__, ss.resource_id);
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+ return;
}
+ if (!virtio_gpu_check_scanout_bounds(ss.scanout_id, ss.resource_id,
+ info.width, info.height, &ss.r,
+ &cmd->error)) {
+ return;
+ }
+
+ virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id);
+
+ qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con,
+ ss.r.width, ss.r.height);
+ virgl_renderer_force_ctx_0();
+ qemu_console_gl_scanout_texture(
+ g->parent_obj.scanout[ss.scanout_id].con, info.tex_id,
+ info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
+ info.width, info.height,
+ ss.r.x, ss.r.y, ss.r.width, ss.r.height,
+ d3d_tex2d);
g->parent_obj.scanout[ss.scanout_id].resource_id = ss.resource_id;
}