Move disable_scanout() branch earlier, return early. (scanout->resource_id is cleared there)
Signed-off-by: Marc-André Lureau <[email protected]> --- hw/display/virtio-gpu-virgl.c | 61 +++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 6cb9365a714f..e2ad27343da5 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -546,6 +546,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); @@ -560,10 +562,12 @@ 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)); @@ -574,33 +578,32 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, 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; } -- 2.55.0.543.g5ebe2ebe4ea8
