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"
30 static void GCC_FMT_ATTR(2, 3) dprint(int level
, const char *fmt
, ...)
36 vfprintf(stderr
, fmt
, args
);
41 int qemu_spice_rect_is_empty(const QXLRect
* r
)
43 return r
->top
== r
->bottom
|| r
->left
== r
->right
;
46 void qemu_spice_rect_union(QXLRect
*dest
, const QXLRect
*r
)
48 if (qemu_spice_rect_is_empty(r
)) {
52 if (qemu_spice_rect_is_empty(dest
)) {
57 dest
->top
= MIN(dest
->top
, r
->top
);
58 dest
->left
= MIN(dest
->left
, r
->left
);
59 dest
->bottom
= MAX(dest
->bottom
, r
->bottom
);
60 dest
->right
= MAX(dest
->right
, r
->right
);
63 QXLCookie
*qxl_cookie_new(int type
, uint64_t io
)
67 cookie
= g_malloc0(sizeof(*cookie
));
73 void qemu_spice_add_memslot(SimpleSpiceDisplay
*ssd
, QXLDevMemSlot
*memslot
,
76 trace_qemu_spice_add_memslot(ssd
->qxl
.id
, memslot
->slot_id
,
77 memslot
->virt_start
, memslot
->virt_end
,
80 if (async
!= QXL_SYNC
) {
81 spice_qxl_add_memslot_async(&ssd
->qxl
, memslot
,
82 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO
,
83 QXL_IO_MEMSLOT_ADD_ASYNC
));
85 spice_qxl_add_memslot(&ssd
->qxl
, memslot
);
89 void qemu_spice_del_memslot(SimpleSpiceDisplay
*ssd
, uint32_t gid
, uint32_t sid
)
91 trace_qemu_spice_del_memslot(ssd
->qxl
.id
, gid
, sid
);
92 spice_qxl_del_memslot(&ssd
->qxl
, gid
, sid
);
95 void qemu_spice_create_primary_surface(SimpleSpiceDisplay
*ssd
, uint32_t id
,
96 QXLDevSurfaceCreate
*surface
,
99 trace_qemu_spice_create_primary_surface(ssd
->qxl
.id
, id
, surface
, async
);
100 if (async
!= QXL_SYNC
) {
101 spice_qxl_create_primary_surface_async(&ssd
->qxl
, id
, surface
,
102 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO
,
103 QXL_IO_CREATE_PRIMARY_ASYNC
));
105 spice_qxl_create_primary_surface(&ssd
->qxl
, id
, surface
);
109 void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay
*ssd
,
110 uint32_t id
, qxl_async_io async
)
112 trace_qemu_spice_destroy_primary_surface(ssd
->qxl
.id
, id
, async
);
113 if (async
!= QXL_SYNC
) {
114 spice_qxl_destroy_primary_surface_async(&ssd
->qxl
, id
,
115 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO
,
116 QXL_IO_DESTROY_PRIMARY_ASYNC
));
118 spice_qxl_destroy_primary_surface(&ssd
->qxl
, id
);
122 void qemu_spice_wakeup(SimpleSpiceDisplay
*ssd
)
124 trace_qemu_spice_wakeup(ssd
->qxl
.id
);
125 spice_qxl_wakeup(&ssd
->qxl
);
128 static void qemu_spice_create_one_update(SimpleSpiceDisplay
*ssd
,
131 SimpleSpiceUpdate
*update
;
132 QXLDrawable
*drawable
;
136 struct timespec time_space
;
137 pixman_image_t
*dest
;
139 trace_qemu_spice_create_update(
140 rect
->left
, rect
->right
,
141 rect
->top
, rect
->bottom
);
143 update
= g_malloc0(sizeof(*update
));
144 drawable
= &update
->drawable
;
145 image
= &update
->image
;
146 cmd
= &update
->ext
.cmd
;
148 bw
= rect
->right
- rect
->left
;
149 bh
= rect
->bottom
- rect
->top
;
150 update
->bitmap
= g_malloc(bw
* bh
* 4);
152 drawable
->bbox
= *rect
;
153 drawable
->clip
.type
= SPICE_CLIP_TYPE_NONE
;
154 drawable
->effect
= QXL_EFFECT_OPAQUE
;
155 drawable
->release_info
.id
= (uintptr_t)(&update
->ext
);
156 drawable
->type
= QXL_DRAW_COPY
;
157 drawable
->surfaces_dest
[0] = -1;
158 drawable
->surfaces_dest
[1] = -1;
159 drawable
->surfaces_dest
[2] = -1;
160 clock_gettime(CLOCK_MONOTONIC
, &time_space
);
161 /* time in milliseconds from epoch. */
162 drawable
->mm_time
= time_space
.tv_sec
* 1000
163 + time_space
.tv_nsec
/ 1000 / 1000;
165 drawable
->u
.copy
.rop_descriptor
= SPICE_ROPD_OP_PUT
;
166 drawable
->u
.copy
.src_bitmap
= (uintptr_t)image
;
167 drawable
->u
.copy
.src_area
.right
= bw
;
168 drawable
->u
.copy
.src_area
.bottom
= bh
;
170 QXL_SET_IMAGE_ID(image
, QXL_IMAGE_GROUP_DEVICE
, ssd
->unique
++);
171 image
->descriptor
.type
= SPICE_IMAGE_TYPE_BITMAP
;
172 image
->bitmap
.flags
= QXL_BITMAP_DIRECT
| QXL_BITMAP_TOP_DOWN
;
173 image
->bitmap
.stride
= bw
* 4;
174 image
->descriptor
.width
= image
->bitmap
.x
= bw
;
175 image
->descriptor
.height
= image
->bitmap
.y
= bh
;
176 image
->bitmap
.data
= (uintptr_t)(update
->bitmap
);
177 image
->bitmap
.palette
= 0;
178 image
->bitmap
.format
= SPICE_BITMAP_FMT_32BIT
;
180 dest
= pixman_image_create_bits(PIXMAN_LE_x8r8g8b8
, bw
, bh
,
181 (void *)update
->bitmap
, bw
* 4);
182 pixman_image_composite(PIXMAN_OP_SRC
, ssd
->surface
, NULL
, ssd
->mirror
,
183 rect
->left
, rect
->top
, 0, 0,
184 rect
->left
, rect
->top
, bw
, bh
);
185 pixman_image_composite(PIXMAN_OP_SRC
, ssd
->mirror
, NULL
, dest
,
186 rect
->left
, rect
->top
, 0, 0,
188 pixman_image_unref(dest
);
190 cmd
->type
= QXL_CMD_DRAW
;
191 cmd
->data
= (uintptr_t)drawable
;
193 QTAILQ_INSERT_TAIL(&ssd
->updates
, update
, next
);
196 static void qemu_spice_create_update(SimpleSpiceDisplay
*ssd
)
198 static const int blksize
= 32;
199 int blocks
= (surface_width(ssd
->ds
) + blksize
- 1) / blksize
;
200 int dirty_top
[blocks
];
201 int y
, yoff1
, yoff2
, x
, xoff
, blk
, bw
;
202 int bpp
= surface_bytes_per_pixel(ssd
->ds
);
203 uint8_t *guest
, *mirror
;
205 if (qemu_spice_rect_is_empty(&ssd
->dirty
)) {
209 for (blk
= 0; blk
< blocks
; blk
++) {
213 guest
= surface_data(ssd
->ds
);
214 mirror
= (void *)pixman_image_get_data(ssd
->mirror
);
215 for (y
= ssd
->dirty
.top
; y
< ssd
->dirty
.bottom
; y
++) {
216 yoff1
= y
* surface_stride(ssd
->ds
);
217 yoff2
= y
* pixman_image_get_stride(ssd
->mirror
);
218 for (x
= ssd
->dirty
.left
; x
< ssd
->dirty
.right
; x
+= blksize
) {
221 bw
= MIN(blksize
, ssd
->dirty
.right
- x
);
222 if (memcmp(guest
+ yoff1
+ xoff
,
223 mirror
+ yoff2
+ 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
,
266 size_t size
= c
? c
->width
* c
->height
* 4 : 0;
267 SimpleSpiceCursor
*update
;
272 update
= g_malloc0(sizeof(*update
) + size
);
274 cursor
= &update
->cursor
;
275 cmd
= &update
->ext
.cmd
;
278 ccmd
->type
= QXL_CURSOR_SET
;
279 ccmd
->u
.set
.position
.x
= ssd
->ptr_x
+ ssd
->hot_x
;
280 ccmd
->u
.set
.position
.y
= ssd
->ptr_y
+ ssd
->hot_y
;
281 ccmd
->u
.set
.visible
= true;
282 ccmd
->u
.set
.shape
= (uintptr_t)cursor
;
283 cursor
->header
.unique
= ssd
->unique
++;
284 cursor
->header
.type
= SPICE_CURSOR_TYPE_ALPHA
;
285 cursor
->header
.width
= c
->width
;
286 cursor
->header
.height
= c
->height
;
287 cursor
->header
.hot_spot_x
= c
->hot_x
;
288 cursor
->header
.hot_spot_y
= c
->hot_y
;
289 cursor
->data_size
= size
;
290 cursor
->chunk
.data_size
= size
;
291 memcpy(cursor
->chunk
.data
, c
->data
, size
);
293 ccmd
->type
= QXL_CURSOR_HIDE
;
295 ccmd
->type
= QXL_CURSOR_MOVE
;
296 ccmd
->u
.position
.x
= ssd
->ptr_x
+ ssd
->hot_x
;
297 ccmd
->u
.position
.y
= ssd
->ptr_y
+ ssd
->hot_y
;
299 ccmd
->release_info
.id
= (uintptr_t)(&update
->ext
);
301 cmd
->type
= QXL_CMD_CURSOR
;
302 cmd
->data
= (uintptr_t)ccmd
;
308 * Called from spice server thread context (via interface_release_resource)
309 * We do *not* hold the global qemu mutex here, so extra care is needed
310 * when calling qemu functions. QEMU interfaces used:
311 * - g_free (underlying glibc free is re-entrant).
313 void qemu_spice_destroy_update(SimpleSpiceDisplay
*sdpy
, SimpleSpiceUpdate
*update
)
315 g_free(update
->bitmap
);
319 void qemu_spice_create_host_memslot(SimpleSpiceDisplay
*ssd
)
321 QXLDevMemSlot memslot
;
323 dprint(1, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
325 memset(&memslot
, 0, sizeof(memslot
));
326 memslot
.slot_group_id
= MEMSLOT_GROUP_HOST
;
327 memslot
.virt_end
= ~0;
328 qemu_spice_add_memslot(ssd
, &memslot
, QXL_SYNC
);
331 void qemu_spice_create_host_primary(SimpleSpiceDisplay
*ssd
)
333 QXLDevSurfaceCreate surface
;
334 uint64_t surface_size
;
336 memset(&surface
, 0, sizeof(surface
));
338 surface_size
= (uint64_t) surface_width(ssd
->ds
) *
339 surface_height(ssd
->ds
) * 4;
340 assert(surface_size
> 0);
341 assert(surface_size
< INT_MAX
);
342 if (ssd
->bufsize
< surface_size
) {
343 ssd
->bufsize
= surface_size
;
345 ssd
->buf
= g_malloc(ssd
->bufsize
);
348 dprint(1, "%s/%d: %ux%u (size %" PRIu64
"/%d)\n", __func__
, ssd
->qxl
.id
,
349 surface_width(ssd
->ds
), surface_height(ssd
->ds
),
350 surface_size
, ssd
->bufsize
);
352 surface
.format
= SPICE_SURFACE_FMT_32_xRGB
;
353 surface
.width
= surface_width(ssd
->ds
);
354 surface
.height
= surface_height(ssd
->ds
);
355 surface
.stride
= -surface
.width
* 4;
356 surface
.mouse_mode
= true;
359 surface
.mem
= (uintptr_t)ssd
->buf
;
360 surface
.group_id
= MEMSLOT_GROUP_HOST
;
362 qemu_spice_create_primary_surface(ssd
, 0, &surface
, QXL_SYNC
);
365 void qemu_spice_destroy_host_primary(SimpleSpiceDisplay
*ssd
)
367 dprint(1, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
369 qemu_spice_destroy_primary_surface(ssd
, 0, QXL_SYNC
);
372 void qemu_spice_display_init_common(SimpleSpiceDisplay
*ssd
)
374 qemu_mutex_init(&ssd
->lock
);
375 QTAILQ_INIT(&ssd
->updates
);
378 if (ssd
->num_surfaces
== 0) {
379 ssd
->num_surfaces
= 1024;
383 /* display listener callbacks */
385 void qemu_spice_display_update(SimpleSpiceDisplay
*ssd
,
386 int x
, int y
, int w
, int h
)
390 dprint(2, "%s/%d: x %d y %d w %d h %d\n", __func__
,
391 ssd
->qxl
.id
, x
, y
, w
, h
);
392 update_area
.left
= x
,
393 update_area
.right
= x
+ w
;
395 update_area
.bottom
= y
+ h
;
397 if (qemu_spice_rect_is_empty(&ssd
->dirty
)) {
400 qemu_spice_rect_union(&ssd
->dirty
, &update_area
);
403 void qemu_spice_display_switch(SimpleSpiceDisplay
*ssd
,
404 DisplaySurface
*surface
)
406 SimpleSpiceUpdate
*update
;
409 if (surface
&& ssd
->surface
&&
410 surface_width(surface
) == pixman_image_get_width(ssd
->surface
) &&
411 surface_height(surface
) == pixman_image_get_height(ssd
->surface
)) {
412 /* no-resize fast path: just swap backing store */
413 dprint(1, "%s/%d: fast (%dx%d)\n", __func__
, ssd
->qxl
.id
,
414 surface_width(surface
), surface_height(surface
));
415 qemu_mutex_lock(&ssd
->lock
);
417 pixman_image_unref(ssd
->surface
);
418 ssd
->surface
= pixman_image_ref(ssd
->ds
->image
);
419 qemu_mutex_unlock(&ssd
->lock
);
420 qemu_spice_display_update(ssd
, 0, 0,
421 surface_width(surface
),
422 surface_height(surface
));
426 /* full mode switch */
427 dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__
, ssd
->qxl
.id
,
428 ssd
->surface
? pixman_image_get_width(ssd
->surface
) : 0,
429 ssd
->surface
? pixman_image_get_height(ssd
->surface
) : 0,
430 surface
? surface_width(surface
) : 0,
431 surface
? surface_height(surface
) : 0);
433 memset(&ssd
->dirty
, 0, sizeof(ssd
->dirty
));
435 pixman_image_unref(ssd
->surface
);
437 pixman_image_unref(ssd
->mirror
);
441 qemu_mutex_lock(&ssd
->lock
);
442 need_destroy
= (ssd
->ds
!= NULL
);
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 ssd
->surface
= pixman_image_ref(ssd
->ds
->image
);
454 ssd
->mirror
= qemu_pixman_mirror_create(ssd
->ds
->format
,
456 qemu_spice_create_host_primary(ssd
);
459 memset(&ssd
->dirty
, 0, sizeof(ssd
->dirty
));
463 static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay
*ssd
)
466 assert(ssd
->dcl
.con
);
467 dpy_cursor_define(ssd
->dcl
.con
, ssd
->cursor
);
468 cursor_put(ssd
->cursor
);
471 if (ssd
->mouse_x
!= -1 && ssd
->mouse_y
!= -1) {
472 assert(ssd
->dcl
.con
);
473 dpy_mouse_set(ssd
->dcl
.con
, ssd
->mouse_x
, ssd
->mouse_y
, 1);
479 void qemu_spice_cursor_refresh_bh(void *opaque
)
481 SimpleSpiceDisplay
*ssd
= opaque
;
483 qemu_mutex_lock(&ssd
->lock
);
484 qemu_spice_cursor_refresh_unlocked(ssd
);
485 qemu_mutex_unlock(&ssd
->lock
);
488 void qemu_spice_display_refresh(SimpleSpiceDisplay
*ssd
)
490 dprint(3, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
491 graphic_hw_update(ssd
->dcl
.con
);
493 qemu_mutex_lock(&ssd
->lock
);
494 if (QTAILQ_EMPTY(&ssd
->updates
) && ssd
->ds
) {
495 qemu_spice_create_update(ssd
);
498 qemu_mutex_unlock(&ssd
->lock
);
502 qemu_spice_wakeup(ssd
);
503 dprint(2, "%s/%d: notify\n", __func__
, ssd
->qxl
.id
);
507 /* spice display interface callbacks */
509 static void interface_attach_worker(QXLInstance
*sin
, QXLWorker
*qxl_worker
)
511 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
513 dprint(1, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
514 ssd
->worker
= qxl_worker
;
517 static void interface_set_compression_level(QXLInstance
*sin
, int level
)
519 dprint(1, "%s/%d:\n", __func__
, sin
->id
);
523 static void interface_set_mm_time(QXLInstance
*sin
, uint32_t mm_time
)
525 dprint(3, "%s/%d:\n", __func__
, sin
->id
);
529 static void interface_get_init_info(QXLInstance
*sin
, QXLDevInitInfo
*info
)
531 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
533 info
->memslot_gen_bits
= MEMSLOT_GENERATION_BITS
;
534 info
->memslot_id_bits
= MEMSLOT_SLOT_BITS
;
535 info
->num_memslots
= NUM_MEMSLOTS
;
536 info
->num_memslots_groups
= NUM_MEMSLOTS_GROUPS
;
537 info
->internal_groupslot_id
= 0;
538 info
->qxl_ram_size
= 16 * 1024 * 1024;
539 info
->n_surfaces
= ssd
->num_surfaces
;
542 static int interface_get_command(QXLInstance
*sin
, QXLCommandExt
*ext
)
544 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
545 SimpleSpiceUpdate
*update
;
548 dprint(3, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
550 qemu_mutex_lock(&ssd
->lock
);
551 update
= QTAILQ_FIRST(&ssd
->updates
);
552 if (update
!= NULL
) {
553 QTAILQ_REMOVE(&ssd
->updates
, update
, next
);
557 qemu_mutex_unlock(&ssd
->lock
);
562 static int interface_req_cmd_notification(QXLInstance
*sin
)
564 dprint(1, "%s/%d:\n", __func__
, sin
->id
);
568 static void interface_release_resource(QXLInstance
*sin
,
569 QXLReleaseInfoExt rext
)
571 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
572 SimpleSpiceUpdate
*update
;
573 SimpleSpiceCursor
*cursor
;
576 dprint(2, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
577 ext
= (void *)(intptr_t)(rext
.info
->id
);
578 switch (ext
->cmd
.type
) {
580 update
= container_of(ext
, SimpleSpiceUpdate
, ext
);
581 qemu_spice_destroy_update(ssd
, update
);
584 cursor
= container_of(ext
, SimpleSpiceCursor
, ext
);
588 g_assert_not_reached();
592 static int interface_get_cursor_command(QXLInstance
*sin
, QXLCommandExt
*ext
)
594 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
597 dprint(3, "%s/%d:\n", __func__
, ssd
->qxl
.id
);
599 qemu_mutex_lock(&ssd
->lock
);
600 if (ssd
->ptr_define
) {
601 *ext
= ssd
->ptr_define
->ext
;
602 ssd
->ptr_define
= NULL
;
604 } else if (ssd
->ptr_move
) {
605 *ext
= ssd
->ptr_move
->ext
;
606 ssd
->ptr_move
= NULL
;
611 qemu_mutex_unlock(&ssd
->lock
);
615 static int interface_req_cursor_notification(QXLInstance
*sin
)
617 dprint(1, "%s:\n", __FUNCTION__
);
621 static void interface_notify_update(QXLInstance
*sin
, uint32_t update_id
)
623 fprintf(stderr
, "%s: abort()\n", __FUNCTION__
);
627 static int interface_flush_resources(QXLInstance
*sin
)
629 fprintf(stderr
, "%s: abort()\n", __FUNCTION__
);
634 static void interface_update_area_complete(QXLInstance
*sin
,
636 QXLRect
*dirty
, uint32_t num_updated_rects
)
638 /* should never be called, used in qxl native mode only */
639 fprintf(stderr
, "%s: abort()\n", __func__
);
643 /* called from spice server thread context only */
644 static void interface_async_complete(QXLInstance
*sin
, uint64_t cookie_token
)
646 /* should never be called, used in qxl native mode only */
647 fprintf(stderr
, "%s: abort()\n", __func__
);
651 static void interface_set_client_capabilities(QXLInstance
*sin
,
652 uint8_t client_present
,
655 dprint(3, "%s:\n", __func__
);
658 static int interface_client_monitors_config(QXLInstance
*sin
,
659 VDAgentMonitorsConfig
*mc
)
661 SimpleSpiceDisplay
*ssd
= container_of(sin
, SimpleSpiceDisplay
, qxl
);
664 if (!dpy_ui_info_supported(ssd
->dcl
.con
)) {
665 return 0; /* == not supported by guest */
673 * FIXME: multihead is tricky due to the way
674 * spice has multihead implemented.
676 memset(&info
, 0, sizeof(info
));
677 if (mc
->num_of_monitors
> 0) {
678 info
.width
= mc
->monitors
[0].width
;
679 info
.height
= mc
->monitors
[0].height
;
681 dpy_set_ui_info(ssd
->dcl
.con
, &info
);
682 dprint(1, "%s/%d: size %dx%d\n", __func__
, ssd
->qxl
.id
,
683 info
.width
, info
.height
);
687 static const QXLInterface dpy_interface
= {
688 .base
.type
= SPICE_INTERFACE_QXL
,
689 .base
.description
= "qemu simple display",
690 .base
.major_version
= SPICE_INTERFACE_QXL_MAJOR
,
691 .base
.minor_version
= SPICE_INTERFACE_QXL_MINOR
,
693 .attache_worker
= interface_attach_worker
,
694 .set_compression_level
= interface_set_compression_level
,
695 .set_mm_time
= interface_set_mm_time
,
696 .get_init_info
= interface_get_init_info
,
698 /* the callbacks below are called from spice server thread context */
699 .get_command
= interface_get_command
,
700 .req_cmd_notification
= interface_req_cmd_notification
,
701 .release_resource
= interface_release_resource
,
702 .get_cursor_command
= interface_get_cursor_command
,
703 .req_cursor_notification
= interface_req_cursor_notification
,
704 .notify_update
= interface_notify_update
,
705 .flush_resources
= interface_flush_resources
,
706 .async_complete
= interface_async_complete
,
707 .update_area_complete
= interface_update_area_complete
,
708 .set_client_capabilities
= interface_set_client_capabilities
,
709 .client_monitors_config
= interface_client_monitors_config
,
712 static void display_update(DisplayChangeListener
*dcl
,
713 int x
, int y
, int w
, int h
)
715 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
716 qemu_spice_display_update(ssd
, x
, y
, w
, h
);
719 static void display_switch(DisplayChangeListener
*dcl
,
720 DisplaySurface
*surface
)
722 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
723 qemu_spice_display_switch(ssd
, surface
);
726 static void display_refresh(DisplayChangeListener
*dcl
)
728 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
729 qemu_spice_display_refresh(ssd
);
732 static void display_mouse_set(DisplayChangeListener
*dcl
,
733 int x
, int y
, int on
)
735 SimpleSpiceDisplay
*ssd
= container_of(dcl
, SimpleSpiceDisplay
, dcl
);
737 qemu_mutex_lock(&ssd
->lock
);
740 g_free(ssd
->ptr_move
);
741 ssd
->ptr_move
= qemu_spice_create_cursor_update(ssd
, NULL
, on
);
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
);
751 ssd
->hot_x
= c
->hot_x
;
752 ssd
->hot_y
= c
->hot_y
;
753 g_free(ssd
->ptr_move
);
754 ssd
->ptr_move
= NULL
;
755 g_free(ssd
->ptr_define
);
756 ssd
->ptr_define
= qemu_spice_create_cursor_update(ssd
, c
, 0);
757 qemu_mutex_unlock(&ssd
->lock
);
760 static const DisplayChangeListenerOps display_listener_ops
= {
762 .dpy_gfx_update
= display_update
,
763 .dpy_gfx_switch
= display_switch
,
764 .dpy_gfx_check_format
= qemu_pixman_check_format
,
765 .dpy_refresh
= display_refresh
,
766 .dpy_mouse_set
= display_mouse_set
,
767 .dpy_cursor_define
= display_mouse_define
,
770 static void qemu_spice_display_init_one(QemuConsole
*con
)
772 SimpleSpiceDisplay
*ssd
= g_new0(SimpleSpiceDisplay
, 1);
774 qemu_spice_display_init_common(ssd
);
776 ssd
->qxl
.base
.sif
= &dpy_interface
.base
;
777 qemu_spice_add_display_interface(&ssd
->qxl
, con
);
780 qemu_spice_create_host_memslot(ssd
);
782 ssd
->dcl
.ops
= &display_listener_ops
;
784 register_displaychangelistener(&ssd
->dcl
);
787 void qemu_spice_display_init(void)
793 con
= qemu_console_lookup_by_index(i
);
794 if (!con
|| !qemu_console_is_graphic(con
)) {
797 if (qemu_spice_have_display_interface(con
)) {
800 qemu_spice_display_init_one(con
);