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 "monitor/monitor.h"
23 #include "ui/console.h"
24 #include "sysemu/sysemu.h"
27 #include "ui/spice-display.h"
31 static void GCC_FMT_ATTR(2, 3) dprint(int level
, const char *fmt
, ...)
37 vfprintf(stderr
, fmt
, args
);
42 int qemu_spice_rect_is_empty(const QXLRect
* r
)
44 return r
->top
== r
->bottom
|| r
->left
== r
->right
;
47 void qemu_spice_rect_union(QXLRect
*dest
, const QXLRect
*r
)
49 if (qemu_spice_rect_is_empty(r
)) {
53 if (qemu_spice_rect_is_empty(dest
)) {
58 dest
->top
= MIN(dest
->top
, r
->top
);
59 dest
->left
= MIN(dest
->left
, r
->left
);
60 dest
->bottom
= MAX(dest
->bottom
, r
->bottom
);
61 dest
->right
= MAX(dest
->right
, r
->right
);
64 QXLCookie
*qxl_cookie_new(int type
, uint64_t io
)
68 cookie
= g_malloc0(sizeof(*cookie
));
74 void qemu_spice_add_memslot(SimpleSpiceDisplay
*ssd
, QXLDevMemSlot
*memslot
,
77 trace_qemu_spice_add_memslot(ssd
->qxl
.id
, memslot
->slot_id
,
78 memslot
->virt_start
, memslot
->virt_end
,
81 if (async
!= QXL_SYNC
) {
82 spice_qxl_add_memslot_async(&ssd
->qxl
, memslot
,
83 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO
,
84 QXL_IO_MEMSLOT_ADD_ASYNC
));
86 spice_qxl_add_memslot(&ssd
->qxl
, memslot
);
90 void qemu_spice_del_memslot(SimpleSpiceDisplay
*ssd
, uint32_t gid
, uint32_t sid
)
92 trace_qemu_spice_del_memslot(ssd
->qxl
.id
, gid
, sid
);
93 spice_qxl_del_memslot(&ssd
->qxl
, gid
, sid
);
96 void qemu_spice_create_primary_surface(SimpleSpiceDisplay
*ssd
, uint32_t id
,
97 QXLDevSurfaceCreate
*surface
,
100 trace_qemu_spice_create_primary_surface(ssd
->qxl
.id
, id
, surface
, async
);
101 if (async
!= QXL_SYNC
) {
102 spice_qxl_create_primary_surface_async(&ssd
->qxl
, id
, surface
,
103 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO
,
104 QXL_IO_CREATE_PRIMARY_ASYNC
));
106 spice_qxl_create_primary_surface(&ssd
->qxl
, id
, surface
);
110 void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay
*ssd
,
111 uint32_t id
, qxl_async_io async
)
113 trace_qemu_spice_destroy_primary_surface(ssd
->qxl
.id
, id
, async
);
114 if (async
!= QXL_SYNC
) {
115 spice_qxl_destroy_primary_surface_async(&ssd
->qxl
, id
,
116 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO
,
117 QXL_IO_DESTROY_PRIMARY_ASYNC
));
119 spice_qxl_destroy_primary_surface(&ssd
->qxl
, id
);
123 void qemu_spice_wakeup(SimpleSpiceDisplay
*ssd
)
125 trace_qemu_spice_wakeup(ssd
->qxl
.id
);
126 spice_qxl_wakeup(&ssd
->qxl
);
129 static void qemu_spice_create_one_update(SimpleSpiceDisplay
*ssd
,
132 SimpleSpiceUpdate
*update
;
133 QXLDrawable
*drawable
;
137 struct timespec time_space
;
138 pixman_image_t
*dest
;
140 trace_qemu_spice_create_update(
141 rect
->left
, rect
->right
,
142 rect
->top
, rect
->bottom
);
144 update
= g_malloc0(sizeof(*update
));
145 drawable
= &update
->drawable
;
146 image
= &update
->image
;
147 cmd
= &update
->ext
.cmd
;
149 bw
= rect
->right
- rect
->left
;
150 bh
= rect
->bottom
- rect
->top
;
151 update
->bitmap
= g_malloc(bw
* bh
* 4);
153 drawable
->bbox
= *rect
;
154 drawable
->clip
.type
= SPICE_CLIP_TYPE_NONE
;
155 drawable
->effect
= QXL_EFFECT_OPAQUE
;
156 drawable
->release_info
.id
= (uintptr_t)(&update
->ext
);
157 drawable
->type
= QXL_DRAW_COPY
;
158 drawable
->surfaces_dest
[0] = -1;
159 drawable
->surfaces_dest
[1] = -1;
160 drawable
->surfaces_dest
[2] = -1;
161 clock_gettime(CLOCK_MONOTONIC
, &time_space
);
162 /* time in milliseconds from epoch. */
163 drawable
->mm_time
= time_space
.tv_sec
* 1000
164 + time_space
.tv_nsec
/ 1000 / 1000;
166 drawable
->u
.copy
.rop_descriptor
= SPICE_ROPD_OP_PUT
;
167 drawable
->u
.copy
.src_bitmap
= (uintptr_t)image
;
168 drawable
->u
.copy
.src_area
.right
= bw
;
169 drawable
->u
.copy
.src_area
.bottom
= bh
;
171 QXL_SET_IMAGE_ID(image
, QXL_IMAGE_GROUP_DEVICE
, ssd
->unique
++);
172 image
->descriptor
.type
= SPICE_IMAGE_TYPE_BITMAP
;
173 image
->bitmap
.flags
= QXL_BITMAP_DIRECT
| QXL_BITMAP_TOP_DOWN
;
174 image
->bitmap
.stride
= bw
* 4;
175 image
->descriptor
.width
= image
->bitmap
.x
= bw
;
176 image
->descriptor
.height
= image
->bitmap
.y
= bh
;
177 image
->bitmap
.data
= (uintptr_t)(update
->bitmap
);
178 image
->bitmap
.palette
= 0;
179 image
->bitmap
.format
= SPICE_BITMAP_FMT_32BIT
;
181 dest
= pixman_image_create_bits(PIXMAN_x8r8g8b8
, bw
, bh
,
182 (void *)update
->bitmap
, bw
* 4);
183 pixman_image_composite(PIXMAN_OP_SRC
, ssd
->surface
, NULL
, ssd
->mirror
,
184 rect
->left
, rect
->top
, 0, 0,
185 rect
->left
, rect
->top
, bw
, bh
);
186 pixman_image_composite(PIXMAN_OP_SRC
, ssd
->mirror
, NULL
, dest
,
187 rect
->left
, rect
->top
, 0, 0,
189 pixman_image_unref(dest
);
191 cmd
->type
= QXL_CMD_DRAW
;
192 cmd
->data
= (uintptr_t)drawable
;
194 QTAILQ_INSERT_TAIL(&ssd
->updates
, update
, next
);
197 static void qemu_spice_create_update(SimpleSpiceDisplay
*ssd
)
199 static const int blksize
= 32;
200 int blocks
= (surface_width(ssd
->ds
) + blksize
- 1) / blksize
;
201 int dirty_top
[blocks
];
202 int y
, yoff
, x
, xoff
, blk
, bw
;
203 int bpp
= surface_bytes_per_pixel(ssd
->ds
);
204 uint8_t *guest
, *mirror
;
206 if (qemu_spice_rect_is_empty(&ssd
->dirty
)) {
210 for (blk
= 0; blk
< blocks
; blk
++) {
214 guest
= surface_data(ssd
->ds
);
215 mirror
= (void *)pixman_image_get_data(ssd
->mirror
);
216 for (y
= ssd
->dirty
.top
; y
< ssd
->dirty
.bottom
; y
++) {
217 yoff
= y
* surface_stride(ssd
->ds
);
218 for (x
= ssd
->dirty
.left
; x
< ssd
->dirty
.right
; x
+= blksize
) {
221 bw
= MIN(blksize
, ssd
->dirty
.right
- x
);
222 if (memcmp(guest
+ yoff
+ xoff
,
223 mirror
+ yoff
+ xoff
,
225 if (dirty_top
[blk
] != -1) {
227 .top
= dirty_top
[blk
],
232 qemu_spice_create_one_update(ssd
, &update
);
236 if (dirty_top
[blk
] == -1) {
243 for (x
= ssd
->dirty
.left
; x
< ssd
->dirty
.right
; x
+= blksize
) {
245 bw
= MIN(blksize
, ssd
->dirty
.right
- x
);
246 if (dirty_top
[blk
] != -1) {
248 .top
= dirty_top
[blk
],
249 .bottom
= ssd
->dirty
.bottom
,
253 qemu_spice_create_one_update(ssd
, &update
);
258 memset(&ssd
->dirty
, 0, sizeof(ssd
->dirty
));
261 static SimpleSpiceCursor
*
262 qemu_spice_create_cursor_update(SimpleSpiceDisplay
*ssd
,
265 size_t size
= c
? c
->width
* c
->height
* 4 : 0;
266 SimpleSpiceCursor
*update
;
271 update
= g_malloc0(sizeof(*update
) + size
);
273 cursor
= &update
->cursor
;
274 cmd
= &update
->ext
.cmd
;
277 ccmd
->type
= QXL_CURSOR_SET
;
278 ccmd
->u
.set
.position
.x
= ssd
->ptr_x
;
279 ccmd
->u
.set
.position
.y
= ssd
->ptr_y
;
280 ccmd
->u
.set
.visible
= true;
281 ccmd
->u
.set
.shape
= (uintptr_t)cursor
;
282 cursor
->header
.unique
= ssd
->unique
++;
283 cursor
->header
.type
= SPICE_CURSOR_TYPE_ALPHA
;
284 cursor
->header
.width
= c
->width
;
285 cursor
->header
.height
= c
->height
;
286 cursor
->header
.hot_spot_x
= c
->hot_x
;
287 cursor
->header
.hot_spot_y
= c
->hot_y
;
288 cursor
->data_size
= size
;
289 cursor
->chunk
.data_size
= size
;
290 memcpy(cursor
->chunk
.data
, c
->data
, size
);
292 ccmd
->type
= QXL_CURSOR_MOVE
;
293 ccmd
->u
.position
.x
= ssd
->ptr_x
;
294 ccmd
->u
.position
.y
= ssd
->ptr_y
;
296 ccmd
->release_info
.id
= (uintptr_t)(&update
->ext
);
298 cmd
->type
= QXL_CMD_CURSOR
;
299 cmd
->data
= (uintptr_t)ccmd
;
305 * Called from spice server thread context (via interface_release_resource)
306 * We do *not* hold the global qemu mutex here, so extra care is needed
307 * when calling qemu functions. QEMU interfaces used:
308 * - g_free (underlying glibc free is re-entrant).
310 void qemu_spice_destroy_update(SimpleSpiceDisplay
*sdpy
, SimpleSpiceUpdate
*update
)
312 g_free(update
->bitmap
);
316 void qemu_spice_create_host_memslot(SimpleSpiceDisplay
*ssd
)
318 QXLDevMemSlot memslot
;
320 dprint(1, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
322 memset(&memslot
, 0, sizeof(memslot
));
323 memslot
.slot_group_id
= MEMSLOT_GROUP_HOST
;
324 memslot
.virt_end
= ~0;
325 qemu_spice_add_memslot(ssd
, &memslot
, QXL_SYNC
);
328 void qemu_spice_create_host_primary(SimpleSpiceDisplay
*ssd
)
330 QXLDevSurfaceCreate surface
;
331 uint64_t surface_size
;
333 memset(&surface
, 0, sizeof(surface
));
335 surface_size
= (uint64_t) surface_width(ssd
->ds
) *
336 surface_height(ssd
->ds
) * 4;
337 assert(surface_size
> 0);
338 assert(surface_size
< INT_MAX
);
339 if (ssd
->bufsize
< surface_size
) {
340 ssd
->bufsize
= surface_size
;
342 ssd
->buf
= g_malloc(ssd
->bufsize
);
345 dprint(1, "%s/%d: %ux%u (size %" PRIu64
"/%d)\n", __func__
, ssd
->qxl
.id
,
346 surface_width(ssd
->ds
), surface_height(ssd
->ds
),
347 surface_size
, ssd
->bufsize
);
349 surface
.format
= SPICE_SURFACE_FMT_32_xRGB
;
350 surface
.width
= surface_width(ssd
->ds
);
351 surface
.height
= surface_height(ssd
->ds
);
352 surface
.stride
= -surface
.width
* 4;
353 surface
.mouse_mode
= true;
356 surface
.mem
= (uintptr_t)ssd
->buf
;
357 surface
.group_id
= MEMSLOT_GROUP_HOST
;
359 qemu_spice_create_primary_surface(ssd
, 0, &surface
, QXL_SYNC
);
362 void qemu_spice_destroy_host_primary(SimpleSpiceDisplay
*ssd
)
364 dprint(1, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
366 qemu_spice_destroy_primary_surface(ssd
, 0, QXL_SYNC
);
369 void qemu_spice_display_init_common(SimpleSpiceDisplay
*ssd
)
371 qemu_mutex_init(&ssd
->lock
);
372 QTAILQ_INIT(&ssd
->updates
);
375 if (ssd
->num_surfaces
== 0) {
376 ssd
->num_surfaces
= 1024;
380 /* display listener callbacks */
382 void qemu_spice_display_update(SimpleSpiceDisplay
*ssd
,
383 int x
, int y
, int w
, int h
)
387 dprint(2, "%s/%d: x %d y %d w %d h %d\n", __func__
,
388 ssd
->qxl
.id
, x
, y
, w
, h
);
389 update_area
.left
= x
,
390 update_area
.right
= x
+ w
;
392 update_area
.bottom
= y
+ h
;
394 if (qemu_spice_rect_is_empty(&ssd
->dirty
)) {
397 qemu_spice_rect_union(&ssd
->dirty
, &update_area
);
400 void qemu_spice_display_switch(SimpleSpiceDisplay
*ssd
,
401 DisplaySurface
*surface
)
403 SimpleSpiceUpdate
*update
;
406 if (surface
&& ssd
->surface
&&
407 surface_width(surface
) == pixman_image_get_width(ssd
->surface
) &&
408 surface_height(surface
) == pixman_image_get_height(ssd
->surface
)) {
409 /* no-resize fast path: just swap backing store */
410 dprint(1, "%s/%d: fast (%dx%d)\n", __func__
, ssd
->qxl
.id
,
411 surface_width(surface
), surface_height(surface
));
412 qemu_mutex_lock(&ssd
->lock
);
414 pixman_image_unref(ssd
->surface
);
415 ssd
->surface
= pixman_image_ref(ssd
->ds
->image
);
416 qemu_mutex_unlock(&ssd
->lock
);
417 qemu_spice_display_update(ssd
, 0, 0,
418 surface_width(surface
),
419 surface_height(surface
));
423 /* full mode switch */
424 dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__
, ssd
->qxl
.id
,
425 ssd
->surface
? pixman_image_get_width(ssd
->surface
) : 0,
426 ssd
->surface
? pixman_image_get_height(ssd
->surface
) : 0,
427 surface
? surface_width(surface
) : 0,
428 surface
? surface_height(surface
) : 0);
430 memset(&ssd
->dirty
, 0, sizeof(ssd
->dirty
));
432 pixman_image_unref(ssd
->surface
);
434 pixman_image_unref(ssd
->mirror
);
438 qemu_mutex_lock(&ssd
->lock
);
439 need_destroy
= (ssd
->ds
!= NULL
);
441 ssd
->surface
= pixman_image_ref(ssd
->ds
->image
);
442 ssd
->mirror
= qemu_pixman_mirror_create(ssd
->ds
->format
,
444 while ((update
= QTAILQ_FIRST(&ssd
->updates
)) != NULL
) {
445 QTAILQ_REMOVE(&ssd
->updates
, update
, next
);
446 qemu_spice_destroy_update(ssd
, update
);
448 qemu_mutex_unlock(&ssd
->lock
);
450 qemu_spice_destroy_host_primary(ssd
);
453 qemu_spice_create_host_primary(ssd
);
456 memset(&ssd
->dirty
, 0, sizeof(ssd
->dirty
));
460 static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay
*ssd
)
463 assert(ssd
->dcl
.con
);
464 dpy_cursor_define(ssd
->dcl
.con
, ssd
->cursor
);
465 cursor_put(ssd
->cursor
);
468 if (ssd
->mouse_x
!= -1 && ssd
->mouse_y
!= -1) {
469 assert(ssd
->dcl
.con
);
470 dpy_mouse_set(ssd
->dcl
.con
, ssd
->mouse_x
, ssd
->mouse_y
, 1);
476 void qemu_spice_cursor_refresh_bh(void *opaque
)
478 SimpleSpiceDisplay
*ssd
= opaque
;
480 qemu_mutex_lock(&ssd
->lock
);
481 qemu_spice_cursor_refresh_unlocked(ssd
);
482 qemu_mutex_unlock(&ssd
->lock
);
485 void qemu_spice_display_refresh(SimpleSpiceDisplay
*ssd
)
487 dprint(3, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
488 graphic_hw_update(ssd
->dcl
.con
);
490 qemu_mutex_lock(&ssd
->lock
);
491 if (QTAILQ_EMPTY(&ssd
->updates
) && ssd
->ds
) {
492 qemu_spice_create_update(ssd
);
495 qemu_mutex_unlock(&ssd
->lock
);
499 qemu_spice_wakeup(ssd
);
500 dprint(2, "%s/%d: notify\n", __func__
, ssd
->qxl
.id
);
504 /* spice display interface callbacks */
506 static void interface_attach_worker(QXLInstance
*sin
, QXLWorker
*qxl_worker
)
508 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
510 dprint(1, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
511 ssd
->worker
= qxl_worker
;
514 static void interface_set_compression_level(QXLInstance
*sin
, int level
)
516 dprint(1, "%s/%d:\n", __func__
, sin
->id
);
520 static void interface_set_mm_time(QXLInstance
*sin
, uint32_t mm_time
)
522 dprint(3, "%s/%d:\n", __func__
, sin
->id
);
526 static void interface_get_init_info(QXLInstance
*sin
, QXLDevInitInfo
*info
)
528 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
530 info
->memslot_gen_bits
= MEMSLOT_GENERATION_BITS
;
531 info
->memslot_id_bits
= MEMSLOT_SLOT_BITS
;
532 info
->num_memslots
= NUM_MEMSLOTS
;
533 info
->num_memslots_groups
= NUM_MEMSLOTS_GROUPS
;
534 info
->internal_groupslot_id
= 0;
535 info
->qxl_ram_size
= 16 * 1024 * 1024;
536 info
->n_surfaces
= ssd
->num_surfaces
;
539 static int interface_get_command(QXLInstance
*sin
, struct QXLCommandExt
*ext
)
541 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
542 SimpleSpiceUpdate
*update
;
545 dprint(3, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
547 qemu_mutex_lock(&ssd
->lock
);
548 update
= QTAILQ_FIRST(&ssd
->updates
);
549 if (update
!= NULL
) {
550 QTAILQ_REMOVE(&ssd
->updates
, update
, next
);
554 qemu_mutex_unlock(&ssd
->lock
);
559 static int interface_req_cmd_notification(QXLInstance
*sin
)
561 dprint(1, "%s/%d:\n", __func__
, sin
->id
);
565 static void interface_release_resource(QXLInstance
*sin
,
566 struct QXLReleaseInfoExt rext
)
568 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
569 SimpleSpiceUpdate
*update
;
570 SimpleSpiceCursor
*cursor
;
573 dprint(2, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
574 ext
= (void *)(intptr_t)(rext
.info
->id
);
575 switch (ext
->cmd
.type
) {
577 update
= container_of(ext
, SimpleSpiceUpdate
, ext
);
578 qemu_spice_destroy_update(ssd
, update
);
581 cursor
= container_of(ext
, SimpleSpiceCursor
, ext
);
585 g_assert_not_reached();
589 static int interface_get_cursor_command(QXLInstance
*sin
, struct QXLCommandExt
*ext
)
591 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
594 dprint(3, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
596 qemu_mutex_lock(&ssd
->lock
);
597 if (ssd
->ptr_define
) {
598 *ext
= ssd
->ptr_define
->ext
;
599 ssd
->ptr_define
= NULL
;
601 } else if (ssd
->ptr_move
) {
602 *ext
= ssd
->ptr_move
->ext
;
603 ssd
->ptr_move
= NULL
;
608 qemu_mutex_unlock(&ssd
->lock
);
612 static int interface_req_cursor_notification(QXLInstance
*sin
)
614 dprint(1, "%s:\n", __FUNCTION__
);
618 static void interface_notify_update(QXLInstance
*sin
, uint32_t update_id
)
620 fprintf(stderr
, "%s: abort()\n", __FUNCTION__
);
624 static int interface_flush_resources(QXLInstance
*sin
)
626 fprintf(stderr
, "%s: abort()\n", __FUNCTION__
);
631 static void interface_update_area_complete(QXLInstance
*sin
,
633 QXLRect
*dirty
, uint32_t num_updated_rects
)
635 /* should never be called, used in qxl native mode only */
636 fprintf(stderr
, "%s: abort()\n", __func__
);
640 /* called from spice server thread context only */
641 static void interface_async_complete(QXLInstance
*sin
, uint64_t cookie_token
)
643 /* should never be called, used in qxl native mode only */
644 fprintf(stderr
, "%s: abort()\n", __func__
);
648 static void interface_set_client_capabilities(QXLInstance
*sin
,
649 uint8_t client_present
,
652 dprint(3, "%s:\n", __func__
);
655 static int interface_client_monitors_config(QXLInstance
*sin
,
656 VDAgentMonitorsConfig
*mc
)
658 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
667 * FIXME: multihead is tricky due to the way
668 * spice has multihead implemented.
670 memset(&info
, 0, sizeof(info
));
671 if (mc
->num_of_monitors
> 0) {
672 info
.width
= mc
->monitors
[0].width
;
673 info
.height
= mc
->monitors
[0].height
;
675 rc
= dpy_set_ui_info(ssd
->dcl
.con
, &info
);
676 dprint(1, "%s/%d: size %dx%d, rc %d <--- ==========================\n",
677 __func__
, ssd
->qxl
.id
, info
.width
, info
.height
, rc
);
679 return 0; /* == not supported by guest */
685 static const QXLInterface dpy_interface
= {
686 .base
.type
= SPICE_INTERFACE_QXL
,
687 .base
.description
= "qemu simple display",
688 .base
.major_version
= SPICE_INTERFACE_QXL_MAJOR
,
689 .base
.minor_version
= SPICE_INTERFACE_QXL_MINOR
,
691 .attache_worker
= interface_attach_worker
,
692 .set_compression_level
= interface_set_compression_level
,
693 .set_mm_time
= interface_set_mm_time
,
694 .get_init_info
= interface_get_init_info
,
696 /* the callbacks below are called from spice server thread context */
697 .get_command
= interface_get_command
,
698 .req_cmd_notification
= interface_req_cmd_notification
,
699 .release_resource
= interface_release_resource
,
700 .get_cursor_command
= interface_get_cursor_command
,
701 .req_cursor_notification
= interface_req_cursor_notification
,
702 .notify_update
= interface_notify_update
,
703 .flush_resources
= interface_flush_resources
,
704 .async_complete
= interface_async_complete
,
705 .update_area_complete
= interface_update_area_complete
,
706 .set_client_capabilities
= interface_set_client_capabilities
,
707 .client_monitors_config
= interface_client_monitors_config
,
710 static void display_update(DisplayChangeListener
*dcl
,
711 int x
, int y
, int w
, int h
)
713 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
714 qemu_spice_display_update(ssd
, x
, y
, w
, h
);
717 static void display_switch(DisplayChangeListener
*dcl
,
718 struct DisplaySurface
*surface
)
720 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
721 qemu_spice_display_switch(ssd
, surface
);
724 static void display_refresh(DisplayChangeListener
*dcl
)
726 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
727 qemu_spice_display_refresh(ssd
);
730 static void display_mouse_set(DisplayChangeListener
*dcl
,
731 int x
, int y
, int on
)
733 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
735 qemu_mutex_lock(&ssd
->lock
);
739 g_free(ssd
->ptr_move
);
741 ssd
->ptr_move
= qemu_spice_create_cursor_update(ssd
, NULL
);
742 qemu_mutex_unlock(&ssd
->lock
);
745 static void display_mouse_define(DisplayChangeListener
*dcl
,
748 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
750 qemu_mutex_lock(&ssd
->lock
);
752 g_free(ssd
->ptr_move
);
753 ssd
->ptr_move
= NULL
;
755 if (ssd
->ptr_define
) {
756 g_free(ssd
->ptr_define
);
758 ssd
->ptr_define
= qemu_spice_create_cursor_update(ssd
, c
);
759 qemu_mutex_unlock(&ssd
->lock
);
762 static const DisplayChangeListenerOps display_listener_ops
= {
764 .dpy_gfx_update
= display_update
,
765 .dpy_gfx_switch
= display_switch
,
766 .dpy_gfx_check_format
= qemu_pixman_check_format
,
767 .dpy_refresh
= display_refresh
,
768 .dpy_mouse_set
= display_mouse_set
,
769 .dpy_cursor_define
= display_mouse_define
,
772 static void qemu_spice_display_init_one(QemuConsole
*con
)
774 SimpleSpiceDisplay
*ssd
= g_new0(SimpleSpiceDisplay
, 1);
776 qemu_spice_display_init_common(ssd
);
778 ssd
->qxl
.base
.sif
= &dpy_interface
.base
;
779 qemu_spice_add_display_interface(&ssd
->qxl
, con
);
782 qemu_spice_create_host_memslot(ssd
);
784 ssd
->dcl
.ops
= &display_listener_ops
;
786 register_displaychangelistener(&ssd
->dcl
);
789 void qemu_spice_display_init(void)
795 con
= qemu_console_lookup_by_index(i
);
796 if (!con
|| !qemu_console_is_graphic(con
)) {
799 if (qemu_spice_have_display_interface(con
)) {
802 qemu_spice_display_init_one(con
);