[PATCH v3 3/4] use QXLState instead of RedDispatcher

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 server/cursor-channel.c  |   2 +-
 server/dcc-send.c        |  17 +-
 server/dcc.c             |   4 +-
 server/display-channel.c |   8 +-
 server/red-qxl.c         | 499 +++++++++++++++++++++++++----------------------
 server/red-qxl.h         |  37 ++--
 server/red-worker.c      |  57 +++---
 server/red-worker.h      |   2 +-
 server/reds-private.h    |   2 +-
 server/reds.c            |  80 ++++----
 server/reds.h            |  11 +-
 11 files changed, 372 insertions(+), 347 deletions(-)

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 3dfeae6..4932617 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..7877c73 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 *red_qxls;
     MainDispatcher *main_dispatcher;
 };
 
diff --git a/server/reds.c b/server/reds.c
index ab923e9..de7c7a1 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->red_qxls; 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->red_qxls);
 
     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->red_qxls),
             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->red_qxls),
                            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->red_qxls = g_list_prepend(reds->red_qxls, 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
+         * red_qxls. 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->red_qxls);
 
     if (num_active_workers > 0) {
         allow_now = TRUE;
-        for (l = reds->dispatchers; l != NULL && allow_now; l = l->next) {
+        for (l = reds->red_qxls; 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->red_qxls == NULL) {
         return FALSE;
     }
 
-    for (l = reds->dispatchers; l != NULL ; l = l->next) {
-        RedDispatcher *now = l->data;
+    for (l = reds->red_qxls; 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->red_qxls; 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->red_qxls; 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->red_qxls; 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->red_qxls; 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->red_qxls; 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->red_qxls; 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->red_qxls) {
         return 0;
     }
 
-    first = reds->dispatchers->data;
+    first = reds->red_qxls->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 {
-- 
2.5.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]