All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 5 of 7] graphical_console_init change
Date: Thu, 18 Dec 2008 19:13:36 +0000	[thread overview]
Message-ID: <494AA0E0.5090700@eu.citrix.com> (raw)

This patch changes the graphical_console_init function to return an
allocated DisplayState instead of a QEMUConsole.

This patch contains just the graphical_console_init change and few other
modifications mainly in console.c and vl.c.
It was necessary to move the display frontends (e.g. sdl and vnc)
initialization after machine->init in vl.c.

This patch does *not* include any required changes to any device, these
changes come with the following patches.


Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

---

diff -r 9fbe822b7bf3 console.c
--- a/console.c	Thu Dec 18 18:19:32 2008 +0000
+++ b/console.c	Thu Dec 18 18:31:42 2008 +0000
@@ -1190,6 +1190,17 @@
     }
 }
 
+static TextConsole *get_graphic_console() {
+    int i;
+    TextConsole *s;
+    for (i = 0; i < nb_consoles; i++) {
+        s = consoles[i];
+        if (s->console_type == GRAPHIC_CONSOLE)
+            return s;
+    }
+    return NULL;
+}
+
 static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
 {
     TextConsole *s;
@@ -1217,27 +1228,39 @@
             consoles[i] = consoles[i - 1];
         }
         consoles[i] = s;
+        nb_consoles++;
     }
     return s;
 }
 
-TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
-                                  vga_hw_invalidate_ptr invalidate,
-                                  vga_hw_screen_dump_ptr screen_dump,
-                                  vga_hw_text_update_ptr text_update,
-                                  void *opaque)
+DisplayState *graphic_console_init(vga_hw_update_ptr update,
+                                   vga_hw_invalidate_ptr invalidate,
+                                   vga_hw_screen_dump_ptr screen_dump,
+                                   vga_hw_text_update_ptr text_update,
+                                   void *opaque)
 {
     TextConsole *s;
+    DisplayState *ds;
+    
+    ds = (DisplayState *) qemu_mallocz(sizeof(DisplayState));
+    if (ds == NULL)
+        return NULL;
+    ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
 
     s = new_console(ds, GRAPHIC_CONSOLE);
-    if (!s)
-      return NULL;
+    if (s == NULL) {
+        qemu_free_displaysurface(ds->surface);
+        qemu_free(ds);
+        return NULL;
+    }
     s->hw_update = update;
     s->hw_invalidate = invalidate;
     s->hw_screen_dump = screen_dump;
     s->hw_text_update = text_update;
     s->hw = opaque;
-    return s;
+
+    register_displaystate(ds); 
+    return ds;
 }
 
 int is_graphic_console(void)
@@ -1285,6 +1308,7 @@
     s->out_fifo.buf = s->out_fifo_buf;
     s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
     s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
+    s->ds = ds;
 
     if (!color_inited) {
         color_inited = 1;
@@ -1337,22 +1361,22 @@
     return chr;
 }
 
-void qemu_console_resize(QEMUConsole *console, int width, int height)
+void qemu_console_resize(DisplayState *ds, int width, int height)
 {
-    console->g_width = width;
-    console->g_height = height;
-    if (active_console == console) {
-        DisplayState *ds = console->ds;
+    TextConsole *s = get_graphic_console();
+    s->g_width = width;
+    s->g_height = height;
+    if (is_graphic_console()) {
         ds->surface = qemu_resize_displaysurface(ds->surface, width, height, 32, 4 * width);
-        dpy_resize(console->ds);
+        dpy_resize(ds);
     }
 }
 
-void qemu_console_copy(QEMUConsole *console, int src_x, int src_y,
-                int dst_x, int dst_y, int w, int h)
+void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
+                       int dst_x, int dst_y, int w, int h)
 {
-    if (active_console == console) {
-            dpy_copy(console->ds, src_x, src_y, dst_x, dst_y, w, h);
+    if (is_graphic_console()) {
+        dpy_copy(ds, src_x, src_y, dst_x, dst_y, w, h);
     }
 }
 
diff -r 9fbe822b7bf3 console.h
--- a/console.h	Thu Dec 18 18:19:32 2008 +0000
+++ b/console.h	Thu Dec 18 18:31:42 2008 +0000
@@ -122,8 +122,12 @@
     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);
+
+    struct DisplayState *next;
 };
 
+void register_displaystate(DisplayState *ds);
+DisplayState *get_displaystate(void);
 DisplaySurface* qemu_create_displaysurface(int width, int height, int bpp, int linesize);
 DisplaySurface* qemu_resize_displaysurface(DisplaySurface *surface,
                                            int width, int height, int bpp, int linesize);
@@ -248,11 +252,12 @@
 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
-TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
-                                  vga_hw_invalidate_ptr invalidate,
-                                  vga_hw_screen_dump_ptr screen_dump,
-                                  vga_hw_text_update_ptr text_update,
-                                  void *opaque);
+DisplayState *graphic_console_init(vga_hw_update_ptr update,
+                                   vga_hw_invalidate_ptr invalidate,
+                                   vga_hw_screen_dump_ptr screen_dump,
+                                   vga_hw_text_update_ptr text_update,
+                                   void *opaque);
+
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
 void vga_hw_screen_dump(const char *filename);
@@ -263,9 +268,9 @@
 CharDriverState *text_console_init(DisplayState *ds, const char *p);
 void console_select(unsigned int index);
 void console_color_init(DisplayState *ds);
-void qemu_console_resize(QEMUConsole *console, int width, int height);
-void qemu_console_copy(QEMUConsole *console, int src_x, int src_y,
-                int dst_x, int dst_y, int w, int h);
+void qemu_console_resize(DisplayState *ds, int width, int height);
+void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
+                       int dst_x, int dst_y, int w, int h);
 
 /* sdl.c */
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
diff -r 9fbe822b7bf3 qemu-char.c
--- a/qemu-char.c	Thu Dec 18 18:19:32 2008 +0000
+++ b/qemu-char.c	Thu Dec 18 18:31:42 2008 +0000
@@ -2128,10 +2128,10 @@
     CharDriverState *chr;
 
     if (!strcmp(filename, "vc")) {
-        chr = text_console_init(&display_state, 0);
+        chr = text_console_init(get_displaystate(), 0);
     } else
     if (strstart(filename, "vc:", &p)) {
-        chr = text_console_init(&display_state, p);
+        chr = text_console_init(get_displaystate(), p);
     } else
     if (!strcmp(filename, "null")) {
         chr = qemu_chr_open_null();
diff -r 9fbe822b7bf3 sysemu.h
--- a/sysemu.h	Thu Dec 18 18:19:32 2008 +0000
+++ b/sysemu.h	Thu Dec 18 18:31:42 2008 +0000
@@ -98,7 +98,6 @@
 extern int semihosting_enabled;
 extern int old_param;
 extern const char *bootp_filename;
-extern DisplayState display_state;
 
 #ifdef USE_KQEMU
 extern int kqemu_allowed;
diff -r 9fbe822b7bf3 vl.c
--- a/vl.c	Thu Dec 18 18:19:32 2008 +0000
+++ b/vl.c	Thu Dec 18 18:31:42 2008 +0000
@@ -188,7 +188,7 @@
 int nb_drives;
 static int vga_ram_size;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
-DisplayState display_state;
+static DisplayState *display_state;
 int nographic;
 static int curses;
 static int sdl;
@@ -2756,6 +2756,23 @@
 }
 
 /***********************************************************/
+/* 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)
+{
+    return display_state;
+}
+
 /* dumb display */
 
 static void dumb_update(DisplayState *ds, int x, int y, int w, int h)
@@ -4484,7 +4501,7 @@
     const char *initrd_filename;
     const char *kernel_filename, *kernel_cmdline;
     const char *boot_devices = "";
-    DisplayState *ds = &display_state;
+    DisplayState *ds;
     DisplayChangeListener *dcl;
     int cyls, heads, secs, translation;
     const char *net_clients[MAX_NET_CLIENTS];
@@ -5376,9 +5393,63 @@
     register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
     register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);
 
+#ifndef _WIN32
+    /* must be after terminal init, SDL library changes signal handlers */
+    termsig_setup();
+#endif
+
+    /* Maintain compatibility with multiple stdio monitors */
+    if (!strcmp(monitor_device,"stdio")) {
+        for (i = 0; i < MAX_SERIAL_PORTS; i++) {
+            const char *devname = serial_devices[i];
+            if (devname && !strcmp(devname,"mon:stdio")) {
+                monitor_device = NULL;
+                break;
+            } else if (devname && !strcmp(devname,"stdio")) {
+                monitor_device = NULL;
+                serial_devices[i] = "mon:stdio";
+                break;
+            }
+        }
+    }
+
+    if (kvm_enabled()) {
+        int ret;
+
+        ret = kvm_init(smp_cpus);
+        if (ret < 0) {
+            fprintf(stderr, "failed to initialize KVM\n");
+            exit(1);
+        }
+    }
+
+    machine->init(ram_size, vga_ram_size, boot_devices, ds,
+                  kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+
+    /* Set KVM's vcpu state to qemu's initial CPUState. */
+    if (kvm_enabled()) {
+        int ret;
+
+        ret = kvm_sync_vcpus();
+        if (ret < 0) {
+            fprintf(stderr, "failed to initialize vcpus\n");
+            exit(1);
+        }
+    }
+
+    /* init USB devices */
+    if (usb_enabled) {
+        for(i = 0; i < usb_devices_index; i++) {
+            if (usb_device_add(usb_devices[i]) < 0) {
+                fprintf(stderr, "Warning: could not add USB device %s\n",
+                        usb_devices[i]);
+            }
+        }
+    }
+
+    /* just use the first displaystate for the moment */
+    ds = display_state;
     /* terminal init */
-    memset(&display_state, 0, sizeof(display_state));
-    ds->surface = qemu_create_displaysurface(640, 480, 32, 640 * 4);
     if (nographic) {
         if (curses) {
             fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
@@ -5410,25 +5481,16 @@
             }
     }
     dpy_resize(ds);
-#ifndef _WIN32
-    /* must be after terminal init, SDL library changes signal handlers */
-    termsig_setup();
-#endif
-
-    /* Maintain compatibility with multiple stdio monitors */
-    if (!strcmp(monitor_device,"stdio")) {
-        for (i = 0; i < MAX_SERIAL_PORTS; i++) {
-            const char *devname = serial_devices[i];
-            if (devname && !strcmp(devname,"mon:stdio")) {
-                monitor_device = NULL;
-                break;
-            } else if (devname && !strcmp(devname,"stdio")) {
-                monitor_device = NULL;
-                serial_devices[i] = "mon:stdio";
-                break;
-            }
-        }
-    }
+
+    dcl = ds->listeners;
+    while (dcl != NULL) {
+        if (dcl->dpy_refresh != NULL) {
+            ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
+            qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
+        }
+        dcl = dcl->next;
+    }
+
     if (monitor_device) {
         monitor_hd = qemu_chr_open("monitor", monitor_device);
         if (!monitor_hd) {
@@ -5470,48 +5532,6 @@
         }
     }
 
-    if (kvm_enabled()) {
-        int ret;
-
-        ret = kvm_init(smp_cpus);
-        if (ret < 0) {
-            fprintf(stderr, "failed to initialize KVM\n");
-            exit(1);
-        }
-    }
-
-    machine->init(ram_size, vga_ram_size, boot_devices, ds,
-                  kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
-
-    /* Set KVM's vcpu state to qemu's initial CPUState. */
-    if (kvm_enabled()) {
-        int ret;
-
-        ret = kvm_sync_vcpus();
-        if (ret < 0) {
-            fprintf(stderr, "failed to initialize vcpus\n");
-            exit(1);
-        }
-    }
-
-    /* init USB devices */
-    if (usb_enabled) {
-        for(i = 0; i < usb_devices_index; i++) {
-            if (usb_device_add(usb_devices[i]) < 0) {
-                fprintf(stderr, "Warning: could not add USB device %s\n",
-                        usb_devices[i]);
-            }
-        }
-    }
-
-    dcl = ds->listeners;
-    while (dcl != NULL) {
-        if (dcl->dpy_refresh != NULL) {
-            display_state.gui_timer = qemu_new_timer(rt_clock, gui_update, &display_state);
-            qemu_mod_timer(display_state.gui_timer, qemu_get_clock(rt_clock));
-        }
-        dcl = dcl->next;
-    }
 #ifdef CONFIG_GDBSTUB
     if (use_gdbstub) {
         /* XXX: use standard host:port notation and modify options

             reply	other threads:[~2008-12-18 19:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-18 19:13 Stefano Stabellini [this message]
2009-01-15 22:19 ` [Qemu-devel] [PATCH 5 of 7] graphical_console_init change Anthony Liguori
2009-01-16 11:15   ` Stefano Stabellini
2009-01-16 11:30     ` Stefano Stabellini
  -- strict thread matches above, loose matches on Subject: below --
2008-11-26 17:47 Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=494AA0E0.5090700@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.