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: Wed, 26 Nov 2008 17:47:52 +0000 [thread overview]
Message-ID: <492D8BC8.70209@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 1f7dd99b4f75 console.c
--- a/console.c Wed Nov 26 14:40:08 2008 +0000
+++ b/console.c Wed Nov 26 14:47:07 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,38 @@
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_createDisplaySurface(640, 480, 32, 640 * 4);
+
s = new_console(ds, GRAPHIC_CONSOLE);
- if (!s)
- return NULL;
+ if (s == NULL) {
+ qemu_freeDisplaySurface(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;
+
+ return ds;
}
int is_graphic_console(void)
@@ -1285,6 +1307,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 +1360,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_resizeDisplaySurface(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 1f7dd99b4f75 console.h
--- a/console.h Wed Nov 26 14:40:08 2008 +0000
+++ b/console.h Wed Nov 26 14:47:07 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_createDisplaySurface(int width, int height, int bpp, int linesize);
DisplaySurface* qemu_resizeDisplaySurface(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 1f7dd99b4f75 qemu-char.c
--- a/qemu-char.c Wed Nov 26 14:40:08 2008 +0000
+++ b/qemu-char.c Wed Nov 26 14:47:07 2008 +0000
@@ -2129,10 +2129,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 1f7dd99b4f75 sysemu.h
--- a/sysemu.h Wed Nov 26 14:40:08 2008 +0000
+++ b/sysemu.h Wed Nov 26 14:47:07 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 1f7dd99b4f75 vl.c
--- a/vl.c Wed Nov 26 14:40:08 2008 +0000
+++ b/vl.c Wed Nov 26 14:47:07 2008 +0000
@@ -186,7 +186,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;
@@ -2731,6 +2731,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)
@@ -4447,7 +4464,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];
@@ -5334,40 +5351,6 @@
register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);
- /* terminal init */
- memset(&display_state, 0, sizeof(display_state));
- ds->surface = qemu_createDisplaySurface(640, 480, 32, 640 * 4);
- if (nographic) {
- if (curses) {
- fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
- exit(1);
- }
- /* nearly nothing to do */
- dumb_display_init(ds);
- } else {
-#if defined(CONFIG_CURSES)
- if (curses) {
- /* At the moment curses cannot be used with other displays */
- curses_display_init(ds, full_screen);
- } else
-#endif
- {
- if (vnc_display != NULL) {
- vnc_display_init(ds);
- if (vnc_display_open(ds, vnc_display) < 0)
- exit(1);
- }
- if (sdl || !vnc_display)
-#if defined(CONFIG_SDL)
- sdl_display_init(ds, full_screen, no_frame);
-#elif defined(CONFIG_COCOA)
- cocoa_display_init(ds, full_screen);
-#else
- dumb_display_init(ds);
-#endif
- }
- }
- dpy_resize(ds);
#ifndef _WIN32
/* must be after terminal init, SDL library changes signal handlers */
termsig_setup();
@@ -5387,6 +5370,30 @@
}
}
}
+
+ 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,
+ kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+
+ /* 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]);
+ }
+ }
+ }
+
if (monitor_device) {
monitor_hd = qemu_chr_open("monitor", monitor_device);
if (!monitor_hd) {
@@ -5428,34 +5435,46 @@
}
}
- 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);
-
- /* 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 */
+ if (nographic) {
+ if (curses) {
+ fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
+ exit(1);
+ }
+ /* nearly nothing to do */
+ dumb_display_init(ds);
+ } else {
+#if defined(CONFIG_CURSES)
+ if (curses) {
+ /* At the moment curses cannot be used with other displays */
+ curses_display_init(ds, full_screen);
+ } else
+#endif
+ {
+ if (vnc_display != NULL) {
+ vnc_display_init(ds);
+ if (vnc_display_open(ds, vnc_display) < 0)
+ exit(1);
+ }
+ if (sdl || !vnc_display)
+#if defined(CONFIG_SDL)
+ sdl_display_init(ds, full_screen, no_frame);
+#elif defined(CONFIG_COCOA)
+ cocoa_display_init(ds, full_screen);
+#else
+ dumb_display_init(ds);
+#endif
+ }
+ }
+ dpy_resize(ds);
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));
+ 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;
}
next reply other threads:[~2008-11-26 17:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-26 17:47 Stefano Stabellini [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-12-18 19:13 [Qemu-devel] [PATCH 5 of 7] graphical_console_init change Stefano Stabellini
2009-01-15 22:19 ` Anthony Liguori
2009-01-16 11:15 ` Stefano Stabellini
2009-01-16 11:30 ` 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=492D8BC8.70209@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 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).