]> git.proxmox.com Git - qemu.git/blame - include/ui/console.h
console: stop using DisplayState in gfx hardware emulation
[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"
7b1b5d19 5#include "qapi/qmp/qdict.h"
1de7afc9 6#include "qemu/notify.h"
83c9089e 7#include "monitor/monitor.h"
cdbc19dd 8#include "trace.h"
1048c88f 9#include "qapi-types.h"
7b1b5d19 10#include "qapi/error.h"
87ecb68b
PB
11
12/* keyboard/mouse support */
13
14#define MOUSE_EVENT_LBUTTON 0x01
15#define MOUSE_EVENT_RBUTTON 0x02
16#define MOUSE_EVENT_MBUTTON 0x04
17
03a23a85
GH
18/* identical to the ps/2 keyboard bits */
19#define QEMU_SCROLL_LOCK_LED (1 << 0)
20#define QEMU_NUM_LOCK_LED (1 << 1)
21#define QEMU_CAPS_LOCK_LED (1 << 2)
22
7ed9eba3
AL
23/* in ms */
24#define GUI_REFRESH_INTERVAL 30
25
87ecb68b 26typedef void QEMUPutKBDEvent(void *opaque, int keycode);
03a23a85 27typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
87ecb68b
PB
28typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
29
30typedef struct QEMUPutMouseEntry {
31 QEMUPutMouseEvent *qemu_put_mouse_event;
32 void *qemu_put_mouse_event_opaque;
33 int qemu_put_mouse_event_absolute;
34 char *qemu_put_mouse_event_name;
35
6fef28ee
AL
36 int index;
37
87ecb68b 38 /* used internally by qemu for handling mice */
6fef28ee 39 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
87ecb68b
PB
40} QEMUPutMouseEntry;
41
03a23a85
GH
42typedef struct QEMUPutLEDEntry {
43 QEMUPutLEDEvent *put_led;
44 void *opaque;
45 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
46} QEMUPutLEDEntry;
47
87ecb68b 48void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
46aaebff 49void qemu_remove_kbd_event_handler(void);
87ecb68b
PB
50QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
51 void *opaque, int absolute,
52 const char *name);
53void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
6fef28ee
AL
54void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
55
03a23a85
GH
56QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
57void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
87ecb68b
PB
58
59void kbd_put_keycode(int keycode);
03a23a85 60void kbd_put_ledstate(int ledstate);
87ecb68b 61void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
eb2e259d
AL
62
63/* Does the current mouse generate absolute events */
87ecb68b 64int kbd_mouse_is_absolute(void);
7e581fb3
AL
65void qemu_add_mouse_mode_change_notifier(Notifier *notify);
66void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
87ecb68b 67
eb2e259d
AL
68/* Of all the mice, is there one that generates absolute events */
69int kbd_mouse_has_absolute(void);
70
bc24a225 71struct MouseTransformInfo {
a5d7eb65
AZ
72 /* Touchscreen resolution */
73 int x;
74 int y;
75 /* Calibration values as used/generated by tslib */
76 int a[7];
77};
78
d54908a5 79void do_mouse_set(Monitor *mon, const QDict *qdict);
87ecb68b
PB
80
81/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
82 constants) */
83#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
84#define QEMU_KEY_BACKSPACE 0x007f
85#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
86#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
87#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
88#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
89#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
90#define QEMU_KEY_END QEMU_KEY_ESC1(4)
91#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
92#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
93#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
94
95#define QEMU_KEY_CTRL_UP 0xe400
96#define QEMU_KEY_CTRL_DOWN 0xe401
97#define QEMU_KEY_CTRL_LEFT 0xe402
98#define QEMU_KEY_CTRL_RIGHT 0xe403
99#define QEMU_KEY_CTRL_HOME 0xe404
100#define QEMU_KEY_CTRL_END 0xe405
101#define QEMU_KEY_CTRL_PAGEUP 0xe406
102#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
103
104void kbd_put_keysym(int keysym);
105
106/* consoles */
107
7d957bd8
AL
108#define QEMU_BIG_ENDIAN_FLAG 0x01
109#define QEMU_ALLOCATED_FLAG 0x02
110
111struct PixelFormat {
112 uint8_t bits_per_pixel;
113 uint8_t bytes_per_pixel;
114 uint8_t depth; /* color depth in bits */
115 uint32_t rmask, gmask, bmask, amask;
116 uint8_t rshift, gshift, bshift, ashift;
117 uint8_t rmax, gmax, bmax, amax;
90a1e3c0 118 uint8_t rbits, gbits, bbits, abits;
7d957bd8
AL
119};
120
121struct DisplaySurface {
69c77777
GH
122 pixman_format_code_t format;
123 pixman_image_t *image;
7d957bd8 124 uint8_t flags;
7d957bd8
AL
125
126 struct PixelFormat pf;
127};
128
254e5950
GH
129/* cursor data format is 32bit RGBA */
130typedef struct QEMUCursor {
131 int width, height;
132 int hot_x, hot_y;
133 int refcount;
134 uint32_t data[];
135} QEMUCursor;
136
137QEMUCursor *cursor_alloc(int width, int height);
138void cursor_get(QEMUCursor *c);
139void cursor_put(QEMUCursor *c);
140QEMUCursor *cursor_builtin_hidden(void);
141QEMUCursor *cursor_builtin_left_ptr(void);
142void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
143int cursor_get_mono_bpl(QEMUCursor *c);
144void cursor_set_mono(QEMUCursor *c,
145 uint32_t foreground, uint32_t background, uint8_t *image,
146 int transparent, uint8_t *mask);
147void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
148void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
149
7c20b4a3
GH
150typedef struct DisplayChangeListenerOps {
151 const char *dpy_name;
152
bc2ed970 153 void (*dpy_refresh)(DisplayChangeListener *dcl);
7c20b4a3
GH
154
155 void (*dpy_gfx_update)(DisplayChangeListener *dcl,
7c20b4a3 156 int x, int y, int w, int h);
c12aeb86 157 void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
c12aeb86 158 struct DisplaySurface *new_surface);
7c20b4a3 159 void (*dpy_gfx_copy)(DisplayChangeListener *dcl,
bc2ed970 160 int src_x, int src_y,
a93a4a22 161 int dst_x, int dst_y, int w, int h);
a93a4a22 162
7c20b4a3 163 void (*dpy_text_cursor)(DisplayChangeListener *dcl,
7c20b4a3
GH
164 int x, int y);
165 void (*dpy_text_resize)(DisplayChangeListener *dcl,
7c20b4a3
GH
166 int w, int h);
167 void (*dpy_text_update)(DisplayChangeListener *dcl,
7c20b4a3
GH
168 int x, int y, int w, int h);
169
170 void (*dpy_mouse_set)(DisplayChangeListener *dcl,
7c20b4a3
GH
171 int x, int y, int on);
172 void (*dpy_cursor_define)(DisplayChangeListener *dcl,
7c20b4a3
GH
173 QEMUCursor *cursor);
174} DisplayChangeListenerOps;
7d957bd8 175
7c20b4a3
GH
176struct DisplayChangeListener {
177 int idle;
178 uint64_t gui_timer_interval;
179 const DisplayChangeListenerOps *ops;
180 DisplayState *ds;
bf2fde70 181
87e487a1 182 QLIST_ENTRY(DisplayChangeListener) next;
7d957bd8
AL
183};
184
185struct DisplayState {
186 struct DisplaySurface *surface;
7d957bd8 187 struct QEMUTimer *gui_timer;
a93a4a22
GH
188 bool have_gfx;
189 bool have_text;
7d957bd8 190
87e487a1 191 QLIST_HEAD(, DisplayChangeListener) listeners;
7d957bd8 192
3023f332 193 struct DisplayState *next;
87ecb68b
PB
194};
195
3023f332
AL
196void register_displaystate(DisplayState *ds);
197DisplayState *get_displaystate(void);
7d957bd8 198DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
b1424e03
GH
199 int linesize, uint8_t *data,
200 bool byteswap);
0da2ea1b 201PixelFormat qemu_different_endianness_pixelformat(int bpp);
202PixelFormat qemu_default_pixelformat(int bpp);
7d957bd8 203
da229ef3
GH
204DisplaySurface *qemu_create_displaysurface(int width, int height);
205void qemu_free_displaysurface(DisplaySurface *surface);
7b5d76da
AL
206
207static inline int is_surface_bgr(DisplaySurface *surface)
208{
209 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
210 return 1;
211 else
212 return 0;
213}
214
7d957bd8
AL
215static inline int is_buffer_shared(DisplaySurface *surface)
216{
187cd1d9 217 return !(surface->flags & QEMU_ALLOCATED_FLAG);
7d957bd8
AL
218}
219
35c9e0a5
GH
220void gui_setup_refresh(DisplayState *ds);
221
7c20b4a3
GH
222void register_displaychangelistener(DisplayState *ds,
223 DisplayChangeListener *dcl);
224void unregister_displaychangelistener(DisplayChangeListener *dcl);
225
c78f7137
GH
226void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
227void dpy_gfx_replace_surface(QemuConsole *con,
da229ef3 228 DisplaySurface *surface);
7c20b4a3 229void dpy_refresh(DisplayState *s);
c78f7137 230void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
7c20b4a3 231 int dst_x, int dst_y, int w, int h);
c78f7137
GH
232void dpy_text_cursor(QemuConsole *con, int x, int y);
233void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
234void dpy_text_resize(QemuConsole *con, int w, int h);
235void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
236void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
237bool dpy_cursor_define_supported(QemuConsole *con);
bf2fde70 238
626e3b34
GH
239static inline int surface_stride(DisplaySurface *s)
240{
241 return pixman_image_get_stride(s->image);
242}
243
244static inline void *surface_data(DisplaySurface *s)
245{
246 return pixman_image_get_data(s->image);
247}
248
249static inline int surface_width(DisplaySurface *s)
250{
251 return pixman_image_get_width(s->image);
252}
253
254static inline int surface_height(DisplaySurface *s)
255{
256 return pixman_image_get_height(s->image);
257}
258
259static inline int surface_bits_per_pixel(DisplaySurface *s)
260{
261 int bits = PIXMAN_FORMAT_BPP(s->format);
262 return bits;
263}
264
265static inline int surface_bytes_per_pixel(DisplaySurface *s)
266{
267 int bits = PIXMAN_FORMAT_BPP(s->format);
268 return (bits + 7) / 8;
269}
270
0e1f5a0c
AL
271static inline int ds_get_linesize(DisplayState *ds)
272{
626e3b34 273 return surface_stride(ds->surface);
0e1f5a0c
AL
274}
275
276static inline uint8_t* ds_get_data(DisplayState *ds)
277{
626e3b34 278 return surface_data(ds->surface);
0e1f5a0c
AL
279}
280
281static inline int ds_get_width(DisplayState *ds)
282{
626e3b34 283 return surface_width(ds->surface);
0e1f5a0c
AL
284}
285
286static inline int ds_get_height(DisplayState *ds)
287{
626e3b34 288 return surface_height(ds->surface);
0e1f5a0c
AL
289}
290
291static inline int ds_get_bits_per_pixel(DisplayState *ds)
292{
626e3b34 293 return surface_bits_per_pixel(ds->surface);
0e1f5a0c
AL
294}
295
8927bcfd
AL
296static inline int ds_get_bytes_per_pixel(DisplayState *ds)
297{
626e3b34 298 return surface_bytes_per_pixel(ds->surface);
64f73592
GH
299}
300
301static inline pixman_format_code_t ds_get_format(DisplayState *ds)
302{
303 return ds->surface->format;
8927bcfd
AL
304}
305
d9a86569
GH
306static inline pixman_image_t *ds_get_image(DisplayState *ds)
307{
308 return ds->surface->image;
309}
310
aa32b38c
BZ
311static inline int ds_get_depth(DisplayState *ds)
312{
313 return ds->surface->pf.depth;
314}
315
316static inline int ds_get_rmask(DisplayState *ds)
317{
318 return ds->surface->pf.rmask;
319}
320
321static inline int ds_get_gmask(DisplayState *ds)
322{
323 return ds->surface->pf.gmask;
324}
325
326static inline int ds_get_bmask(DisplayState *ds)
327{
328 return ds->surface->pf.bmask;
329}
330
df00bed0
DP
331#ifdef CONFIG_CURSES
332#include <curses.h>
333typedef chtype console_ch_t;
334#else
c227f099 335typedef unsigned long console_ch_t;
df00bed0 336#endif
c227f099 337static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
4d3b6f6e 338{
f6d20d0f
BK
339 if (!(ch & 0xff))
340 ch |= ' ';
9ae19b65 341 *dest = ch;
4d3b6f6e
AZ
342}
343
87ecb68b
PB
344typedef void (*vga_hw_update_ptr)(void *);
345typedef void (*vga_hw_invalidate_ptr)(void *);
d7098135
LC
346typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
347 Error **errp);
c227f099 348typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
87ecb68b 349
c78f7137
GH
350QemuConsole *graphic_console_init(vga_hw_update_ptr update,
351 vga_hw_invalidate_ptr invalidate,
352 vga_hw_screen_dump_ptr screen_dump,
353 vga_hw_text_update_ptr text_update,
354 void *opaque);
3023f332 355
87ecb68b
PB
356void vga_hw_update(void);
357void vga_hw_invalidate(void);
c227f099 358void vga_hw_text_update(console_ch_t *chardata);
87ecb68b
PB
359
360int is_graphic_console(void);
c21bbcfa 361int is_fixedsize_console(void);
2796dae0 362void text_consoles_set_display(DisplayState *ds);
87ecb68b
PB
363void console_select(unsigned int index);
364void console_color_init(DisplayState *ds);
c78f7137
GH
365void qemu_console_resize(QemuConsole *con, int width, int height);
366void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
3023f332 367 int dst_x, int dst_y, int w, int h);
c78f7137
GH
368DisplaySurface *qemu_console_surface(QemuConsole *con);
369DisplayState *qemu_console_displaystate(QemuConsole *console);
87ecb68b 370
702ec69c 371typedef CharDriverState *(VcHandler)(ChardevVC *vc);
d82831db 372
702ec69c 373CharDriverState *vc_init(ChardevVC *vc);
d82831db
AL
374void register_vc_handler(VcHandler *handler);
375
87ecb68b
PB
376/* sdl.c */
377void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
378
379/* cocoa.m */
380void cocoa_display_init(DisplayState *ds, int full_screen);
381
382/* vnc.c */
383void vnc_display_init(DisplayState *ds);
007fcd3e 384void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
13661089 385void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
821601ea
JS
386char *vnc_display_local_addr(DisplayState *ds);
387#ifdef CONFIG_VNC
388int vnc_display_password(DisplayState *ds, const char *password);
3c9405a0 389int vnc_display_pw_expire(DisplayState *ds, time_t expires);
821601ea
JS
390#else
391static inline int vnc_display_password(DisplayState *ds, const char *password)
392{
821601ea
JS
393 return -ENODEV;
394}
395static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
396{
821601ea
JS
397 return -ENODEV;
398};
821601ea 399#endif
87ecb68b 400
4d3b6f6e
AZ
401/* curses.c */
402void curses_display_init(DisplayState *ds, int full_screen);
403
1048c88f 404/* input.c */
1048c88f
AK
405int index_from_key(const char *key);
406int index_from_keycode(int code);
407
a4ccabcf
AL
408/* gtk.c */
409void early_gtk_display_init(void);
410void gtk_display_init(DisplayState *ds);
411
87ecb68b 412#endif