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 ++++++++++++++++++++++++++++++++++ ui/gtk.c | 17 +++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/console.c b/ui/console.c index e22931a396..a11b120fc8 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; diff --git a/ui/gtk.c b/ui/gtk.c index ab646b70e1..c63408e036 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -2297,7 +2297,7 @@ static void gd_create_menus(GtkDisplayState *s) static gboolean gtkinit; -void gtk_display_init(DisplayState *ds, DisplayOptions *opts) +static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) { VirtualConsole *vc; @@ -2407,7 +2407,7 @@ void gtk_display_init(DisplayState *ds, DisplayOptions *opts) } } -void early_gtk_display_init(DisplayOptions *opts) +static void early_gtk_display_init(DisplayOptions *opts) { /* The QEMU code relies on the assumption that it's always run in * the C locale. Therefore it is not prepared to deal with @@ -2450,3 +2450,16 @@ void early_gtk_display_init(DisplayOptions *opts) type_register(&char_gd_vc_type_info); #endif } + +static QemuDisplay qemu_display_gtk = { + .type = DISPLAY_TYPE_GTK, + .early_init = early_gtk_display_init, + .init = gtk_display_init, +}; + +static void register_gtk(void) +{ + qemu_display_register(&qemu_display_gtk); +} + +type_init(register_gtk); -- cgit v1.2.3 From 5ee1718f92bd82e0e581191b6326384d291199d3 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:36 +0100 Subject: sdl: switch over to new display registry Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-3-kraxel@redhat.com --- ui/sdl.c | 24 +++++++++++++----------- ui/sdl2.c | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'ui') diff --git a/ui/sdl.c b/ui/sdl.c index c4ae7ab05d..a5fd503c25 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -901,17 +901,7 @@ static const DisplayChangeListenerOps dcl_ops = { .dpy_cursor_define = sdl_mouse_define, }; -void sdl_display_early_init(DisplayOptions *opts) -{ - if (opts->has_gl && opts->gl) { - fprintf(stderr, - "SDL1 display code has no opengl support.\n" - "Please recompile qemu with SDL2, using\n" - "./configure --enable-sdl --with-sdlabi=2.0\n"); - } -} - -void sdl_display_init(DisplayState *ds, DisplayOptions *o) +static void sdl1_display_init(DisplayState *ds, DisplayOptions *o) { int flags; uint8_t data = 0; @@ -1023,3 +1013,15 @@ void sdl_display_init(DisplayState *ds, DisplayOptions *o) atexit(sdl_cleanup); } + +static QemuDisplay qemu_display_sdl1 = { + .type = DISPLAY_TYPE_SDL, + .init = sdl1_display_init, +}; + +static void register_sdl1(void) +{ + qemu_display_register(&qemu_display_sdl1); +} + +type_init(register_sdl1); diff --git a/ui/sdl2.c b/ui/sdl2.c index b5a0fa1d13..83b917fa37 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -751,7 +751,7 @@ static const DisplayChangeListenerOps dcl_gl_ops = { }; #endif -void sdl_display_early_init(DisplayOptions *o) +static void sdl2_display_early_init(DisplayOptions *o) { assert(o->type == DISPLAY_TYPE_SDL); if (o->has_gl && o->gl) { @@ -761,7 +761,7 @@ void sdl_display_early_init(DisplayOptions *o) } } -void sdl_display_init(DisplayState *ds, DisplayOptions *o) +static void sdl2_display_init(DisplayState *ds, DisplayOptions *o) { int flags; uint8_t data = 0; @@ -861,3 +861,16 @@ void sdl_display_init(DisplayState *ds, DisplayOptions *o) atexit(sdl_cleanup); } + +static QemuDisplay qemu_display_sdl2 = { + .type = DISPLAY_TYPE_SDL, + .early_init = sdl2_display_early_init, + .init = sdl2_display_init, +}; + +static void register_sdl1(void) +{ + qemu_display_register(&qemu_display_sdl2); +} + +type_init(register_sdl1); -- cgit v1.2.3 From 5013b9e46a72c96999fab1523f722ab58152c59a Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:37 +0100 Subject: cocoa: switch over to new display registry Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-4-kraxel@redhat.com --- ui/cocoa.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/cocoa.m b/ui/cocoa.m index 90d9aa57ea..8b0dce90cb 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1683,7 +1683,7 @@ static void addRemovableDevicesMenuItems(void) qapi_free_BlockInfoList(pointerToFree); } -void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) +static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); @@ -1713,3 +1713,15 @@ void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) */ addRemovableDevicesMenuItems(); } + +static QemuDisplay qemu_display_cocoa = { + .type = DISPLAY_TYPE_COCOA, + .init = cocoa_display_init, +}; + +static void register_cocoa(void) +{ + qemu_display_register(&qemu_display_cocoa); +} + +type_init(register_cocoa); -- cgit v1.2.3 From b0766612d16da185a822636cf54214123e8038cf Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:38 +0100 Subject: curses: switch over to new display registry Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-5-kraxel@redhat.com --- ui/curses.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/curses.c b/ui/curses.c index 597e47fd4a..59d819fd4d 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -435,7 +435,7 @@ static const DisplayChangeListenerOps dcl_ops = { .dpy_text_cursor = curses_cursor_position, }; -void curses_display_init(DisplayState *ds, DisplayOptions *opts) +static void curses_display_init(DisplayState *ds, DisplayOptions *opts) { #ifndef _WIN32 if (!isatty(1)) { @@ -456,3 +456,15 @@ void curses_display_init(DisplayState *ds, DisplayOptions *opts) invalidate = 1; } + +static QemuDisplay qemu_display_curses = { + .type = DISPLAY_TYPE_CURSES, + .init = curses_display_init, +}; + +static void register_curses(void) +{ + qemu_display_register(&qemu_display_curses); +} + +type_init(register_curses); -- cgit v1.2.3 From 16ab0a74e44300add9a7966e6f4f95ed4c0e833e Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:39 +0100 Subject: egl-headless: switch over to new display registry Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-6-kraxel@redhat.com --- ui/egl-headless.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/egl-headless.c b/ui/egl-headless.c index b33e0b21fd..7c877122d3 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -164,7 +164,12 @@ static const DisplayChangeListenerOps egl_ops = { .dpy_gl_update = egl_scanout_flush, }; -void egl_headless_init(DisplayOptions *opts) +static void early_egl_headless_init(DisplayOptions *opts) +{ + display_opengl = 1; +} + +static void egl_headless_init(DisplayState *ds, DisplayOptions *opts) { QemuConsole *con; egl_dpy *edpy; @@ -188,3 +193,16 @@ void egl_headless_init(DisplayOptions *opts) register_displaychangelistener(&edpy->dcl); } } + +static QemuDisplay qemu_display_egl = { + .type = DISPLAY_TYPE_EGL_HEADLESS, + .early_init = early_egl_headless_init, + .init = egl_headless_init, +}; + +static void register_egl(void) +{ + qemu_display_register(&qemu_display_egl); +} + +type_init(register_egl); -- cgit v1.2.3 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') diff --git a/ui/console.c b/ui/console.c index a11b120fc8..25d342cdcb 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.2.3 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') diff --git a/ui/console.c b/ui/console.c index 25d342cdcb..78efab269a 100644 --- a/ui/console.c +++ b/ui/console.c @@ -2198,6 +2198,9 @@ bool qemu_display_find_default(DisplayOptions *opts) int i; 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; } @@ -2213,6 +2216,9 @@ void qemu_display_early_init(DisplayOptions *opts) if (opts->type == DISPLAY_TYPE_NONE) { 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]); -- cgit v1.2.3 From 8781595bf2931bf00cfd431bac9a100b312e87a9 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:42 +0100 Subject: configure: add X11 vars to config-host.mak Simplifies handling the X11 dependency, also makes ui/Makefile.objs more readable. Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-9-kraxel@redhat.com --- ui/Makefile.objs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/Makefile.objs b/ui/Makefile.objs index ced7d91a63..9b725b07aa 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -17,7 +17,10 @@ common-obj-$(CONFIG_CURSES) += curses.o common-obj-$(CONFIG_VNC) += $(vnc-obj-y) common-obj-$(call lnot,$(CONFIG_VNC)) += vnc-stubs.o common-obj-$(CONFIG_GTK) += gtk.o -common-obj-$(if $(CONFIG_WIN32),n,$(if $(CONFIG_SDL),y,$(CONFIG_GTK))) += x_keymap.o + +common-obj-$(CONFIG_X11) += x_keymap.o +x_keymap.o-cflags := $(X11_CFLAGS) +x_keymap.o-libs := $(X11_LIBS) ifeq ($(CONFIG_SDLABI),1.2) sdl.mo-objs := sdl.o sdl_zoom.o -- cgit v1.2.3 From e0fb129c2f2baac0ef44408751bada8739f99522 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:44 +0100 Subject: ui/gtk: build as module Also drop gtk and vte libs from libs_softmmu, so the libs are not pulled in unless the gtk module actually gets loaded. Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-11-kraxel@redhat.com --- ui/Makefile.objs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/Makefile.objs b/ui/Makefile.objs index 9b725b07aa..49223b0573 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -16,7 +16,6 @@ common-obj-$(CONFIG_COCOA) += cocoa.o common-obj-$(CONFIG_CURSES) += curses.o common-obj-$(CONFIG_VNC) += $(vnc-obj-y) common-obj-$(call lnot,$(CONFIG_VNC)) += vnc-stubs.o -common-obj-$(CONFIG_GTK) += gtk.o common-obj-$(CONFIG_X11) += x_keymap.o x_keymap.o-cflags := $(X11_CFLAGS) @@ -34,6 +33,12 @@ endif sdl.mo-cflags := $(SDL_CFLAGS) sdl.mo-libs := $(SDL_LIBS) +# ui-gtk module +common-obj-$(CONFIG_GTK) += gtk.mo +gtk.mo-objs := gtk.o +gtk.mo-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) +gtk.mo-libs := $(GTK_LIBS) $(VTE_LIBS) + ifeq ($(CONFIG_OPENGL),y) common-obj-y += shader.o common-obj-y += console-gl.o @@ -41,17 +46,13 @@ common-obj-y += egl-helpers.o common-obj-y += egl-context.o common-obj-$(CONFIG_OPENGL_DMABUF) += egl-headless.o ifeq ($(CONFIG_GTK_GL),y) -common-obj-$(CONFIG_GTK) += gtk-gl-area.o +gtk.mo-objs += gtk-gl-area.o else -common-obj-$(CONFIG_GTK) += gtk-egl.o +gtk.mo-objs += gtk-egl.o +gtk.mo-libs += $(OPENGL_LIBS) endif endif -gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) -gtk-egl.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) -gtk-gl-area.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) - -gtk-egl.o-libs += $(OPENGL_LIBS) shader.o-libs += $(OPENGL_LIBS) console-gl.o-libs += $(OPENGL_LIBS) egl-helpers.o-libs += $(OPENGL_LIBS) -- cgit v1.2.3 From 2373f7d581e82c11645a799a032b9e64fd61c1b8 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:45 +0100 Subject: ui/curses: build as module Also drop curses libs from libs_softmmu. Add CURSES_{CFLAGS,LIBS} variables so we can use them for linking the curses module. Also make target/unicore32/helper.o depend on curses which uses curses directly for some reason ... Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-12-kraxel@redhat.com --- ui/Makefile.objs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/Makefile.objs b/ui/Makefile.objs index 49223b0573..a37232762b 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -13,7 +13,6 @@ common-obj-$(CONFIG_LINUX) += input-linux.o common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o common-obj-$(CONFIG_SDL) += sdl.mo common-obj-$(CONFIG_COCOA) += cocoa.o -common-obj-$(CONFIG_CURSES) += curses.o common-obj-$(CONFIG_VNC) += $(vnc-obj-y) common-obj-$(call lnot,$(CONFIG_VNC)) += vnc-stubs.o @@ -39,6 +38,11 @@ gtk.mo-objs := gtk.o gtk.mo-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) gtk.mo-libs := $(GTK_LIBS) $(VTE_LIBS) +common-obj-$(CONFIG_CURSES) += curses.mo +curses.mo-objs := curses.o +curses.mo-cflags := $(CURSES_CFLAGS) +curses.mo-libs := $(CURSES_LIBS) + ifeq ($(CONFIG_OPENGL),y) common-obj-y += shader.o common-obj-y += console-gl.o -- cgit v1.2.3 From 96400a148b3e1337e2c451e95bc3c3c69a05b67c Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 1 Mar 2018 11:05:47 +0100 Subject: ui/sdl: build as module Signed-off-by: Gerd Hoffmann Message-id: 20180301100547.18962-14-kraxel@redhat.com --- ui/Makefile.objs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/Makefile.objs b/ui/Makefile.objs index a37232762b..dcd54a5287 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -11,7 +11,6 @@ common-obj-y += keymaps.o console.o cursor.o qemu-pixman.o common-obj-y += input.o input-keymap.o input-legacy.o common-obj-$(CONFIG_LINUX) += input-linux.o common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o -common-obj-$(CONFIG_SDL) += sdl.mo common-obj-$(CONFIG_COCOA) += cocoa.o common-obj-$(CONFIG_VNC) += $(vnc-obj-y) common-obj-$(call lnot,$(CONFIG_VNC)) += vnc-stubs.o @@ -20,6 +19,8 @@ common-obj-$(CONFIG_X11) += x_keymap.o x_keymap.o-cflags := $(X11_CFLAGS) x_keymap.o-libs := $(X11_LIBS) +# ui-sdl module +common-obj-$(CONFIG_SDL) += sdl.mo ifeq ($(CONFIG_SDLABI),1.2) sdl.mo-objs := sdl.o sdl_zoom.o endif -- cgit v1.2.3