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
24 #include "qemu-common.h"
25 #include "ui/console.h"
26 #include "hw/qdev-core.h"
27 #include "qemu/timer.h"
28 #include "qmp-commands.h"
29 #include "sysemu/char.h"
32 #define DEFAULT_BACKSCROLL 512
33 #define CONSOLE_CURSOR_PERIOD 500
35 typedef struct TextAttributes
{
45 typedef struct TextCell
{
47 TextAttributes t_attrib
;
50 #define MAX_ESC_PARAMS 3
58 typedef struct QEMUFIFO
{
61 int count
, wptr
, rptr
;
64 static int qemu_fifo_write(QEMUFIFO
*f
, const uint8_t *buf
, int len1
)
68 l
= f
->buf_size
- f
->count
;
73 l
= f
->buf_size
- f
->wptr
;
76 memcpy(f
->buf
+ f
->wptr
, buf
, l
);
78 if (f
->wptr
>= f
->buf_size
)
87 static int qemu_fifo_read(QEMUFIFO
*f
, uint8_t *buf
, int len1
)
95 l
= f
->buf_size
- f
->rptr
;
98 memcpy(buf
, f
->buf
+ f
->rptr
, l
);
100 if (f
->rptr
>= f
->buf_size
)
112 TEXT_CONSOLE_FIXED_SIZE
119 console_type_t console_type
;
121 DisplaySurface
*surface
;
124 /* Graphic console state. */
128 const GraphicHwOps
*hw_ops
;
131 /* Text console state */
135 int backscroll_height
;
137 int x_saved
, y_saved
;
140 TextAttributes t_attrib_default
; /* default text attributes */
141 TextAttributes t_attrib
; /* currently active text attributes */
143 int text_x
[2], text_y
[2], cursor_invalidate
;
152 int esc_params
[MAX_ESC_PARAMS
];
155 CharDriverState
*chr
;
156 /* fifo for key pressed */
158 uint8_t out_fifo_buf
[16];
159 QEMUTimer
*kbd_timer
;
162 struct DisplayState
{
163 QEMUTimer
*gui_timer
;
164 uint64_t last_update
;
165 uint64_t update_interval
;
170 QLIST_HEAD(, DisplayChangeListener
) listeners
;
173 static DisplayState
*display_state
;
174 static QemuConsole
*active_console
;
175 static QemuConsole
**consoles
;
176 static int nb_consoles
= 0;
177 static bool cursor_visible_phase
;
178 static QEMUTimer
*cursor_timer
;
180 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
);
181 static void dpy_refresh(DisplayState
*s
);
182 static DisplayState
*get_alloc_displaystate(void);
183 static void text_console_update_cursor_timer(void);
184 static void text_console_update_cursor(void *opaque
);
186 static void gui_update(void *opaque
)
188 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
189 uint64_t dcl_interval
;
190 DisplayState
*ds
= opaque
;
191 DisplayChangeListener
*dcl
;
194 ds
->refreshing
= true;
196 ds
->refreshing
= false;
198 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
199 dcl_interval
= dcl
->update_interval
?
200 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
201 if (interval
> dcl_interval
) {
202 interval
= dcl_interval
;
205 if (ds
->update_interval
!= interval
) {
206 ds
->update_interval
= interval
;
207 for (i
= 0; i
< nb_consoles
; i
++) {
208 if (consoles
[i
]->hw_ops
->update_interval
) {
209 consoles
[i
]->hw_ops
->update_interval(consoles
[i
]->hw
, interval
);
212 trace_console_refresh(interval
);
214 ds
->last_update
= qemu_clock_get_ms(QEMU_CLOCK_REALTIME
);
215 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
218 static void gui_setup_refresh(DisplayState
*ds
)
220 DisplayChangeListener
*dcl
;
221 bool need_timer
= false;
222 bool have_gfx
= false;
223 bool have_text
= false;
225 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
226 if (dcl
->ops
->dpy_refresh
!= NULL
) {
229 if (dcl
->ops
->dpy_gfx_update
!= NULL
) {
232 if (dcl
->ops
->dpy_text_update
!= NULL
) {
237 if (need_timer
&& ds
->gui_timer
== NULL
) {
238 ds
->gui_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, gui_update
, ds
);
239 timer_mod(ds
->gui_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
241 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
242 timer_del(ds
->gui_timer
);
243 timer_free(ds
->gui_timer
);
244 ds
->gui_timer
= NULL
;
247 ds
->have_gfx
= have_gfx
;
248 ds
->have_text
= have_text
;
251 void graphic_hw_update(QemuConsole
*con
)
254 con
= active_console
;
256 if (con
&& con
->hw_ops
->gfx_update
) {
257 con
->hw_ops
->gfx_update(con
->hw
);
261 void graphic_hw_invalidate(QemuConsole
*con
)
264 con
= active_console
;
266 if (con
&& con
->hw_ops
->invalidate
) {
267 con
->hw_ops
->invalidate(con
->hw
);
271 static void ppm_save(const char *filename
, struct DisplaySurface
*ds
,
274 int width
= pixman_image_get_width(ds
->image
);
275 int height
= pixman_image_get_height(ds
->image
);
280 pixman_image_t
*linebuf
;
282 trace_ppm_save(filename
, ds
);
283 fd
= qemu_open(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, 0666);
285 error_setg(errp
, "failed to open file '%s': %s", filename
,
289 f
= fdopen(fd
, "wb");
290 ret
= fprintf(f
, "P6\n%d %d\n%d\n", width
, height
, 255);
295 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
296 for (y
= 0; y
< height
; y
++) {
297 qemu_pixman_linebuf_fill(linebuf
, ds
->image
, width
, 0, y
);
299 ret
= fwrite(pixman_image_get_data(linebuf
), 1,
300 pixman_image_get_stride(linebuf
), f
);
308 qemu_pixman_image_unref(linebuf
);
313 error_setg(errp
, "failed to write to file '%s': %s", filename
,
319 void qmp_screendump(const char *filename
, Error
**errp
)
321 QemuConsole
*con
= qemu_console_lookup_by_index(0);
322 DisplaySurface
*surface
;
325 error_setg(errp
, "There is no QemuConsole I can screendump from.");
329 graphic_hw_update(con
);
330 surface
= qemu_console_surface(con
);
331 ppm_save(filename
, surface
, errp
);
334 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
337 con
= active_console
;
339 if (con
&& con
->hw_ops
->text_update
) {
340 con
->hw_ops
->text_update(con
->hw
, chardata
);
344 static void vga_fill_rect(QemuConsole
*con
,
345 int posx
, int posy
, int width
, int height
,
346 pixman_color_t color
)
348 DisplaySurface
*surface
= qemu_console_surface(con
);
349 pixman_rectangle16_t rect
= {
350 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
353 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
357 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
358 static void vga_bitblt(QemuConsole
*con
,
359 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
361 DisplaySurface
*surface
= qemu_console_surface(con
);
363 pixman_image_composite(PIXMAN_OP_SRC
,
364 surface
->image
, NULL
, surface
->image
,
365 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
368 /***********************************************************/
369 /* basic char display */
371 #define FONT_HEIGHT 16
376 #ifndef CONFIG_CURSES
389 #define QEMU_RGB(r, g, b) \
390 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
392 static const pixman_color_t color_table_rgb
[2][8] = {
394 QEMU_RGB(0x00, 0x00, 0x00), /* black */
395 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
396 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
397 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
398 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
399 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
400 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
401 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
404 QEMU_RGB(0x00, 0x00, 0x00), /* black */
405 QEMU_RGB(0xff, 0x00, 0x00), /* red */
406 QEMU_RGB(0x00, 0xff, 0x00), /* green */
407 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
408 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
409 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
410 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
411 QEMU_RGB(0xff, 0xff, 0xff), /* white */
415 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
416 TextAttributes
*t_attrib
)
418 static pixman_image_t
*glyphs
[256];
419 DisplaySurface
*surface
= qemu_console_surface(s
);
420 pixman_color_t fgcol
, bgcol
;
422 if (t_attrib
->invers
) {
423 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
424 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
426 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
427 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
431 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
433 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
434 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
437 static void text_console_resize(QemuConsole
*s
)
439 TextCell
*cells
, *c
, *c1
;
440 int w1
, x
, y
, last_width
;
442 last_width
= s
->width
;
443 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
444 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
450 cells
= g_malloc(s
->width
* s
->total_height
* sizeof(TextCell
));
451 for(y
= 0; y
< s
->total_height
; y
++) {
452 c
= &cells
[y
* s
->width
];
454 c1
= &s
->cells
[y
* last_width
];
455 for(x
= 0; x
< w1
; x
++) {
459 for(x
= w1
; x
< s
->width
; x
++) {
461 c
->t_attrib
= s
->t_attrib_default
;
469 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
471 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
472 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
473 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
474 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
477 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
479 if (!qemu_console_is_visible(s
)) {
482 if (s
->update_x0
> x
* FONT_WIDTH
)
483 s
->update_x0
= x
* FONT_WIDTH
;
484 if (s
->update_y0
> y
* FONT_HEIGHT
)
485 s
->update_y0
= y
* FONT_HEIGHT
;
486 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
487 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
488 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
489 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
492 static void update_xy(QemuConsole
*s
, int x
, int y
)
497 if (s
->ds
->have_text
) {
498 text_update_xy(s
, x
, y
);
501 y1
= (s
->y_base
+ y
) % s
->total_height
;
502 y2
= y1
- s
->y_displayed
;
504 y2
+= s
->total_height
;
506 if (y2
< s
->height
) {
507 c
= &s
->cells
[y1
* s
->width
+ x
];
508 vga_putcharxy(s
, x
, y2
, c
->ch
,
510 invalidate_xy(s
, x
, y2
);
514 static void console_show_cursor(QemuConsole
*s
, int show
)
520 if (s
->ds
->have_text
) {
521 s
->cursor_invalidate
= 1;
527 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
528 y
= y1
- s
->y_displayed
;
530 y
+= s
->total_height
;
533 c
= &s
->cells
[y1
* s
->width
+ x
];
534 if (show
&& cursor_visible_phase
) {
535 TextAttributes t_attrib
= s
->t_attrib_default
;
536 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
537 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
539 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
541 invalidate_xy(s
, x
, y
);
545 static void console_refresh(QemuConsole
*s
)
547 DisplaySurface
*surface
= qemu_console_surface(s
);
551 if (s
->ds
->have_text
) {
554 s
->text_x
[1] = s
->width
- 1;
555 s
->text_y
[1] = s
->height
- 1;
556 s
->cursor_invalidate
= 1;
559 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
560 color_table_rgb
[0][COLOR_BLACK
]);
562 for (y
= 0; y
< s
->height
; y
++) {
563 c
= s
->cells
+ y1
* s
->width
;
564 for (x
= 0; x
< s
->width
; x
++) {
565 vga_putcharxy(s
, x
, y
, c
->ch
,
569 if (++y1
== s
->total_height
) {
573 console_show_cursor(s
, 1);
574 dpy_gfx_update(s
, 0, 0,
575 surface_width(surface
), surface_height(surface
));
578 static void console_scroll(QemuConsole
*s
, int ydelta
)
583 for(i
= 0; i
< ydelta
; i
++) {
584 if (s
->y_displayed
== s
->y_base
)
586 if (++s
->y_displayed
== s
->total_height
)
591 i
= s
->backscroll_height
;
592 if (i
> s
->total_height
- s
->height
)
593 i
= s
->total_height
- s
->height
;
596 y1
+= s
->total_height
;
597 for(i
= 0; i
< ydelta
; i
++) {
598 if (s
->y_displayed
== y1
)
600 if (--s
->y_displayed
< 0)
601 s
->y_displayed
= s
->total_height
- 1;
607 static void console_put_lf(QemuConsole
*s
)
613 if (s
->y
>= s
->height
) {
614 s
->y
= s
->height
- 1;
616 if (s
->y_displayed
== s
->y_base
) {
617 if (++s
->y_displayed
== s
->total_height
)
620 if (++s
->y_base
== s
->total_height
)
622 if (s
->backscroll_height
< s
->total_height
)
623 s
->backscroll_height
++;
624 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
625 c
= &s
->cells
[y1
* s
->width
];
626 for(x
= 0; x
< s
->width
; x
++) {
628 c
->t_attrib
= s
->t_attrib_default
;
631 if (s
->y_displayed
== s
->y_base
) {
632 if (s
->ds
->have_text
) {
635 s
->text_x
[1] = s
->width
- 1;
636 s
->text_y
[1] = s
->height
- 1;
639 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
640 s
->width
* FONT_WIDTH
,
641 (s
->height
- 1) * FONT_HEIGHT
);
642 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
643 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
644 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
647 s
->update_x1
= s
->width
* FONT_WIDTH
;
648 s
->update_y1
= s
->height
* FONT_HEIGHT
;
653 /* Set console attributes depending on the current escape codes.
654 * NOTE: I know this code is not very efficient (checking every color for it
655 * self) but it is more readable and better maintainable.
657 static void console_handle_escape(QemuConsole
*s
)
661 for (i
=0; i
<s
->nb_esc_params
; i
++) {
662 switch (s
->esc_params
[i
]) {
663 case 0: /* reset all console attributes to default */
664 s
->t_attrib
= s
->t_attrib_default
;
667 s
->t_attrib
.bold
= 1;
670 s
->t_attrib
.uline
= 1;
673 s
->t_attrib
.blink
= 1;
676 s
->t_attrib
.invers
= 1;
679 s
->t_attrib
.unvisible
= 1;
682 s
->t_attrib
.bold
= 0;
685 s
->t_attrib
.uline
= 0;
688 s
->t_attrib
.blink
= 0;
691 s
->t_attrib
.invers
= 0;
694 s
->t_attrib
.unvisible
= 0;
696 /* set foreground color */
698 s
->t_attrib
.fgcol
=COLOR_BLACK
;
701 s
->t_attrib
.fgcol
=COLOR_RED
;
704 s
->t_attrib
.fgcol
=COLOR_GREEN
;
707 s
->t_attrib
.fgcol
=COLOR_YELLOW
;
710 s
->t_attrib
.fgcol
=COLOR_BLUE
;
713 s
->t_attrib
.fgcol
=COLOR_MAGENTA
;
716 s
->t_attrib
.fgcol
=COLOR_CYAN
;
719 s
->t_attrib
.fgcol
=COLOR_WHITE
;
721 /* set background color */
723 s
->t_attrib
.bgcol
=COLOR_BLACK
;
726 s
->t_attrib
.bgcol
=COLOR_RED
;
729 s
->t_attrib
.bgcol
=COLOR_GREEN
;
732 s
->t_attrib
.bgcol
=COLOR_YELLOW
;
735 s
->t_attrib
.bgcol
=COLOR_BLUE
;
738 s
->t_attrib
.bgcol
=COLOR_MAGENTA
;
741 s
->t_attrib
.bgcol
=COLOR_CYAN
;
744 s
->t_attrib
.bgcol
=COLOR_WHITE
;
750 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
752 int y1
= (s
->y_base
+ y
) % s
->total_height
;
753 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
755 c
->t_attrib
= s
->t_attrib_default
;
759 /* set cursor, checking bounds */
760 static void set_cursor(QemuConsole
*s
, int x
, int y
)
768 if (y
>= s
->height
) {
779 static void console_putchar(QemuConsole
*s
, int ch
)
788 case '\r': /* carriage return */
791 case '\n': /* newline */
794 case '\b': /* backspace */
798 case '\t': /* tabspace */
799 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
803 s
->x
= s
->x
+ (8 - (s
->x
% 8));
806 case '\a': /* alert aka. bell */
807 /* TODO: has to be implemented */
810 /* SI (shift in), character set 0 (ignored) */
813 /* SO (shift out), character set 1 (ignored) */
815 case 27: /* esc (introducing an escape sequence) */
816 s
->state
= TTY_STATE_ESC
;
819 if (s
->x
>= s
->width
) {
824 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
825 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
827 c
->t_attrib
= s
->t_attrib
;
828 update_xy(s
, s
->x
, s
->y
);
833 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
835 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
836 s
->esc_params
[i
] = 0;
837 s
->nb_esc_params
= 0;
838 s
->state
= TTY_STATE_CSI
;
840 s
->state
= TTY_STATE_NORM
;
843 case TTY_STATE_CSI
: /* handle escape sequence parameters */
844 if (ch
>= '0' && ch
<= '9') {
845 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
846 int *param
= &s
->esc_params
[s
->nb_esc_params
];
847 int digit
= (ch
- '0');
849 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
850 *param
* 10 + digit
: INT_MAX
;
853 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
857 trace_console_putchar_csi(s
->esc_params
[0], s
->esc_params
[1],
858 ch
, s
->nb_esc_params
);
859 s
->state
= TTY_STATE_NORM
;
863 if (s
->esc_params
[0] == 0) {
864 s
->esc_params
[0] = 1;
866 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
869 /* move cursor down */
870 if (s
->esc_params
[0] == 0) {
871 s
->esc_params
[0] = 1;
873 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
876 /* move cursor right */
877 if (s
->esc_params
[0] == 0) {
878 s
->esc_params
[0] = 1;
880 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
883 /* move cursor left */
884 if (s
->esc_params
[0] == 0) {
885 s
->esc_params
[0] = 1;
887 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
890 /* move cursor to column */
891 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
895 /* move cursor to row, column */
896 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
899 switch (s
->esc_params
[0]) {
901 /* clear to end of screen */
902 for (y
= s
->y
; y
< s
->height
; y
++) {
903 for (x
= 0; x
< s
->width
; x
++) {
904 if (y
== s
->y
&& x
< s
->x
) {
907 console_clear_xy(s
, x
, y
);
912 /* clear from beginning of screen */
913 for (y
= 0; y
<= s
->y
; y
++) {
914 for (x
= 0; x
< s
->width
; x
++) {
915 if (y
== s
->y
&& x
> s
->x
) {
918 console_clear_xy(s
, x
, y
);
923 /* clear entire screen */
924 for (y
= 0; y
<= s
->height
; y
++) {
925 for (x
= 0; x
< s
->width
; x
++) {
926 console_clear_xy(s
, x
, y
);
933 switch (s
->esc_params
[0]) {
936 for(x
= s
->x
; x
< s
->width
; x
++) {
937 console_clear_xy(s
, x
, s
->y
);
941 /* clear from beginning of line */
942 for (x
= 0; x
<= s
->x
; x
++) {
943 console_clear_xy(s
, x
, s
->y
);
947 /* clear entire line */
948 for(x
= 0; x
< s
->width
; x
++) {
949 console_clear_xy(s
, x
, s
->y
);
955 console_handle_escape(s
);
958 /* report cursor position */
959 /* TODO: send ESC[row;colR */
962 /* save cursor position */
967 /* restore cursor position */
972 trace_console_putchar_unhandled(ch
);
980 void console_select(unsigned int index
)
982 DisplayChangeListener
*dcl
;
985 trace_console_select(index
);
986 s
= qemu_console_lookup_by_index(index
);
988 DisplayState
*ds
= s
->ds
;
992 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
993 if (dcl
->con
!= NULL
) {
996 if (dcl
->ops
->dpy_gfx_switch
) {
997 dcl
->ops
->dpy_gfx_switch(dcl
, s
->surface
);
1000 dpy_gfx_update(s
, 0, 0, surface_width(s
->surface
),
1001 surface_height(s
->surface
));
1003 if (ds
->have_text
) {
1004 dpy_text_resize(s
, s
->width
, s
->height
);
1006 text_console_update_cursor(NULL
);
1010 static int console_puts(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1012 QemuConsole
*s
= chr
->opaque
;
1015 s
->update_x0
= s
->width
* FONT_WIDTH
;
1016 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1019 console_show_cursor(s
, 0);
1020 for(i
= 0; i
< len
; i
++) {
1021 console_putchar(s
, buf
[i
]);
1023 console_show_cursor(s
, 1);
1024 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1025 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1026 s
->update_x1
- s
->update_x0
,
1027 s
->update_y1
- s
->update_y0
);
1032 static void kbd_send_chars(void *opaque
)
1034 QemuConsole
*s
= opaque
;
1038 len
= qemu_chr_be_can_write(s
->chr
);
1039 if (len
> s
->out_fifo
.count
)
1040 len
= s
->out_fifo
.count
;
1042 if (len
> sizeof(buf
))
1044 qemu_fifo_read(&s
->out_fifo
, buf
, len
);
1045 qemu_chr_be_write(s
->chr
, buf
, len
);
1047 /* characters are pending: we send them a bit later (XXX:
1048 horrible, should change char device API) */
1049 if (s
->out_fifo
.count
> 0) {
1050 timer_mod(s
->kbd_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1);
1054 /* called when an ascii key is pressed */
1055 void kbd_put_keysym_console(QemuConsole
*s
, int keysym
)
1057 uint8_t buf
[16], *q
;
1060 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1064 case QEMU_KEY_CTRL_UP
:
1065 console_scroll(s
, -1);
1067 case QEMU_KEY_CTRL_DOWN
:
1068 console_scroll(s
, 1);
1070 case QEMU_KEY_CTRL_PAGEUP
:
1071 console_scroll(s
, -10);
1073 case QEMU_KEY_CTRL_PAGEDOWN
:
1074 console_scroll(s
, 10);
1077 /* convert the QEMU keysym to VT100 key string */
1079 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1082 c
= keysym
- 0xe100;
1084 *q
++ = '0' + (c
/ 10);
1085 *q
++ = '0' + (c
% 10);
1087 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1090 *q
++ = keysym
& 0xff;
1091 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1092 console_puts(s
->chr
, (const uint8_t *) "\r", 1);
1098 console_puts(s
->chr
, buf
, q
- buf
);
1100 if (s
->chr
->chr_read
) {
1101 qemu_fifo_write(&s
->out_fifo
, buf
, q
- buf
);
1108 static const int qcode_to_keysym
[Q_KEY_CODE_MAX
] = {
1109 [Q_KEY_CODE_UP
] = QEMU_KEY_UP
,
1110 [Q_KEY_CODE_DOWN
] = QEMU_KEY_DOWN
,
1111 [Q_KEY_CODE_RIGHT
] = QEMU_KEY_RIGHT
,
1112 [Q_KEY_CODE_LEFT
] = QEMU_KEY_LEFT
,
1113 [Q_KEY_CODE_HOME
] = QEMU_KEY_HOME
,
1114 [Q_KEY_CODE_END
] = QEMU_KEY_END
,
1115 [Q_KEY_CODE_PGUP
] = QEMU_KEY_PAGEUP
,
1116 [Q_KEY_CODE_PGDN
] = QEMU_KEY_PAGEDOWN
,
1117 [Q_KEY_CODE_DELETE
] = QEMU_KEY_DELETE
,
1120 bool kbd_put_qcode_console(QemuConsole
*s
, int qcode
)
1124 keysym
= qcode_to_keysym
[qcode
];
1128 kbd_put_keysym_console(s
, keysym
);
1132 void kbd_put_string_console(QemuConsole
*s
, const char *str
, int len
)
1136 for (i
= 0; i
< len
&& str
[i
]; i
++) {
1137 kbd_put_keysym_console(s
, str
[i
]);
1141 void kbd_put_keysym(int keysym
)
1143 kbd_put_keysym_console(active_console
, keysym
);
1146 static void text_console_invalidate(void *opaque
)
1148 QemuConsole
*s
= (QemuConsole
*) opaque
;
1150 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1151 text_console_resize(s
);
1156 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1158 QemuConsole
*s
= (QemuConsole
*) opaque
;
1161 if (s
->text_x
[0] <= s
->text_x
[1]) {
1162 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1163 chardata
+= s
->text_y
[0] * s
->width
;
1164 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1165 for (j
= 0; j
< s
->width
; j
++, src
++)
1166 console_write_ch(chardata
++, s
->cells
[src
].ch
|
1167 (s
->cells
[src
].t_attrib
.fgcol
<< 12) |
1168 (s
->cells
[src
].t_attrib
.bgcol
<< 8) |
1169 (s
->cells
[src
].t_attrib
.bold
<< 21));
1170 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1171 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1172 s
->text_x
[0] = s
->width
;
1173 s
->text_y
[0] = s
->height
;
1177 if (s
->cursor_invalidate
) {
1178 dpy_text_cursor(s
, s
->x
, s
->y
);
1179 s
->cursor_invalidate
= 0;
1183 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
,
1190 obj
= object_new(TYPE_QEMU_CONSOLE
);
1191 s
= QEMU_CONSOLE(obj
);
1193 object_property_add_link(obj
, "device", TYPE_DEVICE
,
1194 (Object
**)&s
->device
,
1195 object_property_allow_set_link
,
1196 OBJ_PROP_LINK_UNREF_ON_RELEASE
,
1198 object_property_add_uint32_ptr(obj
, "head",
1199 &s
->head
, &error_abort
);
1201 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1202 (console_type
== GRAPHIC_CONSOLE
))) {
1206 s
->console_type
= console_type
;
1208 consoles
= g_realloc(consoles
, sizeof(*consoles
) * (nb_consoles
+1));
1209 if (console_type
!= GRAPHIC_CONSOLE
) {
1210 s
->index
= nb_consoles
;
1211 consoles
[nb_consoles
++] = s
;
1213 /* HACK: Put graphical consoles before text consoles. */
1214 for (i
= nb_consoles
; i
> 0; i
--) {
1215 if (consoles
[i
- 1]->console_type
== GRAPHIC_CONSOLE
)
1217 consoles
[i
] = consoles
[i
- 1];
1218 consoles
[i
]->index
= i
;
1227 static void qemu_alloc_display(DisplaySurface
*surface
, int width
, int height
)
1229 qemu_pixman_image_unref(surface
->image
);
1230 surface
->image
= NULL
;
1232 surface
->format
= PIXMAN_x8r8g8b8
;
1233 surface
->image
= pixman_image_create_bits(surface
->format
,
1236 assert(surface
->image
!= NULL
);
1238 surface
->flags
= QEMU_ALLOCATED_FLAG
;
1239 #ifdef HOST_WORDS_BIGENDIAN
1240 surface
->flags
|= QEMU_BIG_ENDIAN_FLAG
;
1244 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1246 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1248 trace_displaysurface_create(surface
, width
, height
);
1249 qemu_alloc_display(surface
, width
, height
);
1253 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
,
1254 pixman_format_code_t format
,
1255 int linesize
, uint8_t *data
)
1257 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1259 trace_displaysurface_create_from(surface
, width
, height
, format
);
1260 surface
->format
= format
;
1261 surface
->image
= pixman_image_create_bits(surface
->format
,
1263 (void *)data
, linesize
);
1264 assert(surface
->image
!= NULL
);
1266 #ifdef HOST_WORDS_BIGENDIAN
1267 surface
->flags
= QEMU_BIG_ENDIAN_FLAG
;
1273 static DisplaySurface
*qemu_create_message_surface(int w
, int h
,
1276 DisplaySurface
*surface
= qemu_create_displaysurface(w
, h
);
1277 pixman_color_t bg
= color_table_rgb
[0][COLOR_BLACK
];
1278 pixman_color_t fg
= color_table_rgb
[0][COLOR_WHITE
];
1279 pixman_image_t
*glyph
;
1283 x
= (w
/ FONT_WIDTH
- len
) / 2;
1284 y
= (h
/ FONT_HEIGHT
- 1) / 2;
1285 for (i
= 0; i
< len
; i
++) {
1286 glyph
= qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, msg
[i
]);
1287 qemu_pixman_glyph_render(glyph
, surface
->image
, &fg
, &bg
,
1288 x
+i
, y
, FONT_WIDTH
, FONT_HEIGHT
);
1289 qemu_pixman_image_unref(glyph
);
1294 void qemu_free_displaysurface(DisplaySurface
*surface
)
1296 if (surface
== NULL
) {
1299 trace_displaysurface_free(surface
);
1300 qemu_pixman_image_unref(surface
->image
);
1304 void register_displaychangelistener(DisplayChangeListener
*dcl
)
1306 static const char nodev
[] =
1307 "This VM has no graphic display device.";
1308 static DisplaySurface
*dummy
;
1311 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1312 dcl
->ds
= get_alloc_displaystate();
1313 QLIST_INSERT_HEAD(&dcl
->ds
->listeners
, dcl
, next
);
1314 gui_setup_refresh(dcl
->ds
);
1319 con
= active_console
;
1321 if (dcl
->ops
->dpy_gfx_switch
) {
1323 dcl
->ops
->dpy_gfx_switch(dcl
, con
->surface
);
1326 dummy
= qemu_create_message_surface(640, 480, nodev
);
1328 dcl
->ops
->dpy_gfx_switch(dcl
, dummy
);
1331 text_console_update_cursor(NULL
);
1334 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1337 DisplayState
*ds
= dcl
->ds
;
1339 dcl
->update_interval
= interval
;
1340 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1341 timer_mod(ds
->gui_timer
, ds
->last_update
+ interval
);
1345 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1347 DisplayState
*ds
= dcl
->ds
;
1348 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1352 QLIST_REMOVE(dcl
, next
);
1353 gui_setup_refresh(ds
);
1356 int dpy_set_ui_info(QemuConsole
*con
, QemuUIInfo
*info
)
1358 assert(con
!= NULL
);
1359 con
->ui_info
= *info
;
1360 if (con
->hw_ops
->ui_info
) {
1361 return con
->hw_ops
->ui_info(con
->hw
, con
->head
, info
);
1366 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1368 DisplayState
*s
= con
->ds
;
1369 DisplayChangeListener
*dcl
;
1370 int width
= surface_width(con
->surface
);
1371 int height
= surface_height(con
->surface
);
1377 w
= MIN(w
, width
- x
);
1378 h
= MIN(h
, height
- y
);
1380 if (!qemu_console_is_visible(con
)) {
1383 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1384 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1387 if (dcl
->ops
->dpy_gfx_update
) {
1388 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1393 void dpy_gfx_replace_surface(QemuConsole
*con
,
1394 DisplaySurface
*surface
)
1396 DisplayState
*s
= con
->ds
;
1397 DisplaySurface
*old_surface
= con
->surface
;
1398 DisplayChangeListener
*dcl
;
1400 con
->surface
= surface
;
1401 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1402 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1405 if (dcl
->ops
->dpy_gfx_switch
) {
1406 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1409 qemu_free_displaysurface(old_surface
);
1412 static void dpy_refresh(DisplayState
*s
)
1414 DisplayChangeListener
*dcl
;
1416 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1417 if (dcl
->ops
->dpy_refresh
) {
1418 dcl
->ops
->dpy_refresh(dcl
);
1423 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
1424 int dst_x
, int dst_y
, int w
, int h
)
1426 DisplayState
*s
= con
->ds
;
1427 DisplayChangeListener
*dcl
;
1429 if (!qemu_console_is_visible(con
)) {
1432 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1433 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1436 if (dcl
->ops
->dpy_gfx_copy
) {
1437 dcl
->ops
->dpy_gfx_copy(dcl
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1439 dcl
->ops
->dpy_gfx_update(dcl
, dst_x
, dst_y
, w
, h
);
1444 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1446 DisplayState
*s
= con
->ds
;
1447 DisplayChangeListener
*dcl
;
1449 if (!qemu_console_is_visible(con
)) {
1452 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1453 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1456 if (dcl
->ops
->dpy_text_cursor
) {
1457 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1462 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1464 DisplayState
*s
= con
->ds
;
1465 DisplayChangeListener
*dcl
;
1467 if (!qemu_console_is_visible(con
)) {
1470 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1471 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1474 if (dcl
->ops
->dpy_text_update
) {
1475 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1480 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1482 DisplayState
*s
= con
->ds
;
1483 struct DisplayChangeListener
*dcl
;
1485 if (!qemu_console_is_visible(con
)) {
1488 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1489 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1492 if (dcl
->ops
->dpy_text_resize
) {
1493 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1498 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1500 DisplayState
*s
= con
->ds
;
1501 DisplayChangeListener
*dcl
;
1503 if (!qemu_console_is_visible(con
)) {
1506 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1507 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1510 if (dcl
->ops
->dpy_mouse_set
) {
1511 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1516 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1518 DisplayState
*s
= con
->ds
;
1519 DisplayChangeListener
*dcl
;
1521 if (!qemu_console_is_visible(con
)) {
1524 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1525 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1528 if (dcl
->ops
->dpy_cursor_define
) {
1529 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1534 bool dpy_cursor_define_supported(QemuConsole
*con
)
1536 DisplayState
*s
= con
->ds
;
1537 DisplayChangeListener
*dcl
;
1539 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1540 if (dcl
->ops
->dpy_cursor_define
) {
1547 /***********************************************************/
1548 /* register display */
1550 /* console.c internal use only */
1551 static DisplayState
*get_alloc_displaystate(void)
1553 if (!display_state
) {
1554 display_state
= g_new0(DisplayState
, 1);
1555 cursor_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
,
1556 text_console_update_cursor
, NULL
);
1558 return display_state
;
1562 * Called by main(), after creating QemuConsoles
1563 * and before initializing ui (sdl/vnc/...).
1565 DisplayState
*init_displaystate(void)
1570 get_alloc_displaystate();
1571 for (i
= 0; i
< nb_consoles
; i
++) {
1572 if (consoles
[i
]->console_type
!= GRAPHIC_CONSOLE
&&
1573 consoles
[i
]->ds
== NULL
) {
1574 text_console_do_init(consoles
[i
]->chr
, display_state
);
1577 /* Hook up into the qom tree here (not in new_console()), once
1578 * all QemuConsoles are created and the order / numbering
1579 * doesn't change any more */
1580 name
= g_strdup_printf("console[%d]", i
);
1581 object_property_add_child(container_get(object_get_root(), "/backend"),
1582 name
, OBJECT(consoles
[i
]), &error_abort
);
1586 return display_state
;
1589 QemuConsole
*graphic_console_init(DeviceState
*dev
, uint32_t head
,
1590 const GraphicHwOps
*hw_ops
,
1593 static const char noinit
[] =
1594 "Guest has not initialized the display (yet).";
1600 ds
= get_alloc_displaystate();
1601 trace_console_gfx_new();
1602 s
= new_console(ds
, GRAPHIC_CONSOLE
, head
);
1606 object_property_set_link(OBJECT(s
), OBJECT(dev
), "device",
1610 s
->surface
= qemu_create_message_surface(width
, height
, noinit
);
1614 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
1616 if (index
>= nb_consoles
) {
1619 return consoles
[index
];
1622 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
, uint32_t head
)
1628 for (i
= 0; i
< nb_consoles
; i
++) {
1632 obj
= object_property_get_link(OBJECT(consoles
[i
]),
1633 "device", &error_abort
);
1634 if (DEVICE(obj
) != dev
) {
1637 h
= object_property_get_int(OBJECT(consoles
[i
]),
1638 "head", &error_abort
);
1647 bool qemu_console_is_visible(QemuConsole
*con
)
1649 return (con
== active_console
) || (con
->dcls
> 0);
1652 bool qemu_console_is_graphic(QemuConsole
*con
)
1655 con
= active_console
;
1657 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
1660 bool qemu_console_is_fixedsize(QemuConsole
*con
)
1663 con
= active_console
;
1665 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
1668 int qemu_console_get_index(QemuConsole
*con
)
1671 con
= active_console
;
1673 return con
? con
->index
: -1;
1676 uint32_t qemu_console_get_head(QemuConsole
*con
)
1679 con
= active_console
;
1681 return con
? con
->head
: -1;
1684 QemuUIInfo
*qemu_console_get_ui_info(QemuConsole
*con
)
1686 assert(con
!= NULL
);
1687 return &con
->ui_info
;
1690 int qemu_console_get_width(QemuConsole
*con
, int fallback
)
1693 con
= active_console
;
1695 return con
? surface_width(con
->surface
) : fallback
;
1698 int qemu_console_get_height(QemuConsole
*con
, int fallback
)
1701 con
= active_console
;
1703 return con
? surface_height(con
->surface
) : fallback
;
1706 static void text_console_set_echo(CharDriverState
*chr
, bool echo
)
1708 QemuConsole
*s
= chr
->opaque
;
1713 static void text_console_update_cursor_timer(void)
1715 timer_mod(cursor_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
)
1716 + CONSOLE_CURSOR_PERIOD
/ 2);
1719 static void text_console_update_cursor(void *opaque
)
1724 cursor_visible_phase
= !cursor_visible_phase
;
1726 for (i
= 0; i
< nb_consoles
; i
++) {
1728 if (qemu_console_is_graphic(s
) ||
1729 !qemu_console_is_visible(s
)) {
1733 graphic_hw_invalidate(s
);
1737 text_console_update_cursor_timer();
1741 static const GraphicHwOps text_console_ops
= {
1742 .invalidate
= text_console_invalidate
,
1743 .text_update
= text_console_update
,
1746 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
)
1749 int g_width
= 80 * FONT_WIDTH
;
1750 int g_height
= 24 * FONT_HEIGHT
;
1754 chr
->chr_write
= console_puts
;
1756 s
->out_fifo
.buf
= s
->out_fifo_buf
;
1757 s
->out_fifo
.buf_size
= sizeof(s
->out_fifo_buf
);
1758 s
->kbd_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, kbd_send_chars
, s
);
1763 s
->total_height
= DEFAULT_BACKSCROLL
;
1767 if (active_console
&& active_console
->surface
) {
1768 g_width
= surface_width(active_console
->surface
);
1769 g_height
= surface_height(active_console
->surface
);
1771 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
1774 s
->hw_ops
= &text_console_ops
;
1777 /* Set text attribute defaults */
1778 s
->t_attrib_default
.bold
= 0;
1779 s
->t_attrib_default
.uline
= 0;
1780 s
->t_attrib_default
.blink
= 0;
1781 s
->t_attrib_default
.invers
= 0;
1782 s
->t_attrib_default
.unvisible
= 0;
1783 s
->t_attrib_default
.fgcol
= COLOR_WHITE
;
1784 s
->t_attrib_default
.bgcol
= COLOR_BLACK
;
1785 /* set current text attributes to default */
1786 s
->t_attrib
= s
->t_attrib_default
;
1787 text_console_resize(s
);
1793 s
->t_attrib
.bgcol
= COLOR_BLUE
;
1794 len
= snprintf(msg
, sizeof(msg
), "%s console\r\n", chr
->label
);
1795 console_puts(chr
, (uint8_t*)msg
, len
);
1796 s
->t_attrib
= s
->t_attrib_default
;
1799 qemu_chr_be_generic_open(chr
);
1804 static CharDriverState
*text_console_init(ChardevVC
*vc
)
1806 CharDriverState
*chr
;
1809 unsigned height
= 0;
1811 chr
= qemu_chr_alloc();
1813 if (vc
->has_width
) {
1815 } else if (vc
->has_cols
) {
1816 width
= vc
->cols
* FONT_WIDTH
;
1819 if (vc
->has_height
) {
1820 height
= vc
->height
;
1821 } else if (vc
->has_rows
) {
1822 height
= vc
->rows
* FONT_HEIGHT
;
1825 trace_console_txt_new(width
, height
);
1826 if (width
== 0 || height
== 0) {
1827 s
= new_console(NULL
, TEXT_CONSOLE
, 0);
1829 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
, 0);
1830 s
->surface
= qemu_create_displaysurface(width
, height
);
1840 chr
->chr_set_echo
= text_console_set_echo
;
1841 /* console/chardev init sometimes completes elsewhere in a 2nd
1842 * stage, so defer OPENED events until they are fully initialized
1844 chr
->explicit_be_open
= true;
1846 if (display_state
) {
1847 text_console_do_init(chr
, display_state
);
1852 static VcHandler
*vc_handler
= text_console_init
;
1854 CharDriverState
*vc_init(ChardevVC
*vc
)
1856 return vc_handler(vc
);
1859 void register_vc_handler(VcHandler
*handler
)
1861 vc_handler
= handler
;
1864 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
1866 DisplaySurface
*surface
;
1868 assert(s
->console_type
== GRAPHIC_CONSOLE
);
1869 surface
= qemu_create_displaysurface(width
, height
);
1870 dpy_gfx_replace_surface(s
, surface
);
1873 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
1874 int dst_x
, int dst_y
, int w
, int h
)
1876 assert(con
->console_type
== GRAPHIC_CONSOLE
);
1877 dpy_gfx_copy(con
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1880 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
1882 return console
->surface
;
1885 DisplayState
*qemu_console_displaystate(QemuConsole
*console
)
1890 PixelFormat
qemu_different_endianness_pixelformat(int bpp
)
1892 pixman_format_code_t fmt
= qemu_default_pixman_format(bpp
, false);
1893 PixelFormat pf
= qemu_pixelformat_from_pixman(fmt
);
1897 PixelFormat
qemu_default_pixelformat(int bpp
)
1899 pixman_format_code_t fmt
= qemu_default_pixman_format(bpp
, true);
1900 PixelFormat pf
= qemu_pixelformat_from_pixman(fmt
);
1904 static void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
,
1909 backend
->vc
= g_new0(ChardevVC
, 1);
1911 val
= qemu_opt_get_number(opts
, "width", 0);
1913 backend
->vc
->has_width
= true;
1914 backend
->vc
->width
= val
;
1917 val
= qemu_opt_get_number(opts
, "height", 0);
1919 backend
->vc
->has_height
= true;
1920 backend
->vc
->height
= val
;
1923 val
= qemu_opt_get_number(opts
, "cols", 0);
1925 backend
->vc
->has_cols
= true;
1926 backend
->vc
->cols
= val
;
1929 val
= qemu_opt_get_number(opts
, "rows", 0);
1931 backend
->vc
->has_rows
= true;
1932 backend
->vc
->rows
= val
;
1936 static const TypeInfo qemu_console_info
= {
1937 .name
= TYPE_QEMU_CONSOLE
,
1938 .parent
= TYPE_OBJECT
,
1939 .instance_size
= sizeof(QemuConsole
),
1940 .class_size
= sizeof(QemuConsoleClass
),
1944 static void register_types(void)
1946 type_register_static(&qemu_console_info
);
1947 register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC
,
1951 type_init(register_types
);