console: add unregister_displaychangelistener

Also change the way the gui_timer is initialized: each time a
displaychangelistener is registered or unregistered we'll check
whether we need a timer (due to dpy_refresh callback being present)
and if so setup a timer, otherwise zap it.  This way the gui timer
works correctly with displaychangelisteners coming and going.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2010-06-04 11:51:31 +02:00
parent 87e487a14b
commit 35c9e0a5c2
2 changed files with 33 additions and 8 deletions

View File

@ -229,9 +229,19 @@ static inline int is_buffer_shared(DisplaySurface *surface)
!(surface->flags & QEMU_REALPIXELS_FLAG)); !(surface->flags & QEMU_REALPIXELS_FLAG));
} }
void gui_setup_refresh(DisplayState *ds);
static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl) static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
{ {
QLIST_INSERT_HEAD(&ds->listeners, dcl, next); QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
gui_setup_refresh(ds);
}
static inline void unregister_displaychangelistener(DisplayState *ds,
DisplayChangeListener *dcl)
{
QLIST_REMOVE(dcl, next);
gui_setup_refresh(ds);
} }
static inline void dpy_update(DisplayState *s, int x, int y, int w, int h) static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)

31
vl.c
View File

@ -1371,6 +1371,29 @@ static void gui_update(void *opaque)
qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock)); qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
} }
void gui_setup_refresh(DisplayState *ds)
{
DisplayChangeListener *dcl;
bool need_timer = false;
QLIST_FOREACH(dcl, &ds->listeners, next) {
if (dcl->dpy_refresh != NULL) {
need_timer = true;
break;
}
}
if (need_timer && ds->gui_timer == NULL) {
ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
}
if (!need_timer && ds->gui_timer != NULL) {
qemu_del_timer(ds->gui_timer);
qemu_free_timer(ds->gui_timer);
ds->gui_timer = NULL;
}
}
struct vm_change_state_entry { struct vm_change_state_entry {
VMChangeStateHandler *cb; VMChangeStateHandler *cb;
void *opaque; void *opaque;
@ -2454,7 +2477,6 @@ int main(int argc, char **argv, char **envp)
const char *kernel_filename, *kernel_cmdline; const char *kernel_filename, *kernel_cmdline;
char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
DisplayState *ds; DisplayState *ds;
DisplayChangeListener *dcl;
int cyls, heads, secs, translation; int cyls, heads, secs, translation;
QemuOpts *hda_opts = NULL, *opts, *machine_opts; QemuOpts *hda_opts = NULL, *opts, *machine_opts;
QemuOptsList *olist; QemuOptsList *olist;
@ -3845,13 +3867,6 @@ int main(int argc, char **argv, char **envp)
/* display setup */ /* display setup */
dpy_resize(ds); dpy_resize(ds);
QLIST_FOREACH(dcl, &ds->listeners, next) {
if (dcl->dpy_refresh != NULL) {
ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
break;
}
}
text_consoles_set_display(ds); text_consoles_set_display(ds);
if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {