xref: /qemu/include/ui/spice-display.h (revision bc6a3565c89243f0aaa24bac6dc37fb52b16d5c5)
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 
30*bc6a3565SAkihiko 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;
897c20b4a3SGerd Hoffmann     DisplayChangeListener dcl;
90a3e22260SGerd Hoffmann     void *buf;
91a3e22260SGerd Hoffmann     int bufsize;
92a3e22260SGerd Hoffmann     QXLInstance qxl;
93a3e22260SGerd Hoffmann     uint32_t unique;
94d9a86569SGerd Hoffmann     pixman_image_t *surface;
95d9a86569SGerd Hoffmann     pixman_image_t *mirror;
96ddd8fdc7SGerd Hoffmann     int32_t num_surfaces;
97a3e22260SGerd Hoffmann 
98a3e22260SGerd Hoffmann     QXLRect dirty;
99a3e22260SGerd Hoffmann     int notify;
100a3e22260SGerd Hoffmann 
101e0c64d08SGerd Hoffmann     /*
102e0c64d08SGerd Hoffmann      * All struct members below this comment can be accessed from
103e0c64d08SGerd Hoffmann      * both spice server and qemu (iothread) context and any access
104e0c64d08SGerd Hoffmann      * to them must be protected by the lock.
105e0c64d08SGerd Hoffmann      */
106e0c64d08SGerd Hoffmann     QemuMutex lock;
107b1af98baSGerd Hoffmann     QTAILQ_HEAD(, SimpleSpiceUpdate) updates;
1085643fc01SGerd Hoffmann 
1095643fc01SGerd Hoffmann     /* cursor (without qxl): displaychangelistener -> spice server */
1105643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_define;
1115643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_move;
112dc8dceeeSMarc-André Lureau     int16_t ptr_x, ptr_y;
113dc8dceeeSMarc-André Lureau     int16_t hot_x, hot_y;
1145643fc01SGerd Hoffmann 
1155643fc01SGerd Hoffmann     /* cursor (with qxl): qxl local renderer -> displaychangelistener */
11607536094SGerd Hoffmann     QEMUCursor *cursor;
11707536094SGerd Hoffmann     int mouse_x, mouse_y;
1180b2824e5SGerd Hoffmann     QEMUBH *cursor_bh;
119474114b7SGerd Hoffmann 
120474114b7SGerd Hoffmann #ifdef HAVE_SPICE_GL
121474114b7SGerd Hoffmann     /* opengl rendering */
122474114b7SGerd Hoffmann     QEMUBH *gl_unblock_bh;
1238e388e90SGerd Hoffmann     QEMUTimer *gl_unblock_timer;
12446e19e14SGerd Hoffmann     QemuGLShader *gls;
12544231843SGerd Hoffmann     int gl_updates;
12644231843SGerd Hoffmann     bool have_scanout;
12744231843SGerd Hoffmann     bool have_surface;
128b153f901SGerd Hoffmann 
129b153f901SGerd Hoffmann     QemuDmaBuf *guest_dmabuf;
130b153f901SGerd Hoffmann     bool guest_dmabuf_refresh;
131b153f901SGerd Hoffmann     bool render_cursor;
132b153f901SGerd Hoffmann 
133b153f901SGerd Hoffmann     egl_fb guest_fb;
134b153f901SGerd Hoffmann     egl_fb blit_fb;
135b153f901SGerd Hoffmann     egl_fb cursor_fb;
136b153f901SGerd Hoffmann     bool have_hot;
137474114b7SGerd Hoffmann #endif
138e0c64d08SGerd Hoffmann };
139e0c64d08SGerd Hoffmann 
140e0c64d08SGerd Hoffmann struct SimpleSpiceUpdate {
141a3e22260SGerd Hoffmann     QXLDrawable drawable;
142a3e22260SGerd Hoffmann     QXLImage image;
143a3e22260SGerd Hoffmann     QXLCommandExt ext;
144a3e22260SGerd Hoffmann     uint8_t *bitmap;
145b1af98baSGerd Hoffmann     QTAILQ_ENTRY(SimpleSpiceUpdate) next;
146e0c64d08SGerd Hoffmann };
147a3e22260SGerd Hoffmann 
1485643fc01SGerd Hoffmann struct SimpleSpiceCursor {
1495643fc01SGerd Hoffmann     QXLCursorCmd cmd;
1505643fc01SGerd Hoffmann     QXLCommandExt ext;
1515643fc01SGerd Hoffmann     QXLCursor cursor;
1525643fc01SGerd Hoffmann };
1535643fc01SGerd Hoffmann 
154fe5c44f9SGerd Hoffmann extern bool spice_opengl;
155fe5c44f9SGerd Hoffmann 
156a3e22260SGerd Hoffmann int qemu_spice_rect_is_empty(const QXLRect* r);
157a3e22260SGerd Hoffmann void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
158a3e22260SGerd Hoffmann 
159a3e22260SGerd Hoffmann void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update);
160a3e22260SGerd Hoffmann void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
161a3e22260SGerd Hoffmann void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
162a3e22260SGerd Hoffmann void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
163c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd);
164a3e22260SGerd Hoffmann 
165a3e22260SGerd Hoffmann void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
166a3e22260SGerd Hoffmann                                int x, int y, int w, int h);
167c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
168c12aeb86SGerd Hoffmann                                DisplaySurface *surface);
169a3e22260SGerd Hoffmann void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
1700b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque);
1715c59d118SGerd Hoffmann 
1725ff4e36cSAlon Levy void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
1735ff4e36cSAlon Levy                             qxl_async_io async);
1745c59d118SGerd Hoffmann void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
1755c59d118SGerd Hoffmann                             uint32_t sid);
1765c59d118SGerd Hoffmann void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
1775ff4e36cSAlon Levy                                        QXLDevSurfaceCreate *surface,
1785ff4e36cSAlon Levy                                        qxl_async_io async);
1795ff4e36cSAlon Levy void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
1805ff4e36cSAlon Levy                                         uint32_t id, qxl_async_io async);
1815c59d118SGerd Hoffmann void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
18271d388d4SYonit Halperin void qemu_spice_display_start(void);
18371d388d4SYonit Halperin void qemu_spice_display_stop(void);
18471d388d4SYonit Halperin int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
185be812c0aSLukáš Hrázký 
186be812c0aSLukáš Hrázký bool qemu_spice_fill_device_address(QemuConsole *con,
187be812c0aSLukáš Hrázký                                     char *device_address,
188be812c0aSLukáš Hrázký                                     size_t size);
189f91005e1SMarkus Armbruster 
190f91005e1SMarkus Armbruster #endif
191