master
h 457 lines 16.8 KB
Raw
1 #ifndef CONSOLE_H
2 #define CONSOLE_H
3
4 #include "ui/qemu-pixman.h"
5 #include "qom/object.h"
6 #include "qemu/notify.h"
7 #include "qapi/qapi-types-ui.h"
8 #include "ui/input.h"
9 #include "ui/surface.h"
10 #include "ui/dmabuf.h"
11
12 #define TYPE_QEMU_CONSOLE "qemu-console"
13 OBJECT_DECLARE_TYPE(QemuConsole, QemuConsoleClass, QEMU_CONSOLE)
14
15 #define TYPE_QEMU_GRAPHIC_CONSOLE "qemu-graphic-console"
16 OBJECT_DECLARE_SIMPLE_TYPE(QemuGraphicConsole, QEMU_GRAPHIC_CONSOLE)
17
18 #define TYPE_QEMU_TEXT_CONSOLE "qemu-text-console"
19 OBJECT_DECLARE_SIMPLE_TYPE(QemuTextConsole, QEMU_TEXT_CONSOLE)
20
21 #define TYPE_QEMU_FIXED_TEXT_CONSOLE "qemu-fixed-text-console"
22 OBJECT_DECLARE_SIMPLE_TYPE(QemuFixedTextConsole, QEMU_FIXED_TEXT_CONSOLE)
23
24 #define QEMU_IS_GRAPHIC_CONSOLE(c) \
25 object_dynamic_cast(OBJECT(c), TYPE_QEMU_GRAPHIC_CONSOLE)
26
27 #define QEMU_IS_TEXT_CONSOLE(c) \
28 object_dynamic_cast(OBJECT(c), TYPE_QEMU_TEXT_CONSOLE)
29
30 #define QEMU_IS_FIXED_TEXT_CONSOLE(c) \
31 object_dynamic_cast(OBJECT(c), TYPE_QEMU_FIXED_TEXT_CONSOLE)
32
33 /* identical to the ps/2 keyboard bits */
34 #define QEMU_SCROLL_LOCK_LED (1 << 0)
35 #define QEMU_NUM_LOCK_LED (1 << 1)
36 #define QEMU_CAPS_LOCK_LED (1 << 2)
37
38 /* in ms */
39 #define GUI_REFRESH_INTERVAL_DEFAULT 30
40 #define GUI_REFRESH_INTERVAL_IDLE 3000
41
42 /* Color number is match to standard vga palette */
43 enum qemu_color_names {
44 QEMU_COLOR_BLACK = 0,
45 QEMU_COLOR_BLUE = 1,
46 QEMU_COLOR_GREEN = 2,
47 QEMU_COLOR_CYAN = 3,
48 QEMU_COLOR_RED = 4,
49 QEMU_COLOR_MAGENTA = 5,
50 QEMU_COLOR_YELLOW = 6,
51 QEMU_COLOR_WHITE = 7
52 };
53 /* Convert to curses char attributes */
54 #define ATTR2CHTYPE(c, fg, bg, bold) \
55 ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c))
56
57 bool qemu_mouse_set(int index, Error **errp);
58
59 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
60 constants) */
61 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
62 #define QEMU_KEY_TAB 0x0009
63 #define QEMU_KEY_BACKSPACE 0x007f
64 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
65 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
66 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
67 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
68 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
69 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
70 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
71 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
72 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
73
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
83 void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym);
84 bool qemu_text_console_put_linux(QemuTextConsole *s, unsigned int lnx,
85 bool ctrl);
86 void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len);
87
88 /* consoles */
89
90 struct QemuConsoleClass {
91 ObjectClass parent_class;
92
93 char * (*get_label)(const QemuConsole *con);
94 };
95
96 typedef struct ScanoutTexture {
97 uint32_t backing_id;
98 bool backing_y_0_top;
99 uint32_t backing_width;
100 uint32_t backing_height;
101 uint32_t x;
102 uint32_t y;
103 uint32_t width;
104 uint32_t height;
105 void *d3d_tex2d;
106 } ScanoutTexture;
107
108 typedef struct QemuUIInfo {
109 /* physical dimension */
110 uint16_t width_mm;
111 uint16_t height_mm;
112 /* geometry */
113 int xoff;
114 int yoff;
115 uint32_t width;
116 uint32_t height;
117 uint32_t refresh_rate;
118 } QemuUIInfo;
119
120 /* cursor data format is 32bit RGBA */
121 typedef struct QEMUCursor {
122 uint16_t width, height;
123 int hot_x, hot_y;
124 int refcount;
125 uint32_t data[];
126 } QEMUCursor;
127
128 QEMUCursor *cursor_alloc(uint16_t width, uint16_t height);
129 QEMUCursor *cursor_ref(QEMUCursor *c);
130 void cursor_unref(QEMUCursor *c);
131 QEMUCursor *cursor_builtin_hidden(void);
132 QEMUCursor *cursor_builtin_left_ptr(void);
133 void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
134 int cursor_get_mono_bpl(QEMUCursor *c);
135 void cursor_set_mono(QEMUCursor *c,
136 uint32_t foreground, uint32_t background, uint8_t *image,
137 int transparent, uint8_t *mask);
138 void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
139
140 typedef void *QEMUGLContext;
141 typedef struct QEMUGLParams QEMUGLParams;
142
143 struct QEMUGLParams {
144 int major_ver;
145 int minor_ver;
146 };
147
148 enum display_scanout {
149 SCANOUT_NONE,
150 SCANOUT_SURFACE,
151 SCANOUT_TEXTURE,
152 SCANOUT_DMABUF,
153 };
154
155 typedef struct DisplayScanout {
156 enum display_scanout kind;
157 union {
158 /* DisplaySurface *surface; is kept in QemuConsole */
159 ScanoutTexture texture;
160 QemuDmaBuf *dmabuf;
161 };
162 } DisplayScanout;
163
164 typedef struct DisplayState DisplayState;
165 typedef struct DisplayGLCtx DisplayGLCtx;
166
167 typedef struct DisplayChangeListenerOps {
168 const char *dpy_name;
169
170 /* optional */
171 void (*dpy_refresh)(DisplayChangeListener *dcl);
172
173 /* optional */
174 void (*dpy_gfx_update)(DisplayChangeListener *dcl,
175 int x, int y, int w, int h);
176 /* optional */
177 void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
178 struct DisplaySurface *new_surface);
179 /* optional */
180 bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
181 pixman_format_code_t format);
182
183 /* optional */
184 void (*dpy_text_cursor)(DisplayChangeListener *dcl,
185 int x, int y);
186 /* optional */
187 void (*dpy_text_resize)(DisplayChangeListener *dcl,
188 int w, int h);
189 /* optional */
190 void (*dpy_text_update)(DisplayChangeListener *dcl,
191 int x, int y, int w, int h);
192
193 /* optional */
194 void (*dpy_mouse_set)(DisplayChangeListener *dcl,
195 int x, int y, bool on);
196 /* optional */
197 void (*dpy_cursor_define)(DisplayChangeListener *dcl,
198 QEMUCursor *cursor);
199
200 /* required if GL */
201 void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl);
202 /* required if GL */
203 void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
204 uint32_t backing_id,
205 bool backing_y_0_top,
206 uint32_t backing_width,
207 uint32_t backing_height,
208 uint32_t x, uint32_t y,
209 uint32_t w, uint32_t h,
210 void *d3d_tex2d);
211 /* optional (default to true if has dpy_gl_scanout_dmabuf) */
212 bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);
213 /* optional */
214 void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl,
215 QemuDmaBuf *dmabuf);
216 /* optional */
217 void (*dpy_gl_cursor_dmabuf)(DisplayChangeListener *dcl,
218 QemuDmaBuf *dmabuf, bool have_hot,
219 uint32_t hot_x, uint32_t hot_y);
220 /* optional */
221 void (*dpy_gl_cursor_position)(DisplayChangeListener *dcl,
222 uint32_t pos_x, uint32_t pos_y);
223 /* optional */
224 void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl,
225 QemuDmaBuf *dmabuf);
226 /* required if GL */
227 void (*dpy_gl_update)(DisplayChangeListener *dcl,
228 uint32_t x, uint32_t y, uint32_t w, uint32_t h);
229
230 } DisplayChangeListenerOps;
231
232 struct DisplayChangeListener {
233 uint64_t update_interval;
234 const DisplayChangeListenerOps *ops;
235 DisplayState *ds;
236 QemuConsole *con;
237
238 QLIST_ENTRY(DisplayChangeListener) next;
239 };
240
241 typedef struct DisplayGLCtxOps {
242 bool (*dpy_gl_ctx_is_compatible_dcl)(DisplayGLCtx *dgc,
243 DisplayChangeListener *dcl);
244 QEMUGLContext (*dpy_gl_ctx_create)(DisplayGLCtx *dgc,
245 QEMUGLParams *params);
246 void (*dpy_gl_ctx_destroy)(DisplayGLCtx *dgc,
247 QEMUGLContext ctx);
248 int (*dpy_gl_ctx_make_current)(DisplayGLCtx *dgc,
249 QEMUGLContext ctx);
250 void (*dpy_gl_ctx_create_texture)(DisplayGLCtx *dgc,
251 DisplaySurface *surface);
252 void (*dpy_gl_ctx_destroy_texture)(DisplayGLCtx *dgc,
253 DisplaySurface *surface);
254 void (*dpy_gl_ctx_update_texture)(DisplayGLCtx *dgc,
255 DisplaySurface *surface,
256 int x, int y, int w, int h);
257 } DisplayGLCtxOps;
258
259 struct DisplayGLCtx {
260 const DisplayGLCtxOps *ops;
261 #ifdef CONFIG_OPENGL
262 QemuGLShader *gls; /* optional shared shader */
263 #endif
264 };
265
266 DisplayState *init_displaystate(void);
267
268 void qemu_console_register_listener(QemuConsole *con,
269 DisplayChangeListener *dcl,
270 const DisplayChangeListenerOps *ops);
271 void qemu_console_listener_set_refresh(DisplayChangeListener *dcl,
272 uint64_t interval);
273 void qemu_console_unregister_listener(DisplayChangeListener *dcl);
274
275 bool qemu_console_ui_info_supported(const QemuConsole *con);
276 const QemuUIInfo *qemu_console_get_ui_info(const QemuConsole *con);
277 int qemu_console_set_ui_info(QemuConsole *con, QemuUIInfo *info, bool delay);
278
279 void qemu_console_update(QemuConsole *con, int x, int y, int w, int h);
280 void qemu_console_update_full(QemuConsole *con);
281 void qemu_console_set_surface(QemuConsole *con,
282 DisplaySurface *surface);
283 void qemu_console_text_set_cursor(QemuConsole *con, int x, int y);
284 void qemu_console_text_update(QemuConsole *con, int x, int y, int w, int h);
285 void qemu_console_text_resize(QemuConsole *con, int w, int h);
286 void qemu_console_set_mouse(QemuConsole *con, int x, int y, bool on);
287 void qemu_console_set_cursor(QemuConsole *con, QEMUCursor *cursor);
288 bool qemu_console_check_format(QemuConsole *con,
289 pixman_format_code_t format);
290
291 void qemu_console_gl_scanout_disable(QemuConsole *con);
292 void qemu_console_gl_scanout_texture(QemuConsole *con,
293 uint32_t backing_id, bool backing_y_0_top,
294 uint32_t backing_width, uint32_t backing_height,
295 uint32_t x, uint32_t y, uint32_t w, uint32_t h,
296 void *d3d_tex2d);
297 void qemu_console_gl_scanout_dmabuf(QemuConsole *con,
298 QemuDmaBuf *dmabuf);
299 void qemu_console_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
300 bool have_hot, uint32_t hot_x, uint32_t hot_y);
301 void qemu_console_gl_cursor_position(QemuConsole *con,
302 uint32_t pos_x, uint32_t pos_y);
303 void qemu_console_gl_release_dmabuf(QemuConsole *con,
304 QemuDmaBuf *dmabuf);
305 void qemu_console_gl_update(QemuConsole *con,
306 uint32_t x, uint32_t y, uint32_t w, uint32_t h);
307
308 QEMUGLContext qemu_console_gl_ctx_create(QemuConsole *con,
309 QEMUGLParams *params);
310 void qemu_console_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx);
311 int qemu_console_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx);
312
313 bool qemu_console_has_gl(QemuConsole *con);
314
315 enum {
316 GRAPHIC_FLAGS_NONE = 0,
317 /* require a console/display with GL callbacks */
318 GRAPHIC_FLAGS_GL = 1 << 0,
319 /* require a console/display with DMABUF import */
320 GRAPHIC_FLAGS_DMABUF = 1 << 1,
321 };
322
323 typedef struct GraphicHwOps {
324 int (*get_flags)(void *opaque); /* optional, default 0 */
325 void (*invalidate)(void *opaque);
326 /*
327 * Returns true if the update is handled synchronously, false if deferred
328 * and graphic_hw_update_done() will be called when ready (to resume waiting
329 * tasks/coroutines).
330 * Optional.
331 */
332 bool (*gfx_update)(void *opaque);
333 void (*text_update)(void *opaque, uint32_t *text);
334 void (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
335 void (*gl_block)(void *opaque, bool block);
336 } GraphicHwOps;
337
338 QemuConsole *qemu_graphic_console_create(DeviceState *dev, uint32_t head,
339 const GraphicHwOps *ops,
340 void *opaque);
341 void qemu_graphic_console_set_hwops(QemuConsole *con,
342 const GraphicHwOps *hw_ops,
343 void *opaque);
344 void qemu_graphic_console_close(QemuConsole *con);
345
346 void qemu_console_hw_update(QemuConsole *con);
347 void qemu_console_hw_update_done(QemuConsole *con);
348 void qemu_console_hw_invalidate(QemuConsole *con);
349 void qemu_console_hw_text_update(QemuConsole *con, uint32_t *chardata);
350 void qemu_console_hw_gl_block(QemuConsole *con, bool block);
351
352 void qemu_console_early_init(void);
353
354 void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *ctx);
355
356 QemuConsole *qemu_console_lookup_default(void);
357 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
358 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
359 QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
360 uint32_t head, Error **errp);
361 QEMUCursor *qemu_console_get_cursor(QemuConsole *con);
362 bool qemu_console_is_graphic(QemuConsole *con);
363 bool qemu_console_is_fixedsize(QemuConsole *con);
364 bool qemu_console_is_gl_blocked(QemuConsole *con);
365 char *qemu_console_get_label(QemuConsole *con);
366 int qemu_console_get_index(QemuConsole *con);
367 uint32_t qemu_console_get_head(QemuConsole *con);
368 int qemu_console_get_width(QemuConsole *con, int fallback);
369 int qemu_console_get_height(QemuConsole *con, int fallback);
370 /* Return the low-level window id for the console */
371 int qemu_console_get_window_id(QemuConsole *con);
372 /* Set the low-level window id for the console */
373 void qemu_console_set_window_id(QemuConsole *con, int window_id);
374
375 void qemu_console_resize(QemuConsole *con, int width, int height);
376 DisplaySurface *qemu_console_surface(QemuConsole *con);
377 void coroutine_fn qemu_console_co_wait_update(QemuConsole *con);
378
379 /* console-gl.c */
380 #ifdef CONFIG_OPENGL
381 bool console_gl_check_format(DisplayChangeListener *dcl,
382 pixman_format_code_t format);
383 void surface_gl_create_texture(QemuGLShader *gls,
384 DisplaySurface *surface);
385 bool surface_gl_create_texture_from_fd(DisplaySurface *surface,
386 int fd, uint32_t *texture,
387 uint32_t *mem_obj);
388 void surface_gl_update_texture(QemuGLShader *gls,
389 DisplaySurface *surface,
390 int x, int y, int w, int h);
391 void surface_gl_render_texture(QemuGLShader *gls,
392 DisplaySurface *surface);
393 void surface_gl_destroy_texture(QemuGLShader *gls,
394 DisplaySurface *surface);
395 void surface_gl_setup_viewport(QemuGLShader *gls,
396 DisplaySurface *surface,
397 int ww, int wh);
398 #endif
399
400 typedef struct QemuDisplay QemuDisplay;
401
402 struct QemuDisplay {
403 DisplayType type;
404 void (*early_init)(DisplayOptions *opts);
405 void (*init)(DisplayState *ds, DisplayOptions *opts);
406 void (*cleanup)(void);
407 const char *vc;
408 };
409
410 void qemu_display_register(QemuDisplay *ui);
411 bool qemu_display_find_default(DisplayOptions *opts);
412 void qemu_display_early_init(DisplayOptions *opts);
413 void qemu_display_init(DisplayState *ds, DisplayOptions *opts);
414 const char *qemu_display_get_vc(DisplayOptions *opts);
415 void qemu_display_cleanup(void);
416 void qemu_display_help(void);
417
418 /*
419 * Console notifications:
420 * Handlers must be idempotent, it may notify multiple times.
421 */
422 typedef enum {
423 QEMU_CONSOLE_ADDED,
424 QEMU_CONSOLE_REMOVED,
425 } QemuConsoleEventType;
426
427 typedef struct QemuConsoleEvent {
428 QemuConsoleEventType type;
429 QemuConsole *con;
430 } QemuConsoleEvent;
431
432 void qemu_console_add_notifier(Notifier *notifier);
433 void qemu_console_remove_notifier(Notifier *notifier);
434 void qemu_console_notify(QemuConsoleEventType type, QemuConsole *con);
435
436 /* vnc.c */
437 void vnc_display_add_client(const char *id, int csock, bool skipauth);
438 int vnc_display_password(const char *id, const char *password, Error **errp);
439 int vnc_display_pw_expire(const char *id, time_t expires);
440 void vnc_parse(const char *str);
441 int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp);
442 bool vnc_display_reload_certs(const char *id, Error **errp);
443 bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp);
444 void vnc_cleanup(void);
445
446 #ifdef CONFIG_LINUX
447 /* udmabuf.c */
448 int udmabuf_fd(void);
449 #endif
450
451 /* util.c */
452 bool qemu_console_fill_device_address(QemuConsole *con,
453 char *device_address,
454 size_t size,
455 Error **errp);
456
457 #endif