[Spice-commits] 4 commits - server/agent-msg-filter.c server/cursor-channel.c server/dcc.c server/dcc-send.c server/display-channel.c server/display-channel.h server/Makefile.am server/red-dispatcher.c server/red-dispatcher.h server/red-qxl.c server/red-qxl.h server/reds.c server/reds.h server/reds-private.h server/red-worker.c server/red-worker.h server/sound.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Fri Mar 4 15:49:51 UTC 2016


 server/Makefile.am        |    4 
 server/agent-msg-filter.c |    2 
 server/cursor-channel.c   |    2 
 server/dcc-send.c         |   17 
 server/dcc.c              |    4 
 server/display-channel.c  |    8 
 server/display-channel.h  |    2 
 server/red-dispatcher.c   | 1032 --------------------------------------------
 server/red-dispatcher.h   |  272 -----------
 server/red-qxl.c          | 1064 ++++++++++++++++++++++++++++++++++++++++++++++
 server/red-qxl.h          |  275 +++++++++++
 server/red-worker.c       |   55 +-
 server/red-worker.h       |    4 
 server/reds-private.h     |    2 
 server/reds.c             |   98 ++--
 server/reds.h             |   11 
 server/sound.c            |    2 
 17 files changed, 1438 insertions(+), 1416 deletions(-)

New commits:
commit 95fa8bfb13a6d43410cd5153efbf99eb1133b003
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Feb 25 22:58:19 2016 +0000

    worker: remove useless qxl_state
    
    qxl_state can be extracted easily from qxl.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/red-qxl.c b/server/red-qxl.c
index e9b8701..b24c6e5 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -974,9 +974,10 @@ void red_qxl_init(QXLInstance *qxl)
     qxl_state->base.loadvm_commands = qxl_worker_loadvm_commands;
 
     qxl_state->max_monitors = UINT_MAX;
+    qxl->st = qxl_state;
 
     // TODO: reference and free
-    RedWorker *worker = red_worker_new(qxl, qxl_state);
+    RedWorker *worker = red_worker_new(qxl);
 
     // TODO: move to their respective channel files
     channel = red_worker_get_cursor_channel(worker);
@@ -999,8 +1000,6 @@ void red_qxl_init(QXLInstance *qxl)
     reds_register_channel(reds, channel);
 
     red_worker_run(worker);
-
-    qxl->st = qxl_state;
 }
 
 struct Dispatcher *red_qxl_get_dispatcher(QXLState *qxl_state)
diff --git a/server/red-worker.c b/server/red-worker.c
index 6fb7865..0eb385a 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -60,7 +60,6 @@
 struct RedWorker {
     pthread_t thread;
     QXLInstance *qxl;
-    QXLState *qxl_state;
     SpiceWatch *dispatch_watch;
     int running;
     SpiceCoreInterfaceInternal core;
@@ -824,7 +823,7 @@ static void handle_dev_wakeup(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     stat_inc_counter(reds, worker->wakeup_counter, 1);
-    red_qxl_clear_pending(worker->qxl_state, RED_DISPATCHER_PENDING_WAKEUP);
+    red_qxl_clear_pending(worker->qxl->st, RED_DISPATCHER_PENDING_WAKEUP);
 }
 
 static void handle_dev_oom(void *opaque, void *payload)
@@ -854,7 +853,7 @@ static void handle_dev_oom(void *opaque, void *payload)
                 display->glz_drawable_count,
                 display->current_size,
                 red_channel_sum_pipes_size(display_red_channel));
-    red_qxl_clear_pending(worker->qxl_state, RED_DISPATCHER_PENDING_OOM);
+    red_qxl_clear_pending(worker->qxl->st, RED_DISPATCHER_PENDING_OOM);
 }
 
 static void handle_dev_reset_cursor(void *opaque, void *payload)
@@ -1195,7 +1194,7 @@ static void worker_handle_dispatcher_async_done(void *opaque,
     RedWorkerMessageAsync *msg_async = payload;
 
     spice_debug(NULL);
-    red_qxl_async_complete(worker->qxl_state, msg_async->cmd);
+    red_qxl_async_complete(worker->qxl->st, msg_async->cmd);
 }
 
 static void worker_dispatcher_record(void *opaque, uint32_t message_type, void *payload)
@@ -1463,7 +1462,7 @@ static GSourceFuncs worker_source_funcs = {
     .dispatch = worker_source_dispatch,
 };
 
-RedWorker* red_worker_new(QXLInstance *qxl, QXLState *qxl_state)
+RedWorker* red_worker_new(QXLInstance *qxl)
 {
     QXLDevInitInfo init_info;
     RedWorker *worker;
@@ -1488,10 +1487,9 @@ RedWorker* red_worker_new(QXLInstance *qxl, QXLState *qxl_state)
             spice_error("failed to write replay header");
         }
     }
-    dispatcher = red_qxl_get_dispatcher(qxl_state);
+    dispatcher = red_qxl_get_dispatcher(qxl->st);
     dispatcher_set_opaque(dispatcher, worker);
 
-    worker->qxl_state = qxl_state;
     worker->qxl = qxl;
     register_callbacks(dispatcher);
     if (worker->record_fd) {
diff --git a/server/red-worker.h b/server/red-worker.h
index 0f9cf61..c93f66c 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -90,7 +90,7 @@ static inline void red_pipes_add_verb(RedChannel *channel, uint16_t verb)
     }
 }
 
-RedWorker* red_worker_new(QXLInstance *qxl, QXLState *qxl_state);
+RedWorker* red_worker_new(QXLInstance *qxl);
 bool       red_worker_run(RedWorker *worker);
 RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
 RedChannel* red_worker_get_display_channel(RedWorker *worker);
commit e9ed125dbd4b9b5129252cab33ee26d881368425
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Feb 25 18:54:09 2016 +0000

    use QXLState instead of RedDispatcher
    
    Considering that:
    - QXLState is the state of QXLInstance implementation;
    - RedDispatcher is the implementation of QXL;
    - qif (QXLInterface*) field can be computed really easy from QXLInstance;
    - most of its state is private.
    Make all structure private and use QXLState instead of RedDispatcher.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 268e34f..f5cb5ee 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -116,7 +116,7 @@ static void cursor_item_unref(CursorItem *item)
         return;
 
     cursor_cmd = item->red_cursor;
-    item->qxl->st->qif->release_resource(item->qxl, cursor_cmd->release_info_ext);
+    qxl_get_interface(item->qxl)->release_resource(item->qxl, cursor_cmd->release_info_ext);
     red_put_cursor_cmd(cursor_cmd);
     free(cursor_cmd);
 
diff --git a/server/dcc-send.c b/server/dcc-send.c
index 4180cc1..16c5098 100644
--- a/server/dcc-send.c
+++ b/server/dcc-send.c
@@ -2306,18 +2306,13 @@ static void marshall_gl_scanout(RedChannelClient *rcc,
     DisplayChannelClient *dcc = RCC_TO_DCC(rcc);
     DisplayChannel *display_channel = DCC_TO_DC(dcc);
     QXLInstance* qxl = display_channel->common.qxl;
-    SpiceMsgDisplayGlScanoutUnix *so = &qxl->st->scanout;
 
-    pthread_mutex_lock(&qxl->st->scanout_mutex);
-
-    if (so->drm_dma_buf_fd == -1)
-        goto end;
-
-    red_channel_client_init_send_data(rcc, SPICE_MSG_DISPLAY_GL_SCANOUT_UNIX, NULL);
-    spice_marshall_msg_display_gl_scanout_unix(m, so);
-
-end:
-    pthread_mutex_unlock(&qxl->st->scanout_mutex);
+    SpiceMsgDisplayGlScanoutUnix *so = red_qxl_get_gl_scanout(qxl->st);
+    if (so != NULL) {
+        red_channel_client_init_send_data(rcc, SPICE_MSG_DISPLAY_GL_SCANOUT_UNIX, NULL);
+        spice_marshall_msg_display_gl_scanout_unix(m, so);
+    }
+    red_qxl_put_gl_scanout(qxl->st, so);
 }
 
 static void marshall_gl_draw(RedChannelClient *rcc,
diff --git a/server/dcc.c b/server/dcc.c
index 74514db..70a9b99 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -467,7 +467,8 @@ void dcc_start(DisplayChannelClient *dcc)
         dcc_create_all_streams(dcc);
     }
 
-    if (qxl->st->scanout.drm_dma_buf_fd >= 0) {
+    SpiceMsgDisplayGlScanoutUnix *scanout = red_qxl_get_gl_scanout(qxl->st);
+    if (scanout) {
         if (reds_stream_is_plain_unix(rcc->stream) &&
             red_channel_client_test_remote_cap(rcc, SPICE_DISPLAY_CAP_GL_SCANOUT)) {
             red_channel_client_pipe_add(rcc, dcc_gl_scanout_item_new(rcc, NULL, 0));
@@ -476,6 +477,7 @@ void dcc_start(DisplayChannelClient *dcc)
             spice_printerr("FIXME: GL not supported on this kind of connection");
         }
     }
+    red_qxl_put_gl_scanout(qxl->st, scanout);
 }
 
 static void dcc_destroy_stream_agents(DisplayChannelClient *dcc)
diff --git a/server/display-channel.c b/server/display-channel.c
index 175ac7e..8065676 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -268,10 +268,10 @@ void display_channel_surface_unref(DisplayChannel *display, uint32_t surface_id)
 
     surface->context.canvas->ops->destroy(surface->context.canvas);
     if (surface->create.info) {
-        qxl->st->qif->release_resource(qxl, surface->create);
+        qxl_get_interface(qxl)->release_resource(qxl, surface->create);
     }
     if (surface->destroy.info) {
-        qxl->st->qif->release_resource(qxl, surface->destroy);
+        qxl_get_interface(qxl)->release_resource(qxl, surface->destroy);
     }
 
     region_destroy(&surface->draw_dirty_region);
@@ -2162,9 +2162,7 @@ static void set_gl_draw_async_count(DisplayChannel *display, int num)
     display->gl_draw_async_count = num;
 
     if (num == 0) {
-        struct AsyncCommand *async = qxl->st->gl_draw_async;
-        qxl->st->gl_draw_async = NULL;
-        red_qxl_async_complete(qxl->st->dispatcher, async);
+        red_qxl_gl_draw_async_complete(qxl->st);
     }
 }
 
diff --git a/server/red-qxl.c b/server/red-qxl.c
index 42edd64..e9b8701 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -45,7 +45,7 @@ struct AsyncCommand {
     uint64_t cookie;
 };
 
-struct RedDispatcher {
+struct QXLState {
     QXLWorker base;
     QXLInstance *qxl;
     Dispatcher dispatcher;
@@ -56,12 +56,16 @@ struct RedDispatcher {
     int use_hardware_cursor;
     QXLDevSurfaceCreate surface_create;
     unsigned int max_monitors;
+
+    pthread_mutex_t scanout_mutex;
+    SpiceMsgDisplayGlScanoutUnix scanout;
+    struct AsyncCommand *gl_draw_async;
 };
 
-static int red_qxl_check_qxl_version(RedDispatcher *rd, int major, int minor)
+static int red_qxl_check_qxl_version(QXLState *rq, int major, int minor)
 {
-    int qxl_major = rd->qxl->st->qif->base.major_version;
-    int qxl_minor = rd->qxl->st->qif->base.minor_version;
+    int qxl_major = qxl_get_interface(rq->qxl)->base.major_version;
+    int qxl_minor = qxl_get_interface(rq->qxl)->base.minor_version;
 
     return ((qxl_major > major) ||
             ((qxl_major == major) && (qxl_minor >= minor)));
@@ -73,10 +77,10 @@ static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
                                      uint32_t *caps)
 {
     RedWorkerMessageDisplayConnect payload = {0,};
-    RedDispatcher *dispatcher;
+    QXLState *qxl_state;
 
     spice_debug("%s", "");
-    dispatcher = (RedDispatcher *)channel->data;
+    qxl_state = (QXLState *)channel->data;
     payload.client = client;
     payload.stream = stream;
     payload.migration = migration;
@@ -88,7 +92,7 @@ static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
     memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
     memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DISPLAY_CONNECT,
                             &payload);
 }
@@ -96,20 +100,20 @@ static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
 static void red_qxl_disconnect_display_peer(RedChannelClient *rcc)
 {
     RedWorkerMessageDisplayDisconnect payload;
-    RedDispatcher *dispatcher;
+    QXLState *qxl_state;
 
     if (!rcc->channel) {
         return;
     }
 
-    dispatcher = (RedDispatcher *)rcc->channel->data;
+    qxl_state = (QXLState *)rcc->channel->data;
 
     spice_printerr("");
     payload.rcc = rcc;
 
     // TODO: we turned it to be sync, due to client_destroy . Should we support async? - for this we will need ref count
     // for channels
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
                             &payload);
 }
@@ -117,14 +121,14 @@ static void red_qxl_disconnect_display_peer(RedChannelClient *rcc)
 static void red_qxl_display_migrate(RedChannelClient *rcc)
 {
     RedWorkerMessageDisplayMigrate payload;
-    RedDispatcher *dispatcher;
+    QXLState *qxl_state;
     if (!rcc->channel) {
         return;
     }
-    dispatcher = (RedDispatcher *)rcc->channel->data;
+    qxl_state = (QXLState *)rcc->channel->data;
     spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
     payload.rcc = rcc;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
                             &payload);
 }
@@ -135,7 +139,7 @@ static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, Reds
                                     uint32_t *caps)
 {
     RedWorkerMessageCursorConnect payload = {0,};
-    RedDispatcher *dispatcher = (RedDispatcher *)channel->data;
+    QXLState *qxl_state = (QXLState *)channel->data;
     spice_printerr("");
     payload.client = client;
     payload.stream = stream;
@@ -148,7 +152,7 @@ static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, Reds
     memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
     memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_CURSOR_CONNECT,
                             &payload);
 }
@@ -156,17 +160,17 @@ static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, Reds
 static void red_qxl_disconnect_cursor_peer(RedChannelClient *rcc)
 {
     RedWorkerMessageCursorDisconnect payload;
-    RedDispatcher *dispatcher;
+    QXLState *qxl_state;
 
     if (!rcc->channel) {
         return;
     }
 
-    dispatcher = (RedDispatcher *)rcc->channel->data;
+    qxl_state = (QXLState *)rcc->channel->data;
     spice_printerr("");
     payload.rcc = rcc;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
                             &payload);
 }
@@ -174,20 +178,20 @@ static void red_qxl_disconnect_cursor_peer(RedChannelClient *rcc)
 static void red_qxl_cursor_migrate(RedChannelClient *rcc)
 {
     RedWorkerMessageCursorMigrate payload;
-    RedDispatcher *dispatcher;
+    QXLState *qxl_state;
 
     if (!rcc->channel) {
         return;
     }
-    dispatcher = (RedDispatcher *)rcc->channel->data;
+    qxl_state = (QXLState *)rcc->channel->data;
     spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
     payload.rcc = rcc;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_CURSOR_MIGRATE,
                             &payload);
 }
 
-static void red_qxl_update_area(RedDispatcher *dispatcher, uint32_t surface_id,
+static void red_qxl_update_area(QXLState *qxl_state, uint32_t surface_id,
                                 QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
                                 uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
@@ -198,27 +202,27 @@ static void red_qxl_update_area(RedDispatcher *dispatcher, uint32_t surface_id,
     payload.qxl_dirty_rects = qxl_dirty_rects;
     payload.num_dirty_rects = num_dirty_rects;
     payload.clear_dirty_region = clear_dirty_region;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_UPDATE,
                             &payload);
 }
 
-gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher)
+gboolean red_qxl_use_client_monitors_config(QXLState *qxl_state)
 {
-    return (red_qxl_check_qxl_version(dispatcher, 3, 3) &&
-        dispatcher->qxl->st->qif->client_monitors_config &&
-        dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl, NULL));
+    return (red_qxl_check_qxl_version(qxl_state, 3, 3) &&
+        qxl_get_interface(qxl_state->qxl)->client_monitors_config &&
+        qxl_get_interface(qxl_state->qxl)->client_monitors_config(qxl_state->qxl, NULL));
 }
 
-gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher,
+gboolean red_qxl_client_monitors_config(QXLState *qxl_state,
                                         VDAgentMonitorsConfig *monitors_config)
 {
-    return (dispatcher->qxl->st->qif->client_monitors_config &&
-        dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl,
-                                                          monitors_config));
+    return (qxl_get_interface(qxl_state->qxl)->client_monitors_config &&
+        qxl_get_interface(qxl_state->qxl)->client_monitors_config(qxl_state->qxl,
+                                                                  monitors_config));
 }
 
-static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
+static AsyncCommand *async_command_alloc(QXLState *qxl_state,
                                          RedWorkerMessage message,
                                          uint64_t cookie)
 {
@@ -231,7 +235,7 @@ static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
     return async_command;
 }
 
-static void red_qxl_update_area_async(RedDispatcher *dispatcher,
+static void red_qxl_update_area_async(QXLState *qxl_state,
                                       uint32_t surface_id,
                                       QXLRect *qxl_area,
                                       uint32_t clear_dirty_region,
@@ -240,11 +244,11 @@ static void red_qxl_update_area_async(RedDispatcher *dispatcher,
     RedWorkerMessage message = RED_WORKER_MESSAGE_UPDATE_ASYNC;
     RedWorkerMessageUpdateAsync payload;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
     payload.surface_id = surface_id;
     payload.qxl_area = *qxl_area;
     payload.clear_dirty_region = clear_dirty_region;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             message,
                             &payload);
 }
@@ -253,332 +257,332 @@ static void qxl_worker_update_area(QXLWorker *qxl_worker, uint32_t surface_id,
                                    QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
                                    uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
-    red_qxl_update_area((RedDispatcher*)qxl_worker, surface_id, qxl_area,
+    red_qxl_update_area((QXLState*)qxl_worker, surface_id, qxl_area,
                         qxl_dirty_rects, num_dirty_rects, clear_dirty_region);
 }
 
-static void red_qxl_add_memslot(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot)
+static void red_qxl_add_memslot(QXLState *qxl_state, QXLDevMemSlot *mem_slot)
 {
     RedWorkerMessageAddMemslot payload;
 
     payload.mem_slot = *mem_slot;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_ADD_MEMSLOT,
                             &payload);
 }
 
 static void qxl_worker_add_memslot(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slot)
 {
-    red_qxl_add_memslot((RedDispatcher*)qxl_worker, mem_slot);
+    red_qxl_add_memslot((QXLState*)qxl_worker, mem_slot);
 }
 
-static void red_qxl_add_memslot_async(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot, uint64_t cookie)
+static void red_qxl_add_memslot_async(QXLState *qxl_state, QXLDevMemSlot *mem_slot, uint64_t cookie)
 {
     RedWorkerMessageAddMemslotAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
     payload.mem_slot = *mem_slot;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
-static void red_qxl_del_memslot(RedDispatcher *dispatcher, uint32_t slot_group_id, uint32_t slot_id)
+static void red_qxl_del_memslot(QXLState *qxl_state, uint32_t slot_group_id, uint32_t slot_id)
 {
     RedWorkerMessageDelMemslot payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DEL_MEMSLOT;
 
     payload.slot_group_id = slot_group_id;
     payload.slot_id = slot_id;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
 static void qxl_worker_del_memslot(QXLWorker *qxl_worker, uint32_t slot_group_id, uint32_t slot_id)
 {
-    red_qxl_del_memslot((RedDispatcher*)qxl_worker, slot_group_id, slot_id);
+    red_qxl_del_memslot((QXLState*)qxl_worker, slot_group_id, slot_id);
 }
 
-static void red_qxl_destroy_surfaces(RedDispatcher *dispatcher)
+static void red_qxl_destroy_surfaces(QXLState *qxl_state)
 {
     RedWorkerMessageDestroySurfaces payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DESTROY_SURFACES,
                             &payload);
 }
 
 static void qxl_worker_destroy_surfaces(QXLWorker *qxl_worker)
 {
-    red_qxl_destroy_surfaces((RedDispatcher*)qxl_worker);
+    red_qxl_destroy_surfaces((QXLState*)qxl_worker);
 }
 
-static void red_qxl_destroy_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
+static void red_qxl_destroy_surfaces_async(QXLState *qxl_state, uint64_t cookie)
 {
     RedWorkerMessageDestroySurfacesAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
-static void red_qxl_destroy_primary_surface_complete(RedDispatcher *dispatcher)
+static void red_qxl_destroy_primary_surface_complete(QXLState *qxl_state)
 {
-    dispatcher->x_res = 0;
-    dispatcher->y_res = 0;
-    dispatcher->use_hardware_cursor = FALSE;
-    dispatcher->primary_active = FALSE;
+    qxl_state->x_res = 0;
+    qxl_state->y_res = 0;
+    qxl_state->use_hardware_cursor = FALSE;
+    qxl_state->primary_active = FALSE;
 
     reds_update_client_mouse_allowed(reds);
 }
 
 static void
-red_qxl_destroy_primary_surface_sync(RedDispatcher *dispatcher,
+red_qxl_destroy_primary_surface_sync(QXLState *qxl_state,
                                      uint32_t surface_id)
 {
     RedWorkerMessageDestroyPrimarySurface payload;
     payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
                             &payload);
-    red_qxl_destroy_primary_surface_complete(dispatcher);
+    red_qxl_destroy_primary_surface_complete(qxl_state);
 }
 
 static void
-red_qxl_destroy_primary_surface_async(RedDispatcher *dispatcher,
+red_qxl_destroy_primary_surface_async(QXLState *qxl_state,
                                       uint32_t surface_id, uint64_t cookie)
 {
     RedWorkerMessageDestroyPrimarySurfaceAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
     payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
 static void
-red_qxl_destroy_primary_surface(RedDispatcher *dispatcher,
+red_qxl_destroy_primary_surface(QXLState *qxl_state,
                                 uint32_t surface_id, int async, uint64_t cookie)
 {
     if (async) {
-        red_qxl_destroy_primary_surface_async(dispatcher, surface_id, cookie);
+        red_qxl_destroy_primary_surface_async(qxl_state, surface_id, cookie);
     } else {
-        red_qxl_destroy_primary_surface_sync(dispatcher, surface_id);
+        red_qxl_destroy_primary_surface_sync(qxl_state, surface_id);
     }
 }
 
 static void qxl_worker_destroy_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id)
 {
-    red_qxl_destroy_primary_surface((RedDispatcher*)qxl_worker, surface_id, 0, 0);
+    red_qxl_destroy_primary_surface((QXLState*)qxl_worker, surface_id, 0, 0);
 }
 
-static void red_qxl_create_primary_surface_complete(RedDispatcher *dispatcher)
+static void red_qxl_create_primary_surface_complete(QXLState *qxl_state)
 {
-    QXLDevSurfaceCreate *surface = &dispatcher->surface_create;
+    QXLDevSurfaceCreate *surface = &qxl_state->surface_create;
 
-    dispatcher->x_res = surface->width;
-    dispatcher->y_res = surface->height;
-    dispatcher->use_hardware_cursor = surface->mouse_mode;
-    dispatcher->primary_active = TRUE;
+    qxl_state->x_res = surface->width;
+    qxl_state->y_res = surface->height;
+    qxl_state->use_hardware_cursor = surface->mouse_mode;
+    qxl_state->primary_active = TRUE;
 
     reds_update_client_mouse_allowed(reds);
-    memset(&dispatcher->surface_create, 0, sizeof(QXLDevSurfaceCreate));
+    memset(&qxl_state->surface_create, 0, sizeof(QXLDevSurfaceCreate));
 }
 
 static void
-red_qxl_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t surface_id,
+red_qxl_create_primary_surface_async(QXLState *qxl_state, uint32_t surface_id,
                                      QXLDevSurfaceCreate *surface, uint64_t cookie)
 {
     RedWorkerMessageCreatePrimarySurfaceAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC;
 
-    dispatcher->surface_create = *surface;
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    qxl_state->surface_create = *surface;
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
     payload.surface_id = surface_id;
     payload.surface = *surface;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
 static void
-red_qxl_create_primary_surface_sync(RedDispatcher *dispatcher, uint32_t surface_id,
+red_qxl_create_primary_surface_sync(QXLState *qxl_state, uint32_t surface_id,
                                     QXLDevSurfaceCreate *surface)
 {
     RedWorkerMessageCreatePrimarySurface payload = {0,};
 
-    dispatcher->surface_create = *surface;
+    qxl_state->surface_create = *surface;
     payload.surface_id = surface_id;
     payload.surface = *surface;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
                             &payload);
-    red_qxl_create_primary_surface_complete(dispatcher);
+    red_qxl_create_primary_surface_complete(qxl_state);
 }
 
 static void
-red_qxl_create_primary_surface(RedDispatcher *dispatcher, uint32_t surface_id,
+red_qxl_create_primary_surface(QXLState *qxl_state, uint32_t surface_id,
                                QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
 {
     if (async) {
-        red_qxl_create_primary_surface_async(dispatcher, surface_id, surface, cookie);
+        red_qxl_create_primary_surface_async(qxl_state, surface_id, surface, cookie);
     } else {
-        red_qxl_create_primary_surface_sync(dispatcher, surface_id, surface);
+        red_qxl_create_primary_surface_sync(qxl_state, surface_id, surface);
     }
 }
 
 static void qxl_worker_create_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id,
                                       QXLDevSurfaceCreate *surface)
 {
-    red_qxl_create_primary_surface((RedDispatcher*)qxl_worker, surface_id, surface, 0, 0);
+    red_qxl_create_primary_surface((QXLState*)qxl_worker, surface_id, surface, 0, 0);
 }
 
-static void red_qxl_reset_image_cache(RedDispatcher *dispatcher)
+static void red_qxl_reset_image_cache(QXLState *qxl_state)
 {
     RedWorkerMessageResetImageCache payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
                             &payload);
 }
 
 static void qxl_worker_reset_image_cache(QXLWorker *qxl_worker)
 {
-    red_qxl_reset_image_cache((RedDispatcher*)qxl_worker);
+    red_qxl_reset_image_cache((QXLState*)qxl_worker);
 }
 
-static void red_qxl_reset_cursor(RedDispatcher *dispatcher)
+static void red_qxl_reset_cursor(QXLState *qxl_state)
 {
     RedWorkerMessageResetCursor payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_RESET_CURSOR,
                             &payload);
 }
 
 static void qxl_worker_reset_cursor(QXLWorker *qxl_worker)
 {
-    red_qxl_reset_cursor((RedDispatcher*)qxl_worker);
+    red_qxl_reset_cursor((QXLState*)qxl_worker);
 }
 
-static void red_qxl_destroy_surface_wait_sync(RedDispatcher *dispatcher,
+static void red_qxl_destroy_surface_wait_sync(QXLState *qxl_state,
                                               uint32_t surface_id)
 {
     RedWorkerMessageDestroySurfaceWait payload;
 
     payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
                             &payload);
 }
 
-static void red_qxl_destroy_surface_wait_async(RedDispatcher *dispatcher,
+static void red_qxl_destroy_surface_wait_async(QXLState *qxl_state,
                                                uint32_t surface_id,
                                                uint64_t cookie)
 {
     RedWorkerMessageDestroySurfaceWaitAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
     payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
-static void red_qxl_destroy_surface_wait(RedDispatcher *dispatcher,
+static void red_qxl_destroy_surface_wait(QXLState *qxl_state,
                                          uint32_t surface_id,
                                          int async, uint64_t cookie)
 {
     if (async) {
-        red_qxl_destroy_surface_wait_async(dispatcher, surface_id, cookie);
+        red_qxl_destroy_surface_wait_async(qxl_state, surface_id, cookie);
     } else {
-        red_qxl_destroy_surface_wait_sync(dispatcher, surface_id);
+        red_qxl_destroy_surface_wait_sync(qxl_state, surface_id);
     }
 }
 
 static void qxl_worker_destroy_surface_wait(QXLWorker *qxl_worker, uint32_t surface_id)
 {
-    red_qxl_destroy_surface_wait((RedDispatcher*)qxl_worker, surface_id, 0, 0);
+    red_qxl_destroy_surface_wait((QXLState*)qxl_worker, surface_id, 0, 0);
 }
 
-static void red_qxl_reset_memslots(RedDispatcher *dispatcher)
+static void red_qxl_reset_memslots(QXLState *qxl_state)
 {
     RedWorkerMessageResetMemslots payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_RESET_MEMSLOTS,
                             &payload);
 }
 
 static void qxl_worker_reset_memslots(QXLWorker *qxl_worker)
 {
-    red_qxl_reset_memslots((RedDispatcher*)qxl_worker);
+    red_qxl_reset_memslots((QXLState*)qxl_worker);
 }
 
-static bool red_qxl_set_pending(RedDispatcher *dispatcher, int pending)
+static bool red_qxl_set_pending(QXLState *qxl_state, int pending)
 {
     // this is not atomic but is not an issue
-    if (test_bit(pending, dispatcher->pending)) {
+    if (test_bit(pending, qxl_state->pending)) {
         return TRUE;
     }
 
-    set_bit(pending, &dispatcher->pending);
+    set_bit(pending, &qxl_state->pending);
     return FALSE;
 }
 
-static void red_qxl_wakeup(RedDispatcher *dispatcher)
+static void red_qxl_wakeup(QXLState *qxl_state)
 {
     RedWorkerMessageWakeup payload;
 
-    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_WAKEUP))
+    if (red_qxl_set_pending(qxl_state, RED_DISPATCHER_PENDING_WAKEUP))
         return;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_WAKEUP,
                             &payload);
 }
 
 static void qxl_worker_wakeup(QXLWorker *qxl_worker)
 {
-    red_qxl_wakeup((RedDispatcher*)qxl_worker);
+    red_qxl_wakeup((QXLState*)qxl_worker);
 }
 
-static void red_qxl_oom(RedDispatcher *dispatcher)
+static void red_qxl_oom(QXLState *qxl_state)
 {
     RedWorkerMessageOom payload;
 
-    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_OOM))
+    if (red_qxl_set_pending(qxl_state, RED_DISPATCHER_PENDING_OOM))
         return;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_OOM,
                             &payload);
 }
 
 static void qxl_worker_oom(QXLWorker *qxl_worker)
 {
-    red_qxl_oom((RedDispatcher*)qxl_worker);
+    red_qxl_oom((QXLState*)qxl_worker);
 }
 
-void red_qxl_start(RedDispatcher *dispatcher)
+void red_qxl_start(QXLState *qxl_state)
 {
     RedWorkerMessageStart payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_START,
                             &payload);
 }
 
 static void qxl_worker_start(QXLWorker *qxl_worker)
 {
-    red_qxl_start((RedDispatcher*)qxl_worker);
+    red_qxl_start((QXLState*)qxl_worker);
 }
 
-static void red_qxl_flush_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
+static void red_qxl_flush_surfaces_async(QXLState *qxl_state, uint64_t cookie)
 {
     RedWorkerMessageFlushSurfacesAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
-static void red_qxl_monitors_config_async(RedDispatcher *dispatcher,
+static void red_qxl_monitors_config_async(QXLState *qxl_state,
                                           QXLPHYSICAL monitors_config,
                                           int group_id,
                                           uint64_t cookie)
@@ -586,38 +590,38 @@ static void red_qxl_monitors_config_async(RedDispatcher *dispatcher,
     RedWorkerMessageMonitorsConfigAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC;
 
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.base.cmd = async_command_alloc(qxl_state, message, cookie);
     payload.monitors_config = monitors_config;
     payload.group_id = group_id;
-    payload.max_monitors = dispatcher->max_monitors;
+    payload.max_monitors = qxl_state->max_monitors;
 
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &payload);
 }
 
-static void red_qxl_driver_unload(RedDispatcher *dispatcher)
+static void red_qxl_driver_unload(QXLState *qxl_state)
 {
     RedWorkerMessageDriverUnload payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_DRIVER_UNLOAD,
                             &payload);
 }
 
-void red_qxl_stop(RedDispatcher *dispatcher)
+void red_qxl_stop(QXLState *qxl_state)
 {
     RedWorkerMessageStop payload;
 
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_STOP,
                             &payload);
 }
 
 static void qxl_worker_stop(QXLWorker *qxl_worker)
 {
-    red_qxl_stop((RedDispatcher*)qxl_worker);
+    red_qxl_stop((QXLState*)qxl_worker);
 }
 
-static void red_qxl_loadvm_commands(RedDispatcher *dispatcher,
+static void red_qxl_loadvm_commands(QXLState *qxl_state,
                                     struct QXLCommandExt *ext,
                                     uint32_t count)
 {
@@ -626,7 +630,7 @@ static void red_qxl_loadvm_commands(RedDispatcher *dispatcher,
     spice_printerr("");
     payload.count = count;
     payload.ext = ext;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_LOADVM_COMMANDS,
                             &payload);
 }
@@ -635,54 +639,54 @@ static void qxl_worker_loadvm_commands(QXLWorker *qxl_worker,
                                        struct QXLCommandExt *ext,
                                        uint32_t count)
 {
-    red_qxl_loadvm_commands((RedDispatcher*)qxl_worker, ext, count);
+    red_qxl_loadvm_commands((QXLState*)qxl_worker, ext, count);
 }
 
-void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t mm_time)
+void red_qxl_set_mm_time(QXLState *qxl_state, uint32_t mm_time)
 {
-    dispatcher->qxl->st->qif->set_mm_time(dispatcher->qxl, mm_time);
+    qxl_get_interface(qxl_state->qxl)->set_mm_time(qxl_state->qxl, mm_time);
 }
 
-void red_qxl_attach_worker(RedDispatcher *dispatcher)
+void red_qxl_attach_worker(QXLState *qxl_state)
 {
-    QXLInstance *qxl = dispatcher->qxl;
-    qxl->st->qif->attache_worker(qxl, &dispatcher->base);
+    QXLInstance *qxl = qxl_state->qxl;
+    qxl_get_interface(qxl_state->qxl)->attache_worker(qxl, &qxl_state->base);
 }
 
-void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level)
+void red_qxl_set_compression_level(QXLState *qxl_state, int level)
 {
-    dispatcher->qxl->st->qif->set_compression_level(dispatcher->qxl, level);
+    qxl_get_interface(qxl_state->qxl)->set_compression_level(qxl_state->qxl, level);
 }
 
-uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher)
+uint32_t red_qxl_get_ram_size(QXLState *qxl_state)
 {
     QXLDevInitInfo qxl_info;
-    dispatcher->qxl->st->qif->get_init_info(dispatcher->qxl, &qxl_info);
+    qxl_get_interface(qxl_state->qxl)->get_init_info(qxl_state->qxl, &qxl_info);
     return qxl_info.qxl_ram_size;
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_wakeup(QXLInstance *instance)
 {
-    red_qxl_wakeup(instance->st->dispatcher);
+    red_qxl_wakeup(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_oom(QXLInstance *instance)
 {
-    red_qxl_oom(instance->st->dispatcher);
+    red_qxl_oom(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_start(QXLInstance *instance)
 {
-    red_qxl_start(instance->st->dispatcher);
+    red_qxl_start(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_stop(QXLInstance *instance)
 {
-    red_qxl_stop(instance->st->dispatcher);
+    red_qxl_stop(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
@@ -690,133 +694,150 @@ void spice_qxl_update_area(QXLInstance *instance, uint32_t surface_id,
                     struct QXLRect *area, struct QXLRect *dirty_rects,
                     uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
-    red_qxl_update_area(instance->st->dispatcher, surface_id, area, dirty_rects,
+    red_qxl_update_area(instance->st, surface_id, area, dirty_rects,
                         num_dirty_rects, clear_dirty_region);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_add_memslot(QXLInstance *instance, QXLDevMemSlot *slot)
 {
-    red_qxl_add_memslot(instance->st->dispatcher, slot);
+    red_qxl_add_memslot(instance->st, slot);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_del_memslot(QXLInstance *instance, uint32_t slot_group_id, uint32_t slot_id)
 {
-    red_qxl_del_memslot(instance->st->dispatcher, slot_group_id, slot_id);
+    red_qxl_del_memslot(instance->st, slot_group_id, slot_id);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_reset_memslots(QXLInstance *instance)
 {
-    red_qxl_reset_memslots(instance->st->dispatcher);
+    red_qxl_reset_memslots(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surfaces(QXLInstance *instance)
 {
-    red_qxl_destroy_surfaces(instance->st->dispatcher);
+    red_qxl_destroy_surfaces(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_primary_surface(QXLInstance *instance, uint32_t surface_id)
 {
-    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 0, 0);
+    red_qxl_destroy_primary_surface(instance->st, surface_id, 0, 0);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_create_primary_surface(QXLInstance *instance, uint32_t surface_id,
                                 QXLDevSurfaceCreate *surface)
 {
-    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 0, 0);
+    red_qxl_create_primary_surface(instance->st, surface_id, surface, 0, 0);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_reset_image_cache(QXLInstance *instance)
 {
-    red_qxl_reset_image_cache(instance->st->dispatcher);
+    red_qxl_reset_image_cache(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_reset_cursor(QXLInstance *instance)
 {
-    red_qxl_reset_cursor(instance->st->dispatcher);
+    red_qxl_reset_cursor(instance->st);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surface_wait(QXLInstance *instance, uint32_t surface_id)
 {
-    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 0, 0);
+    red_qxl_destroy_surface_wait(instance->st, surface_id, 0, 0);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_loadvm_commands(QXLInstance *instance, struct QXLCommandExt *ext, uint32_t count)
 {
-    red_qxl_loadvm_commands(instance->st->dispatcher, ext, count);
+    red_qxl_loadvm_commands(instance->st, ext, count);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_update_area_async(QXLInstance *instance, uint32_t surface_id, QXLRect *qxl_area,
                                  uint32_t clear_dirty_region, uint64_t cookie)
 {
-    red_qxl_update_area_async(instance->st->dispatcher, surface_id, qxl_area,
+    red_qxl_update_area_async(instance->st, surface_id, qxl_area,
                                      clear_dirty_region, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_add_memslot_async(QXLInstance *instance, QXLDevMemSlot *slot, uint64_t cookie)
 {
-    red_qxl_add_memslot_async(instance->st->dispatcher, slot, cookie);
+    red_qxl_add_memslot_async(instance->st, slot, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surfaces_async(QXLInstance *instance, uint64_t cookie)
 {
-    red_qxl_destroy_surfaces_async(instance->st->dispatcher, cookie);
+    red_qxl_destroy_surfaces_async(instance->st, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_primary_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
 {
-    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 1, cookie);
+    red_qxl_destroy_primary_surface(instance->st, surface_id, 1, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_create_primary_surface_async(QXLInstance *instance, uint32_t surface_id,
                                 QXLDevSurfaceCreate *surface, uint64_t cookie)
 {
-    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 1, cookie);
+    red_qxl_create_primary_surface(instance->st, surface_id, surface, 1, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
 {
-    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 1, cookie);
+    red_qxl_destroy_surface_wait(instance->st, surface_id, 1, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_flush_surfaces_async(QXLInstance *instance, uint64_t cookie)
 {
-    red_qxl_flush_surfaces_async(instance->st->dispatcher, cookie);
+    red_qxl_flush_surfaces_async(instance->st, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_monitors_config_async(QXLInstance *instance, QXLPHYSICAL monitors_config,
                                      int group_id, uint64_t cookie)
 {
-    red_qxl_monitors_config_async(instance->st->dispatcher, monitors_config, group_id, cookie);
+    red_qxl_monitors_config_async(instance->st, monitors_config, group_id, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_set_max_monitors(QXLInstance *instance, unsigned int max_monitors)
 {
-    instance->st->dispatcher->max_monitors = MAX(1u, max_monitors);
+    instance->st->max_monitors = MAX(1u, max_monitors);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_driver_unload(QXLInstance *instance)
 {
-    red_qxl_driver_unload(instance->st->dispatcher);
+    red_qxl_driver_unload(instance->st);
+}
+
+SpiceMsgDisplayGlScanoutUnix *red_qxl_get_gl_scanout(QXLState *qxl_state)
+{
+    pthread_mutex_lock(&qxl_state->scanout_mutex);
+    if (qxl_state->scanout.drm_dma_buf_fd >= 0) {
+        return &qxl_state->scanout;
+    }
+    pthread_mutex_unlock(&qxl_state->scanout_mutex);
+    return NULL;
+}
+
+void red_qxl_put_gl_scanout(QXLState *qxl_state, SpiceMsgDisplayGlScanoutUnix *scanout)
+{
+    if (scanout) {
+        pthread_mutex_unlock(&qxl_state->scanout_mutex);
+    }
 }
 
 SPICE_GNUC_VISIBLE
@@ -827,15 +848,17 @@ void spice_qxl_gl_scanout(QXLInstance *qxl,
                           int y_0_top)
 {
     spice_return_if_fail(qxl != NULL);
-    spice_return_if_fail(qxl->st->gl_draw_async == NULL);
 
-    pthread_mutex_lock(&qxl->st->scanout_mutex);
+    QXLState *qxl_state = qxl->st;
+    spice_return_if_fail(qxl_state->gl_draw_async == NULL);
+
+    pthread_mutex_lock(&qxl_state->scanout_mutex);
 
-    if (qxl->st->scanout.drm_dma_buf_fd != -1) {
-        close(qxl->st->scanout.drm_dma_buf_fd);
+    if (qxl_state->scanout.drm_dma_buf_fd != -1) {
+        close(qxl_state->scanout.drm_dma_buf_fd);
     }
 
-    qxl->st->scanout = (SpiceMsgDisplayGlScanoutUnix) {
+    qxl_state->scanout = (SpiceMsgDisplayGlScanoutUnix) {
         .flags = y_0_top ? SPICE_GL_SCANOUT_FLAGS_Y0TOP : 0,
         .drm_dma_buf_fd = fd,
         .width = width,
@@ -844,10 +867,10 @@ void spice_qxl_gl_scanout(QXLInstance *qxl,
         .drm_fourcc_format = format
     };
 
-    pthread_mutex_unlock(&qxl->st->scanout_mutex);
+    pthread_mutex_unlock(&qxl_state->scanout_mutex);
 
     /* FIXME: find a way to coallesce all pending SCANOUTs */
-    dispatcher_send_message(&qxl->st->dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_GL_SCANOUT, NULL);
 }
 
@@ -857,7 +880,7 @@ void spice_qxl_gl_draw_async(QXLInstance *qxl,
                              uint32_t w, uint32_t h,
                              uint64_t cookie)
 {
-    RedDispatcher *dispatcher;
+    QXLState *qxl_state;
     RedWorkerMessage message = RED_WORKER_MESSAGE_GL_DRAW_ASYNC;
     SpiceMsgDisplayGlDraw draw = {
         .x = x,
@@ -867,15 +890,15 @@ void spice_qxl_gl_draw_async(QXLInstance *qxl,
     };
 
     spice_return_if_fail(qxl != NULL);
-    spice_return_if_fail(qxl->st->scanout.drm_dma_buf_fd != -1);
-    spice_return_if_fail(qxl->st->gl_draw_async == NULL);
+    qxl_state = qxl->st;
+    spice_return_if_fail(qxl_state->scanout.drm_dma_buf_fd != -1);
+    spice_return_if_fail(qxl_state->gl_draw_async == NULL);
 
-    dispatcher = qxl->st->dispatcher;
-    qxl->st->gl_draw_async = async_command_alloc(dispatcher, message, cookie);
-    dispatcher_send_message(&dispatcher->dispatcher, message, &draw);
+    qxl_state->gl_draw_async = async_command_alloc(qxl_state, message, cookie);
+    dispatcher_send_message(&qxl_state->dispatcher, message, &draw);
 }
 
-void red_qxl_async_complete(struct RedDispatcher *dispatcher,
+void red_qxl_async_complete(QXLState *qxl_state,
                             AsyncCommand *async_command)
 {
     spice_debug("%p: cookie %" PRId64, async_command, async_command->cookie);
@@ -889,27 +912,35 @@ void red_qxl_async_complete(struct RedDispatcher *dispatcher,
     case RED_WORKER_MESSAGE_GL_DRAW_ASYNC:
         break;
     case RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC:
-        red_qxl_create_primary_surface_complete(dispatcher);
+        red_qxl_create_primary_surface_complete(qxl_state);
         break;
     case RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC:
-        red_qxl_destroy_primary_surface_complete(dispatcher);
+        red_qxl_destroy_primary_surface_complete(qxl_state);
         break;
     default:
         spice_warning("unexpected message %d", async_command->message);
     }
-    dispatcher->qxl->st->qif->async_complete(dispatcher->qxl,
-                                             async_command->cookie);
+    qxl_get_interface(qxl_state->qxl)->async_complete(qxl_state->qxl,
+                                                      async_command->cookie);
     free(async_command);
 }
 
+void red_qxl_gl_draw_async_complete(QXLState *qxl_state)
+{
+    /* this reset before usage prevent a possible race condition */
+    struct AsyncCommand *async = qxl_state->gl_draw_async;
+    qxl_state->gl_draw_async = NULL;
+    red_qxl_async_complete(qxl_state, async);
+}
+
 void red_qxl_init(QXLInstance *qxl)
 {
-    RedDispatcher *red_dispatcher;
+    QXLState *qxl_state;
     RedChannel *channel;
     ClientCbs client_cbs = { NULL, };
 
     spice_return_if_fail(qxl != NULL);
-    spice_return_if_fail(qxl->st->dispatcher == NULL);
+    spice_return_if_fail(qxl->st == NULL);
 
     static gsize initialized = FALSE;
     if (g_once_init_enter(&initialized)) {
@@ -918,32 +949,34 @@ void red_qxl_init(QXLInstance *qxl)
         g_once_init_leave(&initialized, TRUE);
     }
 
-    red_dispatcher = spice_new0(RedDispatcher, 1);
-    red_dispatcher->qxl = qxl;
-    dispatcher_init(&red_dispatcher->dispatcher, RED_WORKER_MESSAGE_COUNT, NULL);
-    red_dispatcher->base.major_version = SPICE_INTERFACE_QXL_MAJOR;
-    red_dispatcher->base.minor_version = SPICE_INTERFACE_QXL_MINOR;
-    red_dispatcher->base.wakeup = qxl_worker_wakeup;
-    red_dispatcher->base.oom = qxl_worker_oom;
-    red_dispatcher->base.start = qxl_worker_start;
-    red_dispatcher->base.stop = qxl_worker_stop;
-    red_dispatcher->base.update_area = qxl_worker_update_area;
-    red_dispatcher->base.add_memslot = qxl_worker_add_memslot;
-    red_dispatcher->base.del_memslot = qxl_worker_del_memslot;
-    red_dispatcher->base.reset_memslots = qxl_worker_reset_memslots;
-    red_dispatcher->base.destroy_surfaces = qxl_worker_destroy_surfaces;
-    red_dispatcher->base.create_primary_surface = qxl_worker_create_primary_surface;
-    red_dispatcher->base.destroy_primary_surface = qxl_worker_destroy_primary_surface;
-
-    red_dispatcher->base.reset_image_cache = qxl_worker_reset_image_cache;
-    red_dispatcher->base.reset_cursor = qxl_worker_reset_cursor;
-    red_dispatcher->base.destroy_surface_wait = qxl_worker_destroy_surface_wait;
-    red_dispatcher->base.loadvm_commands = qxl_worker_loadvm_commands;
-
-    red_dispatcher->max_monitors = UINT_MAX;
+    qxl_state = spice_new0(QXLState, 1);
+    qxl_state->qxl = qxl;
+    pthread_mutex_init(&qxl_state->scanout_mutex, NULL);
+    qxl_state->scanout.drm_dma_buf_fd = -1;
+    dispatcher_init(&qxl_state->dispatcher, RED_WORKER_MESSAGE_COUNT, NULL);
+    qxl_state->base.major_version = SPICE_INTERFACE_QXL_MAJOR;
+    qxl_state->base.minor_version = SPICE_INTERFACE_QXL_MINOR;
+    qxl_state->base.wakeup = qxl_worker_wakeup;
+    qxl_state->base.oom = qxl_worker_oom;
+    qxl_state->base.start = qxl_worker_start;
+    qxl_state->base.stop = qxl_worker_stop;
+    qxl_state->base.update_area = qxl_worker_update_area;
+    qxl_state->base.add_memslot = qxl_worker_add_memslot;
+    qxl_state->base.del_memslot = qxl_worker_del_memslot;
+    qxl_state->base.reset_memslots = qxl_worker_reset_memslots;
+    qxl_state->base.destroy_surfaces = qxl_worker_destroy_surfaces;
+    qxl_state->base.create_primary_surface = qxl_worker_create_primary_surface;
+    qxl_state->base.destroy_primary_surface = qxl_worker_destroy_primary_surface;
+
+    qxl_state->base.reset_image_cache = qxl_worker_reset_image_cache;
+    qxl_state->base.reset_cursor = qxl_worker_reset_cursor;
+    qxl_state->base.destroy_surface_wait = qxl_worker_destroy_surface_wait;
+    qxl_state->base.loadvm_commands = qxl_worker_loadvm_commands;
+
+    qxl_state->max_monitors = UINT_MAX;
 
     // TODO: reference and free
-    RedWorker *worker = red_worker_new(qxl, red_dispatcher);
+    RedWorker *worker = red_worker_new(qxl, qxl_state);
 
     // TODO: move to their respective channel files
     channel = red_worker_get_cursor_channel(worker);
@@ -951,7 +984,7 @@ void red_qxl_init(QXLInstance *qxl)
     client_cbs.disconnect = red_qxl_disconnect_cursor_peer;
     client_cbs.migrate = red_qxl_cursor_migrate;
     red_channel_register_client_cbs(channel, &client_cbs);
-    red_channel_set_data(channel, red_dispatcher);
+    red_channel_set_data(channel, qxl_state);
     reds_register_channel(reds, channel);
 
     channel = red_worker_get_display_channel(worker);
@@ -959,7 +992,7 @@ void red_qxl_init(QXLInstance *qxl)
     client_cbs.disconnect = red_qxl_disconnect_display_peer;
     client_cbs.migrate = red_qxl_display_migrate;
     red_channel_register_client_cbs(channel, &client_cbs);
-    red_channel_set_data(channel, red_dispatcher);
+    red_channel_set_data(channel, qxl_state);
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_STREAM_REPORT);
@@ -967,66 +1000,66 @@ void red_qxl_init(QXLInstance *qxl)
 
     red_worker_run(worker);
 
-    qxl->st->dispatcher = red_dispatcher;
+    qxl->st = qxl_state;
 }
 
-struct Dispatcher *red_qxl_get_dispatcher(RedDispatcher *red_dispatcher)
+struct Dispatcher *red_qxl_get_dispatcher(QXLState *qxl_state)
 {
-    return &red_dispatcher->dispatcher;
+    return &qxl_state->dispatcher;
 }
 
-void red_qxl_set_dispatcher_opaque(RedDispatcher *red_dispatcher,
+void red_qxl_set_dispatcher_opaque(QXLState *qxl_state,
                                    void *opaque)
 {
-    dispatcher_set_opaque(&red_dispatcher->dispatcher, opaque);
+    dispatcher_set_opaque(&qxl_state->dispatcher, opaque);
 }
 
-void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending)
+void red_qxl_clear_pending(QXLState *qxl_state, int pending)
 {
-    spice_return_if_fail(red_dispatcher != NULL);
+    spice_return_if_fail(qxl_state != NULL);
 
-    clear_bit(pending, &red_dispatcher->pending);
+    clear_bit(pending, &qxl_state->pending);
 }
 
-gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher)
+gboolean red_qxl_get_primary_active(QXLState *qxl_state)
 {
-    return dispatcher->primary_active;
+    return qxl_state->primary_active;
 }
 
-gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res)
+gboolean red_qxl_get_allow_client_mouse(QXLState *qxl_state, gint *x_res, gint *y_res)
 {
-    if (dispatcher->use_hardware_cursor) {
+    if (qxl_state->use_hardware_cursor) {
         if (x_res)
-            *x_res = dispatcher->x_res;
+            *x_res = qxl_state->x_res;
         if (y_res)
-            *y_res = dispatcher->y_res;
+            *y_res = qxl_state->y_res;
     }
-    return dispatcher->use_hardware_cursor;
+    return qxl_state->use_hardware_cursor;
 }
 
-void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic)
+void red_qxl_on_ic_change(QXLState *qxl_state, SpiceImageCompression ic)
 {
     RedWorkerMessageSetCompression payload;
     payload.image_compression = ic;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_SET_COMPRESSION,
                             &payload);
 }
 
-void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv)
+void red_qxl_on_sv_change(QXLState *qxl_state, int sv)
 {
     RedWorkerMessageSetStreamingVideo payload;
     payload.streaming_video = sv;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
                             &payload);
 }
 
-void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode)
+void red_qxl_set_mouse_mode(QXLState *qxl_state, uint32_t mode)
 {
     RedWorkerMessageSetMouseMode payload;
     payload.mode = mode;
-    dispatcher_send_message(&dispatcher->dispatcher,
+    dispatcher_send_message(&qxl_state->dispatcher,
                             RED_WORKER_MESSAGE_SET_MOUSE_MODE,
                             &payload);
 }
diff --git a/server/red-qxl.h b/server/red-qxl.h
index 1348e6c..3451217 100644
--- a/server/red-qxl.h
+++ b/server/red-qxl.h
@@ -20,27 +20,30 @@
 
 #include "red-channel.h"
 
-typedef struct RedDispatcher RedDispatcher;
+typedef struct QXLState QXLState;
 
 typedef struct AsyncCommand AsyncCommand;
 
 void red_qxl_init(QXLInstance *qxl);
 
-void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t);
-void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic);
-void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv);
-void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode);
-void red_qxl_attach_worker(RedDispatcher *dispatcher);
-void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level);
-void red_qxl_stop(RedDispatcher *dispatcher);
-void red_qxl_start(RedDispatcher *dispatcher);
-uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher);
-void red_qxl_async_complete(struct RedDispatcher *, AsyncCommand *);
-struct Dispatcher *red_qxl_get_dispatcher(struct RedDispatcher *);
-gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher);
-gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher, VDAgentMonitorsConfig *monitors_config);
-gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher);
-gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res);
+void red_qxl_set_mm_time(QXLState *qxl_state, uint32_t);
+void red_qxl_on_ic_change(QXLState *qxl_state, SpiceImageCompression ic);
+void red_qxl_on_sv_change(QXLState *qxl_state, int sv);
+void red_qxl_set_mouse_mode(QXLState *qxl_state, uint32_t mode);
+void red_qxl_attach_worker(QXLState *qxl_state);
+void red_qxl_set_compression_level(QXLState *qxl_state, int level);
+void red_qxl_stop(QXLState *qxl_state);
+void red_qxl_start(QXLState *qxl_state);
+uint32_t red_qxl_get_ram_size(QXLState *qxl_state);
+void red_qxl_async_complete(QXLState *qxl_state, AsyncCommand *cmd);
+struct Dispatcher *red_qxl_get_dispatcher(QXLState *qxl_state);
+gboolean red_qxl_use_client_monitors_config(QXLState *qxl_state);
+gboolean red_qxl_client_monitors_config(QXLState *qxl_state, VDAgentMonitorsConfig *monitors_config);
+gboolean red_qxl_get_primary_active(QXLState *qxl_state);
+gboolean red_qxl_get_allow_client_mouse(QXLState *qxl_state, gint *x_res, gint *y_res);
+SpiceMsgDisplayGlScanoutUnix *red_qxl_get_gl_scanout(QXLState *qxl_state);
+void red_qxl_put_gl_scanout(QXLState *qxl_state, SpiceMsgDisplayGlScanoutUnix *scanout);
+void red_qxl_gl_draw_async_complete(QXLState *qxl);
 
 typedef uint32_t RedWorkerMessage;
 
@@ -267,6 +270,6 @@ enum {
     RED_DISPATCHER_PENDING_OOM,
 };
 
-void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending);
+void red_qxl_clear_pending(QXLState *qxl_state, int pending);
 
 #endif
diff --git a/server/red-worker.c b/server/red-worker.c
index 8ef0b9f..6fb7865 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -60,7 +60,7 @@
 struct RedWorker {
     pthread_t thread;
     QXLInstance *qxl;
-    RedDispatcher *red_dispatcher;
+    QXLState *qxl_state;
     SpiceWatch *dispatch_watch;
     int running;
     SpiceCoreInterfaceInternal core;
@@ -127,8 +127,8 @@ void red_drawable_unref(RedDrawable *red_drawable)
     if (--red_drawable->refs) {
         return;
     }
-    red_drawable->qxl->st->qif->release_resource(red_drawable->qxl,
-                                                 red_drawable->release_info_ext);
+    qxl_get_interface(red_drawable->qxl)->release_resource(red_drawable->qxl,
+                                                           red_drawable->release_info_ext);
     red_put_drawable(red_drawable);
     free(red_drawable);
 }
@@ -145,12 +145,12 @@ static int red_process_cursor(RedWorker *worker, int *ring_is_empty)
 
     *ring_is_empty = FALSE;
     while (red_channel_max_pipe_size(RED_CHANNEL(worker->cursor_channel)) <= MAX_PIPE_SIZE) {
-        if (!worker->qxl->st->qif->get_cursor_command(worker->qxl, &ext_cmd)) {
+        if (!qxl_get_interface(worker->qxl)->get_cursor_command(worker->qxl, &ext_cmd)) {
             *ring_is_empty = TRUE;
             if (worker->cursor_poll_tries < CMD_RING_POLL_RETRIES) {
                 worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
             } else if (worker->cursor_poll_tries == CMD_RING_POLL_RETRIES &&
-                       !worker->qxl->st->qif->req_cursor_notification(worker->qxl)) {
+                       !qxl_get_interface(worker->qxl)->req_cursor_notification(worker->qxl)) {
                 continue;
             }
             worker->cursor_poll_tries++;
@@ -203,12 +203,12 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
     worker->process_display_generation++;
     *ring_is_empty = FALSE;
     while (red_channel_max_pipe_size(RED_CHANNEL(worker->display_channel)) <= MAX_PIPE_SIZE) {
-        if (!worker->qxl->st->qif->get_command(worker->qxl, &ext_cmd)) {
+        if (!qxl_get_interface(worker->qxl)->get_command(worker->qxl, &ext_cmd)) {
             *ring_is_empty = TRUE;
             if (worker->display_poll_tries < CMD_RING_POLL_RETRIES) {
                 worker->event_timeout = MIN(worker->event_timeout, CMD_RING_POLL_TIMEOUT);
             } else if (worker->display_poll_tries == CMD_RING_POLL_RETRIES &&
-                       !worker->qxl->st->qif->req_cmd_notification(worker->qxl)) {
+                       !qxl_get_interface(worker->qxl)->req_cmd_notification(worker->qxl)) {
                 continue;
             }
             worker->display_poll_tries++;
@@ -245,9 +245,9 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
                 spice_warning("Invalid surface in QXL_CMD_UPDATE");
             } else {
                 display_channel_draw(worker->display_channel, &update.area, update.surface_id);
-                worker->qxl->st->qif->notify_update(worker->qxl, update.update_id);
+                qxl_get_interface(worker->qxl)->notify_update(worker->qxl, update.update_id);
             }
-            worker->qxl->st->qif->release_resource(worker->qxl, update.release_info_ext);
+            qxl_get_interface(worker->qxl)->release_resource(worker->qxl, update.release_info_ext);
             red_put_update_cmd(&update);
             break;
         }
@@ -262,7 +262,7 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
             /* alert: accessing message.data is insecure */
             spice_warning("MESSAGE: %s", message.data);
 #endif
-            worker->qxl->st->qif->release_resource(worker->qxl, message.release_info_ext);
+            qxl_get_interface(worker->qxl)->release_resource(worker->qxl, message.release_info_ext);
             red_put_message(&message);
             break;
         }
@@ -507,11 +507,12 @@ static void guest_set_client_capabilities(RedWorker *worker)
         SPICE_DISPLAY_CAP_COMPOSITE,
         SPICE_DISPLAY_CAP_A8_SURFACE,
     };
+    QXLInterface *qif = qxl_get_interface(worker->qxl);
 
-    if (worker->qxl->st->qif->base.major_version < 3 ||
-        (worker->qxl->st->qif->base.major_version == 3 &&
-        worker->qxl->st->qif->base.minor_version < 2) ||
-        !worker->qxl->st->qif->set_client_capabilities) {
+    if (qif->base.major_version < 3 ||
+        (qif->base.major_version == 3 &&
+        qif->base.minor_version < 2) ||
+        !qif->set_client_capabilities) {
         return;
     }
 #define SET_CAP(a,c)                                                    \
@@ -525,7 +526,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
     }
     if ((worker->display_channel == NULL) ||
         (RED_CHANNEL(worker->display_channel)->clients_num == 0)) {
-        worker->qxl->st->qif->set_client_capabilities(worker->qxl, FALSE, caps);
+        qif->set_client_capabilities(worker->qxl, FALSE, caps);
     } else {
         // Take least common denominator
         for (i = 0 ; i < sizeof(caps_available) / sizeof(caps_available[0]); ++i) {
@@ -538,7 +539,7 @@ static void guest_set_client_capabilities(RedWorker *worker)
                     CLEAR_CAP(caps, caps_available[i]);
             }
         }
-        worker->qxl->st->qif->set_client_capabilities(worker->qxl, TRUE, caps);
+        qif->set_client_capabilities(worker->qxl, TRUE, caps);
     }
 }
 
@@ -577,15 +578,15 @@ static void handle_dev_update_async(void *opaque, void *payload)
     uint32_t num_dirty_rects = 0;
 
     spice_return_if_fail(worker->running);
-    spice_return_if_fail(worker->qxl->st->qif->update_area_complete);
+    spice_return_if_fail(qxl_get_interface(worker->qxl)->update_area_complete);
 
     flush_display_commands(worker);
     display_channel_update(worker->display_channel,
                            msg->surface_id, &msg->qxl_area, msg->clear_dirty_region,
                            &qxl_dirty_rects, &num_dirty_rects);
 
-    worker->qxl->st->qif->update_area_complete(worker->qxl, msg->surface_id,
-                                                qxl_dirty_rects, num_dirty_rects);
+    qxl_get_interface(worker->qxl)->update_area_complete(worker->qxl, msg->surface_id,
+                                                         qxl_dirty_rects, num_dirty_rects);
     free(qxl_dirty_rects);
 }
 
@@ -823,7 +824,7 @@ static void handle_dev_wakeup(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     stat_inc_counter(reds, worker->wakeup_counter, 1);
-    red_qxl_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_WAKEUP);
+    red_qxl_clear_pending(worker->qxl_state, RED_DISPATCHER_PENDING_WAKEUP);
 }
 
 static void handle_dev_oom(void *opaque, void *payload)
@@ -844,16 +845,16 @@ static void handle_dev_oom(void *opaque, void *payload)
     while (red_process_display(worker, &ring_is_empty)) {
         red_channel_push(display_red_channel);
     }
-    if (worker->qxl->st->qif->flush_resources(worker->qxl) == 0) {
+    if (qxl_get_interface(worker->qxl)->flush_resources(worker->qxl) == 0) {
         display_channel_free_some(worker->display_channel);
-        worker->qxl->st->qif->flush_resources(worker->qxl);
+        qxl_get_interface(worker->qxl)->flush_resources(worker->qxl);
     }
     spice_debug("OOM2 #draw=%u, #glz_draw=%u current %u pipes %u",
                 display->drawable_count,
                 display->glz_drawable_count,
                 display->current_size,
                 red_channel_sum_pipes_size(display_red_channel));
-    red_qxl_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_OOM);
+    red_qxl_clear_pending(worker->qxl_state, RED_DISPATCHER_PENDING_OOM);
 }
 
 static void handle_dev_reset_cursor(void *opaque, void *payload)
@@ -1194,7 +1195,7 @@ static void worker_handle_dispatcher_async_done(void *opaque,
     RedWorkerMessageAsync *msg_async = payload;
 
     spice_debug(NULL);
-    red_qxl_async_complete(worker->red_dispatcher, msg_async->cmd);
+    red_qxl_async_complete(worker->qxl_state, msg_async->cmd);
 }
 
 static void worker_dispatcher_record(void *opaque, uint32_t message_type, void *payload)
@@ -1462,14 +1463,14 @@ static GSourceFuncs worker_source_funcs = {
     .dispatch = worker_source_dispatch,
 };
 
-RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher)
+RedWorker* red_worker_new(QXLInstance *qxl, QXLState *qxl_state)
 {
     QXLDevInitInfo init_info;
     RedWorker *worker;
     Dispatcher *dispatcher;
     const char *record_filename;
 
-    qxl->st->qif->get_init_info(qxl, &init_info);
+    qxl_get_interface(qxl)->get_init_info(qxl, &init_info);
 
     worker = spice_new0(RedWorker, 1);
     worker->core = event_loop_core;
@@ -1487,10 +1488,10 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher)
             spice_error("failed to write replay header");
         }
     }
-    dispatcher = red_qxl_get_dispatcher(red_dispatcher);
+    dispatcher = red_qxl_get_dispatcher(qxl_state);
     dispatcher_set_opaque(dispatcher, worker);
 
-    worker->red_dispatcher = red_dispatcher;
+    worker->qxl_state = qxl_state;
     worker->qxl = qxl;
     register_callbacks(dispatcher);
     if (worker->record_fd) {
diff --git a/server/red-worker.h b/server/red-worker.h
index e51e261..0f9cf61 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -90,7 +90,7 @@ static inline void red_pipes_add_verb(RedChannel *channel, uint16_t verb)
     }
 }
 
-RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher);
+RedWorker* red_worker_new(QXLInstance *qxl, QXLState *qxl_state);
 bool       red_worker_run(RedWorker *worker);
 RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
 RedChannel* red_worker_get_display_channel(RedWorker *worker);
diff --git a/server/reds-private.h b/server/reds-private.h
index f567929..6bd6878 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -241,7 +241,7 @@ struct RedsState {
 
     RedSSLParameters ssl_parameters;
     SpiceCoreInterfaceInternal *core;
-    GList *dispatchers;
+    GList *qxl_states;
     MainDispatcher *main_dispatcher;
 };
 
diff --git a/server/reds.c b/server/reds.c
index ab923e9..15a31f9 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -570,8 +570,8 @@ static void reds_set_mouse_mode(RedsState *reds, uint32_t mode)
     }
     reds->mouse_mode = mode;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next)
-        red_qxl_set_mouse_mode(l->data, mode);
+    for (l = reds->qxl_states; l != NULL; l = l->next)
+        red_qxl_set_mouse_mode((QXLState*) l->data, mode);
 
     main_channel_push_mouse_mode(reds->main_channel, reds->mouse_mode, reds->is_client_mouse_allowed);
 }
@@ -584,7 +584,7 @@ gboolean reds_get_agent_mouse(const RedsState *reds)
 static void reds_update_mouse_mode(RedsState *reds)
 {
     int allowed = 0;
-    int qxl_count = g_list_length(reds->dispatchers);
+    int qxl_count = g_list_length(reds->qxl_states);
 
     if ((reds->agent_mouse && reds->vdagent) ||
         (inputs_channel_has_tablet(reds->inputs_channel) && qxl_count == 1)) {
@@ -1681,7 +1681,7 @@ static void reds_handle_main_link(RedsState *reds, RedLinkInfo *link)
     }
 
     if (!mig_target) {
-        main_channel_push_init(mcc, g_list_length(reds->dispatchers),
+        main_channel_push_init(mcc, g_list_length(reds->qxl_states),
             reds->mouse_mode, reds->is_client_mouse_allowed,
             reds_get_mm_time() - MM_TIME_DELTA,
             reds_qxl_ram_size(reds));
@@ -1827,7 +1827,7 @@ void reds_on_client_semi_seamless_migrate_complete(RedsState *reds, RedClient *c
     mcc = red_client_get_main(client);
 
     // TODO: not doing net test. consider doing it on client_migrate_info
-    main_channel_push_init(mcc, g_list_length(reds->dispatchers),
+    main_channel_push_init(mcc, g_list_length(reds->qxl_states),
                            reds->mouse_mode, reds->is_client_mouse_allowed,
                            reds_get_mm_time() - MM_TIME_DELTA,
                            reds_qxl_ram_size(reds));
@@ -3199,7 +3199,7 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
         }
     } else if (strcmp(interface->type, SPICE_INTERFACE_QXL) == 0) {
         QXLInstance *qxl;
-        RedDispatcher *dispatcher;
+        QXLState *qxl_state;
 
         spice_info("SPICE_INTERFACE_QXL");
         if (interface->major_version != SPICE_INTERFACE_QXL_MAJOR ||
@@ -3209,21 +3209,17 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
         }
 
         qxl = SPICE_CONTAINEROF(sin, QXLInstance, base);
-        qxl->st = spice_new0(QXLState, 1);
-        pthread_mutex_init(&qxl->st->scanout_mutex, NULL);
-        qxl->st->scanout.drm_dma_buf_fd = -1;
-        qxl->st->qif = SPICE_CONTAINEROF(interface, QXLInterface, base);
         red_qxl_init(qxl);
-        dispatcher = qxl->st->dispatcher;
-        reds->dispatchers = g_list_prepend(reds->dispatchers, dispatcher);
+        qxl_state = qxl->st;
+        reds->qxl_states = g_list_prepend(reds->qxl_states, qxl_state);
 
-        /* this function has to be called after the dispatcher is on the list
-         * as QXLInstance clients expect the dispatcher to be on the list when
+        /* this function has to be called after the qxl is on the list
+         * as QXLInstance clients expect the qxl to be on the list when
          * this callback is called. This as clients assume they can start the
-         * dispatchers. Also note that this should be the first callback to
+         * qxl_states. Also note that this should be the first callback to
          * be called. */
-        red_qxl_attach_worker(dispatcher);
-        red_qxl_set_compression_level(dispatcher, calc_compression_level(reds));
+        red_qxl_attach_worker(qxl_state);
+        red_qxl_set_compression_level(qxl_state, calc_compression_level(reds));
     } else if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
         SpiceTabletInstance *tablet = SPICE_CONTAINEROF(sin, SpiceTabletInstance, base);
         spice_info("SPICE_INTERFACE_TABLET");
@@ -4150,13 +4146,13 @@ void reds_update_client_mouse_allowed(RedsState *reds)
     int x_res = 0;
     int y_res = 0;
     GList *l;
-    int num_active_workers = g_list_length(reds->dispatchers);
+    int num_active_workers = g_list_length(reds->qxl_states);
 
     if (num_active_workers > 0) {
         allow_now = TRUE;
-        for (l = reds->dispatchers; l != NULL && allow_now; l = l->next) {
+        for (l = reds->qxl_states; l != NULL && allow_now; l = l->next) {
 
-            RedDispatcher *now = l->data;
+            QXLState *now = l->data;
             if (red_qxl_get_primary_active(now)) {
                 allow_now = red_qxl_get_allow_client_mouse(now, &x_res, &y_res);
                 break;
@@ -4174,12 +4170,12 @@ gboolean reds_use_client_monitors_config(RedsState *reds)
 {
     GList *l;
 
-    if (reds->dispatchers == NULL) {
+    if (reds->qxl_states == NULL) {
         return FALSE;
     }
 
-    for (l = reds->dispatchers; l != NULL ; l = l->next) {
-        RedDispatcher *now = l->data;
+    for (l = reds->qxl_states; l != NULL ; l = l->next) {
+        QXLState *now = l->data;
 
         if (!red_qxl_use_client_monitors_config(now))
             return FALSE;
@@ -4191,8 +4187,8 @@ void reds_client_monitors_config(RedsState *reds, VDAgentMonitorsConfig *monitor
 {
     GList *l;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next) {
-        RedDispatcher *now = l->data;
+    for (l = reds->qxl_states; l != NULL; l = l->next) {
+        QXLState *now = l->data;
         if (!red_qxl_client_monitors_config(now, monitors_config)) {
             /* this is a normal condition, some qemu devices might not implement it */
             spice_debug("QXLInterface::client_monitors_config failed\n");
@@ -4204,8 +4200,8 @@ void reds_set_mm_time(RedsState *reds, uint32_t mm_time)
 {
     GList *l;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next) {
-        RedDispatcher *now = l->data;
+    for (l = reds->qxl_states; l != NULL; l = l->next) {
+        QXLState *now = l->data;
         red_qxl_set_mm_time(now, mm_time);
     }
 }
@@ -4227,10 +4223,10 @@ void reds_on_ic_change(RedsState *reds)
     int compression_level = calc_compression_level(reds);
     GList *l;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next) {
-        RedDispatcher *d = l->data;
-        red_qxl_set_compression_level(d, compression_level);
-        red_qxl_on_ic_change(d, spice_server_get_image_compression(reds));
+    for (l = reds->qxl_states; l != NULL; l = l->next) {
+        QXLState *q = l->data;
+        red_qxl_set_compression_level(q, compression_level);
+        red_qxl_on_ic_change(q, spice_server_get_image_compression(reds));
     }
 }
 
@@ -4239,10 +4235,10 @@ void reds_on_sv_change(RedsState *reds)
     int compression_level = calc_compression_level(reds);
     GList *l;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next) {
-        RedDispatcher *d = l->data;
-        red_qxl_set_compression_level(d, compression_level);
-        red_qxl_on_sv_change(d, reds_get_streaming_video(reds));
+    for (l = reds->qxl_states; l != NULL; l = l->next) {
+        QXLState *q = l->data;
+        red_qxl_set_compression_level(q, compression_level);
+        red_qxl_on_sv_change(q, reds_get_streaming_video(reds));
     }
 }
 
@@ -4250,26 +4246,26 @@ void reds_on_vm_stop(RedsState *reds)
 {
     GList *l;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next)
-        red_qxl_stop(l->data);
+    for (l = reds->qxl_states; l != NULL; l = l->next)
+        red_qxl_stop((QXLState*) l->data);
 }
 
 void reds_on_vm_start(RedsState *reds)
 {
     GList *l;
 
-    for (l = reds->dispatchers; l != NULL; l = l->next)
-        red_qxl_start(l->data);
+    for (l = reds->qxl_states; l != NULL; l = l->next)
+        red_qxl_start((QXLState*) l->data);
 }
 
 uint32_t reds_qxl_ram_size(RedsState *reds)
 {
-    RedDispatcher *first;
-    if (!reds->dispatchers) {
+    QXLState *first;
+    if (!reds->qxl_states) {
         return 0;
     }
 
-    first = reds->dispatchers->data;
+    first = reds->qxl_states->data;
     return red_qxl_get_ram_size(first);
 }
 
diff --git a/server/reds.h b/server/reds.h
index 4c0dfe4..18fae58 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -34,13 +34,10 @@
 typedef struct RedsState RedsState;
 extern RedsState *reds;
 
-struct QXLState {
-    QXLInterface          *qif;
-    struct RedDispatcher  *dispatcher;
-    pthread_mutex_t scanout_mutex;
-    SpiceMsgDisplayGlScanoutUnix scanout;
-    struct AsyncCommand *gl_draw_async;
-};
+static inline QXLInterface * qxl_get_interface(QXLInstance *qxl)
+{
+    return SPICE_CONTAINEROF(qxl->base.sif, QXLInterface, base);
+}
 
 struct TunnelWorker;
 struct SpiceNetWireState {
commit 5916dd8fa62e28d78284d63edf06ddf506a970c0
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Feb 25 18:29:01 2016 +0000

    rename red-dispatcher.* files to red-qxl.*
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/Makefile.am b/server/Makefile.am
index 9eb5f44..a7a8d9f 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -93,8 +93,8 @@ libserver_la_SOURCES =				\
 	red-common.h				\
 	dispatcher.c				\
 	dispatcher.h				\
-	red-dispatcher.c			\
-	red-dispatcher.h			\
+	red-qxl.c				\
+	red-qxl.h				\
 	main-dispatcher.c			\
 	main-dispatcher.h			\
 	migration-protocol.h		\
diff --git a/server/agent-msg-filter.c b/server/agent-msg-filter.c
index d72a3e4..a6aee9e 100644
--- a/server/agent-msg-filter.c
+++ b/server/agent-msg-filter.c
@@ -25,7 +25,7 @@
 #include "red-common.h"
 #include "agent-msg-filter.h"
 #include "reds.h"
-#include "red-dispatcher.h"
+#include "red-qxl.h"
 
 void agent_msg_filter_init(struct AgentMsgFilter *filter,
                            gboolean copy_paste, gboolean file_xfer,
diff --git a/server/display-channel.h b/server/display-channel.h
index cf40edd..1bccd22 100644
--- a/server/display-channel.h
+++ b/server/display-channel.h
@@ -33,7 +33,7 @@
 #include "red-record-qxl.h"
 #include "demarshallers.h"
 #include "red-channel.h"
-#include "red-dispatcher.h"
+#include "red-qxl.h"
 #include "dispatcher.h"
 #include "main-channel.h"
 #include "migration-protocol.h"
diff --git a/server/red-dispatcher.c b/server/red-dispatcher.c
deleted file mode 100644
index 7718458..0000000
--- a/server/red-dispatcher.c
+++ /dev/null
@@ -1,1032 +0,0 @@
-/*
-   Copyright (C) 2009 Red Hat, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <pthread.h>
-#include <sys/socket.h>
-#include <inttypes.h>
-
-#include <spice/qxl_dev.h>
-#include "common/quic.h"
-
-#include "spice.h"
-#include "red-worker.h"
-#include "sw-canvas.h"
-#include "reds.h"
-#include "dispatcher.h"
-#include "red-parse-qxl.h"
-
-#include "red-dispatcher.h"
-
-
-struct AsyncCommand {
-    RedWorkerMessage message;
-    uint64_t cookie;
-};
-
-struct RedDispatcher {
-    QXLWorker base;
-    QXLInstance *qxl;
-    Dispatcher dispatcher;
-    uint32_t pending;
-    int primary_active;
-    int x_res;
-    int y_res;
-    int use_hardware_cursor;
-    QXLDevSurfaceCreate surface_create;
-    unsigned int max_monitors;
-};
-
-static int red_qxl_check_qxl_version(RedDispatcher *rd, int major, int minor)
-{
-    int qxl_major = rd->qxl->st->qif->base.major_version;
-    int qxl_minor = rd->qxl->st->qif->base.minor_version;
-
-    return ((qxl_major > major) ||
-            ((qxl_major == major) && (qxl_minor >= minor)));
-}
-
-static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
-                                     RedsStream *stream, int migration,
-                                     int num_common_caps, uint32_t *common_caps, int num_caps,
-                                     uint32_t *caps)
-{
-    RedWorkerMessageDisplayConnect payload = {0,};
-    RedDispatcher *dispatcher;
-
-    spice_debug("%s", "");
-    dispatcher = (RedDispatcher *)channel->data;
-    payload.client = client;
-    payload.stream = stream;
-    payload.migration = migration;
-    payload.num_common_caps = num_common_caps;
-    payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
-    payload.num_caps = num_caps;
-    payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
-
-    memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
-    memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DISPLAY_CONNECT,
-                            &payload);
-}
-
-static void red_qxl_disconnect_display_peer(RedChannelClient *rcc)
-{
-    RedWorkerMessageDisplayDisconnect payload;
-    RedDispatcher *dispatcher;
-
-    if (!rcc->channel) {
-        return;
-    }
-
-    dispatcher = (RedDispatcher *)rcc->channel->data;
-
-    spice_printerr("");
-    payload.rcc = rcc;
-
-    // TODO: we turned it to be sync, due to client_destroy . Should we support async? - for this we will need ref count
-    // for channels
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
-                            &payload);
-}
-
-static void red_qxl_display_migrate(RedChannelClient *rcc)
-{
-    RedWorkerMessageDisplayMigrate payload;
-    RedDispatcher *dispatcher;
-    if (!rcc->channel) {
-        return;
-    }
-    dispatcher = (RedDispatcher *)rcc->channel->data;
-    spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
-    payload.rcc = rcc;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
-                            &payload);
-}
-
-static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
-                                    int migration, int num_common_caps,
-                                    uint32_t *common_caps, int num_caps,
-                                    uint32_t *caps)
-{
-    RedWorkerMessageCursorConnect payload = {0,};
-    RedDispatcher *dispatcher = (RedDispatcher *)channel->data;
-    spice_printerr("");
-    payload.client = client;
-    payload.stream = stream;
-    payload.migration = migration;
-    payload.num_common_caps = num_common_caps;
-    payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
-    payload.num_caps = num_caps;
-    payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
-
-    memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
-    memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_CURSOR_CONNECT,
-                            &payload);
-}
-
-static void red_qxl_disconnect_cursor_peer(RedChannelClient *rcc)
-{
-    RedWorkerMessageCursorDisconnect payload;
-    RedDispatcher *dispatcher;
-
-    if (!rcc->channel) {
-        return;
-    }
-
-    dispatcher = (RedDispatcher *)rcc->channel->data;
-    spice_printerr("");
-    payload.rcc = rcc;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
-                            &payload);
-}
-
-static void red_qxl_cursor_migrate(RedChannelClient *rcc)
-{
-    RedWorkerMessageCursorMigrate payload;
-    RedDispatcher *dispatcher;
-
-    if (!rcc->channel) {
-        return;
-    }
-    dispatcher = (RedDispatcher *)rcc->channel->data;
-    spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
-    payload.rcc = rcc;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_CURSOR_MIGRATE,
-                            &payload);
-}
-
-static void red_qxl_update_area(RedDispatcher *dispatcher, uint32_t surface_id,
-                                QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
-                                uint32_t num_dirty_rects, uint32_t clear_dirty_region)
-{
-    RedWorkerMessageUpdate payload = {0,};
-
-    payload.surface_id = surface_id;
-    payload.qxl_area = qxl_area;
-    payload.qxl_dirty_rects = qxl_dirty_rects;
-    payload.num_dirty_rects = num_dirty_rects;
-    payload.clear_dirty_region = clear_dirty_region;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_UPDATE,
-                            &payload);
-}
-
-gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher)
-{
-    return (red_qxl_check_qxl_version(dispatcher, 3, 3) &&
-        dispatcher->qxl->st->qif->client_monitors_config &&
-        dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl, NULL));
-}
-
-gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher,
-                                        VDAgentMonitorsConfig *monitors_config)
-{
-    return (dispatcher->qxl->st->qif->client_monitors_config &&
-        dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl,
-                                                          monitors_config));
-}
-
-static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
-                                         RedWorkerMessage message,
-                                         uint64_t cookie)
-{
-    AsyncCommand *async_command = spice_new0(AsyncCommand, 1);
-
-    async_command->cookie = cookie;
-    async_command->message = message;
-
-    spice_debug("%p", async_command);
-    return async_command;
-}
-
-static void red_qxl_update_area_async(RedDispatcher *dispatcher,
-                                      uint32_t surface_id,
-                                      QXLRect *qxl_area,
-                                      uint32_t clear_dirty_region,
-                                      uint64_t cookie)
-{
-    RedWorkerMessage message = RED_WORKER_MESSAGE_UPDATE_ASYNC;
-    RedWorkerMessageUpdateAsync payload;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    payload.surface_id = surface_id;
-    payload.qxl_area = *qxl_area;
-    payload.clear_dirty_region = clear_dirty_region;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            message,
-                            &payload);
-}
-
-static void qxl_worker_update_area(QXLWorker *qxl_worker, uint32_t surface_id,
-                                   QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
-                                   uint32_t num_dirty_rects, uint32_t clear_dirty_region)
-{
-    red_qxl_update_area((RedDispatcher*)qxl_worker, surface_id, qxl_area,
-                        qxl_dirty_rects, num_dirty_rects, clear_dirty_region);
-}
-
-static void red_qxl_add_memslot(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot)
-{
-    RedWorkerMessageAddMemslot payload;
-
-    payload.mem_slot = *mem_slot;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_ADD_MEMSLOT,
-                            &payload);
-}
-
-static void qxl_worker_add_memslot(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slot)
-{
-    red_qxl_add_memslot((RedDispatcher*)qxl_worker, mem_slot);
-}
-
-static void red_qxl_add_memslot_async(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot, uint64_t cookie)
-{
-    RedWorkerMessageAddMemslotAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    payload.mem_slot = *mem_slot;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void red_qxl_del_memslot(RedDispatcher *dispatcher, uint32_t slot_group_id, uint32_t slot_id)
-{
-    RedWorkerMessageDelMemslot payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_DEL_MEMSLOT;
-
-    payload.slot_group_id = slot_group_id;
-    payload.slot_id = slot_id;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void qxl_worker_del_memslot(QXLWorker *qxl_worker, uint32_t slot_group_id, uint32_t slot_id)
-{
-    red_qxl_del_memslot((RedDispatcher*)qxl_worker, slot_group_id, slot_id);
-}
-
-static void red_qxl_destroy_surfaces(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageDestroySurfaces payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DESTROY_SURFACES,
-                            &payload);
-}
-
-static void qxl_worker_destroy_surfaces(QXLWorker *qxl_worker)
-{
-    red_qxl_destroy_surfaces((RedDispatcher*)qxl_worker);
-}
-
-static void red_qxl_destroy_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
-{
-    RedWorkerMessageDestroySurfacesAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void red_qxl_destroy_primary_surface_complete(RedDispatcher *dispatcher)
-{
-    dispatcher->x_res = 0;
-    dispatcher->y_res = 0;
-    dispatcher->use_hardware_cursor = FALSE;
-    dispatcher->primary_active = FALSE;
-
-    reds_update_client_mouse_allowed(reds);
-}
-
-static void
-red_qxl_destroy_primary_surface_sync(RedDispatcher *dispatcher,
-                                     uint32_t surface_id)
-{
-    RedWorkerMessageDestroyPrimarySurface payload;
-    payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
-                            &payload);
-    red_qxl_destroy_primary_surface_complete(dispatcher);
-}
-
-static void
-red_qxl_destroy_primary_surface_async(RedDispatcher *dispatcher,
-                                      uint32_t surface_id, uint64_t cookie)
-{
-    RedWorkerMessageDestroyPrimarySurfaceAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void
-red_qxl_destroy_primary_surface(RedDispatcher *dispatcher,
-                                uint32_t surface_id, int async, uint64_t cookie)
-{
-    if (async) {
-        red_qxl_destroy_primary_surface_async(dispatcher, surface_id, cookie);
-    } else {
-        red_qxl_destroy_primary_surface_sync(dispatcher, surface_id);
-    }
-}
-
-static void qxl_worker_destroy_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id)
-{
-    red_qxl_destroy_primary_surface((RedDispatcher*)qxl_worker, surface_id, 0, 0);
-}
-
-static void red_qxl_create_primary_surface_complete(RedDispatcher *dispatcher)
-{
-    QXLDevSurfaceCreate *surface = &dispatcher->surface_create;
-
-    dispatcher->x_res = surface->width;
-    dispatcher->y_res = surface->height;
-    dispatcher->use_hardware_cursor = surface->mouse_mode;
-    dispatcher->primary_active = TRUE;
-
-    reds_update_client_mouse_allowed(reds);
-    memset(&dispatcher->surface_create, 0, sizeof(QXLDevSurfaceCreate));
-}
-
-static void
-red_qxl_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t surface_id,
-                                     QXLDevSurfaceCreate *surface, uint64_t cookie)
-{
-    RedWorkerMessageCreatePrimarySurfaceAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC;
-
-    dispatcher->surface_create = *surface;
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    payload.surface_id = surface_id;
-    payload.surface = *surface;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void
-red_qxl_create_primary_surface_sync(RedDispatcher *dispatcher, uint32_t surface_id,
-                                    QXLDevSurfaceCreate *surface)
-{
-    RedWorkerMessageCreatePrimarySurface payload = {0,};
-
-    dispatcher->surface_create = *surface;
-    payload.surface_id = surface_id;
-    payload.surface = *surface;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
-                            &payload);
-    red_qxl_create_primary_surface_complete(dispatcher);
-}
-
-static void
-red_qxl_create_primary_surface(RedDispatcher *dispatcher, uint32_t surface_id,
-                               QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
-{
-    if (async) {
-        red_qxl_create_primary_surface_async(dispatcher, surface_id, surface, cookie);
-    } else {
-        red_qxl_create_primary_surface_sync(dispatcher, surface_id, surface);
-    }
-}
-
-static void qxl_worker_create_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id,
-                                      QXLDevSurfaceCreate *surface)
-{
-    red_qxl_create_primary_surface((RedDispatcher*)qxl_worker, surface_id, surface, 0, 0);
-}
-
-static void red_qxl_reset_image_cache(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageResetImageCache payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
-                            &payload);
-}
-
-static void qxl_worker_reset_image_cache(QXLWorker *qxl_worker)
-{
-    red_qxl_reset_image_cache((RedDispatcher*)qxl_worker);
-}
-
-static void red_qxl_reset_cursor(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageResetCursor payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_RESET_CURSOR,
-                            &payload);
-}
-
-static void qxl_worker_reset_cursor(QXLWorker *qxl_worker)
-{
-    red_qxl_reset_cursor((RedDispatcher*)qxl_worker);
-}
-
-static void red_qxl_destroy_surface_wait_sync(RedDispatcher *dispatcher,
-                                              uint32_t surface_id)
-{
-    RedWorkerMessageDestroySurfaceWait payload;
-
-    payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
-                            &payload);
-}
-
-static void red_qxl_destroy_surface_wait_async(RedDispatcher *dispatcher,
-                                               uint32_t surface_id,
-                                               uint64_t cookie)
-{
-    RedWorkerMessageDestroySurfaceWaitAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    payload.surface_id = surface_id;
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void red_qxl_destroy_surface_wait(RedDispatcher *dispatcher,
-                                         uint32_t surface_id,
-                                         int async, uint64_t cookie)
-{
-    if (async) {
-        red_qxl_destroy_surface_wait_async(dispatcher, surface_id, cookie);
-    } else {
-        red_qxl_destroy_surface_wait_sync(dispatcher, surface_id);
-    }
-}
-
-static void qxl_worker_destroy_surface_wait(QXLWorker *qxl_worker, uint32_t surface_id)
-{
-    red_qxl_destroy_surface_wait((RedDispatcher*)qxl_worker, surface_id, 0, 0);
-}
-
-static void red_qxl_reset_memslots(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageResetMemslots payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_RESET_MEMSLOTS,
-                            &payload);
-}
-
-static void qxl_worker_reset_memslots(QXLWorker *qxl_worker)
-{
-    red_qxl_reset_memslots((RedDispatcher*)qxl_worker);
-}
-
-static bool red_qxl_set_pending(RedDispatcher *dispatcher, int pending)
-{
-    // this is not atomic but is not an issue
-    if (test_bit(pending, dispatcher->pending)) {
-        return TRUE;
-    }
-
-    set_bit(pending, &dispatcher->pending);
-    return FALSE;
-}
-
-static void red_qxl_wakeup(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageWakeup payload;
-
-    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_WAKEUP))
-        return;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_WAKEUP,
-                            &payload);
-}
-
-static void qxl_worker_wakeup(QXLWorker *qxl_worker)
-{
-    red_qxl_wakeup((RedDispatcher*)qxl_worker);
-}
-
-static void red_qxl_oom(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageOom payload;
-
-    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_OOM))
-        return;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_OOM,
-                            &payload);
-}
-
-static void qxl_worker_oom(QXLWorker *qxl_worker)
-{
-    red_qxl_oom((RedDispatcher*)qxl_worker);
-}
-
-void red_qxl_start(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageStart payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_START,
-                            &payload);
-}
-
-static void qxl_worker_start(QXLWorker *qxl_worker)
-{
-    red_qxl_start((RedDispatcher*)qxl_worker);
-}
-
-static void red_qxl_flush_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
-{
-    RedWorkerMessageFlushSurfacesAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void red_qxl_monitors_config_async(RedDispatcher *dispatcher,
-                                          QXLPHYSICAL monitors_config,
-                                          int group_id,
-                                          uint64_t cookie)
-{
-    RedWorkerMessageMonitorsConfigAsync payload;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC;
-
-    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
-    payload.monitors_config = monitors_config;
-    payload.group_id = group_id;
-    payload.max_monitors = dispatcher->max_monitors;
-
-    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
-}
-
-static void red_qxl_driver_unload(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageDriverUnload payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_DRIVER_UNLOAD,
-                            &payload);
-}
-
-void red_qxl_stop(RedDispatcher *dispatcher)
-{
-    RedWorkerMessageStop payload;
-
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_STOP,
-                            &payload);
-}
-
-static void qxl_worker_stop(QXLWorker *qxl_worker)
-{
-    red_qxl_stop((RedDispatcher*)qxl_worker);
-}
-
-static void red_qxl_loadvm_commands(RedDispatcher *dispatcher,
-                                    struct QXLCommandExt *ext,
-                                    uint32_t count)
-{
-    RedWorkerMessageLoadvmCommands payload;
-
-    spice_printerr("");
-    payload.count = count;
-    payload.ext = ext;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_LOADVM_COMMANDS,
-                            &payload);
-}
-
-static void qxl_worker_loadvm_commands(QXLWorker *qxl_worker,
-                                       struct QXLCommandExt *ext,
-                                       uint32_t count)
-{
-    red_qxl_loadvm_commands((RedDispatcher*)qxl_worker, ext, count);
-}
-
-void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t mm_time)
-{
-    dispatcher->qxl->st->qif->set_mm_time(dispatcher->qxl, mm_time);
-}
-
-void red_qxl_attach_worker(RedDispatcher *dispatcher)
-{
-    QXLInstance *qxl = dispatcher->qxl;
-    qxl->st->qif->attache_worker(qxl, &dispatcher->base);
-}
-
-void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level)
-{
-    dispatcher->qxl->st->qif->set_compression_level(dispatcher->qxl, level);
-}
-
-uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher)
-{
-    QXLDevInitInfo qxl_info;
-    dispatcher->qxl->st->qif->get_init_info(dispatcher->qxl, &qxl_info);
-    return qxl_info.qxl_ram_size;
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_wakeup(QXLInstance *instance)
-{
-    red_qxl_wakeup(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_oom(QXLInstance *instance)
-{
-    red_qxl_oom(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_start(QXLInstance *instance)
-{
-    red_qxl_start(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_stop(QXLInstance *instance)
-{
-    red_qxl_stop(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_update_area(QXLInstance *instance, uint32_t surface_id,
-                    struct QXLRect *area, struct QXLRect *dirty_rects,
-                    uint32_t num_dirty_rects, uint32_t clear_dirty_region)
-{
-    red_qxl_update_area(instance->st->dispatcher, surface_id, area, dirty_rects,
-                        num_dirty_rects, clear_dirty_region);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_add_memslot(QXLInstance *instance, QXLDevMemSlot *slot)
-{
-    red_qxl_add_memslot(instance->st->dispatcher, slot);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_del_memslot(QXLInstance *instance, uint32_t slot_group_id, uint32_t slot_id)
-{
-    red_qxl_del_memslot(instance->st->dispatcher, slot_group_id, slot_id);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_reset_memslots(QXLInstance *instance)
-{
-    red_qxl_reset_memslots(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_destroy_surfaces(QXLInstance *instance)
-{
-    red_qxl_destroy_surfaces(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_destroy_primary_surface(QXLInstance *instance, uint32_t surface_id)
-{
-    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 0, 0);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_create_primary_surface(QXLInstance *instance, uint32_t surface_id,
-                                QXLDevSurfaceCreate *surface)
-{
-    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 0, 0);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_reset_image_cache(QXLInstance *instance)
-{
-    red_qxl_reset_image_cache(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_reset_cursor(QXLInstance *instance)
-{
-    red_qxl_reset_cursor(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_destroy_surface_wait(QXLInstance *instance, uint32_t surface_id)
-{
-    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 0, 0);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_loadvm_commands(QXLInstance *instance, struct QXLCommandExt *ext, uint32_t count)
-{
-    red_qxl_loadvm_commands(instance->st->dispatcher, ext, count);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_update_area_async(QXLInstance *instance, uint32_t surface_id, QXLRect *qxl_area,
-                                 uint32_t clear_dirty_region, uint64_t cookie)
-{
-    red_qxl_update_area_async(instance->st->dispatcher, surface_id, qxl_area,
-                                     clear_dirty_region, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_add_memslot_async(QXLInstance *instance, QXLDevMemSlot *slot, uint64_t cookie)
-{
-    red_qxl_add_memslot_async(instance->st->dispatcher, slot, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_destroy_surfaces_async(QXLInstance *instance, uint64_t cookie)
-{
-    red_qxl_destroy_surfaces_async(instance->st->dispatcher, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_destroy_primary_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
-{
-    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 1, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_create_primary_surface_async(QXLInstance *instance, uint32_t surface_id,
-                                QXLDevSurfaceCreate *surface, uint64_t cookie)
-{
-    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 1, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_destroy_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
-{
-    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 1, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_flush_surfaces_async(QXLInstance *instance, uint64_t cookie)
-{
-    red_qxl_flush_surfaces_async(instance->st->dispatcher, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_monitors_config_async(QXLInstance *instance, QXLPHYSICAL monitors_config,
-                                     int group_id, uint64_t cookie)
-{
-    red_qxl_monitors_config_async(instance->st->dispatcher, monitors_config, group_id, cookie);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_set_max_monitors(QXLInstance *instance, unsigned int max_monitors)
-{
-    instance->st->dispatcher->max_monitors = MAX(1u, max_monitors);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_driver_unload(QXLInstance *instance)
-{
-    red_qxl_driver_unload(instance->st->dispatcher);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_gl_scanout(QXLInstance *qxl,
-                          int fd,
-                          uint32_t width, uint32_t height,
-                          uint32_t stride, uint32_t format,
-                          int y_0_top)
-{
-    spice_return_if_fail(qxl != NULL);
-    spice_return_if_fail(qxl->st->gl_draw_async == NULL);
-
-    pthread_mutex_lock(&qxl->st->scanout_mutex);
-
-    if (qxl->st->scanout.drm_dma_buf_fd != -1) {
-        close(qxl->st->scanout.drm_dma_buf_fd);
-    }
-
-    qxl->st->scanout = (SpiceMsgDisplayGlScanoutUnix) {
-        .flags = y_0_top ? SPICE_GL_SCANOUT_FLAGS_Y0TOP : 0,
-        .drm_dma_buf_fd = fd,
-        .width = width,
-        .height = height,
-        .stride = stride,
-        .drm_fourcc_format = format
-    };
-
-    pthread_mutex_unlock(&qxl->st->scanout_mutex);
-
-    /* FIXME: find a way to coallesce all pending SCANOUTs */
-    dispatcher_send_message(&qxl->st->dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_GL_SCANOUT, NULL);
-}
-
-SPICE_GNUC_VISIBLE
-void spice_qxl_gl_draw_async(QXLInstance *qxl,
-                             uint32_t x, uint32_t y,
-                             uint32_t w, uint32_t h,
-                             uint64_t cookie)
-{
-    RedDispatcher *dispatcher;
-    RedWorkerMessage message = RED_WORKER_MESSAGE_GL_DRAW_ASYNC;
-    SpiceMsgDisplayGlDraw draw = {
-        .x = x,
-        .y = y,
-        .w = w,
-        .h = h
-    };
-
-    spice_return_if_fail(qxl != NULL);
-    spice_return_if_fail(qxl->st->scanout.drm_dma_buf_fd != -1);
-    spice_return_if_fail(qxl->st->gl_draw_async == NULL);
-
-    dispatcher = qxl->st->dispatcher;
-    qxl->st->gl_draw_async = async_command_alloc(dispatcher, message, cookie);
-    dispatcher_send_message(&dispatcher->dispatcher, message, &draw);
-}
-
-void red_qxl_async_complete(struct RedDispatcher *dispatcher,
-                            AsyncCommand *async_command)
-{
-    spice_debug("%p: cookie %" PRId64, async_command, async_command->cookie);
-    switch (async_command->message) {
-    case RED_WORKER_MESSAGE_UPDATE_ASYNC:
-    case RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC:
-    case RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC:
-    case RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC:
-    case RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC:
-    case RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC:
-    case RED_WORKER_MESSAGE_GL_DRAW_ASYNC:
-        break;
-    case RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC:
-        red_qxl_create_primary_surface_complete(dispatcher);
-        break;
-    case RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC:
-        red_qxl_destroy_primary_surface_complete(dispatcher);
-        break;
-    default:
-        spice_warning("unexpected message %d", async_command->message);
-    }
-    dispatcher->qxl->st->qif->async_complete(dispatcher->qxl,
-                                             async_command->cookie);
-    free(async_command);
-}
-
-void red_qxl_init(QXLInstance *qxl)
-{
-    RedDispatcher *red_dispatcher;
-    RedChannel *channel;
-    ClientCbs client_cbs = { NULL, };
-
-    spice_return_if_fail(qxl != NULL);
-    spice_return_if_fail(qxl->st->dispatcher == NULL);
-
-    static gsize initialized = FALSE;
-    if (g_once_init_enter(&initialized)) {
-        quic_init();
-        sw_canvas_init();
-        g_once_init_leave(&initialized, TRUE);
-    }
-
-    red_dispatcher = spice_new0(RedDispatcher, 1);
-    red_dispatcher->qxl = qxl;
-    dispatcher_init(&red_dispatcher->dispatcher, RED_WORKER_MESSAGE_COUNT, NULL);
-    red_dispatcher->base.major_version = SPICE_INTERFACE_QXL_MAJOR;
-    red_dispatcher->base.minor_version = SPICE_INTERFACE_QXL_MINOR;
-    red_dispatcher->base.wakeup = qxl_worker_wakeup;
-    red_dispatcher->base.oom = qxl_worker_oom;
-    red_dispatcher->base.start = qxl_worker_start;
-    red_dispatcher->base.stop = qxl_worker_stop;
-    red_dispatcher->base.update_area = qxl_worker_update_area;
-    red_dispatcher->base.add_memslot = qxl_worker_add_memslot;
-    red_dispatcher->base.del_memslot = qxl_worker_del_memslot;
-    red_dispatcher->base.reset_memslots = qxl_worker_reset_memslots;
-    red_dispatcher->base.destroy_surfaces = qxl_worker_destroy_surfaces;
-    red_dispatcher->base.create_primary_surface = qxl_worker_create_primary_surface;
-    red_dispatcher->base.destroy_primary_surface = qxl_worker_destroy_primary_surface;
-
-    red_dispatcher->base.reset_image_cache = qxl_worker_reset_image_cache;
-    red_dispatcher->base.reset_cursor = qxl_worker_reset_cursor;
-    red_dispatcher->base.destroy_surface_wait = qxl_worker_destroy_surface_wait;
-    red_dispatcher->base.loadvm_commands = qxl_worker_loadvm_commands;
-
-    red_dispatcher->max_monitors = UINT_MAX;
-
-    // TODO: reference and free
-    RedWorker *worker = red_worker_new(qxl, red_dispatcher);
-
-    // TODO: move to their respective channel files
-    channel = red_worker_get_cursor_channel(worker);
-    client_cbs.connect = red_qxl_set_cursor_peer;
-    client_cbs.disconnect = red_qxl_disconnect_cursor_peer;
-    client_cbs.migrate = red_qxl_cursor_migrate;
-    red_channel_register_client_cbs(channel, &client_cbs);
-    red_channel_set_data(channel, red_dispatcher);
-    reds_register_channel(reds, channel);
-
-    channel = red_worker_get_display_channel(worker);
-    client_cbs.connect = red_qxl_set_display_peer;
-    client_cbs.disconnect = red_qxl_disconnect_display_peer;
-    client_cbs.migrate = red_qxl_display_migrate;
-    red_channel_register_client_cbs(channel, &client_cbs);
-    red_channel_set_data(channel, red_dispatcher);
-    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
-    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
-    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_STREAM_REPORT);
-    reds_register_channel(reds, channel);
-
-    red_worker_run(worker);
-
-    qxl->st->dispatcher = red_dispatcher;
-}
-
-struct Dispatcher *red_qxl_get_dispatcher(RedDispatcher *red_dispatcher)
-{
-    return &red_dispatcher->dispatcher;
-}
-
-void red_qxl_set_dispatcher_opaque(RedDispatcher *red_dispatcher,
-                                   void *opaque)
-{
-    dispatcher_set_opaque(&red_dispatcher->dispatcher, opaque);
-}
-
-void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending)
-{
-    spice_return_if_fail(red_dispatcher != NULL);
-
-    clear_bit(pending, &red_dispatcher->pending);
-}
-
-gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher)
-{
-    return dispatcher->primary_active;
-}
-
-gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res)
-{
-    if (dispatcher->use_hardware_cursor) {
-        if (x_res)
-            *x_res = dispatcher->x_res;
-        if (y_res)
-            *y_res = dispatcher->y_res;
-    }
-    return dispatcher->use_hardware_cursor;
-}
-
-void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic)
-{
-    RedWorkerMessageSetCompression payload;
-    payload.image_compression = ic;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_SET_COMPRESSION,
-                            &payload);
-}
-
-void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv)
-{
-    RedWorkerMessageSetStreamingVideo payload;
-    payload.streaming_video = sv;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
-                            &payload);
-}
-
-void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode)
-{
-    RedWorkerMessageSetMouseMode payload;
-    payload.mode = mode;
-    dispatcher_send_message(&dispatcher->dispatcher,
-                            RED_WORKER_MESSAGE_SET_MOUSE_MODE,
-                            &payload);
-}
diff --git a/server/red-dispatcher.h b/server/red-dispatcher.h
deleted file mode 100644
index 1348e6c..0000000
--- a/server/red-dispatcher.h
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
-   Copyright (C) 2009 Red Hat, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _H_RED_DISPATCHER
-#define _H_RED_DISPATCHER
-
-#include "red-channel.h"
-
-typedef struct RedDispatcher RedDispatcher;
-
-typedef struct AsyncCommand AsyncCommand;
-
-void red_qxl_init(QXLInstance *qxl);
-
-void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t);
-void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic);
-void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv);
-void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode);
-void red_qxl_attach_worker(RedDispatcher *dispatcher);
-void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level);
-void red_qxl_stop(RedDispatcher *dispatcher);
-void red_qxl_start(RedDispatcher *dispatcher);
-uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher);
-void red_qxl_async_complete(struct RedDispatcher *, AsyncCommand *);
-struct Dispatcher *red_qxl_get_dispatcher(struct RedDispatcher *);
-gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher);
-gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher, VDAgentMonitorsConfig *monitors_config);
-gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher);
-gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res);
-
-typedef uint32_t RedWorkerMessage;
-
-/* Keep message order, only append new messages!
- * Replay code store enum values into save files.
- */
-enum {
-    RED_WORKER_MESSAGE_NOP,
-
-    RED_WORKER_MESSAGE_UPDATE,
-    RED_WORKER_MESSAGE_WAKEUP,
-    RED_WORKER_MESSAGE_OOM,
-    RED_WORKER_MESSAGE_READY, /* unused */
-
-    RED_WORKER_MESSAGE_DISPLAY_CONNECT,
-    RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
-    RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
-    RED_WORKER_MESSAGE_START,
-    RED_WORKER_MESSAGE_STOP,
-    RED_WORKER_MESSAGE_CURSOR_CONNECT,
-    RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
-    RED_WORKER_MESSAGE_CURSOR_MIGRATE,
-    RED_WORKER_MESSAGE_SET_COMPRESSION,
-    RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
-    RED_WORKER_MESSAGE_SET_MOUSE_MODE,
-    RED_WORKER_MESSAGE_ADD_MEMSLOT,
-    RED_WORKER_MESSAGE_DEL_MEMSLOT,
-    RED_WORKER_MESSAGE_RESET_MEMSLOTS,
-    RED_WORKER_MESSAGE_DESTROY_SURFACES,
-    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
-    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
-    RED_WORKER_MESSAGE_RESET_CURSOR,
-    RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
-    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
-    RED_WORKER_MESSAGE_LOADVM_COMMANDS,
-    /* async commands */
-    RED_WORKER_MESSAGE_UPDATE_ASYNC,
-    RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC,
-    RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC,
-    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC,
-    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC,
-    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC,
-    /* suspend/windows resolution change command */
-    RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC,
-
-    RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE, /* unused */
-    RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE, /* unused */
-
-    RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC,
-    RED_WORKER_MESSAGE_DRIVER_UNLOAD,
-    RED_WORKER_MESSAGE_GL_SCANOUT,
-    RED_WORKER_MESSAGE_GL_DRAW_ASYNC,
-
-    RED_WORKER_MESSAGE_COUNT // LAST
-};
-
-typedef struct RedWorkerMessageDisplayConnect {
-    RedClient * client;
-    RedsStream * stream;
-    uint32_t *common_caps; // red_worker should free
-    uint32_t *caps;        // red_worker should free
-    int migration;
-    int num_common_caps;
-    int num_caps;
-} RedWorkerMessageDisplayConnect;
-
-typedef struct RedWorkerMessageDisplayDisconnect {
-    RedChannelClient *rcc;
-} RedWorkerMessageDisplayDisconnect;
-
-typedef struct RedWorkerMessageDisplayMigrate {
-    RedChannelClient *rcc;
-} RedWorkerMessageDisplayMigrate;
-
-typedef struct RedWorkerMessageCursorConnect {
-    RedClient *client;
-    RedsStream *stream;
-    int migration;
-    uint32_t *common_caps; // red_worker should free
-    int num_common_caps;
-    uint32_t *caps;        // red_worker should free
-    int num_caps;
-} RedWorkerMessageCursorConnect;
-
-typedef struct RedWorkerMessageCursorDisconnect {
-    RedChannelClient *rcc;
-} RedWorkerMessageCursorDisconnect;
-
-typedef struct RedWorkerMessageCursorMigrate {
-    RedChannelClient *rcc;
-} RedWorkerMessageCursorMigrate;
-
-typedef struct RedWorkerMessageUpdate {
-    uint32_t surface_id;
-    QXLRect * qxl_area;
-    QXLRect * qxl_dirty_rects;
-    uint32_t num_dirty_rects;
-    uint32_t clear_dirty_region;
-} RedWorkerMessageUpdate;
-
-typedef struct RedWorkerMessageAsync {
-    AsyncCommand *cmd;
-} RedWorkerMessageAsync;
-
-typedef struct RedWorkerMessageUpdateAsync {
-    RedWorkerMessageAsync base;
-    uint32_t surface_id;
-    QXLRect qxl_area;
-    uint32_t clear_dirty_region;
-} RedWorkerMessageUpdateAsync;
-
-typedef struct RedWorkerMessageAddMemslot {
-    QXLDevMemSlot mem_slot;
-} RedWorkerMessageAddMemslot;
-
-typedef struct RedWorkerMessageAddMemslotAsync {
-    RedWorkerMessageAsync base;
-    QXLDevMemSlot mem_slot;
-} RedWorkerMessageAddMemslotAsync;
-
-typedef struct RedWorkerMessageDelMemslot {
-    uint32_t slot_group_id;
-    uint32_t slot_id;
-} RedWorkerMessageDelMemslot;
-
-typedef struct RedWorkerMessageDestroySurfaces {
-} RedWorkerMessageDestroySurfaces;
-
-typedef struct RedWorkerMessageDestroySurfacesAsync {
-    RedWorkerMessageAsync base;
-} RedWorkerMessageDestroySurfacesAsync;
-
-
-typedef struct RedWorkerMessageDestroyPrimarySurface {
-    uint32_t surface_id;
-} RedWorkerMessageDestroyPrimarySurface;
-
-typedef struct RedWorkerMessageDestroyPrimarySurfaceAsync {
-    RedWorkerMessageAsync base;
-    uint32_t surface_id;
-} RedWorkerMessageDestroyPrimarySurfaceAsync;
-
-typedef struct RedWorkerMessageCreatePrimarySurfaceAsync {
-    RedWorkerMessageAsync base;
-    uint32_t surface_id;
-    QXLDevSurfaceCreate surface;
-} RedWorkerMessageCreatePrimarySurfaceAsync;
-
-typedef struct RedWorkerMessageCreatePrimarySurface {
-    uint32_t surface_id;
-    QXLDevSurfaceCreate surface;
-} RedWorkerMessageCreatePrimarySurface;
-
-typedef struct RedWorkerMessageResetImageCache {
-} RedWorkerMessageResetImageCache;
-
-typedef struct RedWorkerMessageResetCursor {
-} RedWorkerMessageResetCursor;
-
-typedef struct RedWorkerMessageWakeup {
-} RedWorkerMessageWakeup;
-
-typedef struct RedWorkerMessageOom {
-} RedWorkerMessageOom;
-
-typedef struct RedWorkerMessageStart {
-} RedWorkerMessageStart;
-
-typedef struct RedWorkerMessageFlushSurfacesAsync {
-    RedWorkerMessageAsync base;
-} RedWorkerMessageFlushSurfacesAsync;
-
-typedef struct RedWorkerMessageStop {
-} RedWorkerMessageStop;
-
-/* this command is sync, so it's ok to pass a pointer */
-typedef struct RedWorkerMessageLoadvmCommands {
-    uint32_t count;
-    QXLCommandExt *ext;
-} RedWorkerMessageLoadvmCommands;
-
-typedef struct RedWorkerMessageSetCompression {
-    SpiceImageCompression image_compression;
-} RedWorkerMessageSetCompression;
-
-typedef struct RedWorkerMessageSetStreamingVideo {
-    uint32_t streaming_video;
-} RedWorkerMessageSetStreamingVideo;
-
-typedef struct RedWorkerMessageSetMouseMode {
-    uint32_t mode;
-} RedWorkerMessageSetMouseMode;
-
-typedef struct RedWorkerMessageDisplayChannelCreate {
-} RedWorkerMessageDisplayChannelCreate;
-
-typedef struct RedWorkerMessageCursorChannelCreate {
-} RedWorkerMessageCursorChannelCreate;
-
-typedef struct RedWorkerMessageDestroySurfaceWait {
-    uint32_t surface_id;
-} RedWorkerMessageDestroySurfaceWait;
-
-typedef struct RedWorkerMessageDestroySurfaceWaitAsync {
-    RedWorkerMessageAsync base;
-    uint32_t surface_id;
-} RedWorkerMessageDestroySurfaceWaitAsync;
-
-typedef struct RedWorkerMessageResetMemslots {
-} RedWorkerMessageResetMemslots;
-
-typedef struct RedWorkerMessageMonitorsConfigAsync {
-    RedWorkerMessageAsync base;
-    QXLPHYSICAL monitors_config;
-    int group_id;
-    unsigned int max_monitors;
-} RedWorkerMessageMonitorsConfigAsync;
-
-typedef struct RedWorkerMessageDriverUnload {
-} RedWorkerMessageDriverUnload;
-
-enum {
-    RED_DISPATCHER_PENDING_WAKEUP,
-    RED_DISPATCHER_PENDING_OOM,
-};
-
-void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending);
-
-#endif
diff --git a/server/red-qxl.c b/server/red-qxl.c
new file mode 100644
index 0000000..42edd64
--- /dev/null
+++ b/server/red-qxl.c
@@ -0,0 +1,1032 @@
+/*
+   Copyright (C) 2009 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/socket.h>
+#include <inttypes.h>
+
+#include <spice/qxl_dev.h>
+#include "common/quic.h"
+
+#include "spice.h"
+#include "red-worker.h"
+#include "sw-canvas.h"
+#include "reds.h"
+#include "dispatcher.h"
+#include "red-parse-qxl.h"
+
+#include "red-qxl.h"
+
+
+struct AsyncCommand {
+    RedWorkerMessage message;
+    uint64_t cookie;
+};
+
+struct RedDispatcher {
+    QXLWorker base;
+    QXLInstance *qxl;
+    Dispatcher dispatcher;
+    uint32_t pending;
+    int primary_active;
+    int x_res;
+    int y_res;
+    int use_hardware_cursor;
+    QXLDevSurfaceCreate surface_create;
+    unsigned int max_monitors;
+};
+
+static int red_qxl_check_qxl_version(RedDispatcher *rd, int major, int minor)
+{
+    int qxl_major = rd->qxl->st->qif->base.major_version;
+    int qxl_minor = rd->qxl->st->qif->base.minor_version;
+
+    return ((qxl_major > major) ||
+            ((qxl_major == major) && (qxl_minor >= minor)));
+}
+
+static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
+                                     RedsStream *stream, int migration,
+                                     int num_common_caps, uint32_t *common_caps, int num_caps,
+                                     uint32_t *caps)
+{
+    RedWorkerMessageDisplayConnect payload = {0,};
+    RedDispatcher *dispatcher;
+
+    spice_debug("%s", "");
+    dispatcher = (RedDispatcher *)channel->data;
+    payload.client = client;
+    payload.stream = stream;
+    payload.migration = migration;
+    payload.num_common_caps = num_common_caps;
+    payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
+    payload.num_caps = num_caps;
+    payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
+
+    memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
+    memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DISPLAY_CONNECT,
+                            &payload);
+}
+
+static void red_qxl_disconnect_display_peer(RedChannelClient *rcc)
+{
+    RedWorkerMessageDisplayDisconnect payload;
+    RedDispatcher *dispatcher;
+
+    if (!rcc->channel) {
+        return;
+    }
+
+    dispatcher = (RedDispatcher *)rcc->channel->data;
+
+    spice_printerr("");
+    payload.rcc = rcc;
+
+    // TODO: we turned it to be sync, due to client_destroy . Should we support async? - for this we will need ref count
+    // for channels
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
+                            &payload);
+}
+
+static void red_qxl_display_migrate(RedChannelClient *rcc)
+{
+    RedWorkerMessageDisplayMigrate payload;
+    RedDispatcher *dispatcher;
+    if (!rcc->channel) {
+        return;
+    }
+    dispatcher = (RedDispatcher *)rcc->channel->data;
+    spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
+    payload.rcc = rcc;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
+                            &payload);
+}
+
+static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
+                                    int migration, int num_common_caps,
+                                    uint32_t *common_caps, int num_caps,
+                                    uint32_t *caps)
+{
+    RedWorkerMessageCursorConnect payload = {0,};
+    RedDispatcher *dispatcher = (RedDispatcher *)channel->data;
+    spice_printerr("");
+    payload.client = client;
+    payload.stream = stream;
+    payload.migration = migration;
+    payload.num_common_caps = num_common_caps;
+    payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
+    payload.num_caps = num_caps;
+    payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
+
+    memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
+    memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_CURSOR_CONNECT,
+                            &payload);
+}
+
+static void red_qxl_disconnect_cursor_peer(RedChannelClient *rcc)
+{
+    RedWorkerMessageCursorDisconnect payload;
+    RedDispatcher *dispatcher;
+
+    if (!rcc->channel) {
+        return;
+    }
+
+    dispatcher = (RedDispatcher *)rcc->channel->data;
+    spice_printerr("");
+    payload.rcc = rcc;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
+                            &payload);
+}
+
+static void red_qxl_cursor_migrate(RedChannelClient *rcc)
+{
+    RedWorkerMessageCursorMigrate payload;
+    RedDispatcher *dispatcher;
+
+    if (!rcc->channel) {
+        return;
+    }
+    dispatcher = (RedDispatcher *)rcc->channel->data;
+    spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
+    payload.rcc = rcc;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_CURSOR_MIGRATE,
+                            &payload);
+}
+
+static void red_qxl_update_area(RedDispatcher *dispatcher, uint32_t surface_id,
+                                QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
+                                uint32_t num_dirty_rects, uint32_t clear_dirty_region)
+{
+    RedWorkerMessageUpdate payload = {0,};
+
+    payload.surface_id = surface_id;
+    payload.qxl_area = qxl_area;
+    payload.qxl_dirty_rects = qxl_dirty_rects;
+    payload.num_dirty_rects = num_dirty_rects;
+    payload.clear_dirty_region = clear_dirty_region;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_UPDATE,
+                            &payload);
+}
+
+gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher)
+{
+    return (red_qxl_check_qxl_version(dispatcher, 3, 3) &&
+        dispatcher->qxl->st->qif->client_monitors_config &&
+        dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl, NULL));
+}
+
+gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher,
+                                        VDAgentMonitorsConfig *monitors_config)
+{
+    return (dispatcher->qxl->st->qif->client_monitors_config &&
+        dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl,
+                                                          monitors_config));
+}
+
+static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
+                                         RedWorkerMessage message,
+                                         uint64_t cookie)
+{
+    AsyncCommand *async_command = spice_new0(AsyncCommand, 1);
+
+    async_command->cookie = cookie;
+    async_command->message = message;
+
+    spice_debug("%p", async_command);
+    return async_command;
+}
+
+static void red_qxl_update_area_async(RedDispatcher *dispatcher,
+                                      uint32_t surface_id,
+                                      QXLRect *qxl_area,
+                                      uint32_t clear_dirty_region,
+                                      uint64_t cookie)
+{
+    RedWorkerMessage message = RED_WORKER_MESSAGE_UPDATE_ASYNC;
+    RedWorkerMessageUpdateAsync payload;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.surface_id = surface_id;
+    payload.qxl_area = *qxl_area;
+    payload.clear_dirty_region = clear_dirty_region;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            message,
+                            &payload);
+}
+
+static void qxl_worker_update_area(QXLWorker *qxl_worker, uint32_t surface_id,
+                                   QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
+                                   uint32_t num_dirty_rects, uint32_t clear_dirty_region)
+{
+    red_qxl_update_area((RedDispatcher*)qxl_worker, surface_id, qxl_area,
+                        qxl_dirty_rects, num_dirty_rects, clear_dirty_region);
+}
+
+static void red_qxl_add_memslot(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot)
+{
+    RedWorkerMessageAddMemslot payload;
+
+    payload.mem_slot = *mem_slot;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_ADD_MEMSLOT,
+                            &payload);
+}
+
+static void qxl_worker_add_memslot(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slot)
+{
+    red_qxl_add_memslot((RedDispatcher*)qxl_worker, mem_slot);
+}
+
+static void red_qxl_add_memslot_async(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot, uint64_t cookie)
+{
+    RedWorkerMessageAddMemslotAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.mem_slot = *mem_slot;
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void red_qxl_del_memslot(RedDispatcher *dispatcher, uint32_t slot_group_id, uint32_t slot_id)
+{
+    RedWorkerMessageDelMemslot payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_DEL_MEMSLOT;
+
+    payload.slot_group_id = slot_group_id;
+    payload.slot_id = slot_id;
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void qxl_worker_del_memslot(QXLWorker *qxl_worker, uint32_t slot_group_id, uint32_t slot_id)
+{
+    red_qxl_del_memslot((RedDispatcher*)qxl_worker, slot_group_id, slot_id);
+}
+
+static void red_qxl_destroy_surfaces(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageDestroySurfaces payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DESTROY_SURFACES,
+                            &payload);
+}
+
+static void qxl_worker_destroy_surfaces(QXLWorker *qxl_worker)
+{
+    red_qxl_destroy_surfaces((RedDispatcher*)qxl_worker);
+}
+
+static void red_qxl_destroy_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
+{
+    RedWorkerMessageDestroySurfacesAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void red_qxl_destroy_primary_surface_complete(RedDispatcher *dispatcher)
+{
+    dispatcher->x_res = 0;
+    dispatcher->y_res = 0;
+    dispatcher->use_hardware_cursor = FALSE;
+    dispatcher->primary_active = FALSE;
+
+    reds_update_client_mouse_allowed(reds);
+}
+
+static void
+red_qxl_destroy_primary_surface_sync(RedDispatcher *dispatcher,
+                                     uint32_t surface_id)
+{
+    RedWorkerMessageDestroyPrimarySurface payload;
+    payload.surface_id = surface_id;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
+                            &payload);
+    red_qxl_destroy_primary_surface_complete(dispatcher);
+}
+
+static void
+red_qxl_destroy_primary_surface_async(RedDispatcher *dispatcher,
+                                      uint32_t surface_id, uint64_t cookie)
+{
+    RedWorkerMessageDestroyPrimarySurfaceAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.surface_id = surface_id;
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void
+red_qxl_destroy_primary_surface(RedDispatcher *dispatcher,
+                                uint32_t surface_id, int async, uint64_t cookie)
+{
+    if (async) {
+        red_qxl_destroy_primary_surface_async(dispatcher, surface_id, cookie);
+    } else {
+        red_qxl_destroy_primary_surface_sync(dispatcher, surface_id);
+    }
+}
+
+static void qxl_worker_destroy_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id)
+{
+    red_qxl_destroy_primary_surface((RedDispatcher*)qxl_worker, surface_id, 0, 0);
+}
+
+static void red_qxl_create_primary_surface_complete(RedDispatcher *dispatcher)
+{
+    QXLDevSurfaceCreate *surface = &dispatcher->surface_create;
+
+    dispatcher->x_res = surface->width;
+    dispatcher->y_res = surface->height;
+    dispatcher->use_hardware_cursor = surface->mouse_mode;
+    dispatcher->primary_active = TRUE;
+
+    reds_update_client_mouse_allowed(reds);
+    memset(&dispatcher->surface_create, 0, sizeof(QXLDevSurfaceCreate));
+}
+
+static void
+red_qxl_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t surface_id,
+                                     QXLDevSurfaceCreate *surface, uint64_t cookie)
+{
+    RedWorkerMessageCreatePrimarySurfaceAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC;
+
+    dispatcher->surface_create = *surface;
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.surface_id = surface_id;
+    payload.surface = *surface;
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void
+red_qxl_create_primary_surface_sync(RedDispatcher *dispatcher, uint32_t surface_id,
+                                    QXLDevSurfaceCreate *surface)
+{
+    RedWorkerMessageCreatePrimarySurface payload = {0,};
+
+    dispatcher->surface_create = *surface;
+    payload.surface_id = surface_id;
+    payload.surface = *surface;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
+                            &payload);
+    red_qxl_create_primary_surface_complete(dispatcher);
+}
+
+static void
+red_qxl_create_primary_surface(RedDispatcher *dispatcher, uint32_t surface_id,
+                               QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
+{
+    if (async) {
+        red_qxl_create_primary_surface_async(dispatcher, surface_id, surface, cookie);
+    } else {
+        red_qxl_create_primary_surface_sync(dispatcher, surface_id, surface);
+    }
+}
+
+static void qxl_worker_create_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id,
+                                      QXLDevSurfaceCreate *surface)
+{
+    red_qxl_create_primary_surface((RedDispatcher*)qxl_worker, surface_id, surface, 0, 0);
+}
+
+static void red_qxl_reset_image_cache(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageResetImageCache payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
+                            &payload);
+}
+
+static void qxl_worker_reset_image_cache(QXLWorker *qxl_worker)
+{
+    red_qxl_reset_image_cache((RedDispatcher*)qxl_worker);
+}
+
+static void red_qxl_reset_cursor(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageResetCursor payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_RESET_CURSOR,
+                            &payload);
+}
+
+static void qxl_worker_reset_cursor(QXLWorker *qxl_worker)
+{
+    red_qxl_reset_cursor((RedDispatcher*)qxl_worker);
+}
+
+static void red_qxl_destroy_surface_wait_sync(RedDispatcher *dispatcher,
+                                              uint32_t surface_id)
+{
+    RedWorkerMessageDestroySurfaceWait payload;
+
+    payload.surface_id = surface_id;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
+                            &payload);
+}
+
+static void red_qxl_destroy_surface_wait_async(RedDispatcher *dispatcher,
+                                               uint32_t surface_id,
+                                               uint64_t cookie)
+{
+    RedWorkerMessageDestroySurfaceWaitAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.surface_id = surface_id;
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void red_qxl_destroy_surface_wait(RedDispatcher *dispatcher,
+                                         uint32_t surface_id,
+                                         int async, uint64_t cookie)
+{
+    if (async) {
+        red_qxl_destroy_surface_wait_async(dispatcher, surface_id, cookie);
+    } else {
+        red_qxl_destroy_surface_wait_sync(dispatcher, surface_id);
+    }
+}
+
+static void qxl_worker_destroy_surface_wait(QXLWorker *qxl_worker, uint32_t surface_id)
+{
+    red_qxl_destroy_surface_wait((RedDispatcher*)qxl_worker, surface_id, 0, 0);
+}
+
+static void red_qxl_reset_memslots(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageResetMemslots payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_RESET_MEMSLOTS,
+                            &payload);
+}
+
+static void qxl_worker_reset_memslots(QXLWorker *qxl_worker)
+{
+    red_qxl_reset_memslots((RedDispatcher*)qxl_worker);
+}
+
+static bool red_qxl_set_pending(RedDispatcher *dispatcher, int pending)
+{
+    // this is not atomic but is not an issue
+    if (test_bit(pending, dispatcher->pending)) {
+        return TRUE;
+    }
+
+    set_bit(pending, &dispatcher->pending);
+    return FALSE;
+}
+
+static void red_qxl_wakeup(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageWakeup payload;
+
+    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_WAKEUP))
+        return;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_WAKEUP,
+                            &payload);
+}
+
+static void qxl_worker_wakeup(QXLWorker *qxl_worker)
+{
+    red_qxl_wakeup((RedDispatcher*)qxl_worker);
+}
+
+static void red_qxl_oom(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageOom payload;
+
+    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_OOM))
+        return;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_OOM,
+                            &payload);
+}
+
+static void qxl_worker_oom(QXLWorker *qxl_worker)
+{
+    red_qxl_oom((RedDispatcher*)qxl_worker);
+}
+
+void red_qxl_start(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageStart payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_START,
+                            &payload);
+}
+
+static void qxl_worker_start(QXLWorker *qxl_worker)
+{
+    red_qxl_start((RedDispatcher*)qxl_worker);
+}
+
+static void red_qxl_flush_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
+{
+    RedWorkerMessageFlushSurfacesAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void red_qxl_monitors_config_async(RedDispatcher *dispatcher,
+                                          QXLPHYSICAL monitors_config,
+                                          int group_id,
+                                          uint64_t cookie)
+{
+    RedWorkerMessageMonitorsConfigAsync payload;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC;
+
+    payload.base.cmd = async_command_alloc(dispatcher, message, cookie);
+    payload.monitors_config = monitors_config;
+    payload.group_id = group_id;
+    payload.max_monitors = dispatcher->max_monitors;
+
+    dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
+}
+
+static void red_qxl_driver_unload(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageDriverUnload payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_DRIVER_UNLOAD,
+                            &payload);
+}
+
+void red_qxl_stop(RedDispatcher *dispatcher)
+{
+    RedWorkerMessageStop payload;
+
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_STOP,
+                            &payload);
+}
+
+static void qxl_worker_stop(QXLWorker *qxl_worker)
+{
+    red_qxl_stop((RedDispatcher*)qxl_worker);
+}
+
+static void red_qxl_loadvm_commands(RedDispatcher *dispatcher,
+                                    struct QXLCommandExt *ext,
+                                    uint32_t count)
+{
+    RedWorkerMessageLoadvmCommands payload;
+
+    spice_printerr("");
+    payload.count = count;
+    payload.ext = ext;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_LOADVM_COMMANDS,
+                            &payload);
+}
+
+static void qxl_worker_loadvm_commands(QXLWorker *qxl_worker,
+                                       struct QXLCommandExt *ext,
+                                       uint32_t count)
+{
+    red_qxl_loadvm_commands((RedDispatcher*)qxl_worker, ext, count);
+}
+
+void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t mm_time)
+{
+    dispatcher->qxl->st->qif->set_mm_time(dispatcher->qxl, mm_time);
+}
+
+void red_qxl_attach_worker(RedDispatcher *dispatcher)
+{
+    QXLInstance *qxl = dispatcher->qxl;
+    qxl->st->qif->attache_worker(qxl, &dispatcher->base);
+}
+
+void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level)
+{
+    dispatcher->qxl->st->qif->set_compression_level(dispatcher->qxl, level);
+}
+
+uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher)
+{
+    QXLDevInitInfo qxl_info;
+    dispatcher->qxl->st->qif->get_init_info(dispatcher->qxl, &qxl_info);
+    return qxl_info.qxl_ram_size;
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_wakeup(QXLInstance *instance)
+{
+    red_qxl_wakeup(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_oom(QXLInstance *instance)
+{
+    red_qxl_oom(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_start(QXLInstance *instance)
+{
+    red_qxl_start(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_stop(QXLInstance *instance)
+{
+    red_qxl_stop(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_update_area(QXLInstance *instance, uint32_t surface_id,
+                    struct QXLRect *area, struct QXLRect *dirty_rects,
+                    uint32_t num_dirty_rects, uint32_t clear_dirty_region)
+{
+    red_qxl_update_area(instance->st->dispatcher, surface_id, area, dirty_rects,
+                        num_dirty_rects, clear_dirty_region);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_add_memslot(QXLInstance *instance, QXLDevMemSlot *slot)
+{
+    red_qxl_add_memslot(instance->st->dispatcher, slot);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_del_memslot(QXLInstance *instance, uint32_t slot_group_id, uint32_t slot_id)
+{
+    red_qxl_del_memslot(instance->st->dispatcher, slot_group_id, slot_id);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_reset_memslots(QXLInstance *instance)
+{
+    red_qxl_reset_memslots(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_destroy_surfaces(QXLInstance *instance)
+{
+    red_qxl_destroy_surfaces(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_destroy_primary_surface(QXLInstance *instance, uint32_t surface_id)
+{
+    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 0, 0);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_create_primary_surface(QXLInstance *instance, uint32_t surface_id,
+                                QXLDevSurfaceCreate *surface)
+{
+    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 0, 0);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_reset_image_cache(QXLInstance *instance)
+{
+    red_qxl_reset_image_cache(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_reset_cursor(QXLInstance *instance)
+{
+    red_qxl_reset_cursor(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_destroy_surface_wait(QXLInstance *instance, uint32_t surface_id)
+{
+    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 0, 0);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_loadvm_commands(QXLInstance *instance, struct QXLCommandExt *ext, uint32_t count)
+{
+    red_qxl_loadvm_commands(instance->st->dispatcher, ext, count);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_update_area_async(QXLInstance *instance, uint32_t surface_id, QXLRect *qxl_area,
+                                 uint32_t clear_dirty_region, uint64_t cookie)
+{
+    red_qxl_update_area_async(instance->st->dispatcher, surface_id, qxl_area,
+                                     clear_dirty_region, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_add_memslot_async(QXLInstance *instance, QXLDevMemSlot *slot, uint64_t cookie)
+{
+    red_qxl_add_memslot_async(instance->st->dispatcher, slot, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_destroy_surfaces_async(QXLInstance *instance, uint64_t cookie)
+{
+    red_qxl_destroy_surfaces_async(instance->st->dispatcher, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_destroy_primary_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
+{
+    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 1, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_create_primary_surface_async(QXLInstance *instance, uint32_t surface_id,
+                                QXLDevSurfaceCreate *surface, uint64_t cookie)
+{
+    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 1, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_destroy_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
+{
+    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 1, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_flush_surfaces_async(QXLInstance *instance, uint64_t cookie)
+{
+    red_qxl_flush_surfaces_async(instance->st->dispatcher, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_monitors_config_async(QXLInstance *instance, QXLPHYSICAL monitors_config,
+                                     int group_id, uint64_t cookie)
+{
+    red_qxl_monitors_config_async(instance->st->dispatcher, monitors_config, group_id, cookie);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_set_max_monitors(QXLInstance *instance, unsigned int max_monitors)
+{
+    instance->st->dispatcher->max_monitors = MAX(1u, max_monitors);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_driver_unload(QXLInstance *instance)
+{
+    red_qxl_driver_unload(instance->st->dispatcher);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_gl_scanout(QXLInstance *qxl,
+                          int fd,
+                          uint32_t width, uint32_t height,
+                          uint32_t stride, uint32_t format,
+                          int y_0_top)
+{
+    spice_return_if_fail(qxl != NULL);
+    spice_return_if_fail(qxl->st->gl_draw_async == NULL);
+
+    pthread_mutex_lock(&qxl->st->scanout_mutex);
+
+    if (qxl->st->scanout.drm_dma_buf_fd != -1) {
+        close(qxl->st->scanout.drm_dma_buf_fd);
+    }
+
+    qxl->st->scanout = (SpiceMsgDisplayGlScanoutUnix) {
+        .flags = y_0_top ? SPICE_GL_SCANOUT_FLAGS_Y0TOP : 0,
+        .drm_dma_buf_fd = fd,
+        .width = width,
+        .height = height,
+        .stride = stride,
+        .drm_fourcc_format = format
+    };
+
+    pthread_mutex_unlock(&qxl->st->scanout_mutex);
+
+    /* FIXME: find a way to coallesce all pending SCANOUTs */
+    dispatcher_send_message(&qxl->st->dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_GL_SCANOUT, NULL);
+}
+
+SPICE_GNUC_VISIBLE
+void spice_qxl_gl_draw_async(QXLInstance *qxl,
+                             uint32_t x, uint32_t y,
+                             uint32_t w, uint32_t h,
+                             uint64_t cookie)
+{
+    RedDispatcher *dispatcher;
+    RedWorkerMessage message = RED_WORKER_MESSAGE_GL_DRAW_ASYNC;
+    SpiceMsgDisplayGlDraw draw = {
+        .x = x,
+        .y = y,
+        .w = w,
+        .h = h
+    };
+
+    spice_return_if_fail(qxl != NULL);
+    spice_return_if_fail(qxl->st->scanout.drm_dma_buf_fd != -1);
+    spice_return_if_fail(qxl->st->gl_draw_async == NULL);
+
+    dispatcher = qxl->st->dispatcher;
+    qxl->st->gl_draw_async = async_command_alloc(dispatcher, message, cookie);
+    dispatcher_send_message(&dispatcher->dispatcher, message, &draw);
+}
+
+void red_qxl_async_complete(struct RedDispatcher *dispatcher,
+                            AsyncCommand *async_command)
+{
+    spice_debug("%p: cookie %" PRId64, async_command, async_command->cookie);
+    switch (async_command->message) {
+    case RED_WORKER_MESSAGE_UPDATE_ASYNC:
+    case RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC:
+    case RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC:
+    case RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC:
+    case RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC:
+    case RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC:
+    case RED_WORKER_MESSAGE_GL_DRAW_ASYNC:
+        break;
+    case RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC:
+        red_qxl_create_primary_surface_complete(dispatcher);
+        break;
+    case RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC:
+        red_qxl_destroy_primary_surface_complete(dispatcher);
+        break;
+    default:
+        spice_warning("unexpected message %d", async_command->message);
+    }
+    dispatcher->qxl->st->qif->async_complete(dispatcher->qxl,
+                                             async_command->cookie);
+    free(async_command);
+}
+
+void red_qxl_init(QXLInstance *qxl)
+{
+    RedDispatcher *red_dispatcher;
+    RedChannel *channel;
+    ClientCbs client_cbs = { NULL, };
+
+    spice_return_if_fail(qxl != NULL);
+    spice_return_if_fail(qxl->st->dispatcher == NULL);
+
+    static gsize initialized = FALSE;
+    if (g_once_init_enter(&initialized)) {
+        quic_init();
+        sw_canvas_init();
+        g_once_init_leave(&initialized, TRUE);
+    }
+
+    red_dispatcher = spice_new0(RedDispatcher, 1);
+    red_dispatcher->qxl = qxl;
+    dispatcher_init(&red_dispatcher->dispatcher, RED_WORKER_MESSAGE_COUNT, NULL);
+    red_dispatcher->base.major_version = SPICE_INTERFACE_QXL_MAJOR;
+    red_dispatcher->base.minor_version = SPICE_INTERFACE_QXL_MINOR;
+    red_dispatcher->base.wakeup = qxl_worker_wakeup;
+    red_dispatcher->base.oom = qxl_worker_oom;
+    red_dispatcher->base.start = qxl_worker_start;
+    red_dispatcher->base.stop = qxl_worker_stop;
+    red_dispatcher->base.update_area = qxl_worker_update_area;
+    red_dispatcher->base.add_memslot = qxl_worker_add_memslot;
+    red_dispatcher->base.del_memslot = qxl_worker_del_memslot;
+    red_dispatcher->base.reset_memslots = qxl_worker_reset_memslots;
+    red_dispatcher->base.destroy_surfaces = qxl_worker_destroy_surfaces;
+    red_dispatcher->base.create_primary_surface = qxl_worker_create_primary_surface;
+    red_dispatcher->base.destroy_primary_surface = qxl_worker_destroy_primary_surface;
+
+    red_dispatcher->base.reset_image_cache = qxl_worker_reset_image_cache;
+    red_dispatcher->base.reset_cursor = qxl_worker_reset_cursor;
+    red_dispatcher->base.destroy_surface_wait = qxl_worker_destroy_surface_wait;
+    red_dispatcher->base.loadvm_commands = qxl_worker_loadvm_commands;
+
+    red_dispatcher->max_monitors = UINT_MAX;
+
+    // TODO: reference and free
+    RedWorker *worker = red_worker_new(qxl, red_dispatcher);
+
+    // TODO: move to their respective channel files
+    channel = red_worker_get_cursor_channel(worker);
+    client_cbs.connect = red_qxl_set_cursor_peer;
+    client_cbs.disconnect = red_qxl_disconnect_cursor_peer;
+    client_cbs.migrate = red_qxl_cursor_migrate;
+    red_channel_register_client_cbs(channel, &client_cbs);
+    red_channel_set_data(channel, red_dispatcher);
+    reds_register_channel(reds, channel);
+
+    channel = red_worker_get_display_channel(worker);
+    client_cbs.connect = red_qxl_set_display_peer;
+    client_cbs.disconnect = red_qxl_disconnect_display_peer;
+    client_cbs.migrate = red_qxl_display_migrate;
+    red_channel_register_client_cbs(channel, &client_cbs);
+    red_channel_set_data(channel, red_dispatcher);
+    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
+    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
+    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_STREAM_REPORT);
+    reds_register_channel(reds, channel);
+
+    red_worker_run(worker);
+
+    qxl->st->dispatcher = red_dispatcher;
+}
+
+struct Dispatcher *red_qxl_get_dispatcher(RedDispatcher *red_dispatcher)
+{
+    return &red_dispatcher->dispatcher;
+}
+
+void red_qxl_set_dispatcher_opaque(RedDispatcher *red_dispatcher,
+                                   void *opaque)
+{
+    dispatcher_set_opaque(&red_dispatcher->dispatcher, opaque);
+}
+
+void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending)
+{
+    spice_return_if_fail(red_dispatcher != NULL);
+
+    clear_bit(pending, &red_dispatcher->pending);
+}
+
+gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher)
+{
+    return dispatcher->primary_active;
+}
+
+gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res)
+{
+    if (dispatcher->use_hardware_cursor) {
+        if (x_res)
+            *x_res = dispatcher->x_res;
+        if (y_res)
+            *y_res = dispatcher->y_res;
+    }
+    return dispatcher->use_hardware_cursor;
+}
+
+void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic)
+{
+    RedWorkerMessageSetCompression payload;
+    payload.image_compression = ic;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_SET_COMPRESSION,
+                            &payload);
+}
+
+void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv)
+{
+    RedWorkerMessageSetStreamingVideo payload;
+    payload.streaming_video = sv;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
+                            &payload);
+}
+
+void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode)
+{
+    RedWorkerMessageSetMouseMode payload;
+    payload.mode = mode;
+    dispatcher_send_message(&dispatcher->dispatcher,
+                            RED_WORKER_MESSAGE_SET_MOUSE_MODE,
+                            &payload);
+}
diff --git a/server/red-qxl.h b/server/red-qxl.h
new file mode 100644
index 0000000..1348e6c
--- /dev/null
+++ b/server/red-qxl.h
@@ -0,0 +1,272 @@
+/*
+   Copyright (C) 2009 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _H_RED_DISPATCHER
+#define _H_RED_DISPATCHER
+
+#include "red-channel.h"
+
+typedef struct RedDispatcher RedDispatcher;
+
+typedef struct AsyncCommand AsyncCommand;
+
+void red_qxl_init(QXLInstance *qxl);
+
+void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t);
+void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic);
+void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv);
+void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode);
+void red_qxl_attach_worker(RedDispatcher *dispatcher);
+void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level);
+void red_qxl_stop(RedDispatcher *dispatcher);
+void red_qxl_start(RedDispatcher *dispatcher);
+uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher);
+void red_qxl_async_complete(struct RedDispatcher *, AsyncCommand *);
+struct Dispatcher *red_qxl_get_dispatcher(struct RedDispatcher *);
+gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher);
+gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher, VDAgentMonitorsConfig *monitors_config);
+gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher);
+gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res);
+
+typedef uint32_t RedWorkerMessage;
+
+/* Keep message order, only append new messages!
+ * Replay code store enum values into save files.
+ */
+enum {
+    RED_WORKER_MESSAGE_NOP,
+
+    RED_WORKER_MESSAGE_UPDATE,
+    RED_WORKER_MESSAGE_WAKEUP,
+    RED_WORKER_MESSAGE_OOM,
+    RED_WORKER_MESSAGE_READY, /* unused */
+
+    RED_WORKER_MESSAGE_DISPLAY_CONNECT,
+    RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
+    RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
+    RED_WORKER_MESSAGE_START,
+    RED_WORKER_MESSAGE_STOP,
+    RED_WORKER_MESSAGE_CURSOR_CONNECT,
+    RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
+    RED_WORKER_MESSAGE_CURSOR_MIGRATE,
+    RED_WORKER_MESSAGE_SET_COMPRESSION,
+    RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
+    RED_WORKER_MESSAGE_SET_MOUSE_MODE,
+    RED_WORKER_MESSAGE_ADD_MEMSLOT,
+    RED_WORKER_MESSAGE_DEL_MEMSLOT,
+    RED_WORKER_MESSAGE_RESET_MEMSLOTS,
+    RED_WORKER_MESSAGE_DESTROY_SURFACES,
+    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
+    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
+    RED_WORKER_MESSAGE_RESET_CURSOR,
+    RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
+    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
+    RED_WORKER_MESSAGE_LOADVM_COMMANDS,
+    /* async commands */
+    RED_WORKER_MESSAGE_UPDATE_ASYNC,
+    RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC,
+    RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC,
+    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC,
+    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC,
+    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC,
+    /* suspend/windows resolution change command */
+    RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC,
+
+    RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE, /* unused */
+    RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE, /* unused */
+
+    RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC,
+    RED_WORKER_MESSAGE_DRIVER_UNLOAD,
+    RED_WORKER_MESSAGE_GL_SCANOUT,
+    RED_WORKER_MESSAGE_GL_DRAW_ASYNC,
+
+    RED_WORKER_MESSAGE_COUNT // LAST
+};
+
+typedef struct RedWorkerMessageDisplayConnect {
+    RedClient * client;
+    RedsStream * stream;
+    uint32_t *common_caps; // red_worker should free
+    uint32_t *caps;        // red_worker should free
+    int migration;
+    int num_common_caps;
+    int num_caps;
+} RedWorkerMessageDisplayConnect;
+
+typedef struct RedWorkerMessageDisplayDisconnect {
+    RedChannelClient *rcc;
+} RedWorkerMessageDisplayDisconnect;
+
+typedef struct RedWorkerMessageDisplayMigrate {
+    RedChannelClient *rcc;
+} RedWorkerMessageDisplayMigrate;
+
+typedef struct RedWorkerMessageCursorConnect {
+    RedClient *client;
+    RedsStream *stream;
+    int migration;
+    uint32_t *common_caps; // red_worker should free
+    int num_common_caps;
+    uint32_t *caps;        // red_worker should free
+    int num_caps;
+} RedWorkerMessageCursorConnect;
+
+typedef struct RedWorkerMessageCursorDisconnect {
+    RedChannelClient *rcc;
+} RedWorkerMessageCursorDisconnect;
+
+typedef struct RedWorkerMessageCursorMigrate {
+    RedChannelClient *rcc;
+} RedWorkerMessageCursorMigrate;
+
+typedef struct RedWorkerMessageUpdate {
+    uint32_t surface_id;
+    QXLRect * qxl_area;
+    QXLRect * qxl_dirty_rects;
+    uint32_t num_dirty_rects;
+    uint32_t clear_dirty_region;
+} RedWorkerMessageUpdate;
+
+typedef struct RedWorkerMessageAsync {
+    AsyncCommand *cmd;
+} RedWorkerMessageAsync;
+
+typedef struct RedWorkerMessageUpdateAsync {
+    RedWorkerMessageAsync base;
+    uint32_t surface_id;
+    QXLRect qxl_area;
+    uint32_t clear_dirty_region;
+} RedWorkerMessageUpdateAsync;
+
+typedef struct RedWorkerMessageAddMemslot {
+    QXLDevMemSlot mem_slot;
+} RedWorkerMessageAddMemslot;
+
+typedef struct RedWorkerMessageAddMemslotAsync {
+    RedWorkerMessageAsync base;
+    QXLDevMemSlot mem_slot;
+} RedWorkerMessageAddMemslotAsync;
+
+typedef struct RedWorkerMessageDelMemslot {
+    uint32_t slot_group_id;
+    uint32_t slot_id;
+} RedWorkerMessageDelMemslot;
+
+typedef struct RedWorkerMessageDestroySurfaces {
+} RedWorkerMessageDestroySurfaces;
+
+typedef struct RedWorkerMessageDestroySurfacesAsync {
+    RedWorkerMessageAsync base;
+} RedWorkerMessageDestroySurfacesAsync;
+
+
+typedef struct RedWorkerMessageDestroyPrimarySurface {
+    uint32_t surface_id;
+} RedWorkerMessageDestroyPrimarySurface;
+
+typedef struct RedWorkerMessageDestroyPrimarySurfaceAsync {
+    RedWorkerMessageAsync base;
+    uint32_t surface_id;
+} RedWorkerMessageDestroyPrimarySurfaceAsync;
+
+typedef struct RedWorkerMessageCreatePrimarySurfaceAsync {
+    RedWorkerMessageAsync base;
+    uint32_t surface_id;
+    QXLDevSurfaceCreate surface;
+} RedWorkerMessageCreatePrimarySurfaceAsync;
+
+typedef struct RedWorkerMessageCreatePrimarySurface {
+    uint32_t surface_id;
+    QXLDevSurfaceCreate surface;
+} RedWorkerMessageCreatePrimarySurface;
+
+typedef struct RedWorkerMessageResetImageCache {
+} RedWorkerMessageResetImageCache;
+
+typedef struct RedWorkerMessageResetCursor {
+} RedWorkerMessageResetCursor;
+
+typedef struct RedWorkerMessageWakeup {
+} RedWorkerMessageWakeup;
+
+typedef struct RedWorkerMessageOom {
+} RedWorkerMessageOom;
+
+typedef struct RedWorkerMessageStart {
+} RedWorkerMessageStart;
+
+typedef struct RedWorkerMessageFlushSurfacesAsync {
+    RedWorkerMessageAsync base;
+} RedWorkerMessageFlushSurfacesAsync;
+
+typedef struct RedWorkerMessageStop {
+} RedWorkerMessageStop;
+
+/* this command is sync, so it's ok to pass a pointer */
+typedef struct RedWorkerMessageLoadvmCommands {
+    uint32_t count;
+    QXLCommandExt *ext;
+} RedWorkerMessageLoadvmCommands;
+
+typedef struct RedWorkerMessageSetCompression {
+    SpiceImageCompression image_compression;
+} RedWorkerMessageSetCompression;
+
+typedef struct RedWorkerMessageSetStreamingVideo {
+    uint32_t streaming_video;
+} RedWorkerMessageSetStreamingVideo;
+
+typedef struct RedWorkerMessageSetMouseMode {
+    uint32_t mode;
+} RedWorkerMessageSetMouseMode;
+
+typedef struct RedWorkerMessageDisplayChannelCreate {
+} RedWorkerMessageDisplayChannelCreate;
+
+typedef struct RedWorkerMessageCursorChannelCreate {
+} RedWorkerMessageCursorChannelCreate;
+
+typedef struct RedWorkerMessageDestroySurfaceWait {
+    uint32_t surface_id;
+} RedWorkerMessageDestroySurfaceWait;
+
+typedef struct RedWorkerMessageDestroySurfaceWaitAsync {
+    RedWorkerMessageAsync base;
+    uint32_t surface_id;
+} RedWorkerMessageDestroySurfaceWaitAsync;
+
+typedef struct RedWorkerMessageResetMemslots {
+} RedWorkerMessageResetMemslots;
+
+typedef struct RedWorkerMessageMonitorsConfigAsync {
+    RedWorkerMessageAsync base;
+    QXLPHYSICAL monitors_config;
+    int group_id;
+    unsigned int max_monitors;
+} RedWorkerMessageMonitorsConfigAsync;
+
+typedef struct RedWorkerMessageDriverUnload {
+} RedWorkerMessageDriverUnload;
+
+enum {
+    RED_DISPATCHER_PENDING_WAKEUP,
+    RED_DISPATCHER_PENDING_OOM,
+};
+
+void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending);
+
+#endif
diff --git a/server/red-worker.h b/server/red-worker.h
index b22d41d..e51e261 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -19,7 +19,7 @@
 #define _H_REDWORKER
 
 #include "red-common.h"
-#include "red-dispatcher.h"
+#include "red-qxl.h"
 #include "red-parse-qxl.h"
 
 typedef struct RedWorker RedWorker;
diff --git a/server/reds.c b/server/reds.c
index b8f8cbc..ab923e9 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -57,7 +57,7 @@
 #include "agent-msg-filter.h"
 #include "inputs-channel.h"
 #include "main-channel.h"
-#include "red-dispatcher.h"
+#include "red-qxl.h"
 #include "main-dispatcher.h"
 #include "sound.h"
 #include "stat.h"
diff --git a/server/sound.c b/server/sound.c
index 6d64ad2..1aa3a74 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -33,7 +33,7 @@
 #include "red-common.h"
 #include "main-channel.h"
 #include "reds.h"
-#include "red-dispatcher.h"
+#include "red-qxl.h"
 #include "sound.h"
 #include "common/snd_codec.h"
 #include "demarshallers.h"
commit a8ff771ee83357d33d63a9596540183c38e9cd2d
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Feb 25 18:02:41 2016 +0000

    rename red_dispatcher_ functions to red_qxl_
    
    RedDispatcher is basically implementing QXLInstance.
    After some internal discussion we decided to use QXLState structure
    and red_qxl_ as function prefix.
    This is the first of 3 patches that rename functions, structure
    and files.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/display-channel.c b/server/display-channel.c
index 3b5e169..175ac7e 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -2164,7 +2164,7 @@ static void set_gl_draw_async_count(DisplayChannel *display, int num)
     if (num == 0) {
         struct AsyncCommand *async = qxl->st->gl_draw_async;
         qxl->st->gl_draw_async = NULL;
-        red_dispatcher_async_complete(qxl->st->dispatcher, async);
+        red_qxl_async_complete(qxl->st->dispatcher, async);
     }
 }
 
diff --git a/server/red-dispatcher.c b/server/red-dispatcher.c
index c2ca6b6..7718458 100644
--- a/server/red-dispatcher.c
+++ b/server/red-dispatcher.c
@@ -58,7 +58,7 @@ struct RedDispatcher {
     unsigned int max_monitors;
 };
 
-static int red_dispatcher_check_qxl_version(RedDispatcher *rd, int major, int minor)
+static int red_qxl_check_qxl_version(RedDispatcher *rd, int major, int minor)
 {
     int qxl_major = rd->qxl->st->qif->base.major_version;
     int qxl_minor = rd->qxl->st->qif->base.minor_version;
@@ -67,10 +67,10 @@ static int red_dispatcher_check_qxl_version(RedDispatcher *rd, int major, int mi
             ((qxl_major == major) && (qxl_minor >= minor)));
 }
 
-static void red_dispatcher_set_display_peer(RedChannel *channel, RedClient *client,
-                                            RedsStream *stream, int migration,
-                                            int num_common_caps, uint32_t *common_caps, int num_caps,
-                                            uint32_t *caps)
+static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
+                                     RedsStream *stream, int migration,
+                                     int num_common_caps, uint32_t *common_caps, int num_caps,
+                                     uint32_t *caps)
 {
     RedWorkerMessageDisplayConnect payload = {0,};
     RedDispatcher *dispatcher;
@@ -93,7 +93,7 @@ static void red_dispatcher_set_display_peer(RedChannel *channel, RedClient *clie
                             &payload);
 }
 
-static void red_dispatcher_disconnect_display_peer(RedChannelClient *rcc)
+static void red_qxl_disconnect_display_peer(RedChannelClient *rcc)
 {
     RedWorkerMessageDisplayDisconnect payload;
     RedDispatcher *dispatcher;
@@ -114,7 +114,7 @@ static void red_dispatcher_disconnect_display_peer(RedChannelClient *rcc)
                             &payload);
 }
 
-static void red_dispatcher_display_migrate(RedChannelClient *rcc)
+static void red_qxl_display_migrate(RedChannelClient *rcc)
 {
     RedWorkerMessageDisplayMigrate payload;
     RedDispatcher *dispatcher;
@@ -129,10 +129,10 @@ static void red_dispatcher_display_migrate(RedChannelClient *rcc)
                             &payload);
 }
 
-static void red_dispatcher_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
-                                           int migration, int num_common_caps,
-                                           uint32_t *common_caps, int num_caps,
-                                           uint32_t *caps)
+static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
+                                    int migration, int num_common_caps,
+                                    uint32_t *common_caps, int num_caps,
+                                    uint32_t *caps)
 {
     RedWorkerMessageCursorConnect payload = {0,};
     RedDispatcher *dispatcher = (RedDispatcher *)channel->data;
@@ -153,7 +153,7 @@ static void red_dispatcher_set_cursor_peer(RedChannel *channel, RedClient *clien
                             &payload);
 }
 
-static void red_dispatcher_disconnect_cursor_peer(RedChannelClient *rcc)
+static void red_qxl_disconnect_cursor_peer(RedChannelClient *rcc)
 {
     RedWorkerMessageCursorDisconnect payload;
     RedDispatcher *dispatcher;
@@ -171,7 +171,7 @@ static void red_dispatcher_disconnect_cursor_peer(RedChannelClient *rcc)
                             &payload);
 }
 
-static void red_dispatcher_cursor_migrate(RedChannelClient *rcc)
+static void red_qxl_cursor_migrate(RedChannelClient *rcc)
 {
     RedWorkerMessageCursorMigrate payload;
     RedDispatcher *dispatcher;
@@ -187,9 +187,9 @@ static void red_dispatcher_cursor_migrate(RedChannelClient *rcc)
                             &payload);
 }
 
-static void red_dispatcher_update_area(RedDispatcher *dispatcher, uint32_t surface_id,
-                                   QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
-                                   uint32_t num_dirty_rects, uint32_t clear_dirty_region)
+static void red_qxl_update_area(RedDispatcher *dispatcher, uint32_t surface_id,
+                                QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
+                                uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
     RedWorkerMessageUpdate payload = {0,};
 
@@ -203,15 +203,15 @@ static void red_dispatcher_update_area(RedDispatcher *dispatcher, uint32_t surfa
                             &payload);
 }
 
-gboolean red_dispatcher_use_client_monitors_config(RedDispatcher *dispatcher)
+gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher)
 {
-    return (red_dispatcher_check_qxl_version(dispatcher, 3, 3) &&
+    return (red_qxl_check_qxl_version(dispatcher, 3, 3) &&
         dispatcher->qxl->st->qif->client_monitors_config &&
         dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl, NULL));
 }
 
-gboolean red_dispatcher_client_monitors_config(RedDispatcher *dispatcher,
-                                               VDAgentMonitorsConfig *monitors_config)
+gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher,
+                                        VDAgentMonitorsConfig *monitors_config)
 {
     return (dispatcher->qxl->st->qif->client_monitors_config &&
         dispatcher->qxl->st->qif->client_monitors_config(dispatcher->qxl,
@@ -231,11 +231,11 @@ static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
     return async_command;
 }
 
-static void red_dispatcher_update_area_async(RedDispatcher *dispatcher,
-                                         uint32_t surface_id,
-                                         QXLRect *qxl_area,
-                                         uint32_t clear_dirty_region,
-                                         uint64_t cookie)
+static void red_qxl_update_area_async(RedDispatcher *dispatcher,
+                                      uint32_t surface_id,
+                                      QXLRect *qxl_area,
+                                      uint32_t clear_dirty_region,
+                                      uint64_t cookie)
 {
     RedWorkerMessage message = RED_WORKER_MESSAGE_UPDATE_ASYNC;
     RedWorkerMessageUpdateAsync payload;
@@ -253,11 +253,11 @@ static void qxl_worker_update_area(QXLWorker *qxl_worker, uint32_t surface_id,
                                    QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
                                    uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
-    red_dispatcher_update_area((RedDispatcher*)qxl_worker, surface_id, qxl_area,
-                               qxl_dirty_rects, num_dirty_rects, clear_dirty_region);
+    red_qxl_update_area((RedDispatcher*)qxl_worker, surface_id, qxl_area,
+                        qxl_dirty_rects, num_dirty_rects, clear_dirty_region);
 }
 
-static void red_dispatcher_add_memslot(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot)
+static void red_qxl_add_memslot(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot)
 {
     RedWorkerMessageAddMemslot payload;
 
@@ -269,10 +269,10 @@ static void red_dispatcher_add_memslot(RedDispatcher *dispatcher, QXLDevMemSlot
 
 static void qxl_worker_add_memslot(QXLWorker *qxl_worker, QXLDevMemSlot *mem_slot)
 {
-    red_dispatcher_add_memslot((RedDispatcher*)qxl_worker, mem_slot);
+    red_qxl_add_memslot((RedDispatcher*)qxl_worker, mem_slot);
 }
 
-static void red_dispatcher_add_memslot_async(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot, uint64_t cookie)
+static void red_qxl_add_memslot_async(RedDispatcher *dispatcher, QXLDevMemSlot *mem_slot, uint64_t cookie)
 {
     RedWorkerMessageAddMemslotAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC;
@@ -282,7 +282,7 @@ static void red_dispatcher_add_memslot_async(RedDispatcher *dispatcher, QXLDevMe
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
-static void red_dispatcher_del_memslot(RedDispatcher *dispatcher, uint32_t slot_group_id, uint32_t slot_id)
+static void red_qxl_del_memslot(RedDispatcher *dispatcher, uint32_t slot_group_id, uint32_t slot_id)
 {
     RedWorkerMessageDelMemslot payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DEL_MEMSLOT;
@@ -294,10 +294,10 @@ static void red_dispatcher_del_memslot(RedDispatcher *dispatcher, uint32_t slot_
 
 static void qxl_worker_del_memslot(QXLWorker *qxl_worker, uint32_t slot_group_id, uint32_t slot_id)
 {
-    red_dispatcher_del_memslot((RedDispatcher*)qxl_worker, slot_group_id, slot_id);
+    red_qxl_del_memslot((RedDispatcher*)qxl_worker, slot_group_id, slot_id);
 }
 
-static void red_dispatcher_destroy_surfaces(RedDispatcher *dispatcher)
+static void red_qxl_destroy_surfaces(RedDispatcher *dispatcher)
 {
     RedWorkerMessageDestroySurfaces payload;
 
@@ -308,10 +308,10 @@ static void red_dispatcher_destroy_surfaces(RedDispatcher *dispatcher)
 
 static void qxl_worker_destroy_surfaces(QXLWorker *qxl_worker)
 {
-    red_dispatcher_destroy_surfaces((RedDispatcher*)qxl_worker);
+    red_qxl_destroy_surfaces((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_destroy_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
+static void red_qxl_destroy_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
 {
     RedWorkerMessageDestroySurfacesAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC;
@@ -320,7 +320,7 @@ static void red_dispatcher_destroy_surfaces_async(RedDispatcher *dispatcher, uin
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
-static void red_dispatcher_destroy_primary_surface_complete(RedDispatcher *dispatcher)
+static void red_qxl_destroy_primary_surface_complete(RedDispatcher *dispatcher)
 {
     dispatcher->x_res = 0;
     dispatcher->y_res = 0;
@@ -331,20 +331,20 @@ static void red_dispatcher_destroy_primary_surface_complete(RedDispatcher *dispa
 }
 
 static void
-red_dispatcher_destroy_primary_surface_sync(RedDispatcher *dispatcher,
-                                            uint32_t surface_id)
+red_qxl_destroy_primary_surface_sync(RedDispatcher *dispatcher,
+                                     uint32_t surface_id)
 {
     RedWorkerMessageDestroyPrimarySurface payload;
     payload.surface_id = surface_id;
     dispatcher_send_message(&dispatcher->dispatcher,
                             RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
                             &payload);
-    red_dispatcher_destroy_primary_surface_complete(dispatcher);
+    red_qxl_destroy_primary_surface_complete(dispatcher);
 }
 
 static void
-red_dispatcher_destroy_primary_surface_async(RedDispatcher *dispatcher,
-                                             uint32_t surface_id, uint64_t cookie)
+red_qxl_destroy_primary_surface_async(RedDispatcher *dispatcher,
+                                      uint32_t surface_id, uint64_t cookie)
 {
     RedWorkerMessageDestroyPrimarySurfaceAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC;
@@ -355,22 +355,22 @@ red_dispatcher_destroy_primary_surface_async(RedDispatcher *dispatcher,
 }
 
 static void
-red_dispatcher_destroy_primary_surface(RedDispatcher *dispatcher,
-                                       uint32_t surface_id, int async, uint64_t cookie)
+red_qxl_destroy_primary_surface(RedDispatcher *dispatcher,
+                                uint32_t surface_id, int async, uint64_t cookie)
 {
     if (async) {
-        red_dispatcher_destroy_primary_surface_async(dispatcher, surface_id, cookie);
+        red_qxl_destroy_primary_surface_async(dispatcher, surface_id, cookie);
     } else {
-        red_dispatcher_destroy_primary_surface_sync(dispatcher, surface_id);
+        red_qxl_destroy_primary_surface_sync(dispatcher, surface_id);
     }
 }
 
 static void qxl_worker_destroy_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id)
 {
-    red_dispatcher_destroy_primary_surface((RedDispatcher*)qxl_worker, surface_id, 0, 0);
+    red_qxl_destroy_primary_surface((RedDispatcher*)qxl_worker, surface_id, 0, 0);
 }
 
-static void red_dispatcher_create_primary_surface_complete(RedDispatcher *dispatcher)
+static void red_qxl_create_primary_surface_complete(RedDispatcher *dispatcher)
 {
     QXLDevSurfaceCreate *surface = &dispatcher->surface_create;
 
@@ -384,8 +384,8 @@ static void red_dispatcher_create_primary_surface_complete(RedDispatcher *dispat
 }
 
 static void
-red_dispatcher_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t surface_id,
-                                            QXLDevSurfaceCreate *surface, uint64_t cookie)
+red_qxl_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t surface_id,
+                                     QXLDevSurfaceCreate *surface, uint64_t cookie)
 {
     RedWorkerMessageCreatePrimarySurfaceAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC;
@@ -398,8 +398,8 @@ red_dispatcher_create_primary_surface_async(RedDispatcher *dispatcher, uint32_t
 }
 
 static void
-red_dispatcher_create_primary_surface_sync(RedDispatcher *dispatcher, uint32_t surface_id,
-                                           QXLDevSurfaceCreate *surface)
+red_qxl_create_primary_surface_sync(RedDispatcher *dispatcher, uint32_t surface_id,
+                                    QXLDevSurfaceCreate *surface)
 {
     RedWorkerMessageCreatePrimarySurface payload = {0,};
 
@@ -409,27 +409,27 @@ red_dispatcher_create_primary_surface_sync(RedDispatcher *dispatcher, uint32_t s
     dispatcher_send_message(&dispatcher->dispatcher,
                             RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
                             &payload);
-    red_dispatcher_create_primary_surface_complete(dispatcher);
+    red_qxl_create_primary_surface_complete(dispatcher);
 }
 
 static void
-red_dispatcher_create_primary_surface(RedDispatcher *dispatcher, uint32_t surface_id,
-                                      QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
+red_qxl_create_primary_surface(RedDispatcher *dispatcher, uint32_t surface_id,
+                               QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
 {
     if (async) {
-        red_dispatcher_create_primary_surface_async(dispatcher, surface_id, surface, cookie);
+        red_qxl_create_primary_surface_async(dispatcher, surface_id, surface, cookie);
     } else {
-        red_dispatcher_create_primary_surface_sync(dispatcher, surface_id, surface);
+        red_qxl_create_primary_surface_sync(dispatcher, surface_id, surface);
     }
 }
 
 static void qxl_worker_create_primary_surface(QXLWorker *qxl_worker, uint32_t surface_id,
                                       QXLDevSurfaceCreate *surface)
 {
-    red_dispatcher_create_primary_surface((RedDispatcher*)qxl_worker, surface_id, surface, 0, 0);
+    red_qxl_create_primary_surface((RedDispatcher*)qxl_worker, surface_id, surface, 0, 0);
 }
 
-static void red_dispatcher_reset_image_cache(RedDispatcher *dispatcher)
+static void red_qxl_reset_image_cache(RedDispatcher *dispatcher)
 {
     RedWorkerMessageResetImageCache payload;
 
@@ -440,10 +440,10 @@ static void red_dispatcher_reset_image_cache(RedDispatcher *dispatcher)
 
 static void qxl_worker_reset_image_cache(QXLWorker *qxl_worker)
 {
-    red_dispatcher_reset_image_cache((RedDispatcher*)qxl_worker);
+    red_qxl_reset_image_cache((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_reset_cursor(RedDispatcher *dispatcher)
+static void red_qxl_reset_cursor(RedDispatcher *dispatcher)
 {
     RedWorkerMessageResetCursor payload;
 
@@ -454,11 +454,11 @@ static void red_dispatcher_reset_cursor(RedDispatcher *dispatcher)
 
 static void qxl_worker_reset_cursor(QXLWorker *qxl_worker)
 {
-    red_dispatcher_reset_cursor((RedDispatcher*)qxl_worker);
+    red_qxl_reset_cursor((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_destroy_surface_wait_sync(RedDispatcher *dispatcher,
-                                                     uint32_t surface_id)
+static void red_qxl_destroy_surface_wait_sync(RedDispatcher *dispatcher,
+                                              uint32_t surface_id)
 {
     RedWorkerMessageDestroySurfaceWait payload;
 
@@ -468,9 +468,9 @@ static void red_dispatcher_destroy_surface_wait_sync(RedDispatcher *dispatcher,
                             &payload);
 }
 
-static void red_dispatcher_destroy_surface_wait_async(RedDispatcher *dispatcher,
-                                                      uint32_t surface_id,
-                                                      uint64_t cookie)
+static void red_qxl_destroy_surface_wait_async(RedDispatcher *dispatcher,
+                                               uint32_t surface_id,
+                                               uint64_t cookie)
 {
     RedWorkerMessageDestroySurfaceWaitAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC;
@@ -480,23 +480,23 @@ static void red_dispatcher_destroy_surface_wait_async(RedDispatcher *dispatcher,
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
-static void red_dispatcher_destroy_surface_wait(RedDispatcher *dispatcher,
-                                                uint32_t surface_id,
-                                                int async, uint64_t cookie)
+static void red_qxl_destroy_surface_wait(RedDispatcher *dispatcher,
+                                         uint32_t surface_id,
+                                         int async, uint64_t cookie)
 {
     if (async) {
-        red_dispatcher_destroy_surface_wait_async(dispatcher, surface_id, cookie);
+        red_qxl_destroy_surface_wait_async(dispatcher, surface_id, cookie);
     } else {
-        red_dispatcher_destroy_surface_wait_sync(dispatcher, surface_id);
+        red_qxl_destroy_surface_wait_sync(dispatcher, surface_id);
     }
 }
 
 static void qxl_worker_destroy_surface_wait(QXLWorker *qxl_worker, uint32_t surface_id)
 {
-    red_dispatcher_destroy_surface_wait((RedDispatcher*)qxl_worker, surface_id, 0, 0);
+    red_qxl_destroy_surface_wait((RedDispatcher*)qxl_worker, surface_id, 0, 0);
 }
 
-static void red_dispatcher_reset_memslots(RedDispatcher *dispatcher)
+static void red_qxl_reset_memslots(RedDispatcher *dispatcher)
 {
     RedWorkerMessageResetMemslots payload;
 
@@ -507,10 +507,10 @@ static void red_dispatcher_reset_memslots(RedDispatcher *dispatcher)
 
 static void qxl_worker_reset_memslots(QXLWorker *qxl_worker)
 {
-    red_dispatcher_reset_memslots((RedDispatcher*)qxl_worker);
+    red_qxl_reset_memslots((RedDispatcher*)qxl_worker);
 }
 
-static bool red_dispatcher_set_pending(RedDispatcher *dispatcher, int pending)
+static bool red_qxl_set_pending(RedDispatcher *dispatcher, int pending)
 {
     // this is not atomic but is not an issue
     if (test_bit(pending, dispatcher->pending)) {
@@ -521,11 +521,11 @@ static bool red_dispatcher_set_pending(RedDispatcher *dispatcher, int pending)
     return FALSE;
 }
 
-static void red_dispatcher_wakeup(RedDispatcher *dispatcher)
+static void red_qxl_wakeup(RedDispatcher *dispatcher)
 {
     RedWorkerMessageWakeup payload;
 
-    if (red_dispatcher_set_pending(dispatcher, RED_DISPATCHER_PENDING_WAKEUP))
+    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_WAKEUP))
         return;
 
     dispatcher_send_message(&dispatcher->dispatcher,
@@ -535,14 +535,14 @@ static void red_dispatcher_wakeup(RedDispatcher *dispatcher)
 
 static void qxl_worker_wakeup(QXLWorker *qxl_worker)
 {
-    red_dispatcher_wakeup((RedDispatcher*)qxl_worker);
+    red_qxl_wakeup((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_oom(RedDispatcher *dispatcher)
+static void red_qxl_oom(RedDispatcher *dispatcher)
 {
     RedWorkerMessageOom payload;
 
-    if (red_dispatcher_set_pending(dispatcher, RED_DISPATCHER_PENDING_OOM))
+    if (red_qxl_set_pending(dispatcher, RED_DISPATCHER_PENDING_OOM))
         return;
 
     dispatcher_send_message(&dispatcher->dispatcher,
@@ -552,10 +552,10 @@ static void red_dispatcher_oom(RedDispatcher *dispatcher)
 
 static void qxl_worker_oom(QXLWorker *qxl_worker)
 {
-    red_dispatcher_oom((RedDispatcher*)qxl_worker);
+    red_qxl_oom((RedDispatcher*)qxl_worker);
 }
 
-void red_dispatcher_start(RedDispatcher *dispatcher)
+void red_qxl_start(RedDispatcher *dispatcher)
 {
     RedWorkerMessageStart payload;
 
@@ -566,10 +566,10 @@ void red_dispatcher_start(RedDispatcher *dispatcher)
 
 static void qxl_worker_start(QXLWorker *qxl_worker)
 {
-    red_dispatcher_start((RedDispatcher*)qxl_worker);
+    red_qxl_start((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_flush_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
+static void red_qxl_flush_surfaces_async(RedDispatcher *dispatcher, uint64_t cookie)
 {
     RedWorkerMessageFlushSurfacesAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC;
@@ -578,10 +578,10 @@ static void red_dispatcher_flush_surfaces_async(RedDispatcher *dispatcher, uint6
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
-static void red_dispatcher_monitors_config_async(RedDispatcher *dispatcher,
-                                                 QXLPHYSICAL monitors_config,
-                                                 int group_id,
-                                                 uint64_t cookie)
+static void red_qxl_monitors_config_async(RedDispatcher *dispatcher,
+                                          QXLPHYSICAL monitors_config,
+                                          int group_id,
+                                          uint64_t cookie)
 {
     RedWorkerMessageMonitorsConfigAsync payload;
     RedWorkerMessage message = RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC;
@@ -594,7 +594,7 @@ static void red_dispatcher_monitors_config_async(RedDispatcher *dispatcher,
     dispatcher_send_message(&dispatcher->dispatcher, message, &payload);
 }
 
-static void red_dispatcher_driver_unload(RedDispatcher *dispatcher)
+static void red_qxl_driver_unload(RedDispatcher *dispatcher)
 {
     RedWorkerMessageDriverUnload payload;
 
@@ -603,7 +603,7 @@ static void red_dispatcher_driver_unload(RedDispatcher *dispatcher)
                             &payload);
 }
 
-void red_dispatcher_stop(RedDispatcher *dispatcher)
+void red_qxl_stop(RedDispatcher *dispatcher)
 {
     RedWorkerMessageStop payload;
 
@@ -614,12 +614,12 @@ void red_dispatcher_stop(RedDispatcher *dispatcher)
 
 static void qxl_worker_stop(QXLWorker *qxl_worker)
 {
-    red_dispatcher_stop((RedDispatcher*)qxl_worker);
+    red_qxl_stop((RedDispatcher*)qxl_worker);
 }
 
-static void red_dispatcher_loadvm_commands(RedDispatcher *dispatcher,
-                                           struct QXLCommandExt *ext,
-                                           uint32_t count)
+static void red_qxl_loadvm_commands(RedDispatcher *dispatcher,
+                                    struct QXLCommandExt *ext,
+                                    uint32_t count)
 {
     RedWorkerMessageLoadvmCommands payload;
 
@@ -635,26 +635,26 @@ static void qxl_worker_loadvm_commands(QXLWorker *qxl_worker,
                                        struct QXLCommandExt *ext,
                                        uint32_t count)
 {
-    red_dispatcher_loadvm_commands((RedDispatcher*)qxl_worker, ext, count);
+    red_qxl_loadvm_commands((RedDispatcher*)qxl_worker, ext, count);
 }
 
-void red_dispatcher_set_mm_time(RedDispatcher *dispatcher, uint32_t mm_time)
+void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t mm_time)
 {
     dispatcher->qxl->st->qif->set_mm_time(dispatcher->qxl, mm_time);
 }
 
-void red_dispatcher_attach_worker(RedDispatcher *dispatcher)
+void red_qxl_attach_worker(RedDispatcher *dispatcher)
 {
     QXLInstance *qxl = dispatcher->qxl;
     qxl->st->qif->attache_worker(qxl, &dispatcher->base);
 }
 
-void red_dispatcher_set_compression_level(RedDispatcher *dispatcher, int level)
+void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level)
 {
     dispatcher->qxl->st->qif->set_compression_level(dispatcher->qxl, level);
 }
 
-uint32_t red_dispatcher_qxl_ram_size(RedDispatcher *dispatcher)
+uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher)
 {
     QXLDevInitInfo qxl_info;
     dispatcher->qxl->st->qif->get_init_info(dispatcher->qxl, &qxl_info);
@@ -664,25 +664,25 @@ uint32_t red_dispatcher_qxl_ram_size(RedDispatcher *dispatcher)
 SPICE_GNUC_VISIBLE
 void spice_qxl_wakeup(QXLInstance *instance)
 {
-    red_dispatcher_wakeup(instance->st->dispatcher);
+    red_qxl_wakeup(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_oom(QXLInstance *instance)
 {
-    red_dispatcher_oom(instance->st->dispatcher);
+    red_qxl_oom(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_start(QXLInstance *instance)
 {
-    red_dispatcher_start(instance->st->dispatcher);
+    red_qxl_start(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_stop(QXLInstance *instance)
 {
-    red_dispatcher_stop(instance->st->dispatcher);
+    red_qxl_stop(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
@@ -690,121 +690,121 @@ void spice_qxl_update_area(QXLInstance *instance, uint32_t surface_id,
                     struct QXLRect *area, struct QXLRect *dirty_rects,
                     uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
-    red_dispatcher_update_area(instance->st->dispatcher, surface_id, area, dirty_rects,
-                               num_dirty_rects, clear_dirty_region);
+    red_qxl_update_area(instance->st->dispatcher, surface_id, area, dirty_rects,
+                        num_dirty_rects, clear_dirty_region);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_add_memslot(QXLInstance *instance, QXLDevMemSlot *slot)
 {
-    red_dispatcher_add_memslot(instance->st->dispatcher, slot);
+    red_qxl_add_memslot(instance->st->dispatcher, slot);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_del_memslot(QXLInstance *instance, uint32_t slot_group_id, uint32_t slot_id)
 {
-    red_dispatcher_del_memslot(instance->st->dispatcher, slot_group_id, slot_id);
+    red_qxl_del_memslot(instance->st->dispatcher, slot_group_id, slot_id);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_reset_memslots(QXLInstance *instance)
 {
-    red_dispatcher_reset_memslots(instance->st->dispatcher);
+    red_qxl_reset_memslots(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surfaces(QXLInstance *instance)
 {
-    red_dispatcher_destroy_surfaces(instance->st->dispatcher);
+    red_qxl_destroy_surfaces(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_primary_surface(QXLInstance *instance, uint32_t surface_id)
 {
-    red_dispatcher_destroy_primary_surface(instance->st->dispatcher, surface_id, 0, 0);
+    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 0, 0);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_create_primary_surface(QXLInstance *instance, uint32_t surface_id,
                                 QXLDevSurfaceCreate *surface)
 {
-    red_dispatcher_create_primary_surface(instance->st->dispatcher, surface_id, surface, 0, 0);
+    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 0, 0);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_reset_image_cache(QXLInstance *instance)
 {
-    red_dispatcher_reset_image_cache(instance->st->dispatcher);
+    red_qxl_reset_image_cache(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_reset_cursor(QXLInstance *instance)
 {
-    red_dispatcher_reset_cursor(instance->st->dispatcher);
+    red_qxl_reset_cursor(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surface_wait(QXLInstance *instance, uint32_t surface_id)
 {
-    red_dispatcher_destroy_surface_wait(instance->st->dispatcher, surface_id, 0, 0);
+    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 0, 0);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_loadvm_commands(QXLInstance *instance, struct QXLCommandExt *ext, uint32_t count)
 {
-    red_dispatcher_loadvm_commands(instance->st->dispatcher, ext, count);
+    red_qxl_loadvm_commands(instance->st->dispatcher, ext, count);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_update_area_async(QXLInstance *instance, uint32_t surface_id, QXLRect *qxl_area,
                                  uint32_t clear_dirty_region, uint64_t cookie)
 {
-    red_dispatcher_update_area_async(instance->st->dispatcher, surface_id, qxl_area,
+    red_qxl_update_area_async(instance->st->dispatcher, surface_id, qxl_area,
                                      clear_dirty_region, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_add_memslot_async(QXLInstance *instance, QXLDevMemSlot *slot, uint64_t cookie)
 {
-    red_dispatcher_add_memslot_async(instance->st->dispatcher, slot, cookie);
+    red_qxl_add_memslot_async(instance->st->dispatcher, slot, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surfaces_async(QXLInstance *instance, uint64_t cookie)
 {
-    red_dispatcher_destroy_surfaces_async(instance->st->dispatcher, cookie);
+    red_qxl_destroy_surfaces_async(instance->st->dispatcher, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_primary_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
 {
-    red_dispatcher_destroy_primary_surface(instance->st->dispatcher, surface_id, 1, cookie);
+    red_qxl_destroy_primary_surface(instance->st->dispatcher, surface_id, 1, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_create_primary_surface_async(QXLInstance *instance, uint32_t surface_id,
                                 QXLDevSurfaceCreate *surface, uint64_t cookie)
 {
-    red_dispatcher_create_primary_surface(instance->st->dispatcher, surface_id, surface, 1, cookie);
+    red_qxl_create_primary_surface(instance->st->dispatcher, surface_id, surface, 1, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_destroy_surface_async(QXLInstance *instance, uint32_t surface_id, uint64_t cookie)
 {
-    red_dispatcher_destroy_surface_wait(instance->st->dispatcher, surface_id, 1, cookie);
+    red_qxl_destroy_surface_wait(instance->st->dispatcher, surface_id, 1, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_flush_surfaces_async(QXLInstance *instance, uint64_t cookie)
 {
-    red_dispatcher_flush_surfaces_async(instance->st->dispatcher, cookie);
+    red_qxl_flush_surfaces_async(instance->st->dispatcher, cookie);
 }
 
 SPICE_GNUC_VISIBLE
 void spice_qxl_monitors_config_async(QXLInstance *instance, QXLPHYSICAL monitors_config,
                                      int group_id, uint64_t cookie)
 {
-    red_dispatcher_monitors_config_async(instance->st->dispatcher, monitors_config, group_id, cookie);
+    red_qxl_monitors_config_async(instance->st->dispatcher, monitors_config, group_id, cookie);
 }
 
 SPICE_GNUC_VISIBLE
@@ -816,7 +816,7 @@ void spice_qxl_set_max_monitors(QXLInstance *instance, unsigned int max_monitors
 SPICE_GNUC_VISIBLE
 void spice_qxl_driver_unload(QXLInstance *instance)
 {
-    red_dispatcher_driver_unload(instance->st->dispatcher);
+    red_qxl_driver_unload(instance->st->dispatcher);
 }
 
 SPICE_GNUC_VISIBLE
@@ -875,8 +875,8 @@ void spice_qxl_gl_draw_async(QXLInstance *qxl,
     dispatcher_send_message(&dispatcher->dispatcher, message, &draw);
 }
 
-void red_dispatcher_async_complete(struct RedDispatcher *dispatcher,
-                                   AsyncCommand *async_command)
+void red_qxl_async_complete(struct RedDispatcher *dispatcher,
+                            AsyncCommand *async_command)
 {
     spice_debug("%p: cookie %" PRId64, async_command, async_command->cookie);
     switch (async_command->message) {
@@ -889,10 +889,10 @@ void red_dispatcher_async_complete(struct RedDispatcher *dispatcher,
     case RED_WORKER_MESSAGE_GL_DRAW_ASYNC:
         break;
     case RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC:
-        red_dispatcher_create_primary_surface_complete(dispatcher);
+        red_qxl_create_primary_surface_complete(dispatcher);
         break;
     case RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC:
-        red_dispatcher_destroy_primary_surface_complete(dispatcher);
+        red_qxl_destroy_primary_surface_complete(dispatcher);
         break;
     default:
         spice_warning("unexpected message %d", async_command->message);
@@ -902,7 +902,7 @@ void red_dispatcher_async_complete(struct RedDispatcher *dispatcher,
     free(async_command);
 }
 
-void red_dispatcher_init(QXLInstance *qxl)
+void red_qxl_init(QXLInstance *qxl)
 {
     RedDispatcher *red_dispatcher;
     RedChannel *channel;
@@ -947,17 +947,17 @@ void red_dispatcher_init(QXLInstance *qxl)
 
     // TODO: move to their respective channel files
     channel = red_worker_get_cursor_channel(worker);
-    client_cbs.connect = red_dispatcher_set_cursor_peer;
-    client_cbs.disconnect = red_dispatcher_disconnect_cursor_peer;
-    client_cbs.migrate = red_dispatcher_cursor_migrate;
+    client_cbs.connect = red_qxl_set_cursor_peer;
+    client_cbs.disconnect = red_qxl_disconnect_cursor_peer;
+    client_cbs.migrate = red_qxl_cursor_migrate;
     red_channel_register_client_cbs(channel, &client_cbs);
     red_channel_set_data(channel, red_dispatcher);
     reds_register_channel(reds, channel);
 
     channel = red_worker_get_display_channel(worker);
-    client_cbs.connect = red_dispatcher_set_display_peer;
-    client_cbs.disconnect = red_dispatcher_disconnect_display_peer;
-    client_cbs.migrate = red_dispatcher_display_migrate;
+    client_cbs.connect = red_qxl_set_display_peer;
+    client_cbs.disconnect = red_qxl_disconnect_display_peer;
+    client_cbs.migrate = red_qxl_display_migrate;
     red_channel_register_client_cbs(channel, &client_cbs);
     red_channel_set_data(channel, red_dispatcher);
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
@@ -970,30 +970,30 @@ void red_dispatcher_init(QXLInstance *qxl)
     qxl->st->dispatcher = red_dispatcher;
 }
 
-struct Dispatcher *red_dispatcher_get_dispatcher(RedDispatcher *red_dispatcher)
+struct Dispatcher *red_qxl_get_dispatcher(RedDispatcher *red_dispatcher)
 {
     return &red_dispatcher->dispatcher;
 }
 
-void red_dispatcher_set_dispatcher_opaque(RedDispatcher *red_dispatcher,
-                                          void *opaque)
+void red_qxl_set_dispatcher_opaque(RedDispatcher *red_dispatcher,
+                                   void *opaque)
 {
     dispatcher_set_opaque(&red_dispatcher->dispatcher, opaque);
 }
 
-void red_dispatcher_clear_pending(RedDispatcher *red_dispatcher, int pending)
+void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending)
 {
     spice_return_if_fail(red_dispatcher != NULL);
 
     clear_bit(pending, &red_dispatcher->pending);
 }
 
-gboolean red_dispatcher_get_primary_active(RedDispatcher *dispatcher)
+gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher)
 {
     return dispatcher->primary_active;
 }
 
-gboolean red_dispatcher_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res)
+gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res)
 {
     if (dispatcher->use_hardware_cursor) {
         if (x_res)
@@ -1004,7 +1004,7 @@ gboolean red_dispatcher_get_allow_client_mouse(RedDispatcher *dispatcher, gint *
     return dispatcher->use_hardware_cursor;
 }
 
-void red_dispatcher_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic)
+void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic)
 {
     RedWorkerMessageSetCompression payload;
     payload.image_compression = ic;
@@ -1013,7 +1013,7 @@ void red_dispatcher_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompressio
                             &payload);
 }
 
-void red_dispatcher_on_sv_change(RedDispatcher *dispatcher, int sv)
+void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv)
 {
     RedWorkerMessageSetStreamingVideo payload;
     payload.streaming_video = sv;
@@ -1022,7 +1022,7 @@ void red_dispatcher_on_sv_change(RedDispatcher *dispatcher, int sv)
                             &payload);
 }
 
-void red_dispatcher_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode)
+void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode)
 {
     RedWorkerMessageSetMouseMode payload;
     payload.mode = mode;
diff --git a/server/red-dispatcher.h b/server/red-dispatcher.h
index 1aa63c2..1348e6c 100644
--- a/server/red-dispatcher.h
+++ b/server/red-dispatcher.h
@@ -24,23 +24,23 @@ typedef struct RedDispatcher RedDispatcher;
 
 typedef struct AsyncCommand AsyncCommand;
 
-void red_dispatcher_init(QXLInstance *qxl);
-
-void red_dispatcher_set_mm_time(RedDispatcher *dispatcher, uint32_t);
-void red_dispatcher_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic);
-void red_dispatcher_on_sv_change(RedDispatcher *dispatcher, int sv);
-void red_dispatcher_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode);
-void red_dispatcher_attach_worker(RedDispatcher *dispatcher);
-void red_dispatcher_set_compression_level(RedDispatcher *dispatcher, int level);
-void red_dispatcher_stop(RedDispatcher *dispatcher);
-void red_dispatcher_start(RedDispatcher *dispatcher);
-uint32_t red_dispatcher_qxl_ram_size(RedDispatcher *dispatcher);
-void red_dispatcher_async_complete(struct RedDispatcher *, AsyncCommand *);
-struct Dispatcher *red_dispatcher_get_dispatcher(struct RedDispatcher *);
-gboolean red_dispatcher_use_client_monitors_config(RedDispatcher *dispatcher);
-gboolean red_dispatcher_client_monitors_config(RedDispatcher *dispatcher, VDAgentMonitorsConfig *monitors_config);
-gboolean red_dispatcher_get_primary_active(RedDispatcher *dispatcher);
-gboolean red_dispatcher_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res);
+void red_qxl_init(QXLInstance *qxl);
+
+void red_qxl_set_mm_time(RedDispatcher *dispatcher, uint32_t);
+void red_qxl_on_ic_change(RedDispatcher *dispatcher, SpiceImageCompression ic);
+void red_qxl_on_sv_change(RedDispatcher *dispatcher, int sv);
+void red_qxl_set_mouse_mode(RedDispatcher *dispatcher, uint32_t mode);
+void red_qxl_attach_worker(RedDispatcher *dispatcher);
+void red_qxl_set_compression_level(RedDispatcher *dispatcher, int level);
+void red_qxl_stop(RedDispatcher *dispatcher);
+void red_qxl_start(RedDispatcher *dispatcher);
+uint32_t red_qxl_get_ram_size(RedDispatcher *dispatcher);
+void red_qxl_async_complete(struct RedDispatcher *, AsyncCommand *);
+struct Dispatcher *red_qxl_get_dispatcher(struct RedDispatcher *);
+gboolean red_qxl_use_client_monitors_config(RedDispatcher *dispatcher);
+gboolean red_qxl_client_monitors_config(RedDispatcher *dispatcher, VDAgentMonitorsConfig *monitors_config);
+gboolean red_qxl_get_primary_active(RedDispatcher *dispatcher);
+gboolean red_qxl_get_allow_client_mouse(RedDispatcher *dispatcher, gint *x_res, gint *y_res);
 
 typedef uint32_t RedWorkerMessage;
 
@@ -267,6 +267,6 @@ enum {
     RED_DISPATCHER_PENDING_OOM,
 };
 
-void red_dispatcher_clear_pending(RedDispatcher *red_dispatcher, int pending);
+void red_qxl_clear_pending(RedDispatcher *red_dispatcher, int pending);
 
 #endif
diff --git a/server/red-worker.c b/server/red-worker.c
index 002df89..8ef0b9f 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -823,7 +823,7 @@ static void handle_dev_wakeup(void *opaque, void *payload)
     RedWorker *worker = opaque;
 
     stat_inc_counter(reds, worker->wakeup_counter, 1);
-    red_dispatcher_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_WAKEUP);
+    red_qxl_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_WAKEUP);
 }
 
 static void handle_dev_oom(void *opaque, void *payload)
@@ -853,7 +853,7 @@ static void handle_dev_oom(void *opaque, void *payload)
                 display->glz_drawable_count,
                 display->current_size,
                 red_channel_sum_pipes_size(display_red_channel));
-    red_dispatcher_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_OOM);
+    red_qxl_clear_pending(worker->red_dispatcher, RED_DISPATCHER_PENDING_OOM);
 }
 
 static void handle_dev_reset_cursor(void *opaque, void *payload)
@@ -1194,7 +1194,7 @@ static void worker_handle_dispatcher_async_done(void *opaque,
     RedWorkerMessageAsync *msg_async = payload;
 
     spice_debug(NULL);
-    red_dispatcher_async_complete(worker->red_dispatcher, msg_async->cmd);
+    red_qxl_async_complete(worker->red_dispatcher, msg_async->cmd);
 }
 
 static void worker_dispatcher_record(void *opaque, uint32_t message_type, void *payload)
@@ -1487,7 +1487,7 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher)
             spice_error("failed to write replay header");
         }
     }
-    dispatcher = red_dispatcher_get_dispatcher(red_dispatcher);
+    dispatcher = red_qxl_get_dispatcher(red_dispatcher);
     dispatcher_set_opaque(dispatcher, worker);
 
     worker->red_dispatcher = red_dispatcher;
diff --git a/server/reds.c b/server/reds.c
index e986864..b8f8cbc 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -571,7 +571,7 @@ static void reds_set_mouse_mode(RedsState *reds, uint32_t mode)
     reds->mouse_mode = mode;
 
     for (l = reds->dispatchers; l != NULL; l = l->next)
-        red_dispatcher_set_mouse_mode(l->data, mode);
+        red_qxl_set_mouse_mode(l->data, mode);
 
     main_channel_push_mouse_mode(reds->main_channel, reds->mouse_mode, reds->is_client_mouse_allowed);
 }
@@ -3213,7 +3213,7 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
         pthread_mutex_init(&qxl->st->scanout_mutex, NULL);
         qxl->st->scanout.drm_dma_buf_fd = -1;
         qxl->st->qif = SPICE_CONTAINEROF(interface, QXLInterface, base);
-        red_dispatcher_init(qxl);
+        red_qxl_init(qxl);
         dispatcher = qxl->st->dispatcher;
         reds->dispatchers = g_list_prepend(reds->dispatchers, dispatcher);
 
@@ -3222,8 +3222,8 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s,
          * this callback is called. This as clients assume they can start the
          * dispatchers. Also note that this should be the first callback to
          * be called. */
-        red_dispatcher_attach_worker(dispatcher);
-        red_dispatcher_set_compression_level(dispatcher, calc_compression_level(reds));
+        red_qxl_attach_worker(dispatcher);
+        red_qxl_set_compression_level(dispatcher, calc_compression_level(reds));
     } else if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
         SpiceTabletInstance *tablet = SPICE_CONTAINEROF(sin, SpiceTabletInstance, base);
         spice_info("SPICE_INTERFACE_TABLET");
@@ -4157,8 +4157,8 @@ void reds_update_client_mouse_allowed(RedsState *reds)
         for (l = reds->dispatchers; l != NULL && allow_now; l = l->next) {
 
             RedDispatcher *now = l->data;
-            if (red_dispatcher_get_primary_active(now)) {
-                allow_now = red_dispatcher_get_allow_client_mouse(now, &x_res, &y_res);
+            if (red_qxl_get_primary_active(now)) {
+                allow_now = red_qxl_get_allow_client_mouse(now, &x_res, &y_res);
                 break;
             }
         }
@@ -4181,7 +4181,7 @@ gboolean reds_use_client_monitors_config(RedsState *reds)
     for (l = reds->dispatchers; l != NULL ; l = l->next) {
         RedDispatcher *now = l->data;
 
-        if (!red_dispatcher_use_client_monitors_config(now))
+        if (!red_qxl_use_client_monitors_config(now))
             return FALSE;
     }
     return TRUE;
@@ -4193,7 +4193,7 @@ void reds_client_monitors_config(RedsState *reds, VDAgentMonitorsConfig *monitor
 
     for (l = reds->dispatchers; l != NULL; l = l->next) {
         RedDispatcher *now = l->data;
-        if (!red_dispatcher_client_monitors_config(now, monitors_config)) {
+        if (!red_qxl_client_monitors_config(now, monitors_config)) {
             /* this is a normal condition, some qemu devices might not implement it */
             spice_debug("QXLInterface::client_monitors_config failed\n");
         }
@@ -4206,7 +4206,7 @@ void reds_set_mm_time(RedsState *reds, uint32_t mm_time)
 
     for (l = reds->dispatchers; l != NULL; l = l->next) {
         RedDispatcher *now = l->data;
-        red_dispatcher_set_mm_time(now, mm_time);
+        red_qxl_set_mm_time(now, mm_time);
     }
 }
 
@@ -4229,8 +4229,8 @@ void reds_on_ic_change(RedsState *reds)
 
     for (l = reds->dispatchers; l != NULL; l = l->next) {
         RedDispatcher *d = l->data;
-        red_dispatcher_set_compression_level(d, compression_level);
-        red_dispatcher_on_ic_change(d, spice_server_get_image_compression(reds));
+        red_qxl_set_compression_level(d, compression_level);
+        red_qxl_on_ic_change(d, spice_server_get_image_compression(reds));
     }
 }
 
@@ -4241,8 +4241,8 @@ void reds_on_sv_change(RedsState *reds)
 
     for (l = reds->dispatchers; l != NULL; l = l->next) {
         RedDispatcher *d = l->data;
-        red_dispatcher_set_compression_level(d, compression_level);
-        red_dispatcher_on_sv_change(d, reds_get_streaming_video(reds));
+        red_qxl_set_compression_level(d, compression_level);
+        red_qxl_on_sv_change(d, reds_get_streaming_video(reds));
     }
 }
 
@@ -4251,7 +4251,7 @@ void reds_on_vm_stop(RedsState *reds)
     GList *l;
 
     for (l = reds->dispatchers; l != NULL; l = l->next)
-        red_dispatcher_stop(l->data);
+        red_qxl_stop(l->data);
 }
 
 void reds_on_vm_start(RedsState *reds)
@@ -4259,7 +4259,7 @@ void reds_on_vm_start(RedsState *reds)
     GList *l;
 
     for (l = reds->dispatchers; l != NULL; l = l->next)
-        red_dispatcher_start(l->data);
+        red_qxl_start(l->data);
 }
 
 uint32_t reds_qxl_ram_size(RedsState *reds)
@@ -4270,7 +4270,7 @@ uint32_t reds_qxl_ram_size(RedsState *reds)
     }
 
     first = reds->dispatchers->data;
-    return red_dispatcher_qxl_ram_size(first);
+    return red_qxl_get_ram_size(first);
 }
 
 MainDispatcher* reds_get_main_dispatcher(RedsState *reds)


More information about the Spice-commits mailing list