ppc: Pass PowerPCCPU to [h]decr callbacks
[qemu/opensuse.git] / console.h
blobedb195087160e0fd1e532369c86c8bd154ef5136
1 #ifndef CONSOLE_H
2 #define CONSOLE_H
4 #include "qemu-char.h"
5 #include "qemu-pixman.h"
6 #include "qdict.h"
7 #include "notify.h"
8 #include "monitor.h"
9 #include "trace.h"
10 #include "qapi-types.h"
11 #include "error.h"
13 /* keyboard/mouse support */
15 #define MOUSE_EVENT_LBUTTON 0x01
16 #define MOUSE_EVENT_RBUTTON 0x02
17 #define MOUSE_EVENT_MBUTTON 0x04
19 /* identical to the ps/2 keyboard bits */
20 #define QEMU_SCROLL_LOCK_LED (1 << 0)
21 #define QEMU_NUM_LOCK_LED (1 << 1)
22 #define QEMU_CAPS_LOCK_LED (1 << 2)
24 /* in ms */
25 #define GUI_REFRESH_INTERVAL 30
27 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
28 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
29 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
31 typedef struct QEMUPutMouseEntry {
32 QEMUPutMouseEvent *qemu_put_mouse_event;
33 void *qemu_put_mouse_event_opaque;
34 int qemu_put_mouse_event_absolute;
35 char *qemu_put_mouse_event_name;
37 int index;
39 /* used internally by qemu for handling mice */
40 QTAILQ_ENTRY(QEMUPutMouseEntry) node;
41 } QEMUPutMouseEntry;
43 typedef struct QEMUPutLEDEntry {
44 QEMUPutLEDEvent *put_led;
45 void *opaque;
46 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
47 } QEMUPutLEDEntry;
49 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
50 void qemu_remove_kbd_event_handler(void);
51 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
52 void *opaque, int absolute,
53 const char *name);
54 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
55 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
57 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
58 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
60 void kbd_put_keycode(int keycode);
61 void kbd_put_ledstate(int ledstate);
62 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
64 /* Does the current mouse generate absolute events */
65 int kbd_mouse_is_absolute(void);
66 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
67 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
69 /* Of all the mice, is there one that generates absolute events */
70 int kbd_mouse_has_absolute(void);
72 struct MouseTransformInfo {
73 /* Touchscreen resolution */
74 int x;
75 int y;
76 /* Calibration values as used/generated by tslib */
77 int a[7];
80 void do_mouse_set(Monitor *mon, const QDict *qdict);
82 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
83 constants) */
84 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
85 #define QEMU_KEY_BACKSPACE 0x007f
86 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
87 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
88 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
89 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
90 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
91 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
92 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
93 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
94 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
96 #define QEMU_KEY_CTRL_UP 0xe400
97 #define QEMU_KEY_CTRL_DOWN 0xe401
98 #define QEMU_KEY_CTRL_LEFT 0xe402
99 #define QEMU_KEY_CTRL_RIGHT 0xe403
100 #define QEMU_KEY_CTRL_HOME 0xe404
101 #define QEMU_KEY_CTRL_END 0xe405
102 #define QEMU_KEY_CTRL_PAGEUP 0xe406
103 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
105 void kbd_put_keysym(int keysym);
107 /* consoles */
109 #define QEMU_BIG_ENDIAN_FLAG 0x01
110 #define QEMU_ALLOCATED_FLAG 0x02
112 struct PixelFormat {
113 uint8_t bits_per_pixel;
114 uint8_t bytes_per_pixel;
115 uint8_t depth; /* color depth in bits */
116 uint32_t rmask, gmask, bmask, amask;
117 uint8_t rshift, gshift, bshift, ashift;
118 uint8_t rmax, gmax, bmax, amax;
119 uint8_t rbits, gbits, bbits, abits;
122 struct DisplaySurface {
123 pixman_format_code_t format;
124 pixman_image_t *image;
125 uint8_t flags;
127 struct PixelFormat pf;
130 /* cursor data format is 32bit RGBA */
131 typedef struct QEMUCursor {
132 int width, height;
133 int hot_x, hot_y;
134 int refcount;
135 uint32_t data[];
136 } QEMUCursor;
138 QEMUCursor *cursor_alloc(int width, int height);
139 void cursor_get(QEMUCursor *c);
140 void cursor_put(QEMUCursor *c);
141 QEMUCursor *cursor_builtin_hidden(void);
142 QEMUCursor *cursor_builtin_left_ptr(void);
143 void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
144 int cursor_get_mono_bpl(QEMUCursor *c);
145 void cursor_set_mono(QEMUCursor *c,
146 uint32_t foreground, uint32_t background, uint8_t *image,
147 int transparent, uint8_t *mask);
148 void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
149 void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
151 struct DisplayChangeListener {
152 int idle;
153 uint64_t gui_timer_interval;
155 void (*dpy_refresh)(struct DisplayState *s);
157 void (*dpy_gfx_update)(struct DisplayState *s, int x, int y, int w, int h);
158 void (*dpy_gfx_resize)(struct DisplayState *s);
159 void (*dpy_gfx_setdata)(struct DisplayState *s);
160 void (*dpy_gfx_copy)(struct DisplayState *s, int src_x, int src_y,
161 int dst_x, int dst_y, int w, int h);
163 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
164 void (*dpy_text_resize)(struct DisplayState *s, int w, int h);
165 void (*dpy_text_update)(struct DisplayState *s, int x, int y, int w, int h);
167 void (*dpy_mouse_set)(struct DisplayState *s, int x, int y, int on);
168 void (*dpy_cursor_define)(struct DisplayState *s, QEMUCursor *cursor);
170 QLIST_ENTRY(DisplayChangeListener) next;
173 struct DisplayState {
174 struct DisplaySurface *surface;
175 void *opaque;
176 struct QEMUTimer *gui_timer;
177 bool have_gfx;
178 bool have_text;
180 QLIST_HEAD(, DisplayChangeListener) listeners;
182 struct DisplayState *next;
185 void register_displaystate(DisplayState *ds);
186 DisplayState *get_displaystate(void);
187 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
188 int linesize, uint8_t *data);
189 PixelFormat qemu_different_endianness_pixelformat(int bpp);
190 PixelFormat qemu_default_pixelformat(int bpp);
192 DisplaySurface *qemu_create_displaysurface(DisplayState *ds,
193 int width, int height);
194 DisplaySurface *qemu_resize_displaysurface(DisplayState *ds,
195 int width, int height);
196 void qemu_free_displaysurface(DisplayState *ds);
198 static inline int is_surface_bgr(DisplaySurface *surface)
200 if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
201 return 1;
202 else
203 return 0;
206 static inline int is_buffer_shared(DisplaySurface *surface)
208 return !(surface->flags & QEMU_ALLOCATED_FLAG);
211 void gui_setup_refresh(DisplayState *ds);
213 static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
215 QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
216 gui_setup_refresh(ds);
217 if (dcl->dpy_gfx_resize) {
218 dcl->dpy_gfx_resize(ds);
222 static inline void unregister_displaychangelistener(DisplayState *ds,
223 DisplayChangeListener *dcl)
225 QLIST_REMOVE(dcl, next);
226 gui_setup_refresh(ds);
229 static inline void dpy_gfx_update(DisplayState *s, int x, int y, int w, int h)
231 struct DisplayChangeListener *dcl;
232 int width = pixman_image_get_width(s->surface->image);
233 int height = pixman_image_get_height(s->surface->image);
235 x = MAX(x, 0);
236 y = MAX(y, 0);
237 x = MIN(x, width);
238 y = MIN(y, height);
239 w = MIN(w, width - x);
240 h = MIN(h, height - y);
242 QLIST_FOREACH(dcl, &s->listeners, next) {
243 if (dcl->dpy_gfx_update) {
244 dcl->dpy_gfx_update(s, x, y, w, h);
249 static inline void dpy_gfx_resize(DisplayState *s)
251 struct DisplayChangeListener *dcl;
252 QLIST_FOREACH(dcl, &s->listeners, next) {
253 if (dcl->dpy_gfx_resize) {
254 dcl->dpy_gfx_resize(s);
259 static inline void dpy_gfx_setdata(DisplayState *s)
261 struct DisplayChangeListener *dcl;
262 QLIST_FOREACH(dcl, &s->listeners, next) {
263 if (dcl->dpy_gfx_setdata) {
264 dcl->dpy_gfx_setdata(s);
269 static inline void dpy_refresh(DisplayState *s)
271 struct DisplayChangeListener *dcl;
272 QLIST_FOREACH(dcl, &s->listeners, next) {
273 if (dcl->dpy_refresh) {
274 dcl->dpy_refresh(s);
279 static inline void dpy_gfx_copy(struct DisplayState *s, int src_x, int src_y,
280 int dst_x, int dst_y, int w, int h)
282 struct DisplayChangeListener *dcl;
283 QLIST_FOREACH(dcl, &s->listeners, next) {
284 if (dcl->dpy_gfx_copy) {
285 dcl->dpy_gfx_copy(s, src_x, src_y, dst_x, dst_y, w, h);
286 } else { /* TODO */
287 dcl->dpy_gfx_update(s, dst_x, dst_y, w, h);
292 static inline void dpy_text_cursor(struct DisplayState *s, int x, int y)
294 struct DisplayChangeListener *dcl;
295 QLIST_FOREACH(dcl, &s->listeners, next) {
296 if (dcl->dpy_text_cursor) {
297 dcl->dpy_text_cursor(s, x, y);
302 static inline void dpy_text_update(DisplayState *s, int x, int y, int w, int h)
304 struct DisplayChangeListener *dcl;
305 QLIST_FOREACH(dcl, &s->listeners, next) {
306 if (dcl->dpy_text_update) {
307 dcl->dpy_text_update(s, x, y, w, h);
312 static inline void dpy_text_resize(DisplayState *s, int w, int h)
314 struct DisplayChangeListener *dcl;
315 QLIST_FOREACH(dcl, &s->listeners, next) {
316 if (dcl->dpy_text_resize) {
317 dcl->dpy_text_resize(s, w, h);
322 static inline void dpy_mouse_set(struct DisplayState *s, int x, int y, int on)
324 struct DisplayChangeListener *dcl;
325 QLIST_FOREACH(dcl, &s->listeners, next) {
326 if (dcl->dpy_mouse_set) {
327 dcl->dpy_mouse_set(s, x, y, on);
332 static inline void dpy_cursor_define(struct DisplayState *s, QEMUCursor *cursor)
334 struct DisplayChangeListener *dcl;
335 QLIST_FOREACH(dcl, &s->listeners, next) {
336 if (dcl->dpy_cursor_define) {
337 dcl->dpy_cursor_define(s, cursor);
342 static inline bool dpy_cursor_define_supported(struct DisplayState *s)
344 struct DisplayChangeListener *dcl;
345 QLIST_FOREACH(dcl, &s->listeners, next) {
346 if (dcl->dpy_cursor_define) {
347 return true;
350 return false;
353 static inline int ds_get_linesize(DisplayState *ds)
355 return pixman_image_get_stride(ds->surface->image);
358 static inline uint8_t* ds_get_data(DisplayState *ds)
360 return (void *)pixman_image_get_data(ds->surface->image);
363 static inline int ds_get_width(DisplayState *ds)
365 return pixman_image_get_width(ds->surface->image);
368 static inline int ds_get_height(DisplayState *ds)
370 return pixman_image_get_height(ds->surface->image);
373 static inline int ds_get_bits_per_pixel(DisplayState *ds)
375 int bits = PIXMAN_FORMAT_BPP(ds->surface->format);
376 return bits;
379 static inline int ds_get_bytes_per_pixel(DisplayState *ds)
381 int bits = PIXMAN_FORMAT_BPP(ds->surface->format);
382 return (bits + 7) / 8;
385 static inline pixman_format_code_t ds_get_format(DisplayState *ds)
387 return ds->surface->format;
390 static inline pixman_image_t *ds_get_image(DisplayState *ds)
392 return ds->surface->image;
395 static inline int ds_get_depth(DisplayState *ds)
397 return ds->surface->pf.depth;
400 static inline int ds_get_rmask(DisplayState *ds)
402 return ds->surface->pf.rmask;
405 static inline int ds_get_gmask(DisplayState *ds)
407 return ds->surface->pf.gmask;
410 static inline int ds_get_bmask(DisplayState *ds)
412 return ds->surface->pf.bmask;
415 #ifdef CONFIG_CURSES
416 #include <curses.h>
417 typedef chtype console_ch_t;
418 #else
419 typedef unsigned long console_ch_t;
420 #endif
421 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
423 if (!(ch & 0xff))
424 ch |= ' ';
425 *dest = ch;
428 typedef void (*vga_hw_update_ptr)(void *);
429 typedef void (*vga_hw_invalidate_ptr)(void *);
430 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
431 Error **errp);
432 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
434 DisplayState *graphic_console_init(vga_hw_update_ptr update,
435 vga_hw_invalidate_ptr invalidate,
436 vga_hw_screen_dump_ptr screen_dump,
437 vga_hw_text_update_ptr text_update,
438 void *opaque);
440 void vga_hw_update(void);
441 void vga_hw_invalidate(void);
442 void vga_hw_text_update(console_ch_t *chardata);
444 int is_graphic_console(void);
445 int is_fixedsize_console(void);
446 CharDriverState *text_console_init(QemuOpts *opts);
447 void text_consoles_set_display(DisplayState *ds);
448 void console_select(unsigned int index);
449 void console_color_init(DisplayState *ds);
450 void qemu_console_resize(DisplayState *ds, int width, int height);
451 void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
452 int dst_x, int dst_y, int w, int h);
454 /* sdl.c */
455 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
457 /* cocoa.m */
458 void cocoa_display_init(DisplayState *ds, int full_screen);
460 /* vnc.c */
461 void vnc_display_init(DisplayState *ds);
462 void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
463 void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
464 char *vnc_display_local_addr(DisplayState *ds);
465 #ifdef CONFIG_VNC
466 int vnc_display_password(DisplayState *ds, const char *password);
467 int vnc_display_pw_expire(DisplayState *ds, time_t expires);
468 #else
469 static inline int vnc_display_password(DisplayState *ds, const char *password)
471 return -ENODEV;
473 static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
475 return -ENODEV;
477 #endif
479 /* curses.c */
480 void curses_display_init(DisplayState *ds, int full_screen);
482 /* input.c */
483 int index_from_key(const char *key);
484 int index_from_keycode(int code);
486 #endif