xref: /qemu/include/ui/spice-display.h (revision 5e79d516e8ac818d2a90aae9f787775055434ee9)
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)
319f5c6d06SMichal Privoznik # if SPICE_SERVER_VERSION >= 0x000d01 /* release 0.13.1 */
32474114b7SGerd Hoffmann #  define HAVE_SPICE_GL 1
33474114b7SGerd Hoffmann #  include "ui/egl-helpers.h"
34474114b7SGerd Hoffmann #  include "ui/egl-context.h"
35474114b7SGerd Hoffmann # endif
36474114b7SGerd Hoffmann #endif
37474114b7SGerd Hoffmann 
38a3e22260SGerd Hoffmann #define NUM_MEMSLOTS 8
39a3e22260SGerd Hoffmann #define MEMSLOT_GENERATION_BITS 8
40a3e22260SGerd Hoffmann #define MEMSLOT_SLOT_BITS 8
41a3e22260SGerd Hoffmann 
42a3e22260SGerd Hoffmann #define MEMSLOT_GROUP_HOST  0
43a3e22260SGerd Hoffmann #define MEMSLOT_GROUP_GUEST 1
44a3e22260SGerd Hoffmann #define NUM_MEMSLOTS_GROUPS 2
45a3e22260SGerd Hoffmann 
465ff4e36cSAlon Levy /*
475ff4e36cSAlon Levy  * Internal enum to differenciate between options for
485ff4e36cSAlon Levy  * io calls that have a sync (old) version and an _async (new)
495ff4e36cSAlon Levy  * version:
505ff4e36cSAlon Levy  *  QXL_SYNC: use the old version
515ff4e36cSAlon Levy  *  QXL_ASYNC: use the new version and make sure there are no two
525ff4e36cSAlon Levy  *   happening at the same time. This is used for guest initiated
535ff4e36cSAlon Levy  *   calls
545ff4e36cSAlon Levy  */
555ff4e36cSAlon Levy typedef enum qxl_async_io {
565ff4e36cSAlon Levy     QXL_SYNC,
575ff4e36cSAlon Levy     QXL_ASYNC,
585ff4e36cSAlon Levy } qxl_async_io;
595ff4e36cSAlon Levy 
602e1a98c9SAlon Levy enum {
612e1a98c9SAlon Levy     QXL_COOKIE_TYPE_IO,
6281fb6f15SAlon Levy     QXL_COOKIE_TYPE_RENDER_UPDATE_AREA,
63020af1c4SAlon Levy     QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
64474114b7SGerd Hoffmann     QXL_COOKIE_TYPE_GL_DRAW_DONE,
652e1a98c9SAlon Levy };
662e1a98c9SAlon Levy 
672e1a98c9SAlon Levy typedef struct QXLCookie {
682e1a98c9SAlon Levy     int      type;
692e1a98c9SAlon Levy     uint64_t io;
702e1a98c9SAlon Levy     union {
712e1a98c9SAlon Levy         uint32_t surface_id;
7281fb6f15SAlon Levy         QXLRect area;
7381fb6f15SAlon Levy         struct {
7481fb6f15SAlon Levy             QXLRect area;
7581fb6f15SAlon Levy             int redraw;
7681fb6f15SAlon Levy         } render;
7739414ef4SGerd Hoffmann         void *data;
782e1a98c9SAlon Levy     } u;
792e1a98c9SAlon Levy } QXLCookie;
802e1a98c9SAlon Levy 
812e1a98c9SAlon Levy QXLCookie *qxl_cookie_new(int type, uint64_t io);
822e1a98c9SAlon Levy 
83e0c64d08SGerd Hoffmann typedef struct SimpleSpiceDisplay SimpleSpiceDisplay;
84e0c64d08SGerd Hoffmann typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;
855643fc01SGerd Hoffmann typedef struct SimpleSpiceCursor SimpleSpiceCursor;
86e0c64d08SGerd Hoffmann 
87e0c64d08SGerd Hoffmann struct SimpleSpiceDisplay {
8871874c17SGerd Hoffmann     DisplaySurface *ds;
89*5e79d516SMarc-André Lureau     DisplayGLCtx dgc;
907c20b4a3SGerd Hoffmann     DisplayChangeListener dcl;
91a3e22260SGerd Hoffmann     void *buf;
92a3e22260SGerd Hoffmann     int bufsize;
93a3e22260SGerd Hoffmann     QXLInstance qxl;
94a3e22260SGerd Hoffmann     uint32_t unique;
95d9a86569SGerd Hoffmann     pixman_image_t *surface;
96d9a86569SGerd Hoffmann     pixman_image_t *mirror;
97ddd8fdc7SGerd Hoffmann     int32_t num_surfaces;
98a3e22260SGerd Hoffmann 
99a3e22260SGerd Hoffmann     QXLRect dirty;
100a3e22260SGerd Hoffmann     int notify;
101a3e22260SGerd Hoffmann 
102e0c64d08SGerd Hoffmann     /*
103e0c64d08SGerd Hoffmann      * All struct members below this comment can be accessed from
104e0c64d08SGerd Hoffmann      * both spice server and qemu (iothread) context and any access
105e0c64d08SGerd Hoffmann      * to them must be protected by the lock.
106e0c64d08SGerd Hoffmann      */
107e0c64d08SGerd Hoffmann     QemuMutex lock;
108b1af98baSGerd Hoffmann     QTAILQ_HEAD(, SimpleSpiceUpdate) updates;
1095643fc01SGerd Hoffmann 
1105643fc01SGerd Hoffmann     /* cursor (without qxl): displaychangelistener -> spice server */
1115643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_define;
1125643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_move;
113dc8dceeeSMarc-André Lureau     int16_t ptr_x, ptr_y;
114dc8dceeeSMarc-André Lureau     int16_t hot_x, hot_y;
1155643fc01SGerd Hoffmann 
1165643fc01SGerd Hoffmann     /* cursor (with qxl): qxl local renderer -> displaychangelistener */
11707536094SGerd Hoffmann     QEMUCursor *cursor;
11807536094SGerd Hoffmann     int mouse_x, mouse_y;
1190b2824e5SGerd Hoffmann     QEMUBH *cursor_bh;
120474114b7SGerd Hoffmann 
121474114b7SGerd Hoffmann #ifdef HAVE_SPICE_GL
122474114b7SGerd Hoffmann     /* opengl rendering */
123474114b7SGerd Hoffmann     QEMUBH *gl_unblock_bh;
1248e388e90SGerd Hoffmann     QEMUTimer *gl_unblock_timer;
12546e19e14SGerd Hoffmann     QemuGLShader *gls;
12644231843SGerd Hoffmann     int gl_updates;
12744231843SGerd Hoffmann     bool have_scanout;
12844231843SGerd Hoffmann     bool have_surface;
129b153f901SGerd Hoffmann 
130b153f901SGerd Hoffmann     QemuDmaBuf *guest_dmabuf;
131b153f901SGerd Hoffmann     bool guest_dmabuf_refresh;
132b153f901SGerd Hoffmann     bool render_cursor;
133b153f901SGerd Hoffmann 
134b153f901SGerd Hoffmann     egl_fb guest_fb;
135b153f901SGerd Hoffmann     egl_fb blit_fb;
136b153f901SGerd Hoffmann     egl_fb cursor_fb;
137b153f901SGerd Hoffmann     bool have_hot;
138474114b7SGerd Hoffmann #endif
139e0c64d08SGerd Hoffmann };
140e0c64d08SGerd Hoffmann 
141e0c64d08SGerd Hoffmann struct SimpleSpiceUpdate {
142a3e22260SGerd Hoffmann     QXLDrawable drawable;
143a3e22260SGerd Hoffmann     QXLImage image;
144a3e22260SGerd Hoffmann     QXLCommandExt ext;
145a3e22260SGerd Hoffmann     uint8_t *bitmap;
146b1af98baSGerd Hoffmann     QTAILQ_ENTRY(SimpleSpiceUpdate) next;
147e0c64d08SGerd Hoffmann };
148a3e22260SGerd Hoffmann 
1495643fc01SGerd Hoffmann struct SimpleSpiceCursor {
1505643fc01SGerd Hoffmann     QXLCursorCmd cmd;
1515643fc01SGerd Hoffmann     QXLCommandExt ext;
1525643fc01SGerd Hoffmann     QXLCursor cursor;
1535643fc01SGerd Hoffmann };
1545643fc01SGerd Hoffmann 
155fe5c44f9SGerd Hoffmann extern bool spice_opengl;
156fe5c44f9SGerd Hoffmann 
157a3e22260SGerd Hoffmann int qemu_spice_rect_is_empty(const QXLRect* r);
158a3e22260SGerd Hoffmann void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
159a3e22260SGerd Hoffmann 
160a3e22260SGerd Hoffmann void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update);
161a3e22260SGerd Hoffmann void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
162a3e22260SGerd Hoffmann void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
163a3e22260SGerd Hoffmann void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
164c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd);
165a3e22260SGerd Hoffmann 
166a3e22260SGerd Hoffmann void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
167a3e22260SGerd Hoffmann                                int x, int y, int w, int h);
168c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
169c12aeb86SGerd Hoffmann                                DisplaySurface *surface);
170a3e22260SGerd Hoffmann void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
1710b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque);
1725c59d118SGerd Hoffmann 
1735ff4e36cSAlon Levy void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
1745ff4e36cSAlon Levy                             qxl_async_io async);
1755c59d118SGerd Hoffmann void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
1765c59d118SGerd Hoffmann                             uint32_t sid);
1775c59d118SGerd Hoffmann void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
1785ff4e36cSAlon Levy                                        QXLDevSurfaceCreate *surface,
1795ff4e36cSAlon Levy                                        qxl_async_io async);
1805ff4e36cSAlon Levy void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
1815ff4e36cSAlon Levy                                         uint32_t id, qxl_async_io async);
1825c59d118SGerd Hoffmann void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
18371d388d4SYonit Halperin void qemu_spice_display_start(void);
18471d388d4SYonit Halperin void qemu_spice_display_stop(void);
18571d388d4SYonit Halperin int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
186be812c0aSLukáš Hrázký 
187be812c0aSLukáš Hrázký bool qemu_spice_fill_device_address(QemuConsole *con,
188be812c0aSLukáš Hrázký                                     char *device_address,
189be812c0aSLukáš Hrázký                                     size_t size);
190f91005e1SMarkus Armbruster 
191f91005e1SMarkus Armbruster #endif
192