From db71589fd9428156a5b366e348d895d445f77449 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:35 +0100 Subject: console: add qemu display registry, add gtk Add a registry for user interfaces. Add qemu_display_init and qemu_display_early_init helper functions for display initialization. Hook up gtk ui as first user. Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-2-kraxel@redhat.com --- ui/console.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'ui/console.c') diff --git a/ui/console.c b/ui/console.c index e22931a..a11b120 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2180,6 +2180,40 @@ PixelFormat qemu_default_pixelformat(int bpp) return pf; } +static QemuDisplay *dpys[DISPLAY_TYPE__MAX]; + +void qemu_display_register(QemuDisplay *ui) +{ + assert(ui->type < DISPLAY_TYPE__MAX); + dpys[ui->type] = ui; +} + +void qemu_display_early_init(DisplayOptions *opts) +{ + assert(opts->type < DISPLAY_TYPE__MAX); + if (opts->type == DISPLAY_TYPE_NONE) { + return; + } + if (dpys[opts->type] == NULL) { + error_report("Display '%s' is not available.", + DisplayType_lookup.array[opts->type]); + exit(1); + } + if (dpys[opts->type]->early_init) { + dpys[opts->type]->early_init(opts); + } +} + +void qemu_display_init(DisplayState *ds, DisplayOptions *opts) +{ + assert(opts->type < DISPLAY_TYPE__MAX); + if (opts->type == DISPLAY_TYPE_NONE) { + return; + } + assert(dpys[opts->type] != NULL); + dpys[opts->type]->init(ds, opts); +} + void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp) { int val; -- cgit v1.1 From 898f9d41d02d577ac863069772f0708268d2f926 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:40 +0100 Subject: console: add and use qemu_display_find_default Using the new display registry instead of #ifdefs in vl.c. Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-7-kraxel@redhat.com --- ui/console.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ui/console.c') diff --git a/ui/console.c b/ui/console.c index a11b120..25d342c 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2188,6 +2188,25 @@ void qemu_display_register(QemuDisplay *ui) dpys[ui->type] = ui; } +bool qemu_display_find_default(DisplayOptions *opts) +{ + static DisplayType prio[] = { + DISPLAY_TYPE_GTK, + DISPLAY_TYPE_SDL, + DISPLAY_TYPE_COCOA + }; + int i; + + for (i = 0; i < ARRAY_SIZE(prio); i++) { + if (dpys[prio[i]] == NULL) { + continue; + } + opts->type = prio[i]; + return true; + } + return false; +} + void qemu_display_early_init(DisplayOptions *opts) { assert(opts->type < DISPLAY_TYPE__MAX); -- cgit v1.1 From 61b4d9a24668d3b14f80d25ab66f6081f1ab7b17 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:41 +0100 Subject: console: add ui module loading support If a requested user interface is not available, try loading it as module, simliar to block layer modules. Needed to keep things working when followup patches start to build user interfaces as modules. Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-8-kraxel@redhat.com --- ui/console.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ui/console.c') diff --git a/ui/console.c b/ui/console.c index 25d342c..78efab2 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2199,6 +2199,9 @@ bool qemu_display_find_default(DisplayOptions *opts) for (i = 0; i < ARRAY_SIZE(prio); i++) { if (dpys[prio[i]] == NULL) { + ui_module_load_one(DisplayType_lookup.array[prio[i]]); + } + if (dpys[prio[i]] == NULL) { continue; } opts->type = prio[i]; @@ -2214,6 +2217,9 @@ void qemu_display_early_init(DisplayOptions *opts) return; } if (dpys[opts->type] == NULL) { + ui_module_load_one(DisplayType_lookup.array[opts->type]); + } + if (dpys[opts->type] == NULL) { error_report("Display '%s' is not available.", DisplayType_lookup.array[opts->type]); exit(1); -- cgit v1.1