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 #include "exec/memory.h"
33 #define DEFAULT_BACKSCROLL 512
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;
124 DisplayChangeListener *gl;
126 /* Graphic console state. */
131 const GraphicHwOps *hw_ops;
134 /* Text console state */
138 int backscroll_height;
140 int x_saved, y_saved;
143 TextAttributes t_attrib_default; /* default text attributes */
144 TextAttributes t_attrib; /* currently active text attributes */
146 int text_x[2], text_y[2], cursor_invalidate;
155 int esc_params[MAX_ESC_PARAMS];
158 CharDriverState *chr;
159 /* fifo for key pressed */
161 uint8_t out_fifo_buf[16];
162 QEMUTimer *kbd_timer;
165 struct DisplayState {
166 QEMUTimer *gui_timer;
167 uint64_t last_update;
168 uint64_t update_interval;
173 QLIST_HEAD(, DisplayChangeListener) listeners;
176 static DisplayState *display_state;
177 static QemuConsole *active_console;
178 static QemuConsole **consoles;
179 static int nb_consoles = 0;
180 static bool cursor_visible_phase;
181 static QEMUTimer *cursor_timer;
183 static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
184 static void dpy_refresh(DisplayState *s);
185 static DisplayState *get_alloc_displaystate(void);
186 static void text_console_update_cursor_timer(void);
187 static void text_console_update_cursor(void *opaque);
189 static void gui_update(void *opaque)
191 uint64_t interval = GUI_REFRESH_INTERVAL_IDLE;
192 uint64_t dcl_interval;
193 DisplayState *ds = opaque;
194 DisplayChangeListener *dcl;
197 ds->refreshing = true;
199 ds->refreshing = false;
201 QLIST_FOREACH(dcl, &ds->listeners, next) {
202 dcl_interval = dcl->update_interval ?
203 dcl->update_interval : GUI_REFRESH_INTERVAL_DEFAULT;
204 if (interval > dcl_interval) {
205 interval = dcl_interval;
208 if (ds->update_interval != interval) {
209 ds->update_interval = interval;
210 for (i = 0; i < nb_consoles; i++) {
211 if (consoles[i]->hw_ops->update_interval) {
212 consoles[i]->hw_ops->update_interval(consoles[i]->hw, interval);
215 trace_console_refresh(interval);
217 ds->last_update = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
218 timer_mod(ds->gui_timer, ds->last_update + interval);
221 static void gui_setup_refresh(DisplayState *ds)
223 DisplayChangeListener *dcl;
224 bool need_timer = false;
225 bool have_gfx = false;
226 bool have_text = false;
228 QLIST_FOREACH(dcl, &ds->listeners, next) {
229 if (dcl->ops->dpy_refresh != NULL) {
232 if (dcl->ops->dpy_gfx_update != NULL) {
235 if (dcl->ops->dpy_text_update != NULL) {
240 if (need_timer && ds->gui_timer == NULL) {
241 ds->gui_timer = timer_new_ms(QEMU_CLOCK_REALTIME, gui_update, ds);
242 timer_mod(ds->gui_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
244 if (!need_timer && ds->gui_timer != NULL) {
245 timer_del(ds->gui_timer);
246 timer_free(ds->gui_timer);
247 ds->gui_timer = NULL;
250 ds->have_gfx = have_gfx;
251 ds->have_text = have_text;
254 void graphic_hw_update(QemuConsole *con)
257 con = active_console;
259 if (con && con->hw_ops->gfx_update) {
260 con->hw_ops->gfx_update(con->hw);
264 void graphic_hw_invalidate(QemuConsole *con)
267 con = active_console;
269 if (con && con->hw_ops->invalidate) {
270 con->hw_ops->invalidate(con->hw);
274 static void ppm_save(const char *filename, DisplaySurface *ds,
277 int width = pixman_image_get_width(ds->image);
278 int height = pixman_image_get_height(ds->image);
283 pixman_image_t *linebuf;
285 trace_ppm_save(filename, ds);
286 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
288 error_setg(errp, "failed to open file '%s': %s", filename,
292 f = fdopen(fd, "wb");
293 ret = fprintf(f, "P6\n%d %d\n%d\n", width, height, 255);
298 linebuf = qemu_pixman_linebuf_create(PIXMAN_BE_r8g8b8, width);
299 for (y = 0; y < height; y++) {
300 qemu_pixman_linebuf_fill(linebuf, ds->image, width, 0, y);
302 ret = fwrite(pixman_image_get_data(linebuf), 1,
303 pixman_image_get_stride(linebuf), f);
311 qemu_pixman_image_unref(linebuf);
316 error_setg(errp, "failed to write to file '%s': %s", filename,
322 void qmp_screendump(const char *filename, Error **errp)
324 QemuConsole *con = qemu_console_lookup_by_index(0);
325 DisplaySurface *surface;
328 error_setg(errp, "There is no QemuConsole I can screendump from.");
332 graphic_hw_update(con);
333 surface = qemu_console_surface(con);
334 ppm_save(filename, surface, errp);
337 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata)
340 con = active_console;
342 if (con && con->hw_ops->text_update) {
343 con->hw_ops->text_update(con->hw, chardata);
347 static void vga_fill_rect(QemuConsole *con,
348 int posx, int posy, int width, int height,
349 pixman_color_t color)
351 DisplaySurface *surface = qemu_console_surface(con);
352 pixman_rectangle16_t rect = {
353 .x = posx, .y = posy, .width = width, .height = height
356 pixman_image_fill_rectangles(PIXMAN_OP_SRC, surface->image,
360 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
361 static void vga_bitblt(QemuConsole *con,
362 int xs, int ys, int xd, int yd, int w, int h)
364 DisplaySurface *surface = qemu_console_surface(con);
366 pixman_image_composite(PIXMAN_OP_SRC,
367 surface->image, NULL, surface->image,
368 xs, ys, 0, 0, xd, yd, w, h);
371 /***********************************************************/
372 /* basic char display */
374 #define FONT_HEIGHT 16
379 #ifndef CONFIG_CURSES
392 #define QEMU_RGB(r, g, b) \
393 { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
395 static const pixman_color_t color_table_rgb[2][8] = {
397 QEMU_RGB(0x00, 0x00, 0x00), /* black */
398 QEMU_RGB(0xaa, 0x00, 0x00), /* red */
399 QEMU_RGB(0x00, 0xaa, 0x00), /* green */
400 QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
401 QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
402 QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
403 QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
404 QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
407 QEMU_RGB(0x00, 0x00, 0x00), /* black */
408 QEMU_RGB(0xff, 0x00, 0x00), /* red */
409 QEMU_RGB(0x00, 0xff, 0x00), /* green */
410 QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
411 QEMU_RGB(0x00, 0x00, 0xff), /* blue */
412 QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
413 QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
414 QEMU_RGB(0xff, 0xff, 0xff), /* white */
418 static void vga_putcharxy(QemuConsole *s, int x, int y, int ch,
419 TextAttributes *t_attrib)
421 static pixman_image_t *glyphs[256];
422 DisplaySurface *surface = qemu_console_surface(s);
423 pixman_color_t fgcol, bgcol;
425 if (t_attrib->invers) {
426 bgcol = color_table_rgb[t_attrib->bold][t_attrib->fgcol];
427 fgcol = color_table_rgb[t_attrib->bold][t_attrib->bgcol];
429 fgcol = color_table_rgb[t_attrib->bold][t_attrib->fgcol];
430 bgcol = color_table_rgb[t_attrib->bold][t_attrib->bgcol];
434 glyphs[ch] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, ch);
436 qemu_pixman_glyph_render(glyphs[ch], surface->image,
437 &fgcol, &bgcol, x, y, FONT_WIDTH, FONT_HEIGHT);
440 static void text_console_resize(QemuConsole *s)
442 TextCell *cells, *c, *c1;
443 int w1, x, y, last_width;
445 last_width = s->width;
446 s->width = surface_width(s->surface) / FONT_WIDTH;
447 s->height = surface_height(s->surface) / FONT_HEIGHT;
453 cells = g_malloc(s->width * s->total_height * sizeof(TextCell));
454 for(y = 0; y < s->total_height; y++) {
455 c = &cells[y * s->width];
457 c1 = &s->cells[y * last_width];
458 for(x = 0; x < w1; x++) {
462 for(x = w1; x < s->width; x++) {
464 c->t_attrib = s->t_attrib_default;
472 static inline void text_update_xy(QemuConsole *s, int x, int y)
474 s->text_x[0] = MIN(s->text_x[0], x);
475 s->text_x[1] = MAX(s->text_x[1], x);
476 s->text_y[0] = MIN(s->text_y[0], y);
477 s->text_y[1] = MAX(s->text_y[1], y);
480 static void invalidate_xy(QemuConsole *s, int x, int y)
482 if (!qemu_console_is_visible(s)) {
485 if (s->update_x0 > x * FONT_WIDTH)
486 s->update_x0 = x * FONT_WIDTH;
487 if (s->update_y0 > y * FONT_HEIGHT)
488 s->update_y0 = y * FONT_HEIGHT;
489 if (s->update_x1 < (x + 1) * FONT_WIDTH)
490 s->update_x1 = (x + 1) * FONT_WIDTH;
491 if (s->update_y1 < (y + 1) * FONT_HEIGHT)
492 s->update_y1 = (y + 1) * FONT_HEIGHT;
495 static void update_xy(QemuConsole *s, int x, int y)
500 if (s->ds->have_text) {
501 text_update_xy(s, x, y);
504 y1 = (s->y_base + y) % s->total_height;
505 y2 = y1 - s->y_displayed;
507 y2 += s->total_height;
509 if (y2 < s->height) {
510 c = &s->cells[y1 * s->width + x];
511 vga_putcharxy(s, x, y2, c->ch,
513 invalidate_xy(s, x, y2);
517 static void console_show_cursor(QemuConsole *s, int show)
523 if (s->ds->have_text) {
524 s->cursor_invalidate = 1;
530 y1 = (s->y_base + s->y) % s->total_height;
531 y = y1 - s->y_displayed;
533 y += s->total_height;
536 c = &s->cells[y1 * s->width + x];
537 if (show && cursor_visible_phase) {
538 TextAttributes t_attrib = s->t_attrib_default;
539 t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */
540 vga_putcharxy(s, x, y, c->ch, &t_attrib);
542 vga_putcharxy(s, x, y, c->ch, &(c->t_attrib));
544 invalidate_xy(s, x, y);
548 static void console_refresh(QemuConsole *s)
550 DisplaySurface *surface = qemu_console_surface(s);
554 if (s->ds->have_text) {
557 s->text_x[1] = s->width - 1;
558 s->text_y[1] = s->height - 1;
559 s->cursor_invalidate = 1;
562 vga_fill_rect(s, 0, 0, surface_width(surface), surface_height(surface),
563 color_table_rgb[0][COLOR_BLACK]);
565 for (y = 0; y < s->height; y++) {
566 c = s->cells + y1 * s->width;
567 for (x = 0; x < s->width; x++) {
568 vga_putcharxy(s, x, y, c->ch,
572 if (++y1 == s->total_height) {
576 console_show_cursor(s, 1);
577 dpy_gfx_update(s, 0, 0,
578 surface_width(surface), surface_height(surface));
581 static void console_scroll(QemuConsole *s, int ydelta)
586 for(i = 0; i < ydelta; i++) {
587 if (s->y_displayed == s->y_base)
589 if (++s->y_displayed == s->total_height)
594 i = s->backscroll_height;
595 if (i > s->total_height - s->height)
596 i = s->total_height - s->height;
599 y1 += s->total_height;
600 for(i = 0; i < ydelta; i++) {
601 if (s->y_displayed == y1)
603 if (--s->y_displayed < 0)
604 s->y_displayed = s->total_height - 1;
610 static void console_put_lf(QemuConsole *s)
616 if (s->y >= s->height) {
617 s->y = s->height - 1;
619 if (s->y_displayed == s->y_base) {
620 if (++s->y_displayed == s->total_height)
623 if (++s->y_base == s->total_height)
625 if (s->backscroll_height < s->total_height)
626 s->backscroll_height++;
627 y1 = (s->y_base + s->height - 1) % s->total_height;
628 c = &s->cells[y1 * s->width];
629 for(x = 0; x < s->width; x++) {
631 c->t_attrib = s->t_attrib_default;
634 if (s->y_displayed == s->y_base) {
635 if (s->ds->have_text) {
638 s->text_x[1] = s->width - 1;
639 s->text_y[1] = s->height - 1;
642 vga_bitblt(s, 0, FONT_HEIGHT, 0, 0,
643 s->width * FONT_WIDTH,
644 (s->height - 1) * FONT_HEIGHT);
645 vga_fill_rect(s, 0, (s->height - 1) * FONT_HEIGHT,
646 s->width * FONT_WIDTH, FONT_HEIGHT,
647 color_table_rgb[0][s->t_attrib_default.bgcol]);
650 s->update_x1 = s->width * FONT_WIDTH;
651 s->update_y1 = s->height * FONT_HEIGHT;
656 /* Set console attributes depending on the current escape codes.
657 * NOTE: I know this code is not very efficient (checking every color for it
658 * self) but it is more readable and better maintainable.
660 static void console_handle_escape(QemuConsole *s)
664 for (i=0; i<s->nb_esc_params; i++) {
665 switch (s->esc_params[i]) {
666 case 0: /* reset all console attributes to default */
667 s->t_attrib = s->t_attrib_default;
670 s->t_attrib.bold = 1;
673 s->t_attrib.uline = 1;
676 s->t_attrib.blink = 1;
679 s->t_attrib.invers = 1;
682 s->t_attrib.unvisible = 1;
685 s->t_attrib.bold = 0;
688 s->t_attrib.uline = 0;
691 s->t_attrib.blink = 0;
694 s->t_attrib.invers = 0;
697 s->t_attrib.unvisible = 0;
699 /* set foreground color */
701 s->t_attrib.fgcol=COLOR_BLACK;
704 s->t_attrib.fgcol=COLOR_RED;
707 s->t_attrib.fgcol=COLOR_GREEN;
710 s->t_attrib.fgcol=COLOR_YELLOW;
713 s->t_attrib.fgcol=COLOR_BLUE;
716 s->t_attrib.fgcol=COLOR_MAGENTA;
719 s->t_attrib.fgcol=COLOR_CYAN;
722 s->t_attrib.fgcol=COLOR_WHITE;
724 /* set background color */
726 s->t_attrib.bgcol=COLOR_BLACK;
729 s->t_attrib.bgcol=COLOR_RED;
732 s->t_attrib.bgcol=COLOR_GREEN;
735 s->t_attrib.bgcol=COLOR_YELLOW;
738 s->t_attrib.bgcol=COLOR_BLUE;
741 s->t_attrib.bgcol=COLOR_MAGENTA;
744 s->t_attrib.bgcol=COLOR_CYAN;
747 s->t_attrib.bgcol=COLOR_WHITE;
753 static void console_clear_xy(QemuConsole *s, int x, int y)
755 int y1 = (s->y_base + y) % s->total_height;
756 TextCell *c = &s->cells[y1 * s->width + x];
758 c->t_attrib = s->t_attrib_default;
762 /* set cursor, checking bounds */
763 static void set_cursor(QemuConsole *s, int x, int y)
771 if (y >= s->height) {
782 static void console_putchar(QemuConsole *s, int ch)
791 case '\r': /* carriage return */
794 case '\n': /* newline */
797 case '\b': /* backspace */
801 case '\t': /* tabspace */
802 if (s->x + (8 - (s->x % 8)) > s->width) {
806 s->x = s->x + (8 - (s->x % 8));
809 case '\a': /* alert aka. bell */
810 /* TODO: has to be implemented */
813 /* SI (shift in), character set 0 (ignored) */
816 /* SO (shift out), character set 1 (ignored) */
818 case 27: /* esc (introducing an escape sequence) */
819 s->state = TTY_STATE_ESC;
822 if (s->x >= s->width) {
827 y1 = (s->y_base + s->y) % s->total_height;
828 c = &s->cells[y1 * s->width + s->x];
830 c->t_attrib = s->t_attrib;
831 update_xy(s, s->x, s->y);
836 case TTY_STATE_ESC: /* check if it is a terminal escape sequence */
838 for(i=0;i<MAX_ESC_PARAMS;i++)
839 s->esc_params[i] = 0;
840 s->nb_esc_params = 0;
841 s->state = TTY_STATE_CSI;
843 s->state = TTY_STATE_NORM;
846 case TTY_STATE_CSI: /* handle escape sequence parameters */
847 if (ch >= '0' && ch <= '9') {
848 if (s->nb_esc_params < MAX_ESC_PARAMS) {
849 int *param = &s->esc_params[s->nb_esc_params];
850 int digit = (ch - '0');
852 *param = (*param <= (INT_MAX - digit) / 10) ?
853 *param * 10 + digit : INT_MAX;
856 if (s->nb_esc_params < MAX_ESC_PARAMS)
860 trace_console_putchar_csi(s->esc_params[0], s->esc_params[1],
861 ch, s->nb_esc_params);
862 s->state = TTY_STATE_NORM;
866 if (s->esc_params[0] == 0) {
867 s->esc_params[0] = 1;
869 set_cursor(s, s->x, s->y - s->esc_params[0]);
872 /* move cursor down */
873 if (s->esc_params[0] == 0) {
874 s->esc_params[0] = 1;
876 set_cursor(s, s->x, s->y + s->esc_params[0]);
879 /* move cursor right */
880 if (s->esc_params[0] == 0) {
881 s->esc_params[0] = 1;
883 set_cursor(s, s->x + s->esc_params[0], s->y);
886 /* move cursor left */
887 if (s->esc_params[0] == 0) {
888 s->esc_params[0] = 1;
890 set_cursor(s, s->x - s->esc_params[0], s->y);
893 /* move cursor to column */
894 set_cursor(s, s->esc_params[0] - 1, s->y);
898 /* move cursor to row, column */
899 set_cursor(s, s->esc_params[1] - 1, s->esc_params[0] - 1);
902 switch (s->esc_params[0]) {
904 /* clear to end of screen */
905 for (y = s->y; y < s->height; y++) {
906 for (x = 0; x < s->width; x++) {
907 if (y == s->y && x < s->x) {
910 console_clear_xy(s, x, y);
915 /* clear from beginning of screen */
916 for (y = 0; y <= s->y; y++) {
917 for (x = 0; x < s->width; x++) {
918 if (y == s->y && x > s->x) {
921 console_clear_xy(s, x, y);
926 /* clear entire screen */
927 for (y = 0; y <= s->height; y++) {
928 for (x = 0; x < s->width; x++) {
929 console_clear_xy(s, x, y);
936 switch (s->esc_params[0]) {
939 for(x = s->x; x < s->width; x++) {
940 console_clear_xy(s, x, s->y);
944 /* clear from beginning of line */
945 for (x = 0; x <= s->x; x++) {
946 console_clear_xy(s, x, s->y);
950 /* clear entire line */
951 for(x = 0; x < s->width; x++) {
952 console_clear_xy(s, x, s->y);
958 console_handle_escape(s);
961 /* report cursor position */
962 /* TODO: send ESC[row;colR */
965 /* save cursor position */
970 /* restore cursor position */
975 trace_console_putchar_unhandled(ch);
983 void console_select(unsigned int index)
985 DisplayChangeListener *dcl;
988 trace_console_select(index);
989 s = qemu_console_lookup_by_index(index);
991 DisplayState *ds = s->ds;
995 QLIST_FOREACH(dcl, &ds->listeners, next) {
996 if (dcl->con != NULL) {
999 if (dcl->ops->dpy_gfx_switch) {
1000 dcl->ops->dpy_gfx_switch(dcl, s->surface);
1003 dpy_gfx_update(s, 0, 0, surface_width(s->surface),
1004 surface_height(s->surface));
1006 if (ds->have_text) {
1007 dpy_text_resize(s, s->width, s->height);
1009 text_console_update_cursor(NULL);
1013 static int console_puts(CharDriverState *chr, const uint8_t *buf, int len)
1015 QemuConsole *s = chr->opaque;
1018 s->update_x0 = s->width * FONT_WIDTH;
1019 s->update_y0 = s->height * FONT_HEIGHT;
1022 console_show_cursor(s, 0);
1023 for(i = 0; i < len; i++) {
1024 console_putchar(s, buf[i]);
1026 console_show_cursor(s, 1);
1027 if (s->ds->have_gfx && s->update_x0 < s->update_x1) {
1028 dpy_gfx_update(s, s->update_x0, s->update_y0,
1029 s->update_x1 - s->update_x0,
1030 s->update_y1 - s->update_y0);
1035 static void kbd_send_chars(void *opaque)
1037 QemuConsole *s = opaque;
1041 len = qemu_chr_be_can_write(s->chr);
1042 if (len > s->out_fifo.count)
1043 len = s->out_fifo.count;
1045 if (len > sizeof(buf))
1047 qemu_fifo_read(&s->out_fifo, buf, len);
1048 qemu_chr_be_write(s->chr, buf, len);
1050 /* characters are pending: we send them a bit later (XXX:
1051 horrible, should change char device API) */
1052 if (s->out_fifo.count > 0) {
1053 timer_mod(s->kbd_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1);
1057 /* called when an ascii key is pressed */
1058 void kbd_put_keysym_console(QemuConsole *s, int keysym)
1060 uint8_t buf[16], *q;
1063 if (!s || (s->console_type == GRAPHIC_CONSOLE))
1067 case QEMU_KEY_CTRL_UP:
1068 console_scroll(s, -1);
1070 case QEMU_KEY_CTRL_DOWN:
1071 console_scroll(s, 1);
1073 case QEMU_KEY_CTRL_PAGEUP:
1074 console_scroll(s, -10);
1076 case QEMU_KEY_CTRL_PAGEDOWN:
1077 console_scroll(s, 10);
1080 /* convert the QEMU keysym to VT100 key string */
1082 if (keysym >= 0xe100 && keysym <= 0xe11f) {
1085 c = keysym - 0xe100;
1087 *q++ = '0' + (c / 10);
1088 *q++ = '0' + (c % 10);
1090 } else if (keysym >= 0xe120 && keysym <= 0xe17f) {
1093 *q++ = keysym & 0xff;
1094 } else if (s->echo && (keysym == '\r' || keysym == '\n')) {
1095 console_puts(s->chr, (const uint8_t *) "\r", 1);
1101 console_puts(s->chr, buf, q - buf);
1103 if (s->chr->chr_read) {
1104 qemu_fifo_write(&s->out_fifo, buf, q - buf);
1111 static const int qcode_to_keysym[Q_KEY_CODE_MAX] = {
1112 [Q_KEY_CODE_UP] = QEMU_KEY_UP,
1113 [Q_KEY_CODE_DOWN] = QEMU_KEY_DOWN,
1114 [Q_KEY_CODE_RIGHT] = QEMU_KEY_RIGHT,
1115 [Q_KEY_CODE_LEFT] = QEMU_KEY_LEFT,
1116 [Q_KEY_CODE_HOME] = QEMU_KEY_HOME,
1117 [Q_KEY_CODE_END] = QEMU_KEY_END,
1118 [Q_KEY_CODE_PGUP] = QEMU_KEY_PAGEUP,
1119 [Q_KEY_CODE_PGDN] = QEMU_KEY_PAGEDOWN,
1120 [Q_KEY_CODE_DELETE] = QEMU_KEY_DELETE,
1123 bool kbd_put_qcode_console(QemuConsole *s, int qcode)
1127 keysym = qcode_to_keysym[qcode];
1131 kbd_put_keysym_console(s, keysym);
1135 void kbd_put_string_console(QemuConsole *s, const char *str, int len)
1139 for (i = 0; i < len && str[i]; i++) {
1140 kbd_put_keysym_console(s, str[i]);
1144 void kbd_put_keysym(int keysym)
1146 kbd_put_keysym_console(active_console, keysym);
1149 static void text_console_invalidate(void *opaque)
1151 QemuConsole *s = (QemuConsole *) opaque;
1153 if (s->ds->have_text && s->console_type == TEXT_CONSOLE) {
1154 text_console_resize(s);
1159 static void text_console_update(void *opaque, console_ch_t *chardata)
1161 QemuConsole *s = (QemuConsole *) opaque;
1164 if (s->text_x[0] <= s->text_x[1]) {
1165 src = (s->y_base + s->text_y[0]) * s->width;
1166 chardata += s->text_y[0] * s->width;
1167 for (i = s->text_y[0]; i <= s->text_y[1]; i ++)
1168 for (j = 0; j < s->width; j ++, src ++)
1169 console_write_ch(chardata ++, s->cells[src].ch |
1170 (s->cells[src].t_attrib.fgcol << 12) |
1171 (s->cells[src].t_attrib.bgcol << 8) |
1172 (s->cells[src].t_attrib.bold << 21));
1173 dpy_text_update(s, s->text_x[0], s->text_y[0],
1174 s->text_x[1] - s->text_x[0], i - s->text_y[0]);
1175 s->text_x[0] = s->width;
1176 s->text_y[0] = s->height;
1180 if (s->cursor_invalidate) {
1181 dpy_text_cursor(s, s->x, s->y);
1182 s->cursor_invalidate = 0;
1186 static QemuConsole *new_console(DisplayState *ds, console_type_t console_type,
1193 obj = object_new(TYPE_QEMU_CONSOLE);
1194 s = QEMU_CONSOLE(obj);
1196 object_property_add_link(obj, "device", TYPE_DEVICE,
1197 (Object **)&s->device,
1198 object_property_allow_set_link,
1199 OBJ_PROP_LINK_UNREF_ON_RELEASE,
1201 object_property_add_uint32_ptr(obj, "head",
1202 &s->head, &error_abort);
1204 if (!active_console || ((active_console->console_type != GRAPHIC_CONSOLE) &&
1205 (console_type == GRAPHIC_CONSOLE))) {
1209 s->console_type = console_type;
1211 consoles = g_realloc(consoles, sizeof(*consoles) * (nb_consoles+1));
1212 if (console_type != GRAPHIC_CONSOLE) {
1213 s->index = nb_consoles;
1214 consoles[nb_consoles++] = s;
1216 /* HACK: Put graphical consoles before text consoles. */
1217 for (i = nb_consoles; i > 0; i--) {
1218 if (consoles[i - 1]->console_type == GRAPHIC_CONSOLE)
1220 consoles[i] = consoles[i - 1];
1221 consoles[i]->index = i;
1230 static void qemu_alloc_display(DisplaySurface *surface, int width, int height)
1232 qemu_pixman_image_unref(surface->image);
1233 surface->image = NULL;
1235 surface->format = PIXMAN_x8r8g8b8;
1236 surface->image = pixman_image_create_bits(surface->format,
1239 assert(surface->image != NULL);
1241 surface->flags = QEMU_ALLOCATED_FLAG;
1244 DisplaySurface *qemu_create_displaysurface(int width, int height)
1246 DisplaySurface *surface = g_new0(DisplaySurface, 1);
1248 trace_displaysurface_create(surface, width, height);
1249 qemu_alloc_display(surface, width, height);
1253 DisplaySurface *qemu_create_displaysurface_from(int width, int height,
1254 pixman_format_code_t format,
1255 int linesize, uint8_t *data)
1257 DisplaySurface *surface = g_new0(DisplaySurface, 1);
1259 trace_displaysurface_create_from(surface, width, height, format);
1260 surface->format = format;
1261 surface->image = pixman_image_create_bits(surface->format,
1263 (void *)data, linesize);
1264 assert(surface->image != NULL);
1269 static void qemu_unmap_displaysurface_guestmem(pixman_image_t *image,
1272 void *data = pixman_image_get_data(image);
1273 uint32_t size = pixman_image_get_stride(image) *
1274 pixman_image_get_height(image);
1275 cpu_physical_memory_unmap(data, size, 0, 0);
1278 DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height,
1279 pixman_format_code_t format,
1280 int linesize, uint64_t addr)
1282 DisplaySurface *surface;
1286 if (linesize == 0) {
1287 linesize = width * PIXMAN_FORMAT_BPP(format) / 8;
1290 size = (hwaddr)linesize * height;
1291 data = cpu_physical_memory_map(addr, &size, 0);
1292 if (size != (hwaddr)linesize * height) {
1293 cpu_physical_memory_unmap(data, size, 0, 0);
1297 surface = qemu_create_displaysurface_from
1298 (width, height, format, linesize, data);
1299 pixman_image_set_destroy_function
1300 (surface->image, qemu_unmap_displaysurface_guestmem, NULL);
1305 static DisplaySurface *qemu_create_message_surface(int w, int h,
1308 DisplaySurface *surface = qemu_create_displaysurface(w, h);
1309 pixman_color_t bg = color_table_rgb[0][COLOR_BLACK];
1310 pixman_color_t fg = color_table_rgb[0][COLOR_WHITE];
1311 pixman_image_t *glyph;
1315 x = (w / FONT_WIDTH - len) / 2;
1316 y = (h / FONT_HEIGHT - 1) / 2;
1317 for (i = 0; i < len; i++) {
1318 glyph = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, msg[i]);
1319 qemu_pixman_glyph_render(glyph, surface->image, &fg, &bg,
1320 x+i, y, FONT_WIDTH, FONT_HEIGHT);
1321 qemu_pixman_image_unref(glyph);
1326 void qemu_free_displaysurface(DisplaySurface *surface)
1328 if (surface == NULL) {
1331 trace_displaysurface_free(surface);
1332 qemu_pixman_image_unref(surface->image);
1336 bool console_has_gl(QemuConsole *con)
1338 return con->gl != NULL;
1341 void register_displaychangelistener(DisplayChangeListener *dcl)
1343 static const char nodev[] =
1344 "This VM has no graphic display device.";
1345 static DisplaySurface *dummy;
1348 if (dcl->ops->dpy_gl_ctx_create) {
1349 /* display has opengl support */
1352 fprintf(stderr, "can't register two opengl displays (%s, %s)\n",
1353 dcl->ops->dpy_name, dcl->con->gl->ops->dpy_name);
1359 trace_displaychangelistener_register(dcl, dcl->ops->dpy_name);
1360 dcl->ds = get_alloc_displaystate();
1361 QLIST_INSERT_HEAD(&dcl->ds->listeners, dcl, next);
1362 gui_setup_refresh(dcl->ds);
1367 con = active_console;
1369 if (dcl->ops->dpy_gfx_switch) {
1371 dcl->ops->dpy_gfx_switch(dcl, con->surface);
1374 dummy = qemu_create_message_surface(640, 480, nodev);
1376 dcl->ops->dpy_gfx_switch(dcl, dummy);
1379 text_console_update_cursor(NULL);
1382 void update_displaychangelistener(DisplayChangeListener *dcl,
1385 DisplayState *ds = dcl->ds;
1387 dcl->update_interval = interval;
1388 if (!ds->refreshing && ds->update_interval > interval) {
1389 timer_mod(ds->gui_timer, ds->last_update + interval);
1393 void unregister_displaychangelistener(DisplayChangeListener *dcl)
1395 DisplayState *ds = dcl->ds;
1396 trace_displaychangelistener_unregister(dcl, dcl->ops->dpy_name);
1400 QLIST_REMOVE(dcl, next);
1401 gui_setup_refresh(ds);
1404 static void dpy_set_ui_info_timer(void *opaque)
1406 QemuConsole *con = opaque;
1408 con->hw_ops->ui_info(con->hw, con->head, &con->ui_info);
1411 bool dpy_ui_info_supported(QemuConsole *con)
1413 return con->hw_ops->ui_info != NULL;
1416 int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info)
1418 assert(con != NULL);
1419 con->ui_info = *info;
1420 if (!dpy_ui_info_supported(con)) {
1425 * Typically we get a flood of these as the user resizes the window.
1426 * Wait until the dust has settled (one second without updates), then
1427 * go notify the guest.
1429 timer_mod(con->ui_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1433 void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h)
1435 DisplayState *s = con->ds;
1436 DisplayChangeListener *dcl;
1441 width = surface_width(con->surface);
1442 height = surface_height(con->surface);
1448 w = MIN(w, width - x);
1449 h = MIN(h, height - y);
1451 if (!qemu_console_is_visible(con)) {
1454 QLIST_FOREACH(dcl, &s->listeners, next) {
1455 if (con != (dcl->con ? dcl->con : active_console)) {
1458 if (dcl->ops->dpy_gfx_update) {
1459 dcl->ops->dpy_gfx_update(dcl, x, y, w, h);
1464 void dpy_gfx_replace_surface(QemuConsole *con,
1465 DisplaySurface *surface)
1467 DisplayState *s = con->ds;
1468 DisplaySurface *old_surface = con->surface;
1469 DisplayChangeListener *dcl;
1471 con->surface = surface;
1472 QLIST_FOREACH(dcl, &s->listeners, next) {
1473 if (con != (dcl->con ? dcl->con : active_console)) {
1476 if (dcl->ops->dpy_gfx_switch) {
1477 dcl->ops->dpy_gfx_switch(dcl, surface);
1480 qemu_free_displaysurface(old_surface);
1483 bool dpy_gfx_check_format(QemuConsole *con,
1484 pixman_format_code_t format)
1486 DisplayChangeListener *dcl;
1487 DisplayState *s = con->ds;
1489 QLIST_FOREACH(dcl, &s->listeners, next) {
1490 if (dcl->con && dcl->con != con) {
1491 /* dcl bound to another console -> skip */
1494 if (dcl->ops->dpy_gfx_check_format) {
1495 if (!dcl->ops->dpy_gfx_check_format(dcl, format)) {
1499 /* default is to whitelist native 32 bpp only */
1500 if (format != qemu_default_pixman_format(32, true)) {
1508 static void dpy_refresh(DisplayState *s)
1510 DisplayChangeListener *dcl;
1512 QLIST_FOREACH(dcl, &s->listeners, next) {
1513 if (dcl->ops->dpy_refresh) {
1514 dcl->ops->dpy_refresh(dcl);
1519 void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
1520 int dst_x, int dst_y, int w, int h)
1522 DisplayState *s = con->ds;
1523 DisplayChangeListener *dcl;
1525 if (!qemu_console_is_visible(con)) {
1528 QLIST_FOREACH(dcl, &s->listeners, next) {
1529 if (con != (dcl->con ? dcl->con : active_console)) {
1532 if (dcl->ops->dpy_gfx_copy) {
1533 dcl->ops->dpy_gfx_copy(dcl, src_x, src_y, dst_x, dst_y, w, h);
1535 dcl->ops->dpy_gfx_update(dcl, dst_x, dst_y, w, h);
1540 void dpy_text_cursor(QemuConsole *con, int x, int y)
1542 DisplayState *s = con->ds;
1543 DisplayChangeListener *dcl;
1545 if (!qemu_console_is_visible(con)) {
1548 QLIST_FOREACH(dcl, &s->listeners, next) {
1549 if (con != (dcl->con ? dcl->con : active_console)) {
1552 if (dcl->ops->dpy_text_cursor) {
1553 dcl->ops->dpy_text_cursor(dcl, x, y);
1558 void dpy_text_update(QemuConsole *con, int x, int y, int w, int h)
1560 DisplayState *s = con->ds;
1561 DisplayChangeListener *dcl;
1563 if (!qemu_console_is_visible(con)) {
1566 QLIST_FOREACH(dcl, &s->listeners, next) {
1567 if (con != (dcl->con ? dcl->con : active_console)) {
1570 if (dcl->ops->dpy_text_update) {
1571 dcl->ops->dpy_text_update(dcl, x, y, w, h);
1576 void dpy_text_resize(QemuConsole *con, int w, int h)
1578 DisplayState *s = con->ds;
1579 DisplayChangeListener *dcl;
1581 if (!qemu_console_is_visible(con)) {
1584 QLIST_FOREACH(dcl, &s->listeners, next) {
1585 if (con != (dcl->con ? dcl->con : active_console)) {
1588 if (dcl->ops->dpy_text_resize) {
1589 dcl->ops->dpy_text_resize(dcl, w, h);
1594 void dpy_mouse_set(QemuConsole *con, int x, int y, int on)
1596 DisplayState *s = con->ds;
1597 DisplayChangeListener *dcl;
1599 if (!qemu_console_is_visible(con)) {
1602 QLIST_FOREACH(dcl, &s->listeners, next) {
1603 if (con != (dcl->con ? dcl->con : active_console)) {
1606 if (dcl->ops->dpy_mouse_set) {
1607 dcl->ops->dpy_mouse_set(dcl, x, y, on);
1612 void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor)
1614 DisplayState *s = con->ds;
1615 DisplayChangeListener *dcl;
1617 if (!qemu_console_is_visible(con)) {
1620 QLIST_FOREACH(dcl, &s->listeners, next) {
1621 if (con != (dcl->con ? dcl->con : active_console)) {
1624 if (dcl->ops->dpy_cursor_define) {
1625 dcl->ops->dpy_cursor_define(dcl, cursor);
1630 bool dpy_cursor_define_supported(QemuConsole *con)
1632 DisplayState *s = con->ds;
1633 DisplayChangeListener *dcl;
1635 QLIST_FOREACH(dcl, &s->listeners, next) {
1636 if (dcl->ops->dpy_cursor_define) {
1643 QEMUGLContext dpy_gl_ctx_create(QemuConsole *con,
1644 struct QEMUGLParams *qparams)
1647 return con->gl->ops->dpy_gl_ctx_create(con->gl, qparams);
1650 void dpy_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx)
1653 con->gl->ops->dpy_gl_ctx_destroy(con->gl, ctx);
1656 int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx)
1659 return con->gl->ops->dpy_gl_ctx_make_current(con->gl, ctx);
1662 QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con)
1665 return con->gl->ops->dpy_gl_ctx_get_current(con->gl);
1668 void dpy_gl_scanout(QemuConsole *con,
1669 uint32_t backing_id, bool backing_y_0_top,
1670 uint32_t x, uint32_t y, uint32_t width, uint32_t height)
1673 con->gl->ops->dpy_gl_scanout(con->gl, backing_id,
1675 x, y, width, height);
1678 void dpy_gl_update(QemuConsole *con,
1679 uint32_t x, uint32_t y, uint32_t w, uint32_t h)
1682 con->gl->ops->dpy_gl_update(con->gl, x, y, w, h);
1685 /***********************************************************/
1686 /* register display */
1688 /* console.c internal use only */
1689 static DisplayState *get_alloc_displaystate(void)
1691 if (!display_state) {
1692 display_state = g_new0(DisplayState, 1);
1693 cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME,
1694 text_console_update_cursor, NULL);
1696 return display_state;
1700 * Called by main(), after creating QemuConsoles
1701 * and before initializing ui (sdl/vnc/...).
1703 DisplayState *init_displaystate(void)
1708 get_alloc_displaystate();
1709 for (i = 0; i < nb_consoles; i++) {
1710 if (consoles[i]->console_type != GRAPHIC_CONSOLE &&
1711 consoles[i]->ds == NULL) {
1712 text_console_do_init(consoles[i]->chr, display_state);
1715 /* Hook up into the qom tree here (not in new_console()), once
1716 * all QemuConsoles are created and the order / numbering
1717 * doesn't change any more */
1718 name = g_strdup_printf("console[%d]", i);
1719 object_property_add_child(container_get(object_get_root(), "/backend"),
1720 name, OBJECT(consoles[i]), &error_abort);
1724 return display_state;
1727 void graphic_console_set_hwops(QemuConsole *con,
1728 const GraphicHwOps *hw_ops,
1731 con->hw_ops = hw_ops;
1735 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
1736 const GraphicHwOps *hw_ops,
1739 static const char noinit[] =
1740 "Guest has not initialized the display (yet).";
1746 ds = get_alloc_displaystate();
1747 trace_console_gfx_new();
1748 s = new_console(ds, GRAPHIC_CONSOLE, head);
1749 s->ui_timer = timer_new_ms(QEMU_CLOCK_REALTIME, dpy_set_ui_info_timer, s);
1750 graphic_console_set_hwops(s, hw_ops, opaque);
1752 object_property_set_link(OBJECT(s), OBJECT(dev), "device",
1756 s->surface = qemu_create_message_surface(width, height, noinit);
1760 QemuConsole *qemu_console_lookup_by_index(unsigned int index)
1762 if (index >= nb_consoles) {
1765 return consoles[index];
1768 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head)
1774 for (i = 0; i < nb_consoles; i++) {
1778 obj = object_property_get_link(OBJECT(consoles[i]),
1779 "device", &error_abort);
1780 if (DEVICE(obj) != dev) {
1783 h = object_property_get_int(OBJECT(consoles[i]),
1784 "head", &error_abort);
1793 bool qemu_console_is_visible(QemuConsole *con)
1795 return (con == active_console) || (con->dcls > 0);
1798 bool qemu_console_is_graphic(QemuConsole *con)
1801 con = active_console;
1803 return con && (con->console_type == GRAPHIC_CONSOLE);
1806 bool qemu_console_is_fixedsize(QemuConsole *con)
1809 con = active_console;
1811 return con && (con->console_type != TEXT_CONSOLE);
1814 char *qemu_console_get_label(QemuConsole *con)
1816 if (con->console_type == GRAPHIC_CONSOLE) {
1818 return g_strdup(object_get_typename(con->device));
1820 return g_strdup("VGA");
1822 if (con->chr && con->chr->label) {
1823 return g_strdup(con->chr->label);
1825 return g_strdup_printf("vc%d", con->index);
1829 int qemu_console_get_index(QemuConsole *con)
1832 con = active_console;
1834 return con ? con->index : -1;
1837 uint32_t qemu_console_get_head(QemuConsole *con)
1840 con = active_console;
1842 return con ? con->head : -1;
1845 QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con)
1847 assert(con != NULL);
1848 return &con->ui_info;
1851 int qemu_console_get_width(QemuConsole *con, int fallback)
1854 con = active_console;
1856 return con ? surface_width(con->surface) : fallback;
1859 int qemu_console_get_height(QemuConsole *con, int fallback)
1862 con = active_console;
1864 return con ? surface_height(con->surface) : fallback;
1867 static void text_console_set_echo(CharDriverState *chr, bool echo)
1869 QemuConsole *s = chr->opaque;
1874 static void text_console_update_cursor_timer(void)
1876 timer_mod(cursor_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)
1877 + CONSOLE_CURSOR_PERIOD / 2);
1880 static void text_console_update_cursor(void *opaque)
1885 cursor_visible_phase = !cursor_visible_phase;
1887 for (i = 0; i < nb_consoles; i++) {
1889 if (qemu_console_is_graphic(s) ||
1890 !qemu_console_is_visible(s)) {
1894 graphic_hw_invalidate(s);
1898 text_console_update_cursor_timer();
1902 static const GraphicHwOps text_console_ops = {
1903 .invalidate = text_console_invalidate,
1904 .text_update = text_console_update,
1907 static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
1910 int g_width = 80 * FONT_WIDTH;
1911 int g_height = 24 * FONT_HEIGHT;
1915 chr->chr_write = console_puts;
1917 s->out_fifo.buf = s->out_fifo_buf;
1918 s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
1919 s->kbd_timer = timer_new_ms(QEMU_CLOCK_REALTIME, kbd_send_chars, s);
1924 s->total_height = DEFAULT_BACKSCROLL;
1928 if (active_console && active_console->surface) {
1929 g_width = surface_width(active_console->surface);
1930 g_height = surface_height(active_console->surface);
1932 s->surface = qemu_create_displaysurface(g_width, g_height);
1935 s->hw_ops = &text_console_ops;
1938 /* Set text attribute defaults */
1939 s->t_attrib_default.bold = 0;
1940 s->t_attrib_default.uline = 0;
1941 s->t_attrib_default.blink = 0;
1942 s->t_attrib_default.invers = 0;
1943 s->t_attrib_default.unvisible = 0;
1944 s->t_attrib_default.fgcol = COLOR_WHITE;
1945 s->t_attrib_default.bgcol = COLOR_BLACK;
1946 /* set current text attributes to default */
1947 s->t_attrib = s->t_attrib_default;
1948 text_console_resize(s);
1954 s->t_attrib.bgcol = COLOR_BLUE;
1955 len = snprintf(msg, sizeof(msg), "%s console\r\n", chr->label);
1956 console_puts(chr, (uint8_t*)msg, len);
1957 s->t_attrib = s->t_attrib_default;
1960 qemu_chr_be_generic_open(chr);
1965 static CharDriverState *text_console_init(ChardevVC *vc, Error **errp)
1967 CharDriverState *chr;
1970 unsigned height = 0;
1972 chr = qemu_chr_alloc();
1974 if (vc->has_width) {
1976 } else if (vc->has_cols) {
1977 width = vc->cols * FONT_WIDTH;
1980 if (vc->has_height) {
1981 height = vc->height;
1982 } else if (vc->has_rows) {
1983 height = vc->rows * FONT_HEIGHT;
1986 trace_console_txt_new(width, height);
1987 if (width == 0 || height == 0) {
1988 s = new_console(NULL, TEXT_CONSOLE, 0);
1990 s = new_console(NULL, TEXT_CONSOLE_FIXED_SIZE, 0);
1991 s->surface = qemu_create_displaysurface(width, height);
1996 error_setg(errp, "cannot create text console");
2002 chr->chr_set_echo = text_console_set_echo;
2003 /* console/chardev init sometimes completes elsewhere in a 2nd
2004 * stage, so defer OPENED events until they are fully initialized
2006 chr->explicit_be_open = true;
2008 if (display_state) {
2009 text_console_do_init(chr, display_state);
2014 static VcHandler *vc_handler = text_console_init;
2016 static CharDriverState *vc_init(const char *id, ChardevBackend *backend,
2017 ChardevReturn *ret, Error **errp)
2019 return vc_handler(backend->vc, errp);
2022 void register_vc_handler(VcHandler *handler)
2024 vc_handler = handler;
2027 void qemu_console_resize(QemuConsole *s, int width, int height)
2029 DisplaySurface *surface;
2031 assert(s->console_type == GRAPHIC_CONSOLE);
2032 surface = qemu_create_displaysurface(width, height);
2033 dpy_gfx_replace_surface(s, surface);
2036 void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
2037 int dst_x, int dst_y, int w, int h)
2039 assert(con->console_type == GRAPHIC_CONSOLE);
2040 dpy_gfx_copy(con, src_x, src_y, dst_x, dst_y, w, h);
2043 DisplaySurface *qemu_console_surface(QemuConsole *console)
2045 return console->surface;
2048 PixelFormat qemu_default_pixelformat(int bpp)
2050 pixman_format_code_t fmt = qemu_default_pixman_format(bpp, true);
2051 PixelFormat pf = qemu_pixelformat_from_pixman(fmt);
2055 static void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend,
2060 backend->vc = g_new0(ChardevVC, 1);
2062 val = qemu_opt_get_number(opts, "width", 0);
2064 backend->vc->has_width = true;
2065 backend->vc->width = val;
2068 val = qemu_opt_get_number(opts, "height", 0);
2070 backend->vc->has_height = true;
2071 backend->vc->height = val;
2074 val = qemu_opt_get_number(opts, "cols", 0);
2076 backend->vc->has_cols = true;
2077 backend->vc->cols = val;
2080 val = qemu_opt_get_number(opts, "rows", 0);
2082 backend->vc->has_rows = true;
2083 backend->vc->rows = val;
2087 static const TypeInfo qemu_console_info = {
2088 .name = TYPE_QEMU_CONSOLE,
2089 .parent = TYPE_OBJECT,
2090 .instance_size = sizeof(QemuConsole),
2091 .class_size = sizeof(QemuConsoleClass),
2095 static void register_types(void)
2097 type_register_static(&qemu_console_info);
2098 register_char_driver("vc", CHARDEV_BACKEND_KIND_VC, qemu_chr_parse_vc,
2102 type_init(register_types);