Rather than needing to call red_drawable_new() and then initialize it with red_get_drawable(), we can improve slightly red_drawable new so that red_drawable_{new,ref,unref} is all which is used by code out of red-parse-qxl.c. Signed-off-by: Christophe Fergeau <cfergeau@xxxxxxxxxx> --- server/red-parse-qxl.c | 17 ++++++++++++----- server/red-parse-qxl.h | 8 +++----- server/red-worker.c | 11 ++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/server/red-parse-qxl.c b/server/red-parse-qxl.c index 341d050d1..a705c0d9d 100644 --- a/server/red-parse-qxl.c +++ b/server/red-parse-qxl.c @@ -1175,8 +1175,8 @@ static bool red_get_compat_drawable(RedMemSlotInfo *slots, int group_id, return true; } -bool red_get_drawable(RedMemSlotInfo *slots, int group_id, - RedDrawable *red, QXLPHYSICAL addr, uint32_t flags) +static bool red_get_drawable(RedMemSlotInfo *slots, int group_id, + RedDrawable *red, QXLPHYSICAL addr, uint32_t flags) { bool ret; @@ -1188,7 +1188,7 @@ bool red_get_drawable(RedMemSlotInfo *slots, int group_id, return ret; } -void red_put_drawable(RedDrawable *red) +static void red_put_drawable(RedDrawable *red) { red_put_clip(&red->clip); if (red->self_bitmap_image) { @@ -1497,12 +1497,19 @@ void red_drawable_unref(RedDrawable *red_drawable) g_free(red_drawable); } -RedDrawable *red_drawable_new(QXLInstance *qxl) +RedDrawable *red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots, + int group_id, QXLPHYSICAL addr, + uint32_t flags) { - RedDrawable * red = g_new0(RedDrawable, 1); + RedDrawable *red = g_new0(RedDrawable, 1); red->refs = 1; red->qxl = qxl; + if (!red_get_drawable(slots, group_id, red, addr, flags)) { + red_drawable_unref(red); + return NULL; + } + return red; } diff --git a/server/red-parse-qxl.h b/server/red-parse-qxl.h index 3b815a860..cbb880192 100644 --- a/server/red-parse-qxl.h +++ b/server/red-parse-qxl.h @@ -110,14 +110,12 @@ typedef struct RedCursorCmd { void red_get_rect_ptr(SpiceRect *red, const QXLRect *qxl); -RedDrawable *red_drawable_new(QXLInstance *qxl); +RedDrawable *red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots, + int group_id, QXLPHYSICAL addr, + uint32_t flags); RedDrawable *red_drawable_ref(RedDrawable *drawable); void red_drawable_unref(RedDrawable *red_drawable); -bool red_get_drawable(RedMemSlotInfo *slots, int group_id, - RedDrawable *red, QXLPHYSICAL addr, uint32_t flags); -void red_put_drawable(RedDrawable *red); - bool red_get_update_cmd(RedMemSlotInfo *slots, int group_id, RedUpdateCmd *red, QXLPHYSICAL addr); void red_put_update_cmd(RedUpdateCmd *red); diff --git a/server/red-worker.c b/server/red-worker.c index 8f806e8e3..ebc6d423d 100644 --- a/server/red-worker.c +++ b/server/red-worker.c @@ -205,15 +205,16 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty) worker->display_poll_tries = 0; switch (ext_cmd.cmd.type) { case QXL_CMD_DRAW: { - RedDrawable *red_drawable = red_drawable_new(worker->qxl); // returns with 1 ref + RedDrawable *red_drawable; + red_drawable = red_drawable_new(worker->qxl, &worker->mem_slots, + ext_cmd.group_id, ext_cmd.cmd.data, + ext_cmd.flags); // returns with 1 ref - if (red_get_drawable(&worker->mem_slots, ext_cmd.group_id, - red_drawable, ext_cmd.cmd.data, ext_cmd.flags)) { + if (red_drawable != NULL) { display_channel_process_draw(worker->display_channel, red_drawable, worker->process_display_generation); + red_drawable_unref(red_drawable); } - // release the red_drawable - red_drawable_unref(red_drawable); break; } case QXL_CMD_UPDATE: { -- 2.14.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel