blob: 4e6356a96704d5a30e529d1ab27ae3daaa65f682 [file] [log] [blame]
Gerd Hoffmanna3e22262010-08-25 15:32:06 +02001/*
2 * Copyright (C) 2010 Red Hat, Inc.
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
Gerd Hoffmanna3e22262010-08-25 15:32:06 +020018#include "qemu-common.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010019#include "ui/qemu-spice.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010020#include "qemu/timer.h"
21#include "qemu/queue.h"
Paolo Bonzini83c90892012-12-17 18:19:49 +010022#include "monitor/monitor.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010023#include "ui/console.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010024#include "sysemu/sysemu.h"
Alon Levyc480bb72012-03-18 13:46:14 +010025#include "trace.h"
Gerd Hoffmanna3e22262010-08-25 15:32:06 +020026
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010027#include "ui/spice-display.h"
Gerd Hoffmanna3e22262010-08-25 15:32:06 +020028
29static int debug = 0;
30
Stefan Weil2c80e422010-10-13 20:54:27 +020031static void GCC_FMT_ATTR(2, 3) dprint(int level, const char *fmt, ...)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +020032{
33 va_list args;
34
35 if (level <= debug) {
36 va_start(args, fmt);
37 vfprintf(stderr, fmt, args);
38 va_end(args);
39 }
40}
41
42int qemu_spice_rect_is_empty(const QXLRect* r)
43{
44 return r->top == r->bottom || r->left == r->right;
45}
46
47void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r)
48{
49 if (qemu_spice_rect_is_empty(r)) {
50 return;
51 }
52
53 if (qemu_spice_rect_is_empty(dest)) {
54 *dest = *r;
55 return;
56 }
57
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);
62}
63
Alon Levy2e1a98c2012-02-24 23:19:30 +020064QXLCookie *qxl_cookie_new(int type, uint64_t io)
65{
66 QXLCookie *cookie;
67
68 cookie = g_malloc0(sizeof(*cookie));
69 cookie->type = type;
70 cookie->io = io;
71 return cookie;
72}
73
Alon Levy5ff4e362011-07-20 12:20:58 +030074void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
75 qxl_async_io async)
Gerd Hoffmann5c59d112011-07-20 12:20:50 +030076{
Alon Levyc480bb72012-03-18 13:46:14 +010077 trace_qemu_spice_add_memslot(ssd->qxl.id, memslot->slot_id,
78 memslot->virt_start, memslot->virt_end,
79 async);
80
Alon Levy5ff4e362011-07-20 12:20:58 +030081 if (async != QXL_SYNC) {
Alon Levy2e1a98c2012-02-24 23:19:30 +020082 spice_qxl_add_memslot_async(&ssd->qxl, memslot,
Peter Maydell34d14c62012-03-07 13:36:48 +000083 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
84 QXL_IO_MEMSLOT_ADD_ASYNC));
Alon Levy5ff4e362011-07-20 12:20:58 +030085 } else {
Marc-André Lureau26defe82013-10-04 13:10:46 +020086 spice_qxl_add_memslot(&ssd->qxl, memslot);
Alon Levy5ff4e362011-07-20 12:20:58 +030087 }
Gerd Hoffmann5c59d112011-07-20 12:20:50 +030088}
89
90void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, uint32_t sid)
91{
Alon Levyc480bb72012-03-18 13:46:14 +010092 trace_qemu_spice_del_memslot(ssd->qxl.id, gid, sid);
Marc-André Lureau26defe82013-10-04 13:10:46 +020093 spice_qxl_del_memslot(&ssd->qxl, gid, sid);
Gerd Hoffmann5c59d112011-07-20 12:20:50 +030094}
95
96void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
Alon Levy5ff4e362011-07-20 12:20:58 +030097 QXLDevSurfaceCreate *surface,
98 qxl_async_io async)
Gerd Hoffmann5c59d112011-07-20 12:20:50 +030099{
Alon Levyc480bb72012-03-18 13:46:14 +0100100 trace_qemu_spice_create_primary_surface(ssd->qxl.id, id, surface, async);
Alon Levy5ff4e362011-07-20 12:20:58 +0300101 if (async != QXL_SYNC) {
Alon Levy2e1a98c2012-02-24 23:19:30 +0200102 spice_qxl_create_primary_surface_async(&ssd->qxl, id, surface,
Peter Maydell34d14c62012-03-07 13:36:48 +0000103 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
104 QXL_IO_CREATE_PRIMARY_ASYNC));
Alon Levy5ff4e362011-07-20 12:20:58 +0300105 } else {
Marc-André Lureau26defe82013-10-04 13:10:46 +0200106 spice_qxl_create_primary_surface(&ssd->qxl, id, surface);
Alon Levy5ff4e362011-07-20 12:20:58 +0300107 }
Gerd Hoffmann5c59d112011-07-20 12:20:50 +0300108}
109
Alon Levy5ff4e362011-07-20 12:20:58 +0300110void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
111 uint32_t id, qxl_async_io async)
Gerd Hoffmann5c59d112011-07-20 12:20:50 +0300112{
Alon Levyc480bb72012-03-18 13:46:14 +0100113 trace_qemu_spice_destroy_primary_surface(ssd->qxl.id, id, async);
Alon Levy5ff4e362011-07-20 12:20:58 +0300114 if (async != QXL_SYNC) {
Alon Levy2e1a98c2012-02-24 23:19:30 +0200115 spice_qxl_destroy_primary_surface_async(&ssd->qxl, id,
Peter Maydell34d14c62012-03-07 13:36:48 +0000116 (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
117 QXL_IO_DESTROY_PRIMARY_ASYNC));
Alon Levy5ff4e362011-07-20 12:20:58 +0300118 } else {
Marc-André Lureau26defe82013-10-04 13:10:46 +0200119 spice_qxl_destroy_primary_surface(&ssd->qxl, id);
Alon Levy5ff4e362011-07-20 12:20:58 +0300120 }
Gerd Hoffmann5c59d112011-07-20 12:20:50 +0300121}
122
Gerd Hoffmann5c59d112011-07-20 12:20:50 +0300123void qemu_spice_wakeup(SimpleSpiceDisplay *ssd)
124{
Alon Levyc480bb72012-03-18 13:46:14 +0100125 trace_qemu_spice_wakeup(ssd->qxl.id);
Marc-André Lureau26defe82013-10-04 13:10:46 +0200126 spice_qxl_wakeup(&ssd->qxl);
Gerd Hoffmann5c59d112011-07-20 12:20:50 +0300127}
128
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200129static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
130 QXLRect *rect)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200131{
132 SimpleSpiceUpdate *update;
133 QXLDrawable *drawable;
134 QXLImage *image;
135 QXLCommand *cmd;
Gerd Hoffmannd9a86562012-11-02 09:12:49 +0100136 int bw, bh;
Alon Levy22795172011-06-15 20:44:38 +0200137 struct timespec time_space;
Gerd Hoffmannd9a86562012-11-02 09:12:49 +0100138 pixman_image_t *dest;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200139
Alon Levyc480bb72012-03-18 13:46:14 +0100140 trace_qemu_spice_create_update(
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200141 rect->left, rect->right,
142 rect->top, rect->bottom);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200143
Anthony Liguori7267c092011-08-20 22:09:37 -0500144 update = g_malloc0(sizeof(*update));
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200145 drawable = &update->drawable;
146 image = &update->image;
147 cmd = &update->ext.cmd;
148
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200149 bw = rect->right - rect->left;
150 bh = rect->bottom - rect->top;
Anthony Liguori7267c092011-08-20 22:09:37 -0500151 update->bitmap = g_malloc(bw * bh * 4);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200152
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200153 drawable->bbox = *rect;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200154 drawable->clip.type = SPICE_CLIP_TYPE_NONE;
155 drawable->effect = QXL_EFFECT_OPAQUE;
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200156 drawable->release_info.id = (uintptr_t)(&update->ext);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200157 drawable->type = QXL_DRAW_COPY;
158 drawable->surfaces_dest[0] = -1;
159 drawable->surfaces_dest[1] = -1;
160 drawable->surfaces_dest[2] = -1;
Alon Levy22795172011-06-15 20:44:38 +0200161 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;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200165
166 drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
Alon Levya13ccc92012-03-21 18:17:18 +0200167 drawable->u.copy.src_bitmap = (uintptr_t)image;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200168 drawable->u.copy.src_area.right = bw;
169 drawable->u.copy.src_area.bottom = bh;
170
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;
Alon Levya13ccc92012-03-21 18:17:18 +0200177 image->bitmap.data = (uintptr_t)(update->bitmap);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200178 image->bitmap.palette = 0;
179 image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
180
Gerd Hoffmannc1d37cd2015-04-14 08:56:21 +0200181 dest = pixman_image_create_bits(PIXMAN_LE_x8r8g8b8, bw, bh,
Gerd Hoffmannd9a86562012-11-02 09:12:49 +0100182 (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,
188 0, 0, bw, bh);
189 pixman_image_unref(dest);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200190
191 cmd->type = QXL_CMD_DRAW;
Alon Levya13ccc92012-03-21 18:17:18 +0200192 cmd->data = (uintptr_t)drawable;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200193
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200194 QTAILQ_INSERT_TAIL(&ssd->updates, update, next);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200195}
196
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200197static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
198{
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200199 static const int blksize = 32;
Gerd Hoffmann71874c12013-02-28 16:42:28 +0100200 int blocks = (surface_width(ssd->ds) + blksize - 1) / blksize;
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200201 int dirty_top[blocks];
Gerd Hoffmannc6e48472015-06-09 21:08:47 +0200202 int y, yoff1, yoff2, x, xoff, blk, bw;
Gerd Hoffmann71874c12013-02-28 16:42:28 +0100203 int bpp = surface_bytes_per_pixel(ssd->ds);
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200204 uint8_t *guest, *mirror;
205
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200206 if (qemu_spice_rect_is_empty(&ssd->dirty)) {
207 return;
208 };
Gerd Hoffmanna7310dd2012-09-05 09:35:57 +0200209
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200210 for (blk = 0; blk < blocks; blk++) {
211 dirty_top[blk] = -1;
212 }
213
Gerd Hoffmann71874c12013-02-28 16:42:28 +0100214 guest = surface_data(ssd->ds);
Gerd Hoffmannd9a86562012-11-02 09:12:49 +0100215 mirror = (void *)pixman_image_get_data(ssd->mirror);
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200216 for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) {
Gerd Hoffmannc6e48472015-06-09 21:08:47 +0200217 yoff1 = y * surface_stride(ssd->ds);
218 yoff2 = y * pixman_image_get_stride(ssd->mirror);
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200219 for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
220 xoff = x * bpp;
221 blk = x / blksize;
222 bw = MIN(blksize, ssd->dirty.right - x);
Gerd Hoffmannc6e48472015-06-09 21:08:47 +0200223 if (memcmp(guest + yoff1 + xoff,
224 mirror + yoff2 + xoff,
Gerd Hoffmannb021bd22012-09-05 10:41:42 +0200225 bw * bpp) == 0) {
226 if (dirty_top[blk] != -1) {
227 QXLRect update = {
228 .top = dirty_top[blk],
229 .bottom = y,
230 .left = x,
231 .right = x + bw,
232 };
233 qemu_spice_create_one_update(ssd, &update);
234 dirty_top[blk] = -1;
235 }
236 } else {
237 if (dirty_top[blk] == -1) {
238 dirty_top[blk] = y;
239 }
240 }
241 }
242 }
243
244 for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
245 blk = x / blksize;
246 bw = MIN(blksize, ssd->dirty.right - x);
247 if (dirty_top[blk] != -1) {
248 QXLRect update = {
249 .top = dirty_top[blk],
250 .bottom = ssd->dirty.bottom,
251 .left = x,
252 .right = x + bw,
253 };
254 qemu_spice_create_one_update(ssd, &update);
255 dirty_top[blk] = -1;
256 }
257 }
258
Gerd Hoffmannc60319a2012-09-05 08:52:23 +0200259 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
260}
261
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200262static SimpleSpiceCursor*
263qemu_spice_create_cursor_update(SimpleSpiceDisplay *ssd,
Marc-André Lureau700cd852015-03-24 17:50:13 +0100264 QEMUCursor *c,
265 int on)
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200266{
267 size_t size = c ? c->width * c->height * 4 : 0;
268 SimpleSpiceCursor *update;
269 QXLCursorCmd *ccmd;
270 QXLCursor *cursor;
271 QXLCommand *cmd;
272
273 update = g_malloc0(sizeof(*update) + size);
274 ccmd = &update->cmd;
275 cursor = &update->cursor;
276 cmd = &update->ext.cmd;
277
278 if (c) {
279 ccmd->type = QXL_CURSOR_SET;
Marc-André Lureaudc8dcee2015-03-24 17:50:12 +0100280 ccmd->u.set.position.x = ssd->ptr_x + ssd->hot_x;
281 ccmd->u.set.position.y = ssd->ptr_y + ssd->hot_y;
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200282 ccmd->u.set.visible = true;
283 ccmd->u.set.shape = (uintptr_t)cursor;
284 cursor->header.unique = ssd->unique++;
285 cursor->header.type = SPICE_CURSOR_TYPE_ALPHA;
286 cursor->header.width = c->width;
287 cursor->header.height = c->height;
288 cursor->header.hot_spot_x = c->hot_x;
289 cursor->header.hot_spot_y = c->hot_y;
290 cursor->data_size = size;
291 cursor->chunk.data_size = size;
292 memcpy(cursor->chunk.data, c->data, size);
Marc-André Lureau700cd852015-03-24 17:50:13 +0100293 } else if (!on) {
294 ccmd->type = QXL_CURSOR_HIDE;
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200295 } else {
296 ccmd->type = QXL_CURSOR_MOVE;
Marc-André Lureaudc8dcee2015-03-24 17:50:12 +0100297 ccmd->u.position.x = ssd->ptr_x + ssd->hot_x;
298 ccmd->u.position.y = ssd->ptr_y + ssd->hot_y;
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200299 }
300 ccmd->release_info.id = (uintptr_t)(&update->ext);
301
302 cmd->type = QXL_CMD_CURSOR;
303 cmd->data = (uintptr_t)ccmd;
304
305 return update;
306}
307
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200308/*
Stefan Weil4580c492012-08-17 15:20:00 +0200309 * Called from spice server thread context (via interface_release_resource)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200310 * We do *not* hold the global qemu mutex here, so extra care is needed
Stefan Weil5cbdb3a2012-04-07 09:23:39 +0200311 * when calling qemu functions. QEMU interfaces used:
Anthony Liguori7267c092011-08-20 22:09:37 -0500312 * - g_free (underlying glibc free is re-entrant).
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200313 */
314void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update)
315{
Anthony Liguori7267c092011-08-20 22:09:37 -0500316 g_free(update->bitmap);
317 g_free(update);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200318}
319
320void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd)
321{
322 QXLDevMemSlot memslot;
323
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200324 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200325
326 memset(&memslot, 0, sizeof(memslot));
327 memslot.slot_group_id = MEMSLOT_GROUP_HOST;
328 memslot.virt_end = ~0;
Alon Levy5ff4e362011-07-20 12:20:58 +0300329 qemu_spice_add_memslot(ssd, &memslot, QXL_SYNC);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200330}
331
332void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd)
333{
334 QXLDevSurfaceCreate surface;
Gerd Hoffmannab9509c2014-09-03 15:50:08 +0200335 uint64_t surface_size;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200336
Alon Levy160c31f2012-05-24 12:38:11 +0300337 memset(&surface, 0, sizeof(surface));
338
Gerd Hoffmannab9509c2014-09-03 15:50:08 +0200339 surface_size = (uint64_t) surface_width(ssd->ds) *
340 surface_height(ssd->ds) * 4;
341 assert(surface_size > 0);
342 assert(surface_size < INT_MAX);
343 if (ssd->bufsize < surface_size) {
344 ssd->bufsize = surface_size;
345 g_free(ssd->buf);
346 ssd->buf = g_malloc(ssd->bufsize);
347 }
348
349 dprint(1, "%s/%d: %ux%u (size %" PRIu64 "/%d)\n", __func__, ssd->qxl.id,
350 surface_width(ssd->ds), surface_height(ssd->ds),
351 surface_size, ssd->bufsize);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200352
353 surface.format = SPICE_SURFACE_FMT_32_xRGB;
Gerd Hoffmann71874c12013-02-28 16:42:28 +0100354 surface.width = surface_width(ssd->ds);
355 surface.height = surface_height(ssd->ds);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200356 surface.stride = -surface.width * 4;
Gerd Hoffmann869564a2010-04-13 09:05:03 +0200357 surface.mouse_mode = true;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200358 surface.flags = 0;
359 surface.type = 0;
Alon Levya13ccc92012-03-21 18:17:18 +0200360 surface.mem = (uintptr_t)ssd->buf;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200361 surface.group_id = MEMSLOT_GROUP_HOST;
Gerd Hoffmann7466bc42010-10-14 16:55:01 +0200362
Alon Levy5ff4e362011-07-20 12:20:58 +0300363 qemu_spice_create_primary_surface(ssd, 0, &surface, QXL_SYNC);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200364}
365
366void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd)
367{
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200368 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200369
Alon Levy5ff4e362011-07-20 12:20:58 +0300370 qemu_spice_destroy_primary_surface(ssd, 0, QXL_SYNC);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200371}
372
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100373void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd)
Gerd Hoffmanna963f872011-07-20 12:20:51 +0300374{
Gerd Hoffmanna963f872011-07-20 12:20:51 +0300375 qemu_mutex_init(&ssd->lock);
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200376 QTAILQ_INIT(&ssd->updates);
Gerd Hoffmanna963f872011-07-20 12:20:51 +0300377 ssd->mouse_x = -1;
378 ssd->mouse_y = -1;
Gerd Hoffmannddd8fdc2012-09-04 11:39:41 +0200379 if (ssd->num_surfaces == 0) {
380 ssd->num_surfaces = 1024;
381 }
Gerd Hoffmanna963f872011-07-20 12:20:51 +0300382}
383
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200384/* display listener callbacks */
385
386void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
387 int x, int y, int w, int h)
388{
389 QXLRect update_area;
390
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200391 dprint(2, "%s/%d: x %d y %d w %d h %d\n", __func__,
392 ssd->qxl.id, x, y, w, h);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200393 update_area.left = x,
394 update_area.right = x + w;
395 update_area.top = y;
396 update_area.bottom = y + h;
397
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200398 if (qemu_spice_rect_is_empty(&ssd->dirty)) {
399 ssd->notify++;
400 }
401 qemu_spice_rect_union(&ssd->dirty, &update_area);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200402}
403
Gerd Hoffmannc12aeb82013-02-28 15:03:04 +0100404void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
405 DisplaySurface *surface)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200406{
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200407 SimpleSpiceUpdate *update;
Gerd Hoffmann4b87dc42014-01-24 10:48:58 +0100408 bool need_destroy;
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200409
Gerd Hoffmann555e72f2014-11-08 08:56:34 +0100410 if (surface && ssd->surface &&
411 surface_width(surface) == pixman_image_get_width(ssd->surface) &&
412 surface_height(surface) == pixman_image_get_height(ssd->surface)) {
413 /* no-resize fast path: just swap backing store */
414 dprint(1, "%s/%d: fast (%dx%d)\n", __func__, ssd->qxl.id,
415 surface_width(surface), surface_height(surface));
416 qemu_mutex_lock(&ssd->lock);
417 ssd->ds = surface;
418 pixman_image_unref(ssd->surface);
419 ssd->surface = pixman_image_ref(ssd->ds->image);
420 qemu_mutex_unlock(&ssd->lock);
421 qemu_spice_display_update(ssd, 0, 0,
422 surface_width(surface),
423 surface_height(surface));
424 return;
425 }
426
427 /* full mode switch */
428 dprint(1, "%s/%d: full (%dx%d -> %dx%d)\n", __func__, ssd->qxl.id,
429 ssd->surface ? pixman_image_get_width(ssd->surface) : 0,
430 ssd->surface ? pixman_image_get_height(ssd->surface) : 0,
431 surface ? surface_width(surface) : 0,
432 surface ? surface_height(surface) : 0);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200433
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200434 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
Gerd Hoffmannd9a86562012-11-02 09:12:49 +0100435 if (ssd->surface) {
436 pixman_image_unref(ssd->surface);
437 ssd->surface = NULL;
438 pixman_image_unref(ssd->mirror);
439 ssd->mirror = NULL;
440 }
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200441
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200442 qemu_mutex_lock(&ssd->lock);
Gerd Hoffmann4b87dc42014-01-24 10:48:58 +0100443 need_destroy = (ssd->ds != NULL);
Gerd Hoffmann71874c12013-02-28 16:42:28 +0100444 ssd->ds = surface;
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200445 while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {
446 QTAILQ_REMOVE(&ssd->updates, update, next);
447 qemu_spice_destroy_update(ssd, update);
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200448 }
449 qemu_mutex_unlock(&ssd->lock);
Gerd Hoffmann4b87dc42014-01-24 10:48:58 +0100450 if (need_destroy) {
451 qemu_spice_destroy_host_primary(ssd);
452 }
453 if (ssd->ds) {
Gerd Hoffmann51a09092015-01-15 12:06:16 +0100454 ssd->surface = pixman_image_ref(ssd->ds->image);
455 ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format,
456 ssd->ds->image);
Gerd Hoffmann4b87dc42014-01-24 10:48:58 +0100457 qemu_spice_create_host_primary(ssd);
458 }
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200459
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200460 memset(&ssd->dirty, 0, sizeof(ssd->dirty));
461 ssd->notify++;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200462}
463
Gerd Hoffmann0b2824e2014-11-04 13:59:59 +0100464static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200465{
Gerd Hoffmann07536092011-04-27 15:50:32 +0200466 if (ssd->cursor) {
Gerd Hoffmann284d1c62013-03-15 15:45:54 +0100467 assert(ssd->dcl.con);
468 dpy_cursor_define(ssd->dcl.con, ssd->cursor);
Gerd Hoffmann07536092011-04-27 15:50:32 +0200469 cursor_put(ssd->cursor);
470 ssd->cursor = NULL;
471 }
472 if (ssd->mouse_x != -1 && ssd->mouse_y != -1) {
Gerd Hoffmann284d1c62013-03-15 15:45:54 +0100473 assert(ssd->dcl.con);
474 dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1);
Gerd Hoffmann07536092011-04-27 15:50:32 +0200475 ssd->mouse_x = -1;
476 ssd->mouse_y = -1;
477 }
Alon Levybb5a8cd2012-02-24 23:19:25 +0200478}
479
Gerd Hoffmann0b2824e2014-11-04 13:59:59 +0100480void qemu_spice_cursor_refresh_bh(void *opaque)
481{
482 SimpleSpiceDisplay *ssd = opaque;
483
484 qemu_mutex_lock(&ssd->lock);
485 qemu_spice_cursor_refresh_unlocked(ssd);
486 qemu_mutex_unlock(&ssd->lock);
487}
488
Alon Levybb5a8cd2012-02-24 23:19:25 +0200489void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
490{
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200491 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
Gerd Hoffmann284d1c62013-03-15 15:45:54 +0100492 graphic_hw_update(ssd->dcl.con);
Alon Levybb5a8cd2012-02-24 23:19:25 +0200493
494 qemu_mutex_lock(&ssd->lock);
Gerd Hoffmann71874c12013-02-28 16:42:28 +0100495 if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) {
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200496 qemu_spice_create_update(ssd);
Alon Levybb5a8cd2012-02-24 23:19:25 +0200497 ssd->notify++;
498 }
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200499 qemu_mutex_unlock(&ssd->lock);
500
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200501 if (ssd->notify) {
502 ssd->notify = 0;
Gerd Hoffmann5c59d112011-07-20 12:20:50 +0300503 qemu_spice_wakeup(ssd);
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200504 dprint(2, "%s/%d: notify\n", __func__, ssd->qxl.id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200505 }
506}
507
508/* spice display interface callbacks */
509
510static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
511{
512 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
513
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200514 dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200515 ssd->worker = qxl_worker;
516}
517
518static void interface_set_compression_level(QXLInstance *sin, int level)
519{
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200520 dprint(1, "%s/%d:\n", __func__, sin->id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200521 /* nothing to do */
522}
523
524static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time)
525{
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200526 dprint(3, "%s/%d:\n", __func__, sin->id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200527 /* nothing to do */
528}
529
530static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info)
531{
532 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
533
534 info->memslot_gen_bits = MEMSLOT_GENERATION_BITS;
535 info->memslot_id_bits = MEMSLOT_SLOT_BITS;
536 info->num_memslots = NUM_MEMSLOTS;
537 info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
538 info->internal_groupslot_id = 0;
Gerd Hoffmannab9509c2014-09-03 15:50:08 +0200539 info->qxl_ram_size = 16 * 1024 * 1024;
Gerd Hoffmannddd8fdc2012-09-04 11:39:41 +0200540 info->n_surfaces = ssd->num_surfaces;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200541}
542
Chih-Min Chaoc9f88ce2015-04-09 02:04:14 +0800543static int interface_get_command(QXLInstance *sin, QXLCommandExt *ext)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200544{
545 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
546 SimpleSpiceUpdate *update;
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200547 int ret = false;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200548
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200549 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200550
551 qemu_mutex_lock(&ssd->lock);
Gerd Hoffmannb1af98b2012-09-05 08:25:08 +0200552 update = QTAILQ_FIRST(&ssd->updates);
553 if (update != NULL) {
554 QTAILQ_REMOVE(&ssd->updates, update, next);
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200555 *ext = update->ext;
556 ret = true;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200557 }
Gerd Hoffmanne0c64d02011-04-27 15:21:51 +0200558 qemu_mutex_unlock(&ssd->lock);
559
560 return ret;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200561}
562
563static int interface_req_cmd_notification(QXLInstance *sin)
564{
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200565 dprint(1, "%s/%d:\n", __func__, sin->id);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200566 return 1;
567}
568
569static void interface_release_resource(QXLInstance *sin,
Chih-Min Chaoc9f88ce2015-04-09 02:04:14 +0800570 QXLReleaseInfoExt rext)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200571{
572 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200573 SimpleSpiceUpdate *update;
574 SimpleSpiceCursor *cursor;
575 QXLCommandExt *ext;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200576
Gerd Hoffmann35b21222013-10-17 12:11:43 +0200577 dprint(2, "%s/%d:\n", __func__, ssd->qxl.id);
Gerd Hoffmanne8e23b72014-06-20 08:12:44 +0200578 ext = (void *)(intptr_t)(rext.info->id);
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200579 switch (ext->cmd.type) {
580 case QXL_CMD_DRAW:
581 update = container_of(ext, SimpleSpiceUpdate, ext);
582 qemu_spice_destroy_update(ssd, update);
583 break;
584 case QXL_CMD_CURSOR:
585 cursor = container_of(ext, SimpleSpiceCursor, ext);
586 g_free(cursor);
587 break;
588 default:
589 g_assert_not_reached();
590 }
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200591}
592
Chih-Min Chaoc9f88ce2015-04-09 02:04:14 +0800593static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200594{
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200595 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
596 int ret;
597
598 dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
599
600 qemu_mutex_lock(&ssd->lock);
601 if (ssd->ptr_define) {
602 *ext = ssd->ptr_define->ext;
603 ssd->ptr_define = NULL;
604 ret = true;
605 } else if (ssd->ptr_move) {
606 *ext = ssd->ptr_move->ext;
607 ssd->ptr_move = NULL;
608 ret = true;
609 } else {
610 ret = false;
611 }
612 qemu_mutex_unlock(&ssd->lock);
613 return ret;
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200614}
615
616static int interface_req_cursor_notification(QXLInstance *sin)
617{
618 dprint(1, "%s:\n", __FUNCTION__);
619 return 1;
620}
621
622static void interface_notify_update(QXLInstance *sin, uint32_t update_id)
623{
624 fprintf(stderr, "%s: abort()\n", __FUNCTION__);
625 abort();
626}
627
628static int interface_flush_resources(QXLInstance *sin)
629{
630 fprintf(stderr, "%s: abort()\n", __FUNCTION__);
631 abort();
632 return 0;
633}
634
Gerd Hoffmann21a50d02012-11-21 14:41:48 +0100635static void interface_update_area_complete(QXLInstance *sin,
636 uint32_t surface_id,
637 QXLRect *dirty, uint32_t num_updated_rects)
638{
639 /* should never be called, used in qxl native mode only */
640 fprintf(stderr, "%s: abort()\n", __func__);
641 abort();
642}
643
644/* called from spice server thread context only */
645static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
646{
647 /* should never be called, used in qxl native mode only */
648 fprintf(stderr, "%s: abort()\n", __func__);
649 abort();
650}
651
652static void interface_set_client_capabilities(QXLInstance *sin,
653 uint8_t client_present,
654 uint8_t caps[58])
655{
656 dprint(3, "%s:\n", __func__);
657}
658
659static int interface_client_monitors_config(QXLInstance *sin,
Gerd Hoffmann9b74d0d2014-01-24 18:47:20 +0100660 VDAgentMonitorsConfig *mc)
Gerd Hoffmann21a50d02012-11-21 14:41:48 +0100661{
Gerd Hoffmann9b74d0d2014-01-24 18:47:20 +0100662 SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
663 QemuUIInfo info;
664 int rc;
665
Gerd Hoffmanndc491cf2014-04-07 12:15:44 +0200666 if (!mc) {
667 return 1;
668 }
669
Gerd Hoffmann9b74d0d2014-01-24 18:47:20 +0100670 /*
671 * FIXME: multihead is tricky due to the way
672 * spice has multihead implemented.
673 */
674 memset(&info, 0, sizeof(info));
675 if (mc->num_of_monitors > 0) {
676 info.width = mc->monitors[0].width;
677 info.height = mc->monitors[0].height;
678 }
679 rc = dpy_set_ui_info(ssd->dcl.con, &info);
680 dprint(1, "%s/%d: size %dx%d, rc %d <--- ==========================\n",
681 __func__, ssd->qxl.id, info.width, info.height, rc);
682 if (rc != 0) {
683 return 0; /* == not supported by guest */
684 } else {
685 return 1;
686 }
Gerd Hoffmann21a50d02012-11-21 14:41:48 +0100687}
688
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200689static const QXLInterface dpy_interface = {
690 .base.type = SPICE_INTERFACE_QXL,
691 .base.description = "qemu simple display",
692 .base.major_version = SPICE_INTERFACE_QXL_MAJOR,
693 .base.minor_version = SPICE_INTERFACE_QXL_MINOR,
694
695 .attache_worker = interface_attach_worker,
696 .set_compression_level = interface_set_compression_level,
697 .set_mm_time = interface_set_mm_time,
698 .get_init_info = interface_get_init_info,
699
700 /* the callbacks below are called from spice server thread context */
701 .get_command = interface_get_command,
702 .req_cmd_notification = interface_req_cmd_notification,
703 .release_resource = interface_release_resource,
704 .get_cursor_command = interface_get_cursor_command,
705 .req_cursor_notification = interface_req_cursor_notification,
706 .notify_update = interface_notify_update,
707 .flush_resources = interface_flush_resources,
Gerd Hoffmann21a50d02012-11-21 14:41:48 +0100708 .async_complete = interface_async_complete,
709 .update_area_complete = interface_update_area_complete,
710 .set_client_capabilities = interface_set_client_capabilities,
711 .client_monitors_config = interface_client_monitors_config,
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200712};
713
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100714static void display_update(DisplayChangeListener *dcl,
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100715 int x, int y, int w, int h)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200716{
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100717 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
718 qemu_spice_display_update(ssd, x, y, w, h);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200719}
720
Gerd Hoffmannc12aeb82013-02-28 15:03:04 +0100721static void display_switch(DisplayChangeListener *dcl,
Chih-Min Chao9425c002015-04-09 02:04:13 +0800722 DisplaySurface *surface)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200723{
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100724 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
Gerd Hoffmannc12aeb82013-02-28 15:03:04 +0100725 qemu_spice_display_switch(ssd, surface);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200726}
727
Gerd Hoffmannbc2ed972013-03-01 13:03:04 +0100728static void display_refresh(DisplayChangeListener *dcl)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200729{
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100730 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
731 qemu_spice_display_refresh(ssd);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200732}
733
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200734static void display_mouse_set(DisplayChangeListener *dcl,
735 int x, int y, int on)
736{
737 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
738
739 qemu_mutex_lock(&ssd->lock);
740 ssd->ptr_x = x;
Marc-André Lureaud0df04a2015-03-24 17:50:11 +0100741 ssd->ptr_y = y;
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200742 if (ssd->ptr_move) {
743 g_free(ssd->ptr_move);
744 }
Marc-André Lureau700cd852015-03-24 17:50:13 +0100745 ssd->ptr_move = qemu_spice_create_cursor_update(ssd, NULL, on);
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200746 qemu_mutex_unlock(&ssd->lock);
747}
748
749static void display_mouse_define(DisplayChangeListener *dcl,
750 QEMUCursor *c)
751{
752 SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
753
754 qemu_mutex_lock(&ssd->lock);
Marc-André Lureaudc8dcee2015-03-24 17:50:12 +0100755 ssd->hot_x = c->hot_x;
756 ssd->hot_y = c->hot_y;
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200757 if (ssd->ptr_move) {
758 g_free(ssd->ptr_move);
759 ssd->ptr_move = NULL;
760 }
761 if (ssd->ptr_define) {
762 g_free(ssd->ptr_define);
763 }
Marc-André Lureau700cd852015-03-24 17:50:13 +0100764 ssd->ptr_define = qemu_spice_create_cursor_update(ssd, c, 0);
Gerd Hoffmann5643fc02014-06-07 13:03:10 +0200765 qemu_mutex_unlock(&ssd->lock);
766}
767
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100768static const DisplayChangeListenerOps display_listener_ops = {
Gerd Hoffmann0002a512015-01-09 09:31:58 +0100769 .dpy_name = "spice",
770 .dpy_gfx_update = display_update,
771 .dpy_gfx_switch = display_switch,
772 .dpy_gfx_check_format = qemu_pixman_check_format,
773 .dpy_refresh = display_refresh,
774 .dpy_mouse_set = display_mouse_set,
775 .dpy_cursor_define = display_mouse_define,
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200776};
777
Gerd Hoffmann9fa03282013-10-11 22:39:59 +0200778static void qemu_spice_display_init_one(QemuConsole *con)
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200779{
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100780 SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200781
Gerd Hoffmannc78f7132013-03-05 15:24:14 +0100782 qemu_spice_display_init_common(ssd);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200783
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100784 ssd->qxl.base.sif = &dpy_interface.base;
Gerd Hoffmann9fa03282013-10-11 22:39:59 +0200785 qemu_spice_add_display_interface(&ssd->qxl, con);
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100786 assert(ssd->worker);
Gerd Hoffmann7c20b4a2012-11-13 14:51:41 +0100787
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100788 qemu_spice_create_host_memslot(ssd);
Gerd Hoffmann9c80a312013-02-28 14:47:07 +0100789
790 ssd->dcl.ops = &display_listener_ops;
Gerd Hoffmann9fa03282013-10-11 22:39:59 +0200791 ssd->dcl.con = con;
Gerd Hoffmann52090892013-04-23 15:44:31 +0200792 register_displaychangelistener(&ssd->dcl);
Gerd Hoffmanna3e22262010-08-25 15:32:06 +0200793}
Gerd Hoffmann9fa03282013-10-11 22:39:59 +0200794
795void qemu_spice_display_init(void)
796{
797 QemuConsole *con;
798 int i;
799
800 for (i = 0;; i++) {
801 con = qemu_console_lookup_by_index(i);
802 if (!con || !qemu_console_is_graphic(con)) {
803 break;
804 }
805 if (qemu_spice_have_display_interface(con)) {
806 continue;
807 }
808 qemu_spice_display_init_one(con);
809 }
810}