Home | History | Annotate | Download | only in qemu
      1 #ifndef CONSOLE_H
      2 #define CONSOLE_H
      3 
      4 #include "qemu-char.h"
      5 
      6 /* keyboard/mouse support */
      7 
      8 #define MOUSE_EVENT_LBUTTON 0x01
      9 #define MOUSE_EVENT_RBUTTON 0x02
     10 #define MOUSE_EVENT_MBUTTON 0x04
     11 
     12 /* in ms */
     13 #if 1  /* ANDROID */
     14 #define GUI_REFRESH_INTERVAL (1000/60)  /* 60 frames/s is better */
     15 #else
     16 #define GUI_REFRESH_INTERVAL 30
     17 #endif
     18 
     19 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
     20 typedef void QEMUPutKBDEventN(void *opaque, int*  keycodes, int  count);
     21 typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
     22 typedef void QEMUPutGenericEvent(void*  opaque, int  type, int  code, int  value);
     23 
     24 typedef struct QEMUPutMouseEntry {
     25     QEMUPutMouseEvent *qemu_put_mouse_event;
     26     void *qemu_put_mouse_event_opaque;
     27     int qemu_put_mouse_event_absolute;
     28     char *qemu_put_mouse_event_name;
     29 
     30     /* used internally by qemu for handling mice */
     31     struct QEMUPutMouseEntry *next;
     32 } QEMUPutMouseEntry;
     33 
     34 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
     35 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
     36                                                 void *opaque, int absolute,
     37                                                 const char *name);
     38 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
     39 
     40 void kbd_put_keycode(int keycode);
     41 void kbd_put_keycodes(int*  keycodes, int  count);
     42 void  kbd_generic_event(int  type, int code, int  value);
     43 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
     44 int kbd_mouse_is_absolute(void);
     45 
     46 struct MouseTransformInfo {
     47     /* Touchscreen resolution */
     48     int x;
     49     int y;
     50     /* Calibration values as used/generated by tslib */
     51     int a[7];
     52 };
     53 
     54 void do_info_mice(Monitor *mon);
     55 void do_mouse_set(Monitor *mon, int index);
     56 
     57 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
     58    constants) */
     59 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
     60 #define QEMU_KEY_BACKSPACE  0x007f
     61 #define QEMU_KEY_UP         QEMU_KEY_ESC1('A')
     62 #define QEMU_KEY_DOWN       QEMU_KEY_ESC1('B')
     63 #define QEMU_KEY_RIGHT      QEMU_KEY_ESC1('C')
     64 #define QEMU_KEY_LEFT       QEMU_KEY_ESC1('D')
     65 #define QEMU_KEY_HOME       QEMU_KEY_ESC1(1)
     66 #define QEMU_KEY_END        QEMU_KEY_ESC1(4)
     67 #define QEMU_KEY_PAGEUP     QEMU_KEY_ESC1(5)
     68 #define QEMU_KEY_PAGEDOWN   QEMU_KEY_ESC1(6)
     69 #define QEMU_KEY_DELETE     QEMU_KEY_ESC1(3)
     70 
     71 #define QEMU_KEY_CTRL_UP         0xe400
     72 #define QEMU_KEY_CTRL_DOWN       0xe401
     73 #define QEMU_KEY_CTRL_LEFT       0xe402
     74 #define QEMU_KEY_CTRL_RIGHT      0xe403
     75 #define QEMU_KEY_CTRL_HOME       0xe404
     76 #define QEMU_KEY_CTRL_END        0xe405
     77 #define QEMU_KEY_CTRL_PAGEUP     0xe406
     78 #define QEMU_KEY_CTRL_PAGEDOWN   0xe407
     79 
     80 void kbd_put_keysym(int keysym);
     81 
     82 /* consoles */
     83 
     84 #define QEMU_BIG_ENDIAN_FLAG    0x01
     85 #define QEMU_ALLOCATED_FLAG     0x02
     86 
     87 struct PixelFormat {
     88     uint8_t bits_per_pixel;
     89     uint8_t bytes_per_pixel;
     90     uint8_t depth; /* color depth in bits */
     91     uint32_t rmask, gmask, bmask, amask;
     92     uint8_t rshift, gshift, bshift, ashift;
     93     uint8_t rmax, gmax, bmax, amax;
     94     uint8_t rbits, gbits, bbits, abits;
     95 };
     96 
     97 struct DisplaySurface {
     98     uint8_t flags;
     99     int width;
    100     int height;
    101     int linesize;        /* bytes per line */
    102     uint8_t *data;
    103 
    104     struct PixelFormat pf;
    105 };
    106 
    107 struct DisplayChangeListener {
    108     int idle;
    109     uint64_t gui_timer_interval;
    110 
    111     void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
    112     void (*dpy_resize)(struct DisplayState *s);
    113     void (*dpy_setdata)(struct DisplayState *s);
    114     void (*dpy_refresh)(struct DisplayState *s);
    115     void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
    116                      int dst_x, int dst_y, int w, int h);
    117     void (*dpy_fill)(struct DisplayState *s, int x, int y,
    118                      int w, int h, uint32_t c);
    119     void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
    120 
    121     struct DisplayChangeListener *next;
    122 };
    123 
    124 struct DisplayAllocator {
    125     DisplaySurface* (*create_displaysurface)(int width, int height);
    126     DisplaySurface* (*resize_displaysurface)(DisplaySurface *surface, int width, int height);
    127     void (*free_displaysurface)(DisplaySurface *surface);
    128 };
    129 
    130 struct DisplayState {
    131     struct DisplaySurface *surface;
    132     void *opaque;
    133     struct QEMUTimer *gui_timer;
    134 
    135     struct DisplayAllocator* allocator;
    136     struct DisplayChangeListener* listeners;
    137 
    138     void (*mouse_set)(int x, int y, int on);
    139     void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
    140                           uint8_t *image, uint8_t *mask);
    141 
    142     struct DisplayState *next;
    143 };
    144 
    145 void register_displaystate(DisplayState *ds);
    146 DisplayState *get_displaystate(void);
    147 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
    148                                                 int linesize, uint8_t *data);
    149 PixelFormat qemu_different_endianness_pixelformat(int bpp);
    150 PixelFormat qemu_default_pixelformat(int bpp);
    151 
    152 extern struct DisplayAllocator default_allocator;
    153 DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
    154 DisplaySurface* defaultallocator_create_displaysurface(int width, int height);
    155 DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface, int width, int height);
    156 void defaultallocator_free_displaysurface(DisplaySurface *surface);
    157 
    158 static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
    159 {
    160     return ds->allocator->create_displaysurface(width, height);
    161 }
    162 
    163 static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height)
    164 {
    165     return ds->allocator->resize_displaysurface(ds->surface, width, height);
    166 }
    167 
    168 static inline void qemu_free_displaysurface(DisplayState *ds)
    169 {
    170     ds->allocator->free_displaysurface(ds->surface);
    171 }
    172 
    173 static inline int is_surface_bgr(DisplaySurface *surface)
    174 {
    175     if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
    176         return 1;
    177     else
    178         return 0;
    179 }
    180 
    181 static inline int is_buffer_shared(DisplaySurface *surface)
    182 {
    183     return (!(surface->flags & QEMU_ALLOCATED_FLAG));
    184 }
    185 
    186 static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
    187 {
    188     dcl->next = ds->listeners;
    189     ds->listeners = dcl;
    190 }
    191 
    192 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
    193 {
    194     struct DisplayChangeListener *dcl = s->listeners;
    195     while (dcl != NULL) {
    196         dcl->dpy_update(s, x, y, w, h);
    197         dcl = dcl->next;
    198     }
    199 }
    200 
    201 static inline void dpy_resize(DisplayState *s)
    202 {
    203     struct DisplayChangeListener *dcl = s->listeners;
    204     while (dcl != NULL) {
    205         dcl->dpy_resize(s);
    206         dcl = dcl->next;
    207     }
    208 }
    209 
    210 static inline void dpy_setdata(DisplayState *s)
    211 {
    212     struct DisplayChangeListener *dcl = s->listeners;
    213     while (dcl != NULL) {
    214         if (dcl->dpy_setdata) dcl->dpy_setdata(s);
    215         dcl = dcl->next;
    216     }
    217 }
    218 
    219 static inline void dpy_refresh(DisplayState *s)
    220 {
    221     struct DisplayChangeListener *dcl = s->listeners;
    222     while (dcl != NULL) {
    223         if (dcl->dpy_refresh) dcl->dpy_refresh(s);
    224         dcl = dcl->next;
    225     }
    226 }
    227 
    228 static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
    229                              int dst_x, int dst_y, int w, int h) {
    230     struct DisplayChangeListener *dcl = s->listeners;
    231     while (dcl != NULL) {
    232         if (dcl->dpy_copy)
    233             dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
    234         else /* TODO */
    235             dcl->dpy_update(s, dst_x, dst_y, w, h);
    236         dcl = dcl->next;
    237     }
    238 }
    239 
    240 static inline void dpy_fill(struct DisplayState *s, int x, int y,
    241                              int w, int h, uint32_t c) {
    242     struct DisplayChangeListener *dcl = s->listeners;
    243     while (dcl != NULL) {
    244         if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
    245         dcl = dcl->next;
    246     }
    247 }
    248 
    249 static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
    250     struct DisplayChangeListener *dcl = s->listeners;
    251     while (dcl != NULL) {
    252         if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
    253         dcl = dcl->next;
    254     }
    255 }
    256 
    257 static inline int ds_get_linesize(DisplayState *ds)
    258 {
    259     return ds->surface->linesize;
    260 }
    261 
    262 static inline uint8_t* ds_get_data(DisplayState *ds)
    263 {
    264     return ds->surface->data;
    265 }
    266 
    267 static inline int ds_get_width(DisplayState *ds)
    268 {
    269     return ds->surface->width;
    270 }
    271 
    272 static inline int ds_get_height(DisplayState *ds)
    273 {
    274     return ds->surface->height;
    275 }
    276 
    277 static inline int ds_get_bits_per_pixel(DisplayState *ds)
    278 {
    279     return ds->surface->pf.bits_per_pixel;
    280 }
    281 
    282 static inline int ds_get_bytes_per_pixel(DisplayState *ds)
    283 {
    284     return ds->surface->pf.bytes_per_pixel;
    285 }
    286 
    287 typedef unsigned long console_ch_t;
    288 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
    289 {
    290     cpu_to_le32wu((uint32_t *) dest, ch);
    291 }
    292 
    293 typedef void (*vga_hw_update_ptr)(void *);
    294 typedef void (*vga_hw_invalidate_ptr)(void *);
    295 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
    296 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
    297 
    298 DisplayState *graphic_console_init(vga_hw_update_ptr update,
    299                                    vga_hw_invalidate_ptr invalidate,
    300                                    vga_hw_screen_dump_ptr screen_dump,
    301                                    vga_hw_text_update_ptr text_update,
    302                                    void *opaque);
    303 
    304 void vga_hw_update(void);
    305 void vga_hw_invalidate(void);
    306 void vga_hw_screen_dump(const char *filename);
    307 void vga_hw_text_update(console_ch_t *chardata);
    308 
    309 int is_graphic_console(void);
    310 int is_fixedsize_console(void);
    311 CharDriverState *text_console_init(const char *p);
    312 void text_consoles_set_display(DisplayState *ds);
    313 void console_select(unsigned int index);
    314 void console_color_init(DisplayState *ds);
    315 void qemu_console_resize(DisplayState *ds, int width, int height);
    316 void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
    317                        int dst_x, int dst_y, int w, int h);
    318 
    319 /* sdl.c */
    320 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
    321 
    322 /* cocoa.m */
    323 void cocoa_display_init(DisplayState *ds, int full_screen);
    324 
    325 /* vnc.c */
    326 void vnc_display_init(DisplayState *ds);
    327 void vnc_display_close(DisplayState *ds);
    328 int vnc_display_open(DisplayState *ds, const char *display);
    329 int vnc_display_password(DisplayState *ds, const char *password);
    330 void do_info_vnc(Monitor *mon);
    331 char *vnc_display_local_addr(DisplayState *ds);
    332 
    333 /* curses.c */
    334 void curses_display_init(DisplayState *ds, int full_screen);
    335 
    336 #endif
    337