1a3e22260SGerd Hoffmann /* 2a3e22260SGerd Hoffmann * Copyright (C) 2010 Red Hat, Inc. 3a3e22260SGerd Hoffmann * 4a3e22260SGerd Hoffmann * This program is free software; you can redistribute it and/or 5a3e22260SGerd Hoffmann * modify it under the terms of the GNU General Public License as 6a3e22260SGerd Hoffmann * published by the Free Software Foundation; either version 2 or 7a3e22260SGerd Hoffmann * (at your option) version 3 of the License. 8a3e22260SGerd Hoffmann * 9a3e22260SGerd Hoffmann * This program is distributed in the hope that it will be useful, 10a3e22260SGerd Hoffmann * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a3e22260SGerd Hoffmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a3e22260SGerd Hoffmann * GNU General Public License for more details. 13a3e22260SGerd Hoffmann * 14a3e22260SGerd Hoffmann * You should have received a copy of the GNU General Public License 15a3e22260SGerd Hoffmann * along with this program; if not, see <http://www.gnu.org/licenses/>. 16a3e22260SGerd Hoffmann */ 17a3e22260SGerd Hoffmann 18a3e22260SGerd Hoffmann #include <spice/ipc_ring.h> 19a3e22260SGerd Hoffmann #include <spice/enums.h> 20a3e22260SGerd Hoffmann #include <spice/qxl_dev.h> 21a3e22260SGerd Hoffmann 221de7afc9SPaolo Bonzini #include "qemu/thread.h" 2328ecbaeeSPaolo Bonzini #include "ui/qemu-pixman.h" 240b087861SPeter Maydell #include "ui/console.h" 259c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 26a3e22260SGerd Hoffmann 27474114b7SGerd Hoffmann #if defined(CONFIG_OPENGL_DMABUF) 28*9f5c6d06SMichal Privoznik # if SPICE_SERVER_VERSION >= 0x000d01 /* release 0.13.1 */ 29474114b7SGerd Hoffmann # define HAVE_SPICE_GL 1 30474114b7SGerd Hoffmann # include "ui/egl-helpers.h" 31474114b7SGerd Hoffmann # include "ui/egl-context.h" 32474114b7SGerd Hoffmann # endif 33474114b7SGerd Hoffmann #endif 34474114b7SGerd Hoffmann 35a3e22260SGerd Hoffmann #define NUM_MEMSLOTS 8 36a3e22260SGerd Hoffmann #define MEMSLOT_GENERATION_BITS 8 37a3e22260SGerd Hoffmann #define MEMSLOT_SLOT_BITS 8 38a3e22260SGerd Hoffmann 39a3e22260SGerd Hoffmann #define MEMSLOT_GROUP_HOST 0 40a3e22260SGerd Hoffmann #define MEMSLOT_GROUP_GUEST 1 41a3e22260SGerd Hoffmann #define NUM_MEMSLOTS_GROUPS 2 42a3e22260SGerd Hoffmann 435ff4e36cSAlon Levy /* 445ff4e36cSAlon Levy * Internal enum to differenciate between options for 455ff4e36cSAlon Levy * io calls that have a sync (old) version and an _async (new) 465ff4e36cSAlon Levy * version: 475ff4e36cSAlon Levy * QXL_SYNC: use the old version 485ff4e36cSAlon Levy * QXL_ASYNC: use the new version and make sure there are no two 495ff4e36cSAlon Levy * happening at the same time. This is used for guest initiated 505ff4e36cSAlon Levy * calls 515ff4e36cSAlon Levy */ 525ff4e36cSAlon Levy typedef enum qxl_async_io { 535ff4e36cSAlon Levy QXL_SYNC, 545ff4e36cSAlon Levy QXL_ASYNC, 555ff4e36cSAlon Levy } qxl_async_io; 565ff4e36cSAlon Levy 572e1a98c9SAlon Levy enum { 582e1a98c9SAlon Levy QXL_COOKIE_TYPE_IO, 5981fb6f15SAlon Levy QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, 60020af1c4SAlon Levy QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG, 61474114b7SGerd Hoffmann QXL_COOKIE_TYPE_GL_DRAW_DONE, 622e1a98c9SAlon Levy }; 632e1a98c9SAlon Levy 642e1a98c9SAlon Levy typedef struct QXLCookie { 652e1a98c9SAlon Levy int type; 662e1a98c9SAlon Levy uint64_t io; 672e1a98c9SAlon Levy union { 682e1a98c9SAlon Levy uint32_t surface_id; 6981fb6f15SAlon Levy QXLRect area; 7081fb6f15SAlon Levy struct { 7181fb6f15SAlon Levy QXLRect area; 7281fb6f15SAlon Levy int redraw; 7381fb6f15SAlon Levy } render; 742e1a98c9SAlon Levy } u; 752e1a98c9SAlon Levy } QXLCookie; 762e1a98c9SAlon Levy 772e1a98c9SAlon Levy QXLCookie *qxl_cookie_new(int type, uint64_t io); 782e1a98c9SAlon Levy 79e0c64d08SGerd Hoffmann typedef struct SimpleSpiceDisplay SimpleSpiceDisplay; 80e0c64d08SGerd Hoffmann typedef struct SimpleSpiceUpdate SimpleSpiceUpdate; 815643fc01SGerd Hoffmann typedef struct SimpleSpiceCursor SimpleSpiceCursor; 82e0c64d08SGerd Hoffmann 83e0c64d08SGerd Hoffmann struct SimpleSpiceDisplay { 8471874c17SGerd Hoffmann DisplaySurface *ds; 857c20b4a3SGerd Hoffmann DisplayChangeListener dcl; 86a3e22260SGerd Hoffmann void *buf; 87a3e22260SGerd Hoffmann int bufsize; 88a3e22260SGerd Hoffmann QXLWorker *worker; 89a3e22260SGerd Hoffmann QXLInstance qxl; 90a3e22260SGerd Hoffmann uint32_t unique; 91d9a86569SGerd Hoffmann pixman_image_t *surface; 92d9a86569SGerd Hoffmann pixman_image_t *mirror; 93ddd8fdc7SGerd Hoffmann int32_t num_surfaces; 94a3e22260SGerd Hoffmann 95a3e22260SGerd Hoffmann QXLRect dirty; 96a3e22260SGerd Hoffmann int notify; 97a3e22260SGerd Hoffmann 98e0c64d08SGerd Hoffmann /* 99e0c64d08SGerd Hoffmann * All struct members below this comment can be accessed from 100e0c64d08SGerd Hoffmann * both spice server and qemu (iothread) context and any access 101e0c64d08SGerd Hoffmann * to them must be protected by the lock. 102e0c64d08SGerd Hoffmann */ 103e0c64d08SGerd Hoffmann QemuMutex lock; 104b1af98baSGerd Hoffmann QTAILQ_HEAD(, SimpleSpiceUpdate) updates; 1055643fc01SGerd Hoffmann 1065643fc01SGerd Hoffmann /* cursor (without qxl): displaychangelistener -> spice server */ 1075643fc01SGerd Hoffmann SimpleSpiceCursor *ptr_define; 1085643fc01SGerd Hoffmann SimpleSpiceCursor *ptr_move; 109dc8dceeeSMarc-André Lureau int16_t ptr_x, ptr_y; 110dc8dceeeSMarc-André Lureau int16_t hot_x, hot_y; 1115643fc01SGerd Hoffmann 1125643fc01SGerd Hoffmann /* cursor (with qxl): qxl local renderer -> displaychangelistener */ 11307536094SGerd Hoffmann QEMUCursor *cursor; 11407536094SGerd Hoffmann int mouse_x, mouse_y; 1150b2824e5SGerd Hoffmann QEMUBH *cursor_bh; 116474114b7SGerd Hoffmann 117474114b7SGerd Hoffmann #ifdef HAVE_SPICE_GL 118474114b7SGerd Hoffmann /* opengl rendering */ 119474114b7SGerd Hoffmann QEMUBH *gl_unblock_bh; 1208e388e90SGerd Hoffmann QEMUTimer *gl_unblock_timer; 121474114b7SGerd Hoffmann int dmabuf_fd; 122474114b7SGerd Hoffmann #endif 123e0c64d08SGerd Hoffmann }; 124e0c64d08SGerd Hoffmann 125e0c64d08SGerd Hoffmann struct SimpleSpiceUpdate { 126a3e22260SGerd Hoffmann QXLDrawable drawable; 127a3e22260SGerd Hoffmann QXLImage image; 128a3e22260SGerd Hoffmann QXLCommandExt ext; 129a3e22260SGerd Hoffmann uint8_t *bitmap; 130b1af98baSGerd Hoffmann QTAILQ_ENTRY(SimpleSpiceUpdate) next; 131e0c64d08SGerd Hoffmann }; 132a3e22260SGerd Hoffmann 1335643fc01SGerd Hoffmann struct SimpleSpiceCursor { 1345643fc01SGerd Hoffmann QXLCursorCmd cmd; 1355643fc01SGerd Hoffmann QXLCommandExt ext; 1365643fc01SGerd Hoffmann QXLCursor cursor; 1375643fc01SGerd Hoffmann }; 1385643fc01SGerd Hoffmann 139a3e22260SGerd Hoffmann int qemu_spice_rect_is_empty(const QXLRect* r); 140a3e22260SGerd Hoffmann void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r); 141a3e22260SGerd Hoffmann 142a3e22260SGerd Hoffmann void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update); 143a3e22260SGerd Hoffmann void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd); 144a3e22260SGerd Hoffmann void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd); 145a3e22260SGerd Hoffmann void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd); 1461dfb4dd9SLuiz Capitulino void qemu_spice_vm_change_state_handler(void *opaque, int running, 1471dfb4dd9SLuiz Capitulino RunState state); 148c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd); 149a3e22260SGerd Hoffmann 150a3e22260SGerd Hoffmann void qemu_spice_display_update(SimpleSpiceDisplay *ssd, 151a3e22260SGerd Hoffmann int x, int y, int w, int h); 152c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, 153c12aeb86SGerd Hoffmann DisplaySurface *surface); 154a3e22260SGerd Hoffmann void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd); 1550b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque); 1565c59d118SGerd Hoffmann 1575ff4e36cSAlon Levy void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot, 1585ff4e36cSAlon Levy qxl_async_io async); 1595c59d118SGerd Hoffmann void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, 1605c59d118SGerd Hoffmann uint32_t sid); 1615c59d118SGerd Hoffmann void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id, 1625ff4e36cSAlon Levy QXLDevSurfaceCreate *surface, 1635ff4e36cSAlon Levy qxl_async_io async); 1645ff4e36cSAlon Levy void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, 1655ff4e36cSAlon Levy uint32_t id, qxl_async_io async); 1665c59d118SGerd Hoffmann void qemu_spice_wakeup(SimpleSpiceDisplay *ssd); 16771d388d4SYonit Halperin void qemu_spice_display_start(void); 16871d388d4SYonit Halperin void qemu_spice_display_stop(void); 16971d388d4SYonit Halperin int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd); 170