From faa194f8f64d386d47e4c01957130f11a8fae58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Wed, 5 Jan 2022 12:35:39 +0100 Subject: [PATCH] vrend: Use the constants from the protocol to encode copy_transfer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This increases the code readability. Signed-off-by: Corentin Noël Reviewed-by: Gert Wollny --- src/vrend_decode.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/vrend_decode.c b/src/vrend_decode.c index 621cf0c..3bc5e16 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -1421,25 +1421,23 @@ static int vrend_decode_copy_transfer3d(struct vrend_context *ctx, const uint32_ uint32_t dst_handle; uint32_t src_handle; - memset(&info, 0, sizeof(info)); - info.box = &box; - if (length != VIRGL_COPY_TRANSFER3D_SIZE) return EINVAL; + memset(&info, 0, sizeof(info)); + info.box = &box; + // synchronized is set either to 1 or 0. This means that we can use other bits // to identify the direction of copy transfer uint32_t flags = get_buf_entry(buf, VIRGL_COPY_TRANSFER3D_FLAGS); - bool read_from_host = flags & (1 << 1); - bool synchronized = flags & (1 << 0); + bool read_from_host = (flags & VIRGL_COPY_TRANSFER3D_FLAGS_READ_FROM_HOST) != 0; + info.synchronized = (flags & VIRGL_COPY_TRANSFER3D_FLAGS_SYNCHRONIZED) != 0; if (!read_from_host) { // this means that guest would like to make transfer to host // it can also mean that guest is using legacy copy transfer path vrend_decode_transfer_common(buf, &dst_handle, &info); info.offset = get_buf_entry(buf, VIRGL_COPY_TRANSFER3D_SRC_RES_OFFSET); - info.synchronized = (synchronized != 0); - src_handle = get_buf_entry(buf, VIRGL_COPY_TRANSFER3D_SRC_RES_HANDLE); return vrend_renderer_copy_transfer3d(ctx, dst_handle, src_handle, @@ -1447,8 +1445,6 @@ static int vrend_decode_copy_transfer3d(struct vrend_context *ctx, const uint32_ } else { vrend_decode_transfer_common(buf, &src_handle, &info); info.offset = get_buf_entry(buf, VIRGL_COPY_TRANSFER3D_SRC_RES_OFFSET); - info.synchronized = (synchronized != 0); - dst_handle = get_buf_entry(buf, VIRGL_COPY_TRANSFER3D_SRC_RES_HANDLE); return vrend_renderer_copy_transfer3d_from_host(ctx, dst_handle, src_handle,