This allows to share a bit of code in red-parse-qxl.c, but does not help with reducing the number of args which are passed to the parsing functions. Signed-off-by: Christophe Fergeau <cfergeau@xxxxxxxxxx> --- server/red-parse-qxl.c | 112 ++++++++++++++++++++++++++----------------------- server/red-parse-qxl.h | 20 ++++----- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/server/red-parse-qxl.c b/server/red-parse-qxl.c index 9f24c841e..732eabcab 100644 --- a/server/red-parse-qxl.c +++ b/server/red-parse-qxl.c @@ -89,6 +89,35 @@ static inline uint32_t color_16_to_32(uint32_t color) return ret; } +static void * red_qxl_guest_resources_init(RedQXLGuestResources *guest_resources, + QXLInstance *qxl_instance, + RedMemSlotInfo *slots, + int group_id, + QXLPHYSICAL addr, + size_t size) +{ + int error; + void *red_data; + + red_data = (void *)memslot_get_virt(slots, addr, size, group_id, &error); + if (error) { + return NULL; + } + guest_resources->qxl = qxl_instance; + guest_resources->release_info_ext.group_id = group_id; + /* The 'release_info' field in QXL*Cmd is always the very first field */ + guest_resources->release_info_ext.info = red_data; + + return red_data; +} + +static void red_qxl_guest_resources_release(RedQXLGuestResources *guest_resources) +{ + if (guest_resources->qxl != NULL) { + red_qxl_release_resource(guest_resources->qxl, guest_resources->release_info_ext); + } +} + static uint8_t *red_linearize_chunk(RedDataChunk *head, size_t size, bool *free_chunk) { uint8_t *data, *ptr; @@ -1016,15 +1045,13 @@ static bool red_get_native_drawable(QXLInstance *qxl_instance, RedMemSlotInfo *s { QXLDrawable *qxl_drawable; int i; - int error = 0; - qxl_drawable = (QXLDrawable *)memslot_get_virt(slots, addr, sizeof(*qxl_drawable), group_id, &error); - if (error) { + qxl_drawable = red_qxl_guest_resources_init(&red_drawable->guest_resources, + qxl_instance, slots, group_id, + addr, sizeof(*qxl_drawable)); + if (qxl_drawable == NULL) { return false; } - red_drawable->qxl = qxl_instance; - red_drawable->release_info_ext.info = &qxl_drawable->release_info; - red_drawable->release_info_ext.group_id = group_id; red_get_rect_ptr(&red_drawable->bbox, &qxl_drawable->bbox); red_get_clip_ptr(slots, group_id, &red_drawable->clip, &qxl_drawable->clip); @@ -1097,15 +1124,13 @@ static bool red_get_compat_drawable(QXLInstance *qxl_instance, RedMemSlotInfo *s RedDrawable *red_drawable, QXLPHYSICAL addr, uint32_t flags) { QXLCompatDrawable *qxl_drawable; - int error; - qxl_drawable = (QXLCompatDrawable *)memslot_get_virt(slots, addr, sizeof(*qxl_drawable), group_id, &error); - if (error) { + qxl_drawable = red_qxl_guest_resources_init(&red_drawable->guest_resources, + qxl_instance, slots, group_id, + addr, sizeof(*qxl_drawable)); + if (qxl_drawable == NULL) { return false; } - red_drawable->qxl = qxl_instance; - red_drawable->release_info_ext.info = &qxl_drawable->release_info; - red_drawable->release_info_ext.group_id = group_id; red_get_rect_ptr(&red_drawable->bbox, &qxl_drawable->bbox); red_get_clip_ptr(slots, group_id, &red_drawable->clip, &qxl_drawable->clip); @@ -1237,24 +1262,20 @@ static void red_put_drawable(RedDrawable *red_drawable) red_put_whiteness(&red_drawable->u.whiteness); break; } - if (red_drawable->qxl != NULL) { - red_qxl_release_resource(red_drawable->qxl, red_drawable->release_info_ext); - } + red_qxl_guest_resources_release(&red_drawable->guest_resources); } static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots, int group_id, RedUpdateCmd *red_cmd, QXLPHYSICAL addr) { QXLUpdateCmd *qxl_cmd; - int error; - qxl_cmd = (QXLUpdateCmd *)memslot_get_virt(slots, addr, sizeof(*qxl_cmd), group_id, &error); - if (error) { + qxl_cmd = red_qxl_guest_resources_init(&red_cmd->guest_resources, + qxl_instance, slots, group_id, + addr, sizeof(*qxl_cmd)); + if (qxl_cmd == NULL) { return false; } - red_cmd->qxl = qxl_instance; - red_cmd->release_info_ext.info = &qxl_cmd->release_info; - red_cmd->release_info_ext.group_id = group_id; red_get_rect_ptr(&red_cmd->area, &qxl_cmd->area); red_cmd->update_id = qxl_cmd->update_id; @@ -1264,9 +1285,7 @@ static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots, static void red_put_update_cmd(RedUpdateCmd *red_cmd) { - if (red_cmd->qxl != NULL) { - red_qxl_release_resource(red_cmd->qxl, red_cmd->release_info_ext); - } + red_qxl_guest_resources_release(&red_cmd->guest_resources); } RedUpdateCmd *red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots, int group_id, QXLPHYSICAL addr) @@ -1304,7 +1323,6 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in RedMessage *red_message, QXLPHYSICAL addr) { QXLMessage *qxl_message; - int error; int memslot_id; unsigned long len; uint8_t *end; @@ -1315,14 +1333,14 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in * luckily this is for debug logging only, * so we can just ignore it by default. */ - qxl_message = (QXLMessage *)memslot_get_virt(slots, addr, sizeof(*qxl_message), group_id, &error); - if (error) { + //qxl_message = (QXLMessage *)memslot_get_virt(slots, addr, sizeof(*qxl_message), group_id, &error); + qxl_message = red_qxl_guest_resources_init(&red_message->guest_resources, + qxl_instance, slots, group_id, + addr, sizeof(*qxl_message)); + if (qxl_message == NULL) { return false; } - red_message->qxl = qxl_instance; - red_message->release_info_ext.info = &qxl_message->release_info; - red_message->release_info_ext.group_id = group_id; - red_message->data = qxl_message->data; + red_message->data = qxl_message->data; memslot_id = memslot_get_id(slots, addr+sizeof(*qxl_message)); len = memslot_max_size_virt(slots, ((intptr_t) qxl_message)+sizeof(*qxl_message), memslot_id, group_id); len = MIN(len, 100000); @@ -1336,9 +1354,7 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in static void red_put_message(RedMessage *red_message) { - if (red_message->qxl != NULL) { - red_qxl_release_resource(red_message->qxl, red_message->release_info_ext); - } + red_qxl_guest_resources_release(&red_message->guest_resources); } RedMessage *red_message_new(QXLInstance *qxl, RedMemSlotInfo *slots, int group_id, QXLPHYSICAL addr) @@ -1426,14 +1442,12 @@ static bool red_get_surface_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots uint64_t size; int error; - qxl_cmd = (QXLSurfaceCmd *)memslot_get_virt(slots, addr, sizeof(*qxl_cmd), group_id, - &error); - if (error) { + qxl_cmd = red_qxl_guest_resources_init(&red_cmd->guest_resources, + qxl_instance, slots, group_id, + addr, sizeof(*qxl_cmd)); + if (qxl_cmd == NULL) { return false; } - red_cmd->qxl = qxl_instance; - red_cmd->release_info_ext.info = &qxl_cmd->release_info; - red_cmd->release_info_ext.group_id = group_id; red_cmd->surface_id = qxl_cmd->surface_id; red_cmd->type = qxl_cmd->type; @@ -1464,9 +1478,7 @@ static bool red_get_surface_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots static void red_put_surface_cmd(RedSurfaceCmd *red_cmd) { - if (red_cmd->qxl) { - red_qxl_release_resource(red_cmd->qxl, red_cmd->release_info_ext); - } + red_qxl_guest_resources_release(&red_cmd->guest_resources); } RedSurfaceCmd *red_surface_cmd_new(QXLInstance *qxl_instance, RedMemSlotInfo *slots, @@ -1552,15 +1564,13 @@ static bool red_get_cursor_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots, QXLPHYSICAL addr) { QXLCursorCmd *qxl_cmd; - int error; - qxl_cmd = (QXLCursorCmd *)memslot_get_virt(slots, addr, sizeof(*qxl_cmd), group_id, &error); - if (error) { + qxl_cmd = red_qxl_guest_resources_init(&red_cmd->guest_resources, + qxl_instance, slots, group_id, + addr, sizeof(*qxl_cmd)); + if (qxl_cmd == NULL) { return false; } - red_cmd->qxl = qxl_instance; - red_cmd->release_info_ext.info = &qxl_cmd->release_info; - red_cmd->release_info_ext.group_id = group_id; red_cmd->type = qxl_cmd->type; switch (red_cmd->type) { @@ -1603,9 +1613,7 @@ static void red_put_cursor_cmd(RedCursorCmd *red_cmd) red_put_cursor(&red_cmd->u.set.shape); break; } - if (red_cmd->qxl) { - red_qxl_release_resource(red_cmd->qxl, red_cmd->release_info_ext); - } + red_qxl_guest_resources_release(&red_cmd->guest_resources); } RedCursorCmd *red_cursor_cmd_ref(RedCursorCmd *cmd) diff --git a/server/red-parse-qxl.h b/server/red-parse-qxl.h index 43ace663b..2f6af584d 100644 --- a/server/red-parse-qxl.h +++ b/server/red-parse-qxl.h @@ -24,10 +24,14 @@ #include "red-common.h" #include "memslot.h" +typedef struct { + QXLInstance *qxl; + QXLReleaseInfoExt release_info_ext; +} RedQXLGuestResources; + typedef struct RedDrawable { + RedQXLGuestResources guest_resources; int refs; - QXLInstance *qxl; - QXLReleaseInfoExt release_info_ext; uint32_t surface_id; uint8_t effect; uint8_t type; @@ -60,8 +64,7 @@ typedef struct RedDrawable { } RedDrawable; typedef struct RedUpdateCmd { - QXLInstance *qxl; - QXLReleaseInfoExt release_info_ext; + RedQXLGuestResources guest_resources; int refs; SpiceRect area; uint32_t update_id; @@ -69,8 +72,7 @@ typedef struct RedUpdateCmd { } RedUpdateCmd; typedef struct RedMessage { - QXLInstance *qxl; - QXLReleaseInfoExt release_info_ext; + RedQXLGuestResources guest_resources; int refs; int len; uint8_t *data; @@ -85,8 +87,7 @@ typedef struct RedSurfaceCreate { } RedSurfaceCreate; typedef struct RedSurfaceCmd { - QXLInstance *qxl; - QXLReleaseInfoExt release_info_ext; + RedQXLGuestResources guest_resources; int refs; uint32_t surface_id; uint8_t type; @@ -97,8 +98,7 @@ typedef struct RedSurfaceCmd { } RedSurfaceCmd; typedef struct RedCursorCmd { - QXLInstance *qxl; - QXLReleaseInfoExt release_info_ext; + RedQXLGuestResources guest_resources; int refs; uint8_t type; union { -- 2.14.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel