diff options
author | David Turner <digit@android.com> | 2010-09-10 16:11:22 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@android.com> | 2010-09-13 00:30:35 -0700 |
commit | f52506f4827dfa6da47730c4756a984b05db6dda (patch) | |
tree | b44a329946de9bed358d23c12dbe905999bf14c9 | |
parent | 025c32ffcd9f682cd761a836fe8798738d1648f2 (diff) | |
download | external_qemu-f52506f4827dfa6da47730c4756a984b05db6dda.zip external_qemu-f52506f4827dfa6da47730c4756a984b05db6dda.tar.gz external_qemu-f52506f4827dfa6da47730c4756a984b05db6dda.tar.bz2 |
upstream: console changes.
-rw-r--r-- | Makefile.android | 1 | ||||
-rw-r--r-- | console.c | 292 | ||||
-rw-r--r-- | console.h | 17 | ||||
-rw-r--r-- | qemu-char-android.c | 4 | ||||
-rw-r--r-- | qemu-char.c | 2 | ||||
-rw-r--r-- | vl-android.c | 53 |
6 files changed, 222 insertions, 147 deletions
diff --git a/Makefile.android b/Makefile.android index c7eba40..998459d 100644 --- a/Makefile.android +++ b/Makefile.android @@ -657,6 +657,7 @@ CORE_MISC_SOURCES = vl-android.c \ net-android.c \ aio-android.c \ dma-helpers.c \ + qemu-config.c \ qemu-sockets-android.c \ bt-host.c \ bt-vhci.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); -} @@ -184,8 +184,7 @@ struct DisplayState { struct DisplayChangeListener* listeners; void (*mouse_set)(int x, int y, int on); - void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y, - uint8_t *image, uint8_t *mask); + void (*cursor_define)(QEMUCursor *cursor); struct DisplayState *next; }; @@ -197,11 +196,7 @@ DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp, PixelFormat qemu_different_endianness_pixelformat(int bpp); PixelFormat qemu_default_pixelformat(int bpp); -extern struct DisplayAllocator default_allocator; DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da); -DisplaySurface* defaultallocator_create_displaysurface(int width, int height); -DisplaySurface* defaultallocator_resize_displaysurface(DisplaySurface *surface, int width, int height); -void defaultallocator_free_displaysurface(DisplaySurface *surface); static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height) { @@ -228,7 +223,8 @@ static inline int is_surface_bgr(DisplaySurface *surface) static inline int is_buffer_shared(DisplaySurface *surface) { - return (!(surface->flags & QEMU_ALLOCATED_FLAG)); + return (!(surface->flags & QEMU_ALLOCATED_FLAG) && + !(surface->flags & QEMU_REALPIXELS_FLAG)); } static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl) @@ -358,7 +354,8 @@ void vga_hw_text_update(console_ch_t *chardata); int is_graphic_console(void); int is_fixedsize_console(void); -CharDriverState *text_console_init(const char *p); +CharDriverState *text_console_init(QemuOpts *opts); +CharDriverState* text_console_init_compat(const char *label, const char *p); void text_consoles_set_display(DisplayState *ds); void console_select(unsigned int index); void console_color_init(DisplayState *ds); @@ -383,4 +380,8 @@ char *vnc_display_local_addr(DisplayState *ds); /* curses.c */ void curses_display_init(DisplayState *ds, int full_screen); +#ifdef CONFIG_ANDROID +void android_display_init_from(int width, int height, int rotation, int bpp); +#endif + #endif diff --git a/qemu-char-android.c b/qemu-char-android.c index a3cfe46..7753bf9 100644 --- a/qemu-char-android.c +++ b/qemu-char-android.c @@ -2314,10 +2314,10 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename, void (*i CharDriverState *chr; if (!strcmp(filename, "vc")) { - chr = text_console_init(0); + chr = text_console_init_compat(label, NULL); } else if (strstart(filename, "vc:", &p)) { - chr = text_console_init(p); + chr = text_console_init_compat(label, p); } else if (!strcmp(filename, "null")) { chr = qemu_chr_open_null(); diff --git a/qemu-char.c b/qemu-char.c index d941d37..f1834a6 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2441,7 +2441,7 @@ static const struct { { .name = "socket", .open = qemu_chr_open_socket }, { .name = "udp", .open = qemu_chr_open_udp }, { .name = "msmouse", .open = qemu_chr_open_msmouse }, - { .name = "vc", .open = text_console_init }, + { .name = "vc", .open = text_console_init_compat }, #ifdef _WIN32 { .name = "file", .open = qemu_chr_open_win_file_out }, { .name = "pipe", .open = qemu_chr_open_win_pipe }, diff --git a/vl-android.c b/vl-android.c index 0cd5336..b84cd22 100644 --- a/vl-android.c +++ b/vl-android.c @@ -1678,55 +1678,6 @@ void pcmcia_info(Monitor *mon) } /***********************************************************/ -/* register display */ - -struct DisplayAllocator default_allocator = { - defaultallocator_create_displaysurface, - defaultallocator_resize_displaysurface, - defaultallocator_free_displaysurface -}; - -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) -{ - return display_state; -} - -DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da) -{ - if(ds->allocator == &default_allocator) ds->allocator = da; - return ds->allocator; -} - -/* dumb display */ - -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); -} - -static void -android_display_init_from(int width, int height, int rotation, int bpp) -{ - DisplayState *ds = qemu_mallocz(sizeof(DisplayState)); - ds->allocator = &default_allocator; - ds->surface = qemu_create_displaysurface(ds, width, height); - register_displaystate(ds); -} - -/***********************************************************/ /* I/O handling */ typedef struct IOHandlerRecord { @@ -5352,7 +5303,7 @@ int main(int argc, char **argv, char **envp) android_display_height, 0, android_display_bpp); } else { - dumb_display_init(); + ds = get_displaystate(); /* this forces a dumb display init */ } } else if (android_op_gui) { /* Resize display from the command line parameters. */ @@ -5368,7 +5319,7 @@ int main(int argc, char **argv, char **envp) } /* just use the first displaystate for the moment */ - ds = display_state; + ds = display_state = get_displaystate(); if (display_type == DT_DEFAULT) { #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |