egl: Fix A2RGB10 platform_{device,surfaceless} PBuffer configs.
[mesa.git] / src / egl / drivers / dri2 / platform_x11.c
index 7a58e71849285c32928d5c85f6f854fbb9eb9eb7..ff5dc32c03aa010e760bba8e363e9e968e9adc68 100644 (file)
@@ -42,6 +42,7 @@
 #include <sys/stat.h>
 #include "util/debug.h"
 #include "util/macros.h"
+#include "util/bitscan.h"
 
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
@@ -338,7 +339,7 @@ dri2_x11_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
       }
    } else {
       if (type == EGL_PBUFFER_BIT) {
-         dri2_surf->depth = _eglGetConfigKey(conf, EGL_BUFFER_SIZE);
+         dri2_surf->depth = conf->BufferSize;
       }
       swrastCreateDrawable(dri2_dpy, dri2_surf);
    }
@@ -754,61 +755,9 @@ dri2_x11_authenticate(_EGLDisplay *disp, uint32_t id)
    return dri2_x11_do_authenticate(dri2_dpy, id);
 }
 
-static bool
-dri2_x11_config_match_attrib(struct dri2_egl_display *dri2_dpy,
-                             const __DRIconfig *config,
-                             unsigned int attrib,
-                             unsigned int value)
-{
-   uint32_t config_val;
-   if (!dri2_dpy->core->getConfigAttrib(config, attrib, &config_val))
-      return false;
-   return config_val == value;
-}
-
-/**
- * See if the X server can export a pixmap with the given color depth.
- *
- * Glamor in xorg-server 1.20 can't export pixmaps which have a different
- * color depth than the root window as a DRI image.  This makes it impossible
- * to expose pbuffer-only visuals with, say, 16bpp on a 24bpp X display.
- */
-static bool
-x11_can_export_pixmap_with_bpp(struct dri2_egl_display *dri2_dpy, int bpp)
-{
-   bool supported = false;
-
-#ifdef HAVE_DRI3
-   xcb_dri3_buffer_from_pixmap_cookie_t cookie;
-   xcb_dri3_buffer_from_pixmap_reply_t *reply;
-
-   xcb_pixmap_t pixmap = xcb_generate_id(dri2_dpy->conn);
-   xcb_create_pixmap(dri2_dpy->conn, bpp, pixmap, dri2_dpy->screen->root, 1, 1);
-   cookie = xcb_dri3_buffer_from_pixmap(dri2_dpy->conn, pixmap);
-   reply = xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn, cookie, NULL);
-
-   if (reply) {
-      int *fds = xcb_dri3_buffer_from_pixmap_reply_fds(dri2_dpy->conn, reply);
-
-      for (int i = 0; i < reply->nfd; i++) {
-         close(fds[i]);
-      }
-
-      supported = true;
-
-      free(reply);
-   }
-
-   xcb_free_pixmap(dri2_dpy->conn, pixmap);
-#endif
-
-   return supported;
-}
-
 static EGLBoolean
 dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
-                                 _EGLDisplay *disp, bool supports_preserved,
-                                 bool add_pbuffer_configs)
+                                 _EGLDisplay *disp, bool supports_preserved)
 {
    xcb_depth_iterator_t d;
    xcb_visualtype_t *visuals;
@@ -846,16 +795,23 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
                     EGL_NONE
             };
 
-            unsigned int rgba_masks[4] = {
-               visuals[i].red_mask,
-               visuals[i].green_mask,
-               visuals[i].blue_mask,
+            int rgba_shifts[4] = {
+               ffs(visuals[i].red_mask) - 1,
+               ffs(visuals[i].green_mask) - 1,
+               ffs(visuals[i].blue_mask) - 1,
+               -1,
+            };
+
+            unsigned int rgba_sizes[4] = {
+               util_bitcount(visuals[i].red_mask),
+               util_bitcount(visuals[i].green_mask),
+               util_bitcount(visuals[i].blue_mask),
                0,
             };
 
             dri2_conf = dri2_add_config(disp, config, config_count + 1,
                                         surface_type, config_attrs,
-                                        rgba_masks);
+                                        rgba_shifts, rgba_sizes);
             if (dri2_conf)
                if (dri2_conf->base.ConfigID == config_count + 1)
                   config_count++;
@@ -869,11 +825,14 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
              * wants... especially on drivers that only have 32-bit RGBA
              * EGLConfigs! */
             if (d.data->depth == 24 || d.data->depth == 30) {
-               rgba_masks[3] =
-                  ~(rgba_masks[0] | rgba_masks[1] | rgba_masks[2]);
+               unsigned int rgba_mask = ~(visuals[i].red_mask |
+                                          visuals[i].green_mask |
+                                          visuals[i].blue_mask);
+               rgba_shifts[3] = ffs(rgba_mask) - 1;
+               rgba_sizes[3] = util_bitcount(rgba_mask);
                dri2_conf = dri2_add_config(disp, config, config_count + 1,
                                            surface_type, config_attrs,
-                                           rgba_masks);
+                                           rgba_shifts, rgba_sizes);
                if (dri2_conf)
                   if (dri2_conf->base.ConfigID == config_count + 1)
                      config_count++;
@@ -884,47 +843,6 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
       xcb_depth_next(&d);
    }
 
-   /* Add a 565-no-depth-no-stencil pbuffer-only config.  If X11 is depth 24,
-    * we wouldn't have 565 available, which the CTS demands.
-    */
-   if (add_pbuffer_configs && x11_can_export_pixmap_with_bpp(dri2_dpy, 16)) {
-      for (int j = 0; dri2_dpy->driver_configs[j]; j++) {
-         const __DRIconfig *config = dri2_dpy->driver_configs[j];
-         const EGLint config_attrs[] = {
-            EGL_NATIVE_VISUAL_ID,    0,
-            EGL_NATIVE_VISUAL_TYPE,  EGL_NONE,
-            EGL_NONE
-         };
-         EGLint surface_type = EGL_PBUFFER_BIT;
-         unsigned int rgba_masks[4] = {
-            0x1f << 11,
-            0x3f << 5,
-            0x1f << 0,
-            0,
-         };
-
-         /* Check that we've found single-sample, no depth, no stencil,
-          * and single-buffered.
-          */
-         if (!dri2_x11_config_match_attrib(dri2_dpy, config,
-                                           __DRI_ATTRIB_DEPTH_SIZE, 0) ||
-             !dri2_x11_config_match_attrib(dri2_dpy, config,
-                                           __DRI_ATTRIB_STENCIL_SIZE, 0) ||
-             !dri2_x11_config_match_attrib(dri2_dpy, config,
-                                           __DRI_ATTRIB_SAMPLES, 0) ||
-             !dri2_x11_config_match_attrib(dri2_dpy, config,
-                                           __DRI_ATTRIB_DOUBLE_BUFFER, 0)) {
-            continue;
-         }
-
-         if (dri2_add_config(disp, config, config_count + 1, surface_type,
-                             config_attrs, rgba_masks)) {
-            config_count++;
-            break;
-         }
-      }
-   }
-
    if (!config_count) {
       _eglLog(_EGL_WARNING, "DRI2: failed to create any config");
       return EGL_FALSE;
@@ -1400,7 +1318,7 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
 
    dri2_setup_screen(disp);
 
-   if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, true, false))
+   if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, true))
       goto cleanup;
 
    /* Fill vtbl last to prevent accidentally calling virtual function during
@@ -1498,7 +1416,7 @@ dri2_initialize_x11_dri3(_EGLDriver *drv, _EGLDisplay *disp)
 
    dri2_set_WL_bind_wayland_display(drv, disp);
 
-   if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, false, true))
+   if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, false))
       goto cleanup;
 
    dri2_dpy->loader_dri3_ext.core = dri2_dpy->core;
@@ -1608,7 +1526,7 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
 
    dri2_set_WL_bind_wayland_display(drv, disp);
 
-   if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, true, false))
+   if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, true))
       goto cleanup;
 
    /* Fill vtbl last to prevent accidentally calling virtual function during