blob: 92221150825663f9ea22668397fde70380206234 [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001#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
19typedef void QEMUPutKBDEvent(void *opaque, int keycode);
20typedef void QEMUPutKBDEventN(void *opaque, int* keycodes, int count);
21typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
22typedef void QEMUPutGenericEvent(void* opaque, int type, int code, int value);
23
24typedef 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
34void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
35QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
36 void *opaque, int absolute,
37 const char *name);
38void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry);
39
40void kbd_put_keycode(int keycode);
41void kbd_put_keycodes(int* keycodes, int count);
42void kbd_generic_event(int type, int code, int value);
43void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
44int kbd_mouse_is_absolute(void);
45
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070046struct MouseTransformInfo {
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080047 /* Touchscreen resolution */
48 int x;
49 int y;
50 /* Calibration values as used/generated by tslib */
51 int a[7];
52};
53
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070054void do_info_mice(Monitor *mon);
55void do_mouse_set(Monitor *mon, int index);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080056
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
80void kbd_put_keysym(int keysym);
81
82/* consoles */
83
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070084#define QEMU_BIG_ENDIAN_FLAG 0x01
85#define QEMU_ALLOCATED_FLAG 0x02
86
87struct 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
97struct DisplaySurface {
98 uint8_t flags;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080099 int width;
100 int height;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700101 int linesize; /* bytes per line */
102 uint8_t *data;
103
104 struct PixelFormat pf;
105};
106
107struct DisplayChangeListener {
108 int idle;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800109 uint64_t gui_timer_interval;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800110
111 void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700112 void (*dpy_resize)(struct DisplayState *s);
113 void (*dpy_setdata)(struct DisplayState *s);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800114 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);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700120
121 struct DisplayChangeListener *next;
122};
123
124struct 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
130struct DisplayState {
131 struct DisplaySurface *surface;
132 void *opaque;
133 struct QEMUTimer *gui_timer;
134
135 struct DisplayAllocator* allocator;
136 struct DisplayChangeListener* listeners;
137
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800138 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);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700141
142 struct DisplayState *next;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800143};
144
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700145void register_displaystate(DisplayState *ds);
146DisplayState *get_displaystate(void);
147DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
148 int linesize, uint8_t *data);
149PixelFormat qemu_different_endianness_pixelformat(int bpp);
150PixelFormat qemu_default_pixelformat(int bpp);
151
152extern struct DisplayAllocator default_allocator;
153DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
154DisplaySurface* defaultallocator_create_displaysurface(int width, int height);
155DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface, int width, int height);
156void defaultallocator_free_displaysurface(DisplaySurface *surface);
157
158static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
159{
160 return ds->allocator->create_displaysurface(width, height);
161}
162
163static inline DisplaySurface* qemu_resize_displaysurface(DisplayState *ds, int width, int height)
164{
165 return ds->allocator->resize_displaysurface(ds->surface, width, height);
166}
167
168static inline void qemu_free_displaysurface(DisplayState *ds)
169{
170 ds->allocator->free_displaysurface(ds->surface);
171}
172
173static 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
181static inline int is_buffer_shared(DisplaySurface *surface)
182{
183 return (!(surface->flags & QEMU_ALLOCATED_FLAG));
184}
185
186static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
187{
188 dcl->next = ds->listeners;
189 ds->listeners = dcl;
190}
191
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800192static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
193{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700194 struct DisplayChangeListener *dcl = s->listeners;
195 while (dcl != NULL) {
196 dcl->dpy_update(s, x, y, w, h);
197 dcl = dcl->next;
198 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800199}
200
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700201static inline void dpy_resize(DisplayState *s)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800202{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700203 struct DisplayChangeListener *dcl = s->listeners;
204 while (dcl != NULL) {
205 dcl->dpy_resize(s);
206 dcl = dcl->next;
207 }
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800208}
209
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700210static inline void dpy_setdata(DisplayState *s)
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800211{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700212 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
219static 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
228static 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
240static 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
249static 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
257static inline int ds_get_linesize(DisplayState *ds)
258{
259 return ds->surface->linesize;
260}
261
262static inline uint8_t* ds_get_data(DisplayState *ds)
263{
264 return ds->surface->data;
265}
266
267static inline int ds_get_width(DisplayState *ds)
268{
269 return ds->surface->width;
270}
271
272static inline int ds_get_height(DisplayState *ds)
273{
274 return ds->surface->height;
275}
276
277static inline int ds_get_bits_per_pixel(DisplayState *ds)
278{
279 return ds->surface->pf.bits_per_pixel;
280}
281
282static inline int ds_get_bytes_per_pixel(DisplayState *ds)
283{
284 return ds->surface->pf.bytes_per_pixel;
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800285}
286
287typedef unsigned long console_ch_t;
288static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
289{
290 cpu_to_le32wu((uint32_t *) dest, ch);
291}
292
293typedef void (*vga_hw_update_ptr)(void *);
294typedef void (*vga_hw_invalidate_ptr)(void *);
295typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
296typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
297
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700298DisplayState *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
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800304void vga_hw_update(void);
305void vga_hw_invalidate(void);
306void vga_hw_screen_dump(const char *filename);
307void vga_hw_text_update(console_ch_t *chardata);
308
309int is_graphic_console(void);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700310int is_fixedsize_console(void);
311CharDriverState *text_console_init(const char *p);
312void text_consoles_set_display(DisplayState *ds);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800313void console_select(unsigned int index);
314void console_color_init(DisplayState *ds);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700315void qemu_console_resize(DisplayState *ds, int width, int height);
316void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
317 int dst_x, int dst_y, int w, int h);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800318
319/* sdl.c */
320void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
321
322/* cocoa.m */
323void cocoa_display_init(DisplayState *ds, int full_screen);
324
325/* vnc.c */
326void vnc_display_init(DisplayState *ds);
327void vnc_display_close(DisplayState *ds);
328int vnc_display_open(DisplayState *ds, const char *display);
329int vnc_display_password(DisplayState *ds, const char *password);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700330void do_info_vnc(Monitor *mon);
331char *vnc_display_local_addr(DisplayState *ds);
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800332
333/* curses.c */
334void curses_display_init(DisplayState *ds, int full_screen);
335
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800336#endif