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
);
276 pixman_image_t
*linebuf
;
278 trace_ppm_save(filename
, ds
);
279 fd
= qemu_open(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
, 0666);
281 error_setg(errp
, "failed to open file '%s': %s", filename
,
285 f
= fdopen(fd
, "wb");
286 ret
= fprintf(f
, "P6\n%d %d\n%d\n", width
, height
, 255);
291 linebuf
= qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8
, width
);
292 for (y
= 0; y
< height
; y
++) {
293 qemu_pixman_linebuf_fill(linebuf
, ds
->image
, width
, 0, y
);
295 ret
= fwrite(pixman_image_get_data(linebuf
), 1,
296 pixman_image_get_stride(linebuf
), f
);
304 qemu_pixman_image_unref(linebuf
);
309 error_setg(errp
, "failed to write to file '%s': %s", filename
,
315 void qmp_screendump(const char *filename
, Error
**errp
)
317 QemuConsole
*con
= qemu_console_lookup_by_index(0);
318 DisplaySurface
*surface
;
321 error_setg(errp
, "There is no QemuConsole I can screendump from.");
325 graphic_hw_update(con
);
326 surface
= qemu_console_surface(con
);
327 ppm_save(filename
, surface
, errp
);
330 void graphic_hw_text_update(QemuConsole
*con
, console_ch_t
*chardata
)
333 con
= active_console
;
335 if (con
&& con
->hw_ops
->text_update
) {
336 con
->hw_ops
->text_update(con
->hw
, chardata
);
340 static void vga_fill_rect(QemuConsole
*con
,
341 int posx
, int posy
, int width
, int height
,
342 pixman_color_t color
)
344 DisplaySurface
*surface
= qemu_console_surface(con
);
345 pixman_rectangle16_t rect
= {
346 .x
= posx
, .y
= posy
, .width
= width
, .height
= height
349 pixman_image_fill_rectangles(PIXMAN_OP_SRC
, surface
->image
,
353 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
354 static void vga_bitblt(QemuConsole
*con
,
355 int xs
, int ys
, int xd
, int yd
, int w
, int h
)
357 DisplaySurface
*surface
= qemu_console_surface(con
);
359 pixman_image_composite(PIXMAN_OP_SRC
,
360 surface
->image
, NULL
, surface
->image
,
361 xs
, ys
, 0, 0, xd
, yd
, w
, h
);
364 /***********************************************************/
365 /* basic char display */
367 #define FONT_HEIGHT 16
372 #ifndef CONFIG_CURSES
385 #define QEMU_RGB(r, g, b) \
386 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
388 static const pixman_color_t color_table_rgb
[2][8] = {
390 QEMU_RGB(0x00, 0x00, 0x00), /* black */
391 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
392 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
393 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
394 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
395 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
396 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
397 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
400 QEMU_RGB(0x00, 0x00, 0x00), /* black */
401 QEMU_RGB(0xff, 0x00, 0x00), /* red */
402 QEMU_RGB(0x00, 0xff, 0x00), /* green */
403 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
404 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
405 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
406 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
407 QEMU_RGB(0xff, 0xff, 0xff), /* white */
412 static void console_print_text_attributes(TextAttributes
*t_attrib
, char ch
)
414 if (t_attrib
->bold
) {
419 if (t_attrib
->uline
) {
424 if (t_attrib
->blink
) {
429 if (t_attrib
->invers
) {
434 if (t_attrib
->unvisible
) {
440 printf(" fg: %d bg: %d ch:'%2X' '%c'\n", t_attrib
->fgcol
, t_attrib
->bgcol
, ch
, ch
);
444 static void vga_putcharxy(QemuConsole
*s
, int x
, int y
, int ch
,
445 TextAttributes
*t_attrib
)
447 static pixman_image_t
*glyphs
[256];
448 DisplaySurface
*surface
= qemu_console_surface(s
);
449 pixman_color_t fgcol
, bgcol
;
451 if (t_attrib
->invers
) {
452 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
453 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
455 fgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->fgcol
];
456 bgcol
= color_table_rgb
[t_attrib
->bold
][t_attrib
->bgcol
];
460 glyphs
[ch
] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT
, vgafont16
, ch
);
462 qemu_pixman_glyph_render(glyphs
[ch
], surface
->image
,
463 &fgcol
, &bgcol
, x
, y
, FONT_WIDTH
, FONT_HEIGHT
);
466 static void text_console_resize(QemuConsole
*s
)
468 TextCell
*cells
, *c
, *c1
;
469 int w1
, x
, y
, last_width
;
471 last_width
= s
->width
;
472 s
->width
= surface_width(s
->surface
) / FONT_WIDTH
;
473 s
->height
= surface_height(s
->surface
) / FONT_HEIGHT
;
479 cells
= g_malloc(s
->width
* s
->total_height
* sizeof(TextCell
));
480 for(y
= 0; y
< s
->total_height
; y
++) {
481 c
= &cells
[y
* s
->width
];
483 c1
= &s
->cells
[y
* last_width
];
484 for(x
= 0; x
< w1
; x
++) {
488 for(x
= w1
; x
< s
->width
; x
++) {
490 c
->t_attrib
= s
->t_attrib_default
;
498 static inline void text_update_xy(QemuConsole
*s
, int x
, int y
)
500 s
->text_x
[0] = MIN(s
->text_x
[0], x
);
501 s
->text_x
[1] = MAX(s
->text_x
[1], x
);
502 s
->text_y
[0] = MIN(s
->text_y
[0], y
);
503 s
->text_y
[1] = MAX(s
->text_y
[1], y
);
506 static void invalidate_xy(QemuConsole
*s
, int x
, int y
)
508 if (s
->update_x0
> x
* FONT_WIDTH
)
509 s
->update_x0
= x
* FONT_WIDTH
;
510 if (s
->update_y0
> y
* FONT_HEIGHT
)
511 s
->update_y0
= y
* FONT_HEIGHT
;
512 if (s
->update_x1
< (x
+ 1) * FONT_WIDTH
)
513 s
->update_x1
= (x
+ 1) * FONT_WIDTH
;
514 if (s
->update_y1
< (y
+ 1) * FONT_HEIGHT
)
515 s
->update_y1
= (y
+ 1) * FONT_HEIGHT
;
518 static void update_xy(QemuConsole
*s
, int x
, int y
)
523 if (!qemu_console_is_visible(s
)) {
527 if (s
->ds
->have_text
) {
528 text_update_xy(s
, x
, y
);
531 if (s
->ds
->have_gfx
) {
532 y1
= (s
->y_base
+ y
) % s
->total_height
;
533 y2
= y1
- s
->y_displayed
;
535 y2
+= s
->total_height
;
536 if (y2
< s
->height
) {
537 c
= &s
->cells
[y1
* s
->width
+ x
];
538 vga_putcharxy(s
, x
, y2
, c
->ch
,
540 invalidate_xy(s
, x
, y2
);
545 static void console_show_cursor(QemuConsole
*s
, int show
)
551 if (!qemu_console_is_visible(s
)) {
555 if (s
->ds
->have_text
) {
556 s
->cursor_invalidate
= 1;
559 if (s
->ds
->have_gfx
) {
563 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
564 y
= y1
- s
->y_displayed
;
566 y
+= s
->total_height
;
568 c
= &s
->cells
[y1
* s
->width
+ x
];
569 if (show
&& s
->cursor_visible_phase
) {
570 TextAttributes t_attrib
= s
->t_attrib_default
;
571 t_attrib
.invers
= !(t_attrib
.invers
); /* invert fg and bg */
572 vga_putcharxy(s
, x
, y
, c
->ch
, &t_attrib
);
574 vga_putcharxy(s
, x
, y
, c
->ch
, &(c
->t_attrib
));
576 invalidate_xy(s
, x
, y
);
581 static void console_refresh(QemuConsole
*s
)
583 DisplaySurface
*surface
= qemu_console_surface(s
);
587 if (!qemu_console_is_visible(s
)) {
591 if (s
->ds
->have_text
) {
594 s
->text_x
[1] = s
->width
- 1;
595 s
->text_y
[1] = s
->height
- 1;
596 s
->cursor_invalidate
= 1;
599 if (s
->ds
->have_gfx
) {
600 vga_fill_rect(s
, 0, 0, surface_width(surface
), surface_height(surface
),
601 color_table_rgb
[0][COLOR_BLACK
]);
603 for (y
= 0; y
< s
->height
; y
++) {
604 c
= s
->cells
+ y1
* s
->width
;
605 for (x
= 0; x
< s
->width
; x
++) {
606 vga_putcharxy(s
, x
, y
, c
->ch
,
610 if (++y1
== s
->total_height
) {
614 console_show_cursor(s
, 1);
615 dpy_gfx_update(s
, 0, 0,
616 surface_width(surface
), surface_height(surface
));
620 static void console_scroll(QemuConsole
*s
, int ydelta
)
625 for(i
= 0; i
< ydelta
; i
++) {
626 if (s
->y_displayed
== s
->y_base
)
628 if (++s
->y_displayed
== s
->total_height
)
633 i
= s
->backscroll_height
;
634 if (i
> s
->total_height
- s
->height
)
635 i
= s
->total_height
- s
->height
;
638 y1
+= s
->total_height
;
639 for(i
= 0; i
< ydelta
; i
++) {
640 if (s
->y_displayed
== y1
)
642 if (--s
->y_displayed
< 0)
643 s
->y_displayed
= s
->total_height
- 1;
649 static void console_put_lf(QemuConsole
*s
)
655 if (s
->y
>= s
->height
) {
656 s
->y
= s
->height
- 1;
658 if (s
->y_displayed
== s
->y_base
) {
659 if (++s
->y_displayed
== s
->total_height
)
662 if (++s
->y_base
== s
->total_height
)
664 if (s
->backscroll_height
< s
->total_height
)
665 s
->backscroll_height
++;
666 y1
= (s
->y_base
+ s
->height
- 1) % s
->total_height
;
667 c
= &s
->cells
[y1
* s
->width
];
668 for(x
= 0; x
< s
->width
; x
++) {
670 c
->t_attrib
= s
->t_attrib_default
;
673 if (qemu_console_is_visible(s
) && s
->y_displayed
== s
->y_base
) {
674 if (s
->ds
->have_text
) {
677 s
->text_x
[1] = s
->width
- 1;
678 s
->text_y
[1] = s
->height
- 1;
681 if (s
->ds
->have_gfx
) {
682 vga_bitblt(s
, 0, FONT_HEIGHT
, 0, 0,
683 s
->width
* FONT_WIDTH
,
684 (s
->height
- 1) * FONT_HEIGHT
);
685 vga_fill_rect(s
, 0, (s
->height
- 1) * FONT_HEIGHT
,
686 s
->width
* FONT_WIDTH
, FONT_HEIGHT
,
687 color_table_rgb
[0][s
->t_attrib_default
.bgcol
]);
690 s
->update_x1
= s
->width
* FONT_WIDTH
;
691 s
->update_y1
= s
->height
* FONT_HEIGHT
;
697 /* Set console attributes depending on the current escape codes.
698 * NOTE: I know this code is not very efficient (checking every color for it
699 * self) but it is more readable and better maintainable.
701 static void console_handle_escape(QemuConsole
*s
)
705 for (i
=0; i
<s
->nb_esc_params
; i
++) {
706 switch (s
->esc_params
[i
]) {
707 case 0: /* reset all console attributes to default */
708 s
->t_attrib
= s
->t_attrib_default
;
711 s
->t_attrib
.bold
= 1;
714 s
->t_attrib
.uline
= 1;
717 s
->t_attrib
.blink
= 1;
720 s
->t_attrib
.invers
= 1;
723 s
->t_attrib
.unvisible
= 1;
726 s
->t_attrib
.bold
= 0;
729 s
->t_attrib
.uline
= 0;
732 s
->t_attrib
.blink
= 0;
735 s
->t_attrib
.invers
= 0;
738 s
->t_attrib
.unvisible
= 0;
740 /* set foreground color */
742 s
->t_attrib
.fgcol
=COLOR_BLACK
;
745 s
->t_attrib
.fgcol
=COLOR_RED
;
748 s
->t_attrib
.fgcol
=COLOR_GREEN
;
751 s
->t_attrib
.fgcol
=COLOR_YELLOW
;
754 s
->t_attrib
.fgcol
=COLOR_BLUE
;
757 s
->t_attrib
.fgcol
=COLOR_MAGENTA
;
760 s
->t_attrib
.fgcol
=COLOR_CYAN
;
763 s
->t_attrib
.fgcol
=COLOR_WHITE
;
765 /* set background color */
767 s
->t_attrib
.bgcol
=COLOR_BLACK
;
770 s
->t_attrib
.bgcol
=COLOR_RED
;
773 s
->t_attrib
.bgcol
=COLOR_GREEN
;
776 s
->t_attrib
.bgcol
=COLOR_YELLOW
;
779 s
->t_attrib
.bgcol
=COLOR_BLUE
;
782 s
->t_attrib
.bgcol
=COLOR_MAGENTA
;
785 s
->t_attrib
.bgcol
=COLOR_CYAN
;
788 s
->t_attrib
.bgcol
=COLOR_WHITE
;
794 static void console_clear_xy(QemuConsole
*s
, int x
, int y
)
796 int y1
= (s
->y_base
+ y
) % s
->total_height
;
797 TextCell
*c
= &s
->cells
[y1
* s
->width
+ x
];
799 c
->t_attrib
= s
->t_attrib_default
;
803 /* set cursor, checking bounds */
804 static void set_cursor(QemuConsole
*s
, int x
, int y
)
812 if (y
>= s
->height
) {
823 static void console_putchar(QemuConsole
*s
, int ch
)
832 case '\r': /* carriage return */
835 case '\n': /* newline */
838 case '\b': /* backspace */
842 case '\t': /* tabspace */
843 if (s
->x
+ (8 - (s
->x
% 8)) > s
->width
) {
847 s
->x
= s
->x
+ (8 - (s
->x
% 8));
850 case '\a': /* alert aka. bell */
851 /* TODO: has to be implemented */
854 /* SI (shift in), character set 0 (ignored) */
857 /* SO (shift out), character set 1 (ignored) */
859 case 27: /* esc (introducing an escape sequence) */
860 s
->state
= TTY_STATE_ESC
;
863 if (s
->x
>= s
->width
) {
868 y1
= (s
->y_base
+ s
->y
) % s
->total_height
;
869 c
= &s
->cells
[y1
* s
->width
+ s
->x
];
871 c
->t_attrib
= s
->t_attrib
;
872 update_xy(s
, s
->x
, s
->y
);
877 case TTY_STATE_ESC
: /* check if it is a terminal escape sequence */
879 for(i
=0;i
<MAX_ESC_PARAMS
;i
++)
880 s
->esc_params
[i
] = 0;
881 s
->nb_esc_params
= 0;
882 s
->state
= TTY_STATE_CSI
;
884 s
->state
= TTY_STATE_NORM
;
887 case TTY_STATE_CSI
: /* handle escape sequence parameters */
888 if (ch
>= '0' && ch
<= '9') {
889 if (s
->nb_esc_params
< MAX_ESC_PARAMS
) {
890 int *param
= &s
->esc_params
[s
->nb_esc_params
];
891 int digit
= (ch
- '0');
893 *param
= (*param
<= (INT_MAX
- digit
) / 10) ?
894 *param
* 10 + digit
: INT_MAX
;
897 if (s
->nb_esc_params
< MAX_ESC_PARAMS
)
902 fprintf(stderr
, "escape sequence CSI%d;%d%c, %d parameters\n",
903 s
->esc_params
[0], s
->esc_params
[1], ch
, s
->nb_esc_params
);
905 s
->state
= TTY_STATE_NORM
;
909 if (s
->esc_params
[0] == 0) {
910 s
->esc_params
[0] = 1;
912 set_cursor(s
, s
->x
, s
->y
- s
->esc_params
[0]);
915 /* move cursor down */
916 if (s
->esc_params
[0] == 0) {
917 s
->esc_params
[0] = 1;
919 set_cursor(s
, s
->x
, s
->y
+ s
->esc_params
[0]);
922 /* move cursor right */
923 if (s
->esc_params
[0] == 0) {
924 s
->esc_params
[0] = 1;
926 set_cursor(s
, s
->x
+ s
->esc_params
[0], s
->y
);
929 /* move cursor left */
930 if (s
->esc_params
[0] == 0) {
931 s
->esc_params
[0] = 1;
933 set_cursor(s
, s
->x
- s
->esc_params
[0], s
->y
);
936 /* move cursor to column */
937 set_cursor(s
, s
->esc_params
[0] - 1, s
->y
);
941 /* move cursor to row, column */
942 set_cursor(s
, s
->esc_params
[1] - 1, s
->esc_params
[0] - 1);
945 switch (s
->esc_params
[0]) {
947 /* clear to end of screen */
948 for (y
= s
->y
; y
< s
->height
; y
++) {
949 for (x
= 0; x
< s
->width
; x
++) {
950 if (y
== s
->y
&& x
< s
->x
) {
953 console_clear_xy(s
, x
, y
);
958 /* clear from beginning of screen */
959 for (y
= 0; y
<= s
->y
; y
++) {
960 for (x
= 0; x
< s
->width
; x
++) {
961 if (y
== s
->y
&& x
> s
->x
) {
964 console_clear_xy(s
, x
, y
);
969 /* clear entire screen */
970 for (y
= 0; y
<= s
->height
; y
++) {
971 for (x
= 0; x
< s
->width
; x
++) {
972 console_clear_xy(s
, x
, y
);
979 switch (s
->esc_params
[0]) {
982 for(x
= s
->x
; x
< s
->width
; x
++) {
983 console_clear_xy(s
, x
, s
->y
);
987 /* clear from beginning of line */
988 for (x
= 0; x
<= s
->x
; x
++) {
989 console_clear_xy(s
, x
, s
->y
);
993 /* clear entire line */
994 for(x
= 0; x
< s
->width
; x
++) {
995 console_clear_xy(s
, x
, s
->y
);
1001 console_handle_escape(s
);
1004 /* report cursor position */
1005 /* TODO: send ESC[row;colR */
1008 /* save cursor position */
1013 /* restore cursor position */
1018 #ifdef DEBUG_CONSOLE
1019 fprintf(stderr
, "unhandled escape character '%c'\n", ch
);
1028 void console_select(unsigned int index
)
1030 DisplayChangeListener
*dcl
;
1033 if (index
>= MAX_CONSOLES
)
1036 trace_console_select(index
);
1037 s
= qemu_console_lookup_by_index(index
);
1039 DisplayState
*ds
= s
->ds
;
1041 if (active_console
&& active_console
->cursor_timer
) {
1042 qemu_del_timer(active_console
->cursor_timer
);
1046 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1047 if (dcl
->con
!= NULL
) {
1050 if (dcl
->ops
->dpy_gfx_switch
) {
1051 dcl
->ops
->dpy_gfx_switch(dcl
, s
->surface
);
1054 dpy_gfx_update(s
, 0, 0, surface_width(s
->surface
),
1055 surface_height(s
->surface
));
1057 if (ds
->have_text
) {
1058 dpy_text_resize(s
, s
->width
, s
->height
);
1060 if (s
->cursor_timer
) {
1061 qemu_mod_timer(s
->cursor_timer
,
1062 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1067 static int console_puts(CharDriverState
*chr
, const uint8_t *buf
, int len
)
1069 QemuConsole
*s
= chr
->opaque
;
1072 s
->update_x0
= s
->width
* FONT_WIDTH
;
1073 s
->update_y0
= s
->height
* FONT_HEIGHT
;
1076 console_show_cursor(s
, 0);
1077 for(i
= 0; i
< len
; i
++) {
1078 console_putchar(s
, buf
[i
]);
1080 console_show_cursor(s
, 1);
1081 if (s
->ds
->have_gfx
&& s
->update_x0
< s
->update_x1
) {
1082 dpy_gfx_update(s
, s
->update_x0
, s
->update_y0
,
1083 s
->update_x1
- s
->update_x0
,
1084 s
->update_y1
- s
->update_y0
);
1089 static void kbd_send_chars(void *opaque
)
1091 QemuConsole
*s
= opaque
;
1095 len
= qemu_chr_be_can_write(s
->chr
);
1096 if (len
> s
->out_fifo
.count
)
1097 len
= s
->out_fifo
.count
;
1099 if (len
> sizeof(buf
))
1101 qemu_fifo_read(&s
->out_fifo
, buf
, len
);
1102 qemu_chr_be_write(s
->chr
, buf
, len
);
1104 /* characters are pending: we send them a bit later (XXX:
1105 horrible, should change char device API) */
1106 if (s
->out_fifo
.count
> 0) {
1107 qemu_mod_timer(s
->kbd_timer
, qemu_get_clock_ms(rt_clock
) + 1);
1111 /* called when an ascii key is pressed */
1112 void kbd_put_keysym(int keysym
)
1115 uint8_t buf
[16], *q
;
1119 if (!s
|| (s
->console_type
== GRAPHIC_CONSOLE
))
1123 case QEMU_KEY_CTRL_UP
:
1124 console_scroll(s
, -1);
1126 case QEMU_KEY_CTRL_DOWN
:
1127 console_scroll(s
, 1);
1129 case QEMU_KEY_CTRL_PAGEUP
:
1130 console_scroll(s
, -10);
1132 case QEMU_KEY_CTRL_PAGEDOWN
:
1133 console_scroll(s
, 10);
1136 /* convert the QEMU keysym to VT100 key string */
1138 if (keysym
>= 0xe100 && keysym
<= 0xe11f) {
1141 c
= keysym
- 0xe100;
1143 *q
++ = '0' + (c
/ 10);
1144 *q
++ = '0' + (c
% 10);
1146 } else if (keysym
>= 0xe120 && keysym
<= 0xe17f) {
1149 *q
++ = keysym
& 0xff;
1150 } else if (s
->echo
&& (keysym
== '\r' || keysym
== '\n')) {
1151 console_puts(s
->chr
, (const uint8_t *) "\r", 1);
1157 console_puts(s
->chr
, buf
, q
- buf
);
1159 if (s
->chr
->chr_read
) {
1160 qemu_fifo_write(&s
->out_fifo
, buf
, q
- buf
);
1167 static void text_console_invalidate(void *opaque
)
1169 QemuConsole
*s
= (QemuConsole
*) opaque
;
1171 if (s
->ds
->have_text
&& s
->console_type
== TEXT_CONSOLE
) {
1172 text_console_resize(s
);
1177 static void text_console_update(void *opaque
, console_ch_t
*chardata
)
1179 QemuConsole
*s
= (QemuConsole
*) opaque
;
1182 if (s
->text_x
[0] <= s
->text_x
[1]) {
1183 src
= (s
->y_base
+ s
->text_y
[0]) * s
->width
;
1184 chardata
+= s
->text_y
[0] * s
->width
;
1185 for (i
= s
->text_y
[0]; i
<= s
->text_y
[1]; i
++)
1186 for (j
= 0; j
< s
->width
; j
++, src
++)
1187 console_write_ch(chardata
++, s
->cells
[src
].ch
|
1188 (s
->cells
[src
].t_attrib
.fgcol
<< 12) |
1189 (s
->cells
[src
].t_attrib
.bgcol
<< 8) |
1190 (s
->cells
[src
].t_attrib
.bold
<< 21));
1191 dpy_text_update(s
, s
->text_x
[0], s
->text_y
[0],
1192 s
->text_x
[1] - s
->text_x
[0], i
- s
->text_y
[0]);
1193 s
->text_x
[0] = s
->width
;
1194 s
->text_y
[0] = s
->height
;
1198 if (s
->cursor_invalidate
) {
1199 dpy_text_cursor(s
, s
->x
, s
->y
);
1200 s
->cursor_invalidate
= 0;
1204 static QemuConsole
*new_console(DisplayState
*ds
, console_type_t console_type
)
1206 Error
*local_err
= NULL
;
1211 if (nb_consoles
>= MAX_CONSOLES
)
1214 obj
= object_new(TYPE_QEMU_CONSOLE
);
1215 s
= QEMU_CONSOLE(obj
);
1216 object_property_add_link(obj
, "device", TYPE_DEVICE
,
1217 (Object
**)&s
->device
, &local_err
);
1219 if (!active_console
|| ((active_console
->console_type
!= GRAPHIC_CONSOLE
) &&
1220 (console_type
== GRAPHIC_CONSOLE
))) {
1224 s
->console_type
= console_type
;
1225 if (console_type
!= GRAPHIC_CONSOLE
) {
1226 s
->index
= nb_consoles
;
1227 consoles
[nb_consoles
++] = s
;
1229 /* HACK: Put graphical consoles before text consoles. */
1230 for (i
= nb_consoles
; i
> 0; i
--) {
1231 if (consoles
[i
- 1]->console_type
== GRAPHIC_CONSOLE
)
1233 consoles
[i
] = consoles
[i
- 1];
1234 consoles
[i
]->index
= i
;
1243 static void qemu_alloc_display(DisplaySurface
*surface
, int width
, int height
,
1244 int linesize
, PixelFormat pf
, int newflags
)
1248 qemu_pixman_image_unref(surface
->image
);
1249 surface
->image
= NULL
;
1251 surface
->format
= qemu_pixman_get_format(&pf
);
1252 assert(surface
->format
!= 0);
1253 surface
->image
= pixman_image_create_bits(surface
->format
,
1256 assert(surface
->image
!= NULL
);
1258 surface
->flags
= newflags
| QEMU_ALLOCATED_FLAG
;
1259 #ifdef HOST_WORDS_BIGENDIAN
1260 surface
->flags
|= QEMU_BIG_ENDIAN_FLAG
;
1264 DisplaySurface
*qemu_create_displaysurface(int width
, int height
)
1266 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1267 int linesize
= width
* 4;
1269 trace_displaysurface_create(surface
, width
, height
);
1270 qemu_alloc_display(surface
, width
, height
, linesize
,
1271 qemu_default_pixelformat(32), 0);
1275 DisplaySurface
*qemu_create_displaysurface_from(int width
, int height
, int bpp
,
1276 int linesize
, uint8_t *data
,
1279 DisplaySurface
*surface
= g_new0(DisplaySurface
, 1);
1281 trace_displaysurface_create_from(surface
, width
, height
, bpp
, byteswap
);
1283 surface
->pf
= qemu_different_endianness_pixelformat(bpp
);
1285 surface
->pf
= qemu_default_pixelformat(bpp
);
1288 surface
->format
= qemu_pixman_get_format(&surface
->pf
);
1289 assert(surface
->format
!= 0);
1290 surface
->image
= pixman_image_create_bits(surface
->format
,
1292 (void *)data
, linesize
);
1293 assert(surface
->image
!= NULL
);
1295 #ifdef HOST_WORDS_BIGENDIAN
1296 surface
->flags
= QEMU_BIG_ENDIAN_FLAG
;
1302 void qemu_free_displaysurface(DisplaySurface
*surface
)
1304 if (surface
== NULL
) {
1307 trace_displaysurface_free(surface
);
1308 qemu_pixman_image_unref(surface
->image
);
1312 void register_displaychangelistener(DisplayState
*ds
,
1313 DisplayChangeListener
*dcl
)
1317 trace_displaychangelistener_register(dcl
, dcl
->ops
->dpy_name
);
1319 QLIST_INSERT_HEAD(&ds
->listeners
, dcl
, next
);
1320 gui_setup_refresh(ds
);
1325 con
= active_console
;
1327 if (dcl
->ops
->dpy_gfx_switch
&& con
) {
1328 dcl
->ops
->dpy_gfx_switch(dcl
, con
->surface
);
1332 void update_displaychangelistener(DisplayChangeListener
*dcl
,
1335 DisplayState
*ds
= dcl
->ds
;
1337 dcl
->update_interval
= interval
;
1338 if (!ds
->refreshing
&& ds
->update_interval
> interval
) {
1339 qemu_mod_timer(ds
->gui_timer
, ds
->last_update
+ interval
);
1343 void unregister_displaychangelistener(DisplayChangeListener
*dcl
)
1345 DisplayState
*ds
= dcl
->ds
;
1346 trace_displaychangelistener_unregister(dcl
, dcl
->ops
->dpy_name
);
1350 QLIST_REMOVE(dcl
, next
);
1351 gui_setup_refresh(ds
);
1354 void dpy_gfx_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1356 DisplayState
*s
= con
->ds
;
1357 DisplayChangeListener
*dcl
;
1358 int width
= surface_width(con
->surface
);
1359 int height
= surface_height(con
->surface
);
1365 w
= MIN(w
, width
- x
);
1366 h
= MIN(h
, height
- y
);
1368 if (!qemu_console_is_visible(con
)) {
1371 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1372 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1375 if (dcl
->ops
->dpy_gfx_update
) {
1376 dcl
->ops
->dpy_gfx_update(dcl
, x
, y
, w
, h
);
1381 void dpy_gfx_replace_surface(QemuConsole
*con
,
1382 DisplaySurface
*surface
)
1384 DisplayState
*s
= con
->ds
;
1385 DisplaySurface
*old_surface
= con
->surface
;
1386 DisplayChangeListener
*dcl
;
1388 con
->surface
= surface
;
1389 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1390 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1393 if (dcl
->ops
->dpy_gfx_switch
) {
1394 dcl
->ops
->dpy_gfx_switch(dcl
, surface
);
1397 qemu_free_displaysurface(old_surface
);
1400 void dpy_refresh(DisplayState
*s
)
1402 DisplayChangeListener
*dcl
;
1404 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1405 if (dcl
->ops
->dpy_refresh
) {
1406 dcl
->ops
->dpy_refresh(dcl
);
1411 void dpy_gfx_copy(QemuConsole
*con
, int src_x
, int src_y
,
1412 int dst_x
, int dst_y
, int w
, int h
)
1414 DisplayState
*s
= con
->ds
;
1415 DisplayChangeListener
*dcl
;
1417 if (!qemu_console_is_visible(con
)) {
1420 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1421 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1424 if (dcl
->ops
->dpy_gfx_copy
) {
1425 dcl
->ops
->dpy_gfx_copy(dcl
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1427 dcl
->ops
->dpy_gfx_update(dcl
, dst_x
, dst_y
, w
, h
);
1432 void dpy_text_cursor(QemuConsole
*con
, int x
, int y
)
1434 DisplayState
*s
= con
->ds
;
1435 DisplayChangeListener
*dcl
;
1437 if (!qemu_console_is_visible(con
)) {
1440 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1441 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1444 if (dcl
->ops
->dpy_text_cursor
) {
1445 dcl
->ops
->dpy_text_cursor(dcl
, x
, y
);
1450 void dpy_text_update(QemuConsole
*con
, int x
, int y
, int w
, int h
)
1452 DisplayState
*s
= con
->ds
;
1453 DisplayChangeListener
*dcl
;
1455 if (!qemu_console_is_visible(con
)) {
1458 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1459 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1462 if (dcl
->ops
->dpy_text_update
) {
1463 dcl
->ops
->dpy_text_update(dcl
, x
, y
, w
, h
);
1468 void dpy_text_resize(QemuConsole
*con
, int w
, int h
)
1470 DisplayState
*s
= con
->ds
;
1471 struct DisplayChangeListener
*dcl
;
1473 if (!qemu_console_is_visible(con
)) {
1476 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1477 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1480 if (dcl
->ops
->dpy_text_resize
) {
1481 dcl
->ops
->dpy_text_resize(dcl
, w
, h
);
1486 void dpy_mouse_set(QemuConsole
*con
, int x
, int y
, int on
)
1488 DisplayState
*s
= con
->ds
;
1489 DisplayChangeListener
*dcl
;
1491 if (!qemu_console_is_visible(con
)) {
1494 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1495 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1498 if (dcl
->ops
->dpy_mouse_set
) {
1499 dcl
->ops
->dpy_mouse_set(dcl
, x
, y
, on
);
1504 void dpy_cursor_define(QemuConsole
*con
, QEMUCursor
*cursor
)
1506 DisplayState
*s
= con
->ds
;
1507 DisplayChangeListener
*dcl
;
1509 if (!qemu_console_is_visible(con
)) {
1512 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1513 if (con
!= (dcl
->con
? dcl
->con
: active_console
)) {
1516 if (dcl
->ops
->dpy_cursor_define
) {
1517 dcl
->ops
->dpy_cursor_define(dcl
, cursor
);
1522 bool dpy_cursor_define_supported(QemuConsole
*con
)
1524 DisplayState
*s
= con
->ds
;
1525 DisplayChangeListener
*dcl
;
1527 QLIST_FOREACH(dcl
, &s
->listeners
, next
) {
1528 if (dcl
->ops
->dpy_cursor_define
) {
1535 /***********************************************************/
1536 /* register display */
1538 /* console.c internal use only */
1539 static DisplayState
*get_alloc_displaystate(void)
1541 if (!display_state
) {
1542 display_state
= g_new0(DisplayState
, 1);
1544 return display_state
;
1548 * Called by main(), after creating QemuConsoles
1549 * and before initializing ui (sdl/vnc/...).
1551 DisplayState
*init_displaystate(void)
1555 if (!display_state
) {
1556 display_state
= g_new0(DisplayState
, 1);
1559 for (i
= 0; i
< nb_consoles
; i
++) {
1560 if (consoles
[i
]->console_type
!= GRAPHIC_CONSOLE
&&
1561 consoles
[i
]->ds
== NULL
) {
1562 text_console_do_init(consoles
[i
]->chr
, display_state
);
1566 return display_state
;
1569 QemuConsole
*graphic_console_init(DeviceState
*dev
,
1570 const GraphicHwOps
*hw_ops
,
1573 Error
*local_err
= NULL
;
1579 ds
= get_alloc_displaystate();
1580 trace_console_gfx_new();
1581 s
= new_console(ds
, GRAPHIC_CONSOLE
);
1585 object_property_set_link(OBJECT(s
), OBJECT(dev
),
1586 "device", &local_err
);
1589 s
->surface
= qemu_create_displaysurface(width
, height
);
1593 QemuConsole
*qemu_console_lookup_by_index(unsigned int index
)
1595 if (index
>= MAX_CONSOLES
) {
1598 return consoles
[index
];
1601 QemuConsole
*qemu_console_lookup_by_device(DeviceState
*dev
)
1603 Error
*local_err
= NULL
;
1607 for (i
= 0; i
< nb_consoles
; i
++) {
1611 obj
= object_property_get_link(OBJECT(consoles
[i
]),
1612 "device", &local_err
);
1613 if (DEVICE(obj
) == dev
) {
1620 bool qemu_console_is_visible(QemuConsole
*con
)
1622 return (con
== active_console
) || (con
->dcls
> 0);
1625 bool qemu_console_is_graphic(QemuConsole
*con
)
1628 con
= active_console
;
1630 return con
&& (con
->console_type
== GRAPHIC_CONSOLE
);
1633 bool qemu_console_is_fixedsize(QemuConsole
*con
)
1636 con
= active_console
;
1638 return con
&& (con
->console_type
!= TEXT_CONSOLE
);
1641 static void text_console_set_echo(CharDriverState
*chr
, bool echo
)
1643 QemuConsole
*s
= chr
->opaque
;
1648 static void text_console_update_cursor(void *opaque
)
1650 QemuConsole
*s
= opaque
;
1652 s
->cursor_visible_phase
= !s
->cursor_visible_phase
;
1653 graphic_hw_invalidate(s
);
1654 qemu_mod_timer(s
->cursor_timer
,
1655 qemu_get_clock_ms(rt_clock
) + CONSOLE_CURSOR_PERIOD
/ 2);
1658 static const GraphicHwOps text_console_ops
= {
1659 .invalidate
= text_console_invalidate
,
1660 .text_update
= text_console_update
,
1663 static void text_console_do_init(CharDriverState
*chr
, DisplayState
*ds
)
1666 int g_width
= 80 * FONT_WIDTH
;
1667 int g_height
= 24 * FONT_HEIGHT
;
1671 chr
->chr_write
= console_puts
;
1673 s
->out_fifo
.buf
= s
->out_fifo_buf
;
1674 s
->out_fifo
.buf_size
= sizeof(s
->out_fifo_buf
);
1675 s
->kbd_timer
= qemu_new_timer_ms(rt_clock
, kbd_send_chars
, s
);
1680 s
->total_height
= DEFAULT_BACKSCROLL
;
1684 if (active_console
&& active_console
->surface
) {
1685 g_width
= surface_width(active_console
->surface
);
1686 g_height
= surface_height(active_console
->surface
);
1688 s
->surface
= qemu_create_displaysurface(g_width
, g_height
);
1692 qemu_new_timer_ms(rt_clock
, text_console_update_cursor
, s
);
1694 s
->hw_ops
= &text_console_ops
;
1697 /* Set text attribute defaults */
1698 s
->t_attrib_default
.bold
= 0;
1699 s
->t_attrib_default
.uline
= 0;
1700 s
->t_attrib_default
.blink
= 0;
1701 s
->t_attrib_default
.invers
= 0;
1702 s
->t_attrib_default
.unvisible
= 0;
1703 s
->t_attrib_default
.fgcol
= COLOR_WHITE
;
1704 s
->t_attrib_default
.bgcol
= COLOR_BLACK
;
1705 /* set current text attributes to default */
1706 s
->t_attrib
= s
->t_attrib_default
;
1707 text_console_resize(s
);
1713 s
->t_attrib
.bgcol
= COLOR_BLUE
;
1714 len
= snprintf(msg
, sizeof(msg
), "%s console\r\n", chr
->label
);
1715 console_puts(chr
, (uint8_t*)msg
, len
);
1716 s
->t_attrib
= s
->t_attrib_default
;
1719 qemu_chr_be_generic_open(chr
);
1724 static CharDriverState
*text_console_init(ChardevVC
*vc
)
1726 CharDriverState
*chr
;
1729 unsigned height
= 0;
1731 chr
= g_malloc0(sizeof(CharDriverState
));
1733 if (vc
->has_width
) {
1735 } else if (vc
->has_cols
) {
1736 width
= vc
->cols
* FONT_WIDTH
;
1739 if (vc
->has_height
) {
1740 height
= vc
->height
;
1741 } else if (vc
->has_rows
) {
1742 height
= vc
->rows
* FONT_HEIGHT
;
1745 trace_console_txt_new(width
, height
);
1746 if (width
== 0 || height
== 0) {
1747 s
= new_console(NULL
, TEXT_CONSOLE
);
1749 s
= new_console(NULL
, TEXT_CONSOLE_FIXED_SIZE
);
1750 s
->surface
= qemu_create_displaysurface(width
, height
);
1760 chr
->chr_set_echo
= text_console_set_echo
;
1762 if (display_state
) {
1763 text_console_do_init(chr
, display_state
);
1768 static VcHandler
*vc_handler
= text_console_init
;
1770 CharDriverState
*vc_init(ChardevVC
*vc
)
1772 return vc_handler(vc
);
1775 void register_vc_handler(VcHandler
*handler
)
1777 vc_handler
= handler
;
1780 void qemu_console_resize(QemuConsole
*s
, int width
, int height
)
1782 DisplaySurface
*surface
;
1784 assert(s
->console_type
== GRAPHIC_CONSOLE
);
1785 surface
= qemu_create_displaysurface(width
, height
);
1786 dpy_gfx_replace_surface(s
, surface
);
1789 void qemu_console_copy(QemuConsole
*con
, int src_x
, int src_y
,
1790 int dst_x
, int dst_y
, int w
, int h
)
1792 assert(con
->console_type
== GRAPHIC_CONSOLE
);
1793 dpy_gfx_copy(con
, src_x
, src_y
, dst_x
, dst_y
, w
, h
);
1796 DisplaySurface
*qemu_console_surface(QemuConsole
*console
)
1798 return console
->surface
;
1801 DisplayState
*qemu_console_displaystate(QemuConsole
*console
)
1806 PixelFormat
qemu_different_endianness_pixelformat(int bpp
)
1810 memset(&pf
, 0x00, sizeof(PixelFormat
));
1812 pf
.bits_per_pixel
= bpp
;
1813 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1814 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1818 pf
.rmask
= 0x000000FF;
1819 pf
.gmask
= 0x0000FF00;
1820 pf
.bmask
= 0x00FF0000;
1832 pf
.rmask
= 0x0000FF00;
1833 pf
.gmask
= 0x00FF0000;
1834 pf
.bmask
= 0xFF000000;
1835 pf
.amask
= 0x00000000;
1855 PixelFormat
qemu_default_pixelformat(int bpp
)
1859 memset(&pf
, 0x00, sizeof(PixelFormat
));
1861 pf
.bits_per_pixel
= bpp
;
1862 pf
.bytes_per_pixel
= DIV_ROUND_UP(bpp
, 8);
1863 pf
.depth
= bpp
== 32 ? 24 : bpp
;
1867 pf
.bits_per_pixel
= 16;
1868 pf
.rmask
= 0x00007c00;
1869 pf
.gmask
= 0x000003E0;
1870 pf
.bmask
= 0x0000001F;
1882 pf
.rmask
= 0x0000F800;
1883 pf
.gmask
= 0x000007E0;
1884 pf
.bmask
= 0x0000001F;
1896 pf
.rmask
= 0x00FF0000;
1897 pf
.gmask
= 0x0000FF00;
1898 pf
.bmask
= 0x000000FF;
1910 pf
.rmask
= 0x00FF0000;
1911 pf
.gmask
= 0x0000FF00;
1912 pf
.bmask
= 0x000000FF;
1929 static void qemu_chr_parse_vc(QemuOpts
*opts
, ChardevBackend
*backend
,
1934 backend
->vc
= g_new0(ChardevVC
, 1);
1936 val
= qemu_opt_get_number(opts
, "width", 0);
1938 backend
->vc
->has_width
= true;
1939 backend
->vc
->width
= val
;
1942 val
= qemu_opt_get_number(opts
, "height", 0);
1944 backend
->vc
->has_height
= true;
1945 backend
->vc
->height
= val
;
1948 val
= qemu_opt_get_number(opts
, "cols", 0);
1950 backend
->vc
->has_cols
= true;
1951 backend
->vc
->cols
= val
;
1954 val
= qemu_opt_get_number(opts
, "rows", 0);
1956 backend
->vc
->has_rows
= true;
1957 backend
->vc
->rows
= val
;
1961 static const TypeInfo qemu_console_info
= {
1962 .name
= TYPE_QEMU_CONSOLE
,
1963 .parent
= TYPE_OBJECT
,
1964 .instance_size
= sizeof(QemuConsole
),
1965 .class_size
= sizeof(QemuConsoleClass
),
1969 static void register_types(void)
1971 type_register_static(&qemu_console_info
);
1972 register_char_driver_qapi("vc", CHARDEV_BACKEND_KIND_VC
,
1976 type_init(register_types
);