]>
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 GH |
18 | #include "qemu-common.h" |
19 | #include "qemu-spice.h" | |
20 | #include "qemu-timer.h" | |
21 | #include "qemu-queue.h" | |
22 | #include "monitor.h" | |
23 | #include "console.h" | |
24 | #include "sysemu.h" | |
c480bb7d | 25 | #include "trace.h" |
a3e22260 GH |
26 | |
27 | #include "spice-display.h" | |
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; | |
a7310dd3 GH |
153 | uint8_t *src, *mirror, *dst; |
154 | int by, bw, bh, offset, bytes; | |
22795174 | 155 | struct timespec time_space; |
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 | ||
a7310dd3 | 198 | offset = |
c60319a3 GH |
199 | rect->top * ds_get_linesize(ssd->ds) + |
200 | rect->left * ds_get_bytes_per_pixel(ssd->ds); | |
a7310dd3 GH |
201 | bytes = ds_get_bytes_per_pixel(ssd->ds) * bw; |
202 | src = ds_get_data(ssd->ds) + offset; | |
203 | mirror = ssd->ds_mirror + offset; | |
a3e22260 GH |
204 | dst = update->bitmap; |
205 | for (by = 0; by < bh; by++) { | |
a7310dd3 GH |
206 | memcpy(mirror, src, bytes); |
207 | qemu_pf_conv_run(ssd->conv, dst, mirror, bw); | |
a3e22260 | 208 | src += ds_get_linesize(ssd->ds); |
a7310dd3 | 209 | mirror += ds_get_linesize(ssd->ds); |
a3e22260 GH |
210 | dst += image->bitmap.stride; |
211 | } | |
212 | ||
213 | cmd->type = QXL_CMD_DRAW; | |
a13ccc99 | 214 | cmd->data = (uintptr_t)drawable; |
a3e22260 | 215 | |
b1af98ba | 216 | QTAILQ_INSERT_TAIL(&ssd->updates, update, next); |
a3e22260 GH |
217 | } |
218 | ||
c60319a3 GH |
219 | static void qemu_spice_create_update(SimpleSpiceDisplay *ssd) |
220 | { | |
b021bd29 GH |
221 | static const int blksize = 32; |
222 | int blocks = (ds_get_width(ssd->ds) + blksize - 1) / blksize; | |
223 | int dirty_top[blocks]; | |
224 | int y, yoff, x, xoff, blk, bw; | |
225 | int bpp = ds_get_bytes_per_pixel(ssd->ds); | |
226 | uint8_t *guest, *mirror; | |
227 | ||
c60319a3 GH |
228 | if (qemu_spice_rect_is_empty(&ssd->dirty)) { |
229 | return; | |
230 | }; | |
a7310dd3 GH |
231 | |
232 | if (ssd->conv == NULL) { | |
233 | PixelFormat dst = qemu_default_pixelformat(32); | |
234 | ssd->conv = qemu_pf_conv_get(&dst, &ssd->ds->surface->pf); | |
235 | assert(ssd->conv); | |
236 | } | |
237 | if (ssd->ds_mirror == NULL) { | |
238 | int size = ds_get_height(ssd->ds) * ds_get_linesize(ssd->ds); | |
239 | ssd->ds_mirror = g_malloc0(size); | |
240 | } | |
241 | ||
b021bd29 GH |
242 | for (blk = 0; blk < blocks; blk++) { |
243 | dirty_top[blk] = -1; | |
244 | } | |
245 | ||
246 | guest = ds_get_data(ssd->ds); | |
247 | mirror = ssd->ds_mirror; | |
248 | for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) { | |
249 | yoff = y * ds_get_linesize(ssd->ds); | |
250 | for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) { | |
251 | xoff = x * bpp; | |
252 | blk = x / blksize; | |
253 | bw = MIN(blksize, ssd->dirty.right - x); | |
254 | if (memcmp(guest + yoff + xoff, | |
255 | mirror + yoff + xoff, | |
256 | bw * bpp) == 0) { | |
257 | if (dirty_top[blk] != -1) { | |
258 | QXLRect update = { | |
259 | .top = dirty_top[blk], | |
260 | .bottom = y, | |
261 | .left = x, | |
262 | .right = x + bw, | |
263 | }; | |
264 | qemu_spice_create_one_update(ssd, &update); | |
265 | dirty_top[blk] = -1; | |
266 | } | |
267 | } else { | |
268 | if (dirty_top[blk] == -1) { | |
269 | dirty_top[blk] = y; | |
270 | } | |
271 | } | |
272 | } | |
273 | } | |
274 | ||
275 | for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) { | |
276 | blk = x / blksize; | |
277 | bw = MIN(blksize, ssd->dirty.right - x); | |
278 | if (dirty_top[blk] != -1) { | |
279 | QXLRect update = { | |
280 | .top = dirty_top[blk], | |
281 | .bottom = ssd->dirty.bottom, | |
282 | .left = x, | |
283 | .right = x + bw, | |
284 | }; | |
285 | qemu_spice_create_one_update(ssd, &update); | |
286 | dirty_top[blk] = -1; | |
287 | } | |
288 | } | |
289 | ||
c60319a3 GH |
290 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
291 | } | |
292 | ||
a3e22260 | 293 | /* |
4580c490 | 294 | * Called from spice server thread context (via interface_release_resource) |
a3e22260 | 295 | * We do *not* hold the global qemu mutex here, so extra care is needed |
5cbdb3a3 | 296 | * when calling qemu functions. QEMU interfaces used: |
7267c094 | 297 | * - g_free (underlying glibc free is re-entrant). |
a3e22260 GH |
298 | */ |
299 | void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update) | |
300 | { | |
7267c094 AL |
301 | g_free(update->bitmap); |
302 | g_free(update); | |
a3e22260 GH |
303 | } |
304 | ||
305 | void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd) | |
306 | { | |
307 | QXLDevMemSlot memslot; | |
308 | ||
309 | dprint(1, "%s:\n", __FUNCTION__); | |
310 | ||
311 | memset(&memslot, 0, sizeof(memslot)); | |
312 | memslot.slot_group_id = MEMSLOT_GROUP_HOST; | |
313 | memslot.virt_end = ~0; | |
5ff4e36c | 314 | qemu_spice_add_memslot(ssd, &memslot, QXL_SYNC); |
a3e22260 GH |
315 | } |
316 | ||
317 | void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) | |
318 | { | |
319 | QXLDevSurfaceCreate surface; | |
320 | ||
160c31f7 AL |
321 | memset(&surface, 0, sizeof(surface)); |
322 | ||
a3e22260 GH |
323 | dprint(1, "%s: %dx%d\n", __FUNCTION__, |
324 | ds_get_width(ssd->ds), ds_get_height(ssd->ds)); | |
325 | ||
326 | surface.format = SPICE_SURFACE_FMT_32_xRGB; | |
327 | surface.width = ds_get_width(ssd->ds); | |
328 | surface.height = ds_get_height(ssd->ds); | |
329 | surface.stride = -surface.width * 4; | |
869564a9 | 330 | surface.mouse_mode = true; |
a3e22260 GH |
331 | surface.flags = 0; |
332 | surface.type = 0; | |
a13ccc99 | 333 | surface.mem = (uintptr_t)ssd->buf; |
a3e22260 | 334 | surface.group_id = MEMSLOT_GROUP_HOST; |
7466bc49 | 335 | |
5ff4e36c | 336 | qemu_spice_create_primary_surface(ssd, 0, &surface, QXL_SYNC); |
a3e22260 GH |
337 | } |
338 | ||
339 | void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd) | |
340 | { | |
341 | dprint(1, "%s:\n", __FUNCTION__); | |
342 | ||
5ff4e36c | 343 | qemu_spice_destroy_primary_surface(ssd, 0, QXL_SYNC); |
a3e22260 GH |
344 | } |
345 | ||
a963f876 GH |
346 | void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds) |
347 | { | |
348 | ssd->ds = ds; | |
349 | qemu_mutex_init(&ssd->lock); | |
b1af98ba | 350 | QTAILQ_INIT(&ssd->updates); |
a963f876 GH |
351 | ssd->mouse_x = -1; |
352 | ssd->mouse_y = -1; | |
ddd8fdc7 GH |
353 | if (ssd->num_surfaces == 0) { |
354 | ssd->num_surfaces = 1024; | |
355 | } | |
a963f876 | 356 | ssd->bufsize = (16 * 1024 * 1024); |
7267c094 | 357 | ssd->buf = g_malloc(ssd->bufsize); |
a963f876 GH |
358 | } |
359 | ||
a3e22260 GH |
360 | /* display listener callbacks */ |
361 | ||
362 | void qemu_spice_display_update(SimpleSpiceDisplay *ssd, | |
363 | int x, int y, int w, int h) | |
364 | { | |
365 | QXLRect update_area; | |
366 | ||
367 | dprint(2, "%s: x %d y %d w %d h %d\n", __FUNCTION__, x, y, w, h); | |
368 | update_area.left = x, | |
369 | update_area.right = x + w; | |
370 | update_area.top = y; | |
371 | update_area.bottom = y + h; | |
372 | ||
a3e22260 GH |
373 | if (qemu_spice_rect_is_empty(&ssd->dirty)) { |
374 | ssd->notify++; | |
375 | } | |
376 | qemu_spice_rect_union(&ssd->dirty, &update_area); | |
a3e22260 GH |
377 | } |
378 | ||
379 | void qemu_spice_display_resize(SimpleSpiceDisplay *ssd) | |
380 | { | |
b1af98ba GH |
381 | SimpleSpiceUpdate *update; |
382 | ||
a3e22260 GH |
383 | dprint(1, "%s:\n", __FUNCTION__); |
384 | ||
a3e22260 GH |
385 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
386 | qemu_pf_conv_put(ssd->conv); | |
387 | ssd->conv = NULL; | |
a7310dd3 GH |
388 | g_free(ssd->ds_mirror); |
389 | ssd->ds_mirror = NULL; | |
a3e22260 | 390 | |
e0c64d08 | 391 | qemu_mutex_lock(&ssd->lock); |
b1af98ba GH |
392 | while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) { |
393 | QTAILQ_REMOVE(&ssd->updates, update, next); | |
394 | qemu_spice_destroy_update(ssd, update); | |
e0c64d08 GH |
395 | } |
396 | qemu_mutex_unlock(&ssd->lock); | |
a3e22260 GH |
397 | qemu_spice_destroy_host_primary(ssd); |
398 | qemu_spice_create_host_primary(ssd); | |
399 | ||
a3e22260 GH |
400 | memset(&ssd->dirty, 0, sizeof(ssd->dirty)); |
401 | ssd->notify++; | |
a3e22260 GH |
402 | } |
403 | ||
bb5a8cd5 | 404 | void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd) |
a3e22260 | 405 | { |
07536094 | 406 | if (ssd->cursor) { |
bf2fde70 | 407 | dpy_cursor_define(ssd->ds, ssd->cursor); |
07536094 GH |
408 | cursor_put(ssd->cursor); |
409 | ssd->cursor = NULL; | |
410 | } | |
411 | if (ssd->mouse_x != -1 && ssd->mouse_y != -1) { | |
bf2fde70 | 412 | dpy_mouse_set(ssd->ds, ssd->mouse_x, ssd->mouse_y, 1); |
07536094 GH |
413 | ssd->mouse_x = -1; |
414 | ssd->mouse_y = -1; | |
415 | } | |
bb5a8cd5 AL |
416 | } |
417 | ||
418 | void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) | |
419 | { | |
420 | dprint(3, "%s:\n", __func__); | |
421 | vga_hw_update(); | |
422 | ||
423 | qemu_mutex_lock(&ssd->lock); | |
b1af98ba GH |
424 | if (QTAILQ_EMPTY(&ssd->updates)) { |
425 | qemu_spice_create_update(ssd); | |
bb5a8cd5 AL |
426 | ssd->notify++; |
427 | } | |
428 | qemu_spice_cursor_refresh_unlocked(ssd); | |
e0c64d08 GH |
429 | qemu_mutex_unlock(&ssd->lock); |
430 | ||
a3e22260 GH |
431 | if (ssd->notify) { |
432 | ssd->notify = 0; | |
5c59d118 | 433 | qemu_spice_wakeup(ssd); |
a3e22260 GH |
434 | dprint(2, "%s: notify\n", __FUNCTION__); |
435 | } | |
436 | } | |
437 | ||
438 | /* spice display interface callbacks */ | |
439 | ||
440 | static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker) | |
441 | { | |
442 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
443 | ||
444 | dprint(1, "%s:\n", __FUNCTION__); | |
445 | ssd->worker = qxl_worker; | |
446 | } | |
447 | ||
448 | static void interface_set_compression_level(QXLInstance *sin, int level) | |
449 | { | |
450 | dprint(1, "%s:\n", __FUNCTION__); | |
451 | /* nothing to do */ | |
452 | } | |
453 | ||
454 | static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time) | |
455 | { | |
456 | dprint(3, "%s:\n", __FUNCTION__); | |
457 | /* nothing to do */ | |
458 | } | |
459 | ||
460 | static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info) | |
461 | { | |
462 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
463 | ||
464 | info->memslot_gen_bits = MEMSLOT_GENERATION_BITS; | |
465 | info->memslot_id_bits = MEMSLOT_SLOT_BITS; | |
466 | info->num_memslots = NUM_MEMSLOTS; | |
467 | info->num_memslots_groups = NUM_MEMSLOTS_GROUPS; | |
468 | info->internal_groupslot_id = 0; | |
469 | info->qxl_ram_size = ssd->bufsize; | |
ddd8fdc7 | 470 | info->n_surfaces = ssd->num_surfaces; |
a3e22260 GH |
471 | } |
472 | ||
473 | static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext) | |
474 | { | |
475 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
476 | SimpleSpiceUpdate *update; | |
e0c64d08 | 477 | int ret = false; |
a3e22260 GH |
478 | |
479 | dprint(3, "%s:\n", __FUNCTION__); | |
e0c64d08 GH |
480 | |
481 | qemu_mutex_lock(&ssd->lock); | |
b1af98ba GH |
482 | update = QTAILQ_FIRST(&ssd->updates); |
483 | if (update != NULL) { | |
484 | QTAILQ_REMOVE(&ssd->updates, update, next); | |
e0c64d08 GH |
485 | *ext = update->ext; |
486 | ret = true; | |
a3e22260 | 487 | } |
e0c64d08 GH |
488 | qemu_mutex_unlock(&ssd->lock); |
489 | ||
490 | return ret; | |
a3e22260 GH |
491 | } |
492 | ||
493 | static int interface_req_cmd_notification(QXLInstance *sin) | |
494 | { | |
495 | dprint(1, "%s:\n", __FUNCTION__); | |
496 | return 1; | |
497 | } | |
498 | ||
499 | static void interface_release_resource(QXLInstance *sin, | |
500 | struct QXLReleaseInfoExt ext) | |
501 | { | |
502 | SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); | |
503 | uintptr_t id; | |
504 | ||
505 | dprint(2, "%s:\n", __FUNCTION__); | |
506 | id = ext.info->id; | |
507 | qemu_spice_destroy_update(ssd, (void*)id); | |
508 | } | |
509 | ||
510 | static int interface_get_cursor_command(QXLInstance *sin, struct QXLCommandExt *ext) | |
511 | { | |
512 | dprint(3, "%s:\n", __FUNCTION__); | |
513 | return false; | |
514 | } | |
515 | ||
516 | static int interface_req_cursor_notification(QXLInstance *sin) | |
517 | { | |
518 | dprint(1, "%s:\n", __FUNCTION__); | |
519 | return 1; | |
520 | } | |
521 | ||
522 | static void interface_notify_update(QXLInstance *sin, uint32_t update_id) | |
523 | { | |
524 | fprintf(stderr, "%s: abort()\n", __FUNCTION__); | |
525 | abort(); | |
526 | } | |
527 | ||
528 | static int interface_flush_resources(QXLInstance *sin) | |
529 | { | |
530 | fprintf(stderr, "%s: abort()\n", __FUNCTION__); | |
531 | abort(); | |
532 | return 0; | |
533 | } | |
534 | ||
535 | static const QXLInterface dpy_interface = { | |
536 | .base.type = SPICE_INTERFACE_QXL, | |
537 | .base.description = "qemu simple display", | |
538 | .base.major_version = SPICE_INTERFACE_QXL_MAJOR, | |
539 | .base.minor_version = SPICE_INTERFACE_QXL_MINOR, | |
540 | ||
541 | .attache_worker = interface_attach_worker, | |
542 | .set_compression_level = interface_set_compression_level, | |
543 | .set_mm_time = interface_set_mm_time, | |
544 | .get_init_info = interface_get_init_info, | |
545 | ||
546 | /* the callbacks below are called from spice server thread context */ | |
547 | .get_command = interface_get_command, | |
548 | .req_cmd_notification = interface_req_cmd_notification, | |
549 | .release_resource = interface_release_resource, | |
550 | .get_cursor_command = interface_get_cursor_command, | |
551 | .req_cursor_notification = interface_req_cursor_notification, | |
552 | .notify_update = interface_notify_update, | |
553 | .flush_resources = interface_flush_resources, | |
554 | }; | |
555 | ||
556 | static SimpleSpiceDisplay sdpy; | |
557 | ||
558 | static void display_update(struct DisplayState *ds, int x, int y, int w, int h) | |
559 | { | |
560 | qemu_spice_display_update(&sdpy, x, y, w, h); | |
561 | } | |
562 | ||
563 | static void display_resize(struct DisplayState *ds) | |
564 | { | |
565 | qemu_spice_display_resize(&sdpy); | |
566 | } | |
567 | ||
568 | static void display_refresh(struct DisplayState *ds) | |
569 | { | |
570 | qemu_spice_display_refresh(&sdpy); | |
571 | } | |
572 | ||
573 | static DisplayChangeListener display_listener = { | |
a93a4a22 GH |
574 | .dpy_gfx_update = display_update, |
575 | .dpy_gfx_resize = display_resize, | |
a3e22260 GH |
576 | .dpy_refresh = display_refresh, |
577 | }; | |
578 | ||
579 | void qemu_spice_display_init(DisplayState *ds) | |
580 | { | |
581 | assert(sdpy.ds == NULL); | |
a963f876 | 582 | qemu_spice_display_init_common(&sdpy, ds); |
a3e22260 GH |
583 | register_displaychangelistener(ds, &display_listener); |
584 | ||
585 | sdpy.qxl.base.sif = &dpy_interface.base; | |
586 | qemu_spice_add_interface(&sdpy.qxl.base); | |
587 | assert(sdpy.worker); | |
588 | ||
a3e22260 GH |
589 | qemu_spice_create_host_memslot(&sdpy); |
590 | qemu_spice_create_host_primary(&sdpy); | |
591 | } |