pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 1 | #ifndef CONSOLE_H |
| 2 | #define CONSOLE_H |
| 3 | |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 4 | #include "ui/qemu-pixman.h" |
Gerd Hoffmann | 95be066 | 2013-04-17 09:45:10 +0200 | [diff] [blame] | 5 | #include "qom/object.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 6 | #include "qemu/notify.h" |
Eduardo Habkost | f8c75b2 | 2016-04-19 16:55:18 -0300 | [diff] [blame] | 7 | #include "qemu/error-report.h" |
Markus Armbruster | 9af2398 | 2018-02-11 10:36:01 +0100 | [diff] [blame] | 8 | #include "qapi/qapi-types-ui.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 9 | |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 10 | #ifdef CONFIG_OPENGL |
Gerd Hoffmann | dcf3002 | 2015-05-11 12:24:43 +0200 | [diff] [blame] | 11 | # include <epoxy/gl.h> |
Gerd Hoffmann | 46e19e1 | 2017-10-10 15:54:49 +0200 | [diff] [blame] | 12 | # include "ui/shader.h" |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 13 | #endif |
| 14 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 15 | /* keyboard/mouse support */ |
| 16 | |
| 17 | #define MOUSE_EVENT_LBUTTON 0x01 |
| 18 | #define MOUSE_EVENT_RBUTTON 0x02 |
| 19 | #define MOUSE_EVENT_MBUTTON 0x04 |
Gerd Hoffmann | 21bae11 | 2013-12-04 14:08:04 +0100 | [diff] [blame] | 20 | #define MOUSE_EVENT_WHEELUP 0x08 |
| 21 | #define MOUSE_EVENT_WHEELDN 0x10 |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 22 | |
Gerd Hoffmann | 03a23a8 | 2010-02-26 17:17:36 +0100 | [diff] [blame] | 23 | /* identical to the ps/2 keyboard bits */ |
| 24 | #define QEMU_SCROLL_LOCK_LED (1 << 0) |
| 25 | #define QEMU_NUM_LOCK_LED (1 << 1) |
| 26 | #define QEMU_CAPS_LOCK_LED (1 << 2) |
| 27 | |
aliguori | 7ed9eba | 2008-08-21 20:12:05 +0000 | [diff] [blame] | 28 | /* in ms */ |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 29 | #define GUI_REFRESH_INTERVAL_DEFAULT 30 |
| 30 | #define GUI_REFRESH_INTERVAL_IDLE 3000 |
aliguori | 7ed9eba | 2008-08-21 20:12:05 +0000 | [diff] [blame] | 31 | |
OGAWA Hirofumi | 4083733 | 2015-11-29 22:28:24 +0900 | [diff] [blame] | 32 | /* Color number is match to standard vga palette */ |
| 33 | enum qemu_color_names { |
| 34 | QEMU_COLOR_BLACK = 0, |
| 35 | QEMU_COLOR_BLUE = 1, |
| 36 | QEMU_COLOR_GREEN = 2, |
| 37 | QEMU_COLOR_CYAN = 3, |
| 38 | QEMU_COLOR_RED = 4, |
| 39 | QEMU_COLOR_MAGENTA = 5, |
| 40 | QEMU_COLOR_YELLOW = 6, |
| 41 | QEMU_COLOR_WHITE = 7 |
| 42 | }; |
| 43 | /* Convert to curses char attributes */ |
| 44 | #define ATTR2CHTYPE(c, fg, bg, bold) \ |
| 45 | ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c)) |
| 46 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 47 | typedef void QEMUPutKBDEvent(void *opaque, int keycode); |
Gerd Hoffmann | 03a23a8 | 2010-02-26 17:17:36 +0100 | [diff] [blame] | 48 | typedef void QEMUPutLEDEvent(void *opaque, int ledstate); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 49 | typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state); |
| 50 | |
Gerd Hoffmann | 72711ef | 2013-04-24 12:08:37 +0200 | [diff] [blame] | 51 | typedef struct QEMUPutMouseEntry QEMUPutMouseEntry; |
Gerd Hoffmann | 5a37532 | 2013-04-24 12:08:38 +0200 | [diff] [blame] | 52 | typedef struct QEMUPutKbdEntry QEMUPutKbdEntry; |
Gerd Hoffmann | 72711ef | 2013-04-24 12:08:37 +0200 | [diff] [blame] | 53 | typedef struct QEMUPutLEDEntry QEMUPutLEDEntry; |
Gerd Hoffmann | 03a23a8 | 2010-02-26 17:17:36 +0100 | [diff] [blame] | 54 | |
Gerd Hoffmann | 5a37532 | 2013-04-24 12:08:38 +0200 | [diff] [blame] | 55 | QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, |
| 56 | void *opaque); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 57 | QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, |
| 58 | void *opaque, int absolute, |
| 59 | const char *name); |
| 60 | void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry); |
Anthony Liguori | 6fef28e | 2010-03-09 20:52:22 -0600 | [diff] [blame] | 61 | void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry); |
| 62 | |
Gerd Hoffmann | 03a23a8 | 2010-02-26 17:17:36 +0100 | [diff] [blame] | 63 | QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque); |
| 64 | void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 65 | |
Gerd Hoffmann | 03a23a8 | 2010-02-26 17:17:36 +0100 | [diff] [blame] | 66 | void kbd_put_ledstate(int ledstate); |
Anthony Liguori | eb2e259 | 2010-03-09 14:26:40 -0600 | [diff] [blame] | 67 | |
Philippe Mathieu-Daudé | 5a4c2e5 | 2019-01-14 14:08:28 +0100 | [diff] [blame] | 68 | typedef struct MouseTransformInfo { |
balrog | a5d7eb6 | 2008-04-14 21:28:11 +0000 | [diff] [blame] | 69 | /* Touchscreen resolution */ |
| 70 | int x; |
| 71 | int y; |
| 72 | /* Calibration values as used/generated by tslib */ |
| 73 | int a[7]; |
Philippe Mathieu-Daudé | 5a4c2e5 | 2019-01-14 14:08:28 +0100 | [diff] [blame] | 74 | } MouseTransformInfo; |
balrog | a5d7eb6 | 2008-04-14 21:28:11 +0000 | [diff] [blame] | 75 | |
Markus Armbruster | 3e5a50d | 2015-02-06 13:55:43 +0100 | [diff] [blame] | 76 | void hmp_mouse_set(Monitor *mon, const QDict *qdict); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 77 | |
| 78 | /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx |
| 79 | constants) */ |
| 80 | #define QEMU_KEY_ESC1(c) ((c) | 0xe100) |
| 81 | #define QEMU_KEY_BACKSPACE 0x007f |
| 82 | #define QEMU_KEY_UP QEMU_KEY_ESC1('A') |
| 83 | #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B') |
| 84 | #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C') |
| 85 | #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D') |
| 86 | #define QEMU_KEY_HOME QEMU_KEY_ESC1(1) |
| 87 | #define QEMU_KEY_END QEMU_KEY_ESC1(4) |
| 88 | #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5) |
| 89 | #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6) |
| 90 | #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3) |
| 91 | |
| 92 | #define QEMU_KEY_CTRL_UP 0xe400 |
| 93 | #define QEMU_KEY_CTRL_DOWN 0xe401 |
| 94 | #define QEMU_KEY_CTRL_LEFT 0xe402 |
| 95 | #define QEMU_KEY_CTRL_RIGHT 0xe403 |
| 96 | #define QEMU_KEY_CTRL_HOME 0xe404 |
| 97 | #define QEMU_KEY_CTRL_END 0xe405 |
| 98 | #define QEMU_KEY_CTRL_PAGEUP 0xe406 |
| 99 | #define QEMU_KEY_CTRL_PAGEDOWN 0xe407 |
| 100 | |
Gerd Hoffmann | 3f9a6e8 | 2014-05-22 12:05:52 +0200 | [diff] [blame] | 101 | void kbd_put_keysym_console(QemuConsole *s, int keysym); |
Gerd Hoffmann | da024b1 | 2018-03-21 14:50:36 +0100 | [diff] [blame] | 102 | bool kbd_put_qcode_console(QemuConsole *s, int qcode, bool ctrl); |
Gerd Hoffmann | bdef972 | 2014-05-27 09:32:36 +0200 | [diff] [blame] | 103 | void kbd_put_string_console(QemuConsole *s, const char *str, int len); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 104 | void kbd_put_keysym(int keysym); |
| 105 | |
| 106 | /* consoles */ |
| 107 | |
Gerd Hoffmann | 95be066 | 2013-04-17 09:45:10 +0200 | [diff] [blame] | 108 | #define TYPE_QEMU_CONSOLE "qemu-console" |
| 109 | #define QEMU_CONSOLE(obj) \ |
| 110 | OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE) |
| 111 | #define QEMU_CONSOLE_GET_CLASS(obj) \ |
| 112 | OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE) |
| 113 | #define QEMU_CONSOLE_CLASS(klass) \ |
| 114 | OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE) |
| 115 | |
| 116 | typedef struct QemuConsoleClass QemuConsoleClass; |
| 117 | |
| 118 | struct QemuConsoleClass { |
| 119 | ObjectClass parent_class; |
| 120 | }; |
| 121 | |
Benjamin Herrenschmidt | 77bfcf2 | 2014-06-21 14:58:06 +1000 | [diff] [blame] | 122 | #define QEMU_ALLOCATED_FLAG 0x01 |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 123 | |
Philippe Mathieu-Daudé | 7536587 | 2019-01-11 15:08:56 +0100 | [diff] [blame] | 124 | typedef struct DisplaySurface { |
Gerd Hoffmann | 69c7777 | 2012-09-26 15:20:05 +0200 | [diff] [blame] | 125 | pixman_format_code_t format; |
| 126 | pixman_image_t *image; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 127 | uint8_t flags; |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 128 | #ifdef CONFIG_OPENGL |
| 129 | GLenum glformat; |
| 130 | GLenum gltype; |
| 131 | GLuint texture; |
| 132 | #endif |
Philippe Mathieu-Daudé | 7536587 | 2019-01-11 15:08:56 +0100 | [diff] [blame] | 133 | } DisplaySurface; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 134 | |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 135 | typedef struct QemuUIInfo { |
| 136 | /* geometry */ |
| 137 | int xoff; |
| 138 | int yoff; |
| 139 | uint32_t width; |
| 140 | uint32_t height; |
| 141 | } QemuUIInfo; |
| 142 | |
Gerd Hoffmann | 254e595 | 2010-05-21 11:54:32 +0200 | [diff] [blame] | 143 | /* cursor data format is 32bit RGBA */ |
| 144 | typedef struct QEMUCursor { |
| 145 | int width, height; |
| 146 | int hot_x, hot_y; |
| 147 | int refcount; |
| 148 | uint32_t data[]; |
| 149 | } QEMUCursor; |
| 150 | |
| 151 | QEMUCursor *cursor_alloc(int width, int height); |
| 152 | void cursor_get(QEMUCursor *c); |
| 153 | void cursor_put(QEMUCursor *c); |
| 154 | QEMUCursor *cursor_builtin_hidden(void); |
| 155 | QEMUCursor *cursor_builtin_left_ptr(void); |
| 156 | void cursor_print_ascii_art(QEMUCursor *c, const char *prefix); |
| 157 | int cursor_get_mono_bpl(QEMUCursor *c); |
| 158 | void cursor_set_mono(QEMUCursor *c, |
| 159 | uint32_t foreground, uint32_t background, uint8_t *image, |
| 160 | int transparent, uint8_t *mask); |
| 161 | void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask); |
| 162 | void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask); |
| 163 | |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 164 | typedef void *QEMUGLContext; |
| 165 | typedef struct QEMUGLParams QEMUGLParams; |
| 166 | |
| 167 | struct QEMUGLParams { |
| 168 | int major_ver; |
| 169 | int minor_ver; |
| 170 | }; |
| 171 | |
Philippe Mathieu-Daudé | dfbb251 | 2019-01-11 15:08:55 +0100 | [diff] [blame] | 172 | typedef struct QemuDmaBuf { |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 173 | int fd; |
| 174 | uint32_t width; |
| 175 | uint32_t height; |
| 176 | uint32_t stride; |
| 177 | uint32_t fourcc; |
Gerd Hoffmann | 152b7af | 2019-05-29 09:21:41 +0200 | [diff] [blame] | 178 | uint64_t modifier; |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 179 | uint32_t texture; |
Marc-André Lureau | 242d013 | 2018-07-13 15:08:51 +0200 | [diff] [blame] | 180 | bool y0_top; |
Philippe Mathieu-Daudé | dfbb251 | 2019-01-11 15:08:55 +0100 | [diff] [blame] | 181 | } QemuDmaBuf; |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 182 | |
Philippe Mathieu-Daudé | 7536587 | 2019-01-11 15:08:56 +0100 | [diff] [blame] | 183 | typedef struct DisplayState DisplayState; |
| 184 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 185 | typedef struct DisplayChangeListenerOps { |
| 186 | const char *dpy_name; |
| 187 | |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 188 | void (*dpy_refresh)(DisplayChangeListener *dcl); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 189 | |
| 190 | void (*dpy_gfx_update)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 191 | int x, int y, int w, int h); |
Gerd Hoffmann | c12aeb8 | 2013-02-28 15:03:04 +0100 | [diff] [blame] | 192 | void (*dpy_gfx_switch)(DisplayChangeListener *dcl, |
Gerd Hoffmann | c12aeb8 | 2013-02-28 15:03:04 +0100 | [diff] [blame] | 193 | struct DisplaySurface *new_surface); |
Benjamin Herrenschmidt | 49743df | 2014-07-07 16:39:05 +1000 | [diff] [blame] | 194 | bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl, |
| 195 | pixman_format_code_t format); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 196 | |
| 197 | void (*dpy_text_cursor)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 198 | int x, int y); |
| 199 | void (*dpy_text_resize)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 200 | int w, int h); |
| 201 | void (*dpy_text_update)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 202 | int x, int y, int w, int h); |
| 203 | |
| 204 | void (*dpy_mouse_set)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 205 | int x, int y, int on); |
| 206 | void (*dpy_cursor_define)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 207 | QEMUCursor *cursor); |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 208 | |
| 209 | QEMUGLContext (*dpy_gl_ctx_create)(DisplayChangeListener *dcl, |
| 210 | QEMUGLParams *params); |
| 211 | void (*dpy_gl_ctx_destroy)(DisplayChangeListener *dcl, |
| 212 | QEMUGLContext ctx); |
| 213 | int (*dpy_gl_ctx_make_current)(DisplayChangeListener *dcl, |
| 214 | QEMUGLContext ctx); |
| 215 | QEMUGLContext (*dpy_gl_ctx_get_current)(DisplayChangeListener *dcl); |
| 216 | |
Gerd Hoffmann | eaa92c7 | 2017-02-21 10:37:17 +0100 | [diff] [blame] | 217 | void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl); |
Gerd Hoffmann | f4c36bd | 2017-02-21 10:37:16 +0100 | [diff] [blame] | 218 | void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl, |
| 219 | uint32_t backing_id, |
| 220 | bool backing_y_0_top, |
| 221 | uint32_t backing_width, |
| 222 | uint32_t backing_height, |
| 223 | uint32_t x, uint32_t y, |
| 224 | uint32_t w, uint32_t h); |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 225 | void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl, |
| 226 | QemuDmaBuf *dmabuf); |
| 227 | void (*dpy_gl_cursor_dmabuf)(DisplayChangeListener *dcl, |
Gerd Hoffmann | 6e1f2cb | 2018-02-20 12:04:31 +0100 | [diff] [blame] | 228 | QemuDmaBuf *dmabuf, bool have_hot, |
| 229 | uint32_t hot_x, uint32_t hot_y); |
| 230 | void (*dpy_gl_cursor_position)(DisplayChangeListener *dcl, |
| 231 | uint32_t pos_x, uint32_t pos_y); |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 232 | void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl, |
| 233 | QemuDmaBuf *dmabuf); |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 234 | void (*dpy_gl_update)(DisplayChangeListener *dcl, |
| 235 | uint32_t x, uint32_t y, uint32_t w, uint32_t h); |
| 236 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 237 | } DisplayChangeListenerOps; |
| 238 | |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 239 | struct DisplayChangeListener { |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 240 | uint64_t update_interval; |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 241 | const DisplayChangeListenerOps *ops; |
| 242 | DisplayState *ds; |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 243 | QemuConsole *con; |
Gerd Hoffmann | bf2fde7 | 2012-09-12 07:56:45 +0200 | [diff] [blame] | 244 | |
Gerd Hoffmann | 87e487a | 2010-06-04 11:46:35 +0200 | [diff] [blame] | 245 | QLIST_ENTRY(DisplayChangeListener) next; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 248 | DisplayState *init_displaystate(void); |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 249 | DisplaySurface *qemu_create_displaysurface_from(int width, int height, |
| 250 | pixman_format_code_t format, |
| 251 | int linesize, uint8_t *data); |
Gerd Hoffmann | ca58b45 | 2016-04-01 10:27:20 +0200 | [diff] [blame] | 252 | DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image); |
Gerd Hoffmann | 2e5567c | 2018-03-08 17:18:03 +0100 | [diff] [blame] | 253 | DisplaySurface *qemu_create_message_surface(int w, int h, |
| 254 | const char *msg); |
malc | 0da2ea1 | 2009-01-23 19:56:19 +0000 | [diff] [blame] | 255 | PixelFormat qemu_default_pixelformat(int bpp); |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 256 | |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 257 | DisplaySurface *qemu_create_displaysurface(int width, int height); |
| 258 | void qemu_free_displaysurface(DisplaySurface *surface); |
aliguori | 7b5d76d | 2009-03-13 15:02:13 +0000 | [diff] [blame] | 259 | |
| 260 | static inline int is_surface_bgr(DisplaySurface *surface) |
| 261 | { |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 262 | if (PIXMAN_FORMAT_BPP(surface->format) == 32 && |
| 263 | PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) { |
aliguori | 7b5d76d | 2009-03-13 15:02:13 +0000 | [diff] [blame] | 264 | return 1; |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 265 | } else { |
aliguori | 7b5d76d | 2009-03-13 15:02:13 +0000 | [diff] [blame] | 266 | return 0; |
Gerd Hoffmann | 30f1e66 | 2014-06-18 11:03:15 +0200 | [diff] [blame] | 267 | } |
aliguori | 7b5d76d | 2009-03-13 15:02:13 +0000 | [diff] [blame] | 268 | } |
| 269 | |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 270 | static inline int is_buffer_shared(DisplaySurface *surface) |
| 271 | { |
Gerd Hoffmann | 187cd1d | 2012-09-26 07:46:20 +0200 | [diff] [blame] | 272 | return !(surface->flags & QEMU_ALLOCATED_FLAG); |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Gerd Hoffmann | 5209089 | 2013-04-23 15:44:31 +0200 | [diff] [blame] | 275 | void register_displaychangelistener(DisplayChangeListener *dcl); |
Gerd Hoffmann | 0f7b286 | 2013-03-14 11:56:16 +0100 | [diff] [blame] | 276 | void update_displaychangelistener(DisplayChangeListener *dcl, |
| 277 | uint64_t interval); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 278 | void unregister_displaychangelistener(DisplayChangeListener *dcl); |
Gerd Hoffmann | 35c9e0a | 2010-06-04 11:51:31 +0200 | [diff] [blame] | 279 | |
Gerd Hoffmann | b7fb49f | 2015-03-13 12:21:14 +0100 | [diff] [blame] | 280 | bool dpy_ui_info_supported(QemuConsole *con); |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 281 | int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info); |
| 282 | |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 283 | void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h); |
Tina Zhang | 7cd0afe | 2018-04-27 17:11:05 +0800 | [diff] [blame] | 284 | void dpy_gfx_update_full(QemuConsole *con); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 285 | void dpy_gfx_replace_surface(QemuConsole *con, |
Gerd Hoffmann | da229ef | 2013-02-28 10:48:02 +0100 | [diff] [blame] | 286 | DisplaySurface *surface); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 287 | void dpy_text_cursor(QemuConsole *con, int x, int y); |
| 288 | void dpy_text_update(QemuConsole *con, int x, int y, int w, int h); |
| 289 | void dpy_text_resize(QemuConsole *con, int w, int h); |
| 290 | void dpy_mouse_set(QemuConsole *con, int x, int y, int on); |
| 291 | void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor); |
| 292 | bool dpy_cursor_define_supported(QemuConsole *con); |
Benjamin Herrenschmidt | 49743df | 2014-07-07 16:39:05 +1000 | [diff] [blame] | 293 | bool dpy_gfx_check_format(QemuConsole *con, |
| 294 | pixman_format_code_t format); |
Gerd Hoffmann | bf2fde7 | 2012-09-12 07:56:45 +0200 | [diff] [blame] | 295 | |
Gerd Hoffmann | eaa92c7 | 2017-02-21 10:37:17 +0100 | [diff] [blame] | 296 | void dpy_gl_scanout_disable(QemuConsole *con); |
Gerd Hoffmann | f4c36bd | 2017-02-21 10:37:16 +0100 | [diff] [blame] | 297 | void dpy_gl_scanout_texture(QemuConsole *con, |
| 298 | uint32_t backing_id, bool backing_y_0_top, |
| 299 | uint32_t backing_width, uint32_t backing_height, |
| 300 | uint32_t x, uint32_t y, uint32_t w, uint32_t h); |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 301 | void dpy_gl_scanout_dmabuf(QemuConsole *con, |
| 302 | QemuDmaBuf *dmabuf); |
Gerd Hoffmann | 6e1f2cb | 2018-02-20 12:04:31 +0100 | [diff] [blame] | 303 | void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf, |
| 304 | bool have_hot, uint32_t hot_x, uint32_t hot_y); |
| 305 | void dpy_gl_cursor_position(QemuConsole *con, |
| 306 | uint32_t pos_x, uint32_t pos_y); |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 307 | void dpy_gl_release_dmabuf(QemuConsole *con, |
| 308 | QemuDmaBuf *dmabuf); |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 309 | void dpy_gl_update(QemuConsole *con, |
| 310 | uint32_t x, uint32_t y, uint32_t w, uint32_t h); |
| 311 | |
| 312 | QEMUGLContext dpy_gl_ctx_create(QemuConsole *con, |
| 313 | QEMUGLParams *params); |
| 314 | void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx); |
| 315 | int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx); |
| 316 | QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con); |
| 317 | |
| 318 | bool console_has_gl(QemuConsole *con); |
Gerd Hoffmann | 4133fa7 | 2017-10-10 15:54:48 +0200 | [diff] [blame] | 319 | bool console_has_gl_dmabuf(QemuConsole *con); |
Gerd Hoffmann | 06020b9 | 2014-07-11 13:56:51 +0200 | [diff] [blame] | 320 | |
Gerd Hoffmann | 626e3b3 | 2013-02-28 15:24:14 +0100 | [diff] [blame] | 321 | static inline int surface_stride(DisplaySurface *s) |
| 322 | { |
| 323 | return pixman_image_get_stride(s->image); |
| 324 | } |
| 325 | |
| 326 | static inline void *surface_data(DisplaySurface *s) |
| 327 | { |
| 328 | return pixman_image_get_data(s->image); |
| 329 | } |
| 330 | |
| 331 | static inline int surface_width(DisplaySurface *s) |
| 332 | { |
| 333 | return pixman_image_get_width(s->image); |
| 334 | } |
| 335 | |
| 336 | static inline int surface_height(DisplaySurface *s) |
| 337 | { |
| 338 | return pixman_image_get_height(s->image); |
| 339 | } |
| 340 | |
| 341 | static inline int surface_bits_per_pixel(DisplaySurface *s) |
| 342 | { |
| 343 | int bits = PIXMAN_FORMAT_BPP(s->format); |
| 344 | return bits; |
| 345 | } |
| 346 | |
| 347 | static inline int surface_bytes_per_pixel(DisplaySurface *s) |
| 348 | { |
| 349 | int bits = PIXMAN_FORMAT_BPP(s->format); |
Marc-André Lureau | d1a0945 | 2017-06-22 13:04:16 +0200 | [diff] [blame] | 350 | return DIV_ROUND_UP(bits, 8); |
Gerd Hoffmann | 626e3b3 | 2013-02-28 15:24:14 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Max Reitz | e444ea3 | 2015-03-03 12:25:27 -0500 | [diff] [blame] | 353 | static inline pixman_format_code_t surface_format(DisplaySurface *s) |
| 354 | { |
| 355 | return s->format; |
| 356 | } |
| 357 | |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 358 | typedef uint32_t console_ch_t; |
| 359 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 360 | static inline void console_write_ch(console_ch_t *dest, uint32_t ch) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 361 | { |
Aurelien Jarno | 9ae19b6 | 2011-01-04 21:58:24 +0100 | [diff] [blame] | 362 | *dest = ch; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Gerd Hoffmann | 380cd05 | 2013-03-13 14:04:18 +0100 | [diff] [blame] | 365 | typedef struct GraphicHwOps { |
| 366 | void (*invalidate)(void *opaque); |
| 367 | void (*gfx_update)(void *opaque); |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame^] | 368 | bool gfx_update_async; /* if true, calls graphic_hw_update_done() */ |
Gerd Hoffmann | 380cd05 | 2013-03-13 14:04:18 +0100 | [diff] [blame] | 369 | void (*text_update)(void *opaque, console_ch_t *text); |
Gerd Hoffmann | dea1b0b | 2013-03-19 15:01:02 +0100 | [diff] [blame] | 370 | void (*update_interval)(void *opaque, uint64_t interval); |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 371 | int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info); |
Gerd Hoffmann | bba19b8 | 2015-12-03 12:34:25 +0100 | [diff] [blame] | 372 | void (*gl_block)(void *opaque, bool block); |
Gerd Hoffmann | 380cd05 | 2013-03-13 14:04:18 +0100 | [diff] [blame] | 373 | } GraphicHwOps; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 374 | |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 375 | QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head, |
Gerd Hoffmann | aa2beaa | 2013-04-17 10:21:27 +0200 | [diff] [blame] | 376 | const GraphicHwOps *ops, |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 377 | void *opaque); |
Gerd Hoffmann | 1c1f949 | 2014-09-24 17:05:27 +0200 | [diff] [blame] | 378 | void graphic_console_set_hwops(QemuConsole *con, |
| 379 | const GraphicHwOps *hw_ops, |
| 380 | void *opaque); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 381 | void graphic_console_close(QemuConsole *con); |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 382 | |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 383 | void graphic_hw_update(QemuConsole *con); |
Marc-André Lureau | 4d63162 | 2015-08-24 13:20:49 +0200 | [diff] [blame^] | 384 | void graphic_hw_update_done(QemuConsole *con); |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 385 | void graphic_hw_invalidate(QemuConsole *con); |
| 386 | void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata); |
Gerd Hoffmann | bba19b8 | 2015-12-03 12:34:25 +0100 | [diff] [blame] | 387 | void graphic_hw_gl_block(QemuConsole *con, bool block); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 388 | |
Marc-André Lureau | 777357d | 2016-12-07 18:39:10 +0300 | [diff] [blame] | 389 | void qemu_console_early_init(void); |
| 390 | |
Gerd Hoffmann | 284d1c6 | 2013-03-15 15:45:54 +0100 | [diff] [blame] | 391 | QemuConsole *qemu_console_lookup_by_index(unsigned int index); |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 392 | QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head); |
Gerd Hoffmann | f2c1d54 | 2016-01-12 11:45:43 +0100 | [diff] [blame] | 393 | QemuConsole *qemu_console_lookup_by_device_name(const char *device_id, |
| 394 | uint32_t head, Error **errp); |
Gerd Hoffmann | 9588d67 | 2018-03-13 11:17:29 -0600 | [diff] [blame] | 395 | QemuConsole *qemu_console_lookup_unused(void); |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 396 | bool qemu_console_is_visible(QemuConsole *con); |
| 397 | bool qemu_console_is_graphic(QemuConsole *con); |
| 398 | bool qemu_console_is_fixedsize(QemuConsole *con); |
Gerd Hoffmann | f607867 | 2016-09-23 09:50:27 +0200 | [diff] [blame] | 399 | bool qemu_console_is_gl_blocked(QemuConsole *con); |
Gerd Hoffmann | 779ce88 | 2015-02-17 10:41:08 +0100 | [diff] [blame] | 400 | char *qemu_console_get_label(QemuConsole *con); |
Gerd Hoffmann | d4c8533 | 2013-11-28 09:58:18 +0100 | [diff] [blame] | 401 | int qemu_console_get_index(QemuConsole *con); |
Gerd Hoffmann | 5643706 | 2014-01-24 15:35:21 +0100 | [diff] [blame] | 402 | uint32_t qemu_console_get_head(QemuConsole *con); |
Gerd Hoffmann | 6f90f3d | 2014-01-24 17:38:20 +0100 | [diff] [blame] | 403 | QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con); |
Gerd Hoffmann | d4c8533 | 2013-11-28 09:58:18 +0100 | [diff] [blame] | 404 | int qemu_console_get_width(QemuConsole *con, int fallback); |
| 405 | int qemu_console_get_height(QemuConsole *con, int fallback); |
Samuel Thibault | b3cb21b | 2016-12-21 01:38:04 +0100 | [diff] [blame] | 406 | /* Return the low-level window id for the console */ |
| 407 | int qemu_console_get_window_id(QemuConsole *con); |
| 408 | /* Set the low-level window id for the console */ |
| 409 | void qemu_console_set_window_id(QemuConsole *con, int window_id); |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 410 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 411 | void console_select(unsigned int index); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 412 | void qemu_console_resize(QemuConsole *con, int width, int height); |
Gerd Hoffmann | c78f713 | 2013-03-05 15:24:14 +0100 | [diff] [blame] | 413 | DisplaySurface *qemu_console_surface(QemuConsole *con); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 414 | |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 415 | /* console-gl.c */ |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 416 | #ifdef CONFIG_OPENGL |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 417 | bool console_gl_check_format(DisplayChangeListener *dcl, |
| 418 | pixman_format_code_t format); |
Gerd Hoffmann | 46e19e1 | 2017-10-10 15:54:49 +0200 | [diff] [blame] | 419 | void surface_gl_create_texture(QemuGLShader *gls, |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 420 | DisplaySurface *surface); |
Gerd Hoffmann | 46e19e1 | 2017-10-10 15:54:49 +0200 | [diff] [blame] | 421 | void surface_gl_update_texture(QemuGLShader *gls, |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 422 | DisplaySurface *surface, |
| 423 | int x, int y, int w, int h); |
Gerd Hoffmann | 46e19e1 | 2017-10-10 15:54:49 +0200 | [diff] [blame] | 424 | void surface_gl_render_texture(QemuGLShader *gls, |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 425 | DisplaySurface *surface); |
Gerd Hoffmann | 46e19e1 | 2017-10-10 15:54:49 +0200 | [diff] [blame] | 426 | void surface_gl_destroy_texture(QemuGLShader *gls, |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 427 | DisplaySurface *surface); |
Gerd Hoffmann | 46e19e1 | 2017-10-10 15:54:49 +0200 | [diff] [blame] | 428 | void surface_gl_setup_viewport(QemuGLShader *gls, |
Gerd Hoffmann | cd2bc88 | 2015-01-09 11:40:23 +0100 | [diff] [blame] | 429 | DisplaySurface *surface, |
| 430 | int ww, int wh); |
| 431 | #endif |
| 432 | |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 433 | typedef struct QemuDisplay QemuDisplay; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 434 | |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 435 | struct QemuDisplay { |
| 436 | DisplayType type; |
| 437 | void (*early_init)(DisplayOptions *opts); |
| 438 | void (*init)(DisplayState *ds, DisplayOptions *opts); |
| 439 | }; |
| 440 | |
| 441 | void qemu_display_register(QemuDisplay *ui); |
Gerd Hoffmann | 898f9d4 | 2018-03-01 11:05:40 +0100 | [diff] [blame] | 442 | bool qemu_display_find_default(DisplayOptions *opts); |
Gerd Hoffmann | db71589 | 2018-03-01 11:05:35 +0100 | [diff] [blame] | 443 | void qemu_display_early_init(DisplayOptions *opts); |
| 444 | void qemu_display_init(DisplayState *ds, DisplayOptions *opts); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 445 | |
| 446 | /* vnc.c */ |
Fei Li | ab4f931 | 2018-10-17 10:26:50 +0200 | [diff] [blame] | 447 | void vnc_display_init(const char *id, Error **errp); |
Gerd Hoffmann | 4db1462 | 2014-09-16 12:33:03 +0200 | [diff] [blame] | 448 | void vnc_display_open(const char *id, Error **errp); |
Gerd Hoffmann | 14f7143 | 2014-07-29 12:24:55 +0200 | [diff] [blame] | 449 | void vnc_display_add_client(const char *id, int csock, bool skipauth); |
Gerd Hoffmann | 14f7143 | 2014-07-29 12:24:55 +0200 | [diff] [blame] | 450 | int vnc_display_password(const char *id, const char *password); |
| 451 | int vnc_display_pw_expire(const char *id, time_t expires); |
Markus Armbruster | 70b9433 | 2015-02-13 12:50:26 +0100 | [diff] [blame] | 452 | QemuOpts *vnc_parse(const char *str, Error **errp); |
Markus Armbruster | 28d0de7 | 2015-03-13 13:35:14 +0100 | [diff] [blame] | 453 | int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 454 | |
Amos Kong | 1048c88 | 2012-08-31 10:56:25 +0800 | [diff] [blame] | 455 | /* input.c */ |
Wolfgang Bumiller | 64ffbe0 | 2016-01-13 09:09:58 +0100 | [diff] [blame] | 456 | int index_from_key(const char *key, size_t key_length); |
Amos Kong | 1048c88 | 2012-08-31 10:56:25 +0800 | [diff] [blame] | 457 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 458 | #endif |