If USE_WAFFLE and USE_GLX are both enabled, then Waffle takes precedence; the Waffle backend is used.
CC: Pauli Nieminen <[email protected]> Signed-off-by: Chad Versace <[email protected]> --- tests/util/CMakeLists.txt | 4 + tests/util/piglit-framework-fbo.c | 150 +++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index cd8f518..e69127d 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -28,4 +28,8 @@ if(OPENGL_egl_LIBRARY) ) endif(OPENGL_egl_LIBRARY) +if(USE_WAFFLE) + link_libraries("${WAFFLE_waffle_LIBRARY}") +endif(USE_WAFFLE) + piglit_include_target_api() diff --git a/tests/util/piglit-framework-fbo.c b/tests/util/piglit-framework-fbo.c index 277aa1d..37411e3 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 @@ -35,11 +37,17 @@ #include <stdlib.h> #include "piglit-util.h" +#include "piglit-framework.h" +#include "piglit-framework-fbo.h" #ifdef PIGLIT_FRAMEWORK_FBO_USE_GLX #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 @@ -49,6 +57,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() @@ -79,6 +93,138 @@ piglit_framework_fbo_glx_destroy() } #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) +{ + const struct waffle_error_info *info = waffle_error_get_info(); + const char *error_name = waffle_error_to_string(info->code); + + fflush(stdout); + fprintf(stderr, "%s failed with error: %s", func_name, error_name); + if (info->message_length > 0) + fprintf(stderr, ": %s", info->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_gl_init() { @@ -160,6 +306,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_gl_init(); @@ -176,5 +324,7 @@ 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 } -- 1.7.10.1 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
