[Piglit] [PATCH 11/12] util/dispatch: move "to waffle or not to waffle" decision in the caller

Emil Velikov emil.l.velikov at gmail.com
Tue Aug 12 10:18:51 PDT 2014


piglit-dispatch.c is about to get hairy even without this hunk. Also
moving the code in piglit-dispatch-init.c will allow us to have a clear
visual as we start removing the non-waffle (glut) support.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 tests/util/piglit-dispatch-init.c | 85 ++++++++++++++++++++++++++++++++++++---
 tests/util/piglit-dispatch.c      | 71 --------------------------------
 2 files changed, 80 insertions(+), 76 deletions(-)

diff --git a/tests/util/piglit-dispatch-init.c b/tests/util/piglit-dispatch-init.c
index b27330e..941471f 100644
--- a/tests/util/piglit-dispatch-init.c
+++ b/tests/util/piglit-dispatch-init.c
@@ -41,6 +41,13 @@
 
 #endif
 
+#if defined(PIGLIT_USE_WAFFLE)
+#include <waffle.h>
+#include "piglit-util-waffle.h"
+#include "piglit-framework-gl.h"
+#include "piglit-framework-gl/piglit_wfl_framework.h"
+#endif
+
 /**
  * Generated code calls this function if the test tries to use a GL
  * function that is not supported on the current implementation.
@@ -182,6 +189,50 @@ get_core_proc_address(const char *function_name, int gl_10x_version)
 
 #endif
 
+#ifdef PIGLIT_USE_WAFFLE
+static enum waffle_enum piglit_waffle_dl = WAFFLE_DL_OPENGL;
+
+/**
+ * This function is used to retrieve the address of core GL functions
+ * via the waffle library.
+ */
+static piglit_dispatch_function_ptr
+get_wfl_core_proc(const char *name, int gl_10x_version)
+{
+	piglit_dispatch_function_ptr func = NULL;
+	struct piglit_wfl_framework* wfl_fw;
+
+	wfl_fw = piglit_wfl_framework(gl_fw);
+	if (wfl_fw && wfl_fw->display)
+		func = waffle_dl_sym(wfl_fw->display, piglit_waffle_dl, name);
+
+	if (!func)
+		wfl_log_error(__FUNCTION__);
+
+	return func;
+}
+
+/**
+ * This function is used to retrieve the address of functions not part of the
+ * core GL specification via the waffle library.
+ */
+static piglit_dispatch_function_ptr
+get_wfl_ext_proc(const char *name)
+{
+	piglit_dispatch_function_ptr func = NULL;
+	struct piglit_wfl_framework* wfl_fw;
+
+	wfl_fw = piglit_wfl_framework(gl_fw);
+	if (wfl_fw && wfl_fw->display)
+		func = waffle_get_proc_address(wfl_fw->display, name);
+
+	if (!func)
+		wfl_log_error(__FUNCTION__);
+
+	return func;
+}
+#endif
+
 /**
  * Initialize the GL dispatch mechanism to a default configuration.
  *
@@ -200,11 +251,35 @@ piglit_dispatch_default_init(piglit_dispatch_api api)
 	if (already_initialized)
 		return;
 
-	piglit_dispatch_init(api,
-			     get_core_proc_address,
-			     get_ext_proc_address,
-			     default_unsupported,
-			     default_get_proc_address_failure);
+#ifdef PIGLIT_USE_WAFFLE
+	switch (api) {
+	case PIGLIT_DISPATCH_GL:
+		piglit_waffle_dl = WAFFLE_DL_OPENGL;
+		break;
+	case PIGLIT_DISPATCH_ES1:
+		piglit_waffle_dl = WAFFLE_DL_OPENGL_ES1;
+		break;
+	case PIGLIT_DISPATCH_ES2:
+		piglit_waffle_dl = WAFFLE_DL_OPENGL_ES2;
+		break;
+	}
+
+	if (gl_fw) {
+		piglit_dispatch_init(api,
+				     get_wfl_core_proc,
+				     get_wfl_ext_proc,
+				     default_unsupported,
+				     default_get_proc_address_failure);
+	} else
+#endif
+	{
+
+		piglit_dispatch_init(api,
+				     get_core_proc_address,
+				     get_ext_proc_address,
+				     default_unsupported,
+				     default_get_proc_address_failure);
+	}
 
 	already_initialized = true;
 }
diff --git a/tests/util/piglit-dispatch.c b/tests/util/piglit-dispatch.c
index 602ddf1..90a6dba 100644
--- a/tests/util/piglit-dispatch.c
+++ b/tests/util/piglit-dispatch.c
@@ -23,13 +23,6 @@
 #include "piglit-dispatch.h"
 #include "piglit-util-gl.h"
 
-#if defined(PIGLIT_USE_WAFFLE)
-#include <waffle.h>
-#include "piglit-util-waffle.h"
-#include "piglit-framework-gl.h"
-#include "piglit-framework-gl/piglit_wfl_framework.h"
-#endif
-
 /* Global state maintained by the Piglit dispatch mechanism: */
 
 /**
@@ -87,51 +80,6 @@ check_initialized()
 	exit(1);
 }
 
-#ifdef PIGLIT_USE_WAFFLE
-static enum waffle_enum piglit_waffle_dl = WAFFLE_DL_OPENGL;
-
-/**
- * Generated code calls this function to retrieve the address of a
- * core function.
- */
-static piglit_dispatch_function_ptr
-get_wfl_core_proc(const char *name, int gl_10x_version)
-{
-	piglit_dispatch_function_ptr func = NULL;
-	struct piglit_wfl_framework* wfl_fw;
-
-	wfl_fw = piglit_wfl_framework(gl_fw);
-	if (wfl_fw && wfl_fw->display) {
-		func = (piglit_dispatch_function_ptr)waffle_dl_sym(wfl_fw->display,
-								   piglit_waffle_dl, name);
-	}
-	if (!func)
-		wfl_log_error(__FUNCTION__);
-
-	return func;
-}
-
-/**
- * Generated code calls this function to retrieve the address of a
- * core function.
- */
-static piglit_dispatch_function_ptr
-get_wfl_ext_proc(const char *name)
-{
-	piglit_dispatch_function_ptr func = NULL;
-	struct piglit_wfl_framework* wfl_fw;
-
-	wfl_fw = piglit_wfl_framework(gl_fw);
-	if (wfl_fw && wfl_fw->display) {
-		func = (piglit_dispatch_function_ptr)waffle_get_proc_address(wfl_fw->display, name);
-	}
-	if (!func)
-		wfl_log_error(__FUNCTION__);
-
-	return func;
-}
-#endif
-
 /**
  * Generated code calls this function to retrieve the address of a
  * core function.
@@ -225,25 +173,6 @@ piglit_dispatch_init(piglit_dispatch_api api,
 	unsupported = unsupported_proc;
 	get_proc_address_failure = failure_proc;
 
-#ifdef PIGLIT_USE_WAFFLE
-	switch (api) {
-	case PIGLIT_DISPATCH_GL:
-		piglit_waffle_dl = WAFFLE_DL_OPENGL;
-		break;
-	case PIGLIT_DISPATCH_ES1:
-		piglit_waffle_dl = WAFFLE_DL_OPENGL_ES1;
-		break;
-	case PIGLIT_DISPATCH_ES2:
-		piglit_waffle_dl = WAFFLE_DL_OPENGL_ES2;
-		break;
-	}
-
-	if (gl_fw) {
-		get_core_proc_address = get_wfl_core_proc;
-		get_ext_proc_address = get_wfl_ext_proc;
-	}
-#endif
-
 	/* No need to reset the dispatch pointers the first time */
 	if (is_initialized) {
 		reset_dispatch_pointers();
-- 
2.0.2



More information about the Piglit mailing list