4 #include "ui/qemu-pixman.h"
5 #include "qom/object.h"
6 #include "qemu/notify.h"
7 #include "qapi/qapi-types-ui.h"
9 #include "ui/surface.h"
10 #include "ui/dmabuf.h"
12 #define TYPE_QEMU_CONSOLE "qemu-console"
13 OBJECT_DECLARE_TYPE(QemuConsole
, QemuConsoleClass
, QEMU_CONSOLE
)
15 #define TYPE_QEMU_GRAPHIC_CONSOLE "qemu-graphic-console"
16 OBJECT_DECLARE_SIMPLE_TYPE(QemuGraphicConsole
, QEMU_GRAPHIC_CONSOLE
)
18 #define TYPE_QEMU_TEXT_CONSOLE "qemu-text-console"
19 OBJECT_DECLARE_SIMPLE_TYPE(QemuTextConsole
, QEMU_TEXT_CONSOLE
)
21 #define TYPE_QEMU_FIXED_TEXT_CONSOLE "qemu-fixed-text-console"
22 OBJECT_DECLARE_SIMPLE_TYPE(QemuFixedTextConsole
, QEMU_FIXED_TEXT_CONSOLE
)
24 #define QEMU_IS_GRAPHIC_CONSOLE(c) \
25 object_dynamic_cast(OBJECT(c), TYPE_QEMU_GRAPHIC_CONSOLE)
27 #define QEMU_IS_TEXT_CONSOLE(c) \
28 object_dynamic_cast(OBJECT(c), TYPE_QEMU_TEXT_CONSOLE)
30 #define QEMU_IS_FIXED_TEXT_CONSOLE(c) \
31 object_dynamic_cast(OBJECT(c), TYPE_QEMU_FIXED_TEXT_CONSOLE)
33 /* keyboard/mouse support */
35 #define MOUSE_EVENT_LBUTTON 0x01
36 #define MOUSE_EVENT_RBUTTON 0x02
37 #define MOUSE_EVENT_MBUTTON 0x04
38 #define MOUSE_EVENT_WHEELUP 0x08
39 #define MOUSE_EVENT_WHEELDN 0x10
41 /* identical to the ps/2 keyboard bits */
42 #define QEMU_SCROLL_LOCK_LED (1 << 0)
43 #define QEMU_NUM_LOCK_LED (1 << 1)
44 #define QEMU_CAPS_LOCK_LED (1 << 2)
47 #define GUI_REFRESH_INTERVAL_DEFAULT 30
48 #define GUI_REFRESH_INTERVAL_IDLE 3000
50 /* Color number is match to standard vga palette */
51 enum qemu_color_names
{
57 QEMU_COLOR_MAGENTA
= 5,
58 QEMU_COLOR_YELLOW
= 6,
61 /* Convert to curses char attributes */
62 #define ATTR2CHTYPE(c, fg, bg, bold) \
63 ((bold) << 21 | (bg) << 11 | (fg) << 8 | (c))
65 typedef void QEMUPutKBDEvent(void *opaque
, int keycode
);
66 typedef void QEMUPutLEDEvent(void *opaque
, int ledstate
);
67 typedef void QEMUPutMouseEvent(void *opaque
, int dx
, int dy
, int dz
, int buttons_state
);
69 typedef struct QEMUPutMouseEntry QEMUPutMouseEntry
;
70 typedef struct QEMUPutKbdEntry QEMUPutKbdEntry
;
71 typedef struct QEMUPutLEDEntry QEMUPutLEDEntry
;
73 QEMUPutKbdEntry
*qemu_add_kbd_event_handler(QEMUPutKBDEvent
*func
,
75 QEMUPutMouseEntry
*qemu_add_mouse_event_handler(QEMUPutMouseEvent
*func
,
76 void *opaque
, int absolute
,
78 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry
*entry
);
79 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry
*entry
);
81 QEMUPutLEDEntry
*qemu_add_led_event_handler(QEMUPutLEDEvent
*func
, void *opaque
);
82 void qemu_remove_led_event_handler(QEMUPutLEDEntry
*entry
);
84 void kbd_put_ledstate(int ledstate
);
86 bool qemu_mouse_set(int index
, Error
**errp
);
88 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
90 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
91 #define QEMU_KEY_TAB 0x0009
92 #define QEMU_KEY_BACKSPACE 0x007f
93 #define QEMU_KEY_UP QEMU_KEY_ESC1('A')
94 #define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
95 #define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
96 #define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
97 #define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
98 #define QEMU_KEY_END QEMU_KEY_ESC1(4)
99 #define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
100 #define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
101 #define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
103 #define QEMU_KEY_CTRL_UP 0xe400
104 #define QEMU_KEY_CTRL_DOWN 0xe401
105 #define QEMU_KEY_CTRL_LEFT 0xe402
106 #define QEMU_KEY_CTRL_RIGHT 0xe403
107 #define QEMU_KEY_CTRL_HOME 0xe404
108 #define QEMU_KEY_CTRL_END 0xe405
109 #define QEMU_KEY_CTRL_PAGEUP 0xe406
110 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407
112 void qemu_text_console_put_keysym(QemuTextConsole
*s
, int keysym
);
113 bool qemu_text_console_put_qcode(QemuTextConsole
*s
, int qcode
, bool ctrl
);
114 void qemu_text_console_put_string(QemuTextConsole
*s
, const char *str
, int len
);
117 typedef struct touch_slot
{
123 void console_handle_touch_event(QemuConsole
*con
,
124 struct touch_slot touch_slots
[INPUT_EVENT_SLOTS_MAX
],
126 int width
, int height
,
128 InputMultiTouchType type
,
132 struct QemuConsoleClass
{
133 ObjectClass parent_class
;
136 typedef struct ScanoutTexture
{
138 bool backing_y_0_top
;
139 uint32_t backing_width
;
140 uint32_t backing_height
;
148 typedef struct QemuUIInfo
{
149 /* physical dimension */
157 uint32_t refresh_rate
;
160 /* cursor data format is 32bit RGBA */
161 typedef struct QEMUCursor
{
162 uint16_t width
, height
;
168 QEMUCursor
*cursor_alloc(uint16_t width
, uint16_t height
);
169 QEMUCursor
*cursor_ref(QEMUCursor
*c
);
170 void cursor_unref(QEMUCursor
*c
);
171 QEMUCursor
*cursor_builtin_hidden(void);
172 QEMUCursor
*cursor_builtin_left_ptr(void);
173 void cursor_print_ascii_art(QEMUCursor
*c
, const char *prefix
);
174 int cursor_get_mono_bpl(QEMUCursor
*c
);
175 void cursor_set_mono(QEMUCursor
*c
,
176 uint32_t foreground
, uint32_t background
, uint8_t *image
,
177 int transparent
, uint8_t *mask
);
178 void cursor_get_mono_mask(QEMUCursor
*c
, int transparent
, uint8_t *mask
);
180 typedef void *QEMUGLContext
;
181 typedef struct QEMUGLParams QEMUGLParams
;
183 struct QEMUGLParams
{
188 enum display_scanout
{
195 typedef struct DisplayScanout
{
196 enum display_scanout kind
;
198 /* DisplaySurface *surface; is kept in QemuConsole */
199 ScanoutTexture texture
;
204 typedef struct DisplayState DisplayState
;
205 typedef struct DisplayGLCtx DisplayGLCtx
;
207 typedef struct DisplayChangeListenerOps
{
208 const char *dpy_name
;
211 void (*dpy_refresh
)(DisplayChangeListener
*dcl
);
214 void (*dpy_gfx_update
)(DisplayChangeListener
*dcl
,
215 int x
, int y
, int w
, int h
);
217 void (*dpy_gfx_switch
)(DisplayChangeListener
*dcl
,
218 struct DisplaySurface
*new_surface
);
220 bool (*dpy_gfx_check_format
)(DisplayChangeListener
*dcl
,
221 pixman_format_code_t format
);
224 void (*dpy_text_cursor
)(DisplayChangeListener
*dcl
,
227 void (*dpy_text_resize
)(DisplayChangeListener
*dcl
,
230 void (*dpy_text_update
)(DisplayChangeListener
*dcl
,
231 int x
, int y
, int w
, int h
);
234 void (*dpy_mouse_set
)(DisplayChangeListener
*dcl
,
235 int x
, int y
, bool on
);
237 void (*dpy_cursor_define
)(DisplayChangeListener
*dcl
,
241 void (*dpy_gl_scanout_disable
)(DisplayChangeListener
*dcl
);
243 void (*dpy_gl_scanout_texture
)(DisplayChangeListener
*dcl
,
245 bool backing_y_0_top
,
246 uint32_t backing_width
,
247 uint32_t backing_height
,
248 uint32_t x
, uint32_t y
,
249 uint32_t w
, uint32_t h
,
251 /* optional (default to true if has dpy_gl_scanout_dmabuf) */
252 bool (*dpy_has_dmabuf
)(DisplayChangeListener
*dcl
);
254 void (*dpy_gl_scanout_dmabuf
)(DisplayChangeListener
*dcl
,
257 void (*dpy_gl_cursor_dmabuf
)(DisplayChangeListener
*dcl
,
258 QemuDmaBuf
*dmabuf
, bool have_hot
,
259 uint32_t hot_x
, uint32_t hot_y
);
261 void (*dpy_gl_cursor_position
)(DisplayChangeListener
*dcl
,
262 uint32_t pos_x
, uint32_t pos_y
);
264 void (*dpy_gl_release_dmabuf
)(DisplayChangeListener
*dcl
,
267 void (*dpy_gl_update
)(DisplayChangeListener
*dcl
,
268 uint32_t x
, uint32_t y
, uint32_t w
, uint32_t h
);
270 } DisplayChangeListenerOps
;
272 struct DisplayChangeListener
{
273 uint64_t update_interval
;
274 const DisplayChangeListenerOps
*ops
;
278 QLIST_ENTRY(DisplayChangeListener
) next
;
281 typedef struct DisplayGLCtxOps
{
282 bool (*dpy_gl_ctx_is_compatible_dcl
)(DisplayGLCtx
*dgc
,
283 DisplayChangeListener
*dcl
);
284 QEMUGLContext (*dpy_gl_ctx_create
)(DisplayGLCtx
*dgc
,
285 QEMUGLParams
*params
);
286 void (*dpy_gl_ctx_destroy
)(DisplayGLCtx
*dgc
,
288 int (*dpy_gl_ctx_make_current
)(DisplayGLCtx
*dgc
,
290 void (*dpy_gl_ctx_create_texture
)(DisplayGLCtx
*dgc
,
291 DisplaySurface
*surface
);
292 void (*dpy_gl_ctx_destroy_texture
)(DisplayGLCtx
*dgc
,
293 DisplaySurface
*surface
);
294 void (*dpy_gl_ctx_update_texture
)(DisplayGLCtx
*dgc
,
295 DisplaySurface
*surface
,
296 int x
, int y
, int w
, int h
);
299 struct DisplayGLCtx
{
300 const DisplayGLCtxOps
*ops
;
302 QemuGLShader
*gls
; /* optional shared shader */
306 DisplayState
*init_displaystate(void);
308 void register_displaychangelistener(DisplayChangeListener
*dcl
);
309 void update_displaychangelistener(DisplayChangeListener
*dcl
,
311 void unregister_displaychangelistener(DisplayChangeListener
*dcl
);
313 bool dpy_ui_info_supported(const QemuConsole
*con
);
314 const QemuUIInfo
*dpy_get_ui_info(const QemuConsole
*con
);
315 int dpy_set_ui_info(QemuConsole
*con
, QemuUIInfo
*info
, bool delay
);
317 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
);
318 void dpy_gfx_update_full(QemuConsole
*con
);
319 void dpy_gfx_replace_surface(QemuConsole
*con
,
320 DisplaySurface
*surface
);
321 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
);
322 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
);
323 void dpy_text_resize(QemuConsole
*con
, int w
, int h
);
324 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, bool on
);
325 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
);
326 bool dpy_gfx_check_format(QemuConsole
*con
,
327 pixman_format_code_t format
);
329 void dpy_gl_scanout_disable(QemuConsole
*con
);
330 void dpy_gl_scanout_texture(QemuConsole
*con
,
331 uint32_t backing_id
, bool backing_y_0_top
,
332 uint32_t backing_width
, uint32_t backing_height
,
333 uint32_t x
, uint32_t y
, uint32_t w
, uint32_t h
,
335 void dpy_gl_scanout_dmabuf(QemuConsole
*con
,
337 void dpy_gl_cursor_dmabuf(QemuConsole
*con
, QemuDmaBuf
*dmabuf
,
338 bool have_hot
, uint32_t hot_x
, uint32_t hot_y
);
339 void dpy_gl_cursor_position(QemuConsole
*con
,
340 uint32_t pos_x
, uint32_t pos_y
);
341 void dpy_gl_release_dmabuf(QemuConsole
*con
,
343 void dpy_gl_update(QemuConsole
*con
,
344 uint32_t x
, uint32_t y
, uint32_t w
, uint32_t h
);
346 QEMUGLContext
dpy_gl_ctx_create(QemuConsole
*con
,
347 QEMUGLParams
*params
);
348 void dpy_gl_ctx_destroy(QemuConsole
*con
, QEMUGLContext ctx
);
349 int dpy_gl_ctx_make_current(QemuConsole
*con
, QEMUGLContext ctx
);
351 bool console_has_gl(QemuConsole
*con
);
353 typedef uint32_t console_ch_t
;
355 static inline void console_write_ch(console_ch_t
*dest
, uint32_t ch
)
361 GRAPHIC_FLAGS_NONE
= 0,
362 /* require a console/display with GL callbacks */
363 GRAPHIC_FLAGS_GL
= 1 << 0,
364 /* require a console/display with DMABUF import */
365 GRAPHIC_FLAGS_DMABUF
= 1 << 1,
368 typedef struct GraphicHwOps
{
369 int (*get_flags
)(void *opaque
); /* optional, default 0 */
370 void (*invalidate
)(void *opaque
);
371 void (*gfx_update
)(void *opaque
);
372 bool gfx_update_async
; /* if true, calls graphic_hw_update_done() */
373 void (*text_update
)(void *opaque
, console_ch_t
*text
);
374 void (*ui_info
)(void *opaque
, uint32_t head
, QemuUIInfo
*info
);
375 void (*gl_block
)(void *opaque
, bool block
);
378 QemuConsole
*graphic_console_init(DeviceState
*dev
, uint32_t head
,
379 const GraphicHwOps
*ops
,
381 void graphic_console_set_hwops(QemuConsole
*con
,
382 const GraphicHwOps
*hw_ops
,
384 void graphic_console_close(QemuConsole
*con
);
386 void graphic_hw_update(QemuConsole
*con
);
387 void graphic_hw_update_done(QemuConsole
*con
);
388 void graphic_hw_invalidate(QemuConsole
*con
);
389 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
);
390 void graphic_hw_gl_block(QemuConsole
*con
, bool block
);
392 void qemu_console_early_init(void);
394 void qemu_console_set_display_gl_ctx(QemuConsole
*con
, DisplayGLCtx
*ctx
);
396 QemuConsole
*qemu_console_lookup_default(void);
397 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
);
398 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
, uint32_t head
);
399 QemuConsole
*qemu_console_lookup_by_device_name(const char *device_id
,
400 uint32_t head
, Error
**errp
);
401 QEMUCursor
*qemu_console_get_cursor(QemuConsole
*con
);
402 bool qemu_console_is_visible(QemuConsole
*con
);
403 bool qemu_console_is_graphic(QemuConsole
*con
);
404 bool qemu_console_is_fixedsize(QemuConsole
*con
);
405 bool qemu_console_is_gl_blocked(QemuConsole
*con
);
406 char *qemu_console_get_label(QemuConsole
*con
);
407 int qemu_console_get_index(QemuConsole
*con
);
408 uint32_t qemu_console_get_head(QemuConsole
*con
);
409 int qemu_console_get_width(QemuConsole
*con
, int fallback
);
410 int qemu_console_get_height(QemuConsole
*con
, int fallback
);
411 /* Return the low-level window id for the console */
412 int qemu_console_get_window_id(QemuConsole
*con
);
413 /* Set the low-level window id for the console */
414 void qemu_console_set_window_id(QemuConsole
*con
, int window_id
);
416 void qemu_console_resize(QemuConsole
*con
, int width
, int height
);
417 DisplaySurface
*qemu_console_surface(QemuConsole
*con
);
418 void coroutine_fn
qemu_console_co_wait_update(QemuConsole
*con
);
419 int qemu_invalidate_text_consoles(void);
423 bool console_gl_check_format(DisplayChangeListener
*dcl
,
424 pixman_format_code_t format
);
425 void surface_gl_create_texture(QemuGLShader
*gls
,
426 DisplaySurface
*surface
);
427 void surface_gl_update_texture(QemuGLShader
*gls
,
428 DisplaySurface
*surface
,
429 int x
, int y
, int w
, int h
);
430 void surface_gl_render_texture(QemuGLShader
*gls
,
431 DisplaySurface
*surface
);
432 void surface_gl_destroy_texture(QemuGLShader
*gls
,
433 DisplaySurface
*surface
);
434 void surface_gl_setup_viewport(QemuGLShader
*gls
,
435 DisplaySurface
*surface
,
439 typedef struct QemuDisplay QemuDisplay
;
443 void (*early_init
)(DisplayOptions
*opts
);
444 void (*init
)(DisplayState
*ds
, DisplayOptions
*opts
);
448 void qemu_display_register(QemuDisplay
*ui
);
449 bool qemu_display_find_default(DisplayOptions
*opts
);
450 void qemu_display_early_init(DisplayOptions
*opts
);
451 void qemu_display_init(DisplayState
*ds
, DisplayOptions
*opts
);
452 const char *qemu_display_get_vc(DisplayOptions
*opts
);
453 void qemu_display_help(void);
456 void vnc_display_init(const char *id
, Error
**errp
);
457 void vnc_display_open(const char *id
, Error
**errp
);
458 void vnc_display_add_client(const char *id
, int csock
, bool skipauth
);
459 int vnc_display_password(const char *id
, const char *password
);
460 int vnc_display_pw_expire(const char *id
, time_t expires
);
461 void vnc_parse(const char *str
);
462 int vnc_init_func(void *opaque
, QemuOpts
*opts
, Error
**errp
);
463 bool vnc_display_reload_certs(const char *id
, Error
**errp
);
464 bool vnc_display_update(DisplayUpdateOptionsVNC
*arg
, Error
**errp
);
467 int index_from_key(const char *key
, size_t key_length
);
471 int udmabuf_fd(void);
475 bool qemu_console_fill_device_address(QemuConsole
*con
,
476 char *device_address
,