2 * Copyright (C) 2010 Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "qemu-common.h"
19 #include "ui/qemu-spice.h"
20 #include "qemu/timer.h"
21 #include "qemu/queue.h"
22 #include "ui/console.h"
23 #include "sysemu/sysemu.h"
26 #include "ui/spice-display.h"
34 static void GCC_FMT_ATTR(2, 3) dprint(int level, const char *fmt, ...)
40 vfprintf(stderr, fmt, args);
45 int qemu_spice_rect_is_empty(const QXLRect* r)
47 return r->top == r->bottom || r->left == r->right;
50 void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r)
52 if (qemu_spice_rect_is_empty(r)) {
56 if (qemu_spice_rect_is_empty(dest)) {
61 dest->top = MIN(dest->top, r->top);
62 dest->left = MIN(dest->left, r->left);
63 dest->bottom = MAX(dest->bottom, r->bottom);
64 dest->right = MAX(dest->right, r->right);
67 QXLCookie *qxl_cookie_new(int type, uint64_t io)
71 cookie = g_malloc0(sizeof(*cookie));
77 void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
80 trace_qemu_spice_add_memslot(ssd->qxl.id, memslot->slot_id,
81 memslot->virt_start, memslot->virt_end,
84 if (async != QXL_SYNC) {
85 spice_qxl_add_memslot_async(&ssd->qxl, memslot,
86 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
87 QXL_IO_MEMSLOT_ADD_ASYNC));
89 spice_qxl_add_memslot(&ssd->qxl, memslot);
93 void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, uint32_t sid)
95 trace_qemu_spice_del_memslot(ssd->qxl.id, gid, sid);
96 spice_qxl_del_memslot(&ssd->qxl, gid, sid);
99 void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
100 QXLDevSurfaceCreate *surface,
103 trace_qemu_spice_create_primary_surface(ssd->qxl.id, id, surface, async);
104 if (async != QXL_SYNC) {
105 spice_qxl_create_primary_surface_async(&ssd->qxl, id, surface,
106 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
107 QXL_IO_CREATE_PRIMARY_ASYNC));
109 spice_qxl_create_primary_surface(&ssd->qxl, id, surface);
113 void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
114 uint32_t id, qxl_async_io async)
116 trace_qemu_spice_destroy_primary_surface(ssd->qxl.id, id, async);
117 if (async != QXL_SYNC) {
118 spice_qxl_destroy_primary_surface_async(&ssd->qxl, id,
119 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
120 QXL_IO_DESTROY_PRIMARY_ASYNC));
122 spice_qxl_destroy_primary_surface(&ssd->qxl, id);
126 void qemu_spice_wakeup(SimpleSpiceDisplay *ssd)
128 trace_qemu_spice_wakeup(ssd->qxl.id);
129 spice_qxl_wakeup(&ssd->qxl);
132 static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
135 SimpleSpiceUpdate *update;
136 QXLDrawable *drawable;
140 struct timespec time_space;
141 pixman_image_t *dest;
143 trace_qemu_spice_create_update(
144 rect->left, rect->right,
145 rect->top, rect->bottom);
147 update = g_malloc0(sizeof(*update));
148 drawable = &update->drawable;
149 image = &update->image;
150 cmd = &update->ext.cmd;
152 bw = rect->right - rect->left;
153 bh = rect->bottom - rect->top;
154 update->bitmap = g_malloc(bw * bh * 4);
156 drawable->bbox = *rect;
157 drawable->clip.type = SPICE_CLIP_TYPE_NONE;
158 drawable->effect = QXL_EFFECT_OPAQUE;
159 drawable->release_info.id = (uintptr_t)(&update->ext);
160 drawable->type = QXL_DRAW_COPY;
161 drawable->surfaces_dest[0] = -1;
162 drawable->surfaces_dest[1] = -1;
163 drawable->surfaces_dest[2] = -1;
164 clock_gettime(CLOCK_MONOTONIC, &time_space);
165 /* time in milliseconds from epoch. */
166 drawable->mm_time = time_space.tv_sec * 1000
167 + time_space.tv_nsec / 1000 / 1000;
169 drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
170 drawable->u.copy.src_bitmap = (uintptr_t)image;
171 drawable->u.copy.src_area.right = bw;
172 drawable->u.copy.src_area.bottom = bh;
174 QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, ssd->unique++);
175 image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
176 image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;
177 image->bitmap.stride = bw * 4;
178 image->descriptor.width = image->bitmap.x = bw;
179 image->descriptor.height = image->bitmap.y = bh;
180 image->bitmap.data = (uintptr_t)(update->bitmap);
181 image->bitmap.palette = 0;
182 image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
184 dest = pixman_image_create_bits(PIXMAN_LE_x8r8g8b8, bw, bh,
185 (void *)update->bitmap, bw * 4);
186 pixman_image_composite(PIXMAN_OP_SRC, ssd->surface, NULL, ssd->mirror,
187 rect->left, rect->top, 0, 0,
188 rect->left, rect->top, bw, bh);
189 pixman_image_composite(PIXMAN_OP_SRC, ssd->mirror, NULL, dest,
190 rect->left, rect->top, 0, 0,
192 pixman_image_unref(dest);
194 cmd->type = QXL_CMD_DRAW;
195 cmd->data = (uintptr_t)drawable;
197 QTAILQ_INSERT_TAIL(&ssd->updates, update, next);
200 static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
203 static const int blksize = 32;
204 int blocks = (surface_width(ssd->ds) + blksize - 1) / blksize;
205 int dirty_top[blocks];
206 int y, yoff1, yoff2, x, xoff, blk, bw;
207 int bpp = surface_bytes_per_pixel(ssd->ds);
208 uint8_t *guest, *mirror;
211 if (qemu_spice_rect_is_empty(&ssd->dirty)) {
215 if (ssd->surface == NULL) {
216 ssd->surface = pixman_image_ref(ssd->ds->image);
217 ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format,
222 for (blk = 0; blk < blocks; blk++) {
226 guest = surface_data(ssd->ds);
227 mirror = (void *)pixman_image_get_data(ssd->mirror);
228 for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) {
229 yoff1 = y * surface_stride(ssd->ds);
230 yoff2 = y * pixman_image_get_stride(ssd->mirror);
231 for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
234 bw = MIN(blksize, ssd->dirty.right - x);
235 if (memcmp(guest + yoff1 + xoff,
236 mirror + yoff2 + xoff,
238 if (dirty_top[blk] != -1) {
240 .top = dirty_top[blk],
245 qemu_spice_create_one_update(ssd, &update);
249 if (dirty_top[blk] == -1) {
256 for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
258 bw = MIN(blksize, ssd->dirty.right - x);
259 if (dirty_top[blk] != -1) {
261 .top = dirty_top[blk],
262 .bottom = ssd->dirty.bottom,
266 qemu_spice_create_one_update(ssd, &update);
273 pixman_transform_t matrix;
274 struct pixman_f_transform matrix_f;
276 pixman_f_transform_init_identity(&matrix_f);
277 pixman_f_transform_scale(&matrix_f, NULL, RATIO_SCALE, RATIO_SCALE);
278 pixman_transform_from_pixman_f_transform(&matrix, &matrix_f);
279 pixman_image_set_transform(ssd->ds->image, &matrix);
280 pixman_image_set_filter(ssd->ds->image, PIXMAN_FILTER_BEST, NULL, 0);
284 .bottom = surface_height(ssd->ds),
286 .right = surface_width(ssd->ds),
289 qemu_spice_create_one_update(ssd, &update);
292 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
295 static SimpleSpiceCursor*
296 qemu_spice_create_cursor_update(SimpleSpiceDisplay *ssd,
300 size_t size = c ? c->width * c->height * 4 : 0;
301 SimpleSpiceCursor *update;
306 update = g_malloc0(sizeof(*update) + size);
308 cursor = &update->cursor;
309 cmd = &update->ext.cmd;
312 ccmd->type = QXL_CURSOR_SET;
313 ccmd->u.set.position.x = ssd->ptr_x + ssd->hot_x;
314 ccmd->u.set.position.y = ssd->ptr_y + ssd->hot_y;
315 ccmd->u.set.visible = true;
316 ccmd->u.set.shape = (uintptr_t)cursor;
317 cursor->header.unique = ssd->unique++;
318 cursor->header.type = SPICE_CURSOR_TYPE_ALPHA;
319 cursor->header.width = c->width;
320 cursor->header.height = c->height;
321 cursor->header.hot_spot_x = c->hot_x;
322 cursor->header.hot_spot_y = c->hot_y;
323 cursor->data_size = size;
324 cursor->chunk.data_size = size;
325 memcpy(cursor->chunk.data, c->data, size);
327 ccmd->type = QXL_CURSOR_HIDE;
329 ccmd->type = QXL_CURSOR_MOVE;
330 ccmd->u.position.x = ssd->ptr_x + ssd->hot_x;
331 ccmd->u.position.y = ssd->ptr_y + ssd->hot_y;
333 ccmd->release_info.id = (uintptr_t)(&update->ext);
335 cmd->type = QXL_CMD_CURSOR;
336 cmd->data = (uintptr_t)ccmd;
342 * Called from spice server thread context (via interface_release_resource)
343 * We do *not* hold the global qemu mutex here, so extra care is needed
344 * when calling qemu functions. QEMU interfaces used:
345 * - g_free (underlying glibc free is re-entrant).
347 void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update)
349 g_free(update->bitmap);
353 void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd)
355 QXLDevMemSlot memslot;
357 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
359 memset(&memslot, 0, sizeof(memslot));
360 memslot.slot_group_id = MEMSLOT_GROUP_HOST;
361 memslot.virt_end = ~0;
362 qemu_spice_add_memslot(ssd, &memslot, QXL_SYNC);
365 void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd)
367 QXLDevSurfaceCreate surface;
368 uint64_t surface_size;
370 memset(&surface, 0, sizeof(surface));
372 surface_size = (uint64_t) surface_width(ssd->ds) *
373 surface_height(ssd->ds) * 4;
374 assert(surface_size > 0);
375 assert(surface_size < INT_MAX);
376 if (ssd->bufsize < surface_size) {
377 ssd->bufsize = surface_size;
379 ssd->buf = g_malloc(ssd->bufsize);
382 dprint(1, "%s/%d: %ux%u (size %" PRIu64 "/%d)\n", __func__, ssd->qxl.id,
383 surface_width(ssd->ds), surface_height(ssd->ds),
384 surface_size, ssd->bufsize);
386 surface.format = SPICE_SURFACE_FMT_32_xRGB;
387 surface.width = surface_width(ssd->ds);
388 surface.height = surface_height(ssd->ds);
389 surface.stride = -surface.width * 4;
390 surface.mouse_mode = true;
393 surface.mem = (uintptr_t)ssd->buf;
394 surface.group_id = MEMSLOT_GROUP_HOST;
397 surface.width /= RATIO_SCALE;
398 surface.height /= RATIO_SCALE;
401 qemu_spice_create_primary_surface(ssd, 0, &surface, QXL_SYNC);
404 void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd)
406 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
408 qemu_spice_destroy_primary_surface(ssd, 0, QXL_SYNC);
411 void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd)
413 qemu_mutex_init(&ssd->lock);
414 QTAILQ_INIT(&ssd->updates);
417 if (ssd->num_surfaces == 0) {
418 ssd->num_surfaces = 1024;
422 /* display listener callbacks */
424 void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
425 int x, int y, int w, int h)
429 dprint(2, "%s/%d: x %d y %d w %d h %d\n", __func__,
430 ssd->qxl.id, x, y, w, h);
431 update_area.left = x,
432 update_area.right = x + w;
434 update_area.bottom = y + h;
436 if (qemu_spice_rect_is_empty(&ssd->dirty)) {
439 qemu_spice_rect_union(&ssd->dirty, &update_area);
442 void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
443 DisplaySurface *surface)
445 SimpleSpiceUpdate *update;
448 if (surface && ssd->surface &&
449 surface_width(surface) == pixman_image_get_width(ssd->surface) &&
450 surface_height(surface) == pixman_image_get_height(ssd->surface)) {
451 /* no-resize fast path: just swap backing store */
452 dprint(1, "%s/%d: fast (%dx%d)\n", __func__, ssd->qxl.id,
453 surface_width(surface), surface_height(surface));
454 qemu_mutex_lock(&ssd->lock);
456 pixman_image_unref(ssd->surface);
457 ssd->surface = pixman_image_ref(ssd->ds->image);
458 qemu_mutex_unlock(&ssd->lock);
459 qemu_spice_display_update(ssd, 0, 0,
460 surface_width(surface),
461 surface_height(surface));
465 /* full mode switch */
466 dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, ssd->qxl.id,
467 ssd->surface ? pixman_image_get_width(ssd->surface) : 0,
468 ssd->surface ? pixman_image_get_height(ssd->surface) : 0,
469 surface ? surface_width(surface) : 0,
470 surface ? surface_height(surface) : 0);
472 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
474 pixman_image_unref(ssd->surface);
476 pixman_image_unref(ssd->mirror);
480 qemu_mutex_lock(&ssd->lock);
481 need_destroy = (ssd->ds != NULL);
483 while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {
484 QTAILQ_REMOVE(&ssd->updates, update, next);
485 qemu_spice_destroy_update(ssd, update);
487 qemu_mutex_unlock(&ssd->lock);
489 qemu_spice_destroy_host_primary(ssd);
492 ssd->surface = pixman_image_ref(ssd->ds->image);
493 ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format,
495 qemu_spice_create_host_primary(ssd);
498 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
502 static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
505 assert(ssd->dcl.con);
506 dpy_cursor_define(ssd->dcl.con, ssd->cursor);
507 cursor_put(ssd->cursor);
510 if (ssd->mouse_x != -1 && ssd->mouse_y != -1) {
511 assert(ssd->dcl.con);
512 dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1);
518 void qemu_spice_cursor_refresh_bh(void *opaque)
520 SimpleSpiceDisplay *ssd = opaque;
522 qemu_mutex_lock(&ssd->lock);
523 qemu_spice_cursor_refresh_unlocked(ssd);
524 qemu_mutex_unlock(&ssd->lock);
527 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
529 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
530 graphic_hw_update(ssd->dcl.con);
532 qemu_mutex_lock(&ssd->lock);
533 if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) {
534 qemu_spice_create_update(ssd);
537 qemu_mutex_unlock(&ssd->lock);
541 qemu_spice_wakeup(ssd);
542 dprint(2, "%s/%d: notify\n", __func__, ssd->qxl.id);
546 /* spice display interface callbacks */
548 static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
550 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
552 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
553 ssd->worker = qxl_worker;
556 static void interface_set_compression_level(QXLInstance *sin, int level)
558 dprint(1, "%s/%d:\n", __func__, sin->id);
562 static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time)
564 dprint(3, "%s/%d:\n", __func__, sin->id);
568 static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info)
570 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
572 info->memslot_gen_bits = MEMSLOT_GENERATION_BITS;
573 info->memslot_id_bits = MEMSLOT_SLOT_BITS;
574 info->num_memslots = NUM_MEMSLOTS;
575 info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
576 info->internal_groupslot_id = 0;
577 info->qxl_ram_size = 16 * 1024 * 1024;
578 info->n_surfaces = ssd->num_surfaces;
581 static int interface_get_command(QXLInstance *sin, QXLCommandExt *ext)
583 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
584 SimpleSpiceUpdate *update;
587 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
589 qemu_mutex_lock(&ssd->lock);
590 update = QTAILQ_FIRST(&ssd->updates);
591 if (update != NULL) {
592 QTAILQ_REMOVE(&ssd->updates, update, next);
596 qemu_mutex_unlock(&ssd->lock);
601 static int interface_req_cmd_notification(QXLInstance *sin)
603 dprint(1, "%s/%d:\n", __func__, sin->id);
607 static void interface_release_resource(QXLInstance *sin,
608 QXLReleaseInfoExt rext)
610 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
611 SimpleSpiceUpdate *update;
612 SimpleSpiceCursor *cursor;
615 dprint(2, "%s/%d:\n", __func__, ssd->qxl.id);
616 ext = (void *)(intptr_t)(rext.info->id);
617 switch (ext->cmd.type) {
619 update = container_of(ext, SimpleSpiceUpdate, ext);
620 qemu_spice_destroy_update(ssd, update);
623 cursor = container_of(ext, SimpleSpiceCursor, ext);
627 g_assert_not_reached();
631 static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext)
633 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
636 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
638 qemu_mutex_lock(&ssd->lock);
639 if (ssd->ptr_define) {
640 *ext = ssd->ptr_define->ext;
641 ssd->ptr_define = NULL;
643 } else if (ssd->ptr_move) {
644 *ext = ssd->ptr_move->ext;
645 ssd->ptr_move = NULL;
650 qemu_mutex_unlock(&ssd->lock);
654 static int interface_req_cursor_notification(QXLInstance *sin)
656 dprint(1, "%s:\n", __FUNCTION__);
660 static void interface_notify_update(QXLInstance *sin, uint32_t update_id)
662 fprintf(stderr, "%s: abort()\n", __FUNCTION__);
666 static int interface_flush_resources(QXLInstance *sin)
668 fprintf(stderr, "%s: abort()\n", __FUNCTION__);
673 static void interface_update_area_complete(QXLInstance *sin,
675 QXLRect *dirty, uint32_t num_updated_rects)
677 /* should never be called, used in qxl native mode only */
678 fprintf(stderr, "%s: abort()\n", __func__);
682 /* called from spice server thread context only */
683 static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
685 /* should never be called, used in qxl native mode only */
686 fprintf(stderr, "%s: abort()\n", __func__);
690 static void interface_set_client_capabilities(QXLInstance *sin,
691 uint8_t client_present,
694 dprint(3, "%s:\n", __func__);
697 static int interface_client_monitors_config(QXLInstance *sin,
698 VDAgentMonitorsConfig *mc)
700 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
703 if (!dpy_ui_info_supported(ssd->dcl.con)) {
704 return 0; /* == not supported by guest */
712 * FIXME: multihead is tricky due to the way
713 * spice has multihead implemented.
715 memset(&info, 0, sizeof(info));
716 if (mc->num_of_monitors > 0) {
717 info.width = mc->monitors[0].width;
718 info.height = mc->monitors[0].height;
720 dpy_set_ui_info(ssd->dcl.con, &info);
721 dprint(1, "%s/%d: size %dx%d\n", __func__, ssd->qxl.id,
722 info.width, info.height);
726 static const QXLInterface dpy_interface = {
727 .base.type = SPICE_INTERFACE_QXL,
728 .base.description = "qemu simple display",
729 .base.major_version = SPICE_INTERFACE_QXL_MAJOR,
730 .base.minor_version = SPICE_INTERFACE_QXL_MINOR,
732 .attache_worker = interface_attach_worker,
733 .set_compression_level = interface_set_compression_level,
734 .set_mm_time = interface_set_mm_time,
735 .get_init_info = interface_get_init_info,
737 /* the callbacks below are called from spice server thread context */
738 .get_command = interface_get_command,
739 .req_cmd_notification = interface_req_cmd_notification,
740 .release_resource = interface_release_resource,
741 .get_cursor_command = interface_get_cursor_command,
742 .req_cursor_notification = interface_req_cursor_notification,
743 .notify_update = interface_notify_update,
744 .flush_resources = interface_flush_resources,
745 .async_complete = interface_async_complete,
746 .update_area_complete = interface_update_area_complete,
747 .set_client_capabilities = interface_set_client_capabilities,
748 .client_monitors_config = interface_client_monitors_config,
751 static void display_update(DisplayChangeListener *dcl,
752 int x, int y, int w, int h)
754 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
755 qemu_spice_display_update(ssd, x, y, w, h);
758 static void display_switch(DisplayChangeListener *dcl,
759 DisplaySurface *surface)
761 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
762 qemu_spice_display_switch(ssd, surface);
765 static void display_refresh(DisplayChangeListener *dcl)
767 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
768 qemu_spice_display_refresh(ssd);
771 static void display_mouse_set(DisplayChangeListener *dcl,
772 int x, int y, int on)
774 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
776 qemu_mutex_lock(&ssd->lock);
780 g_free(ssd->ptr_move);
782 ssd->ptr_move = qemu_spice_create_cursor_update(ssd, NULL, on);
783 qemu_mutex_unlock(&ssd->lock);
786 static void display_mouse_define(DisplayChangeListener *dcl,
789 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
791 qemu_mutex_lock(&ssd->lock);
792 ssd->hot_x = c->hot_x;
793 ssd->hot_y = c->hot_y;
795 g_free(ssd->ptr_move);
796 ssd->ptr_move = NULL;
798 if (ssd->ptr_define) {
799 g_free(ssd->ptr_define);
801 ssd->ptr_define = qemu_spice_create_cursor_update(ssd, c, 0);
802 qemu_mutex_unlock(&ssd->lock);
805 static const DisplayChangeListenerOps display_listener_ops = {
807 .dpy_gfx_update = display_update,
808 .dpy_gfx_switch = display_switch,
809 .dpy_gfx_check_format = qemu_pixman_check_format,
810 .dpy_refresh = display_refresh,
811 .dpy_mouse_set = display_mouse_set,
812 .dpy_cursor_define = display_mouse_define,
815 static void qemu_spice_display_init_one(QemuConsole *con)
817 SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1);
819 qemu_spice_display_init_common(ssd);
821 ssd->qxl.base.sif = &dpy_interface.base;
822 qemu_spice_add_display_interface(&ssd->qxl, con);
825 qemu_spice_create_host_memslot(ssd);
827 ssd->dcl.ops = &display_listener_ops;
829 register_displaychangelistener(&ssd->dcl);
832 void qemu_spice_display_init(void)
838 con = qemu_console_lookup_by_index(i);
839 if (!con || !qemu_console_is_graphic(con)) {
842 if (qemu_spice_have_display_interface(con)) {
845 qemu_spice_display_init_one(con);