]>
Commit | Line | Data |
---|---|---|
a3e22260 GH |
1 | /* |
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 | ||
a3e22260 | 18 | #include "qemu-common.h" |
28ecbaee | 19 | #include "ui/qemu-spice.h" |
1de7afc9 PB |
20 | #include "qemu/timer.h" |
21 | #include "qemu/queue.h" | |
83c9089e | 22 | #include "monitor/monitor.h" |
28ecbaee | 23 | #include "ui/console.h" |
9c17d615 | 24 | #include "sysemu/sysemu.h" |
c480bb7d | 25 | #include "trace.h" |
a3e22260 | 26 | |
28ecbaee | 27 | #include "ui/spice-display.h" |
a3e22260 GH |
28 | |
29 | static int debug = 0; | |
30 | ||
2c80e423 | 31 | static void GCC_FMT_ATTR(2, 3) dprint(int level, const char *fmt, ...) |
a3e22260 GH |
32 | { |
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 | ||
42 | int qemu_spice_rect_is_empty(const QXLRect* r) | |
43 | { | |
44 | return r->top == r->bottom || r->left == r->right; | |
45 | } | |
46 | ||
47 | void 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 | ||
2e1a98c9 AL |
64 | QXLCookie *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 | ||
5ff4e36c AL |
74 | void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot, |
75 | qxl_async_io async) | |
5c59d118 | 76 | { |
c480bb7d AL |
77 | trace_qemu_spice_add_memslot(ssd->qxl.id, memslot->slot_id, |
78 | memslot->virt_start, memslot->virt_end, | |
79 | async); | |
80 | ||
5ff4e36c | 81 | if (async != QXL_SYNC) { |
2e1a98c9 | 82 | spice_qxl_add_memslot_async(&ssd->qxl, memslot, |
34d14c6d PM |
83 | (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO, |
84 | QXL_IO_MEMSLOT_ADD_ASYNC)); | |
5ff4e36c | 85 | } else { |
26defe81 | 86 | spice_qxl_add_memslot(&ssd->qxl, memslot); |
5ff4e36c | 87 | } |
5c59d118 GH |
88 | } |
89 | ||
90 | void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, uint32_t sid) | |
91 | { | |
c480bb7d | 92 | trace_qemu_spice_del_memslot(ssd->qxl.id, gid, sid); |
26defe81 | 93 | spice_qxl_del_memslot(&ssd->qxl, gid, sid); |
5c59d118 GH |
94 | } |
95 | ||
96 | void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id, | |
5ff4e36c AL |
97 | QXLDevSurfaceCreate *surface, |
98 | qxl_async_io async) | |
5c59d118 | 99 | { |
c480bb7d | 100 | trace_qemu_spice_create_primary_surface(ssd->qxl.id, id, surface, async); |
5ff4e36c | 101 | if (async != QXL_SYNC) { |
2e1a98c9 | 102 | spice_qxl_create_primary_surface_async(&ssd->qxl, id, surface, |
34d14c6d PM |
103 | (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO, |
104 | QXL_IO_CREATE_PRIMARY_ASYNC)); | |
5ff4e36c | 105 | } else { |
26defe81 | 106 | spice_qxl_create_primary_surface(&ssd->qxl, id, surface); |
5ff4e36c | 107 | } |
5c59d118 GH |
108 | } |
109 | ||
5ff4e36c AL |
110 | void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, |
111 | uint32_t id, qxl_async_io async) | |
5c59d118 | 112 | { |
c480bb7d | 113 | trace_qemu_spice_destroy_primary_surface(ssd->qxl.id, id, async); |
5ff4e36c | 114 | if (async != QXL_SYNC) { |
2e1a98c9 | 115 | spice_qxl_destroy_primary_surface_async(&ssd->qxl, id, |
34d14c6d PM |
116 | (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO, |
117 | QXL_IO_DESTROY_PRIMARY_ASYNC)); | |
5ff4e36c | 118 | } else { |
26defe81 | 119 | spice_qxl_destroy_primary_surface(&ssd->qxl, id); |
5ff4e36c | 120 | } |
5c59d118 GH |
121 | } |
122 | ||
5c59d118 GH |
123 | void qemu_spice_wakeup(SimpleSpiceDisplay *ssd) |
124 | { | |
c480bb7d | 125 | trace_qemu_spice_wakeup(ssd->qxl.id); |
26defe81 | 126 | spice_qxl_wakeup(&ssd->qxl); |
5c59d118 GH |
127 | } |
128 | ||
c60319a3 GH |
129 | static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd, |
130 | QXLRect *rect) | |
a3e22260 GH |
131 | { |
132 | SimpleSpiceUpdate *update; | |
133 | QXLDrawable *drawable; | |
134 | QXLImage *image; | |
135 | QXLCommand *cmd; | |
d9a86569 | 136 | int bw, bh; |
22795174 | 137 | struct timespec time_space; |
d9a86569 | 138 | pixman_image_t *dest; |
a3e22260 | 139 | |
c480bb7d | 140 | trace_qemu_spice_create_update( |
c60319a3 GH |
141 | rect->left, rect->right, |
142 | rect->top, rect->bottom); | |
a3e22260 | 143 | |
7267c094 | 144 | update = g_malloc0(sizeof(*update)); |
a3e22260 GH |
145 | drawable = &update->drawable; |
146 | image = &update->image; | |
147 | cmd = &update->ext.cmd; | |
148 | ||
c60319a3 GH |
149 | bw = rect->right - rect->left; |
150 | bh = rect->bottom - rect->top; | |
7267c094 | 151 | update->bitmap = g_malloc(bw * bh * 4); |
a3e22260 | 152 | |
c60319a3 | 153 | drawable->bbox = *rect; |
a3e22260 GH |
154 | drawable->clip.type = SPICE_CLIP_TYPE_NONE; |
155 | drawable->effect = QXL_EFFECT_OPAQUE; | |
a13ccc99 | 156 | drawable->release_info.id = (uintptr_t)update; |
a3e22260 GH |
157 | drawable->type = QXL_DRAW_COPY; |
158 | drawable->surfaces_dest[0] = -1; | |
159 | drawable->surfaces_dest[1] = -1; | |
160 | drawable->surfaces_dest[2] = -1; | |
22795174 AL |
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; | |
a3e22260 GH |
165 | |
166 | drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT; | |
a13ccc99 | 167 | drawable->u.copy.src_bitmap = (uintptr_t)image; |
a3e22260 GH |
168 | 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; | |
a13ccc99 | 177 | image->bitmap.data = (uintptr_t)(update->bitmap); |
a3e22260 GH |
178 | image->bitmap.palette = 0; |
179 | image->bitmap.format = SPICE_BITMAP_FMT_32BIT; | |
180 | ||
d9a86569 GH |
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, | |
188 | 0, 0, bw, bh); | |
189 | pixman_image_unref(dest); | |
a3e22260 GH |
190 | |
191 | cmd->type = QXL_CMD_DRAW; | |
a13ccc99 | 192 | cmd->data = (uintptr_t)drawable; |
a3e22260 | 193 | |
b1af98ba | 194 | QTAILQ_INSERT_TAIL(&ssd->updates, update, next); |
a3e22260 GH |
195 | } |
196 | ||
c60319a3 GH |
197 | static void qemu_spice_create_update(SimpleSpiceDisplay *ssd) |
198 | { | |
b021bd29 | 199 | static const int blksize = 32; |
71874c17 | 200 | int blocks = (surface_width(ssd->ds) + blksize - 1) / blksize; |
b021bd29 GH |
201 | int dirty_top[blocks]; |
202 | int y, yoff, x, xoff, blk, bw; | |
71874c17 | 203 | int bpp = surface_bytes_per_pixel(ssd->ds); |
b021bd29 GH |
204 | uint8_t *guest, *mirror; |
205 | ||
c60319a3 GH |
206 | if (qemu_spice_rect_is_empty(&ssd->dirty)) { |
207 | return; | |
208 | }; | |
a7310dd3 | 209 | |
d9a86569 | 210 | if (ssd->surface == NULL) { |
71874c17 GH |
211 | ssd->surface = pixman_image_ref(ssd->ds->image); |
212 | ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format, | |
213 | ssd->ds->image); | |
a7310dd3 GH |
214 | } |
215 | ||
b021bd29 GH |
216 | for (blk = 0; blk < blocks; blk++) { |
217 | dirty_top[blk] = -1; | |
218 | } | |
219 | ||
71874c17 | 220 | guest = surface_data(ssd->ds); |
d9a86569 | 221 | mirror = (void *)pixman_image_get_data(ssd->mirror); |
b021bd29 | 222 | for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) { |
71874c17 | 223 | yoff = y * surface_stride(ssd->ds); |
b021bd29 GH |
224 | for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) { |
225 | xoff = x * bpp; | |
226 | blk = x / blksize; | |
227 | bw = MIN(blksize, ssd->dirty.right - x); | |
228 | if (memcmp(guest + yoff + xoff, | |
229 | mirror + yoff + xoff, | |
230 | bw * bpp) == 0) { | |
231 | if (dirty_top[blk] != -1) { | |
232 | QXLRect update = { | |
233 | .top = dirty_top[blk], | |
234 | .bottom = y, | |
235 | .left = x, | |
236 | .right = x + bw, | |
237 | }; | |
238 | qemu_spice_create_one_update(ssd, &update); | |
239 | dirty_top[blk] = -1; | |
240 | } | |
241 | } else { | |
242 | if (dirty_top[blk] == -1) { | |
243 | dirty_top[blk] = y; | |
244 | } | |
245 | } | |
246 | } | |
247 | } | |
248 | ||
249 | for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) { | |
250 | blk = x / blksize; | |
251 | bw = MIN(blksize, ssd->dirty.right - x); | |
252 | if (dirty_top[blk] != -1) { | |
253 | QXLRect update = { | |
254 | .top = dirty_top[blk], | |
255 | .bottom = ssd->dirty.bottom, | |
256 | .left = x, | |
257 | .right = x + bw, | |
258 | }; | |
259 | qemu_spice_create_one_update(ssd, &update); | |
260 | dirty_top[blk] = -1; | |
261 | } | |
262 | } | |
263 | ||
c60319a3 GH |
264 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
265 | } | |
266 | ||
a3e22260 | 267 | /* |
4580c490 | 268 | * Called from spice server thread context (via interface_release_resource) |
a3e22260 | 269 | * We do *not* hold the global qemu mutex here, so extra care is needed |
5cbdb3a3 | 270 | * when calling qemu functions. QEMU interfaces used: |
7267c094 | 271 | * - g_free (underlying glibc free is re-entrant). |
a3e22260 GH |
272 | */ |
273 | void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update) | |
274 | { | |
7267c094 AL |
275 | g_free(update->bitmap); |
276 | g_free(update); | |
a3e22260 GH |
277 | } |
278 | ||
279 | void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd) | |
280 | { | |
281 | QXLDevMemSlot memslot; | |
282 | ||
35b2122d | 283 | dprint(1, "%s/%d:\n", __func__, ssd->qxl.id); |
a3e22260 GH |
284 | |
285 | memset(&memslot, 0, sizeof(memslot)); | |
286 | memslot.slot_group_id = MEMSLOT_GROUP_HOST; | |
287 | memslot.virt_end = ~0; | |
5ff4e36c | 288 | qemu_spice_add_memslot(ssd, &memslot, QXL_SYNC); |
a3e22260 GH |
289 | } |
290 | ||
291 | void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) | |
292 | { | |
293 | QXLDevSurfaceCreate surface; | |
294 | ||
160c31f7 AL |
295 | memset(&surface, 0, sizeof(surface)); |
296 | ||
35b2122d | 297 | dprint(1, "%s/%d: %dx%d\n", __func__, ssd->qxl.id, |
71874c17 | 298 | surface_width(ssd->ds), surface_height(ssd->ds)); |
a3e22260 GH |
299 | |
300 | surface.format = SPICE_SURFACE_FMT_32_xRGB; | |
71874c17 GH |
301 | surface.width = surface_width(ssd->ds); |
302 | surface.height = surface_height(ssd->ds); | |
a3e22260 | 303 | surface.stride = -surface.width * 4; |
869564a9 | 304 | surface.mouse_mode = true; |
a3e22260 GH |
305 | surface.flags = 0; |
306 | surface.type = 0; | |
a13ccc99 | 307 | surface.mem = (uintptr_t)ssd->buf; |
a3e22260 | 308 | surface.group_id = MEMSLOT_GROUP_HOST; |
7466bc49 | 309 | |
5ff4e36c | 310 | qemu_spice_create_primary_surface(ssd, 0, &surface, QXL_SYNC); |
a3e22260 GH |
311 | } |
312 | ||
313 | void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd) | |
314 | { | |
35b2122d | 315 | dprint(1, "%s/%d:\n", __func__, ssd->qxl.id); |
a3e22260 | 316 | |
5ff4e36c | 317 | qemu_spice_destroy_primary_surface(ssd, 0, QXL_SYNC); |
a3e22260 GH |
318 | } |
319 | ||
c78f7137 | 320 | void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd) |
a963f876 | 321 | { |
a963f876 | 322 | qemu_mutex_init(&ssd->lock); |
b1af98ba | 323 | QTAILQ_INIT(&ssd->updates); |
a963f876 GH |
324 | ssd->mouse_x = -1; |
325 | ssd->mouse_y = -1; | |
ddd8fdc7 GH |
326 | if (ssd->num_surfaces == 0) { |
327 | ssd->num_surfaces = 1024; | |
328 | } | |
a963f876 | 329 | ssd->bufsize = (16 * 1024 * 1024); |
7267c094 | 330 | ssd->buf = g_malloc(ssd->bufsize); |
a963f876 GH |
331 | } |
332 | ||
a3e22260 GH |
333 | /* display listener callbacks */ |
334 | ||
335 | void qemu_spice_display_update(SimpleSpiceDisplay *ssd, | |
336 | int x, int y, int w, int h) | |
337 | { | |
338 | QXLRect update_area; | |
339 | ||
35b2122d GH |
340 | dprint(2, "%s/%d: x %d y %d w %d h %d\n", __func__, |
341 | ssd->qxl.id, x, y, w, h); | |
a3e22260 GH |
342 | update_area.left = x, |
343 | update_area.right = x + w; | |
344 | update_area.top = y; | |
345 | update_area.bottom = y + h; | |
346 | ||
a3e22260 GH |
347 | if (qemu_spice_rect_is_empty(&ssd->dirty)) { |
348 | ssd->notify++; | |
349 | } | |
350 | qemu_spice_rect_union(&ssd->dirty, &update_area); | |
a3e22260 GH |
351 | } |
352 | ||
c12aeb86 GH |
353 | void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, |
354 | DisplaySurface *surface) | |
a3e22260 | 355 | { |
b1af98ba | 356 | SimpleSpiceUpdate *update; |
4b87dc4c | 357 | bool need_destroy; |
b1af98ba | 358 | |
35b2122d | 359 | dprint(1, "%s/%d:\n", __func__, ssd->qxl.id); |
a3e22260 | 360 | |
a3e22260 | 361 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
d9a86569 GH |
362 | if (ssd->surface) { |
363 | pixman_image_unref(ssd->surface); | |
364 | ssd->surface = NULL; | |
365 | pixman_image_unref(ssd->mirror); | |
366 | ssd->mirror = NULL; | |
367 | } | |
a3e22260 | 368 | |
e0c64d08 | 369 | qemu_mutex_lock(&ssd->lock); |
4b87dc4c | 370 | need_destroy = (ssd->ds != NULL); |
71874c17 | 371 | ssd->ds = surface; |
b1af98ba GH |
372 | while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) { |
373 | QTAILQ_REMOVE(&ssd->updates, update, next); | |
374 | qemu_spice_destroy_update(ssd, update); | |
e0c64d08 GH |
375 | } |
376 | qemu_mutex_unlock(&ssd->lock); | |
4b87dc4c GH |
377 | if (need_destroy) { |
378 | qemu_spice_destroy_host_primary(ssd); | |
379 | } | |
380 | if (ssd->ds) { | |
381 | qemu_spice_create_host_primary(ssd); | |
382 | } | |
a3e22260 | 383 | |
a3e22260 GH |
384 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
385 | ssd->notify++; | |
a3e22260 GH |
386 | } |
387 | ||
bb5a8cd5 | 388 | void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd) |
a3e22260 | 389 | { |
07536094 | 390 | if (ssd->cursor) { |
284d1c6b GH |
391 | assert(ssd->dcl.con); |
392 | dpy_cursor_define(ssd->dcl.con, ssd->cursor); | |
07536094 GH |
393 | cursor_put(ssd->cursor); |
394 | ssd->cursor = NULL; | |
395 | } | |
396 | if (ssd->mouse_x != -1 && ssd->mouse_y != -1) { | |
284d1c6b GH |
397 | assert(ssd->dcl.con); |
398 | dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1); | |
07536094 GH |
399 | ssd->mouse_x = -1; |
400 | ssd->mouse_y = -1; | |
401 | } | |
bb5a8cd5 AL |
402 | } |
403 | ||
404 | void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) | |
405 | { | |
35b2122d | 406 | dprint(3, "%s/%d:\n", __func__, ssd->qxl.id); |
284d1c6b | 407 | graphic_hw_update(ssd->dcl.con); |
bb5a8cd5 AL |
408 | |
409 | qemu_mutex_lock(&ssd->lock); | |
71874c17 | 410 | if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) { |
b1af98ba | 411 | qemu_spice_create_update(ssd); |
bb5a8cd5 AL |
412 | ssd->notify++; |
413 | } | |
414 | qemu_spice_cursor_refresh_unlocked(ssd); | |
e0c64d08 GH |
415 | qemu_mutex_unlock(&ssd->lock); |
416 | ||
a3e22260 GH |
417 | if (ssd->notify) { |
418 | ssd->notify = 0; | |
5c59d118 | 419 | qemu_spice_wakeup(ssd); |
35b2122d | 420 | dprint(2, "%s/%d: notify\n", __func__, ssd->qxl.id); |
a3e22260 GH |
421 | } |
422 | } | |
423 | ||
424 | /* spice display interface callbacks */ | |
425 | ||
426 | static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker) | |
427 | { | |
428 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
429 | ||
35b2122d | 430 | dprint(1, "%s/%d:\n", __func__, ssd->qxl.id); |
a3e22260 GH |
431 | ssd->worker = qxl_worker; |
432 | } | |
433 | ||
434 | static void interface_set_compression_level(QXLInstance *sin, int level) | |
435 | { | |
35b2122d | 436 | dprint(1, "%s/%d:\n", __func__, sin->id); |
a3e22260 GH |
437 | /* nothing to do */ |
438 | } | |
439 | ||
440 | static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time) | |
441 | { | |
35b2122d | 442 | dprint(3, "%s/%d:\n", __func__, sin->id); |
a3e22260 GH |
443 | /* nothing to do */ |
444 | } | |
445 | ||
446 | static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info) | |
447 | { | |
448 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
449 | ||
450 | info->memslot_gen_bits = MEMSLOT_GENERATION_BITS; | |
451 | info->memslot_id_bits = MEMSLOT_SLOT_BITS; | |
452 | info->num_memslots = NUM_MEMSLOTS; | |
453 | info->num_memslots_groups = NUM_MEMSLOTS_GROUPS; | |
454 | info->internal_groupslot_id = 0; | |
455 | info->qxl_ram_size = ssd->bufsize; | |
ddd8fdc7 | 456 | info->n_surfaces = ssd->num_surfaces; |
a3e22260 GH |
457 | } |
458 | ||
459 | static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext) | |
460 | { | |
461 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
462 | SimpleSpiceUpdate *update; | |
e0c64d08 | 463 | int ret = false; |
a3e22260 | 464 | |
35b2122d | 465 | dprint(3, "%s/%d:\n", __func__, ssd->qxl.id); |
e0c64d08 GH |
466 | |
467 | qemu_mutex_lock(&ssd->lock); | |
b1af98ba GH |
468 | update = QTAILQ_FIRST(&ssd->updates); |
469 | if (update != NULL) { | |
470 | QTAILQ_REMOVE(&ssd->updates, update, next); | |
e0c64d08 GH |
471 | *ext = update->ext; |
472 | ret = true; | |
a3e22260 | 473 | } |
e0c64d08 GH |
474 | qemu_mutex_unlock(&ssd->lock); |
475 | ||
476 | return ret; | |
a3e22260 GH |
477 | } |
478 | ||
479 | static int interface_req_cmd_notification(QXLInstance *sin) | |
480 | { | |
35b2122d | 481 | dprint(1, "%s/%d:\n", __func__, sin->id); |
a3e22260 GH |
482 | return 1; |
483 | } | |
484 | ||
485 | static void interface_release_resource(QXLInstance *sin, | |
486 | struct QXLReleaseInfoExt ext) | |
487 | { | |
488 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
489 | uintptr_t id; | |
490 | ||
35b2122d | 491 | dprint(2, "%s/%d:\n", __func__, ssd->qxl.id); |
a3e22260 GH |
492 | id = ext.info->id; |
493 | qemu_spice_destroy_update(ssd, (void*)id); | |
494 | } | |
495 | ||
496 | static int interface_get_cursor_command(QXLInstance *sin, struct QXLCommandExt *ext) | |
497 | { | |
498 | dprint(3, "%s:\n", __FUNCTION__); | |
499 | return false; | |
500 | } | |
501 | ||
502 | static int interface_req_cursor_notification(QXLInstance *sin) | |
503 | { | |
504 | dprint(1, "%s:\n", __FUNCTION__); | |
505 | return 1; | |
506 | } | |
507 | ||
508 | static void interface_notify_update(QXLInstance *sin, uint32_t update_id) | |
509 | { | |
510 | fprintf(stderr, "%s: abort()\n", __FUNCTION__); | |
511 | abort(); | |
512 | } | |
513 | ||
514 | static int interface_flush_resources(QXLInstance *sin) | |
515 | { | |
516 | fprintf(stderr, "%s: abort()\n", __FUNCTION__); | |
517 | abort(); | |
518 | return 0; | |
519 | } | |
520 | ||
21a50d0b GH |
521 | static void interface_update_area_complete(QXLInstance *sin, |
522 | uint32_t surface_id, | |
523 | QXLRect *dirty, uint32_t num_updated_rects) | |
524 | { | |
525 | /* should never be called, used in qxl native mode only */ | |
526 | fprintf(stderr, "%s: abort()\n", __func__); | |
527 | abort(); | |
528 | } | |
529 | ||
530 | /* called from spice server thread context only */ | |
531 | static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token) | |
532 | { | |
533 | /* should never be called, used in qxl native mode only */ | |
534 | fprintf(stderr, "%s: abort()\n", __func__); | |
535 | abort(); | |
536 | } | |
537 | ||
538 | static void interface_set_client_capabilities(QXLInstance *sin, | |
539 | uint8_t client_present, | |
540 | uint8_t caps[58]) | |
541 | { | |
542 | dprint(3, "%s:\n", __func__); | |
543 | } | |
544 | ||
545 | static int interface_client_monitors_config(QXLInstance *sin, | |
9b74d0d5 | 546 | VDAgentMonitorsConfig *mc) |
21a50d0b | 547 | { |
9b74d0d5 GH |
548 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); |
549 | QemuUIInfo info; | |
550 | int rc; | |
551 | ||
dc491cfc GH |
552 | if (!mc) { |
553 | return 1; | |
554 | } | |
555 | ||
9b74d0d5 GH |
556 | /* |
557 | * FIXME: multihead is tricky due to the way | |
558 | * spice has multihead implemented. | |
559 | */ | |
560 | memset(&info, 0, sizeof(info)); | |
561 | if (mc->num_of_monitors > 0) { | |
562 | info.width = mc->monitors[0].width; | |
563 | info.height = mc->monitors[0].height; | |
564 | } | |
565 | rc = dpy_set_ui_info(ssd->dcl.con, &info); | |
566 | dprint(1, "%s/%d: size %dx%d, rc %d <--- ==========================\n", | |
567 | __func__, ssd->qxl.id, info.width, info.height, rc); | |
568 | if (rc != 0) { | |
569 | return 0; /* == not supported by guest */ | |
570 | } else { | |
571 | return 1; | |
572 | } | |
21a50d0b GH |
573 | } |
574 | ||
a3e22260 GH |
575 | static const QXLInterface dpy_interface = { |
576 | .base.type = SPICE_INTERFACE_QXL, | |
577 | .base.description = "qemu simple display", | |
578 | .base.major_version = SPICE_INTERFACE_QXL_MAJOR, | |
579 | .base.minor_version = SPICE_INTERFACE_QXL_MINOR, | |
580 | ||
581 | .attache_worker = interface_attach_worker, | |
582 | .set_compression_level = interface_set_compression_level, | |
583 | .set_mm_time = interface_set_mm_time, | |
584 | .get_init_info = interface_get_init_info, | |
585 | ||
586 | /* the callbacks below are called from spice server thread context */ | |
587 | .get_command = interface_get_command, | |
588 | .req_cmd_notification = interface_req_cmd_notification, | |
589 | .release_resource = interface_release_resource, | |
590 | .get_cursor_command = interface_get_cursor_command, | |
591 | .req_cursor_notification = interface_req_cursor_notification, | |
592 | .notify_update = interface_notify_update, | |
593 | .flush_resources = interface_flush_resources, | |
21a50d0b GH |
594 | .async_complete = interface_async_complete, |
595 | .update_area_complete = interface_update_area_complete, | |
596 | .set_client_capabilities = interface_set_client_capabilities, | |
597 | .client_monitors_config = interface_client_monitors_config, | |
a3e22260 GH |
598 | }; |
599 | ||
7c20b4a3 | 600 | static void display_update(DisplayChangeListener *dcl, |
7c20b4a3 | 601 | int x, int y, int w, int h) |
a3e22260 | 602 | { |
9c80a315 GH |
603 | SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl); |
604 | qemu_spice_display_update(ssd, x, y, w, h); | |
a3e22260 GH |
605 | } |
606 | ||
c12aeb86 | 607 | static void display_switch(DisplayChangeListener *dcl, |
c12aeb86 | 608 | struct DisplaySurface *surface) |
a3e22260 | 609 | { |
9c80a315 | 610 | SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl); |
c12aeb86 | 611 | qemu_spice_display_switch(ssd, surface); |
a3e22260 GH |
612 | } |
613 | ||
bc2ed970 | 614 | static void display_refresh(DisplayChangeListener *dcl) |
a3e22260 | 615 | { |
9c80a315 GH |
616 | SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl); |
617 | qemu_spice_display_refresh(ssd); | |
a3e22260 GH |
618 | } |
619 | ||
7c20b4a3 GH |
620 | static const DisplayChangeListenerOps display_listener_ops = { |
621 | .dpy_name = "spice", | |
a93a4a22 | 622 | .dpy_gfx_update = display_update, |
c12aeb86 | 623 | .dpy_gfx_switch = display_switch, |
7c20b4a3 | 624 | .dpy_refresh = display_refresh, |
a3e22260 GH |
625 | }; |
626 | ||
9fa03286 | 627 | static void qemu_spice_display_init_one(QemuConsole *con) |
a3e22260 | 628 | { |
9c80a315 GH |
629 | SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1); |
630 | ||
c78f7137 | 631 | qemu_spice_display_init_common(ssd); |
a3e22260 | 632 | |
9c80a315 | 633 | ssd->qxl.base.sif = &dpy_interface.base; |
9fa03286 | 634 | qemu_spice_add_display_interface(&ssd->qxl, con); |
9c80a315 | 635 | assert(ssd->worker); |
a3e22260 | 636 | |
9c80a315 | 637 | qemu_spice_create_host_memslot(ssd); |
7c20b4a3 | 638 | |
9c80a315 | 639 | ssd->dcl.ops = &display_listener_ops; |
9fa03286 | 640 | ssd->dcl.con = con; |
5209089f | 641 | register_displaychangelistener(&ssd->dcl); |
a3e22260 | 642 | } |
9fa03286 GH |
643 | |
644 | void qemu_spice_display_init(void) | |
645 | { | |
646 | QemuConsole *con; | |
647 | int i; | |
648 | ||
649 | for (i = 0;; i++) { | |
650 | con = qemu_console_lookup_by_index(i); | |
651 | if (!con || !qemu_console_is_graphic(con)) { | |
652 | break; | |
653 | } | |
654 | if (qemu_spice_have_display_interface(con)) { | |
655 | continue; | |
656 | } | |
657 | qemu_spice_display_init_one(con); | |
658 | } | |
659 | } |