mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-01-11 16:55:33 +00:00
qxl: Add red_message_{new, ref, unref} helpers
Currently, RedMessage are allocated on the stack, and then
initialized/uninitialized with red_{get,put}_message
This makes the API inconsistent with what is being done for RedDrawable
and RedCursor. Since QXLMessage is just a (mostly unused/unsecure) debugging tool,
we can dynamically allocate it instead, and get a consistent API.
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
60c425011c
commit
5840ba2a89
@ -1292,8 +1292,8 @@ void red_put_update_cmd(RedUpdateCmd *red)
|
||||
/* nothing yet */
|
||||
}
|
||||
|
||||
bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, int group_id,
|
||||
RedMessage *red, QXLPHYSICAL addr)
|
||||
static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, int group_id,
|
||||
RedMessage *red, QXLPHYSICAL addr)
|
||||
{
|
||||
QXLMessage *qxl;
|
||||
int memslot_id;
|
||||
@ -1325,13 +1325,45 @@ bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, int group
|
||||
return true;
|
||||
}
|
||||
|
||||
void red_put_message(RedMessage *red)
|
||||
static void red_put_message(RedMessage *red)
|
||||
{
|
||||
if (red->qxl != NULL) {
|
||||
red_qxl_release_resource(red->qxl, red->release_info_ext);
|
||||
}
|
||||
}
|
||||
|
||||
RedMessage *red_message_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
int group_id, QXLPHYSICAL addr)
|
||||
{
|
||||
RedMessage *red;
|
||||
|
||||
red = g_new0(RedMessage, 1);
|
||||
|
||||
red->refs = 1;
|
||||
|
||||
if (!red_get_message(qxl, slots, group_id, red, addr)) {
|
||||
red_message_unref(red);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return red;
|
||||
}
|
||||
|
||||
RedMessage *red_message_ref(RedMessage *red)
|
||||
{
|
||||
red->refs++;
|
||||
return red;
|
||||
}
|
||||
|
||||
void red_message_unref(RedMessage *red)
|
||||
{
|
||||
if (--red->refs) {
|
||||
return;
|
||||
}
|
||||
red_put_message(red);
|
||||
g_free(red);
|
||||
}
|
||||
|
||||
static unsigned int surface_format_to_bpp(uint32_t format)
|
||||
{
|
||||
switch (format) {
|
||||
|
||||
@ -69,6 +69,7 @@ typedef struct RedUpdateCmd {
|
||||
typedef struct RedMessage {
|
||||
QXLInstance *qxl;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
int refs;
|
||||
int len;
|
||||
uint8_t *data;
|
||||
} RedMessage;
|
||||
@ -122,9 +123,10 @@ bool red_get_update_cmd(RedMemSlotInfo *slots, int group_id,
|
||||
RedUpdateCmd *red, QXLPHYSICAL addr);
|
||||
void red_put_update_cmd(RedUpdateCmd *red);
|
||||
|
||||
bool red_get_message(QXLInstance *qxl, RedMemSlotInfo *slots, int group_id,
|
||||
RedMessage *red, QXLPHYSICAL addr);
|
||||
void red_put_message(RedMessage *red);
|
||||
RedMessage *red_message_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
int group_id, QXLPHYSICAL addr);
|
||||
RedMessage *red_message_ref(RedMessage *red);
|
||||
void red_message_unref(RedMessage *red);
|
||||
|
||||
bool red_validate_surface(uint32_t width, uint32_t height,
|
||||
int32_t stride, uint32_t format);
|
||||
|
||||
@ -230,16 +230,17 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
|
||||
break;
|
||||
}
|
||||
case QXL_CMD_MESSAGE: {
|
||||
RedMessage message;
|
||||
RedMessage *message;
|
||||
|
||||
if (!red_get_message(worker->qxl, &worker->mem_slots, ext_cmd.group_id,
|
||||
&message, ext_cmd.cmd.data)) {
|
||||
message = red_message_new(worker->qxl, &worker->mem_slots,
|
||||
ext_cmd.group_id, ext_cmd.cmd.data);
|
||||
if (message == NULL) {
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
spice_warning("MESSAGE: %.*s", message.len, message.data);
|
||||
#endif
|
||||
red_put_message(&message);
|
||||
red_message_unref(message);
|
||||
break;
|
||||
}
|
||||
case QXL_CMD_SURFACE:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user