Skip to contentSkip to conversation

virtio-gpu and sdl2 so far

RFC In review Dave Airlie 3 participants 22 messages Nov 20, 2013 – Jan 13, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

Hey,

I thought I should post this for a bit more feedback and show where I've gone so far,

all available in git
http://cgit.freedesktop.org/~airlied/qemu/log/?h=virtio-gpu

The first patch is the sdl2 port with some minor changes I posted before, then there are a bunch of console changes that I think will make life easier for multi-head.

The sdl2 multi-head patch is why I'd like to keep SDL1.2 separate from SDL2, there is a lot of changes in this, and it would be messy to update SDL1 code at the same time and not cause breakages.

Then there is the virtio-gpu, virtio-vga initial patches, there is still some future proofing work to be done, and I'd like to try and sort out the 3d integration and threading before doing much more with them.

The last patch you can ignore, I just included it because it was in my tree, and its just a hack to keep libvirt happy on my system.

Dave.

#1 lore raw

PATCH 1/8 ui/sdl2 : initial port to SDL 2.0 (v1.2)

From: Dave Airlie <[email protected]>

I've ported the SDL1.2 code over, and rewritten it to use the SDL2 interface.

The biggest changes were in the input handling, where SDL2 has done a major overhaul, and I've had to include a generated translation file to get from SDL2 codes back to qemu compatible ones. I'm still not sure how the keyboard layout code works in qemu, so there may be further work if someone can point me a test case that works with SDL1.2 and doesn't with SDL2.

Some SDL env vars we used to set are no longer used by SDL2, Windows, OSX support is untested,

I don't think we can link to SDL1.2 and SDL2 at the same time, so I felt using --with-sdlabi=2.0 to select the new code should be fine, like how gtk does it.

v1.1: fix keys in text console
v1.2: fix shutdown, cleanups a bit of code, support ARGB cursor

---
 configure                    |  23 +-
 ui/Makefile.objs             |   4 +-
 ui/sdl.c                     |   3 +
 ui/sdl2.c                    | 894 +++++++++++++++++++++++++++++++++++++++++++
 ui/sdl2_scancode_translate.h | 260 +++++++++++++
 ui/sdl_keysym.h              |   3 +-
 6 files changed, 1180 insertions(+), 7 deletions(-)
 create mode 100644 ui/sdl2.c
 create mode 100644 ui/sdl2_scancode_translate.h
configure +19 -4
index 9addff1..bf3be37 100755
@@ -158,6 +158,7 @@ docs=""
 fdt=""
 pixman=""
 sdl=""
+sdlabi="1.2"
 virtfs=""
 vnc="yes"
 sparse="no"
@@ -310,6 +311,7 @@ query_pkg_config() {
 }
 pkg_config=query_pkg_config
 sdl_config="${SDL_CONFIG-${cross_prefix}sdl-config}"
+sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
 
 # default flags for all hosts
 QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS"
@@ -710,6 +712,8 @@ for opt do
   ;;
   --enable-sdl) sdl="yes"
   ;;
+  --with-sdlabi=*) sdlabi="$optarg"
+  ;;
   --disable-qom-cast-debug) qom_cast_debug="no"
   ;;
   --enable-qom-cast-debug) qom_cast_debug="yes"
@@ -1092,6 +1096,7 @@ echo "  --disable-strip          disable stripping binaries"
 echo "  --disable-werror         disable compilation abort on warning"
 echo "  --disable-sdl            disable SDL"
 echo "  --enable-sdl             enable SDL"
+echo "  --with-sdlabi            select preferred SDL ABI 1.2 or 2.0"
 echo "  --disable-gtk            disable gtk UI"
 echo "  --enable-gtk             enable gtk UI"
 echo "  --disable-virtfs         disable VirtFS"
@@ -1751,12 +1756,22 @@ fi
 
 # Look for sdl configuration program (pkg-config or sdl-config).  Try
 # sdl-config even without cross prefix, and favour pkg-config over sdl-config.
-if test "`basename $sdl_config`" != sdl-config && ! has ${sdl_config}; then
-  sdl_config=sdl-config
+
+if test $sdlabi == "2.0"; then
+    sdl_config=$sdl2_config
+    sdlname=sdl2
+    sdlconfigname=sdl2_config
+else
+    sdlname=sdl
+    sdlconfigname=sdl_config
+fi
+
+if test "`basename $sdl_config`" != $sdlconfigname && ! has ${sdl_config}; then
+  sdl_config=$sdlconfigname
 fi
 
-if $pkg_config sdl --exists; then
-  sdlconfig="$pkg_config sdl"
+if $pkg_config $sdlname --exists; then
+  sdlconfig="$pkg_config $sdlname"
   _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
 elif has ${sdl_config}; then
   sdlconfig="$sdl_config"
ui/Makefile.objs +2 -2
index f33be47..721ad37 100644
@@ -9,12 +9,12 @@ vnc-obj-y += vnc-jobs.o
 
 common-obj-y += keymaps.o console.o cursor.o input.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
-common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
+common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
 common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o
 
-$(obj)/sdl.o $(obj)/sdl_zoom.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
+$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
 $(obj)/gtk.o: QEMU_CFLAGS += $(GTK_CFLAGS) $(VTE_CFLAGS)
ui/sdl.c +3 -0
index 9d8583c..736bb95 100644
@@ -26,6 +26,8 @@
 #undef WIN32_LEAN_AND_MEAN
 
 #include <SDL.h>
+
+#if SDL_MAJOR_VERSION == 1
 #include <SDL_syswm.h>
 
 #include "qemu-common.h"
@@ -966,3 +968,4 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 
     atexit(sdl_cleanup);
 }
+#endif
ui/sdl2.c new file +894 -0

894 lines not on this page · raw message

ui/sdl2_scancode_translate.h new file +260 -0

260 lines not on this page · raw message

ui/sdl_keysym.h +2 -1
index ee90480..599d9fc 100644
@@ -200,6 +200,7 @@ static const name2keysym_t name2keysym[]={
 { "yacute",               0x0fd},
 { "thorn",                0x0fe},
 { "ydiaeresis",           0x0ff},
+#if SDL_MAJOR_VERSION == 1
 {"EuroSign", SDLK_EURO},
 
     /* modifiers */
@@ -272,6 +273,6 @@ static const name2keysym_t name2keysym[]={
 {"Num_Lock", SDLK_NUMLOCK},
 {"Pause", SDLK_PAUSE},
 {"Escape", SDLK_ESCAPE},
-
+#endif
 {NULL, 0},
 };
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 2/8 console: add state notifiers for ui<->display

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

These are to be used for the UI to signal the video display, and vice-versa about changes in the state of a console, like size and offsets in relation to other consoles for input handling.

---
 include/ui/console.h |  8 +++++++-
 ui/console.c         | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
include/ui/console.h +7 -1
index 98edf41..5731081 100644
@@ -174,6 +174,9 @@ typedef struct DisplayChangeListenerOps {
                           int x, int y, int on);
     void (*dpy_cursor_define)(DisplayChangeListener *dcl,
                               QEMUCursor *cursor);
+
+    void (*dpy_notify_state)(DisplayChangeListener *dcl,
+			     int x, int y, uint32_t width, uint32_t height);
 } DisplayChangeListenerOps;
 
 struct DisplayChangeListener {
@@ -224,7 +227,8 @@ void dpy_text_resize(QemuConsole *con, int w, int h);
 void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
 void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
 bool dpy_cursor_define_supported(QemuConsole *con);
-
+void dpy_notify_state(QemuConsole *con, int x, int y,
+                      uint32_t width, uint32_t height);
 static inline int surface_stride(DisplaySurface *s)
 {
     return pixman_image_get_stride(s->image);
@@ -275,6 +279,7 @@ typedef struct GraphicHwOps {
     void (*gfx_update)(void *opaque);
     void (*text_update)(void *opaque, console_ch_t *text);
     void (*update_interval)(void *opaque, uint64_t interval);
+    void (*notify_state)(void *opaque, int idx, int x, int y, uint32_t width, uint32_t height);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev,
@@ -284,6 +289,7 @@ QemuConsole *graphic_console_init(DeviceState *dev,
 void graphic_hw_update(QemuConsole *con);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
+void graphic_hw_notify_state(QemuConsole *con, int x, int y, uint32_t width, uint32_t height);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
ui/console.c +26 -0
index aad4fc9..c20e336 100644
@@ -265,6 +265,16 @@ void graphic_hw_invalidate(QemuConsole *con)
     }
 }
 
+void graphic_hw_notify_state(QemuConsole *con, int x, int y, uint32_t width, uint32_t height)
+{
+    if (!con) {
+        con = active_console;
+    }
+    if (con && con->hw_ops->notify_state) {
+        con->hw_ops->notify_state(con->hw, con->index, x, y, width, height);
+    }
+}
+
 static void ppm_save(const char *filename, struct DisplaySurface *ds,
                      Error **errp)
 {
@@ -1562,6 +1572,22 @@ bool dpy_cursor_define_supported(QemuConsole *con)
     return false;
 }
 
+void dpy_notify_state(QemuConsole *con, int x, int y,
+                      uint32_t width, uint32_t height)
+{
+    DisplayState *s = con->ds;
+    DisplayChangeListener *dcl;
+
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (con != (dcl->con ? dcl->con : active_console)) {
+            continue;
+        }
+        if (dcl->ops->dpy_notify_state) {
+            dcl->ops->dpy_notify_state(dcl, x, y, width, height);
+        }
+    }
+}
+
 /***********************************************************/
 /* register display */
 
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 3/8 console: add information retrival wrappers

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

We need to know how many graphics consoles are registered in the UI code so it knows how many windows it should prepare for etc, also so that it could potentially warn for cases it can't handle.

We also need to know the console index so we can add it to the list. (maybe we don't).

---
 include/ui/console.h |  3 +++
 ui/console.c         | 12 ++++++++++++
 2 files changed, 15 insertions(+)
include/ui/console.h +3 -0
index 5731081..be304fe 100644
@@ -306,6 +306,9 @@ void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
 DisplaySurface *qemu_console_surface(QemuConsole *con);
 DisplayState *qemu_console_displaystate(QemuConsole *console);
 
+int qemu_get_console_index(QemuConsole *con);
+int qemu_get_number_graphical_consoles(void);
+
 typedef CharDriverState *(VcHandler)(ChardevVC *vc);
 
 CharDriverState *vc_init(ChardevVC *vc);
ui/console.c +12 -0
index c20e336..4248a6f 100644
@@ -175,6 +175,7 @@ static DisplayState *display_state;
 static QemuConsole *active_console;
 static QemuConsole *consoles[MAX_CONSOLES];
 static int nb_consoles = 0;
+static int nb_graphics_consoles = 0;
 
 static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
 static void dpy_refresh(DisplayState *s);
@@ -1247,6 +1248,7 @@ static QemuConsole *new_console(DisplayState *ds, console_type_t console_type)
         s->index = i;
         consoles[i] = s;
         nb_consoles++;
+        nb_graphics_consoles++;
     }
     return s;
 }
@@ -1873,6 +1875,16 @@ DisplayState *qemu_console_displaystate(QemuConsole *console)
     return console->ds;
 }
 
+int qemu_get_console_index(QemuConsole *console)
+{
+    return console->index;
+}
+
+int qemu_get_number_graphical_consoles(void)
+{
+    return nb_graphics_consoles;
+}
+
 PixelFormat qemu_different_endianness_pixelformat(int bpp)
 {
     PixelFormat pf;
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 4/8 console: add ability to wrap a console.

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

In order to implement virtio-vga on top of virtio-gpu we need to be able to wrap the first console virtio-gpu registers from inside virtio-vga which initialises after virtio-gpu. With this interface virtio-vga can store the virtio-gpu interfaces, and call them from its own ones.

---
 include/ui/console.h |  7 +++++++
 ui/console.c         | 13 +++++++++++++
 2 files changed, 20 insertions(+)
include/ui/console.h +7 -0
index be304fe..a143a0d 100644
@@ -286,6 +286,13 @@ QemuConsole *graphic_console_init(DeviceState *dev,
                                   const GraphicHwOps *ops,
                                   void *opaque);
 
+void graphic_console_wrap(QemuConsole *con,
+			  DeviceState *dev,
+			  const GraphicHwOps *ops,
+			  void *opaque,
+                          const GraphicHwOps **orig_ops,
+                          void **orig_opaque);
+
 void graphic_hw_update(QemuConsole *con);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
ui/console.c +13 -0
index 4248a6f..80e17e5 100644
@@ -1658,6 +1658,19 @@ QemuConsole *graphic_console_init(DeviceState *dev,
     return s;
 }
 
+void graphic_console_wrap(QemuConsole *con,
+			  DeviceState *dev,
+			  const GraphicHwOps *hw_ops,
+			  void *opaque,
+                          const GraphicHwOps **orig_ops,
+                          void **orig_opaque)
+{
+    *orig_opaque = con->hw;
+    *orig_ops = con->hw_ops;
+    con->hw_ops = hw_ops;
+    con->hw = opaque;
+}
+
 QemuConsole *qemu_console_lookup_by_index(unsigned int index)
 {
     if (index >= MAX_CONSOLES) {
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 5/8 sdl2: update for multihead support.

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

This reworks the complete SDL2 code to support multi-head, by using DisplayChangeListeners wrapped inside a structure per-head, containing the SDL2 information along with the console info.

This also adds a hack to allow Ctrl-Alt-n to toggle the first console on/off.

---
 ui/sdl2.c | 322 ++++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 211 insertions(+), 111 deletions(-)
ui/sdl2.c +211 -111
index 4ad7ce3..6f3a919 100644
@@ -39,11 +39,18 @@
 
 #include "sdl2_scancode_translate.h"
 
-static DisplayChangeListener *dcl;
-static DisplaySurface *surface;
-static SDL_Window *real_window;
-static SDL_Renderer *real_renderer;
-static SDL_Texture *guest_texture;
+#define SDL2_MAX_OUTPUT 4
+
+static struct sdl2_console_state {
+    DisplayChangeListener dcl;
+    DisplaySurface *surface;
+    SDL_Texture *texture;
+    SDL_Window *real_window;
+    SDL_Renderer *real_renderer;
+    int idx;
+    int last_vm_running; /* per console for caption reasons */
+    int x, y;
+} sdl2_console[SDL2_MAX_OUTPUT];
 
 static SDL_Surface *guest_sprite_surface;
 static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
@@ -67,70 +74,112 @@ static SDL_Cursor *guest_sprite = NULL;
 static int scaling_active = 0;
 static Notifier mouse_mode_notifier;
 
-static void sdl_update_caption(void);
+static void sdl_update_caption(struct sdl2_console_state *scon);
+
+static struct sdl2_console_state *get_scon_from_window(uint32_t window_id)
+{
+    int i;
+    for (i = 0; i < SDL2_MAX_OUTPUT; i++) {
+        if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id))
+            return &sdl2_console[i];
+    }
+    return NULL;
+}
 
 static void sdl_update(DisplayChangeListener *dcl,
                        int x, int y, int w, int h)
 {
-    if (!surface)
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    SDL_Rect rect;
+    DisplaySurface *surf = qemu_console_surface(dcl->con);
+
+    if (!surf)
+        return;
+    if (!scon->texture)
         return;
 
-    SDL_UpdateTexture(guest_texture, NULL, surface_data(surface),
-                      surface_stride(surface));
-    SDL_RenderCopy(real_renderer, guest_texture, NULL, NULL);
-    SDL_RenderPresent(real_renderer);
+    rect.x = x;
+    rect.y = y;
+    rect.w = w;
+    rect.h = h;
+
+    SDL_UpdateTexture(scon->texture, NULL, surface_data(surf),
+                      surface_stride(surf));
+    SDL_RenderCopy(scon->real_renderer, scon->texture, &rect, &rect);
+    SDL_RenderPresent(scon->real_renderer);
 }
 
-static void do_sdl_resize(int width, int height, int bpp)
+static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height, int bpp)
 {
     int flags;
 
-    if (real_window) {
-        SDL_SetWindowSize(real_window, width, height);
-        SDL_RenderSetLogicalSize(real_renderer, width, height);
+    if (scon->real_window && scon->real_renderer) {
+        if (width && height) {
+            SDL_RenderSetLogicalSize(scon->real_renderer, width, height);
+       
+            SDL_SetWindowSize(scon->real_window, width, height);
+        } else {
+            SDL_DestroyRenderer(scon->real_renderer);
+            SDL_DestroyWindow(scon->real_window);
+            scon->real_renderer = NULL;
+            scon->real_window = NULL;
+        }
     } else {
+        if (!width || !height) {
+            return;
+        }
         flags = 0;
         if (gui_fullscreen)
             flags |= SDL_WINDOW_FULLSCREEN;
         else
             flags |= SDL_WINDOW_RESIZABLE;
 
-        real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,
-                                       SDL_WINDOWPOS_UNDEFINED,
-                                       width, height, flags);
-        real_renderer = SDL_CreateRenderer(real_window, -1, 0);
-        sdl_update_caption();
+        scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,
+                                             SDL_WINDOWPOS_UNDEFINED,
+                                             width, height, flags);
+        scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
+        sdl_update_caption(scon);
     }
 }
 
 static void sdl_switch(DisplayChangeListener *dcl,
                        DisplaySurface *new_surface)
 {
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
     int format = 0;
+    int idx = qemu_get_console_index(dcl->con);
+    DisplaySurface *old_surface = scon->surface;
+
     /* temporary hack: allows to call sdl_switch to handle scaling changes */
     if (new_surface) {
-        surface = new_surface;
+        scon->surface = new_surface;
     }
 
-    if (!scaling_active) {
-        do_sdl_resize(surface_width(surface), surface_height(surface), 0);
-    } else 
-        do_sdl_resize(surface_width(surface), surface_height(surface), 0);
+    if (!new_surface && idx > 0)
+        scon->surface = NULL;
 
-    if (guest_texture)
-        SDL_DestroyTexture(guest_texture);
+    if (new_surface == NULL)
+        do_sdl_resize(scon, 0, 0, 0);
+    else
+        do_sdl_resize(scon, surface_width(scon->surface), surface_height(scon->surface), 0);
 
-    if (surface_bits_per_pixel(surface) == 16)
-        format = SDL_PIXELFORMAT_RGB565;
-    else if (surface_bits_per_pixel(surface) == 32)
-        format = SDL_PIXELFORMAT_ARGB8888;
+    if (old_surface && scon->texture) {
+        SDL_DestroyTexture(scon->texture);
+        scon->texture = NULL;
+    }
 
-    if (!format)
-        exit(1);
-    guest_texture = SDL_CreateTexture(real_renderer, format,
-                                      SDL_TEXTUREACCESS_STREAMING,
-                                      surface_width(surface), surface_height(surface));
-    SDL_RenderSetLogicalSize(real_renderer, surface_width(surface), surface_height(surface));
+    if (new_surface) {
+        if (!scon->texture) {
+            if (surface_bits_per_pixel(scon->surface) == 16)
+                format = SDL_PIXELFORMAT_RGB565;
+            else if (surface_bits_per_pixel(scon->surface) == 32)
+                format = SDL_PIXELFORMAT_ARGB8888;
+
+            scon->texture = SDL_CreateTexture(scon->real_renderer, format,
+                                              SDL_TEXTUREACCESS_STREAMING,
+                                              surface_width(new_surface), surface_height(new_surface));
+        }
+    }
 }
 
 /* generic keyboard conversion */
@@ -250,7 +299,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
         kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
 }
 
-static void sdl_update_caption(void)
+static void sdl_update_caption(struct sdl2_console_state *scon)
 {
     char win_title[1024];
     char icon_title[1024];
@@ -268,15 +317,15 @@ static void sdl_update_caption(void)
     }
 
     if (qemu_name) {
-        snprintf(win_title, sizeof(win_title), "QEMU (%s)%s", qemu_name, status);
+        snprintf(win_title, sizeof(win_title), "QEMU (%s-%d)%s", qemu_name, scon->idx, status);
         snprintf(icon_title, sizeof(icon_title), "QEMU (%s)", qemu_name);
     } else {
         snprintf(win_title, sizeof(win_title), "QEMU%s", status);
         snprintf(icon_title, sizeof(icon_title), "QEMU");
     }
 
-    if (real_window)
-      SDL_SetWindowTitle(real_window, win_title);
+    if (scon->real_window)
+        SDL_SetWindowTitle(scon->real_window, win_title);
 }
 
 static void sdl_hide_cursor(void)
@@ -300,52 +349,52 @@ static void sdl_show_cursor(void)
     if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
         SDL_ShowCursor(1);
         if (guest_cursor &&
-                (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+            (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
             SDL_SetCursor(guest_sprite);
         else
             SDL_SetCursor(sdl_cursor_normal);
     }
 }
 
-static void sdl_grab_start(void)
+static void sdl_grab_start(struct sdl2_console_state *scon)
 {
     /*
      * If the application is not active, do not try to enter grab state. This
      * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
      * application (SDL bug).
      */
-    if (!(SDL_GetWindowFlags(real_window) & SDL_WINDOW_INPUT_FOCUS)) {
+    if (!(SDL_GetWindowFlags(scon->real_window) & SDL_WINDOW_INPUT_FOCUS)) {
         return;
     }
     if (guest_cursor) {
         SDL_SetCursor(guest_sprite);
         if (!kbd_mouse_is_absolute() && !absolute_enabled) {
-            SDL_WarpMouseInWindow(real_window, guest_x, guest_y);
+            SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y);
         }
     } else
         sdl_hide_cursor();
-    SDL_SetWindowGrab(real_window, SDL_TRUE);
+    SDL_SetWindowGrab(scon->real_window, SDL_TRUE);
     gui_grab = 1;
-    sdl_update_caption();
+    sdl_update_caption(scon);
 }
 
-static void sdl_grab_end(void)
+static void sdl_grab_end(struct sdl2_console_state *scon)
 {
-    SDL_SetWindowGrab(real_window, SDL_FALSE);
+    SDL_SetWindowGrab(scon->real_window, SDL_FALSE);
     gui_grab = 0;
     sdl_show_cursor();
-    sdl_update_caption();
+    sdl_update_caption(scon);
 }
 
-static void absolute_mouse_grab(void)
+static void absolute_mouse_grab(struct sdl2_console_state *scon)
 {
     int mouse_x, mouse_y;
     int scr_w, scr_h;
     SDL_GetMouseState(&mouse_x, &mouse_y);
-    SDL_GetWindowSize(real_window, &scr_w, &scr_h);
+    SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
     if (mouse_x > 0 && mouse_x < scr_w - 1 &&
         mouse_y > 0 && mouse_y < scr_h - 1) {
-        sdl_grab_start();
+        sdl_grab_start(scon);
     }
 }
 
@@ -355,18 +404,18 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
         if (!absolute_enabled) {
             absolute_enabled = 1;
             if (qemu_console_is_graphic(NULL)) {
-                absolute_mouse_grab();
+                absolute_mouse_grab(&sdl2_console[0]);
             }
         }
     } else if (absolute_enabled) {
         if (!gui_fullscreen) {
-            sdl_grab_end();
+            sdl_grab_end(&sdl2_console[0]);
         }
         absolute_enabled = 0;
     }
 }
 
-static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state)
+static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int dy, int dz, int x, int y, int state)
 {
     int buttons = 0;
 
@@ -382,9 +431,30 @@ static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state
 
     if (kbd_mouse_is_absolute()) {
         int scr_w, scr_h;
-        SDL_GetWindowSize(real_window, &scr_w, &scr_h);
-        dx = x * 0x7FFF / (scr_w - 1);
-        dy = y * 0x7FFF / (scr_h - 1);
+        int max_w = 0, max_h = 0;
+        int off_x = 0, off_y = 0;
+        int cur_off_x = 0, cur_off_y = 0;
+        int i;
+
+        for (i = 0; i < SDL2_MAX_OUTPUT; i++) {
+            struct sdl2_console_state *thiscon = &sdl2_console[i];
+            if (thiscon->real_window && thiscon->surface) {
+                SDL_GetWindowSize(thiscon->real_window, &scr_w, &scr_h);
+                cur_off_x = thiscon->x;
+                cur_off_y = thiscon->y;
+                if (scr_w + cur_off_x > max_w)
+                    max_w = scr_w + cur_off_x;
+                if (scr_h + cur_off_y > max_h)
+                    max_h = scr_h + cur_off_y;
+                if (i == scon->idx) {
+                    off_x = cur_off_x;
+                    off_y = cur_off_y;
+                }
+            }
+        }
+
+        dx = (off_x + x) * 0x7FFF / (max_w - 1);
+        dy = (off_y + y) * 0x7FFF / (max_h - 1);
     } else if (guest_cursor) {
         x -= guest_x;
         y -= guest_y;
@@ -397,51 +467,52 @@ static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int state
     kbd_mouse_event(dx, dy, dz, buttons);
 }
 
-static void sdl_scale(int width, int height)
+static void sdl_scale(struct sdl2_console_state *scon, int width, int height)
 {
     int bpp = 0;
-    do_sdl_resize(width, height, bpp);
+    do_sdl_resize(scon, width, height, bpp);
     scaling_active = 1;
 }
 
-static void toggle_full_screen(void)
+static void toggle_full_screen(struct sdl2_console_state *scon)
 {
-    int width = surface_width(surface);
-    int height = surface_height(surface);
-    int bpp = surface_bits_per_pixel(surface);
+    int width = surface_width(scon->surface);
+    int height = surface_height(scon->surface);
+    int bpp = surface_bits_per_pixel(scon->surface);
 
     gui_fullscreen = !gui_fullscreen;
     if (gui_fullscreen) {
-        SDL_GetWindowSize(real_window, &gui_saved_width, &gui_saved_height);
+        SDL_GetWindowSize(scon->real_window, &gui_saved_width, &gui_saved_height);
         gui_saved_scaling = scaling_active;
 
-        do_sdl_resize(width, height, bpp);
+        do_sdl_resize(scon, width, height, bpp);
         scaling_active = 0;
 
         gui_saved_grab = gui_grab;
-        sdl_grab_start();
+        sdl_grab_start(scon);
     } else {
         if (gui_saved_scaling) {
-            sdl_scale(gui_saved_width, gui_saved_height);
+            sdl_scale(scon, gui_saved_width, gui_saved_height);
         } else {
-            do_sdl_resize(width, height, 0);
+            do_sdl_resize(scon, width, height, 0);
         }
         if (!gui_saved_grab || !qemu_console_is_graphic(NULL)) {
-            sdl_grab_end();
+            sdl_grab_end(scon);
         }
     }
-    graphic_hw_invalidate(NULL);
-    graphic_hw_update(NULL);
+    graphic_hw_invalidate(scon->dcl.con);
+    graphic_hw_update(scon->dcl.con);
 }
 
 static void handle_keydown(SDL_Event *ev)
 {
     int mod_state;
     int keycode;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (alt_grab) {
         mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
-                    (gui_grab_code | KMOD_LSHIFT);
+            (gui_grab_code | KMOD_LSHIFT);
     } else if (ctrl_grab) {
         mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
     } else {
@@ -452,16 +523,23 @@ static void handle_keydown(SDL_Event *ev)
     if (gui_key_modifier_pressed) {
         keycode = sdl_keyevent_to_keycode(&ev->key);
         switch (keycode) {
+        case 0x31:
+            /* spawn a new connected monitor if we have one */
+            if (sdl2_console[1].surface)
+                graphic_hw_notify_state(sdl2_console[1].dcl.con, 0, 0, 0, 0);
+            else
+                graphic_hw_notify_state(sdl2_console[1].dcl.con, 0, 0, 1024, 768);
+            break;
         case 0x21: /* 'f' key on US keyboard */
-            toggle_full_screen();
+            toggle_full_screen(scon);
             gui_keysym = 1;
             break;
         case 0x16: /* 'u' key on US keyboard */
             if (scaling_active) {
                 scaling_active = 0;
-                sdl_switch(dcl, NULL);
-                graphic_hw_invalidate(NULL);
-                graphic_hw_update(NULL);
+                sdl_switch(&scon->dcl, NULL);
+                graphic_hw_invalidate(scon->dcl.con);
+                graphic_hw_update(scon->dcl.con);
             }
             gui_keysym = 1;
             break;
@@ -476,13 +554,13 @@ static void handle_keydown(SDL_Event *ev)
             if (!qemu_console_is_graphic(NULL)) {
                 /* release grab if going to a text console */
                 if (gui_grab) {
-                    sdl_grab_end();
+                    sdl_grab_end(scon);
                 } else if (absolute_enabled) {
                     sdl_show_cursor();
                 }
             } else if (absolute_enabled) {
                 sdl_hide_cursor();
-                absolute_mouse_grab();
+                absolute_mouse_grab(scon);
             }
             break;
         case 0x1b: /* '+' */
@@ -490,14 +568,14 @@ static void handle_keydown(SDL_Event *ev)
             if (!gui_fullscreen) {
                 int scr_w, scr_h;
                 int width, height;
-                SDL_GetWindowSize(real_window, &scr_w, &scr_h);
+                SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
 
                 width = MAX(scr_w + (keycode == 0x1b ? 50 : -50),
-                                160);
-                height = (surface_height(surface) * width) /
-                    surface_width(surface);
+                            160);
+                height = (surface_height(scon->surface) * width) /
+                    surface_width(scon->surface);
 
-                sdl_scale(width, height);
+                sdl_scale(scon, width, height);
                 graphic_hw_invalidate(NULL);
                 graphic_hw_update(NULL);
                 gui_keysym = 1;
@@ -585,6 +663,7 @@ static void handle_keydown(SDL_Event *ev)
 static void handle_keyup(SDL_Event *ev)
 {
     int mod_state;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (!alt_grab) {
         mod_state = (ev->key.keysym.mod & gui_grab_code);
@@ -597,10 +676,10 @@ static void handle_keyup(SDL_Event *ev)
             /* exit/enter grab if pressing Ctrl-Alt */
             if (!gui_grab) {
                 if (qemu_console_is_graphic(NULL)) {
-                    sdl_grab_start();
+                    sdl_grab_start(scon);
                 }
             } else if (!gui_fullscreen) {
-                sdl_grab_end();
+                sdl_grab_end(scon);
             }
             /* SDL does not send back all the modifiers key, so we must
              * correct it. */
@@ -617,25 +696,26 @@ static void handle_keyup(SDL_Event *ev)
 static void handle_mousemotion(SDL_Event *ev)
 {
     int max_x, max_y;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (qemu_console_is_graphic(NULL) &&
         (kbd_mouse_is_absolute() || absolute_enabled)) {
         int scr_w, scr_h;
-        SDL_GetWindowSize(real_window, &scr_w, &scr_h);
+        SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
         max_x = scr_w - 1;
         max_y = scr_h - 1;
         if (gui_grab && (ev->motion.x == 0 || ev->motion.y == 0 ||
-            ev->motion.x == max_x || ev->motion.y == max_y)) {
-            sdl_grab_end();
+                         ev->motion.x == max_x || ev->motion.y == max_y)) {
+            sdl_grab_end(scon);
         }
         if (!gui_grab &&
             (ev->motion.x > 0 && ev->motion.x < max_x &&
-            ev->motion.y > 0 && ev->motion.y < max_y)) {
-            sdl_grab_start();
+             ev->motion.y > 0 && ev->motion.y < max_y)) {
+            sdl_grab_start(scon);
         }
     }
     if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
-        sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
+        sdl_send_mouse_event(scon, ev->motion.xrel, ev->motion.yrel, 0,
                              ev->motion.x, ev->motion.y, ev->motion.state);
     }
 }
@@ -644,6 +724,7 @@ static void handle_mousebutton(SDL_Event *ev)
 {
     int buttonstate = SDL_GetMouseState(NULL, NULL);
     SDL_MouseButtonEvent *bev;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
     int dz;
 
     if (!qemu_console_is_graphic(NULL)) {
@@ -654,7 +735,7 @@ static void handle_mousebutton(SDL_Event *ev)
     if (!gui_grab && !kbd_mouse_is_absolute()) {
         if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
             /* start grabbing all events */
-            sdl_grab_start();
+            sdl_grab_start(scon);
         }
     } else {
         dz = 0;
@@ -672,19 +753,20 @@ static void handle_mousebutton(SDL_Event *ev)
             dz = 1;
         }
 #endif
-        sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
+        sdl_send_mouse_event(scon, 0, 0, dz, bev->x, bev->y, buttonstate);
     }
 }
 
 static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
 {
     int w, h;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
     switch (ev->window.event) {
     case SDL_WINDOWEVENT_RESIZED:
-        sdl_scale(ev->window.data1, ev->window.data2);
-        graphic_hw_invalidate(NULL);
-        graphic_hw_update(NULL);
+        sdl_scale(scon, ev->window.data1, ev->window.data2);
+        graphic_hw_invalidate(scon->dcl.con);
+        graphic_hw_update(scon->dcl.con);
         break;
     case SDL_WINDOWEVENT_EXPOSED:
         SDL_GetWindowSize(SDL_GetWindowFromID(ev->window.windowID), &w, &h);
@@ -694,12 +776,12 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
     case SDL_WINDOWEVENT_ENTER:
         if (!gui_grab && qemu_console_is_graphic(NULL) &&
             (kbd_mouse_is_absolute() || absolute_enabled)) {
-            absolute_mouse_grab();
+            absolute_mouse_grab(scon);
         }
         break;
     case SDL_WINDOWEVENT_FOCUS_LOST:
         if (gui_grab && !gui_fullscreen)
-            sdl_grab_end();
+            sdl_grab_end(scon);
         break;
     case SDL_WINDOWEVENT_RESTORED:
         update_displaychangelistener(dcl, GUI_REFRESH_INTERVAL_DEFAULT);
@@ -718,14 +800,15 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
 
 static void sdl_refresh(DisplayChangeListener *dcl)
 {
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
     SDL_Event ev1, *ev = &ev1;
 
-    if (last_vm_running != runstate_is_running()) {
-        last_vm_running = runstate_is_running();
-        sdl_update_caption();
+    if (scon->last_vm_running != runstate_is_running()) {
+        scon->last_vm_running = runstate_is_running();
+        sdl_update_caption(scon);
     }
 
-    graphic_hw_update(NULL);
+    graphic_hw_update(dcl->con);
 
     while (SDL_PollEvent(ev)) {
         switch (ev->type) {
@@ -760,13 +843,14 @@ static void sdl_refresh(DisplayChangeListener *dcl)
 static void sdl_mouse_warp(DisplayChangeListener *dcl,
                            int x, int y, int on)
 {
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
     if (on) {
         if (!guest_cursor)
             sdl_show_cursor();
         if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
             SDL_SetCursor(guest_sprite);
             if (!kbd_mouse_is_absolute() && !absolute_enabled) {
-                SDL_WarpMouseInWindow(real_window, x, y);
+                SDL_WarpMouseInWindow(scon->real_window, x, y);
             }
         }
     } else if (gui_grab)
@@ -804,6 +888,15 @@ static void sdl_mouse_define(DisplayChangeListener *dcl,
         SDL_SetCursor(guest_sprite);
 }
 
+static void sdl_notify_state(DisplayChangeListener *dcl,
+                             int x, int y, uint32_t width, uint32_t height)
+{
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+
+    scon->x = x;
+    scon->y = y;
+}
+
 static void sdl_cleanup(void)
 {
     if (guest_sprite)
@@ -818,6 +911,7 @@ static const DisplayChangeListenerOps dcl_ops = {
     .dpy_refresh       = sdl_refresh,
     .dpy_mouse_set     = sdl_mouse_warp,
     .dpy_cursor_define = sdl_mouse_define,
+    .dpy_notify_state  = sdl_notify_state,
 };
 
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
@@ -825,7 +919,8 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     int flags;
     uint8_t data = 0;
     char *filename;
-
+    int nconsoles;
+    int i;
 #if defined(__APPLE__)
     /* always use generic keymaps */
     if (!keyboard_layout)
@@ -866,19 +961,24 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
         if (image) {
             uint32_t colorkey = SDL_MapRGB(image->format, 255, 255, 255);
             SDL_SetColorKey(image, SDL_TRUE, colorkey);
-            SDL_SetWindowIcon(real_window, image);
+            SDL_SetWindowIcon(sdl2_console[0].real_window, image);
         }
         g_free(filename);
     }
 
     if (full_screen) {
         gui_fullscreen = 1;
-        sdl_grab_start();
+        sdl_grab_start(0);
     }
 
-    dcl = g_malloc0(sizeof(DisplayChangeListener));
-    dcl->ops = &dcl_ops;
-    register_displaychangelistener(dcl);
+    nconsoles = qemu_get_number_graphical_consoles();
+    
+    for (i = 0; i < nconsoles; i++) {
+        sdl2_console[i].dcl.ops = &dcl_ops;
+        sdl2_console[i].dcl.con = qemu_console_lookup_by_index(i);
+        register_displaychangelistener(&sdl2_console[i].dcl);
+        sdl2_console[i].idx = i;
+    }
 
     mouse_mode_notifier.notify = sdl_mouse_mode_change;
     qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier);
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 6/8 virtio-gpu: v0.1 of the virtio based GPU code.

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

This is the basic virtio-gpu which is

multi-head capable,
ARGB cursor support,
unaccelerated.

---
 default-configs/x86_64-softmmu.mak |   1 +
 hw/display/Makefile.objs           |   2 +
 hw/display/virtgpu_hw.h            | 225 ++++++++++++++
 hw/display/virtio-gpu.c            | 606 +++++++++++++++++++++++++++++++++++++
 hw/virtio/virtio-pci.c             |  49 +++
 hw/virtio/virtio-pci.h             |  15 +
 include/hw/pci/pci.h               |   1 +
 include/hw/virtio/virtio-gpu.h     |  90 ++++++
 8 files changed, 989 insertions(+)
 create mode 100644 hw/display/virtgpu_hw.h
 create mode 100644 hw/display/virtio-gpu.c
 create mode 100644 include/hw/virtio/virtio-gpu.h
default-configs/x86_64-softmmu.mak +1 -0
index 31bddce..1a00b78 100644
@@ -9,6 +9,7 @@ CONFIG_VGA_PCI=y
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
+CONFIG_VIRTIO_GPU=y
 CONFIG_VMMOUSE=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
hw/display/Makefile.objs +2 -0
index 540df82..10e4066 100644
@@ -32,3 +32,5 @@ obj-$(CONFIG_TCX) += tcx.o
 obj-$(CONFIG_VGA) += vga.o
 
 common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
+
+obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu.o
hw/display/virtgpu_hw.h new file +225 -0

225 lines not on this page · raw message

hw/display/virtio-gpu.c new file +606 -0

606 lines not on this page · raw message

hw/virtio/virtio-pci.c +49 -0

61 lines not on this page · raw message

hw/virtio/virtio-pci.h +15 -0
index 917bcc5..856046d 100644
@@ -24,6 +24,7 @@
 #include "hw/virtio/virtio-balloon.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-9p.h"
+#include "hw/virtio/virtio-gpu.h"
 #ifdef CONFIG_VIRTFS
 #include "hw/9pfs/virtio-9p.h"
 #endif
@@ -39,6 +40,7 @@ typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VHostSCSIPCI VHostSCSIPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
+typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 
 /* virtio-pci-bus */
 
@@ -200,6 +202,19 @@ struct VirtIORngPCI {
     VirtIORNG vdev;
 };
 
+/*
+ * virtio-gpu-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
+#define VIRTIO_GPU_PCI(obj) \
+        OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
+
+struct VirtIOGPUPCI {
+    VirtIOPCIProxy parent_obj;
+    VirtIOGPU vdev;
+};
+
+
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION          0
 
include/hw/pci/pci.h +1 -0
index b783e68..fee5d6b 100644
@@ -80,6 +80,7 @@
 #define PCI_DEVICE_ID_VIRTIO_SCSI        0x1004
 #define PCI_DEVICE_ID_VIRTIO_RNG         0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
+#define PCI_DEVICE_ID_VIRTIO_GPU         0x1010
 
 #define PCI_VENDOR_ID_REDHAT             0x1b36
 #define PCI_DEVICE_ID_REDHAT_BRIDGE      0x0001
include/hw/virtio/virtio-gpu.h new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

PATCH 7/8 virtio-vga: v1

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

This is a virtio-vga device built on top of the virtio-gpu device.

---
 Makefile                           |   2 +-
 default-configs/x86_64-softmmu.mak |   1 +
 hw/display/Makefile.objs           |   1 +
 hw/display/virtio-vga.c            | 156 +++++++++++++++++++++++++++++++++++++
 hw/pci/pci.c                       |   2 +
 include/sysemu/sysemu.h            |   2 +-
 pc-bios/vgabios-virtio.bin         | Bin 0 -> 40448 bytes
 roms/Makefile                      |   2 +-
 roms/config.vga.virtio             |   6 ++
 vl.c                               |  13 ++++
 10 files changed, 182 insertions(+), 3 deletions(-)
 create mode 100644 hw/display/virtio-vga.c
 create mode 100644 pc-bios/vgabios-virtio.bin
 create mode 100644 roms/config.vga.virtio
Makefile +1 -1
index b15003f..093ff9a 100644
@@ -284,7 +284,7 @@ bepo
 
 ifdef INSTALL_BLOBS
 BLOBS=bios.bin sgabios.bin vgabios.bin vgabios-cirrus.bin \
-vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin \
+vgabios-stdvga.bin vgabios-vmware.bin vgabios-qxl.bin vgabios-virtio.bin \
 acpi-dsdt.aml q35-acpi-dsdt.aml \
 ppc_rom.bin openbios-sparc32 openbios-sparc64 openbios-ppc \
 pxe-e1000.rom pxe-eepro100.rom pxe-ne2k_pci.rom \
default-configs/x86_64-softmmu.mak +1 -0
index 1a00b78..22d8587 100644
@@ -10,6 +10,7 @@ CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VIRTIO_GPU=y
+CONFIG_VIRTIO_VGA=y
 CONFIG_VMMOUSE=y
 CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
hw/display/Makefile.objs +1 -0
index 10e4066..63427e9 100644
@@ -34,3 +34,4 @@ obj-$(CONFIG_VGA) += vga.o
 common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
 
 obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu.o
+obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
hw/display/virtio-vga.c new file +156 -0

156 lines not on this page · raw message

hw/pci/pci.c +2 -0
index a98c8a0..32eb43f 100644
@@ -1673,6 +1673,8 @@ PCIDevice *pci_vga_init(PCIBus *bus)
         return pci_create_simple(bus, -1, "VGA");
     case VGA_VMWARE:
         return pci_create_simple(bus, -1, "vmware-svga");
+    case VGA_VIRTIO:
+        return pci_create_simple(bus, -1, "virtio-vga");
     case VGA_NONE:
     default: /* Other non-PCI types. Checking for unsupported types is already
                 done in vl.c. */
include/sysemu/sysemu.h +1 -1
index cd5791e..3523bc9 100644
@@ -103,7 +103,7 @@ typedef enum DisplayType
 extern int autostart;
 
 typedef enum {
-    VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
+    VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL, VGA_VIRTIO
 } VGAInterfaceType;
 
 extern int vga_interface_type;
pc-bios/vgabios-virtio.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2b70d272f2704e7839712a61613844321b93b465
GIT binary patch
roms/Makefile +1 -1
index 10d5a65..882ac32 100644
@@ -1,5 +1,5 @@
 
-vgabios_variants := stdvga cirrus vmware qxl isavga
+vgabios_variants := stdvga cirrus vmware qxl isavga virtio
 vgabios_targets  := $(subst -isavga,,$(patsubst %,vgabios-%.bin,$(vgabios_variants)))
 pxerom_variants  := e1000 eepro100 ne2k_pci pcnet rtl8139 virtio
 pxerom_targets   := 8086100e 80861209 10500940 10222000 10ec8139 1af41000
roms/config.vga.virtio new file +6 -0
new file mode 100644
index 0000000..9a78983
@@ -0,0 +1,6 @@
+CONFIG_BUILD_VGABIOS=y
+CONFIG_VGA_BOCHS=y
+CONFIG_VGA_PCI=y
+CONFIG_OVERRIDE_PCI_ID=y
+CONFIG_VGA_VID=0x1af4
+CONFIG_VGA_DID=0x1010
vl.c +13 -0
index 4ad15b8..de5c40b 100644
@@ -301,6 +301,7 @@ static struct {
     { .driver = "isa-cirrus-vga",       .flag = &default_vga       },
     { .driver = "vmware-svga",          .flag = &default_vga       },
     { .driver = "qxl-vga",              .flag = &default_vga       },
+    { .driver = "virtio-vga",           .flag = &default_vga       },
 };
 
 static QemuOptsList qemu_rtc_opts = {
@@ -2080,6 +2081,11 @@ static bool qxl_vga_available(void)
     return object_class_by_name("qxl-vga");
 }
 
+static bool virtio_vga_available(void)
+{
+    return object_class_by_name("virtio-vga");
+}
+
 static void select_vgahw (const char *p)
 {
     const char *opts;
@@ -2106,6 +2112,13 @@ static void select_vgahw (const char *p)
             fprintf(stderr, "Error: VMWare SVGA not available\n");
             exit(0);
         }
+    } else if (strstart(p, "virtio", &opts)) {
+        if (virtio_vga_available()) {
+            vga_interface_type = VGA_VIRTIO;
+        } else {
+            fprintf(stderr, "Error: Virtio VGA not available\n");
+            exit(0);
+        }
     } else if (strstart(p, "xenfb", &opts)) {
         vga_interface_type = VGA_XENFB;
     } else if (strstart(p, "qxl", &opts)) {
Signature · 1 line
1.8.3.1
#21 lore raw

PATCH 8/8 HACK: just to make things start easier with libvirt

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

---
 hw/display/vga-pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/display/vga-pci.c +2 -1
index b3a45c8..e4bea17 100644
@@ -146,6 +146,7 @@ static int pci_std_vga_initfn(PCIDevice *dev)
     PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
     VGACommonState *s = &d->vga;
 
+	return 0;
     /* vga + console init */
     vga_common_init(s, OBJECT(dev));
     vga_init(s, OBJECT(dev), pci_address_space(dev), pci_address_space_io(dev),
@@ -195,7 +196,7 @@ static void vga_class_init(ObjectClass *klass, void *data)
     k->romfile = "vgabios-stdvga.bin";
     k->vendor_id = PCI_VENDOR_ID_QEMU;
     k->device_id = PCI_DEVICE_ID_QEMU_VGA;
-    k->class_id = PCI_CLASS_DISPLAY_VGA;
+    k->class_id = 0;// PCI_CLASS_DISPLAY_VGA;
     dc->vmsd = &vmstate_vga_pci;
     dc->props = vga_pci_properties;
     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/8] ui/sdl2 : initial port to SDL 2.0 (v1.2)

In reply to Dave Airlie
Quoted 3 lines · Dave Airlie

From: Dave Airlie <[email protected]>

I've ported the SDL1.2 code over, and rewritten it to use the SDL2 interface.

Looks sane on a quick glance. Didn't look in detail yet. I would have suggested to put stuff into structs instead of using global variables, but I see you do that in patch #5. I think you can squash the two into one.

Quoted 5 lines

The biggest changes were in the input handling, where SDL2 has done a major overhaul, and I've had to include a generated translation file to get from SDL2 codes back to qemu compatible ones. I'm still not sure how the keyboard layout code works in qemu, so there may be further work if someone can point me a test case that works with SDL1.2 and doesn't with SDL2.

Can you describe what is has changed from sdl 1.2 -> 2.0?

Ideally qemu wants a scancode which it can feed into keyboard emulation. How that'll get mapped into keysyms is guests bussiness.

When qemu can't get a scancode it will try to translate the keysym back to a scancode, using a keymap (this is what the -k switch is for).

cheers,
Gerd

#4 lore raw

Re: [Qemu-devel] [PATCH 2/8] console: add state notifiers for ui<->display

In reply to Dave Airlie
Quoted 5 lines · Dave Airlie

From: Dave Airlie <[email protected]>

These are to be used for the UI to signal the video display, and vice-versa about changes in the state of a console, like size and offsets in relation to other consoles for input handling.

See other mail from today morning. I think this is input layer's job, not ui code job. Storing the info in QemuConsole is fine. Having a QemuHeadInfo struct for it is probably useful, so the input layer can query it easily, say using a to-be-written qemu_console_get_head_info() function which returns a ptr to the struct.

Notification should also go to the input layer not ui code. Or maybe use a notifier list (see include/qemu/notify.h) so anyone interested can listen, ui code might want to know too (not for input processing, but maybe to arrange window on the host).

cheers,
Gerd

#6 lore raw

Re: [Qemu-devel] [PATCH 3/8] console: add information retrival wrappers

In reply to Dave Airlie

Hi,

Quoted 1 line

+int qemu_get_console_index(QemuConsole *con);

Makes sense to have that. There are other retrival wrappers already (qemu_console_is_*). I'd like to see the new one placed next to the others, and follow the name convention (i.e. use qemu_console_get_index).

Quoted 1 line

+int qemu_get_number_graphical_consoles(void);

Hmm, what is bad with qemu_console_is_graphic? Patch #5 uses it to loop over the gfx consoles. As the code doesn't need to know the number of consoles in advance you can do this instead (like spice):

    for (i = 0;; i++) {
        con = qemu_console_lookup_by_index(i);
        if (!con || !qemu_console_is_graphic(con)) {
            break;
        }
        [ ... ]
    }

cheers,
Gerd

#10 lore raw

Re: [Qemu-devel] [PATCH 6/8] virtio-gpu: v0.1 of the virtio based GPU code.

In reply to Dave Airlie
Quoted 7 lines · Dave Airlie

From: Dave Airlie <[email protected]>

This is the basic virtio-gpu which is

multi-head capable,
ARGB cursor support,
unaccelerated.

I'd like to see an overview on the design of the virtual hardware. What is the purpose of the virtio commands?
What are the steps a guest is supposed to do to get something displayed on the screen?

hw/display/virtio-gpu.c line 138

Quoted 3 lines
hw/display/virtio-gpu.c new file +3 -0
+    res = calloc(1, sizeof(struct virtgpu_simple_resource));
+    if (!res)
+	return;

qemu uses glib memory allocation functions (i.e. g_malloc0 for this one). Also no need to check for NULL.

cheers,
Gerd

#12 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

In reply to Dave Airlie
Quoted 3 lines · Dave Airlie

From: Dave Airlie <[email protected]>

This is a virtio-vga device built on top of the virtio-gpu device.

Ah, I see what you use the wrapping for. Hmm. I think you should use a common base class instead, i.e. something like virtio-gpu-base which holds all the common stuff. Both virtio-gpu and virtio-vga can use that as TypeInfo->parent then. This way virtio-vga doesn't have to muck with virtio-gpu internals. virtio-gpu-base can be tagged as abstract class (using .abstract = true) so it will not be instantiated directly.

cheers,
Gerd

#13 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Quoted 12 lines · Gerd Hoffmann
Quoted 3 lines · Dave Airlie

From: Dave Airlie <[email protected]>

This is a virtio-vga device built on top of the virtio-gpu device.

Ah, I see what you use the wrapping for. Hmm. I think you should use a common base class instead, i.e. something like virtio-gpu-base which holds all the common stuff. Both virtio-gpu and virtio-vga can use that as TypeInfo->parent then. This way virtio-vga doesn't have to muck with virtio-gpu internals. virtio-gpu-base can be tagged as abstract class (using .abstract = true) so it will not be instantiated directly.

I'm not sure what that buys me here, I need the virtio-vga to attach the vga ops the first console that the virtio-gpu registers, it can't be a separate console, and since virtio-gpu initialises before virtio-vga I can't tell it to not register the console.

Its no use attaching just the vga or just the gpu ops to the console I need a wrapper and I can't see how having a common base class would help. I already have a base class, that pci subclasses then vga subclasses that.

Dave.

#14 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Il 21/11/2013 04:12, Dave Airlie ha scritto:

Quoted 4 lines

I'm not sure what that buys me here, I need the virtio-vga to attach the vga ops the first console that the virtio-gpu registers, it can't be a separate console, and since virtio-gpu initialises before virtio-vga I can't tell it to not register the console.

If you make a base class, the ops can be registered in the base class and they just call a method in the base class. The default implementation of the method can be virtio-gpu's, but virtio-vga can override them and make them go to either the virtio-gpu implementation or the VGA implementation.

Paolo

#15 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

In reply to Dave Airlie
Quoted 14 lines · Dave Airlie
Quoted 12 lines · Gerd Hoffmann
Quoted 3 lines · Dave Airlie

From: Dave Airlie <[email protected]>

This is a virtio-vga device built on top of the virtio-gpu device.

Ah, I see what you use the wrapping for. Hmm. I think you should use a common base class instead, i.e. something like virtio-gpu-base which holds all the common stuff. Both virtio-gpu and virtio-vga can use that as TypeInfo->parent then. This way virtio-vga doesn't have to muck with virtio-gpu internals. virtio-gpu-base can be tagged as abstract class (using .abstract = true) so it will not be instantiated directly.

Quoted 4 lines

I'm not sure what that buys me here, I need the virtio-vga to attach the vga ops the first console that the virtio-gpu registers, it can't be a separate console, and since virtio-gpu initialises before virtio-vga I can't tell it to not register the console.

virtio-gpu-core registers no consoles. It just export the hw_ops
functions. virtio-gpu-core inly initializes the stuff which is
identical for both virtio-gpu and virtio-vga, everything else is left to the init functions of the subclasses.

virtio-gpu uses virtio-gpu-core as parent. Registers the the consoles, using the hw_ops functions exported by virtio-gpu-core. Also sets the pci class to DISPLAY_OTHER.

virtio-vga uses virtio-gpu-core as parent too. Registers the consoles, using functions basically doing "if vgamode then call vga hw_ops else call virtio-gpu-core hw_ops". Simliar to what you have today but without the funky wrapping. Sets pci class to DISPLAY_VGA and initializes vga stuff.

cheers,
Gerd

#16 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Quoted 29 lines · Gerd Hoffmann
Quoted 14 lines · Dave Airlie
Quoted 12 lines · Gerd Hoffmann
Quoted 3 lines · Dave Airlie

From: Dave Airlie <[email protected]>

This is a virtio-vga device built on top of the virtio-gpu device.

Ah, I see what you use the wrapping for. Hmm. I think you should use a common base class instead, i.e. something like virtio-gpu-base which holds all the common stuff. Both virtio-gpu and virtio-vga can use that as TypeInfo->parent then. This way virtio-vga doesn't have to muck with virtio-gpu internals. virtio-gpu-base can be tagged as abstract class (using .abstract = true) so it will not be instantiated directly.

Quoted 4 lines

I'm not sure what that buys me here, I need the virtio-vga to attach the vga ops the first console that the virtio-gpu registers, it can't be a separate console, and since virtio-gpu initialises before virtio-vga I can't tell it to not register the console.

virtio-gpu-core registers no consoles. It just export the hw_ops
functions. virtio-gpu-core inly initializes the stuff which is
identical for both virtio-gpu and virtio-vga, everything else is left to the init functions of the subclasses.

virtio-gpu uses virtio-gpu-core as parent. Registers the the consoles, using the hw_ops functions exported by virtio-gpu-core. Also sets the pci class to DISPLAY_OTHER.

Quoted 8 lines

virtio-vga uses virtio-gpu-core as parent too. Registers the consoles, using functions basically doing "if vgamode then call vga hw_ops else call virtio-gpu-core hw_ops". Simliar to what you have today but without the funky wrapping. Sets pci class to DISPLAY_VGA and initializes vga stuff.

cheers,
Gerd

Okay I'm really missing something here and I think I've confused myself completely.

My plan was

virtio-gpu-base - VirtIOGPUBase object - VirtIODevice parent_obj - abstract class - contains vqs + exposes ops

virtio-gpu - virtio-gpu-base wrapper with init sequence for non-VGA virtio gpus (mmio + pci)
virtio-gpu-pci - VirtIOPCIProxy parent_obj - contains a VirtIOGPU vdev that it instantiates in its instance init like all the PCI wrappers

Now the advice given was to have virtio-vga wrap virtio-gpu-base but from what I can see it really can't. Since it needs to act and look like a PCI device

virtio-vga: Also has a VirtIOPCIProxy parent_obj, however as virtio-gpu-base is abstract I can't directly instantiate it, and I can't instantiate virtio-gpu as its the wrong thing,

so do I really need to add another class? rename virtio-vga to virtio-pci-vga and add a new virtio-vga that just wraps virtio-gpu-base?

This is getting a lot messier than the code I had, and the benefits are escaping me, which must mean I'm misinterpreting the instructions given.

This then led to another question how do I call the virtio-gpu-base init functions? directly? as I can't use qdev as they are abstract from what I can see.

Dave.

#17 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Hi,

Quoted 3 lines

Now the advice given was to have virtio-vga wrap virtio-gpu-base but from what I can see it really can't. Since it needs to act and look like a PCI device

Oops, yes. VirtIOPCIProxy wasn't on my radar. That makes things a bit more messy. Can you just push what you have now somewhere? I'll take a closer look next week.

cheers,
Gerd

#18 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Quoted 9 lines · Gerd Hoffmann

Hi,

Quoted 3 lines

Now the advice given was to have virtio-vga wrap virtio-gpu-base but from what I can see it really can't. Since it needs to act and look like a PCI device

Oops, yes. VirtIOPCIProxy wasn't on my radar. That makes things a bit more messy. Can you just push what you have now somewhere? I'll take a closer look next week.

http://cgit.freedesktop.org/~airlied/qemu/log/?h=virtio-gpu-inherit

Well I didn't really get anything working, but the top commit in that branch was where I was on my last random fail.

I think another object is probably required, or making the base one not abstract.

Dave.

#19 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Quoted 11 lines · Dave Airlie
Quoted 9 lines · Gerd Hoffmann

Hi,

Quoted 3 lines

Now the advice given was to have virtio-vga wrap virtio-gpu-base but from what I can see it really can't. Since it needs to act and look like a PCI device

Oops, yes. VirtIOPCIProxy wasn't on my radar. That makes things a bit more messy. Can you just push what you have now somewhere? I'll take a closer look next week.

Quoted 8 lines

http://cgit.freedesktop.org/~airlied/qemu/log/?h=virtio-gpu-inherit

Well I didn't really get anything working, but the top commit in that branch was where I was on my last random fail.

I think another object is probably required, or making the base one not abstract.

Hi Gerd,

just repinging on this, not sure if you can see a solution that works with VirtIOPCIProxy that avoids wrapping.

Dave.

#20 lore raw

Re: [Qemu-devel] [PATCH 7/8] virtio-vga: v1

Quoted 17 lines · Dave Airlie
Quoted 16 lines · Dave Airlie
Quoted 9 lines · Gerd Hoffmann

Hi,

Quoted 3 lines

Now the advice given was to have virtio-vga wrap virtio-gpu-base but from what I can see it really can't. Since it needs to act and look like a PCI device

Oops, yes. VirtIOPCIProxy wasn't on my radar. That makes things a bit more messy. Can you just push what you have now somewhere? I'll take a closer look next week.

http://cgit.freedesktop.org/~airlied/qemu/log/?h=virtio-gpu-inherit

Well I didn't really get anything working, but the top commit in that branch was where I was on my last random fail.

Quoted 7 lines
Quoted 3 lines

I think another object is probably required, or making the base one not abstract.

Hi Gerd,

just repinging on this, not sure if you can see a solution that works with VirtIOPCIProxy that avoids wrapping.

Havn't found time yet. Was sick over xmas/newyear, back online now.

So I have a big email backlog to wade through now, and there are also the input/sdl2 bits which need some love to get it merged. Also not checked yet bugzilla for urgent stuff. So I expect this has to wait at least one more week ...

happy new years & cheers,
Gerd