2 * QEMU graphical console
4 * Copyright (c) 2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "ui/console.h"
27 #include "hw/qdev-core.h"
28 #include "qapi/error.h"
29 #include "qapi/qapi-commands-ui.h"
30 #include "qemu/coroutine.h"
31 #include "qemu/fifo8.h"
32 #include "qemu/error-report.h"
33 #include "qemu/main-loop.h"
34 #include "qemu/module.h"
35 #include "qemu/option.h"
36 #include "qemu/timer.h"
37 #include "chardev/char.h"
39 #include "exec/memory.h"
40 #include "qom/object.h"
42 #define DEFAULT_BACKSCROLL 512
43 #define CONSOLE_CURSOR_PERIOD 500
45 typedef struct TextAttributes
{
55 typedef struct TextCell
{
57 TextAttributes t_attrib
;
60 #define MAX_ESC_PARAMS 3
71 TEXT_CONSOLE_FIXED_SIZE
78 console_type_t console_type
;
80 DisplaySurface
*surface
;
81 DisplayScanout scanout
;
85 QEMUTimer
*gl_unblock_timer
;
88 /* Graphic console state. */
94 int cursor_x
, cursor_y
, cursor_on
;
95 const GraphicHwOps
*hw_ops
;
98 /* Text console state */
102 int backscroll_height
;
104 int x_saved
, y_saved
;
107 TextAttributes t_attrib_default
; /* default text attributes */
108 TextAttributes t_attrib
; /* currently active text attributes */
110 int text_x
[2], text_y
[2], cursor_invalidate
;
119 int esc_params
[MAX_ESC_PARAMS
];
123 /* fifo for key pressed */
127 QTAILQ_ENTRY(QemuConsole
) next
;
132 QemuConsole
*console
;
134 typedef struct VCChardev VCChardev
;
136 struct DisplayState
{
137 QEMUTimer
*gui_timer
;
138 uint64_t last_update
;
139 uint64_t update_interval
;
142 QLIST_HEAD(, DisplayChangeListener
) listeners
;
145 static DisplayState
*display_state
;
146 static QemuConsole
*active_console
;
147 static QTAILQ_HEAD(, QemuConsole
) consoles
=
148 QTAILQ_HEAD_INITIALIZER(consoles
);
149 static bool cursor_visible_phase
;
150 static QEMUTimer
*cursor_timer
;
152 static void text_console_do_init(Chardev
*chr
);
153 static void dpy_refresh(DisplayState
*s
);
154 static DisplayState
*get_alloc_displaystate(void);
155 static void text_console_update_cursor_timer(void);
156 static void text_console_update_cursor(void *opaque
);
157 static bool displaychangelistener_has_dmabuf(DisplayChangeListener
*dcl
);
158 static bool console_compatible_with(QemuConsole
*con
,
159 DisplayChangeListener
*dcl
, Error
**errp
);
161 static void gui_update(void *opaque
)
163 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
164 uint64_t dcl_interval
;
165 DisplayState
*ds
= opaque
;
166 DisplayChangeListener
*dcl
;
168 ds
->refreshing
= true;
170 ds
->refreshing
= false;
172 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
173 dcl_interval
= dcl
->update_interval
?
174 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
175 if (interval
> dcl_interval
) {
176 interval
= dcl_interval
;
179 if (ds
->update_interval
!= interval
) {
180 ds
->update_interval
= interval
;
181 trace_console_refresh(interval
);
183 ds
->last_update
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
184 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
187 static void gui_setup_refresh(DisplayState
*ds
)
189 DisplayChangeListener
*dcl
;
190 bool need_timer
= false;
192 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
193 if (dcl
->ops
->dpy_refresh
!= NULL
) {
198 if (need_timer
&& ds
->gui_timer
== NULL
) {
199 ds
->gui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, gui_update
, ds
);
200 timer_mod(ds
->gui_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
202 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
203 timer_free(ds
->gui_timer
);
204 ds
->gui_timer
= NULL
;
208 void graphic_hw_update_done(QemuConsole
*con
)
211 qemu_co_enter_all(&con
->dump_queue
, NULL
);
215 void graphic_hw_update(QemuConsole
*con
)
218 con
= con
? con
: active_console
;
222 if (con
->hw_ops
->gfx_update
) {
223 con
->hw_ops
->gfx_update(con
->hw
);
224 async
= con
->hw_ops
->gfx_update_async
;
227 graphic_hw_update_done(con
);
231 static void graphic_hw_update_bh(void *con
)
233 graphic_hw_update(con
);
236 void qemu_console_co_wait_update(QemuConsole
*con
)
238 if (qemu_co_queue_empty(&con
->dump_queue
)) {
239 /* Defer the update, it will restart the pending coroutines */
240 aio_bh_schedule_oneshot(qemu_get_aio_context(),
241 graphic_hw_update_bh
, con
);
243 qemu_co_queue_wait(&con
->dump_queue
, NULL
);
247 static void graphic_hw_gl_unblock_timer(void *opaque
)
249 warn_report("console: no gl-unblock within one second");
252 void graphic_hw_gl_block(QemuConsole
*con
, bool block
)
262 assert(con
->gl_block
>= 0);
263 if (!con
->hw_ops
->gl_block
) {
266 if ((block
&& con
->gl_block
!= 1) || (!block
&& con
->gl_block
!= 0)) {
269 con
->hw_ops
->gl_block(con
->hw
, block
);
272 timeout
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
273 timeout
+= 1000; /* one sec */
274 timer_mod(con
->gl_unblock_timer
, timeout
);
276 timer_del(con
->gl_unblock_timer
);
280 int qemu_console_get_window_id(QemuConsole
*con
)
282 return con
->window_id
;
285 void qemu_console_set_window_id(QemuConsole
*con
, int window_id
)
287 con
->window_id
= window_id
;
290 void graphic_hw_invalidate(QemuConsole
*con
)
293 con
= active_console
;
295 if (con
&& con
->hw_ops
->invalidate
) {
296 con
->hw_ops
->invalidate(con
->hw
);
300 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
303 con
= active_console
;
305 if (con
&& con
->hw_ops
->text_update
) {
306 con
->hw_ops
->text_update(con
->hw
, chardata
);
310 static void vga_fill_rect(QemuConsole
*con
,
311 int posx
, int posy
, int width
, int height
,
312 pixman_color_t color
)
314 DisplaySurface
*surface
= qemu_console_surface(con
);
315 pixman_rectangle16_t rect
= {
316 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
319 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
323 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
324 static void vga_bitblt(QemuConsole
*con
,
325 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
327 DisplaySurface
*surface
= qemu_console_surface(con
);
329 pixman_image_composite(PIXMAN_OP_SRC
,
330 surface
->image
, NULL
, surface
->image
,
331 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
334 /***********************************************************/
335 /* basic char display */
337 #define FONT_HEIGHT 16
342 #define QEMU_RGB(r, g, b) \
343 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
345 static const pixman_color_t color_table_rgb
[2][8] = {
347 [QEMU_COLOR_BLACK
] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
348 [QEMU_COLOR_BLUE
] = QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
349 [QEMU_COLOR_GREEN
] = QEMU_RGB(0x00, 0xaa, 0x00), /* green */
350 [QEMU_COLOR_CYAN
] = QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
351 [QEMU_COLOR_RED
] = QEMU_RGB(0xaa, 0x00, 0x00), /* red */
352 [QEMU_COLOR_MAGENTA
] = QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
353 [QEMU_COLOR_YELLOW
] = QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
354 [QEMU_COLOR_WHITE
] = QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
357 [QEMU_COLOR_BLACK
] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
358 [QEMU_COLOR_BLUE
] = QEMU_RGB(0x00, 0x00, 0xff), /* blue */
359 [QEMU_COLOR_GREEN
] = QEMU_RGB(0x00, 0xff, 0x00), /* green */
360 [QEMU_COLOR_CYAN
] = QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
361 [QEMU_COLOR_RED
] = QEMU_RGB(0xff, 0x00, 0x00), /* red */
362 [QEMU_COLOR_MAGENTA
] = QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
363 [QEMU_COLOR_YELLOW
] = QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
364 [QEMU_COLOR_WHITE
] = QEMU_RGB(0xff, 0xff, 0xff), /* white */
368 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
369 TextAttributes
*t_attrib
)
371 static pixman_image_t
*glyphs
[256];
372 DisplaySurface
*surface
= qemu_console_surface(s
);
373 pixman_color_t fgcol
, bgcol
;
375 if (t_attrib
->invers
) {
376 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
377 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
379 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
380 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
384 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
386 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
387 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
390 static void text_console_resize(QemuConsole
*s
)
392 TextCell
*cells
, *c
, *c1
;
393 int w1
, x
, y
, last_width
;
395 assert(s
->scanout
.kind
== SCANOUT_SURFACE
);
397 last_width
= s
->width
;
398 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
399 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
405 cells
= g_new(TextCell
, s
->width
* s
->total_height
+ 1);
406 for(y
= 0; y
< s
->total_height
; y
++) {
407 c
= &cells
[y
* s
->width
];
409 c1
= &s
->cells
[y
* last_width
];
410 for(x
= 0; x
< w1
; x
++) {
414 for(x
= w1
; x
< s
->width
; x
++) {
416 c
->t_attrib
= s
->t_attrib_default
;
424 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
426 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
427 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
428 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
429 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
432 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
434 if (!qemu_console_is_visible(s
)) {
437 if (s
->update_x0
> x
* FONT_WIDTH
)
438 s
->update_x0
= x
* FONT_WIDTH
;
439 if (s
->update_y0
> y
* FONT_HEIGHT
)
440 s
->update_y0
= y
* FONT_HEIGHT
;
441 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
442 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
443 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
444 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
447 static void update_xy(QemuConsole
*s
, int x
, int y
)
452 text_update_xy(s
, x
, y
);
454 y1
= (s
->y_base
+ y
) % s
->total_height
;
455 y2
= y1
- s
->y_displayed
;
457 y2
+= s
->total_height
;
459 if (y2
< s
->height
) {
463 c
= &s
->cells
[y1
* s
->width
+ x
];
464 vga_putcharxy(s
, x
, y2
, c
->ch
,
466 invalidate_xy(s
, x
, y2
);
470 static void console_show_cursor(QemuConsole
*s
, int show
)
476 s
->cursor_invalidate
= 1;
481 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
482 y
= y1
- s
->y_displayed
;
484 y
+= s
->total_height
;
487 c
= &s
->cells
[y1
* s
->width
+ x
];
488 if (show
&& cursor_visible_phase
) {
489 TextAttributes t_attrib
= s
->t_attrib_default
;
490 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
491 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
493 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
495 invalidate_xy(s
, x
, y
);
499 static void console_refresh(QemuConsole
*s
)
501 DisplaySurface
*surface
= qemu_console_surface(s
);
507 s
->text_x
[1] = s
->width
- 1;
508 s
->text_y
[1] = s
->height
- 1;
509 s
->cursor_invalidate
= 1;
511 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
512 color_table_rgb
[0][QEMU_COLOR_BLACK
]);
514 for (y
= 0; y
< s
->height
; y
++) {
515 c
= s
->cells
+ y1
* s
->width
;
516 for (x
= 0; x
< s
->width
; x
++) {
517 vga_putcharxy(s
, x
, y
, c
->ch
,
521 if (++y1
== s
->total_height
) {
525 console_show_cursor(s
, 1);
526 dpy_gfx_update(s
, 0, 0,
527 surface_width(surface
), surface_height(surface
));
530 static void console_scroll(QemuConsole
*s
, int ydelta
)
535 for(i
= 0; i
< ydelta
; i
++) {
536 if (s
->y_displayed
== s
->y_base
)
538 if (++s
->y_displayed
== s
->total_height
)
543 i
= s
->backscroll_height
;
544 if (i
> s
->total_height
- s
->height
)
545 i
= s
->total_height
- s
->height
;
548 y1
+= s
->total_height
;
549 for(i
= 0; i
< ydelta
; i
++) {
550 if (s
->y_displayed
== y1
)
552 if (--s
->y_displayed
< 0)
553 s
->y_displayed
= s
->total_height
- 1;
559 static void console_put_lf(QemuConsole
*s
)
565 if (s
->y
>= s
->height
) {
566 s
->y
= s
->height
- 1;
568 if (s
->y_displayed
== s
->y_base
) {
569 if (++s
->y_displayed
== s
->total_height
)
572 if (++s
->y_base
== s
->total_height
)
574 if (s
->backscroll_height
< s
->total_height
)
575 s
->backscroll_height
++;
576 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
577 c
= &s
->cells
[y1
* s
->width
];
578 for(x
= 0; x
< s
->width
; x
++) {
580 c
->t_attrib
= s
->t_attrib_default
;
583 if (s
->y_displayed
== s
->y_base
) {
586 s
->text_x
[1] = s
->width
- 1;
587 s
->text_y
[1] = s
->height
- 1;
589 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
590 s
->width
* FONT_WIDTH
,
591 (s
->height
- 1) * FONT_HEIGHT
);
592 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
593 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
594 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
597 s
->update_x1
= s
->width
* FONT_WIDTH
;
598 s
->update_y1
= s
->height
* FONT_HEIGHT
;
603 /* Set console attributes depending on the current escape codes.
604 * NOTE: I know this code is not very efficient (checking every color for it
605 * self) but it is more readable and better maintainable.
607 static void console_handle_escape(QemuConsole
*s
)
611 for (i
=0; i
<s
->nb_esc_params
; i
++) {
612 switch (s
->esc_params
[i
]) {
613 case 0: /* reset all console attributes to default */
614 s
->t_attrib
= s
->t_attrib_default
;
617 s
->t_attrib
.bold
= 1;
620 s
->t_attrib
.uline
= 1;
623 s
->t_attrib
.blink
= 1;
626 s
->t_attrib
.invers
= 1;
629 s
->t_attrib
.unvisible
= 1;
632 s
->t_attrib
.bold
= 0;
635 s
->t_attrib
.uline
= 0;
638 s
->t_attrib
.blink
= 0;
641 s
->t_attrib
.invers
= 0;
644 s
->t_attrib
.unvisible
= 0;
646 /* set foreground color */
648 s
->t_attrib
.fgcol
= QEMU_COLOR_BLACK
;
651 s
->t_attrib
.fgcol
= QEMU_COLOR_RED
;
654 s
->t_attrib
.fgcol
= QEMU_COLOR_GREEN
;
657 s
->t_attrib
.fgcol
= QEMU_COLOR_YELLOW
;
660 s
->t_attrib
.fgcol
= QEMU_COLOR_BLUE
;
663 s
->t_attrib
.fgcol
= QEMU_COLOR_MAGENTA
;
666 s
->t_attrib
.fgcol
= QEMU_COLOR_CYAN
;
669 s
->t_attrib
.fgcol
= QEMU_COLOR_WHITE
;
671 /* set background color */
673 s
->t_attrib
.bgcol
= QEMU_COLOR_BLACK
;
676 s
->t_attrib
.bgcol
= QEMU_COLOR_RED
;
679 s
->t_attrib
.bgcol
= QEMU_COLOR_GREEN
;
682 s
->t_attrib
.bgcol
= QEMU_COLOR_YELLOW
;
685 s
->t_attrib
.bgcol
= QEMU_COLOR_BLUE
;
688 s
->t_attrib
.bgcol
= QEMU_COLOR_MAGENTA
;
691 s
->t_attrib
.bgcol
= QEMU_COLOR_CYAN
;
694 s
->t_attrib
.bgcol
= QEMU_COLOR_WHITE
;
700 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
702 int y1
= (s
->y_base
+ y
) % s
->total_height
;
706 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
708 c
->t_attrib
= s
->t_attrib_default
;
712 static void console_put_one(QemuConsole
*s
, int ch
)
716 if (s
->x
>= s
->width
) {
721 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
722 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
724 c
->t_attrib
= s
->t_attrib
;
725 update_xy(s
, s
->x
, s
->y
);
729 static void console_respond_str(QemuConsole
*s
, const char *buf
)
732 console_put_one(s
, *buf
);
737 /* set cursor, checking bounds */
738 static void set_cursor(QemuConsole
*s
, int x
, int y
)
746 if (y
>= s
->height
) {
757 static void console_putchar(QemuConsole
*s
, int ch
)
766 case '\r': /* carriage return */
769 case '\n': /* newline */
772 case '\b': /* backspace */
776 case '\t': /* tabspace */
777 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
781 s
->x
= s
->x
+ (8 - (s
->x
% 8));
784 case '\a': /* alert aka. bell */
785 /* TODO: has to be implemented */
788 /* SI (shift in), character set 0 (ignored) */
791 /* SO (shift out), character set 1 (ignored) */
793 case 27: /* esc (introducing an escape sequence) */
794 s
->state
= TTY_STATE_ESC
;
797 console_put_one(s
, ch
);
801 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
803 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
804 s
->esc_params
[i
] = 0;
805 s
->nb_esc_params
= 0;
806 s
->state
= TTY_STATE_CSI
;
808 s
->state
= TTY_STATE_NORM
;
811 case TTY_STATE_CSI
: /* handle escape sequence parameters */
812 if (ch
>= '0' && ch
<= '9') {
813 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
814 int *param
= &s
->esc_params
[s
->nb_esc_params
];
815 int digit
= (ch
- '0');
817 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
818 *param
* 10 + digit
: INT_MAX
;
821 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
823 if (ch
== ';' || ch
== '?') {
826 trace_console_putchar_csi(s
->esc_params
[0], s
->esc_params
[1],
827 ch
, s
->nb_esc_params
);
828 s
->state
= TTY_STATE_NORM
;
832 if (s
->esc_params
[0] == 0) {
833 s
->esc_params
[0] = 1;
835 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
838 /* move cursor down */
839 if (s
->esc_params
[0] == 0) {
840 s
->esc_params
[0] = 1;
842 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
845 /* move cursor right */
846 if (s
->esc_params
[0] == 0) {
847 s
->esc_params
[0] = 1;
849 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
852 /* move cursor left */
853 if (s
->esc_params
[0] == 0) {
854 s
->esc_params
[0] = 1;
856 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
859 /* move cursor to column */
860 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
864 /* move cursor to row, column */
865 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
868 switch (s
->esc_params
[0]) {
870 /* clear to end of screen */
871 for (y
= s
->y
; y
< s
->height
; y
++) {
872 for (x
= 0; x
< s
->width
; x
++) {
873 if (y
== s
->y
&& x
< s
->x
) {
876 console_clear_xy(s
, x
, y
);
881 /* clear from beginning of screen */
882 for (y
= 0; y
<= s
->y
; y
++) {
883 for (x
= 0; x
< s
->width
; x
++) {
884 if (y
== s
->y
&& x
> s
->x
) {
887 console_clear_xy(s
, x
, y
);
892 /* clear entire screen */
893 for (y
= 0; y
<= s
->height
; y
++) {
894 for (x
= 0; x
< s
->width
; x
++) {
895 console_clear_xy(s
, x
, y
);
902 switch (s
->esc_params
[0]) {
905 for(x
= s
->x
; x
< s
->width
; x
++) {
906 console_clear_xy(s
, x
, s
->y
);
910 /* clear from beginning of line */
911 for (x
= 0; x
<= s
->x
&& x
< s
->width
; x
++) {
912 console_clear_xy(s
, x
, s
->y
);
916 /* clear entire line */
917 for(x
= 0; x
< s
->width
; x
++) {
918 console_clear_xy(s
, x
, s
->y
);
924 console_handle_escape(s
);
927 switch (s
->esc_params
[0]) {
929 /* report console status (always succeed)*/
930 console_respond_str(s
, "\033[0n");
933 /* report cursor position */
934 sprintf(response
, "\033[%d;%dR",
935 (s
->y_base
+ s
->y
) % s
->total_height
+ 1,
937 console_respond_str(s
, response
);
942 /* save cursor position */
947 /* restore cursor position */
952 trace_console_putchar_unhandled(ch
);
960 static void displaychangelistener_gfx_switch(DisplayChangeListener
*dcl
,
961 struct DisplaySurface
*new_surface
,
964 if (dcl
->ops
->dpy_gfx_switch
) {
965 dcl
->ops
->dpy_gfx_switch(dcl
, new_surface
);
968 if (update
&& dcl
->ops
->dpy_gfx_update
) {
969 dcl
->ops
->dpy_gfx_update(dcl
, 0, 0,
970 surface_width(new_surface
),
971 surface_height(new_surface
));
975 static void dpy_gfx_create_texture(QemuConsole
*con
, DisplaySurface
*surface
)
977 if (con
->gl
&& con
->gl
->ops
->dpy_gl_ctx_create_texture
) {
978 con
->gl
->ops
->dpy_gl_ctx_create_texture(con
->gl
, surface
);
982 static void dpy_gfx_destroy_texture(QemuConsole
*con
, DisplaySurface
*surface
)
984 if (con
->gl
&& con
->gl
->ops
->dpy_gl_ctx_destroy_texture
) {
985 con
->gl
->ops
->dpy_gl_ctx_destroy_texture(con
->gl
, surface
);
989 static void dpy_gfx_update_texture(QemuConsole
*con
, DisplaySurface
*surface
,
990 int x
, int y
, int w
, int h
)
992 if (con
->gl
&& con
->gl
->ops
->dpy_gl_ctx_update_texture
) {
993 con
->gl
->ops
->dpy_gl_ctx_update_texture(con
->gl
, surface
, x
, y
, w
, h
);
997 static void displaychangelistener_display_console(DisplayChangeListener
*dcl
,
1001 static const char nodev
[] =
1002 "This VM has no graphic display device.";
1003 static DisplaySurface
*dummy
;
1005 if (!con
|| !console_compatible_with(con
, dcl
, errp
)) {
1007 dummy
= qemu_create_placeholder_surface(640, 480, nodev
);
1010 dpy_gfx_create_texture(con
, dummy
);
1012 displaychangelistener_gfx_switch(dcl
, dummy
, TRUE
);
1016 dpy_gfx_create_texture(con
, con
->surface
);
1017 displaychangelistener_gfx_switch(dcl
, con
->surface
,
1018 con
->scanout
.kind
== SCANOUT_SURFACE
);
1020 if (con
->scanout
.kind
== SCANOUT_DMABUF
&&
1021 displaychangelistener_has_dmabuf(dcl
)) {
1022 dcl
->ops
->dpy_gl_scanout_dmabuf(dcl
, con
->scanout
.dmabuf
);
1023 } else if (con
->scanout
.kind
== SCANOUT_TEXTURE
&&
1024 dcl
->ops
->dpy_gl_scanout_texture
) {
1025 dcl
->ops
->dpy_gl_scanout_texture(dcl
,
1026 con
->scanout
.texture
.backing_id
,
1027 con
->scanout
.texture
.backing_y_0_top
,
1028 con
->scanout
.texture
.backing_width
,
1029 con
->scanout
.texture
.backing_height
,
1030 con
->scanout
.texture
.x
,
1031 con
->scanout
.texture
.y
,
1032 con
->scanout
.texture
.width
,
1033 con
->scanout
.texture
.height
,
1034 con
->scanout
.texture
.d3d_tex2d
);
1038 void console_select(unsigned int index
)
1040 DisplayChangeListener
*dcl
;
1043 trace_console_select(index
);
1044 s
= qemu_console_lookup_by_index(index
);
1046 DisplayState
*ds
= s
->ds
;
1049 QLIST_FOREACH (dcl
, &ds
->listeners
, next
) {
1050 if (dcl
->con
!= NULL
) {
1053 displaychangelistener_display_console(dcl
, s
, NULL
);
1055 dpy_text_resize(s
, s
->width
, s
->height
);
1056 text_console_update_cursor(NULL
);
1060 #define TYPE_CHARDEV_VC "chardev-vc"
1061 DECLARE_INSTANCE_CHECKER(VCChardev
, VC_CHARDEV
,
1064 static int vc_chr_write(Chardev
*chr
, const uint8_t *buf
, int len
)
1066 VCChardev
*drv
= VC_CHARDEV(chr
);
1067 QemuConsole
*s
= drv
->console
;
1070 s
->update_x0
= s
->width
* FONT_WIDTH
;
1071 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1074 console_show_cursor(s
, 0);
1075 for(i
= 0; i
< len
; i
++) {
1076 console_putchar(s
, buf
[i
]);
1078 console_show_cursor(s
, 1);
1079 if (s
->update_x0
< s
->update_x1
) {
1080 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1081 s
->update_x1
- s
->update_x0
,
1082 s
->update_y1
- s
->update_y0
);
1087 static void kbd_send_chars(QemuConsole
*s
)
1089 uint32_t len
, avail
;
1091 len
= qemu_chr_be_can_write(s
->chr
);
1092 avail
= fifo8_num_used(&s
->out_fifo
);
1093 while (len
> 0 && avail
> 0) {
1097 buf
= fifo8_pop_buf(&s
->out_fifo
, MIN(len
, avail
), &size
);
1098 qemu_chr_be_write(s
->chr
, buf
, size
);
1099 len
= qemu_chr_be_can_write(s
->chr
);
1104 /* called when an ascii key is pressed */
1105 void kbd_put_keysym_console(QemuConsole
*s
, int keysym
)
1107 uint8_t buf
[16], *q
;
1111 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1115 case QEMU_KEY_CTRL_UP
:
1116 console_scroll(s
, -1);
1118 case QEMU_KEY_CTRL_DOWN
:
1119 console_scroll(s
, 1);
1121 case QEMU_KEY_CTRL_PAGEUP
:
1122 console_scroll(s
, -10);
1124 case QEMU_KEY_CTRL_PAGEDOWN
:
1125 console_scroll(s
, 10);
1128 /* convert the QEMU keysym to VT100 key string */
1130 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1133 c
= keysym
- 0xe100;
1135 *q
++ = '0' + (c
/ 10);
1136 *q
++ = '0' + (c
% 10);
1138 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1141 *q
++ = keysym
& 0xff;
1142 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1143 qemu_chr_write(s
->chr
, (uint8_t *)"\r", 1, true);
1149 qemu_chr_write(s
->chr
, buf
, q
- buf
, true);
1151 num_free
= fifo8_num_free(&s
->out_fifo
);
1152 fifo8_push_all(&s
->out_fifo
, buf
, MIN(num_free
, q
- buf
));
1158 static const int qcode_to_keysym
[Q_KEY_CODE__MAX
] = {
1159 [Q_KEY_CODE_UP
] = QEMU_KEY_UP
,
1160 [Q_KEY_CODE_DOWN
] = QEMU_KEY_DOWN
,
1161 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_RIGHT
,
1162 [Q_KEY_CODE_LEFT
] = QEMU_KEY_LEFT
,
1163 [Q_KEY_CODE_HOME
] = QEMU_KEY_HOME
,
1164 [Q_KEY_CODE_END
] = QEMU_KEY_END
,
1165 [Q_KEY_CODE_PGUP
] = QEMU_KEY_PAGEUP
,
1166 [Q_KEY_CODE_PGDN
] = QEMU_KEY_PAGEDOWN
,
1167 [Q_KEY_CODE_DELETE
] = QEMU_KEY_DELETE
,
1168 [Q_KEY_CODE_TAB
] = QEMU_KEY_TAB
,
1169 [Q_KEY_CODE_BACKSPACE
] = QEMU_KEY_BACKSPACE
,
1172 static const int ctrl_qcode_to_keysym
[Q_KEY_CODE__MAX
] = {
1173 [Q_KEY_CODE_UP
] = QEMU_KEY_CTRL_UP
,
1174 [Q_KEY_CODE_DOWN
] = QEMU_KEY_CTRL_DOWN
,
1175 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_CTRL_RIGHT
,
1176 [Q_KEY_CODE_LEFT
] = QEMU_KEY_CTRL_LEFT
,
1177 [Q_KEY_CODE_HOME
] = QEMU_KEY_CTRL_HOME
,
1178 [Q_KEY_CODE_END
] = QEMU_KEY_CTRL_END
,
1179 [Q_KEY_CODE_PGUP
] = QEMU_KEY_CTRL_PAGEUP
,
1180 [Q_KEY_CODE_PGDN
] = QEMU_KEY_CTRL_PAGEDOWN
,
1183 bool kbd_put_qcode_console(QemuConsole
*s
, int qcode
, bool ctrl
)
1187 keysym
= ctrl
? ctrl_qcode_to_keysym
[qcode
] : qcode_to_keysym
[qcode
];
1191 kbd_put_keysym_console(s
, keysym
);
1195 void kbd_put_string_console(QemuConsole
*s
, const char *str
, int len
)
1199 for (i
= 0; i
< len
&& str
[i
]; i
++) {
1200 kbd_put_keysym_console(s
, str
[i
]);
1204 void kbd_put_keysym(int keysym
)
1206 kbd_put_keysym_console(active_console
, keysym
);
1209 static void text_console_invalidate(void *opaque
)
1211 QemuConsole
*s
= (QemuConsole
*) opaque
;
1213 if (s
->console_type
== TEXT_CONSOLE
) {
1214 text_console_resize(s
);
1219 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1221 QemuConsole
*s
= (QemuConsole
*) opaque
;
1224 if (s
->text_x
[0] <= s
->text_x
[1]) {
1225 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1226 chardata
+= s
->text_y
[0] * s
->width
;
1227 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1228 for (j
= 0; j
< s
->width
; j
++, src
++) {
1229 console_write_ch(chardata
++,
1230 ATTR2CHTYPE(s
->cells
[src
].ch
,
1231 s
->cells
[src
].t_attrib
.fgcol
,
1232 s
->cells
[src
].t_attrib
.bgcol
,
1233 s
->cells
[src
].t_attrib
.bold
));
1235 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1236 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1237 s
->text_x
[0] = s
->width
;
1238 s
->text_y
[0] = s
->height
;
1242 if (s
->cursor_invalidate
) {
1243 dpy_text_cursor(s
, s
->x
, s
->y
);
1244 s
->cursor_invalidate
= 0;
1248 static QemuConsole
*new_console(console_type_t console_type
, uint32_t head
)
1250 DisplayState
*ds
= get_alloc_displaystate();
1255 obj
= object_new(TYPE_QEMU_CONSOLE
);
1256 s
= QEMU_CONSOLE(obj
);
1257 qemu_co_queue_init(&s
->dump_queue
);
1259 object_property_add_link(obj
, "device", TYPE_DEVICE
,
1260 (Object
**)&s
->device
,
1261 object_property_allow_set_link
,
1262 OBJ_PROP_LINK_STRONG
);
1263 object_property_add_uint32_ptr(obj
, "head", &s
->head
,
1264 OBJ_PROP_FLAG_READ
);
1266 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1267 (console_type
== GRAPHIC_CONSOLE
))) {
1271 s
->console_type
= console_type
;
1274 if (QTAILQ_EMPTY(&consoles
)) {
1276 QTAILQ_INSERT_TAIL(&consoles
, s
, next
);
1277 } else if (console_type
!= GRAPHIC_CONSOLE
|| phase_check(PHASE_MACHINE_READY
)) {
1278 QemuConsole
*last
= QTAILQ_LAST(&consoles
);
1279 s
->index
= last
->index
+ 1;
1280 QTAILQ_INSERT_TAIL(&consoles
, s
, next
);
1283 * HACK: Put graphical consoles before text consoles.
1285 * Only do that for coldplugged devices. After initial device
1286 * initialization we will not renumber the consoles any more.
1288 QemuConsole
*c
= QTAILQ_FIRST(&consoles
);
1290 while (QTAILQ_NEXT(c
, next
) != NULL
&&
1291 c
->console_type
== GRAPHIC_CONSOLE
) {
1292 c
= QTAILQ_NEXT(c
, next
);
1294 if (c
->console_type
== GRAPHIC_CONSOLE
) {
1295 /* have no text consoles */
1296 s
->index
= c
->index
+ 1;
1297 QTAILQ_INSERT_AFTER(&consoles
, c
, s
, next
);
1299 s
->index
= c
->index
;
1300 QTAILQ_INSERT_BEFORE(c
, s
, next
);
1301 /* renumber text consoles */
1302 for (i
= s
->index
+ 1; c
!= NULL
; c
= QTAILQ_NEXT(c
, next
), i
++) {
1311 void qemu_displaysurface_win32_set_handle(DisplaySurface
*surface
,
1312 HANDLE h
, uint32_t offset
)
1314 assert(!surface
->handle
);
1316 surface
->handle
= h
;
1317 surface
->handle_offset
= offset
;
1321 win32_pixman_image_destroy(pixman_image_t
*image
, void *data
)
1323 DisplaySurface
*surface
= data
;
1325 if (!surface
->handle
) {
1329 assert(surface
->handle_offset
== 0);
1331 qemu_win32_map_free(
1332 pixman_image_get_data(surface
->image
),
1339 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1341 DisplaySurface
*surface
;
1344 HANDLE handle
= NULL
;
1347 trace_displaysurface_create(width
, height
);
1350 bits
= qemu_win32_map_alloc(width
* height
* 4, &handle
, &error_abort
);
1353 surface
= qemu_create_displaysurface_from(
1358 surface
->flags
= QEMU_ALLOCATED_FLAG
;
1361 qemu_displaysurface_win32_set_handle(surface
, handle
, 0);
1366 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
,
1367 pixman_format_code_t format
,
1368 int linesize
, uint8_t *data
)
1370 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1372 trace_displaysurface_create_from(surface
, width
, height
, format
);
1373 surface
->format
= format
;
1374 surface
->image
= pixman_image_create_bits(surface
->format
,
1376 (void *)data
, linesize
);
1377 assert(surface
->image
!= NULL
);
1379 pixman_image_set_destroy_function(surface
->image
,
1380 win32_pixman_image_destroy
, surface
);
1386 DisplaySurface
*qemu_create_displaysurface_pixman(pixman_image_t
*image
)
1388 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1390 trace_displaysurface_create_pixman(surface
);
1391 surface
->format
= pixman_image_get_format(image
);
1392 surface
->image
= pixman_image_ref(image
);
1397 DisplaySurface
*qemu_create_placeholder_surface(int w
, int h
,
1400 DisplaySurface
*surface
= qemu_create_displaysurface(w
, h
);
1401 pixman_color_t bg
= color_table_rgb
[0][QEMU_COLOR_BLACK
];
1402 pixman_color_t fg
= color_table_rgb
[0][QEMU_COLOR_WHITE
];
1403 pixman_image_t
*glyph
;
1407 x
= (w
/ FONT_WIDTH
- len
) / 2;
1408 y
= (h
/ FONT_HEIGHT
- 1) / 2;
1409 for (i
= 0; i
< len
; i
++) {
1410 glyph
= qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, msg
[i
]);
1411 qemu_pixman_glyph_render(glyph
, surface
->image
, &fg
, &bg
,
1412 x
+i
, y
, FONT_WIDTH
, FONT_HEIGHT
);
1413 qemu_pixman_image_unref(glyph
);
1415 surface
->flags
|= QEMU_PLACEHOLDER_FLAG
;
1419 void qemu_free_displaysurface(DisplaySurface
*surface
)
1421 if (surface
== NULL
) {
1424 trace_displaysurface_free(surface
);
1425 qemu_pixman_image_unref(surface
->image
);
1429 bool console_has_gl(QemuConsole
*con
)
1431 return con
->gl
!= NULL
;
1434 static bool displaychangelistener_has_dmabuf(DisplayChangeListener
*dcl
)
1436 if (dcl
->ops
->dpy_has_dmabuf
) {
1437 return dcl
->ops
->dpy_has_dmabuf(dcl
);
1440 if (dcl
->ops
->dpy_gl_scanout_dmabuf
) {
1447 static bool console_compatible_with(QemuConsole
*con
,
1448 DisplayChangeListener
*dcl
, Error
**errp
)
1452 flags
= con
->hw_ops
->get_flags
? con
->hw_ops
->get_flags(con
->hw
) : 0;
1454 if (console_has_gl(con
) &&
1455 !con
->gl
->ops
->dpy_gl_ctx_is_compatible_dcl(con
->gl
, dcl
)) {
1456 error_setg(errp
, "Display %s is incompatible with the GL context",
1457 dcl
->ops
->dpy_name
);
1461 if (flags
& GRAPHIC_FLAGS_GL
&&
1462 !console_has_gl(con
)) {
1463 error_setg(errp
, "The console requires a GL context.");
1468 if (flags
& GRAPHIC_FLAGS_DMABUF
&&
1469 !displaychangelistener_has_dmabuf(dcl
)) {
1470 error_setg(errp
, "The console requires display DMABUF support.");
1477 void console_handle_touch_event(QemuConsole
*con
,
1478 struct touch_slot touch_slots
[INPUT_EVENT_SLOTS_MAX
],
1480 int width
, int height
,
1482 InputMultiTouchType type
,
1485 struct touch_slot
*slot
;
1486 bool needs_sync
= false;
1490 if (num_slot
>= INPUT_EVENT_SLOTS_MAX
) {
1492 "Unexpected touch slot number: % " PRId64
" >= %d",
1493 num_slot
, INPUT_EVENT_SLOTS_MAX
);
1497 slot
= &touch_slots
[num_slot
];
1501 if (type
== INPUT_MULTI_TOUCH_TYPE_BEGIN
) {
1502 slot
->tracking_id
= num_slot
;
1505 for (i
= 0; i
< INPUT_EVENT_SLOTS_MAX
; ++i
) {
1506 if (i
== num_slot
) {
1509 update
= INPUT_MULTI_TOUCH_TYPE_UPDATE
;
1512 slot
= &touch_slots
[i
];
1514 if (slot
->tracking_id
== -1) {
1518 if (update
== INPUT_MULTI_TOUCH_TYPE_END
) {
1519 slot
->tracking_id
= -1;
1520 qemu_input_queue_mtt(con
, update
, i
, slot
->tracking_id
);
1523 qemu_input_queue_mtt(con
, update
, i
, slot
->tracking_id
);
1524 qemu_input_queue_btn(con
, INPUT_BUTTON_TOUCH
, true);
1525 qemu_input_queue_mtt_abs(con
,
1526 INPUT_AXIS_X
, (int) slot
->x
,
1528 i
, slot
->tracking_id
);
1529 qemu_input_queue_mtt_abs(con
,
1530 INPUT_AXIS_Y
, (int) slot
->y
,
1532 i
, slot
->tracking_id
);
1538 qemu_input_event_sync();
1542 void qemu_console_set_display_gl_ctx(QemuConsole
*con
, DisplayGLCtx
*gl
)
1544 /* display has opengl support */
1547 error_report("The console already has an OpenGL context.");
1553 void register_displaychangelistener(DisplayChangeListener
*dcl
)
1559 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1560 dcl
->ds
= get_alloc_displaystate();
1561 QLIST_INSERT_HEAD(&dcl
->ds
->listeners
, dcl
, next
);
1562 gui_setup_refresh(dcl
->ds
);
1567 con
= active_console
;
1569 displaychangelistener_display_console(dcl
, con
, dcl
->con
? &error_fatal
: NULL
);
1570 if (con
&& con
->cursor
&& dcl
->ops
->dpy_cursor_define
) {
1571 dcl
->ops
->dpy_cursor_define(dcl
, con
->cursor
);
1573 if (con
&& dcl
->ops
->dpy_mouse_set
) {
1574 dcl
->ops
->dpy_mouse_set(dcl
, con
->cursor_x
, con
->cursor_y
, con
->cursor_on
);
1576 text_console_update_cursor(NULL
);
1579 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1582 DisplayState
*ds
= dcl
->ds
;
1584 dcl
->update_interval
= interval
;
1585 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1586 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
1590 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1592 DisplayState
*ds
= dcl
->ds
;
1593 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1597 QLIST_REMOVE(dcl
, next
);
1599 gui_setup_refresh(ds
);
1602 static void dpy_set_ui_info_timer(void *opaque
)
1604 QemuConsole
*con
= opaque
;
1606 con
->hw_ops
->ui_info(con
->hw
, con
->head
, &con
->ui_info
);
1609 bool dpy_ui_info_supported(QemuConsole
*con
)
1612 con
= active_console
;
1615 return con
->hw_ops
->ui_info
!= NULL
;
1618 const QemuUIInfo
*dpy_get_ui_info(const QemuConsole
*con
)
1621 con
= active_console
;
1624 return &con
->ui_info
;
1627 int dpy_set_ui_info(QemuConsole
*con
, QemuUIInfo
*info
, bool delay
)
1630 con
= active_console
;
1633 if (!dpy_ui_info_supported(con
)) {
1636 if (memcmp(&con
->ui_info
, info
, sizeof(con
->ui_info
)) == 0) {
1637 /* nothing changed -- ignore */
1642 * Typically we get a flood of these as the user resizes the window.
1643 * Wait until the dust has settled (one second without updates), then
1644 * go notify the guest.
1646 con
->ui_info
= *info
;
1647 timer_mod(con
->ui_timer
,
1648 qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + (delay
? 1000 : 0));
1652 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1654 DisplayState
*s
= con
->ds
;
1655 DisplayChangeListener
*dcl
;
1656 int width
= qemu_console_get_width(con
, x
+ w
);
1657 int height
= qemu_console_get_height(con
, y
+ h
);
1663 w
= MIN(w
, width
- x
);
1664 h
= MIN(h
, height
- y
);
1666 if (!qemu_console_is_visible(con
)) {
1669 dpy_gfx_update_texture(con
, con
->surface
, x
, y
, w
, h
);
1670 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1671 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1674 if (dcl
->ops
->dpy_gfx_update
) {
1675 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1680 void dpy_gfx_update_full(QemuConsole
*con
)
1682 int w
= qemu_console_get_width(con
, 0);
1683 int h
= qemu_console_get_height(con
, 0);
1685 dpy_gfx_update(con
, 0, 0, w
, h
);
1688 void dpy_gfx_replace_surface(QemuConsole
*con
,
1689 DisplaySurface
*surface
)
1691 static const char placeholder_msg
[] = "Display output is not active.";
1692 DisplayState
*s
= con
->ds
;
1693 DisplaySurface
*old_surface
= con
->surface
;
1694 DisplaySurface
*new_surface
= surface
;
1695 DisplayChangeListener
*dcl
;
1701 width
= surface_width(old_surface
);
1702 height
= surface_height(old_surface
);
1708 new_surface
= qemu_create_placeholder_surface(width
, height
, placeholder_msg
);
1711 assert(old_surface
!= new_surface
);
1713 con
->scanout
.kind
= SCANOUT_SURFACE
;
1714 con
->surface
= new_surface
;
1715 dpy_gfx_create_texture(con
, new_surface
);
1716 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1717 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1720 displaychangelistener_gfx_switch(dcl
, new_surface
, surface
? FALSE
: TRUE
);
1722 dpy_gfx_destroy_texture(con
, old_surface
);
1723 qemu_free_displaysurface(old_surface
);
1726 bool dpy_gfx_check_format(QemuConsole
*con
,
1727 pixman_format_code_t format
)
1729 DisplayChangeListener
*dcl
;
1730 DisplayState
*s
= con
->ds
;
1732 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1733 if (dcl
->con
&& dcl
->con
!= con
) {
1734 /* dcl bound to another console -> skip */
1737 if (dcl
->ops
->dpy_gfx_check_format
) {
1738 if (!dcl
->ops
->dpy_gfx_check_format(dcl
, format
)) {
1742 /* default is to allow native 32 bpp only */
1743 if (format
!= qemu_default_pixman_format(32, true)) {
1751 static void dpy_refresh(DisplayState
*s
)
1753 DisplayChangeListener
*dcl
;
1755 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1756 if (dcl
->ops
->dpy_refresh
) {
1757 dcl
->ops
->dpy_refresh(dcl
);
1762 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1764 DisplayState
*s
= con
->ds
;
1765 DisplayChangeListener
*dcl
;
1767 if (!qemu_console_is_visible(con
)) {
1770 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1771 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1774 if (dcl
->ops
->dpy_text_cursor
) {
1775 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1780 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1782 DisplayState
*s
= con
->ds
;
1783 DisplayChangeListener
*dcl
;
1785 if (!qemu_console_is_visible(con
)) {
1788 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1789 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1792 if (dcl
->ops
->dpy_text_update
) {
1793 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1798 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1800 DisplayState
*s
= con
->ds
;
1801 DisplayChangeListener
*dcl
;
1803 if (!qemu_console_is_visible(con
)) {
1806 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1807 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1810 if (dcl
->ops
->dpy_text_resize
) {
1811 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1816 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1818 DisplayState
*s
= con
->ds
;
1819 DisplayChangeListener
*dcl
;
1823 con
->cursor_on
= on
;
1824 if (!qemu_console_is_visible(con
)) {
1827 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1828 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1831 if (dcl
->ops
->dpy_mouse_set
) {
1832 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1837 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1839 DisplayState
*s
= con
->ds
;
1840 DisplayChangeListener
*dcl
;
1842 cursor_unref(con
->cursor
);
1843 con
->cursor
= cursor_ref(cursor
);
1844 if (!qemu_console_is_visible(con
)) {
1847 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1848 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1851 if (dcl
->ops
->dpy_cursor_define
) {
1852 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1857 bool dpy_cursor_define_supported(QemuConsole
*con
)
1859 DisplayState
*s
= con
->ds
;
1860 DisplayChangeListener
*dcl
;
1862 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1863 if (dcl
->ops
->dpy_cursor_define
) {
1870 QEMUGLContext
dpy_gl_ctx_create(QemuConsole
*con
,
1871 struct QEMUGLParams
*qparams
)
1874 return con
->gl
->ops
->dpy_gl_ctx_create(con
->gl
, qparams
);
1877 void dpy_gl_ctx_destroy(QemuConsole
*con
, QEMUGLContext ctx
)
1880 con
->gl
->ops
->dpy_gl_ctx_destroy(con
->gl
, ctx
);
1883 int dpy_gl_ctx_make_current(QemuConsole
*con
, QEMUGLContext ctx
)
1886 return con
->gl
->ops
->dpy_gl_ctx_make_current(con
->gl
, ctx
);
1889 void dpy_gl_scanout_disable(QemuConsole
*con
)
1891 DisplayState
*s
= con
->ds
;
1892 DisplayChangeListener
*dcl
;
1894 if (con
->scanout
.kind
!= SCANOUT_SURFACE
) {
1895 con
->scanout
.kind
= SCANOUT_NONE
;
1897 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1898 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1901 if (dcl
->ops
->dpy_gl_scanout_disable
) {
1902 dcl
->ops
->dpy_gl_scanout_disable(dcl
);
1907 void dpy_gl_scanout_texture(QemuConsole
*con
,
1908 uint32_t backing_id
,
1909 bool backing_y_0_top
,
1910 uint32_t backing_width
,
1911 uint32_t backing_height
,
1912 uint32_t x
, uint32_t y
,
1913 uint32_t width
, uint32_t height
,
1916 DisplayState
*s
= con
->ds
;
1917 DisplayChangeListener
*dcl
;
1919 con
->scanout
.kind
= SCANOUT_TEXTURE
;
1920 con
->scanout
.texture
= (ScanoutTexture
) {
1921 backing_id
, backing_y_0_top
, backing_width
, backing_height
,
1922 x
, y
, width
, height
, d3d_tex2d
,
1924 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1925 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1928 if (dcl
->ops
->dpy_gl_scanout_texture
) {
1929 dcl
->ops
->dpy_gl_scanout_texture(dcl
, backing_id
,
1931 backing_width
, backing_height
,
1932 x
, y
, width
, height
,
1938 void dpy_gl_scanout_dmabuf(QemuConsole
*con
,
1941 DisplayState
*s
= con
->ds
;
1942 DisplayChangeListener
*dcl
;
1944 con
->scanout
.kind
= SCANOUT_DMABUF
;
1945 con
->scanout
.dmabuf
= dmabuf
;
1946 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1947 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1950 if (dcl
->ops
->dpy_gl_scanout_dmabuf
) {
1951 dcl
->ops
->dpy_gl_scanout_dmabuf(dcl
, dmabuf
);
1956 void dpy_gl_cursor_dmabuf(QemuConsole
*con
, QemuDmaBuf
*dmabuf
,
1957 bool have_hot
, uint32_t hot_x
, uint32_t hot_y
)
1959 DisplayState
*s
= con
->ds
;
1960 DisplayChangeListener
*dcl
;
1962 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1963 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1966 if (dcl
->ops
->dpy_gl_cursor_dmabuf
) {
1967 dcl
->ops
->dpy_gl_cursor_dmabuf(dcl
, dmabuf
,
1968 have_hot
, hot_x
, hot_y
);
1973 void dpy_gl_cursor_position(QemuConsole
*con
,
1974 uint32_t pos_x
, uint32_t pos_y
)
1976 DisplayState
*s
= con
->ds
;
1977 DisplayChangeListener
*dcl
;
1979 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1980 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1983 if (dcl
->ops
->dpy_gl_cursor_position
) {
1984 dcl
->ops
->dpy_gl_cursor_position(dcl
, pos_x
, pos_y
);
1989 void dpy_gl_release_dmabuf(QemuConsole
*con
,
1992 DisplayState
*s
= con
->ds
;
1993 DisplayChangeListener
*dcl
;
1995 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1996 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1999 if (dcl
->ops
->dpy_gl_release_dmabuf
) {
2000 dcl
->ops
->dpy_gl_release_dmabuf(dcl
, dmabuf
);
2005 void dpy_gl_update(QemuConsole
*con
,
2006 uint32_t x
, uint32_t y
, uint32_t w
, uint32_t h
)
2008 DisplayState
*s
= con
->ds
;
2009 DisplayChangeListener
*dcl
;
2013 graphic_hw_gl_block(con
, true);
2014 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
2015 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
2018 if (dcl
->ops
->dpy_gl_update
) {
2019 dcl
->ops
->dpy_gl_update(dcl
, x
, y
, w
, h
);
2022 graphic_hw_gl_block(con
, false);
2025 /***********************************************************/
2026 /* register display */
2028 /* console.c internal use only */
2029 static DisplayState
*get_alloc_displaystate(void)
2031 if (!display_state
) {
2032 display_state
= g_new0(DisplayState
, 1);
2033 cursor_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2034 text_console_update_cursor
, NULL
);
2036 return display_state
;
2040 * Called by main(), after creating QemuConsoles
2041 * and before initializing ui (sdl/vnc/...).
2043 DisplayState
*init_displaystate(void)
2048 QTAILQ_FOREACH(con
, &consoles
, next
) {
2049 /* Hook up into the qom tree here (not in new_console()), once
2050 * all QemuConsoles are created and the order / numbering
2051 * doesn't change any more */
2052 name
= g_strdup_printf("console[%d]", con
->index
);
2053 object_property_add_child(container_get(object_get_root(), "/backend"),
2058 return display_state
;
2061 void graphic_console_set_hwops(QemuConsole
*con
,
2062 const GraphicHwOps
*hw_ops
,
2065 con
->hw_ops
= hw_ops
;
2069 QemuConsole
*graphic_console_init(DeviceState
*dev
, uint32_t head
,
2070 const GraphicHwOps
*hw_ops
,
2073 static const char noinit
[] =
2074 "Guest has not initialized the display (yet).";
2078 DisplaySurface
*surface
;
2080 s
= qemu_console_lookup_unused();
2082 trace_console_gfx_reuse(s
->index
);
2083 width
= qemu_console_get_width(s
, 0);
2084 height
= qemu_console_get_height(s
, 0);
2086 trace_console_gfx_new();
2087 s
= new_console(GRAPHIC_CONSOLE
, head
);
2088 s
->ui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2089 dpy_set_ui_info_timer
, s
);
2091 graphic_console_set_hwops(s
, hw_ops
, opaque
);
2093 object_property_set_link(OBJECT(s
), "device", OBJECT(dev
),
2097 surface
= qemu_create_placeholder_surface(width
, height
, noinit
);
2098 dpy_gfx_replace_surface(s
, surface
);
2099 s
->gl_unblock_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2100 graphic_hw_gl_unblock_timer
, s
);
2104 static const GraphicHwOps unused_ops
= {
2108 void graphic_console_close(QemuConsole
*con
)
2110 static const char unplugged
[] =
2111 "Guest display has been unplugged";
2112 DisplaySurface
*surface
;
2113 int width
= qemu_console_get_width(con
, 640);
2114 int height
= qemu_console_get_height(con
, 480);
2116 trace_console_gfx_close(con
->index
);
2117 object_property_set_link(OBJECT(con
), "device", NULL
, &error_abort
);
2118 graphic_console_set_hwops(con
, &unused_ops
, NULL
);
2121 dpy_gl_scanout_disable(con
);
2123 surface
= qemu_create_placeholder_surface(width
, height
, unplugged
);
2124 dpy_gfx_replace_surface(con
, surface
);
2127 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
2131 QTAILQ_FOREACH(con
, &consoles
, next
) {
2132 if (con
->index
== index
) {
2139 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
, uint32_t head
)
2145 QTAILQ_FOREACH(con
, &consoles
, next
) {
2146 obj
= object_property_get_link(OBJECT(con
),
2147 "device", &error_abort
);
2148 if (DEVICE(obj
) != dev
) {
2151 h
= object_property_get_uint(OBJECT(con
),
2152 "head", &error_abort
);
2161 QemuConsole
*qemu_console_lookup_by_device_name(const char *device_id
,
2162 uint32_t head
, Error
**errp
)
2167 dev
= qdev_find_recursive(sysbus_get_default(), device_id
);
2169 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2170 "Device '%s' not found", device_id
);
2174 con
= qemu_console_lookup_by_device(dev
, head
);
2176 error_setg(errp
, "Device %s (head %d) is not bound to a QemuConsole",
2184 QemuConsole
*qemu_console_lookup_unused(void)
2189 QTAILQ_FOREACH(con
, &consoles
, next
) {
2190 if (con
->hw_ops
!= &unused_ops
) {
2193 obj
= object_property_get_link(OBJECT(con
),
2194 "device", &error_abort
);
2203 QEMUCursor
*qemu_console_get_cursor(QemuConsole
*con
)
2206 con
= active_console
;
2208 return con
? con
->cursor
: NULL
;
2211 bool qemu_console_is_visible(QemuConsole
*con
)
2213 return (con
== active_console
) || (con
->dcls
> 0);
2216 bool qemu_console_is_graphic(QemuConsole
*con
)
2219 con
= active_console
;
2221 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
2224 bool qemu_console_is_fixedsize(QemuConsole
*con
)
2227 con
= active_console
;
2229 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
2232 bool qemu_console_is_gl_blocked(QemuConsole
*con
)
2234 assert(con
!= NULL
);
2235 return con
->gl_block
;
2238 bool qemu_console_is_multihead(DeviceState
*dev
)
2242 uint32_t f
= 0xffffffff;
2245 QTAILQ_FOREACH(con
, &consoles
, next
) {
2246 obj
= object_property_get_link(OBJECT(con
),
2247 "device", &error_abort
);
2248 if (DEVICE(obj
) != dev
) {
2252 h
= object_property_get_uint(OBJECT(con
),
2253 "head", &error_abort
);
2254 if (f
== 0xffffffff) {
2256 } else if (h
!= f
) {
2263 char *qemu_console_get_label(QemuConsole
*con
)
2265 if (con
->console_type
== GRAPHIC_CONSOLE
) {
2270 dev
= DEVICE(con
->device
);
2271 multihead
= qemu_console_is_multihead(dev
);
2273 return g_strdup_printf("%s.%d", dev
->id
?
2275 object_get_typename(con
->device
),
2278 return g_strdup_printf("%s", dev
->id
?
2280 object_get_typename(con
->device
));
2283 return g_strdup("VGA");
2285 if (con
->chr
&& con
->chr
->label
) {
2286 return g_strdup(con
->chr
->label
);
2288 return g_strdup_printf("vc%d", con
->index
);
2292 int qemu_console_get_index(QemuConsole
*con
)
2295 con
= active_console
;
2297 return con
? con
->index
: -1;
2300 uint32_t qemu_console_get_head(QemuConsole
*con
)
2303 con
= active_console
;
2305 return con
? con
->head
: -1;
2308 int qemu_console_get_width(QemuConsole
*con
, int fallback
)
2311 con
= active_console
;
2316 switch (con
->scanout
.kind
) {
2317 case SCANOUT_DMABUF
:
2318 return con
->scanout
.dmabuf
->width
;
2319 case SCANOUT_TEXTURE
:
2320 return con
->scanout
.texture
.width
;
2321 case SCANOUT_SURFACE
:
2322 return surface_width(con
->surface
);
2328 int qemu_console_get_height(QemuConsole
*con
, int fallback
)
2331 con
= active_console
;
2336 switch (con
->scanout
.kind
) {
2337 case SCANOUT_DMABUF
:
2338 return con
->scanout
.dmabuf
->height
;
2339 case SCANOUT_TEXTURE
:
2340 return con
->scanout
.texture
.height
;
2341 case SCANOUT_SURFACE
:
2342 return surface_height(con
->surface
);
2348 static void vc_chr_accept_input(Chardev
*chr
)
2350 VCChardev
*drv
= VC_CHARDEV(chr
);
2351 QemuConsole
*s
= drv
->console
;
2356 static void vc_chr_set_echo(Chardev
*chr
, bool echo
)
2358 VCChardev
*drv
= VC_CHARDEV(chr
);
2359 QemuConsole
*s
= drv
->console
;
2364 static void text_console_update_cursor_timer(void)
2366 timer_mod(cursor_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
)
2367 + CONSOLE_CURSOR_PERIOD
/ 2);
2370 static void text_console_update_cursor(void *opaque
)
2375 cursor_visible_phase
= !cursor_visible_phase
;
2377 QTAILQ_FOREACH(s
, &consoles
, next
) {
2378 if (qemu_console_is_graphic(s
) ||
2379 !qemu_console_is_visible(s
)) {
2383 graphic_hw_invalidate(s
);
2387 text_console_update_cursor_timer();
2391 static const GraphicHwOps text_console_ops
= {
2392 .invalidate
= text_console_invalidate
,
2393 .text_update
= text_console_update
,
2396 static void text_console_do_init(Chardev
*chr
)
2398 VCChardev
*drv
= VC_CHARDEV(chr
);
2399 QemuConsole
*s
= drv
->console
;
2400 int g_width
= 80 * FONT_WIDTH
;
2401 int g_height
= 24 * FONT_HEIGHT
;
2403 fifo8_create(&s
->out_fifo
, 16);
2407 s
->total_height
= DEFAULT_BACKSCROLL
;
2410 if (s
->scanout
.kind
!= SCANOUT_SURFACE
) {
2411 if (active_console
&& active_console
->scanout
.kind
== SCANOUT_SURFACE
) {
2412 g_width
= qemu_console_get_width(active_console
, g_width
);
2413 g_height
= qemu_console_get_height(active_console
, g_height
);
2415 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
2416 s
->scanout
.kind
= SCANOUT_SURFACE
;
2419 s
->hw_ops
= &text_console_ops
;
2422 /* Set text attribute defaults */
2423 s
->t_attrib_default
.bold
= 0;
2424 s
->t_attrib_default
.uline
= 0;
2425 s
->t_attrib_default
.blink
= 0;
2426 s
->t_attrib_default
.invers
= 0;
2427 s
->t_attrib_default
.unvisible
= 0;
2428 s
->t_attrib_default
.fgcol
= QEMU_COLOR_WHITE
;
2429 s
->t_attrib_default
.bgcol
= QEMU_COLOR_BLACK
;
2430 /* set current text attributes to default */
2431 s
->t_attrib
= s
->t_attrib_default
;
2432 text_console_resize(s
);
2437 s
->t_attrib
.bgcol
= QEMU_COLOR_BLUE
;
2438 msg
= g_strdup_printf("%s console\r\n", chr
->label
);
2439 qemu_chr_write(chr
, (uint8_t *)msg
, strlen(msg
), true);
2441 s
->t_attrib
= s
->t_attrib_default
;
2444 qemu_chr_be_event(chr
, CHR_EVENT_OPENED
);
2447 static void vc_chr_open(Chardev
*chr
,
2448 ChardevBackend
*backend
,
2452 ChardevVC
*vc
= backend
->u
.vc
.data
;
2453 VCChardev
*drv
= VC_CHARDEV(chr
);
2456 unsigned height
= 0;
2458 if (vc
->has_width
) {
2460 } else if (vc
->has_cols
) {
2461 width
= vc
->cols
* FONT_WIDTH
;
2464 if (vc
->has_height
) {
2465 height
= vc
->height
;
2466 } else if (vc
->has_rows
) {
2467 height
= vc
->rows
* FONT_HEIGHT
;
2470 trace_console_txt_new(width
, height
);
2471 if (width
== 0 || height
== 0) {
2472 s
= new_console(TEXT_CONSOLE
, 0);
2474 s
= new_console(TEXT_CONSOLE_FIXED_SIZE
, 0);
2475 s
->scanout
.kind
= SCANOUT_SURFACE
;
2476 s
->surface
= qemu_create_displaysurface(width
, height
);
2482 text_console_do_init(chr
);
2484 /* console/chardev init sometimes completes elsewhere in a 2nd
2485 * stage, so defer OPENED events until they are fully initialized
2490 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
2492 DisplaySurface
*surface
= qemu_console_surface(s
);
2494 assert(s
->console_type
== GRAPHIC_CONSOLE
);
2496 if ((s
->scanout
.kind
!= SCANOUT_SURFACE
||
2497 (surface
&& surface
->flags
& QEMU_ALLOCATED_FLAG
)) &&
2498 qemu_console_get_width(s
, -1) == width
&&
2499 qemu_console_get_height(s
, -1) == height
) {
2503 surface
= qemu_create_displaysurface(width
, height
);
2504 dpy_gfx_replace_surface(s
, surface
);
2507 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
2509 switch (console
->scanout
.kind
) {
2510 case SCANOUT_SURFACE
:
2511 return console
->surface
;
2517 PixelFormat
qemu_default_pixelformat(int bpp
)
2519 pixman_format_code_t fmt
= qemu_default_pixman_format(bpp
, true);
2520 PixelFormat pf
= qemu_pixelformat_from_pixman(fmt
);
2524 static QemuDisplay
*dpys
[DISPLAY_TYPE__MAX
];
2526 void qemu_display_register(QemuDisplay
*ui
)
2528 assert(ui
->type
< DISPLAY_TYPE__MAX
);
2529 dpys
[ui
->type
] = ui
;
2532 bool qemu_display_find_default(DisplayOptions
*opts
)
2534 static DisplayType prio
[] = {
2535 #if defined(CONFIG_GTK)
2538 #if defined(CONFIG_SDL)
2541 #if defined(CONFIG_COCOA)
2547 for (i
= 0; i
< (int)ARRAY_SIZE(prio
); i
++) {
2548 if (dpys
[prio
[i
]] == NULL
) {
2549 Error
*local_err
= NULL
;
2550 int rv
= ui_module_load(DisplayType_str(prio
[i
]), &local_err
);
2552 error_report_err(local_err
);
2555 if (dpys
[prio
[i
]] == NULL
) {
2558 opts
->type
= prio
[i
];
2564 void qemu_display_early_init(DisplayOptions
*opts
)
2566 assert(opts
->type
< DISPLAY_TYPE__MAX
);
2567 if (opts
->type
== DISPLAY_TYPE_NONE
) {
2570 if (dpys
[opts
->type
] == NULL
) {
2571 Error
*local_err
= NULL
;
2572 int rv
= ui_module_load(DisplayType_str(opts
->type
), &local_err
);
2574 error_report_err(local_err
);
2577 if (dpys
[opts
->type
] == NULL
) {
2578 error_report("Display '%s' is not available.",
2579 DisplayType_str(opts
->type
));
2582 if (dpys
[opts
->type
]->early_init
) {
2583 dpys
[opts
->type
]->early_init(opts
);
2587 void qemu_display_init(DisplayState
*ds
, DisplayOptions
*opts
)
2589 assert(opts
->type
< DISPLAY_TYPE__MAX
);
2590 if (opts
->type
== DISPLAY_TYPE_NONE
) {
2593 assert(dpys
[opts
->type
] != NULL
);
2594 dpys
[opts
->type
]->init(ds
, opts
);
2597 void qemu_display_help(void)
2601 printf("Available display backend types:\n");
2603 for (idx
= DISPLAY_TYPE_NONE
; idx
< DISPLAY_TYPE__MAX
; idx
++) {
2605 Error
*local_err
= NULL
;
2606 int rv
= ui_module_load(DisplayType_str(idx
), &local_err
);
2608 error_report_err(local_err
);
2612 printf("%s\n", DisplayType_str(dpys
[idx
]->type
));
2617 void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
, Error
**errp
)
2622 backend
->type
= CHARDEV_BACKEND_KIND_VC
;
2623 vc
= backend
->u
.vc
.data
= g_new0(ChardevVC
, 1);
2624 qemu_chr_parse_common(opts
, qapi_ChardevVC_base(vc
));
2626 val
= qemu_opt_get_number(opts
, "width", 0);
2628 vc
->has_width
= true;
2632 val
= qemu_opt_get_number(opts
, "height", 0);
2634 vc
->has_height
= true;
2638 val
= qemu_opt_get_number(opts
, "cols", 0);
2640 vc
->has_cols
= true;
2644 val
= qemu_opt_get_number(opts
, "rows", 0);
2646 vc
->has_rows
= true;
2651 static const TypeInfo qemu_console_info
= {
2652 .name
= TYPE_QEMU_CONSOLE
,
2653 .parent
= TYPE_OBJECT
,
2654 .instance_size
= sizeof(QemuConsole
),
2655 .class_size
= sizeof(QemuConsoleClass
),
2658 static void char_vc_class_init(ObjectClass
*oc
, void *data
)
2660 ChardevClass
*cc
= CHARDEV_CLASS(oc
);
2662 cc
->parse
= qemu_chr_parse_vc
;
2663 cc
->open
= vc_chr_open
;
2664 cc
->chr_write
= vc_chr_write
;
2665 cc
->chr_accept_input
= vc_chr_accept_input
;
2666 cc
->chr_set_echo
= vc_chr_set_echo
;
2669 static const TypeInfo char_vc_type_info
= {
2670 .name
= TYPE_CHARDEV_VC
,
2671 .parent
= TYPE_CHARDEV
,
2672 .instance_size
= sizeof(VCChardev
),
2673 .class_init
= char_vc_class_init
,
2676 void qemu_console_early_init(void)
2678 /* set the default vc driver */
2679 if (!object_class_by_name(TYPE_CHARDEV_VC
)) {
2680 type_register(&char_vc_type_info
);
2684 static void register_types(void)
2686 type_register_static(&qemu_console_info
);
2689 type_init(register_types
);