Mir: Do not use opengl to find the valid pixel format if we dont use opengl
authorBrandon Schaefer <brandon.schaefer@canonical.com>
Thu, 25 Feb 2016 10:06:33 -0800
changeset 10095 0897c3accd52
parent 10094 fdfdae3f6039
child 10096 330f500d5815
Mir: Do not use opengl to find the valid pixel format if we dont use opengl
src/video/mir/SDL_mirwindow.c
--- a/src/video/mir/SDL_mirwindow.c	Wed Feb 24 21:07:19 2016 +0100
+++ b/src/video/mir/SDL_mirwindow.c	Thu Feb 25 10:06:33 2016 -0800
@@ -46,6 +46,32 @@
     return 0;
 }
 
+MirPixelFormat
+FindValidPixelFormat(MIR_Data* mir_data)
+{
+    unsigned int pf_size = 32;
+    unsigned int valid_formats;
+    unsigned int f;
+
+    MirPixelFormat formats[pf_size];
+    MIR_mir_connection_get_available_surface_formats(mir_data->connection, formats,
+                                                     pf_size, &valid_formats);
+
+    for (f = 0; f < valid_formats; f++) {
+        MirPixelFormat cur_pf = formats[f];
+
+        if (cur_pf == mir_pixel_format_abgr_8888 ||
+            cur_pf == mir_pixel_format_xbgr_8888 ||
+            cur_pf == mir_pixel_format_argb_8888 ||
+            cur_pf == mir_pixel_format_xrgb_8888) {
+
+            return cur_pf;
+        }
+    }
+
+    return mir_pixel_format_invalid;
+}
+
 int
 MIR_CreateWindow(_THIS, SDL_Window* window)
 {
@@ -72,9 +98,14 @@
     mir_window->mir_data = mir_data;
     mir_window->sdl_window = window;
 
-    pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
-                                                           _this->egl_data->egl_display,
-                                                           _this->egl_data->egl_config);
+    if (window->flags & SDL_WINDOW_OPENGL) {
+        pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
+                                                               _this->egl_data->egl_display,
+                                                               _this->egl_data->egl_config);
+    }
+    else {
+        pixel_format = FindValidPixelFormat(mir_data);
+    }
 
     mir_data->pixel_format = pixel_format;
     if (pixel_format == mir_pixel_format_invalid) {