aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamey Sharp <jamey@minilop.net>2014-04-18 11:39:31 -0700
committerEric Anholt <eric@anholt.net>2014-10-10 17:26:53 +0200
commita5d33065cb99562f60cf46436a950bf08c73d0af (patch)
tree0bd08f27821339894743a13a73e800a788a16e43
parentfff28f4c7d7e7c4c959f918078473bff92efaf70 (diff)
downloadpiglit-a5d33065cb99562f60cf46436a950bf08c73d0af.tar.gz
Simplify piglit_glx_get_all_proc_addresses API.
I couldn't stand the number of ways this API could be misused and the amount of code duplication it forced--two closely related issues. This also fixes a bug: The "Failed to get function pointer" test could never have triggered unless the caller passed incorrect arguments, which is not the kind of error it was intended to be testing for. Signed-off-by: Jamey Sharp <jamey@minilop.net> Reviewed-by: Eric Anholt <eric@anholt.net>
-rw-r--r--tests/spec/glx_ext_import_context/common.c27
-rw-r--r--tests/spec/glx_oml_sync_control/common.c30
-rw-r--r--tests/spec/glx_oml_sync_control/common.h10
-rw-r--r--tests/util/piglit-glx-util.c11
-rw-r--r--tests/util/piglit-glx-util.h10
5 files changed, 39 insertions, 49 deletions
diff --git a/tests/spec/glx_ext_import_context/common.c b/tests/spec/glx_ext_import_context/common.c
index 00bed7474..444e9e858 100644
--- a/tests/spec/glx_ext_import_context/common.c
+++ b/tests/spec/glx_ext_import_context/common.c
@@ -31,6 +31,15 @@ PFNGLXGETCONTEXTIDEXTPROC __piglit_glXGetContextIDEXT = NULL;
PFNGLXIMPORTCONTEXTEXTPROC __piglit_glXImportContextEXT = NULL;
PFNGLXFREECONTEXTEXTPROC __piglit_glXFreeContextEXT = NULL;
+#define ADD_FUNC(name) PIGLIT_GLX_PROC(__piglit_##name, name)
+static const struct piglit_glx_proc_reference procedures[] = {
+ ADD_FUNC(glXGetCurrentDisplayEXT),
+ ADD_FUNC(glXQueryContextInfoEXT),
+ ADD_FUNC(glXGetContextIDEXT),
+ ADD_FUNC(glXImportContextEXT),
+ ADD_FUNC(glXFreeContextEXT),
+};
+
Display *dpy = NULL;
XVisualInfo *visinfo = NULL;
GLXContext directCtx = NULL;
@@ -63,22 +72,6 @@ void GLX_EXT_import_context_setup_for_child(void)
void GLX_EXT_import_context_setup(void)
{
- const char *const names[] = {
- "glXGetCurrentDisplayEXT",
- "glXQueryContextInfoEXT",
- "glXGetContextIDEXT",
- "glXImportContextEXT",
- "glXFreeContextEXT"
- };
-
- __GLXextFuncPtr *procedures[ARRAY_SIZE(names)] = {
- (__GLXextFuncPtr *) & __piglit_glXGetCurrentDisplayEXT,
- (__GLXextFuncPtr *) & __piglit_glXQueryContextInfoEXT,
- (__GLXextFuncPtr *) & __piglit_glXGetContextIDEXT,
- (__GLXextFuncPtr *) & __piglit_glXImportContextEXT,
- (__GLXextFuncPtr *) & __piglit_glXFreeContextEXT
- };
-
const char *vendor;
dpy = piglit_get_glx_display();
@@ -113,7 +106,7 @@ void GLX_EXT_import_context_setup(void)
piglit_require_glx_extension(dpy, "GLX_EXT_import_context");
}
- piglit_glx_get_all_proc_addresses(procedures, names, ARRAY_SIZE(names));
+ piglit_glx_get_all_proc_addresses(procedures, ARRAY_SIZE(procedures));
visinfo = piglit_get_glx_visual(dpy);
diff --git a/tests/spec/glx_oml_sync_control/common.c b/tests/spec/glx_oml_sync_control/common.c
index 58c25c7cb..2b2f5a10e 100644
--- a/tests/spec/glx_oml_sync_control/common.c
+++ b/tests/spec/glx_oml_sync_control/common.c
@@ -39,6 +39,16 @@ PFNGLXGETMSCRATEOMLPROC __piglit_glXGetMscRateOML;
PFNGLXSWAPBUFFERSMSCOMLPROC __piglit_glXSwapBuffersMscOML;
PFNGLXWAITFORMSCOMLPROC __piglit_glXWaitForMscOML;
PFNGLXWAITFORSBCOMLPROC __piglit_glXWaitForSbcOML;
+
+#define ADD_FUNC(name) PIGLIT_GLX_PROC(__piglit_##name, name)
+static const struct piglit_glx_proc_reference procs[] = {
+ ADD_FUNC(glXGetSyncValuesOML),
+ ADD_FUNC(glXGetMscRateOML),
+ ADD_FUNC(glXSwapBuffersMscOML),
+ ADD_FUNC(glXWaitForMscOML),
+ ADD_FUNC(glXWaitForSbcOML),
+};
+
Window win;
XVisualInfo *visinfo;
@@ -47,24 +57,6 @@ piglit_oml_sync_control_test_run(enum piglit_result (*draw)(Display *dpy))
{
Display *dpy;
GLXContext ctx;
- const int proc_count = 5;
- __GLXextFuncPtr *procs[proc_count];
- const char *names[proc_count];
- int i;
-
-#define ADD_FUNC(name) \
- do { \
- procs[i] = (__GLXextFuncPtr *)&(__piglit_##name); \
- names[i] = #name; \
- i++; \
- } while (0)
-
- i = 0;
- ADD_FUNC(glXGetSyncValuesOML);
- ADD_FUNC(glXGetMscRateOML);
- ADD_FUNC(glXSwapBuffersMscOML);
- ADD_FUNC(glXWaitForMscOML);
- ADD_FUNC(glXWaitForSbcOML);
dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
@@ -73,7 +65,7 @@ piglit_oml_sync_control_test_run(enum piglit_result (*draw)(Display *dpy))
}
piglit_require_glx_extension(dpy, "GLX_OML_sync_control");
- piglit_glx_get_all_proc_addresses(procs, names, ARRAY_SIZE(procs));
+ piglit_glx_get_all_proc_addresses(procs, ARRAY_SIZE(procs));
visinfo = piglit_get_glx_visual(dpy);
win = piglit_get_glx_window(dpy, visinfo);
diff --git a/tests/spec/glx_oml_sync_control/common.h b/tests/spec/glx_oml_sync_control/common.h
index c06bdd7b8..40ef4a3e9 100644
--- a/tests/spec/glx_oml_sync_control/common.h
+++ b/tests/spec/glx_oml_sync_control/common.h
@@ -1,8 +1,8 @@
-#define glXGetSyncValuesOML __piglit_glXGetSyncValuesOML
-#define glXGetMscRateOML __piglit_glXGetMscRateOML
-#define glXSwapBuffersMscOML __piglit_glXSwapBuffersMscOML
-#define glXWaitForMscOML __piglit_glXWaitForMscOML
-#define glXWaitForSbcOML __piglit_glXWaitForSbcOML
+#define glXGetSyncValuesOML(dpy, drawable, ust, msc, sbc) __piglit_glXGetSyncValuesOML(dpy, drawable, ust, msc, sbc)
+#define glXGetMscRateOML(dpy, drawable, numerator, denominator) __piglit_glXGetMscRateOML(dpy, drawable, numerator, denominator)
+#define glXSwapBuffersMscOML(dpy, drawable, target_msc, divisor, remainder) __piglit_glXSwapBuffersMscOML(dpy, drawable, target_msc, divisor, remainder)
+#define glXWaitForMscOML(dpy, drawable, target_msc, divisor, remainder, ust, msc, sbc) __piglit_glXWaitForMscOML(dpy, drawable, target_msc, divisor, remainder, ust, msc, sbc)
+#define glXWaitForSbcOML(dpy, drawable, target_sbc, ust, msc, sbc) __piglit_glXWaitForSbcOML(dpy, drawable, target_sbc, ust, msc, sbc)
extern PFNGLXGETSYNCVALUESOMLPROC __piglit_glXGetSyncValuesOML;
extern PFNGLXGETMSCRATEOMLPROC __piglit_glXGetMscRateOML;
diff --git a/tests/util/piglit-glx-util.c b/tests/util/piglit-glx-util.c
index 39a6abb10..807d8ffa8 100644
--- a/tests/util/piglit-glx-util.c
+++ b/tests/util/piglit-glx-util.c
@@ -468,19 +468,18 @@ piglit_glx_error_string(int err)
* \c piglit_report_result with \c PIGLIT_FAIL.
*/
void
-piglit_glx_get_all_proc_addresses(__GLXextFuncPtr **procedures,
- const char *const *names,
+piglit_glx_get_all_proc_addresses(const struct piglit_glx_proc_reference *procedures,
unsigned num)
{
unsigned i;
for (i = 0; i < num; i++) {
- *(procedures[i]) =
- glXGetProcAddress((const GLubyte *) names[i]);
- if (procedures[i] == NULL) {
+ *procedures[i].procedure =
+ glXGetProcAddress((const GLubyte *) procedures[i].name);
+ if (*procedures[i].procedure == NULL) {
fprintf(stderr,
"Failed to get function pointer for %s.\n",
- names[i]);
+ procedures[i].name);
piglit_report_result(PIGLIT_FAIL);
}
}
diff --git a/tests/util/piglit-glx-util.h b/tests/util/piglit-glx-util.h
index e74ac29bf..aebed1534 100644
--- a/tests/util/piglit-glx-util.h
+++ b/tests/util/piglit-glx-util.h
@@ -65,7 +65,13 @@ piglit_glx_get_error(Display *dpy, XErrorEvent *err);
const char *
piglit_glx_error_string(int err);
+struct piglit_glx_proc_reference {
+ __GLXextFuncPtr *procedure;
+ const char *name;
+};
+
+#define PIGLIT_GLX_PROC(var, name) { (__GLXextFuncPtr *)&(var), #name }
+
void
-piglit_glx_get_all_proc_addresses(__GLXextFuncPtr **procedures,
- const char *const *names,
+piglit_glx_get_all_proc_addresses(const struct piglit_glx_proc_reference *procedures,
unsigned num);