egl: flesh out a _eglNumAttribs() helper
authorEmil Velikov <emil.velikov@collabora.com>
Thu, 16 May 2019 17:01:33 +0000 (18:01 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 5 Jun 2019 17:35:21 +0000 (13:35 -0400)
Reviewed-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/egl/main/eglapi.c
src/egl/main/egldisplay.h

index 61a3220705d72a2a6adeebcef78b2abc5ea6d490..fb26c8a0888322bbc1827d05a64e70b59fc69a60 100644 (file)
@@ -340,22 +340,16 @@ _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list)
 static EGLint *
 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
 {
+   size_t size = _eglNumAttribs(attr_list);
    EGLint *int_attribs = NULL;
 
    /* Convert attributes from EGLAttrib[] to EGLint[] */
-   if (attr_list) {
-      int i, size = 0;
-
-      while (attr_list[size] != EGL_NONE)
-         size += 2;
-
-      size += 1; /* add space for EGL_NONE */
-
+   if (size) {
       int_attribs = calloc(size, sizeof(int_attribs[0]));
       if (!int_attribs)
          return NULL;
 
-      for (i = 0; i < size; i++)
+      for (size_t i = 0; i < size; i++)
          int_attribs[i] = attr_list[i];
    }
    return int_attribs;
index cfd0ff66d6493b36a4d81e0a78f35eb879b4df05..f37b633b4662883363a9a9b466dfa29898a0a360 100644 (file)
@@ -274,6 +274,19 @@ _eglIsResourceLinked(_EGLResource *res)
    return res->IsLinked;
 }
 
+static inline size_t
+_eglNumAttribs(const EGLAttrib *attribs)
+{
+   size_t len = 0;
+
+   if (attribs) {
+      while (attribs[len] != EGL_NONE)
+         len += 2;
+      len++;
+   }
+   return len;
+}
+
 #ifdef HAVE_X11_PLATFORM
 _EGLDisplay*
 _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);