console.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. #ifndef CONSOLE_H
  2. #define CONSOLE_H
  3. #include "qemu-char.h"
  4. #include "qdict.h"
  5. #include "notify.h"
  6. #include "monitor.h"
  7. #include "trace.h"
  8. /* keyboard/mouse support */
  9. #define MOUSE_EVENT_LBUTTON 0x01
  10. #define MOUSE_EVENT_RBUTTON 0x02
  11. #define MOUSE_EVENT_MBUTTON 0x04
  12. /* identical to the ps/2 keyboard bits */
  13. #define QEMU_SCROLL_LOCK_LED (1 << 0)
  14. #define QEMU_NUM_LOCK_LED (1 << 1)
  15. #define QEMU_CAPS_LOCK_LED (1 << 2)
  16. /* in ms */
  17. #define GUI_REFRESH_INTERVAL 30
  18. typedef void QEMUPutKBDEvent(void *opaque, int keycode);
  19. typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
  20. typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
  21. typedef struct QEMUPutMouseEntry {
  22. QEMUPutMouseEvent *qemu_put_mouse_event;
  23. void *qemu_put_mouse_event_opaque;
  24. int qemu_put_mouse_event_absolute;
  25. char *qemu_put_mouse_event_name;
  26. int index;
  27. /* used internally by qemu for handling mice */
  28. QTAILQ_ENTRY(QEMUPutMouseEntry) node;
  29. } QEMUPutMouseEntry;
  30. typedef struct QEMUPutLEDEntry {
  31. QEMUPutLEDEvent *put_led;
  32. void *opaque;
  33. QTAILQ_ENTRY(QEMUPutLEDEntry) next;
  34. } QEMUPutLEDEntry;
  35. void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
  36. void qemu_remove_kbd_event_handler(void);
  37. QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
  38. void *opaque, int absolute,
  39. const char *name);
  40. void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
  41. void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
  42. QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
  43. void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
  44. void kbd_put_keycode(int keycode);
  45. void kbd_put_ledstate(int ledstate);
  46. void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
  47. /* Does the current mouse generate absolute events */
  48. int kbd_mouse_is_absolute(void);
  49. void qemu_add_mouse_mode_change_notifier(Notifier *notify);
  50. void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
  51. /* Of all the mice, is there one that generates absolute events */
  52. int kbd_mouse_has_absolute(void);
  53. struct MouseTransformInfo {
  54. /* Touchscreen resolution */
  55. int x;
  56. int y;
  57. /* Calibration values as used/generated by tslib */
  58. int a[7];
  59. };
  60. void do_mouse_set(Monitor *mon, const QDict *qdict);
  61. /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
  62. constants) */
  63. #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
  64. #define QEMU_KEY_BACKSPACE 0x007f
  65. #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
  66. #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
  67. #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
  68. #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
  69. #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
  70. #define QEMU_KEY_END QEMU_KEY_ESC1(4)
  71. #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
  72. #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
  73. #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
  74. #define QEMU_KEY_CTRL_UP 0xe400
  75. #define QEMU_KEY_CTRL_DOWN 0xe401
  76. #define QEMU_KEY_CTRL_LEFT 0xe402
  77. #define QEMU_KEY_CTRL_RIGHT 0xe403
  78. #define QEMU_KEY_CTRL_HOME 0xe404
  79. #define QEMU_KEY_CTRL_END 0xe405
  80. #define QEMU_KEY_CTRL_PAGEUP 0xe406
  81. #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
  82. void kbd_put_keysym(int keysym);
  83. /* consoles */
  84. #define QEMU_BIG_ENDIAN_FLAG 0x01
  85. #define QEMU_ALLOCATED_FLAG 0x02
  86. #define QEMU_REALPIXELS_FLAG 0x04
  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. struct DisplaySurface {
  97. uint8_t flags;
  98. int width;
  99. int height;
  100. int linesize; /* bytes per line */
  101. uint8_t *data;
  102. struct PixelFormat pf;
  103. };
  104. /* cursor data format is 32bit RGBA */
  105. typedef struct QEMUCursor {
  106. int width, height;
  107. int hot_x, hot_y;
  108. int refcount;
  109. uint32_t data[];
  110. } QEMUCursor;
  111. QEMUCursor *cursor_alloc(int width, int height);
  112. void cursor_get(QEMUCursor *c);
  113. void cursor_put(QEMUCursor *c);
  114. QEMUCursor *cursor_builtin_hidden(void);
  115. QEMUCursor *cursor_builtin_left_ptr(void);
  116. void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
  117. int cursor_get_mono_bpl(QEMUCursor *c);
  118. void cursor_set_mono(QEMUCursor *c,
  119. uint32_t foreground, uint32_t background, uint8_t *image,
  120. int transparent, uint8_t *mask);
  121. void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
  122. void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
  123. struct DisplayChangeListener {
  124. int idle;
  125. uint64_t gui_timer_interval;
  126. void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
  127. void (*dpy_resize)(struct DisplayState *s);
  128. void (*dpy_setdata)(struct DisplayState *s);
  129. void (*dpy_refresh)(struct DisplayState *s);
  130. void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y,
  131. int dst_x, int dst_y, int w, int h);
  132. void (*dpy_fill)(struct DisplayState *s, int x, int y,
  133. int w, int h, uint32_t c);
  134. void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
  135. struct DisplayChangeListener *next;
  136. };
  137. struct DisplayAllocator {
  138. DisplaySurface* (*create_displaysurface)(int width, int height);
  139. DisplaySurface* (*resize_displaysurface)(DisplaySurface *surface, int width, int height);
  140. void (*free_displaysurface)(DisplaySurface *surface);
  141. };
  142. struct DisplayState {
  143. struct DisplaySurface *surface;
  144. void *opaque;
  145. struct QEMUTimer *gui_timer;
  146. struct DisplayAllocator* allocator;
  147. struct DisplayChangeListener* listeners;
  148. void (*mouse_set)(int x, int y, int on);
  149. void (*cursor_define)(QEMUCursor *cursor);
  150. struct DisplayState *next;
  151. };
  152. void register_displaystate(DisplayState *ds);
  153. DisplayState *get_displaystate(void);
  154. DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
  155. int linesize, uint8_t *data);
  156. void qemu_alloc_display(DisplaySurface *surface, int width, int height,
  157. int linesize, PixelFormat pf, int newflags);
  158. PixelFormat qemu_different_endianness_pixelformat(int bpp);
  159. PixelFormat qemu_default_pixelformat(int bpp);
  160. DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
  161. static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
  162. {
  163. return ds->allocator->create_displaysurface(width, height);
  164. }
  165. static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height)
  166. {
  167. trace_displaysurface_resize(ds, ds->surface, width, height);
  168. return ds->allocator->resize_displaysurface(ds->surface, width, height);
  169. }
  170. static inline void qemu_free_displaysurface(DisplayState *ds)
  171. {
  172. trace_displaysurface_free(ds, ds->surface);
  173. ds->allocator->free_displaysurface(ds->surface);
  174. }
  175. static inline int is_surface_bgr(DisplaySurface *surface)
  176. {
  177. if (surface->pf.bits_per_pixel == 32 && surface->pf.rshift == 0)
  178. return 1;
  179. else
  180. return 0;
  181. }
  182. static inline int is_buffer_shared(DisplaySurface *surface)
  183. {
  184. return (!(surface->flags & QEMU_ALLOCATED_FLAG) &&
  185. !(surface->flags & QEMU_REALPIXELS_FLAG));
  186. }
  187. static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
  188. {
  189. dcl->next = ds->listeners;
  190. ds->listeners = dcl;
  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. static inline void dpy_resize(DisplayState *s)
  201. {
  202. struct DisplayChangeListener *dcl = s->listeners;
  203. while (dcl != NULL) {
  204. dcl->dpy_resize(s);
  205. dcl = dcl->next;
  206. }
  207. }
  208. static inline void dpy_setdata(DisplayState *s)
  209. {
  210. struct DisplayChangeListener *dcl = s->listeners;
  211. while (dcl != NULL) {
  212. if (dcl->dpy_setdata) dcl->dpy_setdata(s);
  213. dcl = dcl->next;
  214. }
  215. }
  216. static inline void dpy_refresh(DisplayState *s)
  217. {
  218. struct DisplayChangeListener *dcl = s->listeners;
  219. while (dcl != NULL) {
  220. if (dcl->dpy_refresh) dcl->dpy_refresh(s);
  221. dcl = dcl->next;
  222. }
  223. }
  224. static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
  225. int dst_x, int dst_y, int w, int h) {
  226. struct DisplayChangeListener *dcl = s->listeners;
  227. while (dcl != NULL) {
  228. if (dcl->dpy_copy)
  229. dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
  230. else /* TODO */
  231. dcl->dpy_update(s, dst_x, dst_y, w, h);
  232. dcl = dcl->next;
  233. }
  234. }
  235. static inline void dpy_fill(struct DisplayState *s, int x, int y,
  236. int w, int h, uint32_t c) {
  237. struct DisplayChangeListener *dcl = s->listeners;
  238. while (dcl != NULL) {
  239. if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
  240. dcl = dcl->next;
  241. }
  242. }
  243. static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
  244. struct DisplayChangeListener *dcl = s->listeners;
  245. while (dcl != NULL) {
  246. if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
  247. dcl = dcl->next;
  248. }
  249. }
  250. static inline int ds_get_linesize(DisplayState *ds)
  251. {
  252. return ds->surface->linesize;
  253. }
  254. static inline uint8_t* ds_get_data(DisplayState *ds)
  255. {
  256. return ds->surface->data;
  257. }
  258. static inline int ds_get_width(DisplayState *ds)
  259. {
  260. return ds->surface->width;
  261. }
  262. static inline int ds_get_height(DisplayState *ds)
  263. {
  264. return ds->surface->height;
  265. }
  266. static inline int ds_get_bits_per_pixel(DisplayState *ds)
  267. {
  268. return ds->surface->pf.bits_per_pixel;
  269. }
  270. static inline int ds_get_bytes_per_pixel(DisplayState *ds)
  271. {
  272. return ds->surface->pf.bytes_per_pixel;
  273. }
  274. #ifdef CONFIG_CURSES
  275. #include <curses.h>
  276. typedef chtype console_ch_t;
  277. #else
  278. typedef unsigned long console_ch_t;
  279. #endif
  280. static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
  281. {
  282. if (!(ch & 0xff))
  283. ch |= ' ';
  284. *dest = ch;
  285. }
  286. typedef void (*vga_hw_update_ptr)(void *);
  287. typedef void (*vga_hw_invalidate_ptr)(void *);
  288. typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
  289. typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
  290. DisplayState *graphic_console_init(vga_hw_update_ptr update,
  291. vga_hw_invalidate_ptr invalidate,
  292. vga_hw_screen_dump_ptr screen_dump,
  293. vga_hw_text_update_ptr text_update,
  294. void *opaque);
  295. void vga_hw_update(void);
  296. void vga_hw_invalidate(void);
  297. void vga_hw_screen_dump(const char *filename);
  298. void vga_hw_text_update(console_ch_t *chardata);
  299. int is_graphic_console(void);
  300. int is_fixedsize_console(void);
  301. CharDriverState *text_console_init(QemuOpts *opts);
  302. void text_consoles_set_display(DisplayState *ds);
  303. void console_select(unsigned int index);
  304. void console_color_init(DisplayState *ds);
  305. void qemu_console_resize(DisplayState *ds, int width, int height);
  306. void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
  307. int dst_x, int dst_y, int w, int h);
  308. /* sdl.c */
  309. void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
  310. /* cocoa.m */
  311. void cocoa_display_init(DisplayState *ds, int full_screen);
  312. /* vnc.c */
  313. void vnc_display_init(DisplayState *ds);
  314. void vnc_display_close(DisplayState *ds);
  315. int vnc_display_open(DisplayState *ds, const char *display);
  316. void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
  317. int vnc_display_disable_login(DisplayState *ds);
  318. char *vnc_display_local_addr(DisplayState *ds);
  319. #ifdef CONFIG_VNC
  320. int vnc_display_password(DisplayState *ds, const char *password);
  321. int vnc_display_pw_expire(DisplayState *ds, time_t expires);
  322. #else
  323. static inline int vnc_display_password(DisplayState *ds, const char *password)
  324. {
  325. return -ENODEV;
  326. }
  327. static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
  328. {
  329. return -ENODEV;
  330. };
  331. #endif
  332. /* curses.c */
  333. void curses_display_init(DisplayState *ds, int full_screen);
  334. #endif