qemu-thread: handle spurious futex_wait wakeups
[qemu/ar7.git] / include / ui / console.h
blob047a2b46402e9ed4590ac07dc6e0a277a4262991
1 #ifndef CONSOLE_H
2 #define CONSOLE_H
4 #include "ui/qemu-pixman.h"
5 #include "qom/object.h"
6 #include "qapi/qmp/qdict.h"
7 #include "qemu/notify.h"
8 #include "qemu/typedefs.h"
9 #include "qapi-types.h"
10 #include "qapi/error.h"
12 #ifdef CONFIG_OPENGL
13 # include <epoxy/gl.h>
14 #endif
16 /* keyboard/mouse support */
18 #define MOUSE_EVENT_LBUTTON 0x01
19 #define MOUSE_EVENT_RBUTTON 0x02
20 #define MOUSE_EVENT_MBUTTON 0x04
21 #define MOUSE_EVENT_WHEELUP 0x08
22 #define MOUSE_EVENT_WHEELDN 0x10
24 /* identical to the ps/2 keyboard bits */
25 #define QEMU_SCROLL_LOCK_LED (1 << 0)
26 #define QEMU_NUM_LOCK_LED (1 << 1)
27 #define QEMU_CAPS_LOCK_LED (1 << 2)
29 /* in ms */
30 #define GUI_REFRESH_INTERVAL_DEFAULT 30
31 #define GUI_REFRESH_INTERVAL_IDLE 3000
33 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
34 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
35 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
37 typedef struct QEMUPutMouseEntry QEMUPutMouseEntry;
38 typedef struct QEMUPutKbdEntry QEMUPutKbdEntry;
39 typedef struct QEMUPutLEDEntry QEMUPutLEDEntry;
41 QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
42 void *opaque);
43 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
44 void *opaque, int absolute,
45 const char *name);
46 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
47 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
49 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
50 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
52 void kbd_put_ledstate(int ledstate);
54 struct MouseTransformInfo {
55 /* Touchscreen resolution */
56 int x;
57 int y;
58 /* Calibration values as used/generated by tslib */
59 int a[7];
62 void hmp_mouse_set(Monitor *mon, const QDict *qdict);
64 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
65 constants) */
66 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
67 #define QEMU_KEY_BACKSPACE 0x007f
68 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
69 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
70 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
71 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
72 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
73 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
74 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
75 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
76 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
78 #define QEMU_KEY_CTRL_UP 0xe400
79 #define QEMU_KEY_CTRL_DOWN 0xe401
80 #define QEMU_KEY_CTRL_LEFT 0xe402
81 #define QEMU_KEY_CTRL_RIGHT 0xe403
82 #define QEMU_KEY_CTRL_HOME 0xe404
83 #define QEMU_KEY_CTRL_END 0xe405
84 #define QEMU_KEY_CTRL_PAGEUP 0xe406
85 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
87 void kbd_put_keysym_console(QemuConsole *s, int keysym);
88 bool kbd_put_qcode_console(QemuConsole *s, int qcode);
89 void kbd_put_string_console(QemuConsole *s, const char *str, int len);
90 void kbd_put_keysym(int keysym);
92 /* consoles */
94 #define TYPE_QEMU_CONSOLE "qemu-console"
95 #define QEMU_CONSOLE(obj) \
96 OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE)
97 #define QEMU_CONSOLE_GET_CLASS(obj) \
98 OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE)
99 #define QEMU_CONSOLE_CLASS(klass) \
100 OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE)
102 typedef struct QemuConsoleClass QemuConsoleClass;
104 struct QemuConsoleClass {
105 ObjectClass parent_class;
108 #define QEMU_ALLOCATED_FLAG 0x01
110 struct PixelFormat {
111 uint8_t bits_per_pixel;
112 uint8_t bytes_per_pixel;
113 uint8_t depth; /* color depth in bits */
114 uint32_t rmask, gmask, bmask, amask;
115 uint8_t rshift, gshift, bshift, ashift;
116 uint8_t rmax, gmax, bmax, amax;
117 uint8_t rbits, gbits, bbits, abits;
120 struct DisplaySurface {
121 pixman_format_code_t format;
122 pixman_image_t *image;
123 uint8_t flags;
124 #ifdef CONFIG_OPENGL
125 GLenum glformat;
126 GLenum gltype;
127 GLuint texture;
128 #endif
131 typedef struct QemuUIInfo {
132 /* geometry */
133 int xoff;
134 int yoff;
135 uint32_t width;
136 uint32_t height;
137 } QemuUIInfo;
139 /* cursor data format is 32bit RGBA */
140 typedef struct QEMUCursor {
141 int width, height;
142 int hot_x, hot_y;
143 int refcount;
144 uint32_t data[];
145 } QEMUCursor;
147 QEMUCursor *cursor_alloc(int width, int height);
148 void cursor_get(QEMUCursor *c);
149 void cursor_put(QEMUCursor *c);
150 QEMUCursor *cursor_builtin_hidden(void);
151 QEMUCursor *cursor_builtin_left_ptr(void);
152 void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
153 int cursor_get_mono_bpl(QEMUCursor *c);
154 void cursor_set_mono(QEMUCursor *c,
155 uint32_t foreground, uint32_t background, uint8_t *image,
156 int transparent, uint8_t *mask);
157 void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
158 void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
160 typedef struct DisplayChangeListenerOps {
161 const char *dpy_name;
163 void (*dpy_refresh)(DisplayChangeListener *dcl);
165 void (*dpy_gfx_update)(DisplayChangeListener *dcl,
166 int x, int y, int w, int h);
167 void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
168 struct DisplaySurface *new_surface);
169 void (*dpy_gfx_copy)(DisplayChangeListener *dcl,
170 int src_x, int src_y,
171 int dst_x, int dst_y, int w, int h);
172 bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
173 pixman_format_code_t format);
175 void (*dpy_text_cursor)(DisplayChangeListener *dcl,
176 int x, int y);
177 void (*dpy_text_resize)(DisplayChangeListener *dcl,
178 int w, int h);
179 void (*dpy_text_update)(DisplayChangeListener *dcl,
180 int x, int y, int w, int h);
182 void (*dpy_mouse_set)(DisplayChangeListener *dcl,
183 int x, int y, int on);
184 void (*dpy_cursor_define)(DisplayChangeListener *dcl,
185 QEMUCursor *cursor);
186 } DisplayChangeListenerOps;
188 struct DisplayChangeListener {
189 uint64_t update_interval;
190 const DisplayChangeListenerOps *ops;
191 DisplayState *ds;
192 QemuConsole *con;
194 QLIST_ENTRY(DisplayChangeListener) next;
197 DisplayState *init_displaystate(void);
198 DisplaySurface *qemu_create_displaysurface_from(int width, int height,
199 pixman_format_code_t format,
200 int linesize, uint8_t *data);
201 DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height,
202 pixman_format_code_t format,
203 int linesize,
204 uint64_t addr);
205 PixelFormat qemu_default_pixelformat(int bpp);
207 DisplaySurface *qemu_create_displaysurface(int width, int height);
208 void qemu_free_displaysurface(DisplaySurface *surface);
210 static inline int is_surface_bgr(DisplaySurface *surface)
212 if (PIXMAN_FORMAT_BPP(surface->format) == 32 &&
213 PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) {
214 return 1;
215 } else {
216 return 0;
220 static inline int is_buffer_shared(DisplaySurface *surface)
222 return !(surface->flags & QEMU_ALLOCATED_FLAG);
225 void register_displaychangelistener(DisplayChangeListener *dcl);
226 void update_displaychangelistener(DisplayChangeListener *dcl,
227 uint64_t interval);
228 void unregister_displaychangelistener(DisplayChangeListener *dcl);
230 bool dpy_ui_info_supported(QemuConsole *con);
231 int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info);
233 void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
234 void dpy_gfx_replace_surface(QemuConsole *con,
235 DisplaySurface *surface);
236 void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
237 int dst_x, int dst_y, int w, int h);
238 void dpy_text_cursor(QemuConsole *con, int x, int y);
239 void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
240 void dpy_text_resize(QemuConsole *con, int w, int h);
241 void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
242 void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
243 bool dpy_cursor_define_supported(QemuConsole *con);
244 bool dpy_gfx_check_format(QemuConsole *con,
245 pixman_format_code_t format);
247 static inline int surface_stride(DisplaySurface *s)
249 return pixman_image_get_stride(s->image);
252 static inline void *surface_data(DisplaySurface *s)
254 return pixman_image_get_data(s->image);
257 static inline int surface_width(DisplaySurface *s)
259 return pixman_image_get_width(s->image);
262 static inline int surface_height(DisplaySurface *s)
264 return pixman_image_get_height(s->image);
267 static inline int surface_bits_per_pixel(DisplaySurface *s)
269 int bits = PIXMAN_FORMAT_BPP(s->format);
270 return bits;
273 static inline int surface_bytes_per_pixel(DisplaySurface *s)
275 int bits = PIXMAN_FORMAT_BPP(s->format);
276 return (bits + 7) / 8;
279 static inline pixman_format_code_t surface_format(DisplaySurface *s)
281 return s->format;
284 #ifdef CONFIG_CURSES
285 #include <curses.h>
286 typedef chtype console_ch_t;
287 #else
288 typedef unsigned long console_ch_t;
289 #endif
290 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
292 if (!(ch & 0xff))
293 ch |= ' ';
294 *dest = ch;
297 typedef struct GraphicHwOps {
298 void (*invalidate)(void *opaque);
299 void (*gfx_update)(void *opaque);
300 void (*text_update)(void *opaque, console_ch_t *text);
301 void (*update_interval)(void *opaque, uint64_t interval);
302 int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
303 } GraphicHwOps;
305 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
306 const GraphicHwOps *ops,
307 void *opaque);
308 void graphic_console_set_hwops(QemuConsole *con,
309 const GraphicHwOps *hw_ops,
310 void *opaque);
312 void graphic_hw_update(QemuConsole *con);
313 void graphic_hw_invalidate(QemuConsole *con);
314 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
316 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
317 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
318 bool qemu_console_is_visible(QemuConsole *con);
319 bool qemu_console_is_graphic(QemuConsole *con);
320 bool qemu_console_is_fixedsize(QemuConsole *con);
321 char *qemu_console_get_label(QemuConsole *con);
322 int qemu_console_get_index(QemuConsole *con);
323 uint32_t qemu_console_get_head(QemuConsole *con);
324 QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con);
325 int qemu_console_get_width(QemuConsole *con, int fallback);
326 int qemu_console_get_height(QemuConsole *con, int fallback);
328 void text_consoles_set_display(DisplayState *ds);
329 void console_select(unsigned int index);
330 void console_color_init(DisplayState *ds);
331 void qemu_console_resize(QemuConsole *con, int width, int height);
332 void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
333 int dst_x, int dst_y, int w, int h);
334 DisplaySurface *qemu_console_surface(QemuConsole *con);
336 /* console-gl.c */
337 typedef struct ConsoleGLState ConsoleGLState;
338 #ifdef CONFIG_OPENGL
339 ConsoleGLState *console_gl_init_context(void);
340 void console_gl_fini_context(ConsoleGLState *gls);
341 bool console_gl_check_format(DisplayChangeListener *dcl,
342 pixman_format_code_t format);
343 void surface_gl_create_texture(ConsoleGLState *gls,
344 DisplaySurface *surface);
345 void surface_gl_update_texture(ConsoleGLState *gls,
346 DisplaySurface *surface,
347 int x, int y, int w, int h);
348 void surface_gl_render_texture(ConsoleGLState *gls,
349 DisplaySurface *surface);
350 void surface_gl_destroy_texture(ConsoleGLState *gls,
351 DisplaySurface *surface);
352 void surface_gl_setup_viewport(ConsoleGLState *gls,
353 DisplaySurface *surface,
354 int ww, int wh);
355 #endif
357 /* sdl.c */
358 void sdl_display_early_init(int opengl);
359 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
361 /* cocoa.m */
362 void cocoa_display_init(DisplayState *ds, int full_screen);
364 /* vnc.c */
365 void vnc_display_init(const char *id);
366 void vnc_display_open(const char *id, Error **errp);
367 void vnc_display_add_client(const char *id, int csock, bool skipauth);
368 char *vnc_display_local_addr(const char *id);
369 #ifdef CONFIG_VNC
370 int vnc_display_password(const char *id, const char *password);
371 int vnc_display_pw_expire(const char *id, time_t expires);
372 QemuOpts *vnc_parse(const char *str, Error **errp);
373 int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp);
374 #else
375 static inline int vnc_display_password(const char *id, const char *password)
377 return -ENODEV;
379 static inline int vnc_display_pw_expire(const char *id, time_t expires)
381 return -ENODEV;
383 #endif
385 /* curses.c */
386 void curses_display_init(DisplayState *ds, int full_screen);
388 /* input.c */
389 int index_from_key(const char *key);
391 /* gtk.c */
392 void early_gtk_display_init(int opengl);
393 void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover);
395 #endif