qemu/include/ui/console.h
<<
>>
Prefs
   1#ifndef CONSOLE_H
   2#define CONSOLE_H
   3
   4#include "ui/qemu-pixman.h"
   5#include "qapi/qmp/qdict.h"
   6#include "qemu/notify.h"
   7#include "monitor/monitor.h"
   8#include "trace.h"
   9#include "qapi-types.h"
  10#include "qapi/error.h"
  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
  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
  23/* in ms */
  24#define GUI_REFRESH_INTERVAL 30
  25
  26typedef void QEMUPutKBDEvent(void *opaque, int keycode);
  27typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
  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
  36    int index;
  37
  38    /* used internally by qemu for handling mice */
  39    QTAILQ_ENTRY(QEMUPutMouseEntry) node;
  40} QEMUPutMouseEntry;
  41
  42typedef struct QEMUPutLEDEntry {
  43    QEMUPutLEDEvent *put_led;
  44    void *opaque;
  45    QTAILQ_ENTRY(QEMUPutLEDEntry) next;
  46} QEMUPutLEDEntry;
  47
  48void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
  49void qemu_remove_kbd_event_handler(void);
  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);
  54void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
  55
  56QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
  57void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
  58
  59void kbd_put_keycode(int keycode);
  60void kbd_put_ledstate(int ledstate);
  61void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
  62
  63/* Does the current mouse generate absolute events */
  64int kbd_mouse_is_absolute(void);
  65void qemu_add_mouse_mode_change_notifier(Notifier *notify);
  66void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
  67
  68/* Of all the mice, is there one that generates absolute events */
  69int kbd_mouse_has_absolute(void);
  70
  71struct MouseTransformInfo {
  72    /* Touchscreen resolution */
  73    int x;
  74    int y;
  75    /* Calibration values as used/generated by tslib */
  76    int a[7];
  77};
  78
  79void do_mouse_set(Monitor *mon, const QDict *qdict);
  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
 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;
 118    uint8_t rbits, gbits, bbits, abits;
 119};
 120
 121struct DisplaySurface {
 122    pixman_format_code_t format;
 123    pixman_image_t *image;
 124    uint8_t flags;
 125
 126    struct PixelFormat pf;
 127};
 128
 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
 150struct DisplayChangeListener {
 151    int idle;
 152    uint64_t gui_timer_interval;
 153
 154    void (*dpy_refresh)(struct DisplayState *s);
 155
 156    void (*dpy_gfx_update)(struct DisplayState *s, int x, int y, int w, int h);
 157    void (*dpy_gfx_resize)(struct DisplayState *s);
 158    void (*dpy_gfx_setdata)(struct DisplayState *s);
 159    void (*dpy_gfx_copy)(struct DisplayState *s, int src_x, int src_y,
 160                         int dst_x, int dst_y, int w, int h);
 161
 162    void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
 163    void (*dpy_text_resize)(struct DisplayState *s, int w, int h);
 164    void (*dpy_text_update)(struct DisplayState *s, int x, int y, int w, int h);
 165
 166    void (*dpy_mouse_set)(struct DisplayState *s, int x, int y, int on);
 167    void (*dpy_cursor_define)(struct DisplayState *s, QEMUCursor *cursor);
 168
 169    QLIST_ENTRY(DisplayChangeListener) next;
 170};
 171
 172struct DisplayState {
 173    struct DisplaySurface *surface;
 174    void *opaque;
 175    struct QEMUTimer *gui_timer;
 176    bool have_gfx;
 177    bool have_text;
 178
 179    QLIST_HEAD(, DisplayChangeListener) listeners;
 180
 181    struct DisplayState *next;
 182};
 183
 184void register_displaystate(DisplayState *ds);
 185DisplayState *get_displaystate(void);
 186DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
 187                                                int linesize, uint8_t *data,
 188                                                bool byteswap);
 189PixelFormat qemu_different_endianness_pixelformat(int bpp);
 190PixelFormat qemu_default_pixelformat(int bpp);
 191
 192DisplaySurface *qemu_create_displaysurface(DisplayState *ds,
 193                                           int width, int height);
 194DisplaySurface *qemu_resize_displaysurface(DisplayState *ds,
 195                                           int width, int height);
 196void qemu_free_displaysurface(DisplayState *ds);
 197
 198static inline int is_surface_bgr(DisplaySurface *surface)
 199{
 200    if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
 201        return 1;
 202    else
 203        return 0;
 204}
 205
 206static inline int is_buffer_shared(DisplaySurface *surface)
 207{
 208    return !(surface->flags & QEMU_ALLOCATED_FLAG);
 209}
 210
 211void gui_setup_refresh(DisplayState *ds);
 212
 213static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
 214{
 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);
 219    }
 220}
 221
 222static inline void unregister_displaychangelistener(DisplayState *ds,
 223                                                    DisplayChangeListener *dcl)
 224{
 225    QLIST_REMOVE(dcl, next);
 226    gui_setup_refresh(ds);
 227}
 228
 229static inline void dpy_gfx_update(DisplayState *s, int x, int y, int w, int h)
 230{
 231    struct DisplayChangeListener *dcl;
 232    int width = pixman_image_get_width(s->surface->image);
 233    int height = pixman_image_get_height(s->surface->image);
 234
 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);
 241
 242    QLIST_FOREACH(dcl, &s->listeners, next) {
 243        if (dcl->dpy_gfx_update) {
 244            dcl->dpy_gfx_update(s, x, y, w, h);
 245        }
 246    }
 247}
 248
 249static inline void dpy_gfx_resize(DisplayState *s)
 250{
 251    struct DisplayChangeListener *dcl;
 252    QLIST_FOREACH(dcl, &s->listeners, next) {
 253        if (dcl->dpy_gfx_resize) {
 254            dcl->dpy_gfx_resize(s);
 255        }
 256    }
 257}
 258
 259static inline void dpy_gfx_setdata(DisplayState *s)
 260{
 261    struct DisplayChangeListener *dcl;
 262    QLIST_FOREACH(dcl, &s->listeners, next) {
 263        if (dcl->dpy_gfx_setdata) {
 264            dcl->dpy_gfx_setdata(s);
 265        }
 266    }
 267}
 268
 269static inline void dpy_refresh(DisplayState *s)
 270{
 271    struct DisplayChangeListener *dcl;
 272    QLIST_FOREACH(dcl, &s->listeners, next) {
 273        if (dcl->dpy_refresh) {
 274            dcl->dpy_refresh(s);
 275        }
 276    }
 277}
 278
 279static 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)
 281{
 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);
 288        }
 289    }
 290}
 291
 292static inline void dpy_text_cursor(struct DisplayState *s, int x, int y)
 293{
 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);
 298        }
 299    }
 300}
 301
 302static inline void dpy_text_update(DisplayState *s, int x, int y, int w, int h)
 303{
 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);
 308        }
 309    }
 310}
 311
 312static inline void dpy_text_resize(DisplayState *s, int w, int h)
 313{
 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);
 318        }
 319    }
 320}
 321
 322static inline void dpy_mouse_set(struct DisplayState *s, int x, int y, int on)
 323{
 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);
 328        }
 329    }
 330}
 331
 332static inline void dpy_cursor_define(struct DisplayState *s, QEMUCursor *cursor)
 333{
 334    struct DisplayChangeListener *dcl;
 335    QLIST_FOREACH(dcl, &s->listeners, next) {
 336        if (dcl->dpy_cursor_define) {
 337            dcl->dpy_cursor_define(s, cursor);
 338        }
 339    }
 340}
 341
 342static inline bool dpy_cursor_define_supported(struct DisplayState *s)
 343{
 344    struct DisplayChangeListener *dcl;
 345    QLIST_FOREACH(dcl, &s->listeners, next) {
 346        if (dcl->dpy_cursor_define) {
 347            return true;
 348        }
 349    }
 350    return false;
 351}
 352
 353static inline int ds_get_linesize(DisplayState *ds)
 354{
 355    return pixman_image_get_stride(ds->surface->image);
 356}
 357
 358static inline uint8_t* ds_get_data(DisplayState *ds)
 359{
 360    return (void *)pixman_image_get_data(ds->surface->image);
 361}
 362
 363static inline int ds_get_width(DisplayState *ds)
 364{
 365    return pixman_image_get_width(ds->surface->image);
 366}
 367
 368static inline int ds_get_height(DisplayState *ds)
 369{
 370    return pixman_image_get_height(ds->surface->image);
 371}
 372
 373static inline int ds_get_bits_per_pixel(DisplayState *ds)
 374{
 375    int bits = PIXMAN_FORMAT_BPP(ds->surface->format);
 376    return bits;
 377}
 378
 379static inline int ds_get_bytes_per_pixel(DisplayState *ds)
 380{
 381    int bits = PIXMAN_FORMAT_BPP(ds->surface->format);
 382    return (bits + 7) / 8;
 383}
 384
 385static inline pixman_format_code_t ds_get_format(DisplayState *ds)
 386{
 387    return ds->surface->format;
 388}
 389
 390static inline pixman_image_t *ds_get_image(DisplayState *ds)
 391{
 392    return ds->surface->image;
 393}
 394
 395static inline int ds_get_depth(DisplayState *ds)
 396{
 397    return ds->surface->pf.depth;
 398}
 399
 400static inline int ds_get_rmask(DisplayState *ds)
 401{
 402    return ds->surface->pf.rmask;
 403}
 404
 405static inline int ds_get_gmask(DisplayState *ds)
 406{
 407    return ds->surface->pf.gmask;
 408}
 409
 410static inline int ds_get_bmask(DisplayState *ds)
 411{
 412    return ds->surface->pf.bmask;
 413}
 414
 415#ifdef CONFIG_CURSES
 416#include <curses.h>
 417typedef chtype console_ch_t;
 418#else
 419typedef unsigned long console_ch_t;
 420#endif
 421static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 422{
 423    if (!(ch & 0xff))
 424        ch |= ' ';
 425    *dest = ch;
 426}
 427
 428typedef void (*vga_hw_update_ptr)(void *);
 429typedef void (*vga_hw_invalidate_ptr)(void *);
 430typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
 431                                       Error **errp);
 432typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 433
 434DisplayState *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);
 439
 440void vga_hw_update(void);
 441void vga_hw_invalidate(void);
 442void vga_hw_text_update(console_ch_t *chardata);
 443
 444int is_graphic_console(void);
 445int is_fixedsize_console(void);
 446CharDriverState *text_console_init(QemuOpts *opts);
 447void text_consoles_set_display(DisplayState *ds);
 448void console_select(unsigned int index);
 449void console_color_init(DisplayState *ds);
 450void qemu_console_resize(DisplayState *ds, int width, int height);
 451void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
 452                       int dst_x, int dst_y, int w, int h);
 453
 454/* sdl.c */
 455void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 456
 457/* cocoa.m */
 458void cocoa_display_init(DisplayState *ds, int full_screen);
 459
 460/* vnc.c */
 461void vnc_display_init(DisplayState *ds);
 462void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
 463void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
 464char *vnc_display_local_addr(DisplayState *ds);
 465#ifdef CONFIG_VNC
 466int vnc_display_password(DisplayState *ds, const char *password);
 467int vnc_display_pw_expire(DisplayState *ds, time_t expires);
 468#else
 469static inline int vnc_display_password(DisplayState *ds, const char *password)
 470{
 471    return -ENODEV;
 472}
 473static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
 474{
 475    return -ENODEV;
 476};
 477#endif
 478
 479/* curses.c */
 480void curses_display_init(DisplayState *ds, int full_screen);
 481
 482/* input.c */
 483int index_from_key(const char *key);
 484int index_from_keycode(int code);
 485
 486#endif
 487