128ecbaeeSPaolo Bonzini /* 228ecbaeeSPaolo Bonzini * Copyright (C) 2010 Red Hat, Inc. 328ecbaeeSPaolo Bonzini * 428ecbaeeSPaolo Bonzini * This program is free software; you can redistribute it and/or 528ecbaeeSPaolo Bonzini * modify it under the terms of the GNU General Public License as 628ecbaeeSPaolo Bonzini * published by the Free Software Foundation; either version 2 or 728ecbaeeSPaolo Bonzini * (at your option) version 3 of the License. 828ecbaeeSPaolo Bonzini * 928ecbaeeSPaolo Bonzini * This program is distributed in the hope that it will be useful, 1028ecbaeeSPaolo Bonzini * but WITHOUT ANY WARRANTY; without even the implied warranty of 1128ecbaeeSPaolo Bonzini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1228ecbaeeSPaolo Bonzini * GNU General Public License for more details. 1328ecbaeeSPaolo Bonzini * 1428ecbaeeSPaolo Bonzini * You should have received a copy of the GNU General Public License 1528ecbaeeSPaolo Bonzini * along with this program; if not, see <http://www.gnu.org/licenses/>. 1628ecbaeeSPaolo Bonzini */ 1728ecbaeeSPaolo Bonzini 18f91005e1SMarkus Armbruster #ifndef UI_SPICE_DISPLAY_H 19f91005e1SMarkus Armbruster #define UI_SPICE_DISPLAY_H 20f91005e1SMarkus Armbruster 21ec150c7eSMarkus Armbruster #include <spice.h> 2228ecbaeeSPaolo Bonzini #include <spice/ipc_ring.h> 2328ecbaeeSPaolo Bonzini #include <spice/enums.h> 2428ecbaeeSPaolo Bonzini #include <spice/qxl_dev.h> 2528ecbaeeSPaolo Bonzini 261de7afc9SPaolo Bonzini #include "qemu/thread.h" 2728ecbaeeSPaolo Bonzini #include "ui/qemu-pixman.h" 280b087861SPeter Maydell #include "ui/console.h" 2928ecbaeeSPaolo Bonzini 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 3628ecbaeeSPaolo Bonzini #define NUM_MEMSLOTS 8 3728ecbaeeSPaolo Bonzini #define MEMSLOT_GENERATION_BITS 8 3828ecbaeeSPaolo Bonzini #define MEMSLOT_SLOT_BITS 8 3928ecbaeeSPaolo Bonzini 4028ecbaeeSPaolo Bonzini #define MEMSLOT_GROUP_HOST 0 4128ecbaeeSPaolo Bonzini #define MEMSLOT_GROUP_GUEST 1 4228ecbaeeSPaolo Bonzini #define NUM_MEMSLOTS_GROUPS 2 4328ecbaeeSPaolo Bonzini 4428ecbaeeSPaolo Bonzini /* 45*d4761b65SMichael Tokarev * Internal enum to differentiate between options for 4628ecbaeeSPaolo Bonzini * io calls that have a sync (old) version and an _async (new) 4728ecbaeeSPaolo Bonzini * version: 4828ecbaeeSPaolo Bonzini * QXL_SYNC: use the old version 4928ecbaeeSPaolo Bonzini * QXL_ASYNC: use the new version and make sure there are no two 5028ecbaeeSPaolo Bonzini * happening at the same time. This is used for guest initiated 5128ecbaeeSPaolo Bonzini * calls 5228ecbaeeSPaolo Bonzini */ 5328ecbaeeSPaolo Bonzini typedef enum qxl_async_io { 5428ecbaeeSPaolo Bonzini QXL_SYNC, 5528ecbaeeSPaolo Bonzini QXL_ASYNC, 5628ecbaeeSPaolo Bonzini } qxl_async_io; 5728ecbaeeSPaolo Bonzini 5828ecbaeeSPaolo Bonzini enum { 5928ecbaeeSPaolo Bonzini QXL_COOKIE_TYPE_IO, 6028ecbaeeSPaolo Bonzini QXL_COOKIE_TYPE_RENDER_UPDATE_AREA, 6128ecbaeeSPaolo Bonzini QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG, 62474114b7SGerd Hoffmann QXL_COOKIE_TYPE_GL_DRAW_DONE, 6328ecbaeeSPaolo Bonzini }; 6428ecbaeeSPaolo Bonzini 6528ecbaeeSPaolo Bonzini typedef struct QXLCookie { 6628ecbaeeSPaolo Bonzini int type; 6728ecbaeeSPaolo Bonzini uint64_t io; 6828ecbaeeSPaolo Bonzini union { 6928ecbaeeSPaolo Bonzini uint32_t surface_id; 7028ecbaeeSPaolo Bonzini QXLRect area; 7128ecbaeeSPaolo Bonzini struct { 7228ecbaeeSPaolo Bonzini QXLRect area; 7328ecbaeeSPaolo Bonzini int redraw; 7428ecbaeeSPaolo Bonzini } render; 7539414ef4SGerd Hoffmann void *data; 7628ecbaeeSPaolo Bonzini } u; 7728ecbaeeSPaolo Bonzini } QXLCookie; 7828ecbaeeSPaolo Bonzini 7928ecbaeeSPaolo Bonzini QXLCookie *qxl_cookie_new(int type, uint64_t io); 8028ecbaeeSPaolo Bonzini 8128ecbaeeSPaolo Bonzini typedef struct SimpleSpiceDisplay SimpleSpiceDisplay; 8228ecbaeeSPaolo Bonzini typedef struct SimpleSpiceUpdate SimpleSpiceUpdate; 835643fc01SGerd Hoffmann typedef struct SimpleSpiceCursor SimpleSpiceCursor; 8428ecbaeeSPaolo Bonzini 8528ecbaeeSPaolo Bonzini struct SimpleSpiceDisplay { 8671874c17SGerd Hoffmann DisplaySurface *ds; 875e79d516SMarc-André Lureau DisplayGLCtx dgc; 887c20b4a3SGerd Hoffmann DisplayChangeListener dcl; 8928ecbaeeSPaolo Bonzini void *buf; 9028ecbaeeSPaolo Bonzini int bufsize; 9128ecbaeeSPaolo Bonzini QXLInstance qxl; 9228ecbaeeSPaolo Bonzini uint32_t unique; 9328ecbaeeSPaolo Bonzini pixman_image_t *surface; 9428ecbaeeSPaolo Bonzini pixman_image_t *mirror; 9528ecbaeeSPaolo Bonzini int32_t num_surfaces; 9628ecbaeeSPaolo Bonzini 9728ecbaeeSPaolo Bonzini QXLRect dirty; 9828ecbaeeSPaolo Bonzini int notify; 9928ecbaeeSPaolo Bonzini 10028ecbaeeSPaolo Bonzini /* 10128ecbaeeSPaolo Bonzini * All struct members below this comment can be accessed from 10228ecbaeeSPaolo Bonzini * both spice server and qemu (iothread) context and any access 10328ecbaeeSPaolo Bonzini * to them must be protected by the lock. 10428ecbaeeSPaolo Bonzini */ 10528ecbaeeSPaolo Bonzini QemuMutex lock; 10628ecbaeeSPaolo Bonzini 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 */ 11528ecbaeeSPaolo Bonzini QEMUCursor *cursor; 11628ecbaeeSPaolo Bonzini 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 13728ecbaeeSPaolo Bonzini }; 13828ecbaeeSPaolo Bonzini 13928ecbaeeSPaolo Bonzini struct SimpleSpiceUpdate { 14028ecbaeeSPaolo Bonzini QXLDrawable drawable; 14128ecbaeeSPaolo Bonzini QXLImage image; 14228ecbaeeSPaolo Bonzini QXLCommandExt ext; 14328ecbaeeSPaolo Bonzini uint8_t *bitmap; 14428ecbaeeSPaolo Bonzini QTAILQ_ENTRY(SimpleSpiceUpdate) next; 14528ecbaeeSPaolo Bonzini }; 14628ecbaeeSPaolo Bonzini 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 15528ecbaeeSPaolo Bonzini int qemu_spice_rect_is_empty(const QXLRect* r); 15628ecbaeeSPaolo Bonzini void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r); 15728ecbaeeSPaolo Bonzini 15828ecbaeeSPaolo Bonzini void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update); 15928ecbaeeSPaolo Bonzini void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd); 16028ecbaeeSPaolo Bonzini void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd); 16128ecbaeeSPaolo Bonzini void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd); 162c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd); 16328ecbaeeSPaolo Bonzini 16428ecbaeeSPaolo Bonzini void qemu_spice_display_update(SimpleSpiceDisplay *ssd, 16528ecbaeeSPaolo Bonzini int x, int y, int w, int h); 166c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, 167c12aeb86SGerd Hoffmann DisplaySurface *surface); 16828ecbaeeSPaolo Bonzini void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd); 1690b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque); 17028ecbaeeSPaolo Bonzini 17128ecbaeeSPaolo Bonzini void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot, 17228ecbaeeSPaolo Bonzini qxl_async_io async); 17328ecbaeeSPaolo Bonzini void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, 17428ecbaeeSPaolo Bonzini uint32_t sid); 17528ecbaeeSPaolo Bonzini void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id, 17628ecbaeeSPaolo Bonzini QXLDevSurfaceCreate *surface, 17728ecbaeeSPaolo Bonzini qxl_async_io async); 17828ecbaeeSPaolo Bonzini void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, 17928ecbaeeSPaolo Bonzini uint32_t id, qxl_async_io async); 18028ecbaeeSPaolo Bonzini void qemu_spice_wakeup(SimpleSpiceDisplay *ssd); 18128ecbaeeSPaolo Bonzini void qemu_spice_display_start(void); 18228ecbaeeSPaolo Bonzini void qemu_spice_display_stop(void); 18328ecbaeeSPaolo Bonzini int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd); 184be812c0aSLukáš Hrázký 185f91005e1SMarkus Armbruster #endif 186