Skip to contentSkip to conversation

move stuff out from vl.c to console.c

PATCH Applied Paolo Bonzini 2 participants 6 messages Feb 10, 2010 – Feb 19, 2010

lore
Share & tools
lore
#0 lore raw

cover move stuff out from vl.c to console.c

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(-)
#1 lore raw

PATCH 1/3 use lazy initialization for display_state

Ensure initialization of a dumb display, if needed, by making all accesses go through get_displaystate.

---
 vl.c |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)
vl.c +15 -14
index 5ddf1fe..94aeb5e 100644
@@ -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);
Signature · 1 line
1.6.6
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] use lazy initialization for display_state

Quoted 5 lines · Paolo Bonzini

Ensure initialization of a dumb display, if needed, by making all accesses go through get_displaystate.

Applied all. Thanks.

Regards,

Anthony Liguori

Quoted 74 lines
---
  vl.c |   29 +++++++++++++++--------------
  1 files changed, 15 insertions(+), 14 deletions(-)
vl.c +15 -14
index 5ddf1fe..94aeb5e 100644
@@ -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);
#3 lore raw

PATCH 2/3 remove knowledge of defaultallocator_free_displaysurface from sdl.c

In reply to Paolo Bonzini

Let register_displayallocator hand over the old width/height to the new allocator.

---
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(-)
sdl.c +0 -4
index cf27ad2..a9b4323 100644
@@ -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);
     }
 
vl.c +7 -1
index 94aeb5e..8e8b4d1 100644
@@ -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;
 }
 
Signature · 1 line
1.6.6
#4 lore raw

PATCH 3/3 move default allocator to console.c

In reply to Paolo Bonzini

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.

---
 console.c |  176 +++++++++++++++++++++++++++++++++++++++----------------------
 console.h |    4 --
 vl.c      |   50 -----------------
 3 files changed, 112 insertions(+), 118 deletions(-)
console.c +112 -64
index 8086bd6..8bcd00b 100644
@@ -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);
-}
console.h +0 -4
index dfc8ae4..916859d 100644
@@ -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)
 {
vl.c +0 -50

62 lines not on this page · raw message

Signature · 1 line
1.6.6
#5 lore raw
In reply to Paolo Bonzini
Quoted 3 lines · Paolo Bonzini

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

Quoted 14 lines

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(-)