[Spice-devel] [RFCv5 05/47] server/red_worker: introduce {display, cursor}_is_connected

Alon Levy alevy at redhat.com
Sun May 8 06:11:01 PDT 2011


Instead of checking for worker->{display,cursor}_channel directly.
---
 server/red_worker.c |   55 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/server/red_worker.c b/server/red_worker.c
index b99927e..4c6da6b 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -1173,9 +1173,21 @@ static inline void red_handle_drawable_surfaces_client_synced(RedWorker *worker,
     red_add_surface_image(worker, drawable->surface_id);
 }
 
+static int display_is_connected(RedWorker *worker)
+{
+    return (worker->display_channel && red_channel_is_connected(
+        &worker->display_channel->common.base));
+}
+
+static int cursor_is_connected(RedWorker *worker)
+{
+    return (worker->cursor_channel && red_channel_is_connected(
+        &worker->cursor_channel->common.base));
+}
+
 static inline void red_pipe_add_drawable(RedWorker *worker, Drawable *drawable)
 {
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
 
@@ -1187,7 +1199,7 @@ static inline void red_pipe_add_drawable(RedWorker *worker, Drawable *drawable)
 
 static inline void red_pipe_add_drawable_to_tail(RedWorker *worker, Drawable *drawable)
 {
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
     drawable->refs++;
@@ -1197,7 +1209,7 @@ static inline void red_pipe_add_drawable_to_tail(RedWorker *worker, Drawable *dr
 static inline void red_pipe_add_drawable_after(RedWorker *worker, Drawable *drawable,
                                                Drawable *pos_after)
 {
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
 
@@ -1211,7 +1223,7 @@ static inline void red_pipe_add_drawable_after(RedWorker *worker, Drawable *draw
 
 static inline PipeItem *red_pipe_get_tail(RedWorker *worker)
 {
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return NULL;
     }
 
@@ -1231,7 +1243,7 @@ static inline void red_pipe_remove_drawable(RedWorker *worker, Drawable *drawabl
 
 static inline void red_pipe_add_image_item(RedWorker *worker, ImageItem *item)
 {
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
     item->refs++;
@@ -1241,7 +1253,7 @@ static inline void red_pipe_add_image_item(RedWorker *worker, ImageItem *item)
 static inline void red_pipe_add_image_item_after(RedWorker *worker, ImageItem *item,
                                                  PipeItem *pos)
 {
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
     item->refs++;
@@ -1349,7 +1361,7 @@ static inline void red_destroy_surface_item(RedWorker *worker, uint32_t surface_
     SurfaceDestroyItem *destroy;
     RedChannel *channel;
 
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
     worker->display_channel->surface_client_created[surface_id] = FALSE;
@@ -1664,7 +1676,7 @@ static void red_clear_surface_drawables_from_pipe(RedWorker *worker, int surface
     PipeItem *item;
     int x;
 
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
 
@@ -2272,11 +2284,11 @@ static void red_detach_streams_behind(RedWorker *worker, QRegion *region)
 
 static void red_streams_update_clip(RedWorker *worker, Drawable *drawable)
 {
-    DisplayChannel *channel;
+    DisplayChannel *channel = worker->display_channel;
     Ring *ring;
     RingItem *item;
 
-    if (!(channel = worker->display_channel)) {
+    if (!display_is_connected(worker)) {
         return;
     }
 
@@ -2547,7 +2559,7 @@ static inline void pre_stream_item_swap(RedWorker *worker, Stream *stream)
 {
     ASSERT(stream->current);
 
-    if (!worker->display_channel || !IS_LOW_BANDWIDTH()) {
+    if (!display_is_connected(worker) || !IS_LOW_BANDWIDTH()) {
         return;
     }
 
@@ -4126,9 +4138,16 @@ static CursorItem *get_cursor_item(RedWorker *worker, RedCursorCmd *cmd, uint32_
 
 static void qxl_process_cursor(RedWorker *worker, RedCursorCmd *cursor_cmd, uint32_t group_id)
 {
-    CursorItem *item = get_cursor_item(worker, cursor_cmd, group_id);
+    CursorItem *item;
     int cursor_show = FALSE;
 
+    if (!cursor_is_connected(worker)) {
+        red_put_cursor_cmd(cursor_cmd);
+        free(cursor_cmd);
+        return;
+    }
+    item = get_cursor_item(worker, cursor_cmd, group_id);
+
     switch (cursor_cmd->type) {
     case QXL_CURSOR_SET:
         worker->cursor_visible = cursor_cmd->u.set.visible;
@@ -4174,7 +4193,7 @@ static int red_process_cursor(RedWorker *worker, uint32_t max_pipe_size, int *ri
     int n = 0;
 
     *ring_is_empty = FALSE;
-    while (!worker->cursor_channel || worker->cursor_channel->common.base.pipe_size <= max_pipe_size) {
+    while (!cursor_is_connected(worker) || worker->cursor_channel->common.base.pipe_size <= max_pipe_size) {
         if (!worker->qxl->st->qif->get_cursor_command(worker->qxl, &ext_cmd)) {
             *ring_is_empty = TRUE;
             if (worker->repoll_cursor_ring < CMD_RING_POLL_RETRIES) {
@@ -4214,7 +4233,7 @@ static int red_process_commands(RedWorker *worker, uint32_t max_pipe_size, int *
     uint64_t start = red_now();
     
     *ring_is_empty = FALSE;
-    while (!worker->display_channel || worker->display_channel->common.base.pipe_size <= max_pipe_size) {
+    while (!display_is_connected(worker) || worker->display_channel->common.base.pipe_size <= max_pipe_size) {
         if (!worker->qxl->st->qif->get_command(worker->qxl, &ext_cmd)) {
             *ring_is_empty = TRUE;;
             if (worker->repoll_cmd_ring < CMD_RING_POLL_RETRIES) {
@@ -4392,7 +4411,7 @@ static void red_add_surface_image(RedWorker *worker, int surface_id)
 
     surface = &worker->surfaces[surface_id];
 
-    if (!worker->display_channel || !surface->context.canvas) {
+    if (!display_is_connected(worker) || !surface->context.canvas) {
         return;
     }
 
@@ -8406,7 +8425,7 @@ static inline void __red_create_surface_item(RedWorker *worker, int surface_id,
     RedSurface *surface;
     SurfaceCreateItem *create;
 
-    if (!worker->display_channel) {
+    if (!display_is_connected(worker)) {
         return;
     }
 
@@ -8507,7 +8526,7 @@ static inline void flush_display_commands(RedWorker *worker)
         int sleep_count = 0;
         for (;;) {
             red_channel_push(&worker->display_channel->common.base);
-            if (!worker->display_channel ||
+            if (!display_is_connected(worker) ||
                  worker->display_channel->common.base.pipe_size <= MAX_PIPE_SIZE) {
                 break;
             }
@@ -8551,7 +8570,7 @@ static inline void flush_cursor_commands(RedWorker *worker)
         int sleep_count = 0;
         for (;;) {
             red_channel_push(&worker->cursor_channel->common.base);
-            if (!worker->cursor_channel ||
+            if (!cursor_is_connected(worker) ||
                                         worker->cursor_channel->common.base.pipe_size <= MAX_PIPE_SIZE) {
                 break;
             }
-- 
1.7.5.1



More information about the Spice-devel mailing list