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 "qemu/timer.h"
27 #include "qmp-commands.h"
28 #include "sysemu/char.h"
30 //#define DEBUG_CONSOLE
31 #define DEFAULT_BACKSCROLL 512
32 #define MAX_CONSOLES 12
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
117 console_type_t console_type
;
119 DisplaySurface
*surface
;
122 /* Graphic console state. */
123 const GraphicHwOps
*hw_ops
;
126 /* Text console state */
130 int backscroll_height
;
132 int x_saved
, y_saved
;
135 TextAttributes t_attrib_default
; /* default text attributes */
136 TextAttributes t_attrib
; /* currently active text attributes */
138 int text_x
[2], text_y
[2], cursor_invalidate
;
140 bool cursor_visible_phase
;
141 QEMUTimer
*cursor_timer
;
149 int esc_params
[MAX_ESC_PARAMS
];
152 CharDriverState
*chr
;
153 /* fifo for key pressed */
155 uint8_t out_fifo_buf
[16];
156 QEMUTimer
*kbd_timer
;
159 struct DisplayState
{
160 struct QEMUTimer
*gui_timer
;
161 uint64_t last_update
;
162 uint64_t update_interval
;
167 QLIST_HEAD(, DisplayChangeListener
) listeners
;
170 static DisplayState
*display_state
;
171 static QemuConsole
*active_console
;
172 static QemuConsole
*consoles
[MAX_CONSOLES
];
173 static int nb_consoles
= 0;
175 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
);
176 static void dpy_refresh(DisplayState
*s
);
178 static void gui_update(void *opaque
)
180 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
181 uint64_t dcl_interval
;
182 DisplayState
*ds
= opaque
;
183 DisplayChangeListener
*dcl
;
186 ds
->refreshing
= true;
188 ds
->refreshing
= false;
190 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
191 dcl_interval
= dcl
->update_interval
?
192 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
193 if (interval
> dcl_interval
) {
194 interval
= dcl_interval
;
197 if (ds
->update_interval
!= interval
) {
198 ds
->update_interval
= interval
;
199 for (i
= 0; i
< nb_consoles
; i
++) {
200 if (consoles
[i
]->hw_ops
->update_interval
) {
201 consoles
[i
]->hw_ops
->update_interval(consoles
[i
]->hw
, interval
);
204 trace_console_refresh(interval
);
206 ds
->last_update
= qemu_get_clock_ms(rt_clock
);
207 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
210 static void gui_setup_refresh(DisplayState
*ds
)
212 DisplayChangeListener
*dcl
;
213 bool need_timer
= false;
214 bool have_gfx
= false;
215 bool have_text
= false;
217 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
218 if (dcl
->ops
->dpy_refresh
!= NULL
) {
221 if (dcl
->ops
->dpy_gfx_update
!= NULL
) {
224 if (dcl
->ops
->dpy_text_update
!= NULL
) {
229 if (need_timer
&& ds
->gui_timer
== NULL
) {
230 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
231 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
233 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
234 qemu_del_timer(ds
->gui_timer
);
235 qemu_free_timer(ds
->gui_timer
);
236 ds
->gui_timer
= NULL
;
239 ds
->have_gfx
= have_gfx
;
240 ds
->have_text
= have_text
;
243 void graphic_hw_update(QemuConsole
*con
)
246 con
= active_console
;
248 if (con
&& con
->hw_ops
->gfx_update
) {
249 con
->hw_ops
->gfx_update(con
->hw
);
253 void graphic_hw_invalidate(QemuConsole
*con
)
256 con
= active_console
;
258 if (con
&& con
->hw_ops
->invalidate
) {
259 con
->hw_ops
->invalidate(con
->hw
);
263 static void ppm_save(const char *filename
, struct DisplaySurface
*ds
,
266 int width
= pixman_image_get_width(ds
->image
);
267 int height
= pixman_image_get_height(ds
->image
);
271 pixman_image_t
*linebuf
;
273 trace_ppm_save(filename
, ds
);
274 f
= fopen(filename
, "wb");
276 error_setg(errp
, "failed to open file '%s': %s", filename
,
280 ret
= fprintf(f
, "P6\n%d %d\n%d\n", width
, height
, 255);
285 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
286 for (y
= 0; y
< height
; y
++) {
287 qemu_pixman_linebuf_fill(linebuf
, ds
->image
, width
, 0, y
);
289 ret
= fwrite(pixman_image_get_data(linebuf
), 1,
290 pixman_image_get_stride(linebuf
), f
);
298 qemu_pixman_image_unref(linebuf
);
303 error_setg(errp
, "failed to write to file '%s': %s", filename
,
309 void qmp_screendump(const char *filename
, Error
**errp
)
311 QemuConsole
*con
= qemu_console_lookup_by_index(0);
312 DisplaySurface
*surface
;
315 error_setg(errp
, "There is no QemuConsole I can screendump from.");
319 graphic_hw_update(con
);
320 surface
= qemu_console_surface(con
);
321 ppm_save(filename
, surface
, errp
);
324 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
327 con
= active_console
;
329 if (con
&& con
->hw_ops
->text_update
) {
330 con
->hw_ops
->text_update(con
->hw
, chardata
);
334 static void vga_fill_rect(QemuConsole
*con
,
335 int posx
, int posy
, int width
, int height
,
336 pixman_color_t color
)
338 DisplaySurface
*surface
= qemu_console_surface(con
);
339 pixman_rectangle16_t rect
= {
340 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
343 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
347 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
348 static void vga_bitblt(QemuConsole
*con
,
349 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
351 DisplaySurface
*surface
= qemu_console_surface(con
);
353 pixman_image_composite(PIXMAN_OP_SRC
,
354 surface
->image
, NULL
, surface
->image
,
355 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
358 /***********************************************************/
359 /* basic char display */
361 #define FONT_HEIGHT 16
366 #ifndef CONFIG_CURSES
379 #define QEMU_RGB(r, g, b) \
380 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
382 static const pixman_color_t color_table_rgb
[2][8] = {
384 QEMU_RGB(0x00, 0x00, 0x00), /* black */
385 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
386 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
387 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
388 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
389 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
390 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
391 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
394 QEMU_RGB(0x00, 0x00, 0x00), /* black */
395 QEMU_RGB(0xff, 0x00, 0x00), /* red */
396 QEMU_RGB(0x00, 0xff, 0x00), /* green */
397 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
398 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
399 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
400 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
401 QEMU_RGB(0xff, 0xff, 0xff), /* white */
406 static void console_print_text_attributes(TextAttributes
*t_attrib
, char ch
)
408 if (t_attrib
->bold
) {
413 if (t_attrib
->uline
) {
418 if (t_attrib
->blink
) {
423 if (t_attrib
->invers
) {
428 if (t_attrib
->unvisible
) {
434 printf(" fg: %d bg: %d ch:'%2X' '%c'\n", t_attrib
->fgcol
, t_attrib
->bgcol
, ch
, ch
);
438 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
439 TextAttributes
*t_attrib
)
441 static pixman_image_t
*glyphs
[256];
442 DisplaySurface
*surface
= qemu_console_surface(s
);
443 pixman_color_t fgcol
, bgcol
;
445 if (t_attrib
->invers
) {
446 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
447 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
449 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
450 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
454 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
456 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
457 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
460 static void text_console_resize(QemuConsole
*s
)
462 TextCell
*cells
, *c
, *c1
;
463 int w1
, x
, y
, last_width
;
465 last_width
= s
->width
;
466 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
467 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
473 cells
= g_malloc(s
->width
* s
->total_height
* sizeof(TextCell
));
474 for(y
= 0; y
< s
->total_height
; y
++) {
475 c
= &cells
[y
* s
->width
];
477 c1
= &s
->cells
[y
* last_width
];
478 for(x
= 0; x
< w1
; x
++) {
482 for(x
= w1
; x
< s
->width
; x
++) {
484 c
->t_attrib
= s
->t_attrib_default
;
492 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
494 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
495 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
496 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
497 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
500 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
502 if (s
->update_x0
> x
* FONT_WIDTH
)
503 s
->update_x0
= x
* FONT_WIDTH
;
504 if (s
->update_y0
> y
* FONT_HEIGHT
)
505 s
->update_y0
= y
* FONT_HEIGHT
;
506 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
507 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
508 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
509 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
512 static void update_xy(QemuConsole
*s
, int x
, int y
)
517 if (!qemu_console_is_visible(s
)) {
521 if (s
->ds
->have_text
) {
522 text_update_xy(s
, x
, y
);
525 if (s
->ds
->have_gfx
) {
526 y1
= (s
->y_base
+ y
) % s
->total_height
;
527 y2
= y1
- s
->y_displayed
;
529 y2
+= s
->total_height
;
530 if (y2
< s
->height
) {
531 c
= &s
->cells
[y1
* s
->width
+ x
];
532 vga_putcharxy(s
, x
, y2
, c
->ch
,
534 invalidate_xy(s
, x
, y2
);
539 static void console_show_cursor(QemuConsole
*s
, int show
)
545 if (!qemu_console_is_visible(s
)) {
549 if (s
->ds
->have_text
) {
550 s
->cursor_invalidate
= 1;
553 if (s
->ds
->have_gfx
) {
557 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
558 y
= y1
- s
->y_displayed
;
560 y
+= s
->total_height
;
562 c
= &s
->cells
[y1
* s
->width
+ x
];
563 if (show
&& s
->cursor_visible_phase
) {
564 TextAttributes t_attrib
= s
->t_attrib_default
;
565 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
566 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
568 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
570 invalidate_xy(s
, x
, y
);
575 static void console_refresh(QemuConsole
*s
)
577 DisplaySurface
*surface
= qemu_console_surface(s
);
581 if (!qemu_console_is_visible(s
)) {
585 if (s
->ds
->have_text
) {
588 s
->text_x
[1] = s
->width
- 1;
589 s
->text_y
[1] = s
->height
- 1;
590 s
->cursor_invalidate
= 1;
593 if (s
->ds
->have_gfx
) {
594 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
595 color_table_rgb
[0][COLOR_BLACK
]);
597 for (y
= 0; y
< s
->height
; y
++) {
598 c
= s
->cells
+ y1
* s
->width
;
599 for (x
= 0; x
< s
->width
; x
++) {
600 vga_putcharxy(s
, x
, y
, c
->ch
,
604 if (++y1
== s
->total_height
) {
608 console_show_cursor(s
, 1);
609 dpy_gfx_update(s
, 0, 0,
610 surface_width(surface
), surface_height(surface
));
614 static void console_scroll(QemuConsole
*s
, int ydelta
)
619 for(i
= 0; i
< ydelta
; i
++) {
620 if (s
->y_displayed
== s
->y_base
)
622 if (++s
->y_displayed
== s
->total_height
)
627 i
= s
->backscroll_height
;
628 if (i
> s
->total_height
- s
->height
)
629 i
= s
->total_height
- s
->height
;
632 y1
+= s
->total_height
;
633 for(i
= 0; i
< ydelta
; i
++) {
634 if (s
->y_displayed
== y1
)
636 if (--s
->y_displayed
< 0)
637 s
->y_displayed
= s
->total_height
- 1;
643 static void console_put_lf(QemuConsole
*s
)
649 if (s
->y
>= s
->height
) {
650 s
->y
= s
->height
- 1;
652 if (s
->y_displayed
== s
->y_base
) {
653 if (++s
->y_displayed
== s
->total_height
)
656 if (++s
->y_base
== s
->total_height
)
658 if (s
->backscroll_height
< s
->total_height
)
659 s
->backscroll_height
++;
660 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
661 c
= &s
->cells
[y1
* s
->width
];
662 for(x
= 0; x
< s
->width
; x
++) {
664 c
->t_attrib
= s
->t_attrib_default
;
667 if (qemu_console_is_visible(s
) && s
->y_displayed
== s
->y_base
) {
668 if (s
->ds
->have_text
) {
671 s
->text_x
[1] = s
->width
- 1;
672 s
->text_y
[1] = s
->height
- 1;
675 if (s
->ds
->have_gfx
) {
676 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
677 s
->width
* FONT_WIDTH
,
678 (s
->height
- 1) * FONT_HEIGHT
);
679 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
680 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
681 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
684 s
->update_x1
= s
->width
* FONT_WIDTH
;
685 s
->update_y1
= s
->height
* FONT_HEIGHT
;
691 /* Set console attributes depending on the current escape codes.
692 * NOTE: I know this code is not very efficient (checking every color for it
693 * self) but it is more readable and better maintainable.
695 static void console_handle_escape(QemuConsole
*s
)
699 for (i
=0; i
<s
->nb_esc_params
; i
++) {
700 switch (s
->esc_params
[i
]) {
701 case 0: /* reset all console attributes to default */
702 s
->t_attrib
= s
->t_attrib_default
;
705 s
->t_attrib
.bold
= 1;
708 s
->t_attrib
.uline
= 1;
711 s
->t_attrib
.blink
= 1;
714 s
->t_attrib
.invers
= 1;
717 s
->t_attrib
.unvisible
= 1;
720 s
->t_attrib
.bold
= 0;
723 s
->t_attrib
.uline
= 0;
726 s
->t_attrib
.blink
= 0;
729 s
->t_attrib
.invers
= 0;
732 s
->t_attrib
.unvisible
= 0;
734 /* set foreground color */
736 s
->t_attrib
.fgcol
=COLOR_BLACK
;
739 s
->t_attrib
.fgcol
=COLOR_RED
;
742 s
->t_attrib
.fgcol
=COLOR_GREEN
;
745 s
->t_attrib
.fgcol
=COLOR_YELLOW
;
748 s
->t_attrib
.fgcol
=COLOR_BLUE
;
751 s
->t_attrib
.fgcol
=COLOR_MAGENTA
;
754 s
->t_attrib
.fgcol
=COLOR_CYAN
;
757 s
->t_attrib
.fgcol
=COLOR_WHITE
;
759 /* set background color */
761 s
->t_attrib
.bgcol
=COLOR_BLACK
;
764 s
->t_attrib
.bgcol
=COLOR_RED
;
767 s
->t_attrib
.bgcol
=COLOR_GREEN
;
770 s
->t_attrib
.bgcol
=COLOR_YELLOW
;
773 s
->t_attrib
.bgcol
=COLOR_BLUE
;
776 s
->t_attrib
.bgcol
=COLOR_MAGENTA
;
779 s
->t_attrib
.bgcol
=COLOR_CYAN
;
782 s
->t_attrib
.bgcol
=COLOR_WHITE
;
788 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
790 int y1
= (s
->y_base
+ y
) % s
->total_height
;
791 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
793 c
->t_attrib
= s
->t_attrib_default
;
797 /* set cursor, checking bounds */
798 static void set_cursor(QemuConsole
*s
, int x
, int y
)
806 if (y
>= s
->height
) {
817 static void console_putchar(QemuConsole
*s
, int ch
)
826 case '\r': /* carriage return */
829 case '\n': /* newline */
832 case '\b': /* backspace */
836 case '\t': /* tabspace */
837 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
841 s
->x
= s
->x
+ (8 - (s
->x
% 8));
844 case '\a': /* alert aka. bell */
845 /* TODO: has to be implemented */
848 /* SI (shift in), character set 0 (ignored) */
851 /* SO (shift out), character set 1 (ignored) */
853 case 27: /* esc (introducing an escape sequence) */
854 s
->state
= TTY_STATE_ESC
;
857 if (s
->x
>= s
->width
) {
862 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
863 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
865 c
->t_attrib
= s
->t_attrib
;
866 update_xy(s
, s
->x
, s
->y
);
871 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
873 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
874 s
->esc_params
[i
] = 0;
875 s
->nb_esc_params
= 0;
876 s
->state
= TTY_STATE_CSI
;
878 s
->state
= TTY_STATE_NORM
;
881 case TTY_STATE_CSI
: /* handle escape sequence parameters */
882 if (ch
>= '0' && ch
<= '9') {
883 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
884 int *param
= &s
->esc_params
[s
->nb_esc_params
];
885 int digit
= (ch
- '0');
887 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
888 *param
* 10 + digit
: INT_MAX
;
891 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
896 fprintf(stderr
, "escape sequence CSI%d;%d%c, %d parameters\n",
897 s
->esc_params
[0], s
->esc_params
[1], ch
, s
->nb_esc_params
);
899 s
->state
= TTY_STATE_NORM
;
903 if (s
->esc_params
[0] == 0) {
904 s
->esc_params
[0] = 1;
906 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
909 /* move cursor down */
910 if (s
->esc_params
[0] == 0) {
911 s
->esc_params
[0] = 1;
913 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
916 /* move cursor right */
917 if (s
->esc_params
[0] == 0) {
918 s
->esc_params
[0] = 1;
920 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
923 /* move cursor left */
924 if (s
->esc_params
[0] == 0) {
925 s
->esc_params
[0] = 1;
927 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
930 /* move cursor to column */
931 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
935 /* move cursor to row, column */
936 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
939 switch (s
->esc_params
[0]) {
941 /* clear to end of screen */
942 for (y
= s
->y
; y
< s
->height
; y
++) {
943 for (x
= 0; x
< s
->width
; x
++) {
944 if (y
== s
->y
&& x
< s
->x
) {
947 console_clear_xy(s
, x
, y
);
952 /* clear from beginning of screen */
953 for (y
= 0; y
<= s
->y
; y
++) {
954 for (x
= 0; x
< s
->width
; x
++) {
955 if (y
== s
->y
&& x
> s
->x
) {
958 console_clear_xy(s
, x
, y
);
963 /* clear entire screen */
964 for (y
= 0; y
<= s
->height
; y
++) {
965 for (x
= 0; x
< s
->width
; x
++) {
966 console_clear_xy(s
, x
, y
);
973 switch (s
->esc_params
[0]) {
976 for(x
= s
->x
; x
< s
->width
; x
++) {
977 console_clear_xy(s
, x
, s
->y
);
981 /* clear from beginning of line */
982 for (x
= 0; x
<= s
->x
; x
++) {
983 console_clear_xy(s
, x
, s
->y
);
987 /* clear entire line */
988 for(x
= 0; x
< s
->width
; x
++) {
989 console_clear_xy(s
, x
, s
->y
);
995 console_handle_escape(s
);
998 /* report cursor position */
999 /* TODO: send ESC[row;colR */
1002 /* save cursor position */
1007 /* restore cursor position */
1012 #ifdef DEBUG_CONSOLE
1013 fprintf(stderr
, "unhandled escape character '%c'\n", ch
);
1022 void console_select(unsigned int index
)
1024 DisplayChangeListener
*dcl
;
1027 if (index
>= MAX_CONSOLES
)
1030 trace_console_select(index
);
1031 s
= qemu_console_lookup_by_index(index
);
1033 DisplayState
*ds
= s
->ds
;
1035 if (active_console
&& active_console
->cursor_timer
) {
1036 qemu_del_timer(active_console
->cursor_timer
);
1040 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1041 if (dcl
->con
!= NULL
) {
1044 if (dcl
->ops
->dpy_gfx_switch
) {
1045 dcl
->ops
->dpy_gfx_switch(dcl
, s
->surface
);
1048 dpy_gfx_update(s
, 0, 0, surface_width(s
->surface
),
1049 surface_height(s
->surface
));
1051 if (ds
->have_text
) {
1052 dpy_text_resize(s
, s
->width
, s
->height
);
1054 if (s
->cursor_timer
) {
1055 qemu_mod_timer(s
->cursor_timer
,
1056 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1061 static int console_puts(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1063 QemuConsole
*s
= chr
->opaque
;
1066 s
->update_x0
= s
->width
* FONT_WIDTH
;
1067 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1070 console_show_cursor(s
, 0);
1071 for(i
= 0; i
< len
; i
++) {
1072 console_putchar(s
, buf
[i
]);
1074 console_show_cursor(s
, 1);
1075 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1076 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1077 s
->update_x1
- s
->update_x0
,
1078 s
->update_y1
- s
->update_y0
);
1083 static void kbd_send_chars(void *opaque
)
1085 QemuConsole
*s
= opaque
;
1089 len
= qemu_chr_be_can_write(s
->chr
);
1090 if (len
> s
->out_fifo
.count
)
1091 len
= s
->out_fifo
.count
;
1093 if (len
> sizeof(buf
))
1095 qemu_fifo_read(&s
->out_fifo
, buf
, len
);
1096 qemu_chr_be_write(s
->chr
, buf
, len
);
1098 /* characters are pending: we send them a bit later (XXX:
1099 horrible, should change char device API) */
1100 if (s
->out_fifo
.count
> 0) {
1101 qemu_mod_timer(s
->kbd_timer
, qemu_get_clock_ms(rt_clock
) + 1);
1105 /* called when an ascii key is pressed */
1106 void kbd_put_keysym(int keysym
)
1109 uint8_t buf
[16], *q
;
1113 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1117 case QEMU_KEY_CTRL_UP
:
1118 console_scroll(s
, -1);
1120 case QEMU_KEY_CTRL_DOWN
:
1121 console_scroll(s
, 1);
1123 case QEMU_KEY_CTRL_PAGEUP
:
1124 console_scroll(s
, -10);
1126 case QEMU_KEY_CTRL_PAGEDOWN
:
1127 console_scroll(s
, 10);
1130 /* convert the QEMU keysym to VT100 key string */
1132 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1135 c
= keysym
- 0xe100;
1137 *q
++ = '0' + (c
/ 10);
1138 *q
++ = '0' + (c
% 10);
1140 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1143 *q
++ = keysym
& 0xff;
1144 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1145 console_puts(s
->chr
, (const uint8_t *) "\r", 1);
1151 console_puts(s
->chr
, buf
, q
- buf
);
1153 if (s
->chr
->chr_read
) {
1154 qemu_fifo_write(&s
->out_fifo
, buf
, q
- buf
);
1161 static void text_console_invalidate(void *opaque
)
1163 QemuConsole
*s
= (QemuConsole
*) opaque
;
1165 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1166 text_console_resize(s
);
1171 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1173 QemuConsole
*s
= (QemuConsole
*) opaque
;
1176 if (s
->text_x
[0] <= s
->text_x
[1]) {
1177 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1178 chardata
+= s
->text_y
[0] * s
->width
;
1179 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1180 for (j
= 0; j
< s
->width
; j
++, src
++)
1181 console_write_ch(chardata
++, s
->cells
[src
].ch
|
1182 (s
->cells
[src
].t_attrib
.fgcol
<< 12) |
1183 (s
->cells
[src
].t_attrib
.bgcol
<< 8) |
1184 (s
->cells
[src
].t_attrib
.bold
<< 21));
1185 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1186 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1187 s
->text_x
[0] = s
->width
;
1188 s
->text_y
[0] = s
->height
;
1192 if (s
->cursor_invalidate
) {
1193 dpy_text_cursor(s
, s
->x
, s
->y
);
1194 s
->cursor_invalidate
= 0;
1198 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
)
1203 if (nb_consoles
>= MAX_CONSOLES
)
1205 s
= g_malloc0(sizeof(QemuConsole
));
1206 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1207 (console_type
== GRAPHIC_CONSOLE
))) {
1211 s
->console_type
= console_type
;
1212 if (console_type
!= GRAPHIC_CONSOLE
) {
1213 s
->index
= nb_consoles
;
1214 consoles
[nb_consoles
++] = s
;
1216 /* HACK: Put graphical consoles before text consoles. */
1217 for (i
= nb_consoles
; i
> 0; i
--) {
1218 if (consoles
[i
- 1]->console_type
== GRAPHIC_CONSOLE
)
1220 consoles
[i
] = consoles
[i
- 1];
1221 consoles
[i
]->index
= i
;
1230 static void qemu_alloc_display(DisplaySurface
*surface
, int width
, int height
,
1231 int linesize
, PixelFormat pf
, int newflags
)
1235 qemu_pixman_image_unref(surface
->image
);
1236 surface
->image
= NULL
;
1238 surface
->format
= qemu_pixman_get_format(&pf
);
1239 assert(surface
->format
!= 0);
1240 surface
->image
= pixman_image_create_bits(surface
->format
,
1243 assert(surface
->image
!= NULL
);
1245 surface
->flags
= newflags
| QEMU_ALLOCATED_FLAG
;
1246 #ifdef HOST_WORDS_BIGENDIAN
1247 surface
->flags
|= QEMU_BIG_ENDIAN_FLAG
;
1251 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1253 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1254 int linesize
= width
* 4;
1256 trace_displaysurface_create(surface
, width
, height
);
1257 qemu_alloc_display(surface
, width
, height
, linesize
,
1258 qemu_default_pixelformat(32), 0);
1262 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
, int bpp
,
1263 int linesize
, uint8_t *data
,
1266 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1268 trace_displaysurface_create_from(surface
, width
, height
, bpp
, byteswap
);
1270 surface
->pf
= qemu_different_endianness_pixelformat(bpp
);
1272 surface
->pf
= qemu_default_pixelformat(bpp
);
1275 surface
->format
= qemu_pixman_get_format(&surface
->pf
);
1276 assert(surface
->format
!= 0);
1277 surface
->image
= pixman_image_create_bits(surface
->format
,
1279 (void *)data
, linesize
);
1280 assert(surface
->image
!= NULL
);
1282 #ifdef HOST_WORDS_BIGENDIAN
1283 surface
->flags
= QEMU_BIG_ENDIAN_FLAG
;
1289 void qemu_free_displaysurface(DisplaySurface
*surface
)
1291 if (surface
== NULL
) {
1294 trace_displaysurface_free(surface
);
1295 qemu_pixman_image_unref(surface
->image
);
1299 void register_displaychangelistener(DisplayState
*ds
,
1300 DisplayChangeListener
*dcl
)
1304 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1306 QLIST_INSERT_HEAD(&ds
->listeners
, dcl
, next
);
1307 gui_setup_refresh(ds
);
1312 con
= active_console
;
1314 if (dcl
->ops
->dpy_gfx_switch
&& con
) {
1315 dcl
->ops
->dpy_gfx_switch(dcl
, con
->surface
);
1319 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1322 DisplayState
*ds
= dcl
->ds
;
1324 dcl
->update_interval
= interval
;
1325 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1326 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
1330 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1332 DisplayState
*ds
= dcl
->ds
;
1333 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1337 QLIST_REMOVE(dcl
, next
);
1338 gui_setup_refresh(ds
);
1341 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1343 DisplayState
*s
= con
->ds
;
1344 DisplayChangeListener
*dcl
;
1345 int width
= surface_width(con
->surface
);
1346 int height
= surface_height(con
->surface
);
1352 w
= MIN(w
, width
- x
);
1353 h
= MIN(h
, height
- y
);
1355 if (!qemu_console_is_visible(con
)) {
1358 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1359 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1362 if (dcl
->ops
->dpy_gfx_update
) {
1363 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1368 void dpy_gfx_replace_surface(QemuConsole
*con
,
1369 DisplaySurface
*surface
)
1371 DisplayState
*s
= con
->ds
;
1372 DisplaySurface
*old_surface
= con
->surface
;
1373 DisplayChangeListener
*dcl
;
1375 con
->surface
= surface
;
1376 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1377 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1380 if (dcl
->ops
->dpy_gfx_switch
) {
1381 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1384 qemu_free_displaysurface(old_surface
);
1387 void dpy_refresh(DisplayState
*s
)
1389 DisplayChangeListener
*dcl
;
1391 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1392 if (dcl
->ops
->dpy_refresh
) {
1393 dcl
->ops
->dpy_refresh(dcl
);
1398 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
1399 int dst_x
, int dst_y
, int w
, int h
)
1401 DisplayState
*s
= con
->ds
;
1402 DisplayChangeListener
*dcl
;
1404 if (!qemu_console_is_visible(con
)) {
1407 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1408 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1411 if (dcl
->ops
->dpy_gfx_copy
) {
1412 dcl
->ops
->dpy_gfx_copy(dcl
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1414 dcl
->ops
->dpy_gfx_update(dcl
, dst_x
, dst_y
, w
, h
);
1419 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1421 DisplayState
*s
= con
->ds
;
1422 DisplayChangeListener
*dcl
;
1424 if (!qemu_console_is_visible(con
)) {
1427 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1428 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1431 if (dcl
->ops
->dpy_text_cursor
) {
1432 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1437 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1439 DisplayState
*s
= con
->ds
;
1440 DisplayChangeListener
*dcl
;
1442 if (!qemu_console_is_visible(con
)) {
1445 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1446 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1449 if (dcl
->ops
->dpy_text_update
) {
1450 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1455 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1457 DisplayState
*s
= con
->ds
;
1458 struct DisplayChangeListener
*dcl
;
1460 if (!qemu_console_is_visible(con
)) {
1463 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1464 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1467 if (dcl
->ops
->dpy_text_resize
) {
1468 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1473 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1475 DisplayState
*s
= con
->ds
;
1476 DisplayChangeListener
*dcl
;
1478 if (!qemu_console_is_visible(con
)) {
1481 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1482 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1485 if (dcl
->ops
->dpy_mouse_set
) {
1486 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1491 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1493 DisplayState
*s
= con
->ds
;
1494 DisplayChangeListener
*dcl
;
1496 if (!qemu_console_is_visible(con
)) {
1499 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1500 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1503 if (dcl
->ops
->dpy_cursor_define
) {
1504 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1509 bool dpy_cursor_define_supported(QemuConsole
*con
)
1511 DisplayState
*s
= con
->ds
;
1512 DisplayChangeListener
*dcl
;
1514 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1515 if (dcl
->ops
->dpy_cursor_define
) {
1522 /***********************************************************/
1523 /* register display */
1525 /* console.c internal use only */
1526 static DisplayState
*get_alloc_displaystate(void)
1528 if (!display_state
) {
1529 display_state
= g_new0(DisplayState
, 1);
1531 return display_state
;
1535 * Called by main(), after creating QemuConsoles
1536 * and before initializing ui (sdl/vnc/...).
1538 DisplayState
*init_displaystate(void)
1542 if (!display_state
) {
1543 display_state
= g_new0(DisplayState
, 1);
1546 for (i
= 0; i
< nb_consoles
; i
++) {
1547 if (consoles
[i
]->console_type
!= GRAPHIC_CONSOLE
&&
1548 consoles
[i
]->ds
== NULL
) {
1549 text_console_do_init(consoles
[i
]->chr
, display_state
);
1553 return display_state
;
1556 QemuConsole
*graphic_console_init(const GraphicHwOps
*hw_ops
,
1564 ds
= get_alloc_displaystate();
1565 trace_console_gfx_new();
1566 s
= new_console(ds
, GRAPHIC_CONSOLE
);
1570 s
->surface
= qemu_create_displaysurface(width
, height
);
1574 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
1576 if (index
>= MAX_CONSOLES
) {
1579 return consoles
[index
];
1582 bool qemu_console_is_visible(QemuConsole
*con
)
1584 return (con
== active_console
) || (con
->dcls
> 0);
1587 bool qemu_console_is_graphic(QemuConsole
*con
)
1590 con
= active_console
;
1592 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
1595 bool qemu_console_is_fixedsize(QemuConsole
*con
)
1598 con
= active_console
;
1600 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
1603 static void text_console_set_echo(CharDriverState
*chr
, bool echo
)
1605 QemuConsole
*s
= chr
->opaque
;
1610 static void text_console_update_cursor(void *opaque
)
1612 QemuConsole
*s
= opaque
;
1614 s
->cursor_visible_phase
= !s
->cursor_visible_phase
;
1615 graphic_hw_invalidate(s
);
1616 qemu_mod_timer(s
->cursor_timer
,
1617 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1620 static const GraphicHwOps text_console_ops
= {
1621 .invalidate
= text_console_invalidate
,
1622 .text_update
= text_console_update
,
1625 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
)
1628 int g_width
= 80 * FONT_WIDTH
;
1629 int g_height
= 24 * FONT_HEIGHT
;
1633 chr
->chr_write
= console_puts
;
1635 s
->out_fifo
.buf
= s
->out_fifo_buf
;
1636 s
->out_fifo
.buf_size
= sizeof(s
->out_fifo_buf
);
1637 s
->kbd_timer
= qemu_new_timer_ms(rt_clock
, kbd_send_chars
, s
);
1642 s
->total_height
= DEFAULT_BACKSCROLL
;
1646 if (active_console
&& active_console
->surface
) {
1647 g_width
= surface_width(active_console
->surface
);
1648 g_height
= surface_height(active_console
->surface
);
1650 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
1654 qemu_new_timer_ms(rt_clock
, text_console_update_cursor
, s
);
1656 s
->hw_ops
= &text_console_ops
;
1659 /* Set text attribute defaults */
1660 s
->t_attrib_default
.bold
= 0;
1661 s
->t_attrib_default
.uline
= 0;
1662 s
->t_attrib_default
.blink
= 0;
1663 s
->t_attrib_default
.invers
= 0;
1664 s
->t_attrib_default
.unvisible
= 0;
1665 s
->t_attrib_default
.fgcol
= COLOR_WHITE
;
1666 s
->t_attrib_default
.bgcol
= COLOR_BLACK
;
1667 /* set current text attributes to default */
1668 s
->t_attrib
= s
->t_attrib_default
;
1669 text_console_resize(s
);
1675 s
->t_attrib
.bgcol
= COLOR_BLUE
;
1676 len
= snprintf(msg
, sizeof(msg
), "%s console\r\n", chr
->label
);
1677 console_puts(chr
, (uint8_t*)msg
, len
);
1678 s
->t_attrib
= s
->t_attrib_default
;
1681 qemu_chr_be_generic_open(chr
);
1686 static CharDriverState
*text_console_init(ChardevVC
*vc
)
1688 CharDriverState
*chr
;
1691 unsigned height
= 0;
1693 chr
= g_malloc0(sizeof(CharDriverState
));
1695 if (vc
->has_width
) {
1697 } else if (vc
->has_cols
) {
1698 width
= vc
->cols
* FONT_WIDTH
;
1701 if (vc
->has_height
) {
1702 height
= vc
->height
;
1703 } else if (vc
->has_rows
) {
1704 height
= vc
->rows
* FONT_HEIGHT
;
1707 trace_console_txt_new(width
, height
);
1708 if (width
== 0 || height
== 0) {
1709 s
= new_console(NULL
, TEXT_CONSOLE
);
1711 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
);
1712 s
->surface
= qemu_create_displaysurface(width
, height
);
1722 chr
->chr_set_echo
= text_console_set_echo
;
1724 if (display_state
) {
1725 text_console_do_init(chr
, display_state
);
1730 static VcHandler
*vc_handler
= text_console_init
;
1732 CharDriverState
*vc_init(ChardevVC
*vc
)
1734 return vc_handler(vc
);
1737 void register_vc_handler(VcHandler
*handler
)
1739 vc_handler
= handler
;
1742 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
1744 DisplaySurface
*surface
;
1746 assert(s
->console_type
== GRAPHIC_CONSOLE
);
1747 surface
= qemu_create_displaysurface(width
, height
);
1748 dpy_gfx_replace_surface(s
, surface
);
1751 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
1752 int dst_x
, int dst_y
, int w
, int h
)
1754 assert(con
->console_type
== GRAPHIC_CONSOLE
);
1755 dpy_gfx_copy(con
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1758 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
1760 return console
->surface
;
1763 DisplayState
*qemu_console_displaystate(QemuConsole
*console
)
1768 PixelFormat
qemu_different_endianness_pixelformat(int bpp
)
1772 memset(&pf
, 0x00, sizeof(PixelFormat
));
1774 pf
.bits_per_pixel
= bpp
;
1775 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1776 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1780 pf
.rmask
= 0x000000FF;
1781 pf
.gmask
= 0x0000FF00;
1782 pf
.bmask
= 0x00FF0000;
1794 pf
.rmask
= 0x0000FF00;
1795 pf
.gmask
= 0x00FF0000;
1796 pf
.bmask
= 0xFF000000;
1797 pf
.amask
= 0x00000000;
1817 PixelFormat
qemu_default_pixelformat(int bpp
)
1821 memset(&pf
, 0x00, sizeof(PixelFormat
));
1823 pf
.bits_per_pixel
= bpp
;
1824 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1825 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1829 pf
.bits_per_pixel
= 16;
1830 pf
.rmask
= 0x00007c00;
1831 pf
.gmask
= 0x000003E0;
1832 pf
.bmask
= 0x0000001F;
1844 pf
.rmask
= 0x0000F800;
1845 pf
.gmask
= 0x000007E0;
1846 pf
.bmask
= 0x0000001F;
1858 pf
.rmask
= 0x00FF0000;
1859 pf
.gmask
= 0x0000FF00;
1860 pf
.bmask
= 0x000000FF;
1872 pf
.rmask
= 0x00FF0000;
1873 pf
.gmask
= 0x0000FF00;
1874 pf
.bmask
= 0x000000FF;
1891 static void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
,
1896 backend
->vc
= g_new0(ChardevVC
, 1);
1898 val
= qemu_opt_get_number(opts
, "width", 0);
1900 backend
->vc
->has_width
= true;
1901 backend
->vc
->width
= val
;
1904 val
= qemu_opt_get_number(opts
, "height", 0);
1906 backend
->vc
->has_height
= true;
1907 backend
->vc
->height
= val
;
1910 val
= qemu_opt_get_number(opts
, "cols", 0);
1912 backend
->vc
->has_cols
= true;
1913 backend
->vc
->cols
= val
;
1916 val
= qemu_opt_get_number(opts
, "rows", 0);
1918 backend
->vc
->has_rows
= true;
1919 backend
->vc
->rows
= val
;
1923 static void register_types(void)
1925 register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC
,
1929 type_init(register_types
);