From patchwork Wed Feb 10 23:29:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 45076 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2A22AB7CB8 for ; Thu, 11 Feb 2010 10:39:42 +1100 (EST) Received: from localhost ([127.0.0.1]:36622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfM9e-0005gW-FS for incoming@patchwork.ozlabs.org; Wed, 10 Feb 2010 18:39:34 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NfM0c-0008N0-Eh for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:30:14 -0500 Received: from [199.232.76.173] (port=46824 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfM0b-0008Ma-TD for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:30:13 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NfM0a-0004P3-OC for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:30:13 -0500 Received: from mail-fx0-f223.google.com ([209.85.220.223]:32872) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NfM0Z-0004Oh-Nr for qemu-devel@nongnu.org; Wed, 10 Feb 2010 18:30:12 -0500 Received: by mail-fx0-f223.google.com with SMTP id 23so607164fxm.2 for ; Wed, 10 Feb 2010 15:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=ZDD/UmFBWS3d65LOMJkBn8LOJj2L0ceUrxMdEQ62g7o=; b=mma5SlCG3sOOoYjAQwJaPzHOxDndycz9AeLyoQ+nYAgX3r0jEDCAtjpOxb4u7faLw5 DI12laMZxfYPdDi3XSFpxw9EgD65xEs2IK3vpldiHCQwnIwZbcQKnIlqPI2/OgsGif8l +N4E0/9vNHt6dc3aSkn8gbmwGK5w6WXsVubbQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=vPdiY6eMqdyKCzvRSK8gq8gS9ucY/J+f+wrxJKaB7ViGiTvjk3iuD2sslzXr2b1I8h 1Dl5/YUfCc1cKlTrdhp/f2202yNbjas7LSKTj4e0VbMx9FDNn+tC0Cvb7eDLxDq/rHTi CywtP2XYsm5MG2mK22t1LgVrN/M7C4DaWK0x4= Received: by 10.223.95.69 with SMTP id c5mr1201044fan.44.1265844611206; Wed, 10 Feb 2010 15:30:11 -0800 (PST) Received: from localhost.localdomain ([85.93.118.17]) by mx.google.com with ESMTPS id 19sm2852341fkr.18.2010.02.10.15.30.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Feb 2010 15:30:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 11 Feb 2010 00:29:57 +0100 Message-Id: <1265844597-29941-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.6.6 In-Reply-To: <1265844597-29941-1-git-send-email-pbonzini@redhat.com> References: <1265844597-29941-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 3/3] move default allocator to console.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Moving stuff in console.c to avoid the need for prototypes makes this patch a bit bigger, but there's no change in the code. Signed-off-by: Paolo Bonzini --- console.c | 176 +++++++++++++++++++++++++++++++++++++++---------------------- console.h | 4 -- vl.c | 50 ----------------- 3 files changed, 112 insertions(+), 118 deletions(-) diff --git a/console.c b/console.c index 8086bd6..8bcd00b 100644 --- a/console.c +++ b/console.c @@ -154,6 +154,7 @@ struct TextConsole { QEMUTimer *kbd_timer; }; +static DisplayState *display_state; static TextConsole *active_console; static TextConsole *consoles[MAX_CONSOLES]; static int nb_consoles = 0; @@ -1265,6 +1266,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, @@ -1559,67 +1671,3 @@ PixelFormat qemu_default_pixelformat(int bpp) } return pf; } - -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; -} - -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; -} - -void defaultallocator_free_displaysurface(DisplaySurface *surface) -{ - if (surface == NULL) - return; - if (surface->flags & QEMU_ALLOCATED_FLAG) - qemu_free(surface->data); - qemu_free(surface); -} diff --git a/console.h b/console.h index dfc8ae4..916859d 100644 --- a/console.h +++ b/console.h @@ -144,11 +144,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) { diff --git a/vl.c b/vl.c index 8e8b4d1..2e24ebd 100644 --- a/vl.c +++ b/vl.c @@ -182,7 +182,6 @@ const char *bios_name = NULL; struct drivelist drives = QTAILQ_HEAD_INITIALIZER(drives); struct driveoptlist driveopts = QTAILQ_HEAD_INITIALIZER(driveopts); enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; -static DisplayState *display_state; DisplayType display_type = DT_DEFAULT; const char* keyboard_layout = NULL; ram_addr_t ram_size; @@ -2560,55 +2559,6 @@ void pcmcia_info(Monitor *mon) } /***********************************************************/ -/* register display */ - -struct DisplayAllocator default_allocator = { - defaultallocator_create_displaysurface, - defaultallocator_resize_displaysurface, - defaultallocator_free_displaysurface -}; - -/* 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); -} - -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; -} - -/***********************************************************/ /* I/O handling */ typedef struct IOHandlerRecord {