[Piglit] [PATCH v2 1/2] piglit gl: convert gl extension checking to use an array of strings

Jordan Justen jordan.l.justen at intel.com
Wed Sep 19 10:12:44 PDT 2012


This better matches the interface of glGetStringi, which should be used
for GL >= 3.0.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 tests/util/piglit-util-gl-common.c |   52 +++++++++++++++++++++++++++++-------
 tests/util/piglit-util.c           |   15 +++++++++++
 tests/util/piglit-util.h           |   12 +++++++++
 3 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c
index b319197..caa3cce 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -26,13 +26,13 @@
 
 
 /**
- * The GL extension string returned by glGetString(GL_EXTENSIONS).
+ * An array of pointers to extension strings.
  *
- * We cache this here because calling glGetString is prohibited
- * between glBegin and glEnd, and to avoid the inefficiency of
- * redundant glGetString queries.
+ * Each extension is pointed to by a separate entry in the array.
+ *
+ * The end of the array is indicated by a NULL pointer.
  */
-static const char *gl_extensions = NULL;
+static const char **gl_extensions = NULL;
 
 bool piglit_is_gles()
 {
@@ -62,13 +62,47 @@ int piglit_get_gl_version()
 	return 10*major+minor;
 }
 
-bool piglit_is_extension_supported(const char *name)
+static const char** split_string(const char *string)
+{
+	char **strings, *string_copy;
+	int i, length, max_words;
+
+	length = strlen(string);
+	max_words = length / 2;
+	strings = malloc ((sizeof(char*) * (max_words + 1)) +
+	                  (sizeof(char) * (length + 1)));
+	assert (strings != NULL);
+
+	string_copy = (char*) &strings[max_words + 1];
+	strcpy(string_copy, string);
+
+	strings[0] = strtok(string_copy, " ");
+	for (i = 0; strings[i] != NULL; ++i)
+		strings[i + 1] = strtok(NULL, " ");
+
+	return (const char**) strings;
+}
+
+static const char** gl_extension_array_from_getstring()
+{
+	const char *gl_extensions_string;
+	gl_extensions_string = (const char *) glGetString(GL_EXTENSIONS);
+	return split_string(gl_extensions_string);
+}
+
+static void initialize_piglit_extension_support(void)
 {
-	if (gl_extensions == NULL) {
-		gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
+	if (gl_extensions != NULL) {
+		return;
 	}
 
-	return piglit_is_extension_in_string(gl_extensions, name);
+	gl_extensions = gl_extension_array_from_getstring();
+}
+
+bool piglit_is_extension_supported(const char *name)
+{
+	initialize_piglit_extension_support();
+	return piglit_is_extension_in_array(gl_extensions, name);
 }
 
 void piglit_require_gl_version(int required_version_times_10)
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 891ae22..411d69c 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -101,6 +101,21 @@ int asprintf(char **strp, const char *fmt, ...)
 
 #endif /* _WIN32 */
 
+bool piglit_is_extension_in_array(const char **haystack, const char *needle)
+{
+	if (needle[0] == 0)
+		return false;
+
+	while (*haystack != NULL) {
+		if (strcmp(*haystack, needle) == 0) {
+			return true;
+		}
+		haystack++;
+	}
+
+	return false;
+}
+
 bool piglit_is_extension_in_string(const char *haystack, const char *needle)
 {
 	const unsigned needle_len = strlen(needle);
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 269a590..a66cb03 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -114,6 +114,18 @@ enum piglit_result {
  */
 bool piglit_is_extension_in_string(const char *haystack, const char *needle);
 
+/**
+ * Determine if an extension is listed in an extension string array
+ *
+ * \param haystack   Array of all extensions to be searched
+ * \param needle     Extension whose presens is to be detected
+ *
+ * \precondition \c haystack is not null
+ *
+ * \sa piglit_is_extension_supported, piglit_is_glx_extension_supported
+ */
+bool piglit_is_extension_in_array(const char **haystack, const char *needle);
+
 int FindLine(const char *program, int position);
 void piglit_merge_result(enum piglit_result *all, enum piglit_result subtest);
 void piglit_report_result(enum piglit_result result);
-- 
1.7.9.5



More information about the Piglit mailing list