sdl2: Support all virtio-gpu formats
authorMax Reitz <mreitz@redhat.com>
Mon, 8 Oct 2018 18:50:13 +0000 (20:50 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Fri, 12 Oct 2018 12:46:24 +0000 (14:46 +0200)
There are some 2D resource formats that can be used through virtio-gpu,
but which are not supported by SDL2 when used for a scanout; these are
all alpha-channel formats and also XBGR (RGBX in non-BE pixman).

Add these formats in the switch converting pixman to SDL format
constants so a guest cannot crash the VM by triggering the
g_assert_not_reached() with an unsupported format.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20181008185013.19371-1-mreitz@redhat.com

[ kraxel: also update sdl2_2d_check_format() ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ui/sdl2-2d.c

index 85484407bea10c65cba427760b96b01317662dac..091ecfcc7ff20f04109233ceb0cb7341d28e66dc 100644 (file)
@@ -101,15 +101,24 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
     case PIXMAN_r5g6b5:
         format = SDL_PIXELFORMAT_RGB565;
         break;
+    case PIXMAN_a8r8g8b8:
     case PIXMAN_x8r8g8b8:
         format = SDL_PIXELFORMAT_ARGB8888;
         break;
+    case PIXMAN_a8b8g8r8:
+    case PIXMAN_x8b8g8r8:
+        format = SDL_PIXELFORMAT_ABGR8888;
+        break;
+    case PIXMAN_r8g8b8a8:
     case PIXMAN_r8g8b8x8:
         format = SDL_PIXELFORMAT_RGBA8888;
         break;
     case PIXMAN_b8g8r8x8:
         format = SDL_PIXELFORMAT_BGRX8888;
         break;
+    case PIXMAN_b8g8r8a8:
+        format = SDL_PIXELFORMAT_BGRA8888;
+        break;
     default:
         g_assert_not_reached();
     }
@@ -149,7 +158,13 @@ bool sdl2_2d_check_format(DisplayChangeListener *dcl,
      * the native ones. Thes are the ones I have tested.
      */
     return (format == PIXMAN_x8r8g8b8 ||
+            format == PIXMAN_a8r8g8b8 ||
+            format == PIXMAN_a8b8g8r8 ||
+            format == PIXMAN_x8b8g8r8 ||
             format == PIXMAN_b8g8r8x8 ||
+            format == PIXMAN_b8g8r8a8 ||
+            format == PIXMAN_r8g8b8x8 ||
+            format == PIXMAN_r8g8b8a8 ||
             format == PIXMAN_x1r5g5b5 ||
             format == PIXMAN_r5g6b5);
 }
This page took 0.027762 seconds and 4 git commands to generate.