xref: /qemu/include/ui/spice-display.h (revision be812c0ab7d5ab741d0d87387a75a0e8bb6461e7)
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     QXLInstance qxl;
90a3e22260SGerd Hoffmann     uint32_t unique;
91d9a86569SGerd Hoffmann     pixman_image_t *surface;
92d9a86569SGerd Hoffmann     pixman_image_t *mirror;
93ddd8fdc7SGerd Hoffmann     int32_t num_surfaces;
94a3e22260SGerd Hoffmann 
95a3e22260SGerd Hoffmann     QXLRect dirty;
96a3e22260SGerd Hoffmann     int notify;
97a3e22260SGerd Hoffmann 
98e0c64d08SGerd Hoffmann     /*
99e0c64d08SGerd Hoffmann      * All struct members below this comment can be accessed from
100e0c64d08SGerd Hoffmann      * both spice server and qemu (iothread) context and any access
101e0c64d08SGerd Hoffmann      * to them must be protected by the lock.
102e0c64d08SGerd Hoffmann      */
103e0c64d08SGerd Hoffmann     QemuMutex lock;
104b1af98baSGerd Hoffmann     QTAILQ_HEAD(, SimpleSpiceUpdate) updates;
1055643fc01SGerd Hoffmann 
1065643fc01SGerd Hoffmann     /* cursor (without qxl): displaychangelistener -> spice server */
1075643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_define;
1085643fc01SGerd Hoffmann     SimpleSpiceCursor *ptr_move;
109dc8dceeeSMarc-André Lureau     int16_t ptr_x, ptr_y;
110dc8dceeeSMarc-André Lureau     int16_t hot_x, hot_y;
1115643fc01SGerd Hoffmann 
1125643fc01SGerd Hoffmann     /* cursor (with qxl): qxl local renderer -> displaychangelistener */
11307536094SGerd Hoffmann     QEMUCursor *cursor;
11407536094SGerd Hoffmann     int mouse_x, mouse_y;
1150b2824e5SGerd Hoffmann     QEMUBH *cursor_bh;
116474114b7SGerd Hoffmann 
117474114b7SGerd Hoffmann #ifdef HAVE_SPICE_GL
118474114b7SGerd Hoffmann     /* opengl rendering */
119474114b7SGerd Hoffmann     QEMUBH *gl_unblock_bh;
1208e388e90SGerd Hoffmann     QEMUTimer *gl_unblock_timer;
12146e19e14SGerd Hoffmann     QemuGLShader *gls;
12244231843SGerd Hoffmann     int gl_updates;
12344231843SGerd Hoffmann     bool have_scanout;
12444231843SGerd Hoffmann     bool have_surface;
125b153f901SGerd Hoffmann 
126b153f901SGerd Hoffmann     QemuDmaBuf *guest_dmabuf;
127b153f901SGerd Hoffmann     bool guest_dmabuf_refresh;
128b153f901SGerd Hoffmann     bool render_cursor;
129b153f901SGerd Hoffmann 
130b153f901SGerd Hoffmann     egl_fb guest_fb;
131b153f901SGerd Hoffmann     egl_fb blit_fb;
132b153f901SGerd Hoffmann     egl_fb cursor_fb;
133b153f901SGerd Hoffmann     bool have_hot;
134474114b7SGerd Hoffmann #endif
135e0c64d08SGerd Hoffmann };
136e0c64d08SGerd Hoffmann 
137e0c64d08SGerd Hoffmann struct SimpleSpiceUpdate {
138a3e22260SGerd Hoffmann     QXLDrawable drawable;
139a3e22260SGerd Hoffmann     QXLImage image;
140a3e22260SGerd Hoffmann     QXLCommandExt ext;
141a3e22260SGerd Hoffmann     uint8_t *bitmap;
142b1af98baSGerd Hoffmann     QTAILQ_ENTRY(SimpleSpiceUpdate) next;
143e0c64d08SGerd Hoffmann };
144a3e22260SGerd Hoffmann 
1455643fc01SGerd Hoffmann struct SimpleSpiceCursor {
1465643fc01SGerd Hoffmann     QXLCursorCmd cmd;
1475643fc01SGerd Hoffmann     QXLCommandExt ext;
1485643fc01SGerd Hoffmann     QXLCursor cursor;
1495643fc01SGerd Hoffmann };
1505643fc01SGerd Hoffmann 
151fe5c44f9SGerd Hoffmann extern bool spice_opengl;
152fe5c44f9SGerd Hoffmann 
153a3e22260SGerd Hoffmann int qemu_spice_rect_is_empty(const QXLRect* r);
154a3e22260SGerd Hoffmann void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
155a3e22260SGerd Hoffmann 
156a3e22260SGerd Hoffmann void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update);
157a3e22260SGerd Hoffmann void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
158a3e22260SGerd Hoffmann void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
159a3e22260SGerd Hoffmann void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
160c78f7137SGerd Hoffmann void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd);
161a3e22260SGerd Hoffmann 
162a3e22260SGerd Hoffmann void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
163a3e22260SGerd Hoffmann                                int x, int y, int w, int h);
164c12aeb86SGerd Hoffmann void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
165c12aeb86SGerd Hoffmann                                DisplaySurface *surface);
166a3e22260SGerd Hoffmann void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
1670b2824e5SGerd Hoffmann void qemu_spice_cursor_refresh_bh(void *opaque);
1685c59d118SGerd Hoffmann 
1695ff4e36cSAlon Levy void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
1705ff4e36cSAlon Levy                             qxl_async_io async);
1715c59d118SGerd Hoffmann void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
1725c59d118SGerd Hoffmann                             uint32_t sid);
1735c59d118SGerd Hoffmann void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
1745ff4e36cSAlon Levy                                        QXLDevSurfaceCreate *surface,
1755ff4e36cSAlon Levy                                        qxl_async_io async);
1765ff4e36cSAlon Levy void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
1775ff4e36cSAlon Levy                                         uint32_t id, qxl_async_io async);
1785c59d118SGerd Hoffmann void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
17971d388d4SYonit Halperin void qemu_spice_display_start(void);
18071d388d4SYonit Halperin void qemu_spice_display_stop(void);
18171d388d4SYonit Halperin int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
182*be812c0aSLukáš Hrázký 
183*be812c0aSLukáš Hrázký bool qemu_spice_fill_device_address(QemuConsole *con,
184*be812c0aSLukáš Hrázký                                     char *device_address,
185*be812c0aSLukáš Hrázký                                     size_t size);
186