]>
Commit | Line | Data |
---|---|---|
87ecb68b PB |
1 | #ifndef CONSOLE_H |
2 | #define CONSOLE_H | |
3 | ||
28ecbaee | 4 | #include "ui/qemu-pixman.h" |
95be0669 | 5 | #include "qom/object.h" |
7b1b5d19 | 6 | #include "qapi/qmp/qdict.h" |
1de7afc9 | 7 | #include "qemu/notify.h" |
83c9089e | 8 | #include "monitor/monitor.h" |
1048c88f | 9 | #include "qapi-types.h" |
7b1b5d19 | 10 | #include "qapi/error.h" |
87ecb68b | 11 | |
cd2bc889 GH |
12 | #ifdef CONFIG_OPENGL |
13 | # include <GLES2/gl2.h> | |
14 | # include <GLES2/gl2ext.h> | |
15 | #endif | |
16 | ||
87ecb68b PB |
17 | /* keyboard/mouse support */ |
18 | ||
19 | #define MOUSE_EVENT_LBUTTON 0x01 | |
20 | #define MOUSE_EVENT_RBUTTON 0x02 | |
21 | #define MOUSE_EVENT_MBUTTON 0x04 | |
21bae11a GH |
22 | #define MOUSE_EVENT_WHEELUP 0x08 |
23 | #define MOUSE_EVENT_WHEELDN 0x10 | |
87ecb68b | 24 | |
03a23a85 GH |
25 | /* identical to the ps/2 keyboard bits */ |
26 | #define QEMU_SCROLL_LOCK_LED (1 << 0) | |
27 | #define QEMU_NUM_LOCK_LED (1 << 1) | |
28 | #define QEMU_CAPS_LOCK_LED (1 << 2) | |
29 | ||
7ed9eba3 | 30 | /* in ms */ |
0f7b2864 GH |
31 | #define GUI_REFRESH_INTERVAL_DEFAULT 30 |
32 | #define GUI_REFRESH_INTERVAL_IDLE 3000 | |
7ed9eba3 | 33 | |
87ecb68b | 34 | typedef void QEMUPutKBDEvent(void *opaque, int keycode); |
03a23a85 | 35 | typedef void QEMUPutLEDEvent(void *opaque, int ledstate); |
87ecb68b PB |
36 | typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state); |
37 | ||
72711efb | 38 | typedef struct QEMUPutMouseEntry QEMUPutMouseEntry; |
5a37532d | 39 | typedef struct QEMUPutKbdEntry QEMUPutKbdEntry; |
72711efb | 40 | typedef struct QEMUPutLEDEntry QEMUPutLEDEntry; |
03a23a85 | 41 | |
5a37532d GH |
42 | QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, |
43 | void *opaque); | |
87ecb68b PB |
44 | QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func, |
45 | void *opaque, int absolute, | |
46 | const char *name); | |
47 | void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry); | |
6fef28ee AL |
48 | void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry); |
49 | ||
03a23a85 GH |
50 | QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque); |
51 | void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry); | |
87ecb68b | 52 | |
03a23a85 | 53 | void kbd_put_ledstate(int ledstate); |
eb2e259d | 54 | |
bc24a225 | 55 | struct MouseTransformInfo { |
a5d7eb65 AZ |
56 | /* Touchscreen resolution */ |
57 | int x; | |
58 | int y; | |
59 | /* Calibration values as used/generated by tslib */ | |
60 | int a[7]; | |
61 | }; | |
62 | ||
3e5a50d6 | 63 | void hmp_mouse_set(Monitor *mon, const QDict *qdict); |
87ecb68b PB |
64 | |
65 | /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx | |
66 | constants) */ | |
67 | #define QEMU_KEY_ESC1(c) ((c) | 0xe100) | |
68 | #define QEMU_KEY_BACKSPACE 0x007f | |
69 | #define QEMU_KEY_UP QEMU_KEY_ESC1('A') | |
70 | #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B') | |
71 | #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C') | |
72 | #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D') | |
73 | #define QEMU_KEY_HOME QEMU_KEY_ESC1(1) | |
74 | #define QEMU_KEY_END QEMU_KEY_ESC1(4) | |
75 | #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5) | |
76 | #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6) | |
77 | #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3) | |
78 | ||
79 | #define QEMU_KEY_CTRL_UP 0xe400 | |
80 | #define QEMU_KEY_CTRL_DOWN 0xe401 | |
81 | #define QEMU_KEY_CTRL_LEFT 0xe402 | |
82 | #define QEMU_KEY_CTRL_RIGHT 0xe403 | |
83 | #define QEMU_KEY_CTRL_HOME 0xe404 | |
84 | #define QEMU_KEY_CTRL_END 0xe405 | |
85 | #define QEMU_KEY_CTRL_PAGEUP 0xe406 | |
86 | #define QEMU_KEY_CTRL_PAGEDOWN 0xe407 | |
87 | ||
3f9a6e85 | 88 | void kbd_put_keysym_console(QemuConsole *s, int keysym); |
50ef4679 | 89 | bool kbd_put_qcode_console(QemuConsole *s, int qcode); |
bdef9724 | 90 | void kbd_put_string_console(QemuConsole *s, const char *str, int len); |
87ecb68b PB |
91 | void kbd_put_keysym(int keysym); |
92 | ||
93 | /* consoles */ | |
94 | ||
95be0669 GH |
95 | #define TYPE_QEMU_CONSOLE "qemu-console" |
96 | #define QEMU_CONSOLE(obj) \ | |
97 | OBJECT_CHECK(QemuConsole, (obj), TYPE_QEMU_CONSOLE) | |
98 | #define QEMU_CONSOLE_GET_CLASS(obj) \ | |
99 | OBJECT_GET_CLASS(QemuConsoleClass, (obj), TYPE_QEMU_CONSOLE) | |
100 | #define QEMU_CONSOLE_CLASS(klass) \ | |
101 | OBJECT_CLASS_CHECK(QemuConsoleClass, (klass), TYPE_QEMU_CONSOLE) | |
102 | ||
103 | typedef struct QemuConsoleClass QemuConsoleClass; | |
104 | ||
105 | struct QemuConsoleClass { | |
106 | ObjectClass parent_class; | |
107 | }; | |
108 | ||
77bfcf28 | 109 | #define QEMU_ALLOCATED_FLAG 0x01 |
7d957bd8 AL |
110 | |
111 | struct 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; | |
90a1e3c0 | 118 | uint8_t rbits, gbits, bbits, abits; |
7d957bd8 AL |
119 | }; |
120 | ||
121 | struct DisplaySurface { | |
69c77777 GH |
122 | pixman_format_code_t format; |
123 | pixman_image_t *image; | |
7d957bd8 | 124 | uint8_t flags; |
cd2bc889 GH |
125 | #ifdef CONFIG_OPENGL |
126 | GLenum glformat; | |
127 | GLenum gltype; | |
128 | GLuint texture; | |
129 | #endif | |
7d957bd8 AL |
130 | }; |
131 | ||
6f90f3d7 GH |
132 | typedef struct QemuUIInfo { |
133 | /* geometry */ | |
134 | int xoff; | |
135 | int yoff; | |
136 | uint32_t width; | |
137 | uint32_t height; | |
138 | } QemuUIInfo; | |
139 | ||
254e5950 GH |
140 | /* cursor data format is 32bit RGBA */ |
141 | typedef struct QEMUCursor { | |
142 | int width, height; | |
143 | int hot_x, hot_y; | |
144 | int refcount; | |
145 | uint32_t data[]; | |
146 | } QEMUCursor; | |
147 | ||
148 | QEMUCursor *cursor_alloc(int width, int height); | |
149 | void cursor_get(QEMUCursor *c); | |
150 | void cursor_put(QEMUCursor *c); | |
151 | QEMUCursor *cursor_builtin_hidden(void); | |
152 | QEMUCursor *cursor_builtin_left_ptr(void); | |
153 | void cursor_print_ascii_art(QEMUCursor *c, const char *prefix); | |
154 | int cursor_get_mono_bpl(QEMUCursor *c); | |
155 | void cursor_set_mono(QEMUCursor *c, | |
156 | uint32_t foreground, uint32_t background, uint8_t *image, | |
157 | int transparent, uint8_t *mask); | |
158 | void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask); | |
159 | void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask); | |
160 | ||
7c20b4a3 GH |
161 | typedef struct DisplayChangeListenerOps { |
162 | const char *dpy_name; | |
163 | ||
bc2ed970 | 164 | void (*dpy_refresh)(DisplayChangeListener *dcl); |
7c20b4a3 GH |
165 | |
166 | void (*dpy_gfx_update)(DisplayChangeListener *dcl, | |
7c20b4a3 | 167 | int x, int y, int w, int h); |
c12aeb86 | 168 | void (*dpy_gfx_switch)(DisplayChangeListener *dcl, |
c12aeb86 | 169 | struct DisplaySurface *new_surface); |
7c20b4a3 | 170 | void (*dpy_gfx_copy)(DisplayChangeListener *dcl, |
bc2ed970 | 171 | int src_x, int src_y, |
a93a4a22 | 172 | int dst_x, int dst_y, int w, int h); |
49743df3 BH |
173 | bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl, |
174 | pixman_format_code_t format); | |
a93a4a22 | 175 | |
7c20b4a3 | 176 | void (*dpy_text_cursor)(DisplayChangeListener *dcl, |
7c20b4a3 GH |
177 | int x, int y); |
178 | void (*dpy_text_resize)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
179 | int w, int h); |
180 | void (*dpy_text_update)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
181 | int x, int y, int w, int h); |
182 | ||
183 | void (*dpy_mouse_set)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
184 | int x, int y, int on); |
185 | void (*dpy_cursor_define)(DisplayChangeListener *dcl, | |
7c20b4a3 GH |
186 | QEMUCursor *cursor); |
187 | } DisplayChangeListenerOps; | |
7d957bd8 | 188 | |
7c20b4a3 | 189 | struct DisplayChangeListener { |
0f7b2864 | 190 | uint64_t update_interval; |
7c20b4a3 GH |
191 | const DisplayChangeListenerOps *ops; |
192 | DisplayState *ds; | |
284d1c6b | 193 | QemuConsole *con; |
bf2fde70 | 194 | |
87e487a1 | 195 | QLIST_ENTRY(DisplayChangeListener) next; |
7d957bd8 AL |
196 | }; |
197 | ||
64840c66 | 198 | DisplayState *init_displaystate(void); |
30f1e661 GH |
199 | DisplaySurface *qemu_create_displaysurface_from(int width, int height, |
200 | pixman_format_code_t format, | |
201 | int linesize, uint8_t *data); | |
a77549b3 GH |
202 | DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height, |
203 | pixman_format_code_t format, | |
204 | int linesize, | |
205 | uint64_t addr); | |
0da2ea1b | 206 | PixelFormat qemu_default_pixelformat(int bpp); |
7d957bd8 | 207 | |
da229ef3 GH |
208 | DisplaySurface *qemu_create_displaysurface(int width, int height); |
209 | void qemu_free_displaysurface(DisplaySurface *surface); | |
7b5d76da AL |
210 | |
211 | static inline int is_surface_bgr(DisplaySurface *surface) | |
212 | { | |
30f1e661 GH |
213 | if (PIXMAN_FORMAT_BPP(surface->format) == 32 && |
214 | PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) { | |
7b5d76da | 215 | return 1; |
30f1e661 | 216 | } else { |
7b5d76da | 217 | return 0; |
30f1e661 | 218 | } |
7b5d76da AL |
219 | } |
220 | ||
7d957bd8 AL |
221 | static inline int is_buffer_shared(DisplaySurface *surface) |
222 | { | |
187cd1d9 | 223 | return !(surface->flags & QEMU_ALLOCATED_FLAG); |
7d957bd8 AL |
224 | } |
225 | ||
5209089f | 226 | void register_displaychangelistener(DisplayChangeListener *dcl); |
0f7b2864 GH |
227 | void update_displaychangelistener(DisplayChangeListener *dcl, |
228 | uint64_t interval); | |
7c20b4a3 GH |
229 | void unregister_displaychangelistener(DisplayChangeListener *dcl); |
230 | ||
6f90f3d7 GH |
231 | int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info); |
232 | ||
c78f7137 GH |
233 | void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h); |
234 | void dpy_gfx_replace_surface(QemuConsole *con, | |
da229ef3 | 235 | DisplaySurface *surface); |
c78f7137 | 236 | void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y, |
7c20b4a3 | 237 | int dst_x, int dst_y, int w, int h); |
c78f7137 GH |
238 | void dpy_text_cursor(QemuConsole *con, int x, int y); |
239 | void dpy_text_update(QemuConsole *con, int x, int y, int w, int h); | |
240 | void dpy_text_resize(QemuConsole *con, int w, int h); | |
241 | void dpy_mouse_set(QemuConsole *con, int x, int y, int on); | |
242 | void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor); | |
243 | bool dpy_cursor_define_supported(QemuConsole *con); | |
4c38762f GH |
244 | void dpy_gfx_update_dirty(QemuConsole *con, |
245 | MemoryRegion *address_space, | |
246 | uint64_t base, | |
247 | bool invalidate); | |
49743df3 BH |
248 | bool dpy_gfx_check_format(QemuConsole *con, |
249 | pixman_format_code_t format); | |
bf2fde70 | 250 | |
626e3b34 GH |
251 | static inline int surface_stride(DisplaySurface *s) |
252 | { | |
253 | return pixman_image_get_stride(s->image); | |
254 | } | |
255 | ||
256 | static inline void *surface_data(DisplaySurface *s) | |
257 | { | |
258 | return pixman_image_get_data(s->image); | |
259 | } | |
260 | ||
261 | static inline int surface_width(DisplaySurface *s) | |
262 | { | |
263 | return pixman_image_get_width(s->image); | |
264 | } | |
265 | ||
266 | static inline int surface_height(DisplaySurface *s) | |
267 | { | |
268 | return pixman_image_get_height(s->image); | |
269 | } | |
270 | ||
271 | static inline int surface_bits_per_pixel(DisplaySurface *s) | |
272 | { | |
273 | int bits = PIXMAN_FORMAT_BPP(s->format); | |
274 | return bits; | |
275 | } | |
276 | ||
277 | static inline int surface_bytes_per_pixel(DisplaySurface *s) | |
278 | { | |
279 | int bits = PIXMAN_FORMAT_BPP(s->format); | |
280 | return (bits + 7) / 8; | |
281 | } | |
282 | ||
df00bed0 DP |
283 | #ifdef CONFIG_CURSES |
284 | #include <curses.h> | |
285 | typedef chtype console_ch_t; | |
286 | #else | |
c227f099 | 287 | typedef unsigned long console_ch_t; |
df00bed0 | 288 | #endif |
c227f099 | 289 | static inline void console_write_ch(console_ch_t *dest, uint32_t ch) |
4d3b6f6e | 290 | { |
f6d20d0f BK |
291 | if (!(ch & 0xff)) |
292 | ch |= ' '; | |
9ae19b65 | 293 | *dest = ch; |
4d3b6f6e AZ |
294 | } |
295 | ||
380cd056 GH |
296 | typedef struct GraphicHwOps { |
297 | void (*invalidate)(void *opaque); | |
298 | void (*gfx_update)(void *opaque); | |
299 | void (*text_update)(void *opaque, console_ch_t *text); | |
dea1b0bd | 300 | void (*update_interval)(void *opaque, uint64_t interval); |
6f90f3d7 | 301 | int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info); |
380cd056 | 302 | } GraphicHwOps; |
87ecb68b | 303 | |
5643706a | 304 | QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head, |
aa2beaa1 | 305 | const GraphicHwOps *ops, |
c78f7137 | 306 | void *opaque); |
1c1f9498 GH |
307 | void graphic_console_set_hwops(QemuConsole *con, |
308 | const GraphicHwOps *hw_ops, | |
309 | void *opaque); | |
3023f332 | 310 | |
1dbfa005 GH |
311 | void graphic_hw_update(QemuConsole *con); |
312 | void graphic_hw_invalidate(QemuConsole *con); | |
313 | void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata); | |
87ecb68b | 314 | |
284d1c6b | 315 | QemuConsole *qemu_console_lookup_by_index(unsigned int index); |
5643706a | 316 | QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head); |
81c0d5a6 GH |
317 | bool qemu_console_is_visible(QemuConsole *con); |
318 | bool qemu_console_is_graphic(QemuConsole *con); | |
319 | bool qemu_console_is_fixedsize(QemuConsole *con); | |
779ce88f | 320 | char *qemu_console_get_label(QemuConsole *con); |
d4c85337 | 321 | int qemu_console_get_index(QemuConsole *con); |
5643706a | 322 | uint32_t qemu_console_get_head(QemuConsole *con); |
6f90f3d7 | 323 | QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con); |
d4c85337 GH |
324 | int qemu_console_get_width(QemuConsole *con, int fallback); |
325 | int qemu_console_get_height(QemuConsole *con, int fallback); | |
81c0d5a6 | 326 | |
2796dae0 | 327 | void text_consoles_set_display(DisplayState *ds); |
87ecb68b PB |
328 | void console_select(unsigned int index); |
329 | void console_color_init(DisplayState *ds); | |
c78f7137 GH |
330 | void qemu_console_resize(QemuConsole *con, int width, int height); |
331 | void qemu_console_copy(QemuConsole *con, int src_x, int src_y, | |
3023f332 | 332 | int dst_x, int dst_y, int w, int h); |
c78f7137 | 333 | DisplaySurface *qemu_console_surface(QemuConsole *con); |
87ecb68b | 334 | |
cd2bc889 GH |
335 | /* console-gl.c */ |
336 | typedef struct ConsoleGLState ConsoleGLState; | |
337 | #ifdef CONFIG_OPENGL | |
338 | ConsoleGLState *console_gl_init_context(void); | |
339 | void console_gl_fini_context(ConsoleGLState *gls); | |
340 | bool console_gl_check_format(DisplayChangeListener *dcl, | |
341 | pixman_format_code_t format); | |
342 | void surface_gl_create_texture(ConsoleGLState *gls, | |
343 | DisplaySurface *surface); | |
344 | void surface_gl_update_texture(ConsoleGLState *gls, | |
345 | DisplaySurface *surface, | |
346 | int x, int y, int w, int h); | |
347 | void surface_gl_render_texture(ConsoleGLState *gls, | |
348 | DisplaySurface *surface); | |
349 | void surface_gl_destroy_texture(ConsoleGLState *gls, | |
350 | DisplaySurface *surface); | |
351 | void surface_gl_setup_viewport(ConsoleGLState *gls, | |
352 | DisplaySurface *surface, | |
353 | int ww, int wh); | |
354 | #endif | |
355 | ||
87ecb68b PB |
356 | /* sdl.c */ |
357 | void sdl_display_init(DisplayState *ds, int full_screen, int no_frame); | |
358 | ||
359 | /* cocoa.m */ | |
360 | void cocoa_display_init(DisplayState *ds, int full_screen); | |
361 | ||
362 | /* vnc.c */ | |
14f7143e | 363 | void vnc_display_init(const char *id); |
4db14629 | 364 | void vnc_display_open(const char *id, Error **errp); |
14f7143e GH |
365 | void vnc_display_add_client(const char *id, int csock, bool skipauth); |
366 | char *vnc_display_local_addr(const char *id); | |
821601ea | 367 | #ifdef CONFIG_VNC |
14f7143e GH |
368 | int vnc_display_password(const char *id, const char *password); |
369 | int vnc_display_pw_expire(const char *id, time_t expires); | |
4db14629 GH |
370 | QemuOpts *vnc_parse_func(const char *str); |
371 | int vnc_init_func(QemuOpts *opts, void *opaque); | |
821601ea | 372 | #else |
14f7143e | 373 | static inline int vnc_display_password(const char *id, const char *password) |
821601ea | 374 | { |
821601ea JS |
375 | return -ENODEV; |
376 | } | |
14f7143e | 377 | static inline int vnc_display_pw_expire(const char *id, time_t expires) |
821601ea | 378 | { |
821601ea JS |
379 | return -ENODEV; |
380 | }; | |
821601ea | 381 | #endif |
87ecb68b | 382 | |
4d3b6f6e AZ |
383 | /* curses.c */ |
384 | void curses_display_init(DisplayState *ds, int full_screen); | |
385 | ||
1048c88f | 386 | /* input.c */ |
1048c88f | 387 | int index_from_key(const char *key); |
1048c88f | 388 | |
a4ccabcf AL |
389 | /* gtk.c */ |
390 | void early_gtk_display_init(void); | |
881249c7 | 391 | void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover); |
a4ccabcf | 392 | |
87ecb68b | 393 | #endif |