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
119 console_type_t console_type
;
121 DisplaySurface
*surface
;
124 /* Graphic console state. */
125 const GraphicHwOps
*hw_ops
;
128 /* Text console state */
132 int backscroll_height
;
134 int x_saved
, y_saved
;
137 TextAttributes t_attrib_default
; /* default text attributes */
138 TextAttributes t_attrib
; /* currently active text attributes */
140 int text_x
[2], text_y
[2], cursor_invalidate
;
142 bool cursor_visible_phase
;
143 QEMUTimer
*cursor_timer
;
151 int esc_params
[MAX_ESC_PARAMS
];
154 CharDriverState
*chr
;
155 /* fifo for key pressed */
157 uint8_t out_fifo_buf
[16];
158 QEMUTimer
*kbd_timer
;
161 struct DisplayState
{
162 struct QEMUTimer
*gui_timer
;
163 uint64_t last_update
;
164 uint64_t update_interval
;
169 QLIST_HEAD(, DisplayChangeListener
) listeners
;
172 static DisplayState
*display_state
;
173 static QemuConsole
*active_console
;
174 static QemuConsole
*consoles
[MAX_CONSOLES
];
175 static int nb_consoles
= 0;
177 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
);
178 static void dpy_refresh(DisplayState
*s
);
180 static void gui_update(void *opaque
)
182 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
183 uint64_t dcl_interval
;
184 DisplayState
*ds
= opaque
;
185 DisplayChangeListener
*dcl
;
188 ds
->refreshing
= true;
190 ds
->refreshing
= false;
192 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
193 dcl_interval
= dcl
->update_interval
?
194 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
195 if (interval
> dcl_interval
) {
196 interval
= dcl_interval
;
199 if (ds
->update_interval
!= interval
) {
200 ds
->update_interval
= interval
;
201 for (i
= 0; i
< nb_consoles
; i
++) {
202 if (consoles
[i
]->hw_ops
->update_interval
) {
203 consoles
[i
]->hw_ops
->update_interval(consoles
[i
]->hw
, interval
);
206 trace_console_refresh(interval
);
208 ds
->last_update
= qemu_get_clock_ms(rt_clock
);
209 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
212 static void gui_setup_refresh(DisplayState
*ds
)
214 DisplayChangeListener
*dcl
;
215 bool need_timer
= false;
216 bool have_gfx
= false;
217 bool have_text
= false;
219 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
220 if (dcl
->ops
->dpy_refresh
!= NULL
) {
223 if (dcl
->ops
->dpy_gfx_update
!= NULL
) {
226 if (dcl
->ops
->dpy_text_update
!= NULL
) {
231 if (need_timer
&& ds
->gui_timer
== NULL
) {
232 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
233 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
235 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
236 qemu_del_timer(ds
->gui_timer
);
237 qemu_free_timer(ds
->gui_timer
);
238 ds
->gui_timer
= NULL
;
241 ds
->have_gfx
= have_gfx
;
242 ds
->have_text
= have_text
;
245 void graphic_hw_update(QemuConsole
*con
)
248 con
= active_console
;
250 if (con
&& con
->hw_ops
->gfx_update
) {
251 con
->hw_ops
->gfx_update(con
->hw
);
255 void graphic_hw_invalidate(QemuConsole
*con
)
258 con
= active_console
;
260 if (con
&& con
->hw_ops
->invalidate
) {
261 con
->hw_ops
->invalidate(con
->hw
);
265 static void ppm_save(const char *filename
, struct DisplaySurface
*ds
,
268 int width
= pixman_image_get_width(ds
->image
);
269 int height
= pixman_image_get_height(ds
->image
);
273 pixman_image_t
*linebuf
;
275 trace_ppm_save(filename
, ds
);
276 f
= fopen(filename
, "wb");
278 error_setg(errp
, "failed to open file '%s': %s", filename
,
282 ret
= fprintf(f
, "P6\n%d %d\n%d\n", width
, height
, 255);
287 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
288 for (y
= 0; y
< height
; y
++) {
289 qemu_pixman_linebuf_fill(linebuf
, ds
->image
, width
, 0, y
);
291 ret
= fwrite(pixman_image_get_data(linebuf
), 1,
292 pixman_image_get_stride(linebuf
), f
);
300 qemu_pixman_image_unref(linebuf
);
305 error_setg(errp
, "failed to write to file '%s': %s", filename
,
311 void qmp_screendump(const char *filename
, Error
**errp
)
313 QemuConsole
*con
= qemu_console_lookup_by_index(0);
314 DisplaySurface
*surface
;
317 error_setg(errp
, "There is no QemuConsole I can screendump from.");
321 graphic_hw_update(con
);
322 surface
= qemu_console_surface(con
);
323 ppm_save(filename
, surface
, errp
);
326 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
329 con
= active_console
;
331 if (con
&& con
->hw_ops
->text_update
) {
332 con
->hw_ops
->text_update(con
->hw
, chardata
);
336 static void vga_fill_rect(QemuConsole
*con
,
337 int posx
, int posy
, int width
, int height
,
338 pixman_color_t color
)
340 DisplaySurface
*surface
= qemu_console_surface(con
);
341 pixman_rectangle16_t rect
= {
342 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
345 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
349 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
350 static void vga_bitblt(QemuConsole
*con
,
351 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
353 DisplaySurface
*surface
= qemu_console_surface(con
);
355 pixman_image_composite(PIXMAN_OP_SRC
,
356 surface
->image
, NULL
, surface
->image
,
357 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
360 /***********************************************************/
361 /* basic char display */
363 #define FONT_HEIGHT 16
368 #ifndef CONFIG_CURSES
381 #define QEMU_RGB(r, g, b) \
382 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
384 static const pixman_color_t color_table_rgb
[2][8] = {
386 QEMU_RGB(0x00, 0x00, 0x00), /* black */
387 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
388 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
389 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
390 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
391 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
392 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
393 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
396 QEMU_RGB(0x00, 0x00, 0x00), /* black */
397 QEMU_RGB(0xff, 0x00, 0x00), /* red */
398 QEMU_RGB(0x00, 0xff, 0x00), /* green */
399 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
400 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
401 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
402 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
403 QEMU_RGB(0xff, 0xff, 0xff), /* white */
408 static void console_print_text_attributes(TextAttributes
*t_attrib
, char ch
)
410 if (t_attrib
->bold
) {
415 if (t_attrib
->uline
) {
420 if (t_attrib
->blink
) {
425 if (t_attrib
->invers
) {
430 if (t_attrib
->unvisible
) {
436 printf(" fg: %d bg: %d ch:'%2X' '%c'\n", t_attrib
->fgcol
, t_attrib
->bgcol
, ch
, ch
);
440 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
441 TextAttributes
*t_attrib
)
443 static pixman_image_t
*glyphs
[256];
444 DisplaySurface
*surface
= qemu_console_surface(s
);
445 pixman_color_t fgcol
, bgcol
;
447 if (t_attrib
->invers
) {
448 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
449 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
451 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
452 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
456 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
458 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
459 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
462 static void text_console_resize(QemuConsole
*s
)
464 TextCell
*cells
, *c
, *c1
;
465 int w1
, x
, y
, last_width
;
467 last_width
= s
->width
;
468 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
469 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
475 cells
= g_malloc(s
->width
* s
->total_height
* sizeof(TextCell
));
476 for(y
= 0; y
< s
->total_height
; y
++) {
477 c
= &cells
[y
* s
->width
];
479 c1
= &s
->cells
[y
* last_width
];
480 for(x
= 0; x
< w1
; x
++) {
484 for(x
= w1
; x
< s
->width
; x
++) {
486 c
->t_attrib
= s
->t_attrib_default
;
494 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
496 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
497 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
498 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
499 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
502 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
504 if (s
->update_x0
> x
* FONT_WIDTH
)
505 s
->update_x0
= x
* FONT_WIDTH
;
506 if (s
->update_y0
> y
* FONT_HEIGHT
)
507 s
->update_y0
= y
* FONT_HEIGHT
;
508 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
509 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
510 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
511 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
514 static void update_xy(QemuConsole
*s
, int x
, int y
)
519 if (!qemu_console_is_visible(s
)) {
523 if (s
->ds
->have_text
) {
524 text_update_xy(s
, x
, y
);
527 if (s
->ds
->have_gfx
) {
528 y1
= (s
->y_base
+ y
) % s
->total_height
;
529 y2
= y1
- s
->y_displayed
;
531 y2
+= s
->total_height
;
532 if (y2
< s
->height
) {
533 c
= &s
->cells
[y1
* s
->width
+ x
];
534 vga_putcharxy(s
, x
, y2
, c
->ch
,
536 invalidate_xy(s
, x
, y2
);
541 static void console_show_cursor(QemuConsole
*s
, int show
)
547 if (!qemu_console_is_visible(s
)) {
551 if (s
->ds
->have_text
) {
552 s
->cursor_invalidate
= 1;
555 if (s
->ds
->have_gfx
) {
559 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
560 y
= y1
- s
->y_displayed
;
562 y
+= s
->total_height
;
564 c
= &s
->cells
[y1
* s
->width
+ x
];
565 if (show
&& s
->cursor_visible_phase
) {
566 TextAttributes t_attrib
= s
->t_attrib_default
;
567 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
568 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
570 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
572 invalidate_xy(s
, x
, y
);
577 static void console_refresh(QemuConsole
*s
)
579 DisplaySurface
*surface
= qemu_console_surface(s
);
583 if (!qemu_console_is_visible(s
)) {
587 if (s
->ds
->have_text
) {
590 s
->text_x
[1] = s
->width
- 1;
591 s
->text_y
[1] = s
->height
- 1;
592 s
->cursor_invalidate
= 1;
595 if (s
->ds
->have_gfx
) {
596 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
597 color_table_rgb
[0][COLOR_BLACK
]);
599 for (y
= 0; y
< s
->height
; y
++) {
600 c
= s
->cells
+ y1
* s
->width
;
601 for (x
= 0; x
< s
->width
; x
++) {
602 vga_putcharxy(s
, x
, y
, c
->ch
,
606 if (++y1
== s
->total_height
) {
610 console_show_cursor(s
, 1);
611 dpy_gfx_update(s
, 0, 0,
612 surface_width(surface
), surface_height(surface
));
616 static void console_scroll(QemuConsole
*s
, int ydelta
)
621 for(i
= 0; i
< ydelta
; i
++) {
622 if (s
->y_displayed
== s
->y_base
)
624 if (++s
->y_displayed
== s
->total_height
)
629 i
= s
->backscroll_height
;
630 if (i
> s
->total_height
- s
->height
)
631 i
= s
->total_height
- s
->height
;
634 y1
+= s
->total_height
;
635 for(i
= 0; i
< ydelta
; i
++) {
636 if (s
->y_displayed
== y1
)
638 if (--s
->y_displayed
< 0)
639 s
->y_displayed
= s
->total_height
- 1;
645 static void console_put_lf(QemuConsole
*s
)
651 if (s
->y
>= s
->height
) {
652 s
->y
= s
->height
- 1;
654 if (s
->y_displayed
== s
->y_base
) {
655 if (++s
->y_displayed
== s
->total_height
)
658 if (++s
->y_base
== s
->total_height
)
660 if (s
->backscroll_height
< s
->total_height
)
661 s
->backscroll_height
++;
662 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
663 c
= &s
->cells
[y1
* s
->width
];
664 for(x
= 0; x
< s
->width
; x
++) {
666 c
->t_attrib
= s
->t_attrib_default
;
669 if (qemu_console_is_visible(s
) && s
->y_displayed
== s
->y_base
) {
670 if (s
->ds
->have_text
) {
673 s
->text_x
[1] = s
->width
- 1;
674 s
->text_y
[1] = s
->height
- 1;
677 if (s
->ds
->have_gfx
) {
678 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
679 s
->width
* FONT_WIDTH
,
680 (s
->height
- 1) * FONT_HEIGHT
);
681 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
682 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
683 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
686 s
->update_x1
= s
->width
* FONT_WIDTH
;
687 s
->update_y1
= s
->height
* FONT_HEIGHT
;
693 /* Set console attributes depending on the current escape codes.
694 * NOTE: I know this code is not very efficient (checking every color for it
695 * self) but it is more readable and better maintainable.
697 static void console_handle_escape(QemuConsole
*s
)
701 for (i
=0; i
<s
->nb_esc_params
; i
++) {
702 switch (s
->esc_params
[i
]) {
703 case 0: /* reset all console attributes to default */
704 s
->t_attrib
= s
->t_attrib_default
;
707 s
->t_attrib
.bold
= 1;
710 s
->t_attrib
.uline
= 1;
713 s
->t_attrib
.blink
= 1;
716 s
->t_attrib
.invers
= 1;
719 s
->t_attrib
.unvisible
= 1;
722 s
->t_attrib
.bold
= 0;
725 s
->t_attrib
.uline
= 0;
728 s
->t_attrib
.blink
= 0;
731 s
->t_attrib
.invers
= 0;
734 s
->t_attrib
.unvisible
= 0;
736 /* set foreground color */
738 s
->t_attrib
.fgcol
=COLOR_BLACK
;
741 s
->t_attrib
.fgcol
=COLOR_RED
;
744 s
->t_attrib
.fgcol
=COLOR_GREEN
;
747 s
->t_attrib
.fgcol
=COLOR_YELLOW
;
750 s
->t_attrib
.fgcol
=COLOR_BLUE
;
753 s
->t_attrib
.fgcol
=COLOR_MAGENTA
;
756 s
->t_attrib
.fgcol
=COLOR_CYAN
;
759 s
->t_attrib
.fgcol
=COLOR_WHITE
;
761 /* set background color */
763 s
->t_attrib
.bgcol
=COLOR_BLACK
;
766 s
->t_attrib
.bgcol
=COLOR_RED
;
769 s
->t_attrib
.bgcol
=COLOR_GREEN
;
772 s
->t_attrib
.bgcol
=COLOR_YELLOW
;
775 s
->t_attrib
.bgcol
=COLOR_BLUE
;
778 s
->t_attrib
.bgcol
=COLOR_MAGENTA
;
781 s
->t_attrib
.bgcol
=COLOR_CYAN
;
784 s
->t_attrib
.bgcol
=COLOR_WHITE
;
790 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
792 int y1
= (s
->y_base
+ y
) % s
->total_height
;
793 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
795 c
->t_attrib
= s
->t_attrib_default
;
799 /* set cursor, checking bounds */
800 static void set_cursor(QemuConsole
*s
, int x
, int y
)
808 if (y
>= s
->height
) {
819 static void console_putchar(QemuConsole
*s
, int ch
)
828 case '\r': /* carriage return */
831 case '\n': /* newline */
834 case '\b': /* backspace */
838 case '\t': /* tabspace */
839 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
843 s
->x
= s
->x
+ (8 - (s
->x
% 8));
846 case '\a': /* alert aka. bell */
847 /* TODO: has to be implemented */
850 /* SI (shift in), character set 0 (ignored) */
853 /* SO (shift out), character set 1 (ignored) */
855 case 27: /* esc (introducing an escape sequence) */
856 s
->state
= TTY_STATE_ESC
;
859 if (s
->x
>= s
->width
) {
864 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
865 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
867 c
->t_attrib
= s
->t_attrib
;
868 update_xy(s
, s
->x
, s
->y
);
873 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
875 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
876 s
->esc_params
[i
] = 0;
877 s
->nb_esc_params
= 0;
878 s
->state
= TTY_STATE_CSI
;
880 s
->state
= TTY_STATE_NORM
;
883 case TTY_STATE_CSI
: /* handle escape sequence parameters */
884 if (ch
>= '0' && ch
<= '9') {
885 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
886 int *param
= &s
->esc_params
[s
->nb_esc_params
];
887 int digit
= (ch
- '0');
889 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
890 *param
* 10 + digit
: INT_MAX
;
893 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
898 fprintf(stderr
, "escape sequence CSI%d;%d%c, %d parameters\n",
899 s
->esc_params
[0], s
->esc_params
[1], ch
, s
->nb_esc_params
);
901 s
->state
= TTY_STATE_NORM
;
905 if (s
->esc_params
[0] == 0) {
906 s
->esc_params
[0] = 1;
908 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
911 /* move cursor down */
912 if (s
->esc_params
[0] == 0) {
913 s
->esc_params
[0] = 1;
915 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
918 /* move cursor right */
919 if (s
->esc_params
[0] == 0) {
920 s
->esc_params
[0] = 1;
922 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
925 /* move cursor left */
926 if (s
->esc_params
[0] == 0) {
927 s
->esc_params
[0] = 1;
929 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
932 /* move cursor to column */
933 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
937 /* move cursor to row, column */
938 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
941 switch (s
->esc_params
[0]) {
943 /* clear to end of screen */
944 for (y
= s
->y
; y
< s
->height
; y
++) {
945 for (x
= 0; x
< s
->width
; x
++) {
946 if (y
== s
->y
&& x
< s
->x
) {
949 console_clear_xy(s
, x
, y
);
954 /* clear from beginning of screen */
955 for (y
= 0; y
<= s
->y
; y
++) {
956 for (x
= 0; x
< s
->width
; x
++) {
957 if (y
== s
->y
&& x
> s
->x
) {
960 console_clear_xy(s
, x
, y
);
965 /* clear entire screen */
966 for (y
= 0; y
<= s
->height
; y
++) {
967 for (x
= 0; x
< s
->width
; x
++) {
968 console_clear_xy(s
, x
, y
);
975 switch (s
->esc_params
[0]) {
978 for(x
= s
->x
; x
< s
->width
; x
++) {
979 console_clear_xy(s
, x
, s
->y
);
983 /* clear from beginning of line */
984 for (x
= 0; x
<= s
->x
; x
++) {
985 console_clear_xy(s
, x
, s
->y
);
989 /* clear entire line */
990 for(x
= 0; x
< s
->width
; x
++) {
991 console_clear_xy(s
, x
, s
->y
);
997 console_handle_escape(s
);
1000 /* report cursor position */
1001 /* TODO: send ESC[row;colR */
1004 /* save cursor position */
1009 /* restore cursor position */
1014 #ifdef DEBUG_CONSOLE
1015 fprintf(stderr
, "unhandled escape character '%c'\n", ch
);
1024 void console_select(unsigned int index
)
1026 DisplayChangeListener
*dcl
;
1029 if (index
>= MAX_CONSOLES
)
1032 trace_console_select(index
);
1033 s
= qemu_console_lookup_by_index(index
);
1035 DisplayState
*ds
= s
->ds
;
1037 if (active_console
&& active_console
->cursor_timer
) {
1038 qemu_del_timer(active_console
->cursor_timer
);
1042 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1043 if (dcl
->con
!= NULL
) {
1046 if (dcl
->ops
->dpy_gfx_switch
) {
1047 dcl
->ops
->dpy_gfx_switch(dcl
, s
->surface
);
1050 dpy_gfx_update(s
, 0, 0, surface_width(s
->surface
),
1051 surface_height(s
->surface
));
1053 if (ds
->have_text
) {
1054 dpy_text_resize(s
, s
->width
, s
->height
);
1056 if (s
->cursor_timer
) {
1057 qemu_mod_timer(s
->cursor_timer
,
1058 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1063 static int console_puts(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1065 QemuConsole
*s
= chr
->opaque
;
1068 s
->update_x0
= s
->width
* FONT_WIDTH
;
1069 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1072 console_show_cursor(s
, 0);
1073 for(i
= 0; i
< len
; i
++) {
1074 console_putchar(s
, buf
[i
]);
1076 console_show_cursor(s
, 1);
1077 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1078 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1079 s
->update_x1
- s
->update_x0
,
1080 s
->update_y1
- s
->update_y0
);
1085 static void kbd_send_chars(void *opaque
)
1087 QemuConsole
*s
= opaque
;
1091 len
= qemu_chr_be_can_write(s
->chr
);
1092 if (len
> s
->out_fifo
.count
)
1093 len
= s
->out_fifo
.count
;
1095 if (len
> sizeof(buf
))
1097 qemu_fifo_read(&s
->out_fifo
, buf
, len
);
1098 qemu_chr_be_write(s
->chr
, buf
, len
);
1100 /* characters are pending: we send them a bit later (XXX:
1101 horrible, should change char device API) */
1102 if (s
->out_fifo
.count
> 0) {
1103 qemu_mod_timer(s
->kbd_timer
, qemu_get_clock_ms(rt_clock
) + 1);
1107 /* called when an ascii key is pressed */
1108 void kbd_put_keysym(int keysym
)
1111 uint8_t buf
[16], *q
;
1115 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1119 case QEMU_KEY_CTRL_UP
:
1120 console_scroll(s
, -1);
1122 case QEMU_KEY_CTRL_DOWN
:
1123 console_scroll(s
, 1);
1125 case QEMU_KEY_CTRL_PAGEUP
:
1126 console_scroll(s
, -10);
1128 case QEMU_KEY_CTRL_PAGEDOWN
:
1129 console_scroll(s
, 10);
1132 /* convert the QEMU keysym to VT100 key string */
1134 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1137 c
= keysym
- 0xe100;
1139 *q
++ = '0' + (c
/ 10);
1140 *q
++ = '0' + (c
% 10);
1142 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1145 *q
++ = keysym
& 0xff;
1146 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1147 console_puts(s
->chr
, (const uint8_t *) "\r", 1);
1153 console_puts(s
->chr
, buf
, q
- buf
);
1155 if (s
->chr
->chr_read
) {
1156 qemu_fifo_write(&s
->out_fifo
, buf
, q
- buf
);
1163 static void text_console_invalidate(void *opaque
)
1165 QemuConsole
*s
= (QemuConsole
*) opaque
;
1167 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1168 text_console_resize(s
);
1173 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1175 QemuConsole
*s
= (QemuConsole
*) opaque
;
1178 if (s
->text_x
[0] <= s
->text_x
[1]) {
1179 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1180 chardata
+= s
->text_y
[0] * s
->width
;
1181 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1182 for (j
= 0; j
< s
->width
; j
++, src
++)
1183 console_write_ch(chardata
++, s
->cells
[src
].ch
|
1184 (s
->cells
[src
].t_attrib
.fgcol
<< 12) |
1185 (s
->cells
[src
].t_attrib
.bgcol
<< 8) |
1186 (s
->cells
[src
].t_attrib
.bold
<< 21));
1187 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1188 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1189 s
->text_x
[0] = s
->width
;
1190 s
->text_y
[0] = s
->height
;
1194 if (s
->cursor_invalidate
) {
1195 dpy_text_cursor(s
, s
->x
, s
->y
);
1196 s
->cursor_invalidate
= 0;
1200 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
)
1206 if (nb_consoles
>= MAX_CONSOLES
)
1208 obj
= object_new(TYPE_QEMU_CONSOLE
);
1209 s
= QEMU_CONSOLE(obj
);
1210 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1211 (console_type
== GRAPHIC_CONSOLE
))) {
1215 s
->console_type
= console_type
;
1216 if (console_type
!= GRAPHIC_CONSOLE
) {
1217 s
->index
= nb_consoles
;
1218 consoles
[nb_consoles
++] = s
;
1220 /* HACK: Put graphical consoles before text consoles. */
1221 for (i
= nb_consoles
; i
> 0; i
--) {
1222 if (consoles
[i
- 1]->console_type
== GRAPHIC_CONSOLE
)
1224 consoles
[i
] = consoles
[i
- 1];
1225 consoles
[i
]->index
= i
;
1234 static void qemu_alloc_display(DisplaySurface
*surface
, int width
, int height
,
1235 int linesize
, PixelFormat pf
, int newflags
)
1239 qemu_pixman_image_unref(surface
->image
);
1240 surface
->image
= NULL
;
1242 surface
->format
= qemu_pixman_get_format(&pf
);
1243 assert(surface
->format
!= 0);
1244 surface
->image
= pixman_image_create_bits(surface
->format
,
1247 assert(surface
->image
!= NULL
);
1249 surface
->flags
= newflags
| QEMU_ALLOCATED_FLAG
;
1250 #ifdef HOST_WORDS_BIGENDIAN
1251 surface
->flags
|= QEMU_BIG_ENDIAN_FLAG
;
1255 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1257 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1258 int linesize
= width
* 4;
1260 trace_displaysurface_create(surface
, width
, height
);
1261 qemu_alloc_display(surface
, width
, height
, linesize
,
1262 qemu_default_pixelformat(32), 0);
1266 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
, int bpp
,
1267 int linesize
, uint8_t *data
,
1270 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1272 trace_displaysurface_create_from(surface
, width
, height
, bpp
, byteswap
);
1274 surface
->pf
= qemu_different_endianness_pixelformat(bpp
);
1276 surface
->pf
= qemu_default_pixelformat(bpp
);
1279 surface
->format
= qemu_pixman_get_format(&surface
->pf
);
1280 assert(surface
->format
!= 0);
1281 surface
->image
= pixman_image_create_bits(surface
->format
,
1283 (void *)data
, linesize
);
1284 assert(surface
->image
!= NULL
);
1286 #ifdef HOST_WORDS_BIGENDIAN
1287 surface
->flags
= QEMU_BIG_ENDIAN_FLAG
;
1293 void qemu_free_displaysurface(DisplaySurface
*surface
)
1295 if (surface
== NULL
) {
1298 trace_displaysurface_free(surface
);
1299 qemu_pixman_image_unref(surface
->image
);
1303 void register_displaychangelistener(DisplayState
*ds
,
1304 DisplayChangeListener
*dcl
)
1308 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1310 QLIST_INSERT_HEAD(&ds
->listeners
, dcl
, next
);
1311 gui_setup_refresh(ds
);
1316 con
= active_console
;
1318 if (dcl
->ops
->dpy_gfx_switch
&& con
) {
1319 dcl
->ops
->dpy_gfx_switch(dcl
, con
->surface
);
1323 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1326 DisplayState
*ds
= dcl
->ds
;
1328 dcl
->update_interval
= interval
;
1329 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1330 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
1334 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1336 DisplayState
*ds
= dcl
->ds
;
1337 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1341 QLIST_REMOVE(dcl
, next
);
1342 gui_setup_refresh(ds
);
1345 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1347 DisplayState
*s
= con
->ds
;
1348 DisplayChangeListener
*dcl
;
1349 int width
= surface_width(con
->surface
);
1350 int height
= surface_height(con
->surface
);
1356 w
= MIN(w
, width
- x
);
1357 h
= MIN(h
, height
- y
);
1359 if (!qemu_console_is_visible(con
)) {
1362 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1363 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1366 if (dcl
->ops
->dpy_gfx_update
) {
1367 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1372 void dpy_gfx_replace_surface(QemuConsole
*con
,
1373 DisplaySurface
*surface
)
1375 DisplayState
*s
= con
->ds
;
1376 DisplaySurface
*old_surface
= con
->surface
;
1377 DisplayChangeListener
*dcl
;
1379 con
->surface
= surface
;
1380 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1381 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1384 if (dcl
->ops
->dpy_gfx_switch
) {
1385 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1388 qemu_free_displaysurface(old_surface
);
1391 void dpy_refresh(DisplayState
*s
)
1393 DisplayChangeListener
*dcl
;
1395 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1396 if (dcl
->ops
->dpy_refresh
) {
1397 dcl
->ops
->dpy_refresh(dcl
);
1402 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
1403 int dst_x
, int dst_y
, int w
, int h
)
1405 DisplayState
*s
= con
->ds
;
1406 DisplayChangeListener
*dcl
;
1408 if (!qemu_console_is_visible(con
)) {
1411 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1412 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1415 if (dcl
->ops
->dpy_gfx_copy
) {
1416 dcl
->ops
->dpy_gfx_copy(dcl
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1418 dcl
->ops
->dpy_gfx_update(dcl
, dst_x
, dst_y
, w
, h
);
1423 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1425 DisplayState
*s
= con
->ds
;
1426 DisplayChangeListener
*dcl
;
1428 if (!qemu_console_is_visible(con
)) {
1431 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1432 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1435 if (dcl
->ops
->dpy_text_cursor
) {
1436 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1441 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1443 DisplayState
*s
= con
->ds
;
1444 DisplayChangeListener
*dcl
;
1446 if (!qemu_console_is_visible(con
)) {
1449 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1450 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1453 if (dcl
->ops
->dpy_text_update
) {
1454 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1459 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1461 DisplayState
*s
= con
->ds
;
1462 struct DisplayChangeListener
*dcl
;
1464 if (!qemu_console_is_visible(con
)) {
1467 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1468 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1471 if (dcl
->ops
->dpy_text_resize
) {
1472 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1477 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1479 DisplayState
*s
= con
->ds
;
1480 DisplayChangeListener
*dcl
;
1482 if (!qemu_console_is_visible(con
)) {
1485 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1486 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1489 if (dcl
->ops
->dpy_mouse_set
) {
1490 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1495 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1497 DisplayState
*s
= con
->ds
;
1498 DisplayChangeListener
*dcl
;
1500 if (!qemu_console_is_visible(con
)) {
1503 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1504 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1507 if (dcl
->ops
->dpy_cursor_define
) {
1508 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1513 bool dpy_cursor_define_supported(QemuConsole
*con
)
1515 DisplayState
*s
= con
->ds
;
1516 DisplayChangeListener
*dcl
;
1518 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1519 if (dcl
->ops
->dpy_cursor_define
) {
1526 /***********************************************************/
1527 /* register display */
1529 /* console.c internal use only */
1530 static DisplayState
*get_alloc_displaystate(void)
1532 if (!display_state
) {
1533 display_state
= g_new0(DisplayState
, 1);
1535 return display_state
;
1539 * Called by main(), after creating QemuConsoles
1540 * and before initializing ui (sdl/vnc/...).
1542 DisplayState
*init_displaystate(void)
1546 if (!display_state
) {
1547 display_state
= g_new0(DisplayState
, 1);
1550 for (i
= 0; i
< nb_consoles
; i
++) {
1551 if (consoles
[i
]->console_type
!= GRAPHIC_CONSOLE
&&
1552 consoles
[i
]->ds
== NULL
) {
1553 text_console_do_init(consoles
[i
]->chr
, display_state
);
1557 return display_state
;
1560 QemuConsole
*graphic_console_init(const GraphicHwOps
*hw_ops
,
1568 ds
= get_alloc_displaystate();
1569 trace_console_gfx_new();
1570 s
= new_console(ds
, GRAPHIC_CONSOLE
);
1574 s
->surface
= qemu_create_displaysurface(width
, height
);
1578 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
1580 if (index
>= MAX_CONSOLES
) {
1583 return consoles
[index
];
1586 bool qemu_console_is_visible(QemuConsole
*con
)
1588 return (con
== active_console
) || (con
->dcls
> 0);
1591 bool qemu_console_is_graphic(QemuConsole
*con
)
1594 con
= active_console
;
1596 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
1599 bool qemu_console_is_fixedsize(QemuConsole
*con
)
1602 con
= active_console
;
1604 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
1607 static void text_console_set_echo(CharDriverState
*chr
, bool echo
)
1609 QemuConsole
*s
= chr
->opaque
;
1614 static void text_console_update_cursor(void *opaque
)
1616 QemuConsole
*s
= opaque
;
1618 s
->cursor_visible_phase
= !s
->cursor_visible_phase
;
1619 graphic_hw_invalidate(s
);
1620 qemu_mod_timer(s
->cursor_timer
,
1621 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1624 static const GraphicHwOps text_console_ops
= {
1625 .invalidate
= text_console_invalidate
,
1626 .text_update
= text_console_update
,
1629 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
)
1632 int g_width
= 80 * FONT_WIDTH
;
1633 int g_height
= 24 * FONT_HEIGHT
;
1637 chr
->chr_write
= console_puts
;
1639 s
->out_fifo
.buf
= s
->out_fifo_buf
;
1640 s
->out_fifo
.buf_size
= sizeof(s
->out_fifo_buf
);
1641 s
->kbd_timer
= qemu_new_timer_ms(rt_clock
, kbd_send_chars
, s
);
1646 s
->total_height
= DEFAULT_BACKSCROLL
;
1650 if (active_console
&& active_console
->surface
) {
1651 g_width
= surface_width(active_console
->surface
);
1652 g_height
= surface_height(active_console
->surface
);
1654 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
1658 qemu_new_timer_ms(rt_clock
, text_console_update_cursor
, s
);
1660 s
->hw_ops
= &text_console_ops
;
1663 /* Set text attribute defaults */
1664 s
->t_attrib_default
.bold
= 0;
1665 s
->t_attrib_default
.uline
= 0;
1666 s
->t_attrib_default
.blink
= 0;
1667 s
->t_attrib_default
.invers
= 0;
1668 s
->t_attrib_default
.unvisible
= 0;
1669 s
->t_attrib_default
.fgcol
= COLOR_WHITE
;
1670 s
->t_attrib_default
.bgcol
= COLOR_BLACK
;
1671 /* set current text attributes to default */
1672 s
->t_attrib
= s
->t_attrib_default
;
1673 text_console_resize(s
);
1679 s
->t_attrib
.bgcol
= COLOR_BLUE
;
1680 len
= snprintf(msg
, sizeof(msg
), "%s console\r\n", chr
->label
);
1681 console_puts(chr
, (uint8_t*)msg
, len
);
1682 s
->t_attrib
= s
->t_attrib_default
;
1685 qemu_chr_be_generic_open(chr
);
1690 static CharDriverState
*text_console_init(ChardevVC
*vc
)
1692 CharDriverState
*chr
;
1695 unsigned height
= 0;
1697 chr
= g_malloc0(sizeof(CharDriverState
));
1699 if (vc
->has_width
) {
1701 } else if (vc
->has_cols
) {
1702 width
= vc
->cols
* FONT_WIDTH
;
1705 if (vc
->has_height
) {
1706 height
= vc
->height
;
1707 } else if (vc
->has_rows
) {
1708 height
= vc
->rows
* FONT_HEIGHT
;
1711 trace_console_txt_new(width
, height
);
1712 if (width
== 0 || height
== 0) {
1713 s
= new_console(NULL
, TEXT_CONSOLE
);
1715 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
);
1716 s
->surface
= qemu_create_displaysurface(width
, height
);
1726 chr
->chr_set_echo
= text_console_set_echo
;
1728 if (display_state
) {
1729 text_console_do_init(chr
, display_state
);
1734 static VcHandler
*vc_handler
= text_console_init
;
1736 CharDriverState
*vc_init(ChardevVC
*vc
)
1738 return vc_handler(vc
);
1741 void register_vc_handler(VcHandler
*handler
)
1743 vc_handler
= handler
;
1746 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
1748 DisplaySurface
*surface
;
1750 assert(s
->console_type
== GRAPHIC_CONSOLE
);
1751 surface
= qemu_create_displaysurface(width
, height
);
1752 dpy_gfx_replace_surface(s
, surface
);
1755 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
1756 int dst_x
, int dst_y
, int w
, int h
)
1758 assert(con
->console_type
== GRAPHIC_CONSOLE
);
1759 dpy_gfx_copy(con
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1762 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
1764 return console
->surface
;
1767 DisplayState
*qemu_console_displaystate(QemuConsole
*console
)
1772 PixelFormat
qemu_different_endianness_pixelformat(int bpp
)
1776 memset(&pf
, 0x00, sizeof(PixelFormat
));
1778 pf
.bits_per_pixel
= bpp
;
1779 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1780 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1784 pf
.rmask
= 0x000000FF;
1785 pf
.gmask
= 0x0000FF00;
1786 pf
.bmask
= 0x00FF0000;
1798 pf
.rmask
= 0x0000FF00;
1799 pf
.gmask
= 0x00FF0000;
1800 pf
.bmask
= 0xFF000000;
1801 pf
.amask
= 0x00000000;
1821 PixelFormat
qemu_default_pixelformat(int bpp
)
1825 memset(&pf
, 0x00, sizeof(PixelFormat
));
1827 pf
.bits_per_pixel
= bpp
;
1828 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1829 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1833 pf
.bits_per_pixel
= 16;
1834 pf
.rmask
= 0x00007c00;
1835 pf
.gmask
= 0x000003E0;
1836 pf
.bmask
= 0x0000001F;
1848 pf
.rmask
= 0x0000F800;
1849 pf
.gmask
= 0x000007E0;
1850 pf
.bmask
= 0x0000001F;
1862 pf
.rmask
= 0x00FF0000;
1863 pf
.gmask
= 0x0000FF00;
1864 pf
.bmask
= 0x000000FF;
1876 pf
.rmask
= 0x00FF0000;
1877 pf
.gmask
= 0x0000FF00;
1878 pf
.bmask
= 0x000000FF;
1895 static void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
,
1900 backend
->vc
= g_new0(ChardevVC
, 1);
1902 val
= qemu_opt_get_number(opts
, "width", 0);
1904 backend
->vc
->has_width
= true;
1905 backend
->vc
->width
= val
;
1908 val
= qemu_opt_get_number(opts
, "height", 0);
1910 backend
->vc
->has_height
= true;
1911 backend
->vc
->height
= val
;
1914 val
= qemu_opt_get_number(opts
, "cols", 0);
1916 backend
->vc
->has_cols
= true;
1917 backend
->vc
->cols
= val
;
1920 val
= qemu_opt_get_number(opts
, "rows", 0);
1922 backend
->vc
->has_rows
= true;
1923 backend
->vc
->rows
= val
;
1927 static const TypeInfo qemu_console_info
= {
1928 .name
= TYPE_QEMU_CONSOLE
,
1929 .parent
= TYPE_OBJECT
,
1930 .instance_size
= sizeof(QemuConsole
),
1931 .class_size
= sizeof(QemuConsoleClass
),
1935 static void register_types(void)
1937 type_register_static(&qemu_console_info
);
1938 register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC
,
1942 type_init(register_types
);