xref: /qemu/include/ui/spice-display.h (revision 46e19e149f3b129a22c440caba853188df67deab)
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)
289f5c6d06SMichal 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;
7439414ef4SGerd Hoffmann         void *data;
752e1a98c9SAlon Levy     } u;
762e1a98c9SAlon Levy } QXLCookie;
772e1a98c9SAlon Levy 
782e1a98c9SAlon Levy QXLCookie *qxl_cookie_new(int type, uint64_t io);
792e1a98c9SAlon Levy 
80e0c64d08SGerd Hoffmann typedef struct SimpleSpiceDisplay SimpleSpiceDisplay;
81e0c64d08SGerd Hoffmann typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;
825643fc01SGerd Hoffmann typedef struct SimpleSpiceCursor SimpleSpiceCursor;
83e0c64d08SGerd Hoffmann 
84e0c64d08SGerd Hoffmann struct SimpleSpiceDisplay {
8571874c17SGerd Hoffmann     DisplaySurface *ds;
867c20b4a3SGerd Hoffmann     DisplayChangeListener dcl;
87a3e22260SGerd Hoffmann     void *buf;
88a3e22260SGerd Hoffmann     int bufsize;
89a3e22260SGerd Hoffmann     QXLWorker *worker;
90a3e22260SGerd Hoffmann     QXLInstance qxl;
91a3e22260SGerd Hoffmann     uint32_t unique;
92d9a86569SGerd Hoffmann     pixman_image_t *surface;
93d9a86569SGerd Hoffmann     pixman_image_t *mirror;
94ddd8fdc7SGerd Hoffmann     int32_t num_surfaces;
95a3e22260SGerd Hoffmann 
96a3e22260SGerd Hoffmann     QXLRect dirty;
97a3e22260SGerd Hoffmann     int notify;
98a3e22260SGerd Hoffmann 
99e0c64d08SGerd Hoffmann     /*
100e0c64d08SGerd Hoffmann      * All struct members below this comment can be accessed from
101e0c64d08SGerd Hoffmann      * both spice server and qemu (iothread) context and any access
102e0c64d08SGerd Hoffmann      * to them must be protected by the lock.
103e0c64d08SGerd Hoffmann      */
104e0c64d08SGerd Hoffmann     QemuMutex lock;
105b1af98baSGerd Hoffmann     QTAILQ_HEAD(, SimpleSpiceUpdate) updates;
1065643fc01SGerd Hoffmann 
1075643fc01SGerd Hoffmann     /* cursor (without qxl): displaychangelistener -> spice server */
1085643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_define;
1095643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_move;
110dc8dceeeSMarc-André Lureau     int16_t ptr_x, ptr_y;
111dc8dceeeSMarc-André Lureau     int16_t hot_x, hot_y;
1125643fc01SGerd Hoffmann 
1135643fc01SGerd Hoffmann     /* cursor (with qxl): qxl local renderer -> displaychangelistener */
11407536094SGerd Hoffmann     QEMUCursor *cursor;
11507536094SGerd Hoffmann     int mouse_x, mouse_y;
1160b2824e5SGerd Hoffmann     QEMUBH *cursor_bh;
117474114b7SGerd Hoffmann 
118474114b7SGerd Hoffmann #ifdef HAVE_SPICE_GL
119474114b7SGerd Hoffmann     /* opengl rendering */
120474114b7SGerd Hoffmann     QEMUBH *gl_unblock_bh;
1218e388e90SGerd Hoffmann     QEMUTimer *gl_unblock_timer;
122*46e19e14SGerd Hoffmann     QemuGLShader *gls;
12344231843SGerd Hoffmann     int gl_updates;
12444231843SGerd Hoffmann     bool have_scanout;
12544231843SGerd Hoffmann     bool have_surface;
126474114b7SGerd Hoffmann #endif
127e0c64d08SGerd Hoffmann };
128e0c64d08SGerd Hoffmann 
129e0c64d08SGerd Hoffmann struct SimpleSpiceUpdate {
130a3e22260SGerd Hoffmann     QXLDrawable drawable;
131a3e22260SGerd Hoffmann     QXLImage image;
132a3e22260SGerd Hoffmann     QXLCommandExt ext;
133a3e22260SGerd Hoffmann     uint8_t *bitmap;
134b1af98baSGerd Hoffmann     QTAILQ_ENTRY(SimpleSpiceUpdate) next;
135e0c64d08SGerd Hoffmann };
136a3e22260SGerd Hoffmann 
1375643fc01SGerd Hoffmann struct SimpleSpiceCursor {
1385643fc01SGerd Hoffmann     QXLCursorCmd cmd;
1395643fc01SGerd Hoffmann     QXLCommandExt ext;
1405643fc01SGerd Hoffmann     QXLCursor cursor;
1415643fc01SGerd Hoffmann };
1425643fc01SGerd Hoffmann 
143fe5c44f9SGerd Hoffmann extern bool spice_opengl;
144fe5c44f9SGerd Hoffmann 
145a3e22260SGerd Hoffmann int qemu_spice_rect_is_empty(const QXLRect* r);
146a3e22260SGerd Hoffmann void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
147a3e22260SGerd Hoffmann 
148a3e22260SGerd Hoffmann void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update);
149a3e22260SGerd Hoffmann void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
150a3e22260SGerd Hoffmann void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
151a3e22260SGerd Hoffmann void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
152c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd);
153a3e22260SGerd Hoffmann 
154a3e22260SGerd Hoffmann void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
155a3e22260SGerd Hoffmann                                int x, int y, int w, int h);
156c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
157c12aeb86SGerd Hoffmann                                DisplaySurface *surface);
158a3e22260SGerd Hoffmann void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
1590b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque);
1605c59d118SGerd Hoffmann 
1615ff4e36cSAlon Levy void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
1625ff4e36cSAlon Levy                             qxl_async_io async);
1635c59d118SGerd Hoffmann void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
1645c59d118SGerd Hoffmann                             uint32_t sid);
1655c59d118SGerd Hoffmann void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
1665ff4e36cSAlon Levy                                        QXLDevSurfaceCreate *surface,
1675ff4e36cSAlon Levy                                        qxl_async_io async);
1685ff4e36cSAlon Levy void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
1695ff4e36cSAlon Levy                                         uint32_t id, qxl_async_io async);
1705c59d118SGerd Hoffmann void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
17171d388d4SYonit Halperin void qemu_spice_display_start(void);
17271d388d4SYonit Halperin void qemu_spice_display_stop(void);
17371d388d4SYonit Halperin int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
174