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/fifo8.h"
31 #include "qemu/main-loop.h"
32 #include "qemu/module.h"
33 #include "qemu/option.h"
34 #include "qemu/timer.h"
35 #include "chardev/char.h"
37 #include "exec/memory.h"
38 #include "io/channel-file.h"
39 #include "qom/object.h"
41 #define DEFAULT_BACKSCROLL 512
42 #define CONSOLE_CURSOR_PERIOD 500
44 typedef struct TextAttributes
{
54 typedef struct TextCell
{
56 TextAttributes t_attrib
;
59 #define MAX_ESC_PARAMS 3
70 TEXT_CONSOLE_FIXED_SIZE
77 console_type_t console_type
;
79 DisplaySurface
*surface
;
80 DisplayScanout scanout
;
84 QEMUTimer
*gl_unblock_timer
;
87 /* Graphic console state. */
92 const GraphicHwOps
*hw_ops
;
95 /* Text console state */
99 int backscroll_height
;
101 int x_saved
, y_saved
;
104 TextAttributes t_attrib_default
; /* default text attributes */
105 TextAttributes t_attrib
; /* currently active text attributes */
107 int text_x
[2], text_y
[2], cursor_invalidate
;
116 int esc_params
[MAX_ESC_PARAMS
];
120 /* fifo for key pressed */
124 QTAILQ_ENTRY(QemuConsole
) next
;
127 struct DisplayState
{
128 QEMUTimer
*gui_timer
;
129 uint64_t last_update
;
130 uint64_t update_interval
;
135 QLIST_HEAD(, DisplayChangeListener
) listeners
;
138 static DisplayState
*display_state
;
139 static QemuConsole
*active_console
;
140 static QTAILQ_HEAD(, QemuConsole
) consoles
=
141 QTAILQ_HEAD_INITIALIZER(consoles
);
142 static bool cursor_visible_phase
;
143 static QEMUTimer
*cursor_timer
;
145 static void text_console_do_init(Chardev
*chr
, DisplayState
*ds
);
146 static void dpy_refresh(DisplayState
*s
);
147 static DisplayState
*get_alloc_displaystate(void);
148 static void text_console_update_cursor_timer(void);
149 static void text_console_update_cursor(void *opaque
);
150 static bool displaychangelistener_has_dmabuf(DisplayChangeListener
*dcl
);
151 static bool console_compatible_with(QemuConsole
*con
,
152 DisplayChangeListener
*dcl
, Error
**errp
);
154 static void gui_update(void *opaque
)
156 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
157 uint64_t dcl_interval
;
158 DisplayState
*ds
= opaque
;
159 DisplayChangeListener
*dcl
;
162 ds
->refreshing
= true;
164 ds
->refreshing
= false;
166 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
167 dcl_interval
= dcl
->update_interval
?
168 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
169 if (interval
> dcl_interval
) {
170 interval
= dcl_interval
;
173 if (ds
->update_interval
!= interval
) {
174 ds
->update_interval
= interval
;
175 QTAILQ_FOREACH(con
, &consoles
, next
) {
176 if (con
->hw_ops
->update_interval
) {
177 con
->hw_ops
->update_interval(con
->hw
, interval
);
180 trace_console_refresh(interval
);
182 ds
->last_update
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
183 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
186 static void gui_setup_refresh(DisplayState
*ds
)
188 DisplayChangeListener
*dcl
;
189 bool need_timer
= false;
190 bool have_gfx
= false;
191 bool have_text
= false;
193 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
194 if (dcl
->ops
->dpy_refresh
!= NULL
) {
197 if (dcl
->ops
->dpy_gfx_update
!= NULL
) {
200 if (dcl
->ops
->dpy_text_update
!= NULL
) {
205 if (need_timer
&& ds
->gui_timer
== NULL
) {
206 ds
->gui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, gui_update
, ds
);
207 timer_mod(ds
->gui_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
209 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
210 timer_free(ds
->gui_timer
);
211 ds
->gui_timer
= NULL
;
214 ds
->have_gfx
= have_gfx
;
215 ds
->have_text
= have_text
;
218 void graphic_hw_update_done(QemuConsole
*con
)
221 qemu_co_queue_restart_all(&con
->dump_queue
);
225 void graphic_hw_update(QemuConsole
*con
)
228 con
= con
? con
: active_console
;
232 if (con
->hw_ops
->gfx_update
) {
233 con
->hw_ops
->gfx_update(con
->hw
);
234 async
= con
->hw_ops
->gfx_update_async
;
237 graphic_hw_update_done(con
);
241 static void graphic_hw_gl_unblock_timer(void *opaque
)
243 warn_report("console: no gl-unblock within one second");
246 void graphic_hw_gl_block(QemuConsole
*con
, bool block
)
256 assert(con
->gl_block
>= 0);
257 if (!con
->hw_ops
->gl_block
) {
260 if ((block
&& con
->gl_block
!= 1) || (!block
&& con
->gl_block
!= 0)) {
263 con
->hw_ops
->gl_block(con
->hw
, block
);
266 timeout
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
267 timeout
+= 1000; /* one sec */
268 timer_mod(con
->gl_unblock_timer
, timeout
);
270 timer_del(con
->gl_unblock_timer
);
274 int qemu_console_get_window_id(QemuConsole
*con
)
276 return con
->window_id
;
279 void qemu_console_set_window_id(QemuConsole
*con
, int window_id
)
281 con
->window_id
= window_id
;
284 void graphic_hw_invalidate(QemuConsole
*con
)
287 con
= active_console
;
289 if (con
&& con
->hw_ops
->invalidate
) {
290 con
->hw_ops
->invalidate(con
->hw
);
294 static bool ppm_save(int fd
, pixman_image_t
*image
, Error
**errp
)
296 int width
= pixman_image_get_width(image
);
297 int height
= pixman_image_get_height(image
);
298 g_autoptr(Object
) ioc
= OBJECT(qio_channel_file_new_fd(fd
));
299 g_autofree
char *header
= NULL
;
300 g_autoptr(pixman_image_t
) linebuf
= NULL
;
303 trace_ppm_save(fd
, image
);
305 header
= g_strdup_printf("P6\n%d %d\n%d\n", width
, height
, 255);
306 if (qio_channel_write_all(QIO_CHANNEL(ioc
),
307 header
, strlen(header
), errp
) < 0) {
311 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
312 for (y
= 0; y
< height
; y
++) {
313 qemu_pixman_linebuf_fill(linebuf
, image
, width
, 0, y
);
314 if (qio_channel_write_all(QIO_CHANNEL(ioc
),
315 (char *)pixman_image_get_data(linebuf
),
316 pixman_image_get_stride(linebuf
), errp
) < 0) {
324 static void graphic_hw_update_bh(void *con
)
326 graphic_hw_update(con
);
329 /* Safety: coroutine-only, concurrent-coroutine safe, main thread only */
331 qmp_screendump(const char *filename
, bool has_device
, const char *device
,
332 bool has_head
, int64_t head
, Error
**errp
)
334 g_autoptr(pixman_image_t
) image
= NULL
;
336 DisplaySurface
*surface
;
340 con
= qemu_console_lookup_by_device_name(device
, has_head
? head
: 0,
347 error_setg(errp
, "'head' must be specified together with 'device'");
350 con
= qemu_console_lookup_by_index(0);
352 error_setg(errp
, "There is no console to take a screendump from");
357 if (qemu_co_queue_empty(&con
->dump_queue
)) {
358 /* Defer the update, it will restart the pending coroutines */
359 aio_bh_schedule_oneshot(qemu_get_aio_context(),
360 graphic_hw_update_bh
, con
);
362 qemu_co_queue_wait(&con
->dump_queue
, NULL
);
365 * All pending coroutines are woken up, while the BQL is held. No
366 * further graphic update are possible until it is released. Take
367 * an image ref before that.
369 surface
= qemu_console_surface(con
);
371 error_setg(errp
, "no surface");
374 image
= pixman_image_ref(surface
->image
);
376 fd
= qemu_open_old(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, 0666);
378 error_setg(errp
, "failed to open file '%s': %s", filename
,
384 * The image content could potentially be updated as the coroutine
385 * yields and releases the BQL. It could produce corrupted dump, but
386 * it should be otherwise safe.
388 if (!ppm_save(fd
, image
, errp
)) {
389 qemu_unlink(filename
);
393 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
396 con
= active_console
;
398 if (con
&& con
->hw_ops
->text_update
) {
399 con
->hw_ops
->text_update(con
->hw
, chardata
);
403 static void vga_fill_rect(QemuConsole
*con
,
404 int posx
, int posy
, int width
, int height
,
405 pixman_color_t color
)
407 DisplaySurface
*surface
= qemu_console_surface(con
);
408 pixman_rectangle16_t rect
= {
409 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
412 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
416 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
417 static void vga_bitblt(QemuConsole
*con
,
418 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
420 DisplaySurface
*surface
= qemu_console_surface(con
);
422 pixman_image_composite(PIXMAN_OP_SRC
,
423 surface
->image
, NULL
, surface
->image
,
424 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
427 /***********************************************************/
428 /* basic char display */
430 #define FONT_HEIGHT 16
435 #define QEMU_RGB(r, g, b) \
436 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
438 static const pixman_color_t color_table_rgb
[2][8] = {
440 [QEMU_COLOR_BLACK
] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
441 [QEMU_COLOR_BLUE
] = QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
442 [QEMU_COLOR_GREEN
] = QEMU_RGB(0x00, 0xaa, 0x00), /* green */
443 [QEMU_COLOR_CYAN
] = QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
444 [QEMU_COLOR_RED
] = QEMU_RGB(0xaa, 0x00, 0x00), /* red */
445 [QEMU_COLOR_MAGENTA
] = QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
446 [QEMU_COLOR_YELLOW
] = QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
447 [QEMU_COLOR_WHITE
] = QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
450 [QEMU_COLOR_BLACK
] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
451 [QEMU_COLOR_BLUE
] = QEMU_RGB(0x00, 0x00, 0xff), /* blue */
452 [QEMU_COLOR_GREEN
] = QEMU_RGB(0x00, 0xff, 0x00), /* green */
453 [QEMU_COLOR_CYAN
] = QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
454 [QEMU_COLOR_RED
] = QEMU_RGB(0xff, 0x00, 0x00), /* red */
455 [QEMU_COLOR_MAGENTA
] = QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
456 [QEMU_COLOR_YELLOW
] = QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
457 [QEMU_COLOR_WHITE
] = QEMU_RGB(0xff, 0xff, 0xff), /* white */
461 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
462 TextAttributes
*t_attrib
)
464 static pixman_image_t
*glyphs
[256];
465 DisplaySurface
*surface
= qemu_console_surface(s
);
466 pixman_color_t fgcol
, bgcol
;
468 if (t_attrib
->invers
) {
469 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
470 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
472 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
473 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
477 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
479 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
480 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
483 static void text_console_resize(QemuConsole
*s
)
485 TextCell
*cells
, *c
, *c1
;
486 int w1
, x
, y
, last_width
;
488 assert(s
->scanout
.kind
== SCANOUT_SURFACE
);
490 last_width
= s
->width
;
491 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
492 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
498 cells
= g_new(TextCell
, s
->width
* s
->total_height
+ 1);
499 for(y
= 0; y
< s
->total_height
; y
++) {
500 c
= &cells
[y
* s
->width
];
502 c1
= &s
->cells
[y
* last_width
];
503 for(x
= 0; x
< w1
; x
++) {
507 for(x
= w1
; x
< s
->width
; x
++) {
509 c
->t_attrib
= s
->t_attrib_default
;
517 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
519 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
520 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
521 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
522 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
525 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
527 if (!qemu_console_is_visible(s
)) {
530 if (s
->update_x0
> x
* FONT_WIDTH
)
531 s
->update_x0
= x
* FONT_WIDTH
;
532 if (s
->update_y0
> y
* FONT_HEIGHT
)
533 s
->update_y0
= y
* FONT_HEIGHT
;
534 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
535 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
536 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
537 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
540 static void update_xy(QemuConsole
*s
, int x
, int y
)
545 if (s
->ds
->have_text
) {
546 text_update_xy(s
, x
, y
);
549 y1
= (s
->y_base
+ y
) % s
->total_height
;
550 y2
= y1
- s
->y_displayed
;
552 y2
+= s
->total_height
;
554 if (y2
< s
->height
) {
558 c
= &s
->cells
[y1
* s
->width
+ x
];
559 vga_putcharxy(s
, x
, y2
, c
->ch
,
561 invalidate_xy(s
, x
, y2
);
565 static void console_show_cursor(QemuConsole
*s
, int show
)
571 if (s
->ds
->have_text
) {
572 s
->cursor_invalidate
= 1;
578 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
579 y
= y1
- s
->y_displayed
;
581 y
+= s
->total_height
;
584 c
= &s
->cells
[y1
* s
->width
+ x
];
585 if (show
&& cursor_visible_phase
) {
586 TextAttributes t_attrib
= s
->t_attrib_default
;
587 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
588 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
590 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
592 invalidate_xy(s
, x
, y
);
596 static void console_refresh(QemuConsole
*s
)
598 DisplaySurface
*surface
= qemu_console_surface(s
);
602 if (s
->ds
->have_text
) {
605 s
->text_x
[1] = s
->width
- 1;
606 s
->text_y
[1] = s
->height
- 1;
607 s
->cursor_invalidate
= 1;
610 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
611 color_table_rgb
[0][QEMU_COLOR_BLACK
]);
613 for (y
= 0; y
< s
->height
; y
++) {
614 c
= s
->cells
+ y1
* s
->width
;
615 for (x
= 0; x
< s
->width
; x
++) {
616 vga_putcharxy(s
, x
, y
, c
->ch
,
620 if (++y1
== s
->total_height
) {
624 console_show_cursor(s
, 1);
625 dpy_gfx_update(s
, 0, 0,
626 surface_width(surface
), surface_height(surface
));
629 static void console_scroll(QemuConsole
*s
, int ydelta
)
634 for(i
= 0; i
< ydelta
; i
++) {
635 if (s
->y_displayed
== s
->y_base
)
637 if (++s
->y_displayed
== s
->total_height
)
642 i
= s
->backscroll_height
;
643 if (i
> s
->total_height
- s
->height
)
644 i
= s
->total_height
- s
->height
;
647 y1
+= s
->total_height
;
648 for(i
= 0; i
< ydelta
; i
++) {
649 if (s
->y_displayed
== y1
)
651 if (--s
->y_displayed
< 0)
652 s
->y_displayed
= s
->total_height
- 1;
658 static void console_put_lf(QemuConsole
*s
)
664 if (s
->y
>= s
->height
) {
665 s
->y
= s
->height
- 1;
667 if (s
->y_displayed
== s
->y_base
) {
668 if (++s
->y_displayed
== s
->total_height
)
671 if (++s
->y_base
== s
->total_height
)
673 if (s
->backscroll_height
< s
->total_height
)
674 s
->backscroll_height
++;
675 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
676 c
= &s
->cells
[y1
* s
->width
];
677 for(x
= 0; x
< s
->width
; x
++) {
679 c
->t_attrib
= s
->t_attrib_default
;
682 if (s
->y_displayed
== s
->y_base
) {
683 if (s
->ds
->have_text
) {
686 s
->text_x
[1] = s
->width
- 1;
687 s
->text_y
[1] = s
->height
- 1;
690 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
691 s
->width
* FONT_WIDTH
,
692 (s
->height
- 1) * FONT_HEIGHT
);
693 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
694 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
695 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
698 s
->update_x1
= s
->width
* FONT_WIDTH
;
699 s
->update_y1
= s
->height
* FONT_HEIGHT
;
704 /* Set console attributes depending on the current escape codes.
705 * NOTE: I know this code is not very efficient (checking every color for it
706 * self) but it is more readable and better maintainable.
708 static void console_handle_escape(QemuConsole
*s
)
712 for (i
=0; i
<s
->nb_esc_params
; i
++) {
713 switch (s
->esc_params
[i
]) {
714 case 0: /* reset all console attributes to default */
715 s
->t_attrib
= s
->t_attrib_default
;
718 s
->t_attrib
.bold
= 1;
721 s
->t_attrib
.uline
= 1;
724 s
->t_attrib
.blink
= 1;
727 s
->t_attrib
.invers
= 1;
730 s
->t_attrib
.unvisible
= 1;
733 s
->t_attrib
.bold
= 0;
736 s
->t_attrib
.uline
= 0;
739 s
->t_attrib
.blink
= 0;
742 s
->t_attrib
.invers
= 0;
745 s
->t_attrib
.unvisible
= 0;
747 /* set foreground color */
749 s
->t_attrib
.fgcol
= QEMU_COLOR_BLACK
;
752 s
->t_attrib
.fgcol
= QEMU_COLOR_RED
;
755 s
->t_attrib
.fgcol
= QEMU_COLOR_GREEN
;
758 s
->t_attrib
.fgcol
= QEMU_COLOR_YELLOW
;
761 s
->t_attrib
.fgcol
= QEMU_COLOR_BLUE
;
764 s
->t_attrib
.fgcol
= QEMU_COLOR_MAGENTA
;
767 s
->t_attrib
.fgcol
= QEMU_COLOR_CYAN
;
770 s
->t_attrib
.fgcol
= QEMU_COLOR_WHITE
;
772 /* set background color */
774 s
->t_attrib
.bgcol
= QEMU_COLOR_BLACK
;
777 s
->t_attrib
.bgcol
= QEMU_COLOR_RED
;
780 s
->t_attrib
.bgcol
= QEMU_COLOR_GREEN
;
783 s
->t_attrib
.bgcol
= QEMU_COLOR_YELLOW
;
786 s
->t_attrib
.bgcol
= QEMU_COLOR_BLUE
;
789 s
->t_attrib
.bgcol
= QEMU_COLOR_MAGENTA
;
792 s
->t_attrib
.bgcol
= QEMU_COLOR_CYAN
;
795 s
->t_attrib
.bgcol
= QEMU_COLOR_WHITE
;
801 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
803 int y1
= (s
->y_base
+ y
) % s
->total_height
;
807 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
809 c
->t_attrib
= s
->t_attrib_default
;
813 static void console_put_one(QemuConsole
*s
, int ch
)
817 if (s
->x
>= s
->width
) {
822 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
823 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
825 c
->t_attrib
= s
->t_attrib
;
826 update_xy(s
, s
->x
, s
->y
);
830 static void console_respond_str(QemuConsole
*s
, const char *buf
)
833 console_put_one(s
, *buf
);
838 /* set cursor, checking bounds */
839 static void set_cursor(QemuConsole
*s
, int x
, int y
)
847 if (y
>= s
->height
) {
858 static void console_putchar(QemuConsole
*s
, int ch
)
867 case '\r': /* carriage return */
870 case '\n': /* newline */
873 case '\b': /* backspace */
877 case '\t': /* tabspace */
878 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
882 s
->x
= s
->x
+ (8 - (s
->x
% 8));
885 case '\a': /* alert aka. bell */
886 /* TODO: has to be implemented */
889 /* SI (shift in), character set 0 (ignored) */
892 /* SO (shift out), character set 1 (ignored) */
894 case 27: /* esc (introducing an escape sequence) */
895 s
->state
= TTY_STATE_ESC
;
898 console_put_one(s
, ch
);
902 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
904 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
905 s
->esc_params
[i
] = 0;
906 s
->nb_esc_params
= 0;
907 s
->state
= TTY_STATE_CSI
;
909 s
->state
= TTY_STATE_NORM
;
912 case TTY_STATE_CSI
: /* handle escape sequence parameters */
913 if (ch
>= '0' && ch
<= '9') {
914 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
915 int *param
= &s
->esc_params
[s
->nb_esc_params
];
916 int digit
= (ch
- '0');
918 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
919 *param
* 10 + digit
: INT_MAX
;
922 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
924 if (ch
== ';' || ch
== '?') {
927 trace_console_putchar_csi(s
->esc_params
[0], s
->esc_params
[1],
928 ch
, s
->nb_esc_params
);
929 s
->state
= TTY_STATE_NORM
;
933 if (s
->esc_params
[0] == 0) {
934 s
->esc_params
[0] = 1;
936 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
939 /* move cursor down */
940 if (s
->esc_params
[0] == 0) {
941 s
->esc_params
[0] = 1;
943 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
946 /* move cursor right */
947 if (s
->esc_params
[0] == 0) {
948 s
->esc_params
[0] = 1;
950 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
953 /* move cursor left */
954 if (s
->esc_params
[0] == 0) {
955 s
->esc_params
[0] = 1;
957 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
960 /* move cursor to column */
961 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
965 /* move cursor to row, column */
966 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
969 switch (s
->esc_params
[0]) {
971 /* clear to end of screen */
972 for (y
= s
->y
; y
< s
->height
; y
++) {
973 for (x
= 0; x
< s
->width
; x
++) {
974 if (y
== s
->y
&& x
< s
->x
) {
977 console_clear_xy(s
, x
, y
);
982 /* clear from beginning of screen */
983 for (y
= 0; y
<= s
->y
; y
++) {
984 for (x
= 0; x
< s
->width
; x
++) {
985 if (y
== s
->y
&& x
> s
->x
) {
988 console_clear_xy(s
, x
, y
);
993 /* clear entire screen */
994 for (y
= 0; y
<= s
->height
; y
++) {
995 for (x
= 0; x
< s
->width
; x
++) {
996 console_clear_xy(s
, x
, y
);
1003 switch (s
->esc_params
[0]) {
1006 for(x
= s
->x
; x
< s
->width
; x
++) {
1007 console_clear_xy(s
, x
, s
->y
);
1011 /* clear from beginning of line */
1012 for (x
= 0; x
<= s
->x
&& x
< s
->width
; x
++) {
1013 console_clear_xy(s
, x
, s
->y
);
1017 /* clear entire line */
1018 for(x
= 0; x
< s
->width
; x
++) {
1019 console_clear_xy(s
, x
, s
->y
);
1025 console_handle_escape(s
);
1028 switch (s
->esc_params
[0]) {
1030 /* report console status (always succeed)*/
1031 console_respond_str(s
, "\033[0n");
1034 /* report cursor position */
1035 sprintf(response
, "\033[%d;%dR",
1036 (s
->y_base
+ s
->y
) % s
->total_height
+ 1,
1038 console_respond_str(s
, response
);
1043 /* save cursor position */
1048 /* restore cursor position */
1053 trace_console_putchar_unhandled(ch
);
1061 static void displaychangelistener_gfx_switch(DisplayChangeListener
*dcl
,
1062 struct DisplaySurface
*new_surface
,
1065 if (dcl
->ops
->dpy_gfx_switch
) {
1066 dcl
->ops
->dpy_gfx_switch(dcl
, new_surface
);
1069 if (update
&& dcl
->ops
->dpy_gfx_update
) {
1070 dcl
->ops
->dpy_gfx_update(dcl
, 0, 0,
1071 surface_width(new_surface
),
1072 surface_height(new_surface
));
1076 static void dpy_gfx_create_texture(QemuConsole
*con
, DisplaySurface
*surface
)
1078 if (con
->gl
&& con
->gl
->ops
->dpy_gl_ctx_create_texture
) {
1079 con
->gl
->ops
->dpy_gl_ctx_create_texture(con
->gl
, surface
);
1083 static void dpy_gfx_destroy_texture(QemuConsole
*con
, DisplaySurface
*surface
)
1085 if (con
->gl
&& con
->gl
->ops
->dpy_gl_ctx_destroy_texture
) {
1086 con
->gl
->ops
->dpy_gl_ctx_destroy_texture(con
->gl
, surface
);
1090 static void dpy_gfx_update_texture(QemuConsole
*con
, DisplaySurface
*surface
,
1091 int x
, int y
, int w
, int h
)
1093 if (con
->gl
&& con
->gl
->ops
->dpy_gl_ctx_update_texture
) {
1094 con
->gl
->ops
->dpy_gl_ctx_update_texture(con
->gl
, surface
, x
, y
, w
, h
);
1098 static void displaychangelistener_display_console(DisplayChangeListener
*dcl
,
1102 static const char nodev
[] =
1103 "This VM has no graphic display device.";
1104 static DisplaySurface
*dummy
;
1106 if (!con
|| !console_compatible_with(con
, dcl
, errp
)) {
1108 dummy
= qemu_create_placeholder_surface(640, 480, nodev
);
1111 dpy_gfx_create_texture(con
, dummy
);
1113 displaychangelistener_gfx_switch(dcl
, dummy
, TRUE
);
1117 dpy_gfx_create_texture(con
, con
->surface
);
1118 displaychangelistener_gfx_switch(dcl
, con
->surface
,
1119 con
->scanout
.kind
== SCANOUT_SURFACE
);
1121 if (con
->scanout
.kind
== SCANOUT_DMABUF
&&
1122 displaychangelistener_has_dmabuf(dcl
)) {
1123 dcl
->ops
->dpy_gl_scanout_dmabuf(dcl
, con
->scanout
.dmabuf
);
1124 } else if (con
->scanout
.kind
== SCANOUT_TEXTURE
&&
1125 dcl
->ops
->dpy_gl_scanout_texture
) {
1126 dcl
->ops
->dpy_gl_scanout_texture(dcl
,
1127 con
->scanout
.texture
.backing_id
,
1128 con
->scanout
.texture
.backing_y_0_top
,
1129 con
->scanout
.texture
.backing_width
,
1130 con
->scanout
.texture
.backing_height
,
1131 con
->scanout
.texture
.x
,
1132 con
->scanout
.texture
.y
,
1133 con
->scanout
.texture
.width
,
1134 con
->scanout
.texture
.height
);
1138 void console_select(unsigned int index
)
1140 DisplayChangeListener
*dcl
;
1143 trace_console_select(index
);
1144 s
= qemu_console_lookup_by_index(index
);
1146 DisplayState
*ds
= s
->ds
;
1150 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1151 if (dcl
->con
!= NULL
) {
1154 displaychangelistener_display_console(dcl
, s
, NULL
);
1157 if (ds
->have_text
) {
1158 dpy_text_resize(s
, s
->width
, s
->height
);
1160 text_console_update_cursor(NULL
);
1166 QemuConsole
*console
;
1168 typedef struct VCChardev VCChardev
;
1170 #define TYPE_CHARDEV_VC "chardev-vc"
1171 DECLARE_INSTANCE_CHECKER(VCChardev
, VC_CHARDEV
,
1174 static int vc_chr_write(Chardev
*chr
, const uint8_t *buf
, int len
)
1176 VCChardev
*drv
= VC_CHARDEV(chr
);
1177 QemuConsole
*s
= drv
->console
;
1184 s
->update_x0
= s
->width
* FONT_WIDTH
;
1185 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1188 console_show_cursor(s
, 0);
1189 for(i
= 0; i
< len
; i
++) {
1190 console_putchar(s
, buf
[i
]);
1192 console_show_cursor(s
, 1);
1193 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1194 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1195 s
->update_x1
- s
->update_x0
,
1196 s
->update_y1
- s
->update_y0
);
1201 static void kbd_send_chars(QemuConsole
*s
)
1203 uint32_t len
, avail
;
1205 len
= qemu_chr_be_can_write(s
->chr
);
1206 avail
= fifo8_num_used(&s
->out_fifo
);
1207 while (len
> 0 && avail
> 0) {
1211 buf
= fifo8_pop_buf(&s
->out_fifo
, MIN(len
, avail
), &size
);
1212 qemu_chr_be_write(s
->chr
, (uint8_t *)buf
, size
);
1213 len
= qemu_chr_be_can_write(s
->chr
);
1218 /* called when an ascii key is pressed */
1219 void kbd_put_keysym_console(QemuConsole
*s
, int keysym
)
1221 uint8_t buf
[16], *q
;
1225 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1229 case QEMU_KEY_CTRL_UP
:
1230 console_scroll(s
, -1);
1232 case QEMU_KEY_CTRL_DOWN
:
1233 console_scroll(s
, 1);
1235 case QEMU_KEY_CTRL_PAGEUP
:
1236 console_scroll(s
, -10);
1238 case QEMU_KEY_CTRL_PAGEDOWN
:
1239 console_scroll(s
, 10);
1242 /* convert the QEMU keysym to VT100 key string */
1244 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1247 c
= keysym
- 0xe100;
1249 *q
++ = '0' + (c
/ 10);
1250 *q
++ = '0' + (c
% 10);
1252 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1255 *q
++ = keysym
& 0xff;
1256 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1257 vc_chr_write(s
->chr
, (const uint8_t *) "\r", 1);
1263 vc_chr_write(s
->chr
, buf
, q
- buf
);
1265 num_free
= fifo8_num_free(&s
->out_fifo
);
1266 fifo8_push_all(&s
->out_fifo
, buf
, MIN(num_free
, q
- buf
));
1272 static const int qcode_to_keysym
[Q_KEY_CODE__MAX
] = {
1273 [Q_KEY_CODE_UP
] = QEMU_KEY_UP
,
1274 [Q_KEY_CODE_DOWN
] = QEMU_KEY_DOWN
,
1275 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_RIGHT
,
1276 [Q_KEY_CODE_LEFT
] = QEMU_KEY_LEFT
,
1277 [Q_KEY_CODE_HOME
] = QEMU_KEY_HOME
,
1278 [Q_KEY_CODE_END
] = QEMU_KEY_END
,
1279 [Q_KEY_CODE_PGUP
] = QEMU_KEY_PAGEUP
,
1280 [Q_KEY_CODE_PGDN
] = QEMU_KEY_PAGEDOWN
,
1281 [Q_KEY_CODE_DELETE
] = QEMU_KEY_DELETE
,
1282 [Q_KEY_CODE_BACKSPACE
] = QEMU_KEY_BACKSPACE
,
1285 static const int ctrl_qcode_to_keysym
[Q_KEY_CODE__MAX
] = {
1286 [Q_KEY_CODE_UP
] = QEMU_KEY_CTRL_UP
,
1287 [Q_KEY_CODE_DOWN
] = QEMU_KEY_CTRL_DOWN
,
1288 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_CTRL_RIGHT
,
1289 [Q_KEY_CODE_LEFT
] = QEMU_KEY_CTRL_LEFT
,
1290 [Q_KEY_CODE_HOME
] = QEMU_KEY_CTRL_HOME
,
1291 [Q_KEY_CODE_END
] = QEMU_KEY_CTRL_END
,
1292 [Q_KEY_CODE_PGUP
] = QEMU_KEY_CTRL_PAGEUP
,
1293 [Q_KEY_CODE_PGDN
] = QEMU_KEY_CTRL_PAGEDOWN
,
1296 bool kbd_put_qcode_console(QemuConsole
*s
, int qcode
, bool ctrl
)
1300 keysym
= ctrl
? ctrl_qcode_to_keysym
[qcode
] : qcode_to_keysym
[qcode
];
1304 kbd_put_keysym_console(s
, keysym
);
1308 void kbd_put_string_console(QemuConsole
*s
, const char *str
, int len
)
1312 for (i
= 0; i
< len
&& str
[i
]; i
++) {
1313 kbd_put_keysym_console(s
, str
[i
]);
1317 void kbd_put_keysym(int keysym
)
1319 kbd_put_keysym_console(active_console
, keysym
);
1322 static void text_console_invalidate(void *opaque
)
1324 QemuConsole
*s
= (QemuConsole
*) opaque
;
1326 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1327 text_console_resize(s
);
1332 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1334 QemuConsole
*s
= (QemuConsole
*) opaque
;
1337 if (s
->text_x
[0] <= s
->text_x
[1]) {
1338 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1339 chardata
+= s
->text_y
[0] * s
->width
;
1340 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1341 for (j
= 0; j
< s
->width
; j
++, src
++) {
1342 console_write_ch(chardata
++,
1343 ATTR2CHTYPE(s
->cells
[src
].ch
,
1344 s
->cells
[src
].t_attrib
.fgcol
,
1345 s
->cells
[src
].t_attrib
.bgcol
,
1346 s
->cells
[src
].t_attrib
.bold
));
1348 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1349 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1350 s
->text_x
[0] = s
->width
;
1351 s
->text_y
[0] = s
->height
;
1355 if (s
->cursor_invalidate
) {
1356 dpy_text_cursor(s
, s
->x
, s
->y
);
1357 s
->cursor_invalidate
= 0;
1361 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
,
1368 obj
= object_new(TYPE_QEMU_CONSOLE
);
1369 s
= QEMU_CONSOLE(obj
);
1370 qemu_co_queue_init(&s
->dump_queue
);
1372 object_property_add_link(obj
, "device", TYPE_DEVICE
,
1373 (Object
**)&s
->device
,
1374 object_property_allow_set_link
,
1375 OBJ_PROP_LINK_STRONG
);
1376 object_property_add_uint32_ptr(obj
, "head", &s
->head
,
1377 OBJ_PROP_FLAG_READ
);
1379 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1380 (console_type
== GRAPHIC_CONSOLE
))) {
1384 s
->console_type
= console_type
;
1387 if (QTAILQ_EMPTY(&consoles
)) {
1389 QTAILQ_INSERT_TAIL(&consoles
, s
, next
);
1390 } else if (console_type
!= GRAPHIC_CONSOLE
|| phase_check(PHASE_MACHINE_READY
)) {
1391 QemuConsole
*last
= QTAILQ_LAST(&consoles
);
1392 s
->index
= last
->index
+ 1;
1393 QTAILQ_INSERT_TAIL(&consoles
, s
, next
);
1396 * HACK: Put graphical consoles before text consoles.
1398 * Only do that for coldplugged devices. After initial device
1399 * initialization we will not renumber the consoles any more.
1401 QemuConsole
*c
= QTAILQ_FIRST(&consoles
);
1403 while (QTAILQ_NEXT(c
, next
) != NULL
&&
1404 c
->console_type
== GRAPHIC_CONSOLE
) {
1405 c
= QTAILQ_NEXT(c
, next
);
1407 if (c
->console_type
== GRAPHIC_CONSOLE
) {
1408 /* have no text consoles */
1409 s
->index
= c
->index
+ 1;
1410 QTAILQ_INSERT_AFTER(&consoles
, c
, s
, next
);
1412 s
->index
= c
->index
;
1413 QTAILQ_INSERT_BEFORE(c
, s
, next
);
1414 /* renumber text consoles */
1415 for (i
= s
->index
+ 1; c
!= NULL
; c
= QTAILQ_NEXT(c
, next
), i
++) {
1423 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1425 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1427 trace_displaysurface_create(surface
, width
, height
);
1428 surface
->format
= PIXMAN_x8r8g8b8
;
1429 surface
->image
= pixman_image_create_bits(surface
->format
,
1432 assert(surface
->image
!= NULL
);
1433 surface
->flags
= QEMU_ALLOCATED_FLAG
;
1438 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
,
1439 pixman_format_code_t format
,
1440 int linesize
, uint8_t *data
)
1442 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1444 trace_displaysurface_create_from(surface
, width
, height
, format
);
1445 surface
->format
= format
;
1446 surface
->image
= pixman_image_create_bits(surface
->format
,
1448 (void *)data
, linesize
);
1449 assert(surface
->image
!= NULL
);
1454 DisplaySurface
*qemu_create_displaysurface_pixman(pixman_image_t
*image
)
1456 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1458 trace_displaysurface_create_pixman(surface
);
1459 surface
->format
= pixman_image_get_format(image
);
1460 surface
->image
= pixman_image_ref(image
);
1465 DisplaySurface
*qemu_create_placeholder_surface(int w
, int h
,
1468 DisplaySurface
*surface
= qemu_create_displaysurface(w
, h
);
1469 pixman_color_t bg
= color_table_rgb
[0][QEMU_COLOR_BLACK
];
1470 pixman_color_t fg
= color_table_rgb
[0][QEMU_COLOR_WHITE
];
1471 pixman_image_t
*glyph
;
1475 x
= (w
/ FONT_WIDTH
- len
) / 2;
1476 y
= (h
/ FONT_HEIGHT
- 1) / 2;
1477 for (i
= 0; i
< len
; i
++) {
1478 glyph
= qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, msg
[i
]);
1479 qemu_pixman_glyph_render(glyph
, surface
->image
, &fg
, &bg
,
1480 x
+i
, y
, FONT_WIDTH
, FONT_HEIGHT
);
1481 qemu_pixman_image_unref(glyph
);
1483 surface
->flags
|= QEMU_PLACEHOLDER_FLAG
;
1487 void qemu_free_displaysurface(DisplaySurface
*surface
)
1489 if (surface
== NULL
) {
1492 trace_displaysurface_free(surface
);
1493 qemu_pixman_image_unref(surface
->image
);
1497 bool console_has_gl(QemuConsole
*con
)
1499 return con
->gl
!= NULL
;
1502 static bool displaychangelistener_has_dmabuf(DisplayChangeListener
*dcl
)
1504 if (dcl
->ops
->dpy_has_dmabuf
) {
1505 return dcl
->ops
->dpy_has_dmabuf(dcl
);
1508 if (dcl
->ops
->dpy_gl_scanout_dmabuf
) {
1515 static bool console_compatible_with(QemuConsole
*con
,
1516 DisplayChangeListener
*dcl
, Error
**errp
)
1520 flags
= con
->hw_ops
->get_flags
? con
->hw_ops
->get_flags(con
->hw
) : 0;
1522 if (console_has_gl(con
) &&
1523 !con
->gl
->ops
->dpy_gl_ctx_is_compatible_dcl(con
->gl
, dcl
)) {
1524 error_setg(errp
, "Display %s is incompatible with the GL context",
1525 dcl
->ops
->dpy_name
);
1529 if (flags
& GRAPHIC_FLAGS_GL
&&
1530 !console_has_gl(con
)) {
1531 error_setg(errp
, "The console requires a GL context.");
1536 if (flags
& GRAPHIC_FLAGS_DMABUF
&&
1537 !displaychangelistener_has_dmabuf(dcl
)) {
1538 error_setg(errp
, "The console requires display DMABUF support.");
1545 void qemu_console_set_display_gl_ctx(QemuConsole
*con
, DisplayGLCtx
*gl
)
1547 /* display has opengl support */
1550 error_report("The console already has an OpenGL context.");
1556 void register_displaychangelistener(DisplayChangeListener
*dcl
)
1562 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1563 dcl
->ds
= get_alloc_displaystate();
1564 QLIST_INSERT_HEAD(&dcl
->ds
->listeners
, dcl
, next
);
1565 gui_setup_refresh(dcl
->ds
);
1570 con
= active_console
;
1572 displaychangelistener_display_console(dcl
, con
, dcl
->con
? &error_fatal
: NULL
);
1573 text_console_update_cursor(NULL
);
1576 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1579 DisplayState
*ds
= dcl
->ds
;
1581 dcl
->update_interval
= interval
;
1582 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1583 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
1587 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1589 DisplayState
*ds
= dcl
->ds
;
1590 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1594 QLIST_REMOVE(dcl
, next
);
1596 gui_setup_refresh(ds
);
1599 static void dpy_set_ui_info_timer(void *opaque
)
1601 QemuConsole
*con
= opaque
;
1603 con
->hw_ops
->ui_info(con
->hw
, con
->head
, &con
->ui_info
);
1606 bool dpy_ui_info_supported(QemuConsole
*con
)
1609 con
= active_console
;
1612 return con
->hw_ops
->ui_info
!= NULL
;
1615 const QemuUIInfo
*dpy_get_ui_info(const QemuConsole
*con
)
1618 con
= active_console
;
1621 return &con
->ui_info
;
1624 int dpy_set_ui_info(QemuConsole
*con
, QemuUIInfo
*info
, bool delay
)
1627 con
= active_console
;
1630 if (!dpy_ui_info_supported(con
)) {
1633 if (memcmp(&con
->ui_info
, info
, sizeof(con
->ui_info
)) == 0) {
1634 /* nothing changed -- ignore */
1639 * Typically we get a flood of these as the user resizes the window.
1640 * Wait until the dust has settled (one second without updates), then
1641 * go notify the guest.
1643 con
->ui_info
= *info
;
1644 timer_mod(con
->ui_timer
,
1645 qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + (delay
? 1000 : 0));
1649 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1651 DisplayState
*s
= con
->ds
;
1652 DisplayChangeListener
*dcl
;
1653 int width
= qemu_console_get_width(con
, x
+ w
);
1654 int height
= qemu_console_get_height(con
, y
+ h
);
1660 w
= MIN(w
, width
- x
);
1661 h
= MIN(h
, height
- y
);
1663 if (!qemu_console_is_visible(con
)) {
1666 dpy_gfx_update_texture(con
, con
->surface
, x
, y
, w
, h
);
1667 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1668 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1671 if (dcl
->ops
->dpy_gfx_update
) {
1672 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1677 void dpy_gfx_update_full(QemuConsole
*con
)
1679 int w
= qemu_console_get_width(con
, 0);
1680 int h
= qemu_console_get_height(con
, 0);
1682 dpy_gfx_update(con
, 0, 0, w
, h
);
1685 void dpy_gfx_replace_surface(QemuConsole
*con
,
1686 DisplaySurface
*surface
)
1688 static const char placeholder_msg
[] = "Display output is not active.";
1689 DisplayState
*s
= con
->ds
;
1690 DisplaySurface
*old_surface
= con
->surface
;
1691 DisplayChangeListener
*dcl
;
1697 width
= surface_width(old_surface
);
1698 height
= surface_height(old_surface
);
1704 surface
= qemu_create_placeholder_surface(width
, height
, placeholder_msg
);
1707 assert(old_surface
!= surface
);
1709 con
->scanout
.kind
= SCANOUT_SURFACE
;
1710 con
->surface
= surface
;
1711 dpy_gfx_create_texture(con
, surface
);
1712 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1713 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1716 displaychangelistener_gfx_switch(dcl
, surface
, FALSE
);
1718 dpy_gfx_destroy_texture(con
, old_surface
);
1719 qemu_free_displaysurface(old_surface
);
1722 bool dpy_gfx_check_format(QemuConsole
*con
,
1723 pixman_format_code_t format
)
1725 DisplayChangeListener
*dcl
;
1726 DisplayState
*s
= con
->ds
;
1728 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1729 if (dcl
->con
&& dcl
->con
!= con
) {
1730 /* dcl bound to another console -> skip */
1733 if (dcl
->ops
->dpy_gfx_check_format
) {
1734 if (!dcl
->ops
->dpy_gfx_check_format(dcl
, format
)) {
1738 /* default is to allow native 32 bpp only */
1739 if (format
!= qemu_default_pixman_format(32, true)) {
1747 static void dpy_refresh(DisplayState
*s
)
1749 DisplayChangeListener
*dcl
;
1751 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1752 if (dcl
->ops
->dpy_refresh
) {
1753 dcl
->ops
->dpy_refresh(dcl
);
1758 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1760 DisplayState
*s
= con
->ds
;
1761 DisplayChangeListener
*dcl
;
1763 if (!qemu_console_is_visible(con
)) {
1766 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1767 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1770 if (dcl
->ops
->dpy_text_cursor
) {
1771 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1776 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1778 DisplayState
*s
= con
->ds
;
1779 DisplayChangeListener
*dcl
;
1781 if (!qemu_console_is_visible(con
)) {
1784 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1785 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1788 if (dcl
->ops
->dpy_text_update
) {
1789 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1794 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1796 DisplayState
*s
= con
->ds
;
1797 DisplayChangeListener
*dcl
;
1799 if (!qemu_console_is_visible(con
)) {
1802 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1803 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1806 if (dcl
->ops
->dpy_text_resize
) {
1807 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1812 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1814 DisplayState
*s
= con
->ds
;
1815 DisplayChangeListener
*dcl
;
1817 if (!qemu_console_is_visible(con
)) {
1820 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1821 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1824 if (dcl
->ops
->dpy_mouse_set
) {
1825 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1830 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1832 DisplayState
*s
= con
->ds
;
1833 DisplayChangeListener
*dcl
;
1835 if (!qemu_console_is_visible(con
)) {
1838 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1839 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1842 if (dcl
->ops
->dpy_cursor_define
) {
1843 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1848 bool dpy_cursor_define_supported(QemuConsole
*con
)
1850 DisplayState
*s
= con
->ds
;
1851 DisplayChangeListener
*dcl
;
1853 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1854 if (dcl
->ops
->dpy_cursor_define
) {
1861 QEMUGLContext
dpy_gl_ctx_create(QemuConsole
*con
,
1862 struct QEMUGLParams
*qparams
)
1865 return con
->gl
->ops
->dpy_gl_ctx_create(con
->gl
, qparams
);
1868 void dpy_gl_ctx_destroy(QemuConsole
*con
, QEMUGLContext ctx
)
1871 con
->gl
->ops
->dpy_gl_ctx_destroy(con
->gl
, ctx
);
1874 int dpy_gl_ctx_make_current(QemuConsole
*con
, QEMUGLContext ctx
)
1877 return con
->gl
->ops
->dpy_gl_ctx_make_current(con
->gl
, ctx
);
1880 void dpy_gl_scanout_disable(QemuConsole
*con
)
1882 DisplayState
*s
= con
->ds
;
1883 DisplayChangeListener
*dcl
;
1885 if (con
->scanout
.kind
!= SCANOUT_SURFACE
) {
1886 con
->scanout
.kind
= SCANOUT_NONE
;
1888 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1889 if (dcl
->ops
->dpy_gl_scanout_disable
) {
1890 dcl
->ops
->dpy_gl_scanout_disable(dcl
);
1895 void dpy_gl_scanout_texture(QemuConsole
*con
,
1896 uint32_t backing_id
,
1897 bool backing_y_0_top
,
1898 uint32_t backing_width
,
1899 uint32_t backing_height
,
1900 uint32_t x
, uint32_t y
,
1901 uint32_t width
, uint32_t height
)
1903 DisplayState
*s
= con
->ds
;
1904 DisplayChangeListener
*dcl
;
1906 con
->scanout
.kind
= SCANOUT_TEXTURE
;
1907 con
->scanout
.texture
= (ScanoutTexture
) {
1908 backing_id
, backing_y_0_top
, backing_width
, backing_height
,
1911 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1912 if (dcl
->ops
->dpy_gl_scanout_texture
) {
1913 dcl
->ops
->dpy_gl_scanout_texture(dcl
, backing_id
,
1915 backing_width
, backing_height
,
1916 x
, y
, width
, height
);
1921 void dpy_gl_scanout_dmabuf(QemuConsole
*con
,
1924 DisplayState
*s
= con
->ds
;
1925 DisplayChangeListener
*dcl
;
1927 con
->scanout
.kind
= SCANOUT_DMABUF
;
1928 con
->scanout
.dmabuf
= dmabuf
;
1929 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1930 if (dcl
->ops
->dpy_gl_scanout_dmabuf
) {
1931 dcl
->ops
->dpy_gl_scanout_dmabuf(dcl
, dmabuf
);
1936 void dpy_gl_cursor_dmabuf(QemuConsole
*con
, QemuDmaBuf
*dmabuf
,
1937 bool have_hot
, uint32_t hot_x
, uint32_t hot_y
)
1939 DisplayState
*s
= con
->ds
;
1940 DisplayChangeListener
*dcl
;
1942 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1943 if (dcl
->ops
->dpy_gl_cursor_dmabuf
) {
1944 dcl
->ops
->dpy_gl_cursor_dmabuf(dcl
, dmabuf
,
1945 have_hot
, hot_x
, hot_y
);
1950 void dpy_gl_cursor_position(QemuConsole
*con
,
1951 uint32_t pos_x
, uint32_t pos_y
)
1953 DisplayState
*s
= con
->ds
;
1954 DisplayChangeListener
*dcl
;
1956 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1957 if (dcl
->ops
->dpy_gl_cursor_position
) {
1958 dcl
->ops
->dpy_gl_cursor_position(dcl
, pos_x
, pos_y
);
1963 void dpy_gl_release_dmabuf(QemuConsole
*con
,
1966 DisplayState
*s
= con
->ds
;
1967 DisplayChangeListener
*dcl
;
1969 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1970 if (dcl
->ops
->dpy_gl_release_dmabuf
) {
1971 dcl
->ops
->dpy_gl_release_dmabuf(dcl
, dmabuf
);
1976 void dpy_gl_update(QemuConsole
*con
,
1977 uint32_t x
, uint32_t y
, uint32_t w
, uint32_t h
)
1979 DisplayState
*s
= con
->ds
;
1980 DisplayChangeListener
*dcl
;
1984 graphic_hw_gl_block(con
, true);
1985 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1986 if (dcl
->ops
->dpy_gl_update
) {
1987 dcl
->ops
->dpy_gl_update(dcl
, x
, y
, w
, h
);
1990 graphic_hw_gl_block(con
, false);
1993 /***********************************************************/
1994 /* register display */
1996 /* console.c internal use only */
1997 static DisplayState
*get_alloc_displaystate(void)
1999 if (!display_state
) {
2000 display_state
= g_new0(DisplayState
, 1);
2001 cursor_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2002 text_console_update_cursor
, NULL
);
2004 return display_state
;
2008 * Called by main(), after creating QemuConsoles
2009 * and before initializing ui (sdl/vnc/...).
2011 DisplayState
*init_displaystate(void)
2016 get_alloc_displaystate();
2017 QTAILQ_FOREACH(con
, &consoles
, next
) {
2018 if (con
->console_type
!= GRAPHIC_CONSOLE
&&
2020 text_console_do_init(con
->chr
, display_state
);
2023 /* Hook up into the qom tree here (not in new_console()), once
2024 * all QemuConsoles are created and the order / numbering
2025 * doesn't change any more */
2026 name
= g_strdup_printf("console[%d]", con
->index
);
2027 object_property_add_child(container_get(object_get_root(), "/backend"),
2032 return display_state
;
2035 void graphic_console_set_hwops(QemuConsole
*con
,
2036 const GraphicHwOps
*hw_ops
,
2039 con
->hw_ops
= hw_ops
;
2043 QemuConsole
*graphic_console_init(DeviceState
*dev
, uint32_t head
,
2044 const GraphicHwOps
*hw_ops
,
2047 static const char noinit
[] =
2048 "Guest has not initialized the display (yet).";
2053 DisplaySurface
*surface
;
2055 ds
= get_alloc_displaystate();
2056 s
= qemu_console_lookup_unused();
2058 trace_console_gfx_reuse(s
->index
);
2059 width
= qemu_console_get_width(s
, 0);
2060 height
= qemu_console_get_height(s
, 0);
2062 trace_console_gfx_new();
2063 s
= new_console(ds
, GRAPHIC_CONSOLE
, head
);
2064 s
->ui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2065 dpy_set_ui_info_timer
, s
);
2067 graphic_console_set_hwops(s
, hw_ops
, opaque
);
2069 object_property_set_link(OBJECT(s
), "device", OBJECT(dev
),
2073 surface
= qemu_create_placeholder_surface(width
, height
, noinit
);
2074 dpy_gfx_replace_surface(s
, surface
);
2075 s
->gl_unblock_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
2076 graphic_hw_gl_unblock_timer
, s
);
2080 static const GraphicHwOps unused_ops
= {
2084 void graphic_console_close(QemuConsole
*con
)
2086 static const char unplugged
[] =
2087 "Guest display has been unplugged";
2088 DisplaySurface
*surface
;
2089 int width
= qemu_console_get_width(con
, 640);
2090 int height
= qemu_console_get_height(con
, 480);
2092 trace_console_gfx_close(con
->index
);
2093 object_property_set_link(OBJECT(con
), "device", NULL
, &error_abort
);
2094 graphic_console_set_hwops(con
, &unused_ops
, NULL
);
2097 dpy_gl_scanout_disable(con
);
2099 surface
= qemu_create_placeholder_surface(width
, height
, unplugged
);
2100 dpy_gfx_replace_surface(con
, surface
);
2103 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
2107 QTAILQ_FOREACH(con
, &consoles
, next
) {
2108 if (con
->index
== index
) {
2115 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
, uint32_t head
)
2121 QTAILQ_FOREACH(con
, &consoles
, next
) {
2122 obj
= object_property_get_link(OBJECT(con
),
2123 "device", &error_abort
);
2124 if (DEVICE(obj
) != dev
) {
2127 h
= object_property_get_uint(OBJECT(con
),
2128 "head", &error_abort
);
2137 QemuConsole
*qemu_console_lookup_by_device_name(const char *device_id
,
2138 uint32_t head
, Error
**errp
)
2143 dev
= qdev_find_recursive(sysbus_get_default(), device_id
);
2145 error_set(errp
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2146 "Device '%s' not found", device_id
);
2150 con
= qemu_console_lookup_by_device(dev
, head
);
2152 error_setg(errp
, "Device %s (head %d) is not bound to a QemuConsole",
2160 QemuConsole
*qemu_console_lookup_unused(void)
2165 QTAILQ_FOREACH(con
, &consoles
, next
) {
2166 if (con
->hw_ops
!= &unused_ops
) {
2169 obj
= object_property_get_link(OBJECT(con
),
2170 "device", &error_abort
);
2179 bool qemu_console_is_visible(QemuConsole
*con
)
2181 return (con
== active_console
) || (con
->dcls
> 0);
2184 bool qemu_console_is_graphic(QemuConsole
*con
)
2187 con
= active_console
;
2189 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
2192 bool qemu_console_is_fixedsize(QemuConsole
*con
)
2195 con
= active_console
;
2197 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
2200 bool qemu_console_is_gl_blocked(QemuConsole
*con
)
2202 assert(con
!= NULL
);
2203 return con
->gl_block
;
2206 char *qemu_console_get_label(QemuConsole
*con
)
2208 if (con
->console_type
== GRAPHIC_CONSOLE
) {
2210 return g_strdup(object_get_typename(con
->device
));
2212 return g_strdup("VGA");
2214 if (con
->chr
&& con
->chr
->label
) {
2215 return g_strdup(con
->chr
->label
);
2217 return g_strdup_printf("vc%d", con
->index
);
2221 int qemu_console_get_index(QemuConsole
*con
)
2224 con
= active_console
;
2226 return con
? con
->index
: -1;
2229 uint32_t qemu_console_get_head(QemuConsole
*con
)
2232 con
= active_console
;
2234 return con
? con
->head
: -1;
2237 int qemu_console_get_width(QemuConsole
*con
, int fallback
)
2240 con
= active_console
;
2245 switch (con
->scanout
.kind
) {
2246 case SCANOUT_DMABUF
:
2247 return con
->scanout
.dmabuf
->width
;
2248 case SCANOUT_TEXTURE
:
2249 return con
->scanout
.texture
.width
;
2250 case SCANOUT_SURFACE
:
2251 return surface_width(con
->surface
);
2257 int qemu_console_get_height(QemuConsole
*con
, int fallback
)
2260 con
= active_console
;
2265 switch (con
->scanout
.kind
) {
2266 case SCANOUT_DMABUF
:
2267 return con
->scanout
.dmabuf
->height
;
2268 case SCANOUT_TEXTURE
:
2269 return con
->scanout
.texture
.height
;
2270 case SCANOUT_SURFACE
:
2271 return surface_height(con
->surface
);
2277 static void vc_chr_accept_input(Chardev
*chr
)
2279 VCChardev
*drv
= VC_CHARDEV(chr
);
2280 QemuConsole
*s
= drv
->console
;
2285 static void vc_chr_set_echo(Chardev
*chr
, bool echo
)
2287 VCChardev
*drv
= VC_CHARDEV(chr
);
2288 QemuConsole
*s
= drv
->console
;
2293 static void text_console_update_cursor_timer(void)
2295 timer_mod(cursor_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
)
2296 + CONSOLE_CURSOR_PERIOD
/ 2);
2299 static void text_console_update_cursor(void *opaque
)
2304 cursor_visible_phase
= !cursor_visible_phase
;
2306 QTAILQ_FOREACH(s
, &consoles
, next
) {
2307 if (qemu_console_is_graphic(s
) ||
2308 !qemu_console_is_visible(s
)) {
2312 graphic_hw_invalidate(s
);
2316 text_console_update_cursor_timer();
2320 static const GraphicHwOps text_console_ops
= {
2321 .invalidate
= text_console_invalidate
,
2322 .text_update
= text_console_update
,
2325 static void text_console_do_init(Chardev
*chr
, DisplayState
*ds
)
2327 VCChardev
*drv
= VC_CHARDEV(chr
);
2328 QemuConsole
*s
= drv
->console
;
2329 int g_width
= 80 * FONT_WIDTH
;
2330 int g_height
= 24 * FONT_HEIGHT
;
2332 fifo8_create(&s
->out_fifo
, 16);
2337 s
->total_height
= DEFAULT_BACKSCROLL
;
2340 if (s
->scanout
.kind
!= SCANOUT_SURFACE
) {
2341 if (active_console
&& active_console
->scanout
.kind
== SCANOUT_SURFACE
) {
2342 g_width
= qemu_console_get_width(active_console
, g_width
);
2343 g_height
= qemu_console_get_height(active_console
, g_height
);
2345 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
2346 s
->scanout
.kind
= SCANOUT_SURFACE
;
2349 s
->hw_ops
= &text_console_ops
;
2352 /* Set text attribute defaults */
2353 s
->t_attrib_default
.bold
= 0;
2354 s
->t_attrib_default
.uline
= 0;
2355 s
->t_attrib_default
.blink
= 0;
2356 s
->t_attrib_default
.invers
= 0;
2357 s
->t_attrib_default
.unvisible
= 0;
2358 s
->t_attrib_default
.fgcol
= QEMU_COLOR_WHITE
;
2359 s
->t_attrib_default
.bgcol
= QEMU_COLOR_BLACK
;
2360 /* set current text attributes to default */
2361 s
->t_attrib
= s
->t_attrib_default
;
2362 text_console_resize(s
);
2367 s
->t_attrib
.bgcol
= QEMU_COLOR_BLUE
;
2368 msg
= g_strdup_printf("%s console\r\n", chr
->label
);
2369 vc_chr_write(chr
, (uint8_t *)msg
, strlen(msg
));
2371 s
->t_attrib
= s
->t_attrib_default
;
2374 qemu_chr_be_event(chr
, CHR_EVENT_OPENED
);
2377 static void vc_chr_open(Chardev
*chr
,
2378 ChardevBackend
*backend
,
2382 ChardevVC
*vc
= backend
->u
.vc
.data
;
2383 VCChardev
*drv
= VC_CHARDEV(chr
);
2386 unsigned height
= 0;
2388 if (vc
->has_width
) {
2390 } else if (vc
->has_cols
) {
2391 width
= vc
->cols
* FONT_WIDTH
;
2394 if (vc
->has_height
) {
2395 height
= vc
->height
;
2396 } else if (vc
->has_rows
) {
2397 height
= vc
->rows
* FONT_HEIGHT
;
2400 trace_console_txt_new(width
, height
);
2401 if (width
== 0 || height
== 0) {
2402 s
= new_console(NULL
, TEXT_CONSOLE
, 0);
2404 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
, 0);
2405 s
->scanout
.kind
= SCANOUT_SURFACE
;
2406 s
->surface
= qemu_create_displaysurface(width
, height
);
2410 error_setg(errp
, "cannot create text console");
2417 if (display_state
) {
2418 text_console_do_init(chr
, display_state
);
2421 /* console/chardev init sometimes completes elsewhere in a 2nd
2422 * stage, so defer OPENED events until they are fully initialized
2427 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
2429 DisplaySurface
*surface
;
2431 assert(s
->console_type
== GRAPHIC_CONSOLE
);
2433 if (qemu_console_get_width(s
, -1) == width
&&
2434 qemu_console_get_height(s
, -1) == height
) {
2438 surface
= qemu_create_displaysurface(width
, height
);
2439 dpy_gfx_replace_surface(s
, surface
);
2442 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
2444 switch (console
->scanout
.kind
) {
2445 case SCANOUT_SURFACE
:
2446 return console
->surface
;
2452 PixelFormat
qemu_default_pixelformat(int bpp
)
2454 pixman_format_code_t fmt
= qemu_default_pixman_format(bpp
, true);
2455 PixelFormat pf
= qemu_pixelformat_from_pixman(fmt
);
2459 static QemuDisplay
*dpys
[DISPLAY_TYPE__MAX
];
2461 void qemu_display_register(QemuDisplay
*ui
)
2463 assert(ui
->type
< DISPLAY_TYPE__MAX
);
2464 dpys
[ui
->type
] = ui
;
2467 bool qemu_display_find_default(DisplayOptions
*opts
)
2469 static DisplayType prio
[] = {
2470 #if defined(CONFIG_GTK)
2473 #if defined(CONFIG_SDL)
2476 #if defined(CONFIG_COCOA)
2482 for (i
= 0; i
< (int)ARRAY_SIZE(prio
); i
++) {
2483 if (dpys
[prio
[i
]] == NULL
) {
2484 ui_module_load_one(DisplayType_str(prio
[i
]));
2486 if (dpys
[prio
[i
]] == NULL
) {
2489 opts
->type
= prio
[i
];
2495 void qemu_display_early_init(DisplayOptions
*opts
)
2497 assert(opts
->type
< DISPLAY_TYPE__MAX
);
2498 if (opts
->type
== DISPLAY_TYPE_NONE
) {
2501 if (dpys
[opts
->type
] == NULL
) {
2502 ui_module_load_one(DisplayType_str(opts
->type
));
2504 if (dpys
[opts
->type
] == NULL
) {
2505 error_report("Display '%s' is not available.",
2506 DisplayType_str(opts
->type
));
2509 if (dpys
[opts
->type
]->early_init
) {
2510 dpys
[opts
->type
]->early_init(opts
);
2514 void qemu_display_init(DisplayState
*ds
, DisplayOptions
*opts
)
2516 assert(opts
->type
< DISPLAY_TYPE__MAX
);
2517 if (opts
->type
== DISPLAY_TYPE_NONE
) {
2520 assert(dpys
[opts
->type
] != NULL
);
2521 dpys
[opts
->type
]->init(ds
, opts
);
2524 void qemu_display_help(void)
2528 printf("Available display backend types:\n");
2530 for (idx
= DISPLAY_TYPE_NONE
; idx
< DISPLAY_TYPE__MAX
; idx
++) {
2532 ui_module_load_one(DisplayType_str(idx
));
2535 printf("%s\n", DisplayType_str(dpys
[idx
]->type
));
2540 void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
, Error
**errp
)
2545 backend
->type
= CHARDEV_BACKEND_KIND_VC
;
2546 vc
= backend
->u
.vc
.data
= g_new0(ChardevVC
, 1);
2547 qemu_chr_parse_common(opts
, qapi_ChardevVC_base(vc
));
2549 val
= qemu_opt_get_number(opts
, "width", 0);
2551 vc
->has_width
= true;
2555 val
= qemu_opt_get_number(opts
, "height", 0);
2557 vc
->has_height
= true;
2561 val
= qemu_opt_get_number(opts
, "cols", 0);
2563 vc
->has_cols
= true;
2567 val
= qemu_opt_get_number(opts
, "rows", 0);
2569 vc
->has_rows
= true;
2574 static const TypeInfo qemu_console_info
= {
2575 .name
= TYPE_QEMU_CONSOLE
,
2576 .parent
= TYPE_OBJECT
,
2577 .instance_size
= sizeof(QemuConsole
),
2578 .class_size
= sizeof(QemuConsoleClass
),
2581 static void char_vc_class_init(ObjectClass
*oc
, void *data
)
2583 ChardevClass
*cc
= CHARDEV_CLASS(oc
);
2585 cc
->parse
= qemu_chr_parse_vc
;
2586 cc
->open
= vc_chr_open
;
2587 cc
->chr_write
= vc_chr_write
;
2588 cc
->chr_accept_input
= vc_chr_accept_input
;
2589 cc
->chr_set_echo
= vc_chr_set_echo
;
2592 static const TypeInfo char_vc_type_info
= {
2593 .name
= TYPE_CHARDEV_VC
,
2594 .parent
= TYPE_CHARDEV
,
2595 .instance_size
= sizeof(VCChardev
),
2596 .class_init
= char_vc_class_init
,
2599 void qemu_console_early_init(void)
2601 /* set the default vc driver */
2602 if (!object_class_by_name(TYPE_CHARDEV_VC
)) {
2603 type_register(&char_vc_type_info
);
2607 static void register_types(void)
2609 type_register_static(&qemu_console_info
);
2612 type_init(register_types
);