[Spice-devel] [spice-server v4 02/11] qxl: Make red_{get, put}_drawable static

Christophe Fergeau cfergeau at redhat.com
Thu Nov 29 12:50:04 UTC 2018


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.
---
 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 e1f547b7a..03a3a655a 100644
--- a/server/red-parse-qxl.c
+++ b/server/red-parse-qxl.c
@@ -1170,8 +1170,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;
 
@@ -1183,7 +1183,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) {
@@ -1486,12 +1486,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 d9ae792af..9168553db 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -198,15 +198,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.19.1



More information about the Spice-devel mailing list