[Mesa-dev] [PATCH 2/9] egl: handle the full attrib list in display::options

Emil Velikov emil.l.velikov at gmail.com
Mon May 6 15:01:25 UTC 2019


From: Adam Jackson <ajax at redhat.com>

Earlier spec is vague, although EGL 1.5 makes it clear:

     Multiple calls made to eglGetPlatformDisplay with the same
     parameters will return the same EGLDisplay handle.

With this commit we store and compare the full attrib list.

v2 (Emil):
 - Split into separate patches
 - Use EGLBoolean over int masked as such
 - Don't return free'd pointed on calloc failure

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/egl/main/eglapi.c     |  2 +-
 src/egl/main/egldisplay.c | 61 +++++++++++++++++++++++++++++++++------
 src/egl/main/egldisplay.h |  3 +-
 3 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 4481eb9cd0f..f77df8ff437 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -373,7 +373,7 @@ eglGetDisplay(EGLNativeDisplayType nativeDisplay)
    native_display_ptr = (void*) nativeDisplay;
 
    plat = _eglGetNativePlatform(native_display_ptr);
-   disp = _eglFindDisplay(plat, native_display_ptr);
+   disp = _eglFindDisplay(plat, native_display_ptr, NULL);
    return _eglGetDisplayHandle(disp);
 }
 
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index ba5f84510fe..9a2ac48e8bc 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -202,20 +202,49 @@ _eglFiniDisplay(void)
          }
       }
 
+      free(disp->Options.Attribs);
       free(disp);
    }
    _eglGlobal.DisplayList = NULL;
 }
 
+static EGLBoolean
+_eglSameAttribs(const EGLAttrib *a, const EGLAttrib *b)
+{
+   size_t na = _eglNumAttribs(a);
+   size_t nb = _eglNumAttribs(b);
+
+   /* different numbers of attributes must be different */
+   if (na != nb)
+      return EGL_FALSE;
+
+   /* both lists NULL are the same */
+   if (!a && !b)
+      return EGL_TRUE;
+
+   /* otherwise, compare the lists */
+   return memcmp(a, b, na) == 0 ? EGL_TRUE : EGL_FALSE;
+}
 
 /**
  * Find the display corresponding to the specified native display, or create a
- * new one.
+ * new one. EGL 1.5 says:
+ *
+ *     Multiple calls made to eglGetPlatformDisplay with the same parameters
+ *     will return the same EGLDisplay handle.
+ *
+ * We read this extremely strictly, and treat a call with NULL attribs as
+ * different from a call with attribs only equal to { EGL_NONE }. Similarly
+ * we do not sort the attribute list, so even if all attribute _values_ are
+ * identical, different attribute orders will be considered different
+ * parameters.
  */
 _EGLDisplay *
-_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
+_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy,
+                const EGLAttrib *attrib_list)
 {
    _EGLDisplay *disp;
+   size_t num_attribs;
 
    if (plat == _EGL_INVALID_PLATFORM)
       return NULL;
@@ -225,7 +254,8 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
    /* search the display list first */
    disp = _eglGlobal.DisplayList;
    while (disp) {
-      if (disp->Platform == plat && disp->PlatformDisplay == plat_dpy)
+      if (disp->Platform == plat && disp->PlatformDisplay == plat_dpy &&
+          _eglSameAttribs(disp->Options.Attribs, attrib_list))
          break;
       disp = disp->Next;
    }
@@ -237,13 +267,24 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
          mtx_init(&disp->Mutex, mtx_plain);
          disp->Platform = plat;
          disp->PlatformDisplay = plat_dpy;
-
-         /* add to the display list */ 
+         num_attribs = _eglNumAttribs(attrib_list);
+         if (num_attribs) {
+            disp->Options.Attribs = calloc(num_attribs, sizeof(EGLAttrib));
+            if (!disp->Options.Attribs) {
+               free(disp);
+               disp = NULL;
+               goto out;
+            }
+            memcpy(disp->Options.Attribs, attrib_list,
+                   num_attribs * sizeof(EGLAttrib));
+         }
+         /* add to the display list */
          disp->Next = _eglGlobal.DisplayList;
          _eglGlobal.DisplayList = disp;
       }
    }
 
+out:
    mtx_unlock(_eglGlobal.Mutex);
 
    return disp;
@@ -477,7 +518,8 @@ _eglGetX11Display(Display *native_display,
                   const EGLAttrib *attrib_list)
 {
    _EGLDisplay *display = _eglFindDisplay(_EGL_PLATFORM_X11,
-                                          native_display);
+                                          native_display,
+                                          attrib_list);
 
    if (!display) {
       _eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
@@ -503,7 +545,7 @@ _eglGetGbmDisplay(struct gbm_device *native_display,
       return NULL;
    }
 
-   return _eglFindDisplay(_EGL_PLATFORM_DRM, native_display);
+   return _eglFindDisplay(_EGL_PLATFORM_DRM, native_display, attrib_list);
 }
 #endif /* HAVE_DRM_PLATFORM */
 
@@ -518,7 +560,7 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
       return NULL;
    }
 
-   return _eglFindDisplay(_EGL_PLATFORM_WAYLAND, native_display);
+   return _eglFindDisplay(_EGL_PLATFORM_WAYLAND, native_display, attrib_list);
 }
 #endif /* HAVE_WAYLAND_PLATFORM */
 
@@ -539,6 +581,7 @@ _eglGetSurfacelessDisplay(void *native_display,
       return NULL;
    }
 
-   return _eglFindDisplay(_EGL_PLATFORM_SURFACELESS, native_display);
+   return _eglFindDisplay(_EGL_PLATFORM_SURFACELESS, native_display,
+                          attrib_list);
 }
 #endif /* HAVE_SURFACELESS_PLATFORM */
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index f37b633b466..2c9fd6c3399 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -168,6 +168,7 @@ struct _egl_display
    struct {
       EGLBoolean ForceSoftware; /**< Use software path only */
       void *Platform;         /**< Platform-specific options */
+      EGLAttrib *Attribs;     /**< Platform-specific options */
    } Options;
 
    /* these fields are set by the driver during init */
@@ -202,7 +203,7 @@ _eglFiniDisplay(void);
 
 
 extern _EGLDisplay *
-_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy);
+_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr);
 
 
 extern void
-- 
2.21.0



More information about the mesa-dev mailing list