mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 06:32:44 +00:00
red-parse-qxl: Use a base reference class for RedUpdateCmd
Don't code manually reference counting for this structure Signed-off-by: Frediano Ziglio <freddy77@gmail.com> Acked-by: Victor Toso <victortoso@redhat.com>
This commit is contained in:
parent
45f2d94ac3
commit
110b97e51e
@ -1295,45 +1295,26 @@ static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void red_put_update_cmd(RedUpdateCmd *red)
|
||||
RedUpdateCmd::~RedUpdateCmd()
|
||||
{
|
||||
if (red->qxl != nullptr) {
|
||||
red_qxl_release_resource(red->qxl, red->release_info_ext);
|
||||
if (qxl != nullptr) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
|
||||
RedUpdateCmd *red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
int group_id, QXLPHYSICAL addr)
|
||||
red::shared_ptr<const RedUpdateCmd>
|
||||
red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
int group_id, QXLPHYSICAL addr)
|
||||
{
|
||||
RedUpdateCmd *red;
|
||||
auto red = red::make_shared<RedUpdateCmd>();
|
||||
|
||||
red = g_new0(RedUpdateCmd, 1);
|
||||
|
||||
red->refs = 1;
|
||||
|
||||
if (!red_get_update_cmd(qxl, slots, group_id, red, addr)) {
|
||||
red_update_cmd_unref(red);
|
||||
return nullptr;
|
||||
if (!red_get_update_cmd(qxl, slots, group_id, red.get(), addr)) {
|
||||
red.reset();
|
||||
}
|
||||
|
||||
return red;
|
||||
}
|
||||
|
||||
RedUpdateCmd *red_update_cmd_ref(RedUpdateCmd *red)
|
||||
{
|
||||
red->refs++;
|
||||
return red;
|
||||
}
|
||||
|
||||
void red_update_cmd_unref(RedUpdateCmd *red)
|
||||
{
|
||||
if (--red->refs) {
|
||||
return;
|
||||
}
|
||||
red_put_update_cmd(red);
|
||||
g_free(red);
|
||||
}
|
||||
|
||||
static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, int group_id,
|
||||
RedMessage *red, QXLPHYSICAL addr)
|
||||
{
|
||||
|
||||
@ -62,14 +62,14 @@ typedef struct RedDrawable {
|
||||
} u;
|
||||
} RedDrawable;
|
||||
|
||||
typedef struct RedUpdateCmd {
|
||||
struct RedUpdateCmd final: public red::simple_ptr_counted<RedUpdateCmd> {
|
||||
~RedUpdateCmd();
|
||||
QXLInstance *qxl;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
int refs;
|
||||
SpiceRect area;
|
||||
uint32_t update_id;
|
||||
uint32_t surface_id;
|
||||
} RedUpdateCmd;
|
||||
};
|
||||
|
||||
struct RedMessage final: public red::simple_ptr_counted<RedMessage> {
|
||||
~RedMessage();
|
||||
@ -126,10 +126,9 @@ RedDrawable *red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
RedDrawable *red_drawable_ref(RedDrawable *drawable);
|
||||
void red_drawable_unref(RedDrawable *red_drawable);
|
||||
|
||||
RedUpdateCmd *red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
int group_id, QXLPHYSICAL addr);
|
||||
RedUpdateCmd *red_update_cmd_ref(RedUpdateCmd *red);
|
||||
void red_update_cmd_unref(RedUpdateCmd *red);
|
||||
red::shared_ptr<const RedUpdateCmd>
|
||||
red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
int group_id, QXLPHYSICAL addr);
|
||||
|
||||
red::shared_ptr<const RedMessage>
|
||||
red_message_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
|
||||
@ -204,11 +204,9 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
|
||||
break;
|
||||
}
|
||||
case QXL_CMD_UPDATE: {
|
||||
RedUpdateCmd *update;
|
||||
|
||||
update = red_update_cmd_new(worker->qxl, &worker->mem_slots,
|
||||
ext_cmd.group_id, ext_cmd.cmd.data);
|
||||
if (update == nullptr) {
|
||||
auto update = red_update_cmd_new(worker->qxl, &worker->mem_slots,
|
||||
ext_cmd.group_id, ext_cmd.cmd.data);
|
||||
if (!update) {
|
||||
break;
|
||||
}
|
||||
if (!display_channel_validate_surface(worker->display_channel, update->surface_id)) {
|
||||
@ -217,7 +215,6 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
|
||||
display_channel_draw(worker->display_channel, &update->area, update->surface_id);
|
||||
red_qxl_notify_update(worker->qxl, update->update_id);
|
||||
}
|
||||
red_update_cmd_unref(update);
|
||||
break;
|
||||
}
|
||||
case QXL_CMD_MESSAGE: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user