]> git.proxmox.com Git - mirror_qemu.git/blame - include/ui/console.h
curses: switch over to new display registry
[mirror_qemu.git] / include / ui / console.h
CommitLineData
87ecb68b
PB
1#ifndef CONSOLE_H
2#define CONSOLE_H
3
28ecbaee 4#include "ui/qemu-pixman.h"
95be0669 5#include "qom/object.h"
1de7afc9 6#include "qemu/notify.h"
f8c75b24 7#include "qemu/error-report.h"
87ecb68b 8
cd2bc889 9#ifdef CONFIG_OPENGL
dcf30025 10# include <epoxy/gl.h>
46e19e14 11# include "ui/shader.h"
cd2bc889
GH
12#endif
13
87ecb68b
PB
14/* keyboard/mouse support */
15
16#define MOUSE_EVENT_LBUTTON 0x01
17#define MOUSE_EVENT_RBUTTON 0x02
18#define MOUSE_EVENT_MBUTTON 0x04
21bae11a
GH
19#define MOUSE_EVENT_WHEELUP 0x08
20#define MOUSE_EVENT_WHEELDN 0x10
87ecb68b 21
03a23a85
GH
22/* identical to the ps/2 keyboard bits */
23#define QEMU_SCROLL_LOCK_LED (1 << 0)
24#define QEMU_NUM_LOCK_LED (1 << 1)
25#define QEMU_CAPS_LOCK_LED (1 << 2)
26
7ed9eba3 27/* in ms */
0f7b2864
GH
28#define GUI_REFRESH_INTERVAL_DEFAULT 30
29#define GUI_REFRESH_INTERVAL_IDLE 3000
7ed9eba3 30
4083733d
OH
31/* Color number is match to standard vga palette */
32enum qemu_color_names {
33 QEMU_COLOR_BLACK = 0,
34 QEMU_COLOR_BLUE = 1,
35 QEMU_COLOR_GREEN = 2,
36 QEMU_COLOR_CYAN = 3,
37 QEMU_COLOR_RED = 4,
38 QEMU_COLOR_MAGENTA = 5,
39 QEMU_COLOR_YELLOW = 6,
40 QEMU_COLOR_WHITE = 7
41};
42/* Convert to curses char attributes */
43#define ATTR2CHTYPE(c, fg, bg, bold) \
44 ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c))
45
87ecb68b 46typedef void QEMUPutKBDEvent(void *opaque, int keycode);
03a23a85 47typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
87ecb68b
PB
48typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
49
72711efb 50typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
5a37532d 51typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
72711efb 52typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
03a23a85 53
5a37532d
GH
54QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
55 void *opaque);
87ecb68b
PB
56QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
57 void *opaque, int absolute,
58 const char *name);
59void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
6fef28ee
AL
60void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
61
03a23a85
GH
62QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
63void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
87ecb68b 64
03a23a85 65void kbd_put_ledstate(int ledstate);
eb2e259d 66
bc24a225 67struct MouseTransformInfo {
a5d7eb65
AZ
68 /* Touchscreen resolution */
69 int x;
70 int y;
71 /* Calibration values as used/generated by tslib */
72 int a[7];
73};
74
3e5a50d6 75void hmp_mouse_set(Monitor *mon, const QDict *qdict);
87ecb68b
PB
76
77/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
78 constants) */
79#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
80#define QEMU_KEY_BACKSPACE 0x007f
81#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
82#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
83#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
84#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
85#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
86#define QEMU_KEY_END QEMU_KEY_ESC1(4)
87#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
88#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
89#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
90
91#define QEMU_KEY_CTRL_UP 0xe400
92#define QEMU_KEY_CTRL_DOWN 0xe401
93#define QEMU_KEY_CTRL_LEFT 0xe402
94#define QEMU_KEY_CTRL_RIGHT 0xe403
95#define QEMU_KEY_CTRL_HOME 0xe404
96#define QEMU_KEY_CTRL_END 0xe405
97#define QEMU_KEY_CTRL_PAGEUP 0xe406
98#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
99
3f9a6e85 100void kbd_put_keysym_console(QemuConsole *s, int keysym);
50ef4679 101bool kbd_put_qcode_console(QemuConsole *s, int qcode);
bdef9724 102void kbd_put_string_console(QemuConsole *s, const char *str, int len);
87ecb68b
PB
103void kbd_put_keysym(int keysym);
104
105/* consoles */
106
95be0669
GH
107#define TYPE_QEMU_CONSOLE "qemu-console"
108#define QEMU_CONSOLE(obj) \
109 OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE)
110#define QEMU_CONSOLE_GET_CLASS(obj) \
111 OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE)
112#define QEMU_CONSOLE_CLASS(klass) \
113 OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE)
114
115typedef struct QemuConsoleClass QemuConsoleClass;
116
117struct QemuConsoleClass {
118 ObjectClass parent_class;
119};
120
77bfcf28 121#define QEMU_ALLOCATED_FLAG 0x01
7d957bd8
AL
122
123struct PixelFormat {
124 uint8_t bits_per_pixel;
125 uint8_t bytes_per_pixel;
126 uint8_t depth; /* color depth in bits */
127 uint32_t rmask, gmask, bmask, amask;
128 uint8_t rshift, gshift, bshift, ashift;
129 uint8_t rmax, gmax, bmax, amax;
90a1e3c0 130 uint8_t rbits, gbits, bbits, abits;
7d957bd8
AL
131};
132
133struct DisplaySurface {
69c77777
GH
134 pixman_format_code_t format;
135 pixman_image_t *image;
7d957bd8 136 uint8_t flags;
cd2bc889
GH
137#ifdef CONFIG_OPENGL
138 GLenum glformat;
139 GLenum gltype;
140 GLuint texture;
141#endif
7d957bd8
AL
142};
143
6f90f3d7
GH
144typedef struct QemuUIInfo {
145 /* geometry */
146 int xoff;
147 int yoff;
148 uint32_t width;
149 uint32_t height;
150} QemuUIInfo;
151
254e5950
GH
152/* cursor data format is 32bit RGBA */
153typedef struct QEMUCursor {
154 int width, height;
155 int hot_x, hot_y;
156 int refcount;
157 uint32_t data[];
158} QEMUCursor;
159
160QEMUCursor *cursor_alloc(int width, int height);
161void cursor_get(QEMUCursor *c);
162void cursor_put(QEMUCursor *c);
163QEMUCursor *cursor_builtin_hidden(void);
164QEMUCursor *cursor_builtin_left_ptr(void);
165void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
166int cursor_get_mono_bpl(QEMUCursor *c);
167void cursor_set_mono(QEMUCursor *c,
168 uint32_t foreground, uint32_t background, uint8_t *image,
169 int transparent, uint8_t *mask);
170void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
171void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
172
06020b95
GH
173typedef void *QEMUGLContext;
174typedef struct QEMUGLParams QEMUGLParams;
175
176struct QEMUGLParams {
177 int major_ver;
178 int minor_ver;
179};
180
4133fa71
GH
181struct QemuDmaBuf {
182 int fd;
183 uint32_t width;
184 uint32_t height;
185 uint32_t stride;
186 uint32_t fourcc;
187 uint32_t texture;
188};
189
7c20b4a3
GH
190typedef struct DisplayChangeListenerOps {
191 const char *dpy_name;
192
bc2ed970 193 void (*dpy_refresh)(DisplayChangeListener *dcl);
7c20b4a3
GH
194
195 void (*dpy_gfx_update)(DisplayChangeListener *dcl,
7c20b4a3 196 int x, int y, int w, int h);
c12aeb86 197 void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
c12aeb86 198 struct DisplaySurface *new_surface);
49743df3
BH
199 bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
200 pixman_format_code_t format);
a93a4a22 201
7c20b4a3 202 void (*dpy_text_cursor)(DisplayChangeListener *dcl,
7c20b4a3
GH
203 int x, int y);
204 void (*dpy_text_resize)(DisplayChangeListener *dcl,
7c20b4a3
GH
205 int w, int h);
206 void (*dpy_text_update)(DisplayChangeListener *dcl,
7c20b4a3
GH
207 int x, int y, int w, int h);
208
209 void (*dpy_mouse_set)(DisplayChangeListener *dcl,
7c20b4a3
GH
210 int x, int y, int on);
211 void (*dpy_cursor_define)(DisplayChangeListener *dcl,
7c20b4a3 212 QEMUCursor *cursor);
06020b95
GH
213
214 QEMUGLContext (*dpy_gl_ctx_create)(DisplayChangeListener *dcl,
215 QEMUGLParams *params);
216 void (*dpy_gl_ctx_destroy)(DisplayChangeListener *dcl,
217 QEMUGLContext ctx);
218 int (*dpy_gl_ctx_make_current)(DisplayChangeListener *dcl,
219 QEMUGLContext ctx);
220 QEMUGLContext (*dpy_gl_ctx_get_current)(DisplayChangeListener *dcl);
221
eaa92c76 222 void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl);
f4c36bda
GH
223 void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
224 uint32_t backing_id,
225 bool backing_y_0_top,
226 uint32_t backing_width,
227 uint32_t backing_height,
228 uint32_t x, uint32_t y,
229 uint32_t w, uint32_t h);
4133fa71
GH
230 void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl,
231 QemuDmaBuf *dmabuf);
232 void (*dpy_gl_cursor_dmabuf)(DisplayChangeListener *dcl,
6e1f2cb5
GH
233 QemuDmaBuf *dmabuf, bool have_hot,
234 uint32_t hot_x, uint32_t hot_y);
235 void (*dpy_gl_cursor_position)(DisplayChangeListener *dcl,
236 uint32_t pos_x, uint32_t pos_y);
4133fa71
GH
237 void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl,
238 QemuDmaBuf *dmabuf);
06020b95
GH
239 void (*dpy_gl_update)(DisplayChangeListener *dcl,
240 uint32_t x, uint32_t y, uint32_t w, uint32_t h);
241
7c20b4a3 242} DisplayChangeListenerOps;
7d957bd8 243
7c20b4a3 244struct DisplayChangeListener {
0f7b2864 245 uint64_t update_interval;
7c20b4a3
GH
246 const DisplayChangeListenerOps *ops;
247 DisplayState *ds;
284d1c6b 248 QemuConsole *con;
bf2fde70 249
87e487a1 250 QLIST_ENTRY(DisplayChangeListener) next;
7d957bd8
AL
251};
252
64840c66 253DisplayState *init_displaystate(void);
30f1e661
GH
254DisplaySurface *qemu_create_displaysurface_from(int width, int height,
255 pixman_format_code_t format,
256 int linesize, uint8_t *data);
ca58b45f 257DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
a77549b3
GH
258DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height,
259 pixman_format_code_t format,
260 int linesize,
261 uint64_t addr);
0da2ea1b 262PixelFormat qemu_default_pixelformat(int bpp);
7d957bd8 263
da229ef3
GH
264DisplaySurface *qemu_create_displaysurface(int width, int height);
265void qemu_free_displaysurface(DisplaySurface *surface);
7b5d76da
AL
266
267static inline int is_surface_bgr(DisplaySurface *surface)
268{
30f1e661
GH
269 if (PIXMAN_FORMAT_BPP(surface->format) == 32 &&
270 PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) {
7b5d76da 271 return 1;
30f1e661 272 } else {
7b5d76da 273 return 0;
30f1e661 274 }
7b5d76da
AL
275}
276
7d957bd8
AL
277static inline int is_buffer_shared(DisplaySurface *surface)
278{
187cd1d9 279 return !(surface->flags & QEMU_ALLOCATED_FLAG);
7d957bd8
AL
280}
281
5209089f 282void register_displaychangelistener(DisplayChangeListener *dcl);
0f7b2864
GH
283void update_displaychangelistener(DisplayChangeListener *dcl,
284 uint64_t interval);
7c20b4a3
GH
285void unregister_displaychangelistener(DisplayChangeListener *dcl);
286
b7fb49f0 287bool dpy_ui_info_supported(QemuConsole *con);
6f90f3d7
GH
288int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info);
289
c78f7137
GH
290void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
291void dpy_gfx_replace_surface(QemuConsole *con,
da229ef3 292 DisplaySurface *surface);
c78f7137
GH
293void dpy_text_cursor(QemuConsole *con, int x, int y);
294void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
295void dpy_text_resize(QemuConsole *con, int w, int h);
296void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
297void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
298bool dpy_cursor_define_supported(QemuConsole *con);
49743df3
BH
299bool dpy_gfx_check_format(QemuConsole *con,
300 pixman_format_code_t format);
bf2fde70 301
eaa92c76 302void dpy_gl_scanout_disable(QemuConsole *con);
f4c36bda
GH
303void dpy_gl_scanout_texture(QemuConsole *con,
304 uint32_t backing_id, bool backing_y_0_top,
305 uint32_t backing_width, uint32_t backing_height,
306 uint32_t x, uint32_t y, uint32_t w, uint32_t h);
4133fa71
GH
307void dpy_gl_scanout_dmabuf(QemuConsole *con,
308 QemuDmaBuf *dmabuf);
6e1f2cb5
GH
309void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
310 bool have_hot, uint32_t hot_x, uint32_t hot_y);
311void dpy_gl_cursor_position(QemuConsole *con,
312 uint32_t pos_x, uint32_t pos_y);
4133fa71
GH
313void dpy_gl_release_dmabuf(QemuConsole *con,
314 QemuDmaBuf *dmabuf);
06020b95
GH
315void dpy_gl_update(QemuConsole *con,
316 uint32_t x, uint32_t y, uint32_t w, uint32_t h);
317
318QEMUGLContext dpy_gl_ctx_create(QemuConsole *con,
319 QEMUGLParams *params);
320void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx);
321int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx);
322QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con);
323
324bool console_has_gl(QemuConsole *con);
4133fa71 325bool console_has_gl_dmabuf(QemuConsole *con);
06020b95 326
626e3b34
GH
327static inline int surface_stride(DisplaySurface *s)
328{
329 return pixman_image_get_stride(s->image);
330}
331
332static inline void *surface_data(DisplaySurface *s)
333{
334 return pixman_image_get_data(s->image);
335}
336
337static inline int surface_width(DisplaySurface *s)
338{
339 return pixman_image_get_width(s->image);
340}
341
342static inline int surface_height(DisplaySurface *s)
343{
344 return pixman_image_get_height(s->image);
345}
346
347static inline int surface_bits_per_pixel(DisplaySurface *s)
348{
349 int bits = PIXMAN_FORMAT_BPP(s->format);
350 return bits;
351}
352
353static inline int surface_bytes_per_pixel(DisplaySurface *s)
354{
355 int bits = PIXMAN_FORMAT_BPP(s->format);
d1a0945f 356 return DIV_ROUND_UP(bits, 8);
626e3b34
GH
357}
358
e444ea34
HR
359static inline pixman_format_code_t surface_format(DisplaySurface *s)
360{
361 return s->format;
362}
363
e2f82e92
GH
364typedef uint32_t console_ch_t;
365
c227f099 366static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
4d3b6f6e 367{
9ae19b65 368 *dest = ch;
4d3b6f6e
AZ
369}
370
380cd056
GH
371typedef struct GraphicHwOps {
372 void (*invalidate)(void *opaque);
373 void (*gfx_update)(void *opaque);
374 void (*text_update)(void *opaque, console_ch_t *text);
dea1b0bd 375 void (*update_interval)(void *opaque, uint64_t interval);
6f90f3d7 376 int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
bba19b88 377 void (*gl_block)(void *opaque, bool block);
380cd056 378} GraphicHwOps;
87ecb68b 379
5643706a 380QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
aa2beaa1 381 const GraphicHwOps *ops,
c78f7137 382 void *opaque);
1c1f9498
GH
383void graphic_console_set_hwops(QemuConsole *con,
384 const GraphicHwOps *hw_ops,
385 void *opaque);
3023f332 386
1dbfa005
GH
387void graphic_hw_update(QemuConsole *con);
388void graphic_hw_invalidate(QemuConsole *con);
389void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
bba19b88 390void graphic_hw_gl_block(QemuConsole *con, bool block);
87ecb68b 391
777357d7
MAL
392void qemu_console_early_init(void);
393
284d1c6b 394QemuConsole *qemu_console_lookup_by_index(unsigned int index);
5643706a 395QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
f2c1d54c
GH
396QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
397 uint32_t head, Error **errp);
81c0d5a6
GH
398bool qemu_console_is_visible(QemuConsole *con);
399bool qemu_console_is_graphic(QemuConsole *con);
400bool qemu_console_is_fixedsize(QemuConsole *con);
f607867c 401bool qemu_console_is_gl_blocked(QemuConsole *con);
779ce88f 402char *qemu_console_get_label(QemuConsole *con);
d4c85337 403int qemu_console_get_index(QemuConsole *con);
5643706a 404uint32_t qemu_console_get_head(QemuConsole *con);
6f90f3d7 405QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
d4c85337
GH
406int qemu_console_get_width(QemuConsole *con, int fallback);
407int qemu_console_get_height(QemuConsole *con, int fallback);
b3cb21b9
ST
408/* Return the low-level window id for the console */
409int qemu_console_get_window_id(QemuConsole *con);
410/* Set the low-level window id for the console */
411void qemu_console_set_window_id(QemuConsole *con, int window_id);
81c0d5a6 412
87ecb68b 413void console_select(unsigned int index);
c78f7137 414void qemu_console_resize(QemuConsole *con, int width, int height);
c78f7137 415DisplaySurface *qemu_console_surface(QemuConsole *con);
87ecb68b 416
cd2bc889 417/* console-gl.c */
cd2bc889 418#ifdef CONFIG_OPENGL
cd2bc889
GH
419bool console_gl_check_format(DisplayChangeListener *dcl,
420 pixman_format_code_t format);
46e19e14 421void surface_gl_create_texture(QemuGLShader *gls,
cd2bc889 422 DisplaySurface *surface);
46e19e14 423void surface_gl_update_texture(QemuGLShader *gls,
cd2bc889
GH
424 DisplaySurface *surface,
425 int x, int y, int w, int h);
46e19e14 426void surface_gl_render_texture(QemuGLShader *gls,
cd2bc889 427 DisplaySurface *surface);
46e19e14 428void surface_gl_destroy_texture(QemuGLShader *gls,
cd2bc889 429 DisplaySurface *surface);
46e19e14 430void surface_gl_setup_viewport(QemuGLShader *gls,
cd2bc889
GH
431 DisplaySurface *surface,
432 int ww, int wh);
433#endif
434
db71589f
GH
435typedef struct QemuDisplay QemuDisplay;
436
437struct QemuDisplay {
438 DisplayType type;
439 void (*early_init)(DisplayOptions *opts);
440 void (*init)(DisplayState *ds, DisplayOptions *opts);
441};
442
443void qemu_display_register(QemuDisplay *ui);
444void qemu_display_early_init(DisplayOptions *opts);
445void qemu_display_init(DisplayState *ds, DisplayOptions *opts);
446
87ecb68b 447/* vnc.c */
14f7143e 448void vnc_display_init(const char *id);
4db14629 449void vnc_display_open(const char *id, Error **errp);
14f7143e 450void vnc_display_add_client(const char *id, int csock, bool skipauth);
14f7143e
GH
451int vnc_display_password(const char *id, const char *password);
452int vnc_display_pw_expire(const char *id, time_t expires);
70b94331 453QemuOpts *vnc_parse(const char *str, Error **errp);
28d0de7a 454int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp);
87ecb68b 455
1048c88f 456/* input.c */
64ffbe04 457int index_from_key(const char *key, size_t key_length);
1048c88f 458
bb1599b6 459/* egl-headless.c */
0d2dd9f0 460void egl_headless_init(DisplayOptions *opts);
bb1599b6 461
87ecb68b 462#endif