* [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c
@ 2010-02-10 23:29 Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state Paolo Bonzini
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:29 UTC (permalink / raw)
To: qemu-devel
Moving stuff around to console.c; video does not belong in a target-dependent
file.
Paolo Bonzini (3):
use lazy initialization for display_state
remove knowledge of defaultallocator_free_displaysurface from sdl.c
move default allocator to console.c
console.c | 176 +++++++++++++++++++++++++++++++++++++++----------------------
console.h | 4 --
sdl.c | 4 --
vl.c | 47 +----------------
4 files changed, 114 insertions(+), 117 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state
2010-02-10 23:29 [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c Paolo Bonzini
@ 2010-02-10 23:29 ` Paolo Bonzini
2010-02-19 21:28 ` Anthony Liguori
2010-02-10 23:29 ` [Qemu-devel] [PATCH 2/3] remove knowledge of defaultallocator_free_displaysurface from sdl.c Paolo Bonzini
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:29 UTC (permalink / raw)
To: qemu-devel
Ensure initialization of a dumb display, if needed, by making
all accesses go through get_displaystate.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
vl.c | 29 +++++++++++++++--------------
1 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/vl.c b/vl.c
index 5ddf1fe..94aeb5e 100644
--- a/vl.c
+++ b/vl.c
@@ -2568,6 +2568,16 @@ struct DisplayAllocator default_allocator = {
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;
@@ -2580,6 +2590,9 @@ void register_displaystate(DisplayState *ds)
DisplayState *get_displaystate(void)
{
+ if (!display_state) {
+ dumb_display_init();
+ }
return display_state;
}
@@ -2589,16 +2602,6 @@ DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *
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);
-}
-
/***********************************************************/
/* I/O handling */
@@ -5871,10 +5874,8 @@ int main(int argc, char **argv, char **envp)
if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0)
exit(1);
- if (!display_state)
- dumb_display_init();
/* just use the first displaystate for the moment */
- ds = display_state;
+ ds = get_displaystate();
if (display_type == DT_DEFAULT) {
#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
@@ -5932,7 +5933,7 @@ int main(int argc, char **argv, char **envp)
qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
}
- text_consoles_set_display(display_state);
+ text_consoles_set_display(ds);
if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0)
exit(1);
--
1.6.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/3] remove knowledge of defaultallocator_free_displaysurface from sdl.c
2010-02-10 23:29 [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state Paolo Bonzini
@ 2010-02-10 23:29 ` Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 3/3] move default allocator to console.c Paolo Bonzini
2010-02-11 2:10 ` [Qemu-devel] [PATCH 0/3] move stuff out from vl.c " Anthony Liguori
3 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:29 UTC (permalink / raw)
To: qemu-devel
Let register_displayallocator hand over the old width/height to the new
allocator.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
So these functions will be made static when moved to console.c.
sdl.c | 4 ----
vl.c | 8 +++++++-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/sdl.c b/sdl.c
index cf27ad2..a9b4323 100644
--- a/sdl.c
+++ b/sdl.c
@@ -872,10 +872,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
da->resize_displaysurface = sdl_resize_displaysurface;
da->free_displaysurface = sdl_free_displaysurface;
if (register_displayallocator(ds, da) == da) {
- DisplaySurface *surf;
- surf = sdl_create_displaysurface(ds_get_width(ds), ds_get_height(ds));
- defaultallocator_free_displaysurface(ds->surface);
- ds->surface = surf;
dpy_resize(ds);
}
diff --git a/vl.c b/vl.c
index 94aeb5e..8e8b4d1 100644
--- a/vl.c
+++ b/vl.c
@@ -2598,7 +2598,13 @@ DisplayState *get_displaystate(void)
DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da)
{
- if(ds->allocator == &default_allocator) ds->allocator = 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;
}
--
1.6.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/3] move default allocator to console.c
2010-02-10 23:29 [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 2/3] remove knowledge of defaultallocator_free_displaysurface from sdl.c Paolo Bonzini
@ 2010-02-10 23:29 ` Paolo Bonzini
2010-02-11 2:10 ` [Qemu-devel] [PATCH 0/3] move stuff out from vl.c " Anthony Liguori
3 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2010-02-10 23:29 UTC (permalink / raw)
To: qemu-devel
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 <pbonzini@redhat.com>
---
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 {
--
1.6.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c
2010-02-10 23:29 [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c Paolo Bonzini
` (2 preceding siblings ...)
2010-02-10 23:29 ` [Qemu-devel] [PATCH 3/3] move default allocator to console.c Paolo Bonzini
@ 2010-02-11 2:10 ` Anthony Liguori
3 siblings, 0 replies; 6+ messages in thread
From: Anthony Liguori @ 2010-02-11 2:10 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
On 02/10/2010 05:29 PM, Paolo Bonzini wrote:
> Moving stuff around to console.c; video does not belong in a target-dependent
> file.
>
Excellent. I love series that move stuff out of vl.c :-)
Regards,
Anthony Liguori
> Paolo Bonzini (3):
> use lazy initialization for display_state
> remove knowledge of defaultallocator_free_displaysurface from sdl.c
> move default allocator to console.c
>
> console.c | 176 +++++++++++++++++++++++++++++++++++++++----------------------
> console.h | 4 --
> sdl.c | 4 --
> vl.c | 47 +----------------
> 4 files changed, 114 insertions(+), 117 deletions(-)
>
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state
2010-02-10 23:29 ` [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state Paolo Bonzini
@ 2010-02-19 21:28 ` Anthony Liguori
0 siblings, 0 replies; 6+ messages in thread
From: Anthony Liguori @ 2010-02-19 21:28 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
On 02/10/2010 05:29 PM, Paolo Bonzini wrote:
> Ensure initialization of a dumb display, if needed, by making
> all accesses go through get_displaystate.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
>
Applied all. Thanks.
Regards,
Anthony Liguori
> ---
> vl.c | 29 +++++++++++++++--------------
> 1 files changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/vl.c b/vl.c
> index 5ddf1fe..94aeb5e 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2568,6 +2568,16 @@ struct DisplayAllocator default_allocator = {
> 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;
> @@ -2580,6 +2590,9 @@ void register_displaystate(DisplayState *ds)
>
> DisplayState *get_displaystate(void)
> {
> + if (!display_state) {
> + dumb_display_init();
> + }
> return display_state;
> }
>
> @@ -2589,16 +2602,6 @@ DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *
> 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);
> -}
> -
> /***********************************************************/
> /* I/O handling */
>
> @@ -5871,10 +5874,8 @@ int main(int argc, char **argv, char **envp)
> if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0)
> exit(1);
>
> - if (!display_state)
> - dumb_display_init();
> /* just use the first displaystate for the moment */
> - ds = display_state;
> + ds = get_displaystate();
>
> if (display_type == DT_DEFAULT) {
> #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
> @@ -5932,7 +5933,7 @@ int main(int argc, char **argv, char **envp)
> qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
> }
>
> - text_consoles_set_display(display_state);
> + text_consoles_set_display(ds);
>
> if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0)
> exit(1);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-02-19 21:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-10 23:29 [Qemu-devel] [PATCH 0/3] move stuff out from vl.c to console.c Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state Paolo Bonzini
2010-02-19 21:28 ` Anthony Liguori
2010-02-10 23:29 ` [Qemu-devel] [PATCH 2/3] remove knowledge of defaultallocator_free_displaysurface from sdl.c Paolo Bonzini
2010-02-10 23:29 ` [Qemu-devel] [PATCH 3/3] move default allocator to console.c Paolo Bonzini
2010-02-11 2:10 ` [Qemu-devel] [PATCH 0/3] move stuff out from vl.c " Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).