spice-display.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. #include "qemu-common.h"
  18. #include "ui/qemu-spice.h"
  19. #include "qemu/timer.h"
  20. #include "qemu/queue.h"
  21. #include "monitor/monitor.h"
  22. #include "ui/console.h"
  23. #include "sysemu/sysemu.h"
  24. #include "trace.h"
  25. #include "ui/spice-display.h"
  26. static int debug = 0;
  27. static void GCC_FMT_ATTR(2, 3) dprint(int level, const char *fmt, ...)
  28. {
  29. va_list args;
  30. if (level <= debug) {
  31. va_start(args, fmt);
  32. vfprintf(stderr, fmt, args);
  33. va_end(args);
  34. }
  35. }
  36. int qemu_spice_rect_is_empty(const QXLRect* r)
  37. {
  38. return r->top == r->bottom || r->left == r->right;
  39. }
  40. void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r)
  41. {
  42. if (qemu_spice_rect_is_empty(r)) {
  43. return;
  44. }
  45. if (qemu_spice_rect_is_empty(dest)) {
  46. *dest = *r;
  47. return;
  48. }
  49. dest->top = MIN(dest->top, r->top);
  50. dest->left = MIN(dest->left, r->left);
  51. dest->bottom = MAX(dest->bottom, r->bottom);
  52. dest->right = MAX(dest->right, r->right);
  53. }
  54. QXLCookie *qxl_cookie_new(int type, uint64_t io)
  55. {
  56. QXLCookie *cookie;
  57. cookie = g_malloc0(sizeof(*cookie));
  58. cookie->type = type;
  59. cookie->io = io;
  60. return cookie;
  61. }
  62. void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
  63. qxl_async_io async)
  64. {
  65. trace_qemu_spice_add_memslot(ssd->qxl.id, memslot->slot_id,
  66. memslot->virt_start, memslot->virt_end,
  67. async);
  68. if (async != QXL_SYNC) {
  69. spice_qxl_add_memslot_async(&ssd->qxl, memslot,
  70. (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
  71. QXL_IO_MEMSLOT_ADD_ASYNC));
  72. } else {
  73. spice_qxl_add_memslot(&ssd->qxl, memslot);
  74. }
  75. }
  76. void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, uint32_t sid)
  77. {
  78. trace_qemu_spice_del_memslot(ssd->qxl.id, gid, sid);
  79. spice_qxl_del_memslot(&ssd->qxl, gid, sid);
  80. }
  81. void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
  82. QXLDevSurfaceCreate *surface,
  83. qxl_async_io async)
  84. {
  85. trace_qemu_spice_create_primary_surface(ssd->qxl.id, id, surface, async);
  86. if (async != QXL_SYNC) {
  87. spice_qxl_create_primary_surface_async(&ssd->qxl, id, surface,
  88. (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
  89. QXL_IO_CREATE_PRIMARY_ASYNC));
  90. } else {
  91. spice_qxl_create_primary_surface(&ssd->qxl, id, surface);
  92. }
  93. }
  94. void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
  95. uint32_t id, qxl_async_io async)
  96. {
  97. trace_qemu_spice_destroy_primary_surface(ssd->qxl.id, id, async);
  98. if (async != QXL_SYNC) {
  99. spice_qxl_destroy_primary_surface_async(&ssd->qxl, id,
  100. (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
  101. QXL_IO_DESTROY_PRIMARY_ASYNC));
  102. } else {
  103. spice_qxl_destroy_primary_surface(&ssd->qxl, id);
  104. }
  105. }
  106. void qemu_spice_wakeup(SimpleSpiceDisplay *ssd)
  107. {
  108. trace_qemu_spice_wakeup(ssd->qxl.id);
  109. spice_qxl_wakeup(&ssd->qxl);
  110. }
  111. static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
  112. QXLRect *rect)
  113. {
  114. SimpleSpiceUpdate *update;
  115. QXLDrawable *drawable;
  116. QXLImage *image;
  117. QXLCommand *cmd;
  118. int bw, bh;
  119. struct timespec time_space;
  120. pixman_image_t *dest;
  121. trace_qemu_spice_create_update(
  122. rect->left, rect->right,
  123. rect->top, rect->bottom);
  124. update = g_malloc0(sizeof(*update));
  125. drawable = &update->drawable;
  126. image = &update->image;
  127. cmd = &update->ext.cmd;
  128. bw = rect->right - rect->left;
  129. bh = rect->bottom - rect->top;
  130. update->bitmap = g_malloc(bw * bh * 4);
  131. drawable->bbox = *rect;
  132. drawable->clip.type = SPICE_CLIP_TYPE_NONE;
  133. drawable->effect = QXL_EFFECT_OPAQUE;
  134. drawable->release_info.id = (uintptr_t)update;
  135. drawable->type = QXL_DRAW_COPY;
  136. drawable->surfaces_dest[0] = -1;
  137. drawable->surfaces_dest[1] = -1;
  138. drawable->surfaces_dest[2] = -1;
  139. clock_gettime(CLOCK_MONOTONIC, &time_space);
  140. /* time in milliseconds from epoch. */
  141. drawable->mm_time = time_space.tv_sec * 1000
  142. + time_space.tv_nsec / 1000 / 1000;
  143. drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
  144. drawable->u.copy.src_bitmap = (uintptr_t)image;
  145. drawable->u.copy.src_area.right = bw;
  146. drawable->u.copy.src_area.bottom = bh;
  147. QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, ssd->unique++);
  148. image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
  149. image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;
  150. image->bitmap.stride = bw * 4;
  151. image->descriptor.width = image->bitmap.x = bw;
  152. image->descriptor.height = image->bitmap.y = bh;
  153. image->bitmap.data = (uintptr_t)(update->bitmap);
  154. image->bitmap.palette = 0;
  155. image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
  156. dest = pixman_image_create_bits(PIXMAN_x8r8g8b8, bw, bh,
  157. (void *)update->bitmap, bw * 4);
  158. pixman_image_composite(PIXMAN_OP_SRC, ssd->surface, NULL, ssd->mirror,
  159. rect->left, rect->top, 0, 0,
  160. rect->left, rect->top, bw, bh);
  161. pixman_image_composite(PIXMAN_OP_SRC, ssd->mirror, NULL, dest,
  162. rect->left, rect->top, 0, 0,
  163. 0, 0, bw, bh);
  164. pixman_image_unref(dest);
  165. cmd->type = QXL_CMD_DRAW;
  166. cmd->data = (uintptr_t)drawable;
  167. QTAILQ_INSERT_TAIL(&ssd->updates, update, next);
  168. }
  169. static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
  170. {
  171. static const int blksize = 32;
  172. int blocks = (surface_width(ssd->ds) + blksize - 1) / blksize;
  173. int dirty_top[blocks];
  174. int y, yoff, x, xoff, blk, bw;
  175. int bpp = surface_bytes_per_pixel(ssd->ds);
  176. uint8_t *guest, *mirror;
  177. if (qemu_spice_rect_is_empty(&ssd->dirty)) {
  178. return;
  179. };
  180. if (ssd->surface == NULL) {
  181. ssd->surface = pixman_image_ref(ssd->ds->image);
  182. ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format,
  183. ssd->ds->image);
  184. }
  185. for (blk = 0; blk < blocks; blk++) {
  186. dirty_top[blk] = -1;
  187. }
  188. guest = surface_data(ssd->ds);
  189. mirror = (void *)pixman_image_get_data(ssd->mirror);
  190. for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) {
  191. yoff = y * surface_stride(ssd->ds);
  192. for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
  193. xoff = x * bpp;
  194. blk = x / blksize;
  195. bw = MIN(blksize, ssd->dirty.right - x);
  196. if (memcmp(guest + yoff + xoff,
  197. mirror + yoff + xoff,
  198. bw * bpp) == 0) {
  199. if (dirty_top[blk] != -1) {
  200. QXLRect update = {
  201. .top = dirty_top[blk],
  202. .bottom = y,
  203. .left = x,
  204. .right = x + bw,
  205. };
  206. qemu_spice_create_one_update(ssd, &update);
  207. dirty_top[blk] = -1;
  208. }
  209. } else {
  210. if (dirty_top[blk] == -1) {
  211. dirty_top[blk] = y;
  212. }
  213. }
  214. }
  215. }
  216. for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
  217. blk = x / blksize;
  218. bw = MIN(blksize, ssd->dirty.right - x);
  219. if (dirty_top[blk] != -1) {
  220. QXLRect update = {
  221. .top = dirty_top[blk],
  222. .bottom = ssd->dirty.bottom,
  223. .left = x,
  224. .right = x + bw,
  225. };
  226. qemu_spice_create_one_update(ssd, &update);
  227. dirty_top[blk] = -1;
  228. }
  229. }
  230. memset(&ssd->dirty, 0, sizeof(ssd->dirty));
  231. }
  232. /*
  233. * Called from spice server thread context (via interface_release_resource)
  234. * We do *not* hold the global qemu mutex here, so extra care is needed
  235. * when calling qemu functions. QEMU interfaces used:
  236. * - g_free (underlying glibc free is re-entrant).
  237. */
  238. void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update)
  239. {
  240. g_free(update->bitmap);
  241. g_free(update);
  242. }
  243. void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd)
  244. {
  245. QXLDevMemSlot memslot;
  246. dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
  247. memset(&memslot, 0, sizeof(memslot));
  248. memslot.slot_group_id = MEMSLOT_GROUP_HOST;
  249. memslot.virt_end = ~0;
  250. qemu_spice_add_memslot(ssd, &memslot, QXL_SYNC);
  251. }
  252. void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd)
  253. {
  254. QXLDevSurfaceCreate surface;
  255. memset(&surface, 0, sizeof(surface));
  256. dprint(1, "%s/%d: %dx%d\n", __func__, ssd->qxl.id,
  257. surface_width(ssd->ds), surface_height(ssd->ds));
  258. surface.format = SPICE_SURFACE_FMT_32_xRGB;
  259. surface.width = surface_width(ssd->ds);
  260. surface.height = surface_height(ssd->ds);
  261. surface.stride = -surface.width * 4;
  262. surface.mouse_mode = true;
  263. surface.flags = 0;
  264. surface.type = 0;
  265. surface.mem = (uintptr_t)ssd->buf;
  266. surface.group_id = MEMSLOT_GROUP_HOST;
  267. qemu_spice_create_primary_surface(ssd, 0, &surface, QXL_SYNC);
  268. }
  269. void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd)
  270. {
  271. dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
  272. qemu_spice_destroy_primary_surface(ssd, 0, QXL_SYNC);
  273. }
  274. void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd)
  275. {
  276. qemu_mutex_init(&ssd->lock);
  277. QTAILQ_INIT(&ssd->updates);
  278. ssd->mouse_x = -1;
  279. ssd->mouse_y = -1;
  280. if (ssd->num_surfaces == 0) {
  281. ssd->num_surfaces = 1024;
  282. }
  283. ssd->bufsize = (16 * 1024 * 1024);
  284. ssd->buf = g_malloc(ssd->bufsize);
  285. }
  286. /* display listener callbacks */
  287. void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
  288. int x, int y, int w, int h)
  289. {
  290. QXLRect update_area;
  291. dprint(2, "%s/%d: x %d y %d w %d h %d\n", __func__,
  292. ssd->qxl.id, x, y, w, h);
  293. update_area.left = x,
  294. update_area.right = x + w;
  295. update_area.top = y;
  296. update_area.bottom = y + h;
  297. if (qemu_spice_rect_is_empty(&ssd->dirty)) {
  298. ssd->notify++;
  299. }
  300. qemu_spice_rect_union(&ssd->dirty, &update_area);
  301. }
  302. void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
  303. DisplaySurface *surface)
  304. {
  305. SimpleSpiceUpdate *update;
  306. bool need_destroy;
  307. dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
  308. memset(&ssd->dirty, 0, sizeof(ssd->dirty));
  309. if (ssd->surface) {
  310. pixman_image_unref(ssd->surface);
  311. ssd->surface = NULL;
  312. pixman_image_unref(ssd->mirror);
  313. ssd->mirror = NULL;
  314. }
  315. qemu_mutex_lock(&ssd->lock);
  316. need_destroy = (ssd->ds != NULL);
  317. ssd->ds = surface;
  318. while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {
  319. QTAILQ_REMOVE(&ssd->updates, update, next);
  320. qemu_spice_destroy_update(ssd, update);
  321. }
  322. qemu_mutex_unlock(&ssd->lock);
  323. if (need_destroy) {
  324. qemu_spice_destroy_host_primary(ssd);
  325. }
  326. if (ssd->ds) {
  327. qemu_spice_create_host_primary(ssd);
  328. }
  329. memset(&ssd->dirty, 0, sizeof(ssd->dirty));
  330. ssd->notify++;
  331. }
  332. void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
  333. {
  334. if (ssd->cursor) {
  335. assert(ssd->dcl.con);
  336. dpy_cursor_define(ssd->dcl.con, ssd->cursor);
  337. cursor_put(ssd->cursor);
  338. ssd->cursor = NULL;
  339. }
  340. if (ssd->mouse_x != -1 && ssd->mouse_y != -1) {
  341. assert(ssd->dcl.con);
  342. dpy_mouse_set(ssd->dcl.con, ssd->mouse_x, ssd->mouse_y, 1);
  343. ssd->mouse_x = -1;
  344. ssd->mouse_y = -1;
  345. }
  346. }
  347. void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
  348. {
  349. dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
  350. graphic_hw_update(ssd->dcl.con);
  351. qemu_mutex_lock(&ssd->lock);
  352. if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) {
  353. qemu_spice_create_update(ssd);
  354. ssd->notify++;
  355. }
  356. qemu_spice_cursor_refresh_unlocked(ssd);
  357. qemu_mutex_unlock(&ssd->lock);
  358. if (ssd->notify) {
  359. ssd->notify = 0;
  360. qemu_spice_wakeup(ssd);
  361. dprint(2, "%s/%d: notify\n", __func__, ssd->qxl.id);
  362. }
  363. }
  364. /* spice display interface callbacks */
  365. static void interface_attach_worker(QXLInstance *sin, QXLWorker *qxl_worker)
  366. {
  367. SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
  368. dprint(1, "%s/%d:\n", __func__, ssd->qxl.id);
  369. ssd->worker = qxl_worker;
  370. }
  371. static void interface_set_compression_level(QXLInstance *sin, int level)
  372. {
  373. dprint(1, "%s/%d:\n", __func__, sin->id);
  374. /* nothing to do */
  375. }
  376. static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time)
  377. {
  378. dprint(3, "%s/%d:\n", __func__, sin->id);
  379. /* nothing to do */
  380. }
  381. static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info)
  382. {
  383. SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
  384. info->memslot_gen_bits = MEMSLOT_GENERATION_BITS;
  385. info->memslot_id_bits = MEMSLOT_SLOT_BITS;
  386. info->num_memslots = NUM_MEMSLOTS;
  387. info->num_memslots_groups = NUM_MEMSLOTS_GROUPS;
  388. info->internal_groupslot_id = 0;
  389. info->qxl_ram_size = ssd->bufsize;
  390. info->n_surfaces = ssd->num_surfaces;
  391. }
  392. static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)
  393. {
  394. SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
  395. SimpleSpiceUpdate *update;
  396. int ret = false;
  397. dprint(3, "%s/%d:\n", __func__, ssd->qxl.id);
  398. qemu_mutex_lock(&ssd->lock);
  399. update = QTAILQ_FIRST(&ssd->updates);
  400. if (update != NULL) {
  401. QTAILQ_REMOVE(&ssd->updates, update, next);
  402. *ext = update->ext;
  403. ret = true;
  404. }
  405. qemu_mutex_unlock(&ssd->lock);
  406. return ret;
  407. }
  408. static int interface_req_cmd_notification(QXLInstance *sin)
  409. {
  410. dprint(1, "%s/%d:\n", __func__, sin->id);
  411. return 1;
  412. }
  413. static void interface_release_resource(QXLInstance *sin,
  414. struct QXLReleaseInfoExt ext)
  415. {
  416. SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
  417. uintptr_t id;
  418. dprint(2, "%s/%d:\n", __func__, ssd->qxl.id);
  419. id = ext.info->id;
  420. qemu_spice_destroy_update(ssd, (void*)id);
  421. }
  422. static int interface_get_cursor_command(QXLInstance *sin, struct QXLCommandExt *ext)
  423. {
  424. dprint(3, "%s:\n", __FUNCTION__);
  425. return false;
  426. }
  427. static int interface_req_cursor_notification(QXLInstance *sin)
  428. {
  429. dprint(1, "%s:\n", __FUNCTION__);
  430. return 1;
  431. }
  432. static void interface_notify_update(QXLInstance *sin, uint32_t update_id)
  433. {
  434. fprintf(stderr, "%s: abort()\n", __FUNCTION__);
  435. abort();
  436. }
  437. static int interface_flush_resources(QXLInstance *sin)
  438. {
  439. fprintf(stderr, "%s: abort()\n", __FUNCTION__);
  440. abort();
  441. return 0;
  442. }
  443. static void interface_update_area_complete(QXLInstance *sin,
  444. uint32_t surface_id,
  445. QXLRect *dirty, uint32_t num_updated_rects)
  446. {
  447. /* should never be called, used in qxl native mode only */
  448. fprintf(stderr, "%s: abort()\n", __func__);
  449. abort();
  450. }
  451. /* called from spice server thread context only */
  452. static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
  453. {
  454. /* should never be called, used in qxl native mode only */
  455. fprintf(stderr, "%s: abort()\n", __func__);
  456. abort();
  457. }
  458. static void interface_set_client_capabilities(QXLInstance *sin,
  459. uint8_t client_present,
  460. uint8_t caps[58])
  461. {
  462. dprint(3, "%s:\n", __func__);
  463. }
  464. static int interface_client_monitors_config(QXLInstance *sin,
  465. VDAgentMonitorsConfig *mc)
  466. {
  467. SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl);
  468. QemuUIInfo info;
  469. int rc;
  470. if (!mc) {
  471. return 1;
  472. }
  473. /*
  474. * FIXME: multihead is tricky due to the way
  475. * spice has multihead implemented.
  476. */
  477. memset(&info, 0, sizeof(info));
  478. if (mc->num_of_monitors > 0) {
  479. info.width = mc->monitors[0].width;
  480. info.height = mc->monitors[0].height;
  481. }
  482. rc = dpy_set_ui_info(ssd->dcl.con, &info);
  483. dprint(1, "%s/%d: size %dx%d, rc %d <--- ==========================\n",
  484. __func__, ssd->qxl.id, info.width, info.height, rc);
  485. if (rc != 0) {
  486. return 0; /* == not supported by guest */
  487. } else {
  488. return 1;
  489. }
  490. }
  491. static const QXLInterface dpy_interface = {
  492. .base.type = SPICE_INTERFACE_QXL,
  493. .base.description = "qemu simple display",
  494. .base.major_version = SPICE_INTERFACE_QXL_MAJOR,
  495. .base.minor_version = SPICE_INTERFACE_QXL_MINOR,
  496. .attache_worker = interface_attach_worker,
  497. .set_compression_level = interface_set_compression_level,
  498. .set_mm_time = interface_set_mm_time,
  499. .get_init_info = interface_get_init_info,
  500. /* the callbacks below are called from spice server thread context */
  501. .get_command = interface_get_command,
  502. .req_cmd_notification = interface_req_cmd_notification,
  503. .release_resource = interface_release_resource,
  504. .get_cursor_command = interface_get_cursor_command,
  505. .req_cursor_notification = interface_req_cursor_notification,
  506. .notify_update = interface_notify_update,
  507. .flush_resources = interface_flush_resources,
  508. .async_complete = interface_async_complete,
  509. .update_area_complete = interface_update_area_complete,
  510. .set_client_capabilities = interface_set_client_capabilities,
  511. .client_monitors_config = interface_client_monitors_config,
  512. };
  513. static void display_update(DisplayChangeListener *dcl,
  514. int x, int y, int w, int h)
  515. {
  516. SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
  517. qemu_spice_display_update(ssd, x, y, w, h);
  518. }
  519. static void display_switch(DisplayChangeListener *dcl,
  520. struct DisplaySurface *surface)
  521. {
  522. SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
  523. qemu_spice_display_switch(ssd, surface);
  524. }
  525. static void display_refresh(DisplayChangeListener *dcl)
  526. {
  527. SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
  528. qemu_spice_display_refresh(ssd);
  529. }
  530. static const DisplayChangeListenerOps display_listener_ops = {
  531. .dpy_name = "spice",
  532. .dpy_gfx_update = display_update,
  533. .dpy_gfx_switch = display_switch,
  534. .dpy_refresh = display_refresh,
  535. };
  536. static void qemu_spice_display_init_one(QemuConsole *con)
  537. {
  538. SimpleSpiceDisplay *ssd = g_new0(SimpleSpiceDisplay, 1);
  539. qemu_spice_display_init_common(ssd);
  540. ssd->qxl.base.sif = &dpy_interface.base;
  541. qemu_spice_add_display_interface(&ssd->qxl, con);
  542. assert(ssd->worker);
  543. qemu_spice_create_host_memslot(ssd);
  544. ssd->dcl.ops = &display_listener_ops;
  545. ssd->dcl.con = con;
  546. register_displaychangelistener(&ssd->dcl);
  547. }
  548. void qemu_spice_display_init(void)
  549. {
  550. QemuConsole *con;
  551. int i;
  552. for (i = 0;; i++) {
  553. con = qemu_console_lookup_by_index(i);
  554. if (!con || !qemu_console_is_graphic(con)) {
  555. break;
  556. }
  557. if (qemu_spice_have_display_interface(con)) {
  558. continue;
  559. }
  560. qemu_spice_display_init_one(con);
  561. }
  562. }