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 surface_format(surface) == pixman_image_get_format(ssd->surface)) {
452 /* no-resize fast path: just swap backing store */
453 dprint(1, "%s/%d: fast (%dx%d)\n", __func__, ssd->qxl.id,
454 surface_width(surface), surface_height(surface));
455 qemu_mutex_lock(&ssd->lock);
457 pixman_image_unref(ssd->surface);
458 ssd->surface = pixman_image_ref(ssd->ds->image);
459 qemu_mutex_unlock(&ssd->lock);
460 qemu_spice_display_update(ssd, 0, 0,
461 surface_width(surface),
462 surface_height(surface));
466 /* full mode switch */
467 dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, ssd->qxl.id,
468 ssd->surface ? pixman_image_get_width(ssd->surface) : 0,
469 ssd->surface ? pixman_image_get_height(ssd->surface) : 0,
470 surface ? surface_width(surface) : 0,
471 surface ? surface_height(surface) : 0);
473 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
475 pixman_image_unref(ssd->surface);
477 pixman_image_unref(ssd->mirror);
481 qemu_mutex_lock(&ssd->lock);
482 need_destroy = (ssd->ds != NULL);
484 while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {
485 QTAILQ_REMOVE(&ssd->updates, update, next);
486 qemu_spice_destroy_update(ssd, update);
488 qemu_mutex_unlock(&ssd->lock);
490 qemu_spice_destroy_host_primary(ssd);
493 ssd->surface = pixman_image_ref(ssd->ds->image);
494 ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format,
496 qemu_spice_create_host_primary(ssd);
499 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
503 static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
506 assert(ssd->dcl.con);
507 dpy_cursor_define(ssd->dcl.con, ssd->cursor);
508 cursor_put(ssd->cursor);
511 if (ssd->mouse_x != -1 && ssd->mouse_y != -1) {
512 assert(ssd->dcl.con);
513 dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1);
519 void qemu_spice_cursor_refresh_bh(void *opaque)
521 SimpleSpiceDisplay *ssd = opaque;
523 qemu_mutex_lock(&ssd->lock);
524 qemu_spice_cursor_refresh_unlocked(ssd);
525 qemu_mutex_unlock(&ssd->lock);
528 void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
530 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
531 graphic_hw_update(ssd->dcl.con);
533 qemu_mutex_lock(&ssd->lock);
534 if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) {
535 qemu_spice_create_update(ssd);
538 qemu_mutex_unlock(&ssd->lock);
542 qemu_spice_wakeup(ssd);
543 dprint(2, "%s/%d: notify\n", __func__, ssd->qxl.id);
547 /* spice display interface callbacks */
549 static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
551 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
553 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
554 ssd->worker = qxl_worker;
557 static void interface_set_compression_level(QXLInstance *sin, int level)
559 dprint(1, "%s/%d:\n", __func__, sin->id);
563 static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time)
565 dprint(3, "%s/%d:\n", __func__, sin->id);
569 static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info)
571 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
573 info->memslot_gen_bits = MEMSLOT_GENERATION_BITS;
574 info->memslot_id_bits = MEMSLOT_SLOT_BITS;
575 info->num_memslots = NUM_MEMSLOTS;
576 info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
577 info->internal_groupslot_id = 0;
578 info->qxl_ram_size = 16 * 1024 * 1024;
579 info->n_surfaces = ssd->num_surfaces;
582 static int interface_get_command(QXLInstance *sin, QXLCommandExt *ext)
584 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
585 SimpleSpiceUpdate *update;
588 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
590 qemu_mutex_lock(&ssd->lock);
591 update = QTAILQ_FIRST(&ssd->updates);
592 if (update != NULL) {
593 QTAILQ_REMOVE(&ssd->updates, update, next);
597 qemu_mutex_unlock(&ssd->lock);
602 static int interface_req_cmd_notification(QXLInstance *sin)
604 dprint(1, "%s/%d:\n", __func__, sin->id);
608 static void interface_release_resource(QXLInstance *sin,
609 QXLReleaseInfoExt rext)
611 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
612 SimpleSpiceUpdate *update;
613 SimpleSpiceCursor *cursor;
616 dprint(2, "%s/%d:\n", __func__, ssd->qxl.id);
617 ext = (void *)(intptr_t)(rext.info->id);
618 switch (ext->cmd.type) {
620 update = container_of(ext, SimpleSpiceUpdate, ext);
621 qemu_spice_destroy_update(ssd, update);
624 cursor = container_of(ext, SimpleSpiceCursor, ext);
628 g_assert_not_reached();
632 static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext)
634 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
637 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
639 qemu_mutex_lock(&ssd->lock);
640 if (ssd->ptr_define) {
641 *ext = ssd->ptr_define->ext;
642 ssd->ptr_define = NULL;
644 } else if (ssd->ptr_move) {
645 *ext = ssd->ptr_move->ext;
646 ssd->ptr_move = NULL;
651 qemu_mutex_unlock(&ssd->lock);
655 static int interface_req_cursor_notification(QXLInstance *sin)
657 dprint(1, "%s:\n", __FUNCTION__);
661 static void interface_notify_update(QXLInstance *sin, uint32_t update_id)
663 fprintf(stderr, "%s: abort()\n", __FUNCTION__);
667 static int interface_flush_resources(QXLInstance *sin)
669 fprintf(stderr, "%s: abort()\n", __FUNCTION__);
674 static void interface_update_area_complete(QXLInstance *sin,
676 QXLRect *dirty, uint32_t num_updated_rects)
678 /* should never be called, used in qxl native mode only */
679 fprintf(stderr, "%s: abort()\n", __func__);
683 /* called from spice server thread context only */
684 static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
686 /* should never be called, used in qxl native mode only */
687 fprintf(stderr, "%s: abort()\n", __func__);
691 static void interface_set_client_capabilities(QXLInstance *sin,
692 uint8_t client_present,
695 dprint(3, "%s:\n", __func__);
698 static int interface_client_monitors_config(QXLInstance *sin,
699 VDAgentMonitorsConfig *mc)
701 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
704 if (!dpy_ui_info_supported(ssd->dcl.con)) {
705 return 0; /* == not supported by guest */
713 * FIXME: multihead is tricky due to the way
714 * spice has multihead implemented.
716 memset(&info, 0, sizeof(info));
717 if (mc->num_of_monitors > 0) {
718 info.width = mc->monitors[0].width;
719 info.height = mc->monitors[0].height;
721 dpy_set_ui_info(ssd->dcl.con, &info);
722 dprint(1, "%s/%d: size %dx%d\n", __func__, ssd->qxl.id,
723 info.width, info.height);
727 static const QXLInterface dpy_interface = {
728 .base.type = SPICE_INTERFACE_QXL,
729 .base.description = "qemu simple display",
730 .base.major_version = SPICE_INTERFACE_QXL_MAJOR,
731 .base.minor_version = SPICE_INTERFACE_QXL_MINOR,
733 .attache_worker = interface_attach_worker,
734 .set_compression_level = interface_set_compression_level,
735 .set_mm_time = interface_set_mm_time,
736 .get_init_info = interface_get_init_info,
738 /* the callbacks below are called from spice server thread context */
739 .get_command = interface_get_command,
740 .req_cmd_notification = interface_req_cmd_notification,
741 .release_resource = interface_release_resource,
742 .get_cursor_command = interface_get_cursor_command,
743 .req_cursor_notification = interface_req_cursor_notification,
744 .notify_update = interface_notify_update,
745 .flush_resources = interface_flush_resources,
746 .async_complete = interface_async_complete,
747 .update_area_complete = interface_update_area_complete,
748 .set_client_capabilities = interface_set_client_capabilities,
749 .client_monitors_config = interface_client_monitors_config,
752 static void display_update(DisplayChangeListener *dcl,
753 int x, int y, int w, int h)
755 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
756 qemu_spice_display_update(ssd, x, y, w, h);
759 static void display_switch(DisplayChangeListener *dcl,
760 DisplaySurface *surface)
762 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
763 qemu_spice_display_switch(ssd, surface);
766 static void display_refresh(DisplayChangeListener *dcl)
768 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
769 qemu_spice_display_refresh(ssd);
772 static void display_mouse_set(DisplayChangeListener *dcl,
773 int x, int y, int on)
775 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
777 qemu_mutex_lock(&ssd->lock);
780 g_free(ssd->ptr_move);
781 ssd->ptr_move = qemu_spice_create_cursor_update(ssd, NULL, on);
782 qemu_mutex_unlock(&ssd->lock);
785 static void display_mouse_define(DisplayChangeListener *dcl,
788 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
790 qemu_mutex_lock(&ssd->lock);
791 ssd->hot_x = c->hot_x;
792 ssd->hot_y = c->hot_y;
793 g_free(ssd->ptr_move);
794 ssd->ptr_move = NULL;
795 g_free(ssd->ptr_define);
796 ssd->ptr_define = qemu_spice_create_cursor_update(ssd, c, 0);
797 qemu_mutex_unlock(&ssd->lock);
800 static const DisplayChangeListenerOps display_listener_ops = {
802 .dpy_gfx_update = display_update,
803 .dpy_gfx_switch = display_switch,
804 .dpy_gfx_check_format = qemu_pixman_check_format,
805 .dpy_refresh = display_refresh,
806 .dpy_mouse_set = display_mouse_set,
807 .dpy_cursor_define = display_mouse_define,
810 static void qemu_spice_display_init_one(QemuConsole *con)
812 SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1);
814 qemu_spice_display_init_common(ssd);
816 ssd->qxl.base.sif = &dpy_interface.base;
817 qemu_spice_add_display_interface(&ssd->qxl, con);
820 qemu_spice_create_host_memslot(ssd);
822 ssd->dcl.ops = &display_listener_ops;
824 register_displaychangelistener(&ssd->dcl);
827 void qemu_spice_display_init(void)
833 con = qemu_console_lookup_by_index(i);
834 if (!con || !qemu_console_is_graphic(con)) {
837 if (qemu_spice_have_display_interface(con)) {
840 qemu_spice_display_init_one(con);