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"
31 //#define DEBUG_CONSOLE
32 #define DEFAULT_BACKSCROLL 512
33 #define MAX_CONSOLES 12
34 #define CONSOLE_CURSOR_PERIOD 500
36 typedef struct TextAttributes
{
46 typedef struct TextCell
{
48 TextAttributes t_attrib
;
51 #define MAX_ESC_PARAMS 3
59 typedef struct QEMUFIFO
{
62 int count
, wptr
, rptr
;
65 static int qemu_fifo_write(QEMUFIFO
*f
, const uint8_t *buf
, int len1
)
69 l
= f
->buf_size
- f
->count
;
74 l
= f
->buf_size
- f
->wptr
;
77 memcpy(f
->buf
+ f
->wptr
, buf
, l
);
79 if (f
->wptr
>= f
->buf_size
)
88 static int qemu_fifo_read(QEMUFIFO
*f
, uint8_t *buf
, int len1
)
96 l
= f
->buf_size
- f
->rptr
;
99 memcpy(buf
, f
->buf
+ f
->rptr
, l
);
101 if (f
->rptr
>= f
->buf_size
)
113 TEXT_CONSOLE_FIXED_SIZE
120 console_type_t console_type
;
122 DisplaySurface
*surface
;
125 /* Graphic console state. */
127 const GraphicHwOps
*hw_ops
;
130 /* Text console state */
134 int backscroll_height
;
136 int x_saved
, y_saved
;
139 TextAttributes t_attrib_default
; /* default text attributes */
140 TextAttributes t_attrib
; /* currently active text attributes */
142 int text_x
[2], text_y
[2], cursor_invalidate
;
144 bool cursor_visible_phase
;
145 QEMUTimer
*cursor_timer
;
153 int esc_params
[MAX_ESC_PARAMS
];
156 CharDriverState
*chr
;
157 /* fifo for key pressed */
159 uint8_t out_fifo_buf
[16];
160 QEMUTimer
*kbd_timer
;
163 struct DisplayState
{
164 struct QEMUTimer
*gui_timer
;
165 uint64_t last_update
;
166 uint64_t update_interval
;
171 QLIST_HEAD(, DisplayChangeListener
) listeners
;
174 static DisplayState
*display_state
;
175 static QemuConsole
*active_console
;
176 static QemuConsole
*consoles
[MAX_CONSOLES
];
177 static int nb_consoles
= 0;
179 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
);
180 static void dpy_refresh(DisplayState
*s
);
182 static void gui_update(void *opaque
)
184 uint64_t interval
= GUI_REFRESH_INTERVAL_IDLE
;
185 uint64_t dcl_interval
;
186 DisplayState
*ds
= opaque
;
187 DisplayChangeListener
*dcl
;
190 ds
->refreshing
= true;
192 ds
->refreshing
= false;
194 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
195 dcl_interval
= dcl
->update_interval
?
196 dcl
->update_interval
: GUI_REFRESH_INTERVAL_DEFAULT
;
197 if (interval
> dcl_interval
) {
198 interval
= dcl_interval
;
201 if (ds
->update_interval
!= interval
) {
202 ds
->update_interval
= interval
;
203 for (i
= 0; i
< nb_consoles
; i
++) {
204 if (consoles
[i
]->hw_ops
->update_interval
) {
205 consoles
[i
]->hw_ops
->update_interval(consoles
[i
]->hw
, interval
);
208 trace_console_refresh(interval
);
210 ds
->last_update
= qemu_get_clock_ms(rt_clock
);
211 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
214 static void gui_setup_refresh(DisplayState
*ds
)
216 DisplayChangeListener
*dcl
;
217 bool need_timer
= false;
218 bool have_gfx
= false;
219 bool have_text
= false;
221 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
222 if (dcl
->ops
->dpy_refresh
!= NULL
) {
225 if (dcl
->ops
->dpy_gfx_update
!= NULL
) {
228 if (dcl
->ops
->dpy_text_update
!= NULL
) {
233 if (need_timer
&& ds
->gui_timer
== NULL
) {
234 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
235 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
237 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
238 qemu_del_timer(ds
->gui_timer
);
239 qemu_free_timer(ds
->gui_timer
);
240 ds
->gui_timer
= NULL
;
243 ds
->have_gfx
= have_gfx
;
244 ds
->have_text
= have_text
;
247 void graphic_hw_update(QemuConsole
*con
)
250 con
= active_console
;
252 if (con
&& con
->hw_ops
->gfx_update
) {
253 con
->hw_ops
->gfx_update(con
->hw
);
257 void graphic_hw_invalidate(QemuConsole
*con
)
260 con
= active_console
;
262 if (con
&& con
->hw_ops
->invalidate
) {
263 con
->hw_ops
->invalidate(con
->hw
);
267 static void ppm_save(const char *filename
, struct DisplaySurface
*ds
,
270 int width
= pixman_image_get_width(ds
->image
);
271 int height
= pixman_image_get_height(ds
->image
);
275 pixman_image_t
*linebuf
;
277 trace_ppm_save(filename
, ds
);
278 f
= fopen(filename
, "wb");
280 error_setg(errp
, "failed to open file '%s': %s", filename
,
284 ret
= fprintf(f
, "P6\n%d %d\n%d\n", width
, height
, 255);
289 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
290 for (y
= 0; y
< height
; y
++) {
291 qemu_pixman_linebuf_fill(linebuf
, ds
->image
, width
, 0, y
);
293 ret
= fwrite(pixman_image_get_data(linebuf
), 1,
294 pixman_image_get_stride(linebuf
), f
);
302 qemu_pixman_image_unref(linebuf
);
307 error_setg(errp
, "failed to write to file '%s': %s", filename
,
313 void qmp_screendump(const char *filename
, Error
**errp
)
315 QemuConsole
*con
= qemu_console_lookup_by_index(0);
316 DisplaySurface
*surface
;
319 error_setg(errp
, "There is no QemuConsole I can screendump from.");
323 graphic_hw_update(con
);
324 surface
= qemu_console_surface(con
);
325 ppm_save(filename
, surface
, errp
);
328 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
331 con
= active_console
;
333 if (con
&& con
->hw_ops
->text_update
) {
334 con
->hw_ops
->text_update(con
->hw
, chardata
);
338 static void vga_fill_rect(QemuConsole
*con
,
339 int posx
, int posy
, int width
, int height
,
340 pixman_color_t color
)
342 DisplaySurface
*surface
= qemu_console_surface(con
);
343 pixman_rectangle16_t rect
= {
344 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
347 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
351 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
352 static void vga_bitblt(QemuConsole
*con
,
353 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
355 DisplaySurface
*surface
= qemu_console_surface(con
);
357 pixman_image_composite(PIXMAN_OP_SRC
,
358 surface
->image
, NULL
, surface
->image
,
359 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
362 /***********************************************************/
363 /* basic char display */
365 #define FONT_HEIGHT 16
370 #ifndef CONFIG_CURSES
383 #define QEMU_RGB(r, g, b) \
384 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
386 static const pixman_color_t color_table_rgb
[2][8] = {
388 QEMU_RGB(0x00, 0x00, 0x00), /* black */
389 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
390 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
391 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
392 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
393 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
394 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
395 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
398 QEMU_RGB(0x00, 0x00, 0x00), /* black */
399 QEMU_RGB(0xff, 0x00, 0x00), /* red */
400 QEMU_RGB(0x00, 0xff, 0x00), /* green */
401 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
402 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
403 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
404 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
405 QEMU_RGB(0xff, 0xff, 0xff), /* white */
410 static void console_print_text_attributes(TextAttributes
*t_attrib
, char ch
)
412 if (t_attrib
->bold
) {
417 if (t_attrib
->uline
) {
422 if (t_attrib
->blink
) {
427 if (t_attrib
->invers
) {
432 if (t_attrib
->unvisible
) {
438 printf(" fg: %d bg: %d ch:'%2X' '%c'\n", t_attrib
->fgcol
, t_attrib
->bgcol
, ch
, ch
);
442 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
443 TextAttributes
*t_attrib
)
445 static pixman_image_t
*glyphs
[256];
446 DisplaySurface
*surface
= qemu_console_surface(s
);
447 pixman_color_t fgcol
, bgcol
;
449 if (t_attrib
->invers
) {
450 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
451 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
453 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
454 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
458 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
460 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
461 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
464 static void text_console_resize(QemuConsole
*s
)
466 TextCell
*cells
, *c
, *c1
;
467 int w1
, x
, y
, last_width
;
469 last_width
= s
->width
;
470 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
471 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
477 cells
= g_malloc(s
->width
* s
->total_height
* sizeof(TextCell
));
478 for(y
= 0; y
< s
->total_height
; y
++) {
479 c
= &cells
[y
* s
->width
];
481 c1
= &s
->cells
[y
* last_width
];
482 for(x
= 0; x
< w1
; x
++) {
486 for(x
= w1
; x
< s
->width
; x
++) {
488 c
->t_attrib
= s
->t_attrib_default
;
496 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
498 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
499 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
500 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
501 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
504 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
506 if (s
->update_x0
> x
* FONT_WIDTH
)
507 s
->update_x0
= x
* FONT_WIDTH
;
508 if (s
->update_y0
> y
* FONT_HEIGHT
)
509 s
->update_y0
= y
* FONT_HEIGHT
;
510 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
511 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
512 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
513 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
516 static void update_xy(QemuConsole
*s
, int x
, int y
)
521 if (!qemu_console_is_visible(s
)) {
525 if (s
->ds
->have_text
) {
526 text_update_xy(s
, x
, y
);
529 if (s
->ds
->have_gfx
) {
530 y1
= (s
->y_base
+ y
) % s
->total_height
;
531 y2
= y1
- s
->y_displayed
;
533 y2
+= s
->total_height
;
534 if (y2
< s
->height
) {
535 c
= &s
->cells
[y1
* s
->width
+ x
];
536 vga_putcharxy(s
, x
, y2
, c
->ch
,
538 invalidate_xy(s
, x
, y2
);
543 static void console_show_cursor(QemuConsole
*s
, int show
)
549 if (!qemu_console_is_visible(s
)) {
553 if (s
->ds
->have_text
) {
554 s
->cursor_invalidate
= 1;
557 if (s
->ds
->have_gfx
) {
561 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
562 y
= y1
- s
->y_displayed
;
564 y
+= s
->total_height
;
566 c
= &s
->cells
[y1
* s
->width
+ x
];
567 if (show
&& s
->cursor_visible_phase
) {
568 TextAttributes t_attrib
= s
->t_attrib_default
;
569 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
570 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
572 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
574 invalidate_xy(s
, x
, y
);
579 static void console_refresh(QemuConsole
*s
)
581 DisplaySurface
*surface
= qemu_console_surface(s
);
585 if (!qemu_console_is_visible(s
)) {
589 if (s
->ds
->have_text
) {
592 s
->text_x
[1] = s
->width
- 1;
593 s
->text_y
[1] = s
->height
- 1;
594 s
->cursor_invalidate
= 1;
597 if (s
->ds
->have_gfx
) {
598 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
599 color_table_rgb
[0][COLOR_BLACK
]);
601 for (y
= 0; y
< s
->height
; y
++) {
602 c
= s
->cells
+ y1
* s
->width
;
603 for (x
= 0; x
< s
->width
; x
++) {
604 vga_putcharxy(s
, x
, y
, c
->ch
,
608 if (++y1
== s
->total_height
) {
612 console_show_cursor(s
, 1);
613 dpy_gfx_update(s
, 0, 0,
614 surface_width(surface
), surface_height(surface
));
618 static void console_scroll(QemuConsole
*s
, int ydelta
)
623 for(i
= 0; i
< ydelta
; i
++) {
624 if (s
->y_displayed
== s
->y_base
)
626 if (++s
->y_displayed
== s
->total_height
)
631 i
= s
->backscroll_height
;
632 if (i
> s
->total_height
- s
->height
)
633 i
= s
->total_height
- s
->height
;
636 y1
+= s
->total_height
;
637 for(i
= 0; i
< ydelta
; i
++) {
638 if (s
->y_displayed
== y1
)
640 if (--s
->y_displayed
< 0)
641 s
->y_displayed
= s
->total_height
- 1;
647 static void console_put_lf(QemuConsole
*s
)
653 if (s
->y
>= s
->height
) {
654 s
->y
= s
->height
- 1;
656 if (s
->y_displayed
== s
->y_base
) {
657 if (++s
->y_displayed
== s
->total_height
)
660 if (++s
->y_base
== s
->total_height
)
662 if (s
->backscroll_height
< s
->total_height
)
663 s
->backscroll_height
++;
664 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
665 c
= &s
->cells
[y1
* s
->width
];
666 for(x
= 0; x
< s
->width
; x
++) {
668 c
->t_attrib
= s
->t_attrib_default
;
671 if (qemu_console_is_visible(s
) && s
->y_displayed
== s
->y_base
) {
672 if (s
->ds
->have_text
) {
675 s
->text_x
[1] = s
->width
- 1;
676 s
->text_y
[1] = s
->height
- 1;
679 if (s
->ds
->have_gfx
) {
680 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
681 s
->width
* FONT_WIDTH
,
682 (s
->height
- 1) * FONT_HEIGHT
);
683 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
684 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
685 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
688 s
->update_x1
= s
->width
* FONT_WIDTH
;
689 s
->update_y1
= s
->height
* FONT_HEIGHT
;
695 /* Set console attributes depending on the current escape codes.
696 * NOTE: I know this code is not very efficient (checking every color for it
697 * self) but it is more readable and better maintainable.
699 static void console_handle_escape(QemuConsole
*s
)
703 for (i
=0; i
<s
->nb_esc_params
; i
++) {
704 switch (s
->esc_params
[i
]) {
705 case 0: /* reset all console attributes to default */
706 s
->t_attrib
= s
->t_attrib_default
;
709 s
->t_attrib
.bold
= 1;
712 s
->t_attrib
.uline
= 1;
715 s
->t_attrib
.blink
= 1;
718 s
->t_attrib
.invers
= 1;
721 s
->t_attrib
.unvisible
= 1;
724 s
->t_attrib
.bold
= 0;
727 s
->t_attrib
.uline
= 0;
730 s
->t_attrib
.blink
= 0;
733 s
->t_attrib
.invers
= 0;
736 s
->t_attrib
.unvisible
= 0;
738 /* set foreground color */
740 s
->t_attrib
.fgcol
=COLOR_BLACK
;
743 s
->t_attrib
.fgcol
=COLOR_RED
;
746 s
->t_attrib
.fgcol
=COLOR_GREEN
;
749 s
->t_attrib
.fgcol
=COLOR_YELLOW
;
752 s
->t_attrib
.fgcol
=COLOR_BLUE
;
755 s
->t_attrib
.fgcol
=COLOR_MAGENTA
;
758 s
->t_attrib
.fgcol
=COLOR_CYAN
;
761 s
->t_attrib
.fgcol
=COLOR_WHITE
;
763 /* set background color */
765 s
->t_attrib
.bgcol
=COLOR_BLACK
;
768 s
->t_attrib
.bgcol
=COLOR_RED
;
771 s
->t_attrib
.bgcol
=COLOR_GREEN
;
774 s
->t_attrib
.bgcol
=COLOR_YELLOW
;
777 s
->t_attrib
.bgcol
=COLOR_BLUE
;
780 s
->t_attrib
.bgcol
=COLOR_MAGENTA
;
783 s
->t_attrib
.bgcol
=COLOR_CYAN
;
786 s
->t_attrib
.bgcol
=COLOR_WHITE
;
792 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
794 int y1
= (s
->y_base
+ y
) % s
->total_height
;
795 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
797 c
->t_attrib
= s
->t_attrib_default
;
801 /* set cursor, checking bounds */
802 static void set_cursor(QemuConsole
*s
, int x
, int y
)
810 if (y
>= s
->height
) {
821 static void console_putchar(QemuConsole
*s
, int ch
)
830 case '\r': /* carriage return */
833 case '\n': /* newline */
836 case '\b': /* backspace */
840 case '\t': /* tabspace */
841 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
845 s
->x
= s
->x
+ (8 - (s
->x
% 8));
848 case '\a': /* alert aka. bell */
849 /* TODO: has to be implemented */
852 /* SI (shift in), character set 0 (ignored) */
855 /* SO (shift out), character set 1 (ignored) */
857 case 27: /* esc (introducing an escape sequence) */
858 s
->state
= TTY_STATE_ESC
;
861 if (s
->x
>= s
->width
) {
866 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
867 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
869 c
->t_attrib
= s
->t_attrib
;
870 update_xy(s
, s
->x
, s
->y
);
875 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
877 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
878 s
->esc_params
[i
] = 0;
879 s
->nb_esc_params
= 0;
880 s
->state
= TTY_STATE_CSI
;
882 s
->state
= TTY_STATE_NORM
;
885 case TTY_STATE_CSI
: /* handle escape sequence parameters */
886 if (ch
>= '0' && ch
<= '9') {
887 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
888 int *param
= &s
->esc_params
[s
->nb_esc_params
];
889 int digit
= (ch
- '0');
891 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
892 *param
* 10 + digit
: INT_MAX
;
895 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
900 fprintf(stderr
, "escape sequence CSI%d;%d%c, %d parameters\n",
901 s
->esc_params
[0], s
->esc_params
[1], ch
, s
->nb_esc_params
);
903 s
->state
= TTY_STATE_NORM
;
907 if (s
->esc_params
[0] == 0) {
908 s
->esc_params
[0] = 1;
910 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
913 /* move cursor down */
914 if (s
->esc_params
[0] == 0) {
915 s
->esc_params
[0] = 1;
917 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
920 /* move cursor right */
921 if (s
->esc_params
[0] == 0) {
922 s
->esc_params
[0] = 1;
924 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
927 /* move cursor left */
928 if (s
->esc_params
[0] == 0) {
929 s
->esc_params
[0] = 1;
931 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
934 /* move cursor to column */
935 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
939 /* move cursor to row, column */
940 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
943 switch (s
->esc_params
[0]) {
945 /* clear to end of screen */
946 for (y
= s
->y
; y
< s
->height
; y
++) {
947 for (x
= 0; x
< s
->width
; x
++) {
948 if (y
== s
->y
&& x
< s
->x
) {
951 console_clear_xy(s
, x
, y
);
956 /* clear from beginning of screen */
957 for (y
= 0; y
<= s
->y
; y
++) {
958 for (x
= 0; x
< s
->width
; x
++) {
959 if (y
== s
->y
&& x
> s
->x
) {
962 console_clear_xy(s
, x
, y
);
967 /* clear entire screen */
968 for (y
= 0; y
<= s
->height
; y
++) {
969 for (x
= 0; x
< s
->width
; x
++) {
970 console_clear_xy(s
, x
, y
);
977 switch (s
->esc_params
[0]) {
980 for(x
= s
->x
; x
< s
->width
; x
++) {
981 console_clear_xy(s
, x
, s
->y
);
985 /* clear from beginning of line */
986 for (x
= 0; x
<= s
->x
; x
++) {
987 console_clear_xy(s
, x
, s
->y
);
991 /* clear entire line */
992 for(x
= 0; x
< s
->width
; x
++) {
993 console_clear_xy(s
, x
, s
->y
);
999 console_handle_escape(s
);
1002 /* report cursor position */
1003 /* TODO: send ESC[row;colR */
1006 /* save cursor position */
1011 /* restore cursor position */
1016 #ifdef DEBUG_CONSOLE
1017 fprintf(stderr
, "unhandled escape character '%c'\n", ch
);
1026 void console_select(unsigned int index
)
1028 DisplayChangeListener
*dcl
;
1031 if (index
>= MAX_CONSOLES
)
1034 trace_console_select(index
);
1035 s
= qemu_console_lookup_by_index(index
);
1037 DisplayState
*ds
= s
->ds
;
1039 if (active_console
&& active_console
->cursor_timer
) {
1040 qemu_del_timer(active_console
->cursor_timer
);
1044 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1045 if (dcl
->con
!= NULL
) {
1048 if (dcl
->ops
->dpy_gfx_switch
) {
1049 dcl
->ops
->dpy_gfx_switch(dcl
, s
->surface
);
1052 dpy_gfx_update(s
, 0, 0, surface_width(s
->surface
),
1053 surface_height(s
->surface
));
1055 if (ds
->have_text
) {
1056 dpy_text_resize(s
, s
->width
, s
->height
);
1058 if (s
->cursor_timer
) {
1059 qemu_mod_timer(s
->cursor_timer
,
1060 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1065 static int console_puts(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1067 QemuConsole
*s
= chr
->opaque
;
1070 s
->update_x0
= s
->width
* FONT_WIDTH
;
1071 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1074 console_show_cursor(s
, 0);
1075 for(i
= 0; i
< len
; i
++) {
1076 console_putchar(s
, buf
[i
]);
1078 console_show_cursor(s
, 1);
1079 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1080 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1081 s
->update_x1
- s
->update_x0
,
1082 s
->update_y1
- s
->update_y0
);
1087 static void kbd_send_chars(void *opaque
)
1089 QemuConsole
*s
= opaque
;
1093 len
= qemu_chr_be_can_write(s
->chr
);
1094 if (len
> s
->out_fifo
.count
)
1095 len
= s
->out_fifo
.count
;
1097 if (len
> sizeof(buf
))
1099 qemu_fifo_read(&s
->out_fifo
, buf
, len
);
1100 qemu_chr_be_write(s
->chr
, buf
, len
);
1102 /* characters are pending: we send them a bit later (XXX:
1103 horrible, should change char device API) */
1104 if (s
->out_fifo
.count
> 0) {
1105 qemu_mod_timer(s
->kbd_timer
, qemu_get_clock_ms(rt_clock
) + 1);
1109 /* called when an ascii key is pressed */
1110 void kbd_put_keysym(int keysym
)
1113 uint8_t buf
[16], *q
;
1117 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1121 case QEMU_KEY_CTRL_UP
:
1122 console_scroll(s
, -1);
1124 case QEMU_KEY_CTRL_DOWN
:
1125 console_scroll(s
, 1);
1127 case QEMU_KEY_CTRL_PAGEUP
:
1128 console_scroll(s
, -10);
1130 case QEMU_KEY_CTRL_PAGEDOWN
:
1131 console_scroll(s
, 10);
1134 /* convert the QEMU keysym to VT100 key string */
1136 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1139 c
= keysym
- 0xe100;
1141 *q
++ = '0' + (c
/ 10);
1142 *q
++ = '0' + (c
% 10);
1144 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1147 *q
++ = keysym
& 0xff;
1148 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1149 console_puts(s
->chr
, (const uint8_t *) "\r", 1);
1155 console_puts(s
->chr
, buf
, q
- buf
);
1157 if (s
->chr
->chr_read
) {
1158 qemu_fifo_write(&s
->out_fifo
, buf
, q
- buf
);
1165 static void text_console_invalidate(void *opaque
)
1167 QemuConsole
*s
= (QemuConsole
*) opaque
;
1169 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1170 text_console_resize(s
);
1175 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1177 QemuConsole
*s
= (QemuConsole
*) opaque
;
1180 if (s
->text_x
[0] <= s
->text_x
[1]) {
1181 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1182 chardata
+= s
->text_y
[0] * s
->width
;
1183 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1184 for (j
= 0; j
< s
->width
; j
++, src
++)
1185 console_write_ch(chardata
++, s
->cells
[src
].ch
|
1186 (s
->cells
[src
].t_attrib
.fgcol
<< 12) |
1187 (s
->cells
[src
].t_attrib
.bgcol
<< 8) |
1188 (s
->cells
[src
].t_attrib
.bold
<< 21));
1189 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1190 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1191 s
->text_x
[0] = s
->width
;
1192 s
->text_y
[0] = s
->height
;
1196 if (s
->cursor_invalidate
) {
1197 dpy_text_cursor(s
, s
->x
, s
->y
);
1198 s
->cursor_invalidate
= 0;
1202 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
)
1204 Error
*local_err
= NULL
;
1209 if (nb_consoles
>= MAX_CONSOLES
)
1212 obj
= object_new(TYPE_QEMU_CONSOLE
);
1213 s
= QEMU_CONSOLE(obj
);
1214 object_property_add_link(obj
, "device", TYPE_DEVICE
,
1215 (Object
**)&s
->device
, &local_err
);
1217 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1218 (console_type
== GRAPHIC_CONSOLE
))) {
1222 s
->console_type
= console_type
;
1223 if (console_type
!= GRAPHIC_CONSOLE
) {
1224 s
->index
= nb_consoles
;
1225 consoles
[nb_consoles
++] = s
;
1227 /* HACK: Put graphical consoles before text consoles. */
1228 for (i
= nb_consoles
; i
> 0; i
--) {
1229 if (consoles
[i
- 1]->console_type
== GRAPHIC_CONSOLE
)
1231 consoles
[i
] = consoles
[i
- 1];
1232 consoles
[i
]->index
= i
;
1241 static void qemu_alloc_display(DisplaySurface
*surface
, int width
, int height
,
1242 int linesize
, PixelFormat pf
, int newflags
)
1246 qemu_pixman_image_unref(surface
->image
);
1247 surface
->image
= NULL
;
1249 surface
->format
= qemu_pixman_get_format(&pf
);
1250 assert(surface
->format
!= 0);
1251 surface
->image
= pixman_image_create_bits(surface
->format
,
1254 assert(surface
->image
!= NULL
);
1256 surface
->flags
= newflags
| QEMU_ALLOCATED_FLAG
;
1257 #ifdef HOST_WORDS_BIGENDIAN
1258 surface
->flags
|= QEMU_BIG_ENDIAN_FLAG
;
1262 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1264 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1265 int linesize
= width
* 4;
1267 trace_displaysurface_create(surface
, width
, height
);
1268 qemu_alloc_display(surface
, width
, height
, linesize
,
1269 qemu_default_pixelformat(32), 0);
1273 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
, int bpp
,
1274 int linesize
, uint8_t *data
,
1277 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1279 trace_displaysurface_create_from(surface
, width
, height
, bpp
, byteswap
);
1281 surface
->pf
= qemu_different_endianness_pixelformat(bpp
);
1283 surface
->pf
= qemu_default_pixelformat(bpp
);
1286 surface
->format
= qemu_pixman_get_format(&surface
->pf
);
1287 assert(surface
->format
!= 0);
1288 surface
->image
= pixman_image_create_bits(surface
->format
,
1290 (void *)data
, linesize
);
1291 assert(surface
->image
!= NULL
);
1293 #ifdef HOST_WORDS_BIGENDIAN
1294 surface
->flags
= QEMU_BIG_ENDIAN_FLAG
;
1300 void qemu_free_displaysurface(DisplaySurface
*surface
)
1302 if (surface
== NULL
) {
1305 trace_displaysurface_free(surface
);
1306 qemu_pixman_image_unref(surface
->image
);
1310 void register_displaychangelistener(DisplayState
*ds
,
1311 DisplayChangeListener
*dcl
)
1315 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1317 QLIST_INSERT_HEAD(&ds
->listeners
, dcl
, next
);
1318 gui_setup_refresh(ds
);
1323 con
= active_console
;
1325 if (dcl
->ops
->dpy_gfx_switch
&& con
) {
1326 dcl
->ops
->dpy_gfx_switch(dcl
, con
->surface
);
1330 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1333 DisplayState
*ds
= dcl
->ds
;
1335 dcl
->update_interval
= interval
;
1336 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1337 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
1341 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1343 DisplayState
*ds
= dcl
->ds
;
1344 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1348 QLIST_REMOVE(dcl
, next
);
1349 gui_setup_refresh(ds
);
1352 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1354 DisplayState
*s
= con
->ds
;
1355 DisplayChangeListener
*dcl
;
1356 int width
= surface_width(con
->surface
);
1357 int height
= surface_height(con
->surface
);
1363 w
= MIN(w
, width
- x
);
1364 h
= MIN(h
, height
- y
);
1366 if (!qemu_console_is_visible(con
)) {
1369 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1370 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1373 if (dcl
->ops
->dpy_gfx_update
) {
1374 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1379 void dpy_gfx_replace_surface(QemuConsole
*con
,
1380 DisplaySurface
*surface
)
1382 DisplayState
*s
= con
->ds
;
1383 DisplaySurface
*old_surface
= con
->surface
;
1384 DisplayChangeListener
*dcl
;
1386 con
->surface
= surface
;
1387 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1388 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1391 if (dcl
->ops
->dpy_gfx_switch
) {
1392 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1395 qemu_free_displaysurface(old_surface
);
1398 void dpy_refresh(DisplayState
*s
)
1400 DisplayChangeListener
*dcl
;
1402 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1403 if (dcl
->ops
->dpy_refresh
) {
1404 dcl
->ops
->dpy_refresh(dcl
);
1409 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
1410 int dst_x
, int dst_y
, int w
, int h
)
1412 DisplayState
*s
= con
->ds
;
1413 DisplayChangeListener
*dcl
;
1415 if (!qemu_console_is_visible(con
)) {
1418 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1419 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1422 if (dcl
->ops
->dpy_gfx_copy
) {
1423 dcl
->ops
->dpy_gfx_copy(dcl
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1425 dcl
->ops
->dpy_gfx_update(dcl
, dst_x
, dst_y
, w
, h
);
1430 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1432 DisplayState
*s
= con
->ds
;
1433 DisplayChangeListener
*dcl
;
1435 if (!qemu_console_is_visible(con
)) {
1438 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1439 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1442 if (dcl
->ops
->dpy_text_cursor
) {
1443 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1448 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1450 DisplayState
*s
= con
->ds
;
1451 DisplayChangeListener
*dcl
;
1453 if (!qemu_console_is_visible(con
)) {
1456 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1457 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1460 if (dcl
->ops
->dpy_text_update
) {
1461 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1466 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1468 DisplayState
*s
= con
->ds
;
1469 struct DisplayChangeListener
*dcl
;
1471 if (!qemu_console_is_visible(con
)) {
1474 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1475 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1478 if (dcl
->ops
->dpy_text_resize
) {
1479 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1484 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1486 DisplayState
*s
= con
->ds
;
1487 DisplayChangeListener
*dcl
;
1489 if (!qemu_console_is_visible(con
)) {
1492 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1493 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1496 if (dcl
->ops
->dpy_mouse_set
) {
1497 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1502 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1504 DisplayState
*s
= con
->ds
;
1505 DisplayChangeListener
*dcl
;
1507 if (!qemu_console_is_visible(con
)) {
1510 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1511 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1514 if (dcl
->ops
->dpy_cursor_define
) {
1515 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1520 bool dpy_cursor_define_supported(QemuConsole
*con
)
1522 DisplayState
*s
= con
->ds
;
1523 DisplayChangeListener
*dcl
;
1525 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1526 if (dcl
->ops
->dpy_cursor_define
) {
1533 /***********************************************************/
1534 /* register display */
1536 /* console.c internal use only */
1537 static DisplayState
*get_alloc_displaystate(void)
1539 if (!display_state
) {
1540 display_state
= g_new0(DisplayState
, 1);
1542 return display_state
;
1546 * Called by main(), after creating QemuConsoles
1547 * and before initializing ui (sdl/vnc/...).
1549 DisplayState
*init_displaystate(void)
1553 if (!display_state
) {
1554 display_state
= g_new0(DisplayState
, 1);
1557 for (i
= 0; i
< nb_consoles
; i
++) {
1558 if (consoles
[i
]->console_type
!= GRAPHIC_CONSOLE
&&
1559 consoles
[i
]->ds
== NULL
) {
1560 text_console_do_init(consoles
[i
]->chr
, display_state
);
1564 return display_state
;
1567 QemuConsole
*graphic_console_init(DeviceState
*dev
,
1568 const GraphicHwOps
*hw_ops
,
1571 Error
*local_err
= NULL
;
1577 ds
= get_alloc_displaystate();
1578 trace_console_gfx_new();
1579 s
= new_console(ds
, GRAPHIC_CONSOLE
);
1583 object_property_set_link(OBJECT(s
), OBJECT(dev
),
1584 "device", &local_err
);
1587 s
->surface
= qemu_create_displaysurface(width
, height
);
1591 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
1593 if (index
>= MAX_CONSOLES
) {
1596 return consoles
[index
];
1599 bool qemu_console_is_visible(QemuConsole
*con
)
1601 return (con
== active_console
) || (con
->dcls
> 0);
1604 bool qemu_console_is_graphic(QemuConsole
*con
)
1607 con
= active_console
;
1609 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
1612 bool qemu_console_is_fixedsize(QemuConsole
*con
)
1615 con
= active_console
;
1617 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
1620 static void text_console_set_echo(CharDriverState
*chr
, bool echo
)
1622 QemuConsole
*s
= chr
->opaque
;
1627 static void text_console_update_cursor(void *opaque
)
1629 QemuConsole
*s
= opaque
;
1631 s
->cursor_visible_phase
= !s
->cursor_visible_phase
;
1632 graphic_hw_invalidate(s
);
1633 qemu_mod_timer(s
->cursor_timer
,
1634 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1637 static const GraphicHwOps text_console_ops
= {
1638 .invalidate
= text_console_invalidate
,
1639 .text_update
= text_console_update
,
1642 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
)
1645 int g_width
= 80 * FONT_WIDTH
;
1646 int g_height
= 24 * FONT_HEIGHT
;
1650 chr
->chr_write
= console_puts
;
1652 s
->out_fifo
.buf
= s
->out_fifo_buf
;
1653 s
->out_fifo
.buf_size
= sizeof(s
->out_fifo_buf
);
1654 s
->kbd_timer
= qemu_new_timer_ms(rt_clock
, kbd_send_chars
, s
);
1659 s
->total_height
= DEFAULT_BACKSCROLL
;
1663 if (active_console
&& active_console
->surface
) {
1664 g_width
= surface_width(active_console
->surface
);
1665 g_height
= surface_height(active_console
->surface
);
1667 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
1671 qemu_new_timer_ms(rt_clock
, text_console_update_cursor
, s
);
1673 s
->hw_ops
= &text_console_ops
;
1676 /* Set text attribute defaults */
1677 s
->t_attrib_default
.bold
= 0;
1678 s
->t_attrib_default
.uline
= 0;
1679 s
->t_attrib_default
.blink
= 0;
1680 s
->t_attrib_default
.invers
= 0;
1681 s
->t_attrib_default
.unvisible
= 0;
1682 s
->t_attrib_default
.fgcol
= COLOR_WHITE
;
1683 s
->t_attrib_default
.bgcol
= COLOR_BLACK
;
1684 /* set current text attributes to default */
1685 s
->t_attrib
= s
->t_attrib_default
;
1686 text_console_resize(s
);
1692 s
->t_attrib
.bgcol
= COLOR_BLUE
;
1693 len
= snprintf(msg
, sizeof(msg
), "%s console\r\n", chr
->label
);
1694 console_puts(chr
, (uint8_t*)msg
, len
);
1695 s
->t_attrib
= s
->t_attrib_default
;
1698 qemu_chr_be_generic_open(chr
);
1703 static CharDriverState
*text_console_init(ChardevVC
*vc
)
1705 CharDriverState
*chr
;
1708 unsigned height
= 0;
1710 chr
= g_malloc0(sizeof(CharDriverState
));
1712 if (vc
->has_width
) {
1714 } else if (vc
->has_cols
) {
1715 width
= vc
->cols
* FONT_WIDTH
;
1718 if (vc
->has_height
) {
1719 height
= vc
->height
;
1720 } else if (vc
->has_rows
) {
1721 height
= vc
->rows
* FONT_HEIGHT
;
1724 trace_console_txt_new(width
, height
);
1725 if (width
== 0 || height
== 0) {
1726 s
= new_console(NULL
, TEXT_CONSOLE
);
1728 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
);
1729 s
->surface
= qemu_create_displaysurface(width
, height
);
1739 chr
->chr_set_echo
= text_console_set_echo
;
1741 if (display_state
) {
1742 text_console_do_init(chr
, display_state
);
1747 static VcHandler
*vc_handler
= text_console_init
;
1749 CharDriverState
*vc_init(ChardevVC
*vc
)
1751 return vc_handler(vc
);
1754 void register_vc_handler(VcHandler
*handler
)
1756 vc_handler
= handler
;
1759 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
1761 DisplaySurface
*surface
;
1763 assert(s
->console_type
== GRAPHIC_CONSOLE
);
1764 surface
= qemu_create_displaysurface(width
, height
);
1765 dpy_gfx_replace_surface(s
, surface
);
1768 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
1769 int dst_x
, int dst_y
, int w
, int h
)
1771 assert(con
->console_type
== GRAPHIC_CONSOLE
);
1772 dpy_gfx_copy(con
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1775 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
1777 return console
->surface
;
1780 DisplayState
*qemu_console_displaystate(QemuConsole
*console
)
1785 PixelFormat
qemu_different_endianness_pixelformat(int bpp
)
1789 memset(&pf
, 0x00, sizeof(PixelFormat
));
1791 pf
.bits_per_pixel
= bpp
;
1792 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1793 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1797 pf
.rmask
= 0x000000FF;
1798 pf
.gmask
= 0x0000FF00;
1799 pf
.bmask
= 0x00FF0000;
1811 pf
.rmask
= 0x0000FF00;
1812 pf
.gmask
= 0x00FF0000;
1813 pf
.bmask
= 0xFF000000;
1814 pf
.amask
= 0x00000000;
1834 PixelFormat
qemu_default_pixelformat(int bpp
)
1838 memset(&pf
, 0x00, sizeof(PixelFormat
));
1840 pf
.bits_per_pixel
= bpp
;
1841 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1842 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1846 pf
.bits_per_pixel
= 16;
1847 pf
.rmask
= 0x00007c00;
1848 pf
.gmask
= 0x000003E0;
1849 pf
.bmask
= 0x0000001F;
1861 pf
.rmask
= 0x0000F800;
1862 pf
.gmask
= 0x000007E0;
1863 pf
.bmask
= 0x0000001F;
1875 pf
.rmask
= 0x00FF0000;
1876 pf
.gmask
= 0x0000FF00;
1877 pf
.bmask
= 0x000000FF;
1889 pf
.rmask
= 0x00FF0000;
1890 pf
.gmask
= 0x0000FF00;
1891 pf
.bmask
= 0x000000FF;
1908 static void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
,
1913 backend
->vc
= g_new0(ChardevVC
, 1);
1915 val
= qemu_opt_get_number(opts
, "width", 0);
1917 backend
->vc
->has_width
= true;
1918 backend
->vc
->width
= val
;
1921 val
= qemu_opt_get_number(opts
, "height", 0);
1923 backend
->vc
->has_height
= true;
1924 backend
->vc
->height
= val
;
1927 val
= qemu_opt_get_number(opts
, "cols", 0);
1929 backend
->vc
->has_cols
= true;
1930 backend
->vc
->cols
= val
;
1933 val
= qemu_opt_get_number(opts
, "rows", 0);
1935 backend
->vc
->has_rows
= true;
1936 backend
->vc
->rows
= val
;
1940 static const TypeInfo qemu_console_info
= {
1941 .name
= TYPE_QEMU_CONSOLE
,
1942 .parent
= TYPE_OBJECT
,
1943 .instance_size
= sizeof(QemuConsole
),
1944 .class_size
= sizeof(QemuConsoleClass
),
1948 static void register_types(void)
1950 type_register_static(&qemu_console_info
);
1951 register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC
,
1955 type_init(register_types
);