[Mesa-dev] [PATCH 15/18] egl/gbm: Remove duplicate format table

Daniel Stone daniels at collabora.com
Thu Feb 8 13:55:39 UTC 2018


Now that we have mask/channel information in gbm_dri's format conversion
table, we can remove the copy in EGL.

As this table contains more formats (notably including R8 and RG8, which
can be used for BO but not surface allocation), we now compare the masks
of all channels when trying to find a suitable config. Without doing
this, an XRGB8888 EGLConfig would match on an R8 format.

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 src/egl/drivers/dri2/platform_drm.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 6e7403d9ab2..94b5be026c8 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -572,37 +572,36 @@ static EGLBoolean
 drm_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-   static const struct {
-      int format;
-      unsigned int red_mask;
-      unsigned int alpha_mask;
-   } visuals[] = {
-      { GBM_FORMAT_XRGB2101010, 0x3ff00000, 0x00000000 },
-      { GBM_FORMAT_ARGB2101010, 0x3ff00000, 0xc0000000 },
-      { GBM_FORMAT_XRGB8888,    0x00ff0000, 0x00000000 },
-      { GBM_FORMAT_ARGB8888,    0x00ff0000, 0xff000000 },
-      { GBM_FORMAT_RGB565,      0x0000f800, 0x00000000 },
-   };
-
-   unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
+   const struct gbm_dri_visual *visuals = dri2_dpy->gbm_dri->visual_table;
+   int num_visuals = dri2_dpy->gbm_dri->num_visuals;
+   unsigned int format_count[num_visuals];
    unsigned int config_count = 0;
 
+   memset(format_count, 0, num_visuals * sizeof(unsigned int));
+
    for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) {
-      unsigned int red, alpha;
+      unsigned int red, green, blue, alpha;
 
       dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
                                       __DRI_ATTRIB_RED_MASK, &red);
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_GREEN_MASK, &green);
+      dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+                                      __DRI_ATTRIB_BLUE_MASK, &blue);
       dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
                                       __DRI_ATTRIB_ALPHA_MASK, &alpha);
 
-      for (unsigned j = 0; j < ARRAY_SIZE(visuals); j++) {
+      for (unsigned j = 0; j < num_visuals; j++) {
          struct dri2_egl_config *dri2_conf;
 
-         if (visuals[j].red_mask != red || visuals[j].alpha_mask != alpha)
+         if (visuals[j].rgba_masks[0] != red ||
+             visuals[j].rgba_masks[1] != green ||
+             visuals[j].rgba_masks[2] != blue ||
+	     visuals[j].rgba_masks[3] != alpha)
             continue;
 
          const EGLint attr_list[] = {
-            EGL_NATIVE_VISUAL_ID,  visuals[j].format,
+            EGL_NATIVE_VISUAL_ID, visuals[j].gbm_format,
             EGL_NONE,
          };
 
@@ -619,7 +618,7 @@ drm_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
    for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) {
       if (!format_count[i]) {
          _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x",
-                 visuals[i].format);
+                 visuals[i].gbm_format);
       }
    }
 
-- 
2.14.3



More information about the mesa-dev mailing list