[Mesa-dev] [PATCH 4/7] egl: Add _eglConvertIntsToAttribs()

Chad Versace chadversary at chromium.org
Wed Sep 28 06:28:06 UTC 2016


This function converts an attribute list from EGLint[] to EGLAttrib[].
Will be used in following patches to cleanup EGLSync attribute parsing.
---
 src/egl/main/eglapi.c | 41 +++++++++++++++++++++++++++++++++++++++++
 src/egl/main/eglapi.h |  2 ++
 2 files changed, 43 insertions(+)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 07f6794..697957e 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -251,6 +251,47 @@ _eglUnlockDisplay(_EGLDisplay *dpy)
 }
 
 
+/**
+ * Convert an attribute list from EGLint[] to EGLAttrib[].
+ *
+ * Return an EGL error code. The output parameter out_attrib_list is modified
+ * only on success.
+ */
+EGLint
+_eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list)
+{
+   size_t len = 0;
+   EGLAttrib *attrib_list;
+
+   if (int_list) {
+      while (int_list[2*len] != EGL_NONE)
+         ++len;
+   }
+
+   if (len == 0) {
+      *out_attrib_list = NULL;
+      return EGL_SUCCESS;
+   }
+
+   if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib))
+      return EGL_BAD_ALLOC;
+
+   attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib));
+   if (!attrib_list)
+      return EGL_BAD_ALLOC;
+
+   for (size_t i = 0; i < len; ++i) {
+      attrib_list[2*i + 0] = int_list[2*i + 0];
+      attrib_list[2*i + 1] = int_list[2*i + 1];
+   }
+
+   attrib_list[2*len] = EGL_NONE;
+
+   *out_attrib_list = attrib_list;
+   return EGL_SUCCESS;
+}
+
+
 static EGLint *
 _eglConvertAttribsToInt(const EGLAttrib *attr_list)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 2d6a24f..5d9c1b8 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -199,6 +199,8 @@ struct _egl_api
                                 struct mesa_glinterop_export_out *out);
 };
 
+EGLint _eglConvertIntsToAttribs(const EGLint *int_list,
+                                EGLAttrib **out_attrib_list);
 
 #ifdef __cplusplus
 }
-- 
2.10.0



More information about the mesa-dev mailing list