]>
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 AL |
85 | } else { |
86 | ssd->worker->add_memslot(ssd->worker, memslot); | |
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); |
5c59d118 GH |
93 | ssd->worker->del_memslot(ssd->worker, gid, sid); |
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 AL |
105 | } else { |
106 | ssd->worker->create_primary_surface(ssd->worker, id, surface); | |
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 AL |
118 | } else { |
119 | ssd->worker->destroy_primary_surface(ssd->worker, id); | |
120 | } | |
5c59d118 GH |
121 | } |
122 | ||
5c59d118 GH |
123 | void qemu_spice_wakeup(SimpleSpiceDisplay *ssd) |
124 | { | |
c480bb7d | 125 | trace_qemu_spice_wakeup(ssd->qxl.id); |
5c59d118 GH |
126 | ssd->worker->wakeup(ssd->worker); |
127 | } | |
128 | ||
71d388d4 YH |
129 | static int spice_display_is_running; |
130 | ||
131 | void qemu_spice_display_start(void) | |
132 | { | |
133 | spice_display_is_running = true; | |
134 | } | |
135 | ||
136 | void qemu_spice_display_stop(void) | |
137 | { | |
138 | spice_display_is_running = false; | |
139 | } | |
140 | ||
71d388d4 YH |
141 | int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd) |
142 | { | |
71d388d4 | 143 | return spice_display_is_running; |
71d388d4 YH |
144 | } |
145 | ||
c60319a3 GH |
146 | static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd, |
147 | QXLRect *rect) | |
a3e22260 GH |
148 | { |
149 | SimpleSpiceUpdate *update; | |
150 | QXLDrawable *drawable; | |
151 | QXLImage *image; | |
152 | QXLCommand *cmd; | |
d9a86569 | 153 | int bw, bh; |
22795174 | 154 | struct timespec time_space; |
d9a86569 | 155 | pixman_image_t *dest; |
a3e22260 | 156 | |
c480bb7d | 157 | trace_qemu_spice_create_update( |
c60319a3 GH |
158 | rect->left, rect->right, |
159 | rect->top, rect->bottom); | |
a3e22260 | 160 | |
7267c094 | 161 | update = g_malloc0(sizeof(*update)); |
a3e22260 GH |
162 | drawable = &update->drawable; |
163 | image = &update->image; | |
164 | cmd = &update->ext.cmd; | |
165 | ||
c60319a3 GH |
166 | bw = rect->right - rect->left; |
167 | bh = rect->bottom - rect->top; | |
7267c094 | 168 | update->bitmap = g_malloc(bw * bh * 4); |
a3e22260 | 169 | |
c60319a3 | 170 | drawable->bbox = *rect; |
a3e22260 GH |
171 | drawable->clip.type = SPICE_CLIP_TYPE_NONE; |
172 | drawable->effect = QXL_EFFECT_OPAQUE; | |
a13ccc99 | 173 | drawable->release_info.id = (uintptr_t)update; |
a3e22260 GH |
174 | drawable->type = QXL_DRAW_COPY; |
175 | drawable->surfaces_dest[0] = -1; | |
176 | drawable->surfaces_dest[1] = -1; | |
177 | drawable->surfaces_dest[2] = -1; | |
22795174 AL |
178 | clock_gettime(CLOCK_MONOTONIC, &time_space); |
179 | /* time in milliseconds from epoch. */ | |
180 | drawable->mm_time = time_space.tv_sec * 1000 | |
181 | + time_space.tv_nsec / 1000 / 1000; | |
a3e22260 GH |
182 | |
183 | drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT; | |
a13ccc99 | 184 | drawable->u.copy.src_bitmap = (uintptr_t)image; |
a3e22260 GH |
185 | drawable->u.copy.src_area.right = bw; |
186 | drawable->u.copy.src_area.bottom = bh; | |
187 | ||
188 | QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, ssd->unique++); | |
189 | image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP; | |
190 | image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN; | |
191 | image->bitmap.stride = bw * 4; | |
192 | image->descriptor.width = image->bitmap.x = bw; | |
193 | image->descriptor.height = image->bitmap.y = bh; | |
a13ccc99 | 194 | image->bitmap.data = (uintptr_t)(update->bitmap); |
a3e22260 GH |
195 | image->bitmap.palette = 0; |
196 | image->bitmap.format = SPICE_BITMAP_FMT_32BIT; | |
197 | ||
d9a86569 GH |
198 | dest = pixman_image_create_bits(PIXMAN_x8r8g8b8, bw, bh, |
199 | (void *)update->bitmap, bw * 4); | |
200 | pixman_image_composite(PIXMAN_OP_SRC, ssd->surface, NULL, ssd->mirror, | |
201 | rect->left, rect->top, 0, 0, | |
202 | rect->left, rect->top, bw, bh); | |
203 | pixman_image_composite(PIXMAN_OP_SRC, ssd->mirror, NULL, dest, | |
204 | rect->left, rect->top, 0, 0, | |
205 | 0, 0, bw, bh); | |
206 | pixman_image_unref(dest); | |
a3e22260 GH |
207 | |
208 | cmd->type = QXL_CMD_DRAW; | |
a13ccc99 | 209 | cmd->data = (uintptr_t)drawable; |
a3e22260 | 210 | |
b1af98ba | 211 | QTAILQ_INSERT_TAIL(&ssd->updates, update, next); |
a3e22260 GH |
212 | } |
213 | ||
c60319a3 GH |
214 | static void qemu_spice_create_update(SimpleSpiceDisplay *ssd) |
215 | { | |
b021bd29 | 216 | static const int blksize = 32; |
71874c17 | 217 | int blocks = (surface_width(ssd->ds) + blksize - 1) / blksize; |
b021bd29 GH |
218 | int dirty_top[blocks]; |
219 | int y, yoff, x, xoff, blk, bw; | |
71874c17 | 220 | int bpp = surface_bytes_per_pixel(ssd->ds); |
b021bd29 GH |
221 | uint8_t *guest, *mirror; |
222 | ||
c60319a3 GH |
223 | if (qemu_spice_rect_is_empty(&ssd->dirty)) { |
224 | return; | |
225 | }; | |
a7310dd3 | 226 | |
d9a86569 | 227 | if (ssd->surface == NULL) { |
71874c17 GH |
228 | ssd->surface = pixman_image_ref(ssd->ds->image); |
229 | ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format, | |
230 | ssd->ds->image); | |
a7310dd3 GH |
231 | } |
232 | ||
b021bd29 GH |
233 | for (blk = 0; blk < blocks; blk++) { |
234 | dirty_top[blk] = -1; | |
235 | } | |
236 | ||
71874c17 | 237 | guest = surface_data(ssd->ds); |
d9a86569 | 238 | mirror = (void *)pixman_image_get_data(ssd->mirror); |
b021bd29 | 239 | for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) { |
71874c17 | 240 | yoff = y * surface_stride(ssd->ds); |
b021bd29 GH |
241 | for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) { |
242 | xoff = x * bpp; | |
243 | blk = x / blksize; | |
244 | bw = MIN(blksize, ssd->dirty.right - x); | |
245 | if (memcmp(guest + yoff + xoff, | |
246 | mirror + yoff + xoff, | |
247 | bw * bpp) == 0) { | |
248 | if (dirty_top[blk] != -1) { | |
249 | QXLRect update = { | |
250 | .top = dirty_top[blk], | |
251 | .bottom = y, | |
252 | .left = x, | |
253 | .right = x + bw, | |
254 | }; | |
255 | qemu_spice_create_one_update(ssd, &update); | |
256 | dirty_top[blk] = -1; | |
257 | } | |
258 | } else { | |
259 | if (dirty_top[blk] == -1) { | |
260 | dirty_top[blk] = y; | |
261 | } | |
262 | } | |
263 | } | |
264 | } | |
265 | ||
266 | for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) { | |
267 | blk = x / blksize; | |
268 | bw = MIN(blksize, ssd->dirty.right - x); | |
269 | if (dirty_top[blk] != -1) { | |
270 | QXLRect update = { | |
271 | .top = dirty_top[blk], | |
272 | .bottom = ssd->dirty.bottom, | |
273 | .left = x, | |
274 | .right = x + bw, | |
275 | }; | |
276 | qemu_spice_create_one_update(ssd, &update); | |
277 | dirty_top[blk] = -1; | |
278 | } | |
279 | } | |
280 | ||
c60319a3 GH |
281 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
282 | } | |
283 | ||
a3e22260 | 284 | /* |
4580c490 | 285 | * Called from spice server thread context (via interface_release_resource) |
a3e22260 | 286 | * We do *not* hold the global qemu mutex here, so extra care is needed |
5cbdb3a3 | 287 | * when calling qemu functions. QEMU interfaces used: |
7267c094 | 288 | * - g_free (underlying glibc free is re-entrant). |
a3e22260 GH |
289 | */ |
290 | void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update) | |
291 | { | |
7267c094 AL |
292 | g_free(update->bitmap); |
293 | g_free(update); | |
a3e22260 GH |
294 | } |
295 | ||
296 | void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd) | |
297 | { | |
298 | QXLDevMemSlot memslot; | |
299 | ||
300 | dprint(1, "%s:\n", __FUNCTION__); | |
301 | ||
302 | memset(&memslot, 0, sizeof(memslot)); | |
303 | memslot.slot_group_id = MEMSLOT_GROUP_HOST; | |
304 | memslot.virt_end = ~0; | |
5ff4e36c | 305 | qemu_spice_add_memslot(ssd, &memslot, QXL_SYNC); |
a3e22260 GH |
306 | } |
307 | ||
308 | void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) | |
309 | { | |
310 | QXLDevSurfaceCreate surface; | |
311 | ||
160c31f7 AL |
312 | memset(&surface, 0, sizeof(surface)); |
313 | ||
a3e22260 | 314 | dprint(1, "%s: %dx%d\n", __FUNCTION__, |
71874c17 | 315 | surface_width(ssd->ds), surface_height(ssd->ds)); |
a3e22260 GH |
316 | |
317 | surface.format = SPICE_SURFACE_FMT_32_xRGB; | |
71874c17 GH |
318 | surface.width = surface_width(ssd->ds); |
319 | surface.height = surface_height(ssd->ds); | |
a3e22260 | 320 | surface.stride = -surface.width * 4; |
869564a9 | 321 | surface.mouse_mode = true; |
a3e22260 GH |
322 | surface.flags = 0; |
323 | surface.type = 0; | |
a13ccc99 | 324 | surface.mem = (uintptr_t)ssd->buf; |
a3e22260 | 325 | surface.group_id = MEMSLOT_GROUP_HOST; |
7466bc49 | 326 | |
5ff4e36c | 327 | qemu_spice_create_primary_surface(ssd, 0, &surface, QXL_SYNC); |
a3e22260 GH |
328 | } |
329 | ||
330 | void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd) | |
331 | { | |
332 | dprint(1, "%s:\n", __FUNCTION__); | |
333 | ||
5ff4e36c | 334 | qemu_spice_destroy_primary_surface(ssd, 0, QXL_SYNC); |
a3e22260 GH |
335 | } |
336 | ||
c78f7137 | 337 | void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd) |
a963f876 | 338 | { |
a963f876 | 339 | qemu_mutex_init(&ssd->lock); |
b1af98ba | 340 | QTAILQ_INIT(&ssd->updates); |
a963f876 GH |
341 | ssd->mouse_x = -1; |
342 | ssd->mouse_y = -1; | |
ddd8fdc7 GH |
343 | if (ssd->num_surfaces == 0) { |
344 | ssd->num_surfaces = 1024; | |
345 | } | |
a963f876 | 346 | ssd->bufsize = (16 * 1024 * 1024); |
7267c094 | 347 | ssd->buf = g_malloc(ssd->bufsize); |
a963f876 GH |
348 | } |
349 | ||
a3e22260 GH |
350 | /* display listener callbacks */ |
351 | ||
352 | void qemu_spice_display_update(SimpleSpiceDisplay *ssd, | |
353 | int x, int y, int w, int h) | |
354 | { | |
355 | QXLRect update_area; | |
356 | ||
357 | dprint(2, "%s: x %d y %d w %d h %d\n", __FUNCTION__, x, y, w, h); | |
358 | update_area.left = x, | |
359 | update_area.right = x + w; | |
360 | update_area.top = y; | |
361 | update_area.bottom = y + h; | |
362 | ||
a3e22260 GH |
363 | if (qemu_spice_rect_is_empty(&ssd->dirty)) { |
364 | ssd->notify++; | |
365 | } | |
366 | qemu_spice_rect_union(&ssd->dirty, &update_area); | |
a3e22260 GH |
367 | } |
368 | ||
c12aeb86 GH |
369 | void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, |
370 | DisplaySurface *surface) | |
a3e22260 | 371 | { |
b1af98ba GH |
372 | SimpleSpiceUpdate *update; |
373 | ||
a3e22260 GH |
374 | dprint(1, "%s:\n", __FUNCTION__); |
375 | ||
a3e22260 | 376 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
d9a86569 GH |
377 | if (ssd->surface) { |
378 | pixman_image_unref(ssd->surface); | |
379 | ssd->surface = NULL; | |
380 | pixman_image_unref(ssd->mirror); | |
381 | ssd->mirror = NULL; | |
382 | } | |
a3e22260 | 383 | |
e0c64d08 | 384 | qemu_mutex_lock(&ssd->lock); |
71874c17 | 385 | ssd->ds = surface; |
b1af98ba GH |
386 | while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) { |
387 | QTAILQ_REMOVE(&ssd->updates, update, next); | |
388 | qemu_spice_destroy_update(ssd, update); | |
e0c64d08 GH |
389 | } |
390 | qemu_mutex_unlock(&ssd->lock); | |
a3e22260 GH |
391 | qemu_spice_destroy_host_primary(ssd); |
392 | qemu_spice_create_host_primary(ssd); | |
393 | ||
a3e22260 GH |
394 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
395 | ssd->notify++; | |
a3e22260 GH |
396 | } |
397 | ||
bb5a8cd5 | 398 | void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd) |
a3e22260 | 399 | { |
07536094 | 400 | if (ssd->cursor) { |
284d1c6b GH |
401 | assert(ssd->dcl.con); |
402 | dpy_cursor_define(ssd->dcl.con, ssd->cursor); | |
07536094 GH |
403 | cursor_put(ssd->cursor); |
404 | ssd->cursor = NULL; | |
405 | } | |
406 | if (ssd->mouse_x != -1 && ssd->mouse_y != -1) { | |
284d1c6b GH |
407 | assert(ssd->dcl.con); |
408 | dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1); | |
07536094 GH |
409 | ssd->mouse_x = -1; |
410 | ssd->mouse_y = -1; | |
411 | } | |
bb5a8cd5 AL |
412 | } |
413 | ||
414 | void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) | |
415 | { | |
416 | dprint(3, "%s:\n", __func__); | |
284d1c6b | 417 | graphic_hw_update(ssd->dcl.con); |
bb5a8cd5 AL |
418 | |
419 | qemu_mutex_lock(&ssd->lock); | |
71874c17 | 420 | if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) { |
b1af98ba | 421 | qemu_spice_create_update(ssd); |
bb5a8cd5 AL |
422 | ssd->notify++; |
423 | } | |
424 | qemu_spice_cursor_refresh_unlocked(ssd); | |
e0c64d08 GH |
425 | qemu_mutex_unlock(&ssd->lock); |
426 | ||
a3e22260 GH |
427 | if (ssd->notify) { |
428 | ssd->notify = 0; | |
5c59d118 | 429 | qemu_spice_wakeup(ssd); |
a3e22260 GH |
430 | dprint(2, "%s: notify\n", __FUNCTION__); |
431 | } | |
432 | } | |
433 | ||
434 | /* spice display interface callbacks */ | |
435 | ||
436 | static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker) | |
437 | { | |
438 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
439 | ||
440 | dprint(1, "%s:\n", __FUNCTION__); | |
441 | ssd->worker = qxl_worker; | |
442 | } | |
443 | ||
444 | static void interface_set_compression_level(QXLInstance *sin, int level) | |
445 | { | |
446 | dprint(1, "%s:\n", __FUNCTION__); | |
447 | /* nothing to do */ | |
448 | } | |
449 | ||
450 | static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time) | |
451 | { | |
452 | dprint(3, "%s:\n", __FUNCTION__); | |
453 | /* nothing to do */ | |
454 | } | |
455 | ||
456 | static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info) | |
457 | { | |
458 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
459 | ||
460 | info->memslot_gen_bits = MEMSLOT_GENERATION_BITS; | |
461 | info->memslot_id_bits = MEMSLOT_SLOT_BITS; | |
462 | info->num_memslots = NUM_MEMSLOTS; | |
463 | info->num_memslots_groups = NUM_MEMSLOTS_GROUPS; | |
464 | info->internal_groupslot_id = 0; | |
465 | info->qxl_ram_size = ssd->bufsize; | |
ddd8fdc7 | 466 | info->n_surfaces = ssd->num_surfaces; |
a3e22260 GH |
467 | } |
468 | ||
469 | static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext) | |
470 | { | |
471 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
472 | SimpleSpiceUpdate *update; | |
e0c64d08 | 473 | int ret = false; |
a3e22260 GH |
474 | |
475 | dprint(3, "%s:\n", __FUNCTION__); | |
e0c64d08 GH |
476 | |
477 | qemu_mutex_lock(&ssd->lock); | |
b1af98ba GH |
478 | update = QTAILQ_FIRST(&ssd->updates); |
479 | if (update != NULL) { | |
480 | QTAILQ_REMOVE(&ssd->updates, update, next); | |
e0c64d08 GH |
481 | *ext = update->ext; |
482 | ret = true; | |
a3e22260 | 483 | } |
e0c64d08 GH |
484 | qemu_mutex_unlock(&ssd->lock); |
485 | ||
486 | return ret; | |
a3e22260 GH |
487 | } |
488 | ||
489 | static int interface_req_cmd_notification(QXLInstance *sin) | |
490 | { | |
491 | dprint(1, "%s:\n", __FUNCTION__); | |
492 | return 1; | |
493 | } | |
494 | ||
495 | static void interface_release_resource(QXLInstance *sin, | |
496 | struct QXLReleaseInfoExt ext) | |
497 | { | |
498 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
499 | uintptr_t id; | |
500 | ||
501 | dprint(2, "%s:\n", __FUNCTION__); | |
502 | id = ext.info->id; | |
503 | qemu_spice_destroy_update(ssd, (void*)id); | |
504 | } | |
505 | ||
506 | static int interface_get_cursor_command(QXLInstance *sin, struct QXLCommandExt *ext) | |
507 | { | |
508 | dprint(3, "%s:\n", __FUNCTION__); | |
509 | return false; | |
510 | } | |
511 | ||
512 | static int interface_req_cursor_notification(QXLInstance *sin) | |
513 | { | |
514 | dprint(1, "%s:\n", __FUNCTION__); | |
515 | return 1; | |
516 | } | |
517 | ||
518 | static void interface_notify_update(QXLInstance *sin, uint32_t update_id) | |
519 | { | |
520 | fprintf(stderr, "%s: abort()\n", __FUNCTION__); | |
521 | abort(); | |
522 | } | |
523 | ||
524 | static int interface_flush_resources(QXLInstance *sin) | |
525 | { | |
526 | fprintf(stderr, "%s: abort()\n", __FUNCTION__); | |
527 | abort(); | |
528 | return 0; | |
529 | } | |
530 | ||
21a50d0b GH |
531 | static void interface_update_area_complete(QXLInstance *sin, |
532 | uint32_t surface_id, | |
533 | QXLRect *dirty, uint32_t num_updated_rects) | |
534 | { | |
535 | /* should never be called, used in qxl native mode only */ | |
536 | fprintf(stderr, "%s: abort()\n", __func__); | |
537 | abort(); | |
538 | } | |
539 | ||
540 | /* called from spice server thread context only */ | |
541 | static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token) | |
542 | { | |
543 | /* should never be called, used in qxl native mode only */ | |
544 | fprintf(stderr, "%s: abort()\n", __func__); | |
545 | abort(); | |
546 | } | |
547 | ||
548 | static void interface_set_client_capabilities(QXLInstance *sin, | |
549 | uint8_t client_present, | |
550 | uint8_t caps[58]) | |
551 | { | |
552 | dprint(3, "%s:\n", __func__); | |
553 | } | |
554 | ||
555 | static int interface_client_monitors_config(QXLInstance *sin, | |
556 | VDAgentMonitorsConfig *monitors_config) | |
557 | { | |
558 | dprint(3, "%s:\n", __func__); | |
559 | return 0; /* == not supported by guest */ | |
560 | } | |
561 | ||
a3e22260 GH |
562 | static const QXLInterface dpy_interface = { |
563 | .base.type = SPICE_INTERFACE_QXL, | |
564 | .base.description = "qemu simple display", | |
565 | .base.major_version = SPICE_INTERFACE_QXL_MAJOR, | |
566 | .base.minor_version = SPICE_INTERFACE_QXL_MINOR, | |
567 | ||
568 | .attache_worker = interface_attach_worker, | |
569 | .set_compression_level = interface_set_compression_level, | |
570 | .set_mm_time = interface_set_mm_time, | |
571 | .get_init_info = interface_get_init_info, | |
572 | ||
573 | /* the callbacks below are called from spice server thread context */ | |
574 | .get_command = interface_get_command, | |
575 | .req_cmd_notification = interface_req_cmd_notification, | |
576 | .release_resource = interface_release_resource, | |
577 | .get_cursor_command = interface_get_cursor_command, | |
578 | .req_cursor_notification = interface_req_cursor_notification, | |
579 | .notify_update = interface_notify_update, | |
580 | .flush_resources = interface_flush_resources, | |
21a50d0b GH |
581 | .async_complete = interface_async_complete, |
582 | .update_area_complete = interface_update_area_complete, | |
583 | .set_client_capabilities = interface_set_client_capabilities, | |
584 | .client_monitors_config = interface_client_monitors_config, | |
a3e22260 GH |
585 | }; |
586 | ||
7c20b4a3 | 587 | static void display_update(DisplayChangeListener *dcl, |
7c20b4a3 | 588 | int x, int y, int w, int h) |
a3e22260 | 589 | { |
9c80a315 GH |
590 | SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl); |
591 | qemu_spice_display_update(ssd, x, y, w, h); | |
a3e22260 GH |
592 | } |
593 | ||
c12aeb86 | 594 | static void display_switch(DisplayChangeListener *dcl, |
c12aeb86 | 595 | struct DisplaySurface *surface) |
a3e22260 | 596 | { |
9c80a315 | 597 | SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl); |
c12aeb86 | 598 | qemu_spice_display_switch(ssd, surface); |
a3e22260 GH |
599 | } |
600 | ||
bc2ed970 | 601 | static void display_refresh(DisplayChangeListener *dcl) |
a3e22260 | 602 | { |
9c80a315 GH |
603 | SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl); |
604 | qemu_spice_display_refresh(ssd); | |
a3e22260 GH |
605 | } |
606 | ||
7c20b4a3 GH |
607 | static const DisplayChangeListenerOps display_listener_ops = { |
608 | .dpy_name = "spice", | |
a93a4a22 | 609 | .dpy_gfx_update = display_update, |
c12aeb86 | 610 | .dpy_gfx_switch = display_switch, |
7c20b4a3 | 611 | .dpy_refresh = display_refresh, |
a3e22260 GH |
612 | }; |
613 | ||
614 | void qemu_spice_display_init(DisplayState *ds) | |
615 | { | |
9c80a315 GH |
616 | SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1); |
617 | ||
c78f7137 | 618 | qemu_spice_display_init_common(ssd); |
a3e22260 | 619 | |
9c80a315 GH |
620 | ssd->qxl.base.sif = &dpy_interface.base; |
621 | qemu_spice_add_interface(&ssd->qxl.base); | |
622 | assert(ssd->worker); | |
a3e22260 | 623 | |
9c80a315 | 624 | qemu_spice_create_host_memslot(ssd); |
7c20b4a3 | 625 | |
9c80a315 | 626 | ssd->dcl.ops = &display_listener_ops; |
284d1c6b | 627 | ssd->dcl.con = qemu_console_lookup_by_index(0); |
5209089f | 628 | register_displaychangelistener(&ssd->dcl); |
71874c17 GH |
629 | |
630 | qemu_spice_create_host_primary(ssd); | |
a3e22260 | 631 | } |