If the CMake option USE_WAFFLE is enabled, then use Waffle for the piglit_framework_fbo code module. Otherwise, use GLX.
As a side effect, this adds support for running "-fbo" tests under X11/EGL and Wayland. Signed-off-by: Chad Versace <[email protected]> --- tests/util/CMakeLists.gl.txt | 4 + tests/util/CMakeLists.gles1.txt | 6 ++ tests/util/CMakeLists.gles2.txt | 6 ++ tests/util/piglit-framework-fbo.c | 153 +++++++++++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+) diff --git a/tests/util/CMakeLists.gl.txt b/tests/util/CMakeLists.gl.txt index 90c773c..9c3a7d4 100644 --- a/tests/util/CMakeLists.gl.txt +++ b/tests/util/CMakeLists.gl.txt @@ -49,4 +49,8 @@ if(UNIX) target_link_libraries(piglitutil m) endif(UNIX) +if(USE_WAFFLE) + target_link_libraries(piglitutil "${WAFFLE_waffle_LIBRARY}") +endif(USE_WAFFLE) + # vim: ft=cmake: diff --git a/tests/util/CMakeLists.gles1.txt b/tests/util/CMakeLists.gles1.txt index 9e4263a..5f568f5 100644 --- a/tests/util/CMakeLists.gles1.txt +++ b/tests/util/CMakeLists.gles1.txt @@ -17,4 +17,10 @@ if(UNIX) target_link_libraries(piglitutil_${piglit_target_api} m) endif(UNIX) +if(USE_WAFFLE) + target_link_libraries(piglitutil_${piglit_target_api} + "${WAFFLE_waffle_LIBRARY}" + ) +endif(USE_WAFFLE) + # vim: ft=cmake: diff --git a/tests/util/CMakeLists.gles2.txt b/tests/util/CMakeLists.gles2.txt index 274ce4c..40e4b78 100644 --- a/tests/util/CMakeLists.gles2.txt +++ b/tests/util/CMakeLists.gles2.txt @@ -19,4 +19,10 @@ if(UNIX) target_link_libraries(piglitutil_${piglit_target_api} m) endif(UNIX) +if(USE_WAFFLE) + target_link_libraries(piglitutil_${piglit_target_api} + "${WAFFLE_waffle_LIBRARY}" + ) +endif(USE_WAFFLE) + # vim: ft=cmake: diff --git a/tests/util/piglit-framework-fbo.c b/tests/util/piglit-framework-fbo.c index eaf3de6..9dfceec 100644 --- a/tests/util/piglit-framework-fbo.c +++ b/tests/util/piglit-framework-fbo.c @@ -23,6 +23,8 @@ #if defined(USE_OPENGL_ES1) # define PIGLIT_FRAMEWORK_FBO_DISABLED +#elif defined(USE_WAFFLE) +# define PIGLIT_FRAMEWORK_FBO_USE_WAFFLE #elif defined(USE_GLX) # define PIGLIT_FRAMEWORK_FBO_USE_GLX #else @@ -43,6 +45,10 @@ #include "piglit-glx-util.h" #endif +#ifdef PIGLIT_FRAMEWORK_FBO_USE_WAFFLE +#include <waffle/waffle.h> +#endif + bool piglit_use_fbo = false; #ifdef PIGLIT_FRAMEWORK_FBO_USE_GLX @@ -52,6 +58,12 @@ XVisualInfo *piglit_glx_visinfo; GLXContext piglit_glx_context; #endif +#ifdef PIGLIT_FRAMEWORK_FBO_USE_WAFFLE +static struct waffle_display *piglit_waffle_display; +static struct waffle_window *piglit_waffle_window; +static struct waffle_context *piglit_waffle_context; +#endif + #ifdef PIGLIT_FRAMEWORK_FBO_USE_GLX static void piglit_framework_fbo_glx_init(void) @@ -82,6 +94,143 @@ piglit_framework_fbo_glx_destroy(void) } #endif +#ifdef PIGLIT_FRAMEWORK_FBO_USE_WAFFLE +/** + * \brief Print a description of the Waffle error and report test failure. + * + * The \a func_name is the name of the Waffle function that failed. + */ +static void +fatal_waffle_error(const char *func_name) +{ + int32_t error_code; + const char *error_name; + const char *message; + size_t message_length; + + waffle_error_get_info(&error_code, &message, &message_length); + error_name = waffle_error_to_string(error_code); + + fflush(stdout); + fprintf(stderr, "%s failed with error: %s", func_name, error_name); + if (message_length > 0) + fprintf(stderr, ": %s", message); + fprintf(stderr, "\n"); + + piglit_report_result(PIGLIT_FAIL); +} + +static void +piglit_framework_fbo_waffle_init(void) +{ + int i; + bool ok = true; + const char *env_platform; + int32_t waffle_platform; + int32_t waffle_context_api; + int32_t init_attrib_list[64]; + int32_t config_attrib_list[64]; + struct waffle_config *config; + + env_platform = getenv("WAFFLE_PLATFORM"); + + if (env_platform == NULL) { + waffle_platform = WAFFLE_PLATFORM_GLX; + } else if (!strcmp(env_platform, "glx")) { + waffle_platform = WAFFLE_PLATFORM_GLX; + } else if (!strcmp(env_platform, "x11_egl")) { + waffle_platform = WAFFLE_PLATFORM_X11_EGL; + } else if (!strcmp(env_platform, "wayland")) { + waffle_platform = WAFFLE_PLATFORM_WAYLAND; + } else { + fprintf(stderr, "environment var WAFFLE_PLATFORM has bad " + "value \"%s\"", env_platform); + } + +#if defined(USE_OPENGL) + waffle_context_api = WAFFLE_CONTEXT_OPENGL; +#elif defined(USE_OPENGL_ES1) + waffle_context_api = WAFFLE_CONTEXT_OPENGL_ES1; +#elif defined(USE_OPENGL_ES2) + waffle_context_api = WAFFLE_CONTEXT_OPENGL_ES2; +#else +# error +#endif + i = 0; + init_attrib_list[i++] = WAFFLE_PLATFORM; + init_attrib_list[i++] = waffle_platform; + init_attrib_list[i++] = WAFFLE_NONE; + + i = 0; + config_attrib_list[i++] = WAFFLE_CONTEXT_API; + config_attrib_list[i++] = waffle_context_api; + config_attrib_list[i++] = WAFFLE_RED_SIZE; + config_attrib_list[i++] = 1; + config_attrib_list[i++] = WAFFLE_GREEN_SIZE; + config_attrib_list[i++] = 1; + config_attrib_list[i++] = WAFFLE_BLUE_SIZE; + config_attrib_list[i++] = 1; + config_attrib_list[i++] = WAFFLE_DOUBLE_BUFFERED; + config_attrib_list[i++] = 1; + config_attrib_list[i++] = WAFFLE_NONE; + + ok = waffle_init(init_attrib_list); + if (!ok) + fatal_waffle_error("waffle_init"); + + piglit_waffle_display = waffle_display_connect(NULL); + if (!piglit_waffle_display) + fatal_waffle_error("waffle_display_connect"); + + config = waffle_config_choose(piglit_waffle_display, + config_attrib_list); + if (!config) + fatal_waffle_error("waffle_config_choose"); + + piglit_waffle_context = waffle_context_create(config, NULL); + if (!piglit_waffle_context) + fatal_waffle_error("waffle_context_create"); + + piglit_waffle_window = waffle_window_create(config, + piglit_width, + piglit_height); + if (!piglit_waffle_window) + fatal_waffle_error("waffle_window_create"); + + ok = waffle_make_current(piglit_waffle_display, + piglit_waffle_window, + piglit_waffle_context); + if (!ok) + fatal_waffle_error("waffle_make_current"); + + // Cleanup. + ok = waffle_config_destroy(config); + if (!ok) + fatal_waffle_error("waffle_config_destroy"); +} + +static void +piglit_framework_fbo_waffle_destroy(void) +{ + bool ok = true; + + ok = waffle_make_current(piglit_waffle_display, NULL, NULL); + if (!ok) + fatal_waffle_error("waffle_make_current"); + + ok = waffle_context_destroy(piglit_waffle_context); + if (!ok) + fatal_waffle_error("waffle_context_destroy"); + + ok = waffle_display_disconnect(piglit_waffle_display); + if (!ok) + fatal_waffle_error("waffle_display_connect"); + + piglit_waffle_display = NULL; + piglit_waffle_context = NULL; +} +#endif + static bool piglit_framework_fbo_init_gl(void) { @@ -169,6 +318,8 @@ piglit_framework_fbo_destroy(void) #if defined(PIGLIT_FRAMEWORK_FBO_USE_GLX) piglit_framework_fbo_glx_destroy(); +#elif defined(PIGLIT_FRAMEWORK_FBO_USE_WAFFLE) + piglit_framework_fbo_waffle_destroy(); #endif } @@ -177,6 +328,8 @@ piglit_framework_fbo_init(void) { #if defined(PIGLIT_FRAMEWORK_FBO_USE_GLX) piglit_framework_fbo_glx_init(); +#elif defined(PIGLIT_FRAMEWORK_FBO_USE_WAFFLE) + piglit_framework_fbo_waffle_init(); #endif return piglit_framework_fbo_init_gl(); -- 1.7.10.1 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
