glx/extensions: split set_glx_extension into find_ and set_
authorMartin Peres <martin.peres@mupuf.org>
Thu, 15 Oct 2020 05:47:50 +0000 (08:47 +0300)
committerMartin Peres <martin.peres@mupuf.org>
Thu, 22 Oct 2020 04:47:28 +0000 (07:47 +0300)
An upcoming commit will require to find an extension in a list. Rather
than duplicating part of the code from set_glx_extension, split it into
find_extension and set_glx_extension.

NOTE: set_glx_extension is a bit of a misnomer since it is also used
for gl extensions. This is why the find function is named
find_extension rather than find_glx_extension.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Signed-off-by: Martin Peres <martin.peres@mupuf.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7212>

src/glx/glxextensions.c

index f4d3807..82fd2c8 100644 (file)
@@ -352,34 +352,50 @@ static void __glXProcessServerString(const struct extension_info *ext,
                                      unsigned char *server_support);
 
 /**
- * Set the state of a GLX extension.
+ * Find an extension in the list based on its name.
  *
+ * \param ext       List of extensions where to search.
  * \param name      Name of the extension.
  * \param name_len  Length, in characters, of the extension name.
- * \param state     New state (either enabled or disabled) of the extension.
- * \param supported Table in which the state of the extension is to be set.
  */
-static void
-set_glx_extension(const struct extension_info *ext,
-                  const char *name, unsigned name_len, GLboolean state,
-                  unsigned char *supported)
+static const struct extension_info *
+find_extension(const struct extension_info *ext, const char *name,
+               unsigned name_len)
 {
    unsigned i;
 
-
    for (i = 0; ext[i].name != NULL; i++) {
       if ((name_len == ext[i].name_len)
           && (strncmp(ext[i].name, name, name_len) == 0)) {
-         if (state) {
-            SET_BIT(supported, ext[i].bit);
-         }
-         else {
-            CLR_BIT(supported, ext[i].bit);
-         }
-
-         return;
+         return &ext[i];
       }
    }
+
+   return NULL;
+}
+
+/**
+ * Set the state of a GLX extension.
+ *
+ * \param name      Name of the extension.
+ * \param name_len  Length, in characters, of the extension name.
+ * \param state     New state (either enabled or disabled) of the extension.
+ * \param supported Table in which the state of the extension is to be set.
+ */
+static void
+set_glx_extension(const struct extension_info *ext_list,
+                  const char *name, unsigned name_len, GLboolean state,
+                  unsigned char *supported)
+{
+   const struct extension_info *ext = find_extension(ext_list, name, name_len);
+   if (!ext)
+       return;
+
+   if (state) {
+      SET_BIT(supported, ext->bit);
+   } else {
+      CLR_BIT(supported, ext->bit);
+   }
 }