From f52506f4827dfa6da47730c4756a984b05db6dda Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 10 Sep 2010 16:11:22 +0200 Subject: upstream: console changes. --- console.c | 292 ++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 207 insertions(+), 85 deletions(-) (limited to 'console.c') diff --git a/console.c b/console.c index 50dda6c..6125894 100644 --- a/console.c +++ b/console.c @@ -154,16 +154,19 @@ struct TextConsole { QEMUTimer *kbd_timer; }; +static DisplayState *display_state; static TextConsole *active_console; static TextConsole *consoles[MAX_CONSOLES]; static int nb_consoles = 0; +#ifdef CONFIG_ANDROID /* Graphic console width, height and bits per pixel. * These default values can be changed with the "-android-gui" option. */ int android_display_width = 640; int android_display_height = 480; int android_display_bpp = 32; +#endif void vga_hw_update(void) { @@ -1271,6 +1274,117 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type) return s; } +static DisplaySurface* defaultallocator_create_displaysurface(int width, int height) +{ + DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface)); + + surface->width = width; + surface->height = height; + surface->linesize = width * 4; + surface->pf = qemu_default_pixelformat(32); +#ifdef HOST_WORDS_BIGENDIAN + surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG; +#else + surface->flags = QEMU_ALLOCATED_FLAG; +#endif + surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height); + + return surface; +} + +static DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface, + int width, int height) +{ + surface->width = width; + surface->height = height; + surface->linesize = width * 4; + surface->pf = qemu_default_pixelformat(32); + if (surface->flags & QEMU_ALLOCATED_FLAG) + surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height); + else + surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height); +#ifdef HOST_WORDS_BIGENDIAN + surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG; +#else + surface->flags = QEMU_ALLOCATED_FLAG; +#endif + + return surface; +} + +DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp, + int linesize, uint8_t *data) +{ + DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface)); + + surface->width = width; + surface->height = height; + surface->linesize = linesize; + surface->pf = qemu_default_pixelformat(bpp); +#ifdef HOST_WORDS_BIGENDIAN + surface->flags = QEMU_BIG_ENDIAN_FLAG; +#endif + surface->data = data; + + return surface; +} + +static void defaultallocator_free_displaysurface(DisplaySurface *surface) +{ + if (surface == NULL) + return; + if (surface->flags & QEMU_ALLOCATED_FLAG) + qemu_free(surface->data); + qemu_free(surface); +} + +static struct DisplayAllocator default_allocator = { + defaultallocator_create_displaysurface, + defaultallocator_resize_displaysurface, + defaultallocator_free_displaysurface +}; + +static void dumb_display_init(void) +{ + DisplayState *ds = qemu_mallocz(sizeof(DisplayState)); + ds->allocator = &default_allocator; + ds->surface = qemu_create_displaysurface(ds, 640, 480); + register_displaystate(ds); +} + +/***********************************************************/ +/* register display */ + +void register_displaystate(DisplayState *ds) +{ + DisplayState **s; + s = &display_state; + while (*s != NULL) + s = &(*s)->next; + ds->next = NULL; + *s = ds; +} + +DisplayState *get_displaystate(void) +{ + if (!display_state) { + dumb_display_init (); + } + return display_state; +} + +DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da) +{ + if(ds->allocator == &default_allocator) { + DisplaySurface *surf; + surf = da->create_displaysurface(ds_get_width(ds), ds_get_height(ds)); + defaultallocator_free_displaysurface(ds->surface); + ds->surface = surf; + ds->allocator = da; + } + return ds->allocator; +} + DisplayState *graphic_console_init(vga_hw_update_ptr update, vga_hw_invalidate_ptr invalidate, vga_hw_screen_dump_ptr screen_dump, @@ -1281,8 +1395,12 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update, DisplayState *ds; ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState)); - ds->allocator = &default_allocator; + ds->allocator = &default_allocator; +#ifdef CONFIG_ANDROID ds->surface = qemu_create_displaysurface(ds, android_display_width, android_display_height); +#else + ds->surface = qemu_create_displaysurface(ds, 640, 480); +#endif s = new_console(ds, GRAPHIC_CONSOLE); if (s == NULL) { @@ -1323,16 +1441,31 @@ void console_color_init(DisplayState *ds) static int n_text_consoles; static CharDriverState *text_consoles[128]; -static char *text_console_strs[128]; +static QemuOpts *text_console_opts[128]; -static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const char *p) +static void text_console_do_init(CharDriverState *chr, DisplayState *ds, QemuOpts *opts) { TextConsole *s; unsigned width; unsigned height; static int color_inited; - s = new_console(ds, (p == NULL) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE); + width = qemu_opt_get_number(opts, "width", 0); + if (width == 0) + width = qemu_opt_get_number(opts, "cols", 0) * FONT_WIDTH; + + height = qemu_opt_get_number(opts, "height", 0); + if (height == 0) + height = qemu_opt_get_number(opts, "rows", 0) * FONT_HEIGHT; + + if (width == 0 || height == 0) { + s = new_console(ds, TEXT_CONSOLE); + width = ds_get_width(s->ds); + height = ds_get_height(s->ds); + } else { + s = new_console(ds, TEXT_CONSOLE_FIXED_SIZE); + } + if (!s) { free(chr); return; @@ -1356,23 +1489,6 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c s->total_height = DEFAULT_BACKSCROLL; s->x = 0; s->y = 0; - width = ds_get_width(s->ds); - height = ds_get_height(s->ds); - if (p != NULL) { - width = strtoul(p, (char **)&p, 10); - if (*p == 'C') { - p++; - width *= FONT_WIDTH; - } - if (*p == 'x') { - p++; - height = strtoul(p, (char **)&p, 10); - if (*p == 'C') { - p++; - height *= FONT_HEIGHT; - } - } - } s->g_width = width; s->g_height = height; @@ -1392,12 +1508,22 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const c s->t_attrib = s->t_attrib_default; text_console_resize(s); + if (chr->label) { + char msg[128]; + int len; + + s->t_attrib.bgcol = COLOR_BLUE; + len = snprintf(msg, sizeof(msg), "%s console\r\n", chr->label); + console_puts(chr, (uint8_t*)msg, len); + s->t_attrib = s->t_attrib_default; + } + qemu_chr_generic_open(chr); if (chr->init) chr->init(chr); } -CharDriverState *text_console_init(const char *p) +CharDriverState *text_console_init(QemuOpts *opts) { CharDriverState *chr; @@ -1408,19 +1534,52 @@ CharDriverState *text_console_init(const char *p) exit(1); } text_consoles[n_text_consoles] = chr; - text_console_strs[n_text_consoles] = p ? qemu_strdup(p) : NULL; + text_console_opts[n_text_consoles] = opts; n_text_consoles++; return chr; } +CharDriverState* text_console_init_compat(const char *label, const char *p) +{ + QemuOpts *opts; + int width, height; + char temp[32]; + + opts = qemu_opts_create(qemu_find_opts("chardev"), label, 1); + if (NULL == opts) + return NULL; + + if (p != NULL) { + width = strtoul(p, (char **)&p, 10); + if (*p == 'C') { + p++; + width *= FONT_WIDTH; + } + snprintf(temp, sizeof temp, "%d", width); + qemu_opt_set(opts, "width", temp); + if (*p == 'x') { + p++; + height = strtoul(p, (char **)&p, 10); + if (*p == 'C') { + p++; + height *= FONT_HEIGHT; + } + snprintf(temp, sizeof temp, "%d", height); + qemu_opt_set(opts, "height", temp); + } + } + return text_console_init(opts); +} + void text_consoles_set_display(DisplayState *ds) { int i; for (i = 0; i < n_text_consoles; i++) { - text_console_do_init(text_consoles[i], ds, text_console_strs[i]); - qemu_free(text_console_strs[i]); + text_console_do_init(text_consoles[i], ds, text_console_opts[i]); + qemu_opts_del(text_console_opts[i]); + text_console_opts[i] = NULL; } n_text_consoles = 0; @@ -1507,6 +1666,22 @@ PixelFormat qemu_default_pixelformat(int bpp) pf.depth = bpp == 32 ? 24 : bpp; switch (bpp) { + case 15: + pf.bits_per_pixel = 16; + pf.bytes_per_pixel = 2; + pf.rmask = 0x00007c00; + pf.gmask = 0x000003E0; + pf.bmask = 0x0000001F; + pf.rmax = 31; + pf.gmax = 31; + pf.bmax = 31; + pf.rshift = 10; + pf.gshift = 5; + pf.bshift = 0; + pf.rbits = 5; + pf.gbits = 5; + pf.bbits = 5; + break; case 16: pf.rmask = 0x0000F800; pf.gmask = 0x000007E0; @@ -1557,66 +1732,13 @@ PixelFormat qemu_default_pixelformat(int bpp) return pf; } -DisplaySurface* defaultallocator_create_displaysurface(int width, int height) +#ifdef CONFIG_ANDROID +void +android_display_init_from(int width, int height, int rotation, int bpp) { - DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface)); - - surface->width = width; - surface->height = height; - surface->pf = qemu_default_pixelformat(android_display_bpp); - surface->linesize = width * surface->pf.bytes_per_pixel; -#ifdef HOST_WORDS_BIGENDIAN - surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG; -#else - surface->flags = QEMU_ALLOCATED_FLAG; -#endif - surface->data = (uint8_t*) qemu_mallocz(surface->linesize * surface->height); - - return surface; -} - -DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface, - int width, int height) -{ - surface->width = width; - surface->height = height; - surface->pf = qemu_default_pixelformat(android_display_bpp); - surface->linesize = width * surface->pf.bytes_per_pixel; - if (surface->flags & QEMU_ALLOCATED_FLAG) - surface->data = (uint8_t*) qemu_realloc(surface->data, surface->linesize * surface->height); - else - surface->data = (uint8_t*) qemu_malloc(surface->linesize * surface->height); -#ifdef HOST_WORDS_BIGENDIAN - surface->flags = QEMU_ALLOCATED_FLAG | QEMU_BIG_ENDIAN_FLAG; -#else - surface->flags = QEMU_ALLOCATED_FLAG; -#endif - - return surface; + DisplayState *ds = qemu_mallocz(sizeof(DisplayState)); + ds->allocator = &default_allocator; + ds->surface = qemu_create_displaysurface(ds, width, height); + register_displaystate(ds); } - -DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp, - int linesize, uint8_t *data) -{ - DisplaySurface *surface = (DisplaySurface*) qemu_mallocz(sizeof(DisplaySurface)); - - surface->width = width; - surface->height = height; - surface->linesize = linesize; - surface->pf = qemu_default_pixelformat(bpp); -#ifdef HOST_WORDS_BIGENDIAN - surface->flags = QEMU_BIG_ENDIAN_FLAG; #endif - surface->data = data; - - return surface; -} - -void defaultallocator_free_displaysurface(DisplaySurface *surface) -{ - if (surface == NULL) - return; - if (surface->flags & QEMU_ALLOCATED_FLAG) - qemu_free(surface->data); - qemu_free(surface); -} -- cgit v1.1