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 18f91005e1SMarkus Armbruster #ifndef UI_SPICE_DISPLAY_H 19f91005e1SMarkus Armbruster #define UI_SPICE_DISPLAY_H 20f91005e1SMarkus Armbruster 21ec150c7eSMarkus Armbruster #include <spice.h> 22a3e22260SGerd Hoffmann #include <spice/ipc_ring.h> 23a3e22260SGerd Hoffmann #include <spice/enums.h> 24a3e22260SGerd Hoffmann #include <spice/qxl_dev.h> 25a3e22260SGerd Hoffmann 261de7afc9SPaolo Bonzini #include "qemu/thread.h" 2728ecbaeeSPaolo Bonzini #include "ui/qemu-pixman.h" 280b087861SPeter Maydell #include "ui/console.h" 29a3e22260SGerd Hoffmann 30bc6a3565SAkihiko Odaki #if defined(CONFIG_OPENGL) && defined(CONFIG_GBM) 31474114b7SGerd Hoffmann # define HAVE_SPICE_GL 1 32474114b7SGerd Hoffmann # include "ui/egl-helpers.h" 33474114b7SGerd Hoffmann # include "ui/egl-context.h" 34474114b7SGerd Hoffmann #endif 35474114b7SGerd Hoffmann 36a3e22260SGerd Hoffmann #define NUM_MEMSLOTS 8 37a3e22260SGerd Hoffmann #define MEMSLOT_GENERATION_BITS 8 38a3e22260SGerd Hoffmann #define MEMSLOT_SLOT_BITS 8 39a3e22260SGerd Hoffmann 40a3e22260SGerd Hoffmann #define MEMSLOT_GROUP_HOST 0 41a3e22260SGerd Hoffmann #define MEMSLOT_GROUP_GUEST 1 42a3e22260SGerd Hoffmann #define NUM_MEMSLOTS_GROUPS 2 43a3e22260SGerd Hoffmann 445ff4e36cSAlon Levy /* 45*d4761b65SMichael Tokarev * Internal enum to differentiate between options for 465ff4e36cSAlon Levy * io calls that have a sync (old) version and an _async (new) 475ff4e36cSAlon Levy * version: 485ff4e36cSAlon Levy * QXL_SYNC: use the old version 495ff4e36cSAlon Levy * QXL_ASYNC: use the new version and make sure there are no two 505ff4e36cSAlon Levy * happening at the same time. This is used for guest initiated 515ff4e36cSAlon Levy * calls 525ff4e36cSAlon Levy */ 535ff4e36cSAlon Levy typedef enum qxl_async_io { 545ff4e36cSAlon Levy QXL_SYNC, 555ff4e36cSAlon Levy QXL_ASYNC, 565ff4e36cSAlon Levy } qxl_async_io; 575ff4e36cSAlon Levy 582e1a98c9SAlon Levy enum { 592e1a98c9SAlon Levy QXL_COOKIE_TYPE_IO, 6081fb6f15SAlon Levy QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, 61020af1c4SAlon Levy QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG, 62474114b7SGerd Hoffmann QXL_COOKIE_TYPE_GL_DRAW_DONE, 632e1a98c9SAlon Levy }; 642e1a98c9SAlon Levy 652e1a98c9SAlon Levy typedef struct QXLCookie { 662e1a98c9SAlon Levy int type; 672e1a98c9SAlon Levy uint64_t io; 682e1a98c9SAlon Levy union { 692e1a98c9SAlon Levy uint32_t surface_id; 7081fb6f15SAlon Levy QXLRect area; 7181fb6f15SAlon Levy struct { 7281fb6f15SAlon Levy QXLRect area; 7381fb6f15SAlon Levy int redraw; 7481fb6f15SAlon Levy } render; 7539414ef4SGerd Hoffmann void *data; 762e1a98c9SAlon Levy } u; 772e1a98c9SAlon Levy } QXLCookie; 782e1a98c9SAlon Levy 792e1a98c9SAlon Levy QXLCookie *qxl_cookie_new(int type, uint64_t io); 802e1a98c9SAlon Levy 81e0c64d08SGerd Hoffmann typedef struct SimpleSpiceDisplay SimpleSpiceDisplay; 82e0c64d08SGerd Hoffmann typedef struct SimpleSpiceUpdate SimpleSpiceUpdate; 835643fc01SGerd Hoffmann typedef struct SimpleSpiceCursor SimpleSpiceCursor; 84e0c64d08SGerd Hoffmann 85e0c64d08SGerd Hoffmann struct SimpleSpiceDisplay { 8671874c17SGerd Hoffmann DisplaySurface *ds; 875e79d516SMarc-André Lureau DisplayGLCtx dgc; 887c20b4a3SGerd Hoffmann DisplayChangeListener dcl; 89a3e22260SGerd Hoffmann void *buf; 90a3e22260SGerd Hoffmann int bufsize; 91a3e22260SGerd Hoffmann QXLInstance qxl; 92a3e22260SGerd Hoffmann uint32_t unique; 93d9a86569SGerd Hoffmann pixman_image_t *surface; 94d9a86569SGerd Hoffmann pixman_image_t *mirror; 95ddd8fdc7SGerd Hoffmann int32_t num_surfaces; 96a3e22260SGerd Hoffmann 97a3e22260SGerd Hoffmann QXLRect dirty; 98a3e22260SGerd Hoffmann int notify; 99a3e22260SGerd Hoffmann 100e0c64d08SGerd Hoffmann /* 101e0c64d08SGerd Hoffmann * All struct members below this comment can be accessed from 102e0c64d08SGerd Hoffmann * both spice server and qemu (iothread) context and any access 103e0c64d08SGerd Hoffmann * to them must be protected by the lock. 104e0c64d08SGerd Hoffmann */ 105e0c64d08SGerd Hoffmann QemuMutex lock; 106b1af98baSGerd Hoffmann QTAILQ_HEAD(, SimpleSpiceUpdate) updates; 1075643fc01SGerd Hoffmann 1085643fc01SGerd Hoffmann /* cursor (without qxl): displaychangelistener -> spice server */ 1095643fc01SGerd Hoffmann SimpleSpiceCursor *ptr_define; 1105643fc01SGerd Hoffmann SimpleSpiceCursor *ptr_move; 111dc8dceeeSMarc-André Lureau int16_t ptr_x, ptr_y; 112dc8dceeeSMarc-André Lureau int16_t hot_x, hot_y; 1135643fc01SGerd Hoffmann 1145643fc01SGerd Hoffmann /* cursor (with qxl): qxl local renderer -> displaychangelistener */ 11507536094SGerd Hoffmann QEMUCursor *cursor; 11607536094SGerd Hoffmann int mouse_x, mouse_y; 1170b2824e5SGerd Hoffmann QEMUBH *cursor_bh; 118474114b7SGerd Hoffmann 119474114b7SGerd Hoffmann #ifdef HAVE_SPICE_GL 120474114b7SGerd Hoffmann /* opengl rendering */ 121474114b7SGerd Hoffmann QEMUBH *gl_unblock_bh; 1228e388e90SGerd Hoffmann QEMUTimer *gl_unblock_timer; 12346e19e14SGerd Hoffmann QemuGLShader *gls; 12444231843SGerd Hoffmann int gl_updates; 12544231843SGerd Hoffmann bool have_scanout; 12644231843SGerd Hoffmann bool have_surface; 127b153f901SGerd Hoffmann 128b153f901SGerd Hoffmann QemuDmaBuf *guest_dmabuf; 129b153f901SGerd Hoffmann bool guest_dmabuf_refresh; 130b153f901SGerd Hoffmann bool render_cursor; 131b153f901SGerd Hoffmann 132b153f901SGerd Hoffmann egl_fb guest_fb; 133b153f901SGerd Hoffmann egl_fb blit_fb; 134b153f901SGerd Hoffmann egl_fb cursor_fb; 135b153f901SGerd Hoffmann bool have_hot; 136474114b7SGerd Hoffmann #endif 137e0c64d08SGerd Hoffmann }; 138e0c64d08SGerd Hoffmann 139e0c64d08SGerd Hoffmann struct SimpleSpiceUpdate { 140a3e22260SGerd Hoffmann QXLDrawable drawable; 141a3e22260SGerd Hoffmann QXLImage image; 142a3e22260SGerd Hoffmann QXLCommandExt ext; 143a3e22260SGerd Hoffmann uint8_t *bitmap; 144b1af98baSGerd Hoffmann QTAILQ_ENTRY(SimpleSpiceUpdate) next; 145e0c64d08SGerd Hoffmann }; 146a3e22260SGerd Hoffmann 1475643fc01SGerd Hoffmann struct SimpleSpiceCursor { 1485643fc01SGerd Hoffmann QXLCursorCmd cmd; 1495643fc01SGerd Hoffmann QXLCommandExt ext; 1505643fc01SGerd Hoffmann QXLCursor cursor; 1515643fc01SGerd Hoffmann }; 1525643fc01SGerd Hoffmann 153fe5c44f9SGerd Hoffmann extern bool spice_opengl; 154fe5c44f9SGerd Hoffmann 155a3e22260SGerd Hoffmann int qemu_spice_rect_is_empty(const QXLRect* r); 156a3e22260SGerd Hoffmann void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r); 157a3e22260SGerd Hoffmann 158a3e22260SGerd Hoffmann void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update); 159a3e22260SGerd Hoffmann void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd); 160a3e22260SGerd Hoffmann void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd); 161a3e22260SGerd Hoffmann void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd); 162c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd); 163a3e22260SGerd Hoffmann 164a3e22260SGerd Hoffmann void qemu_spice_display_update(SimpleSpiceDisplay *ssd, 165a3e22260SGerd Hoffmann int x, int y, int w, int h); 166c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, 167c12aeb86SGerd Hoffmann DisplaySurface *surface); 168a3e22260SGerd Hoffmann void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd); 1690b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque); 1705c59d118SGerd Hoffmann 1715ff4e36cSAlon Levy void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot, 1725ff4e36cSAlon Levy qxl_async_io async); 1735c59d118SGerd Hoffmann void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, 1745c59d118SGerd Hoffmann uint32_t sid); 1755c59d118SGerd Hoffmann void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id, 1765ff4e36cSAlon Levy QXLDevSurfaceCreate *surface, 1775ff4e36cSAlon Levy qxl_async_io async); 1785ff4e36cSAlon Levy void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, 1795ff4e36cSAlon Levy uint32_t id, qxl_async_io async); 1805c59d118SGerd Hoffmann void qemu_spice_wakeup(SimpleSpiceDisplay *ssd); 18171d388d4SYonit Halperin void qemu_spice_display_start(void); 18271d388d4SYonit Halperin void qemu_spice_display_stop(void); 18371d388d4SYonit Halperin int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd); 184be812c0aSLukáš Hrázký 185f91005e1SMarkus Armbruster #endif 186