[Piglit] [PATCH] gbm: use libcaca to display results in non-auto mode
Kenneth Graunke
kenneth at whitecape.org
Sat Feb 8 01:38:09 CET 2014
On 02/07/2014 11:04 AM, Jordan Justen wrote:
> If GBM is enabled, attempt to locate libcaca too.
>
> If the test was not run with -auto, then use libcaca
> to draw a text version of the test's results to the
> console.
>
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
Oh man! It's like the Fedora Hot Dog(*) all over again...your only
options are [YES] or [HELL YES] :D
(*) https://fedoraproject.org/wiki/Features/Hot_Dog
Acked-by: Kenneth Graunke <kenneth at whitecape.org>
It looks like libcaca is changing API from 0.9 to 1.0, so this will
probably need (simple) updates in the future.
Some comments below.
> ---
> CMakeLists.txt | 8 ++
> tests/util/CMakeLists.txt | 4 +
> .../piglit-framework-gl/piglit_gbm_framework.c | 85 ++++++++++++++++++++++
> 3 files changed, 97 insertions(+)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index bef9c35..71a40ba 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -318,6 +318,14 @@ if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
> add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
> endif()
>
> +if(GBM_FOUND)
> +FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
> +if(HAVE_LIBCACA)
> + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
This line doesn't seem necessary...
> + add_definitions(-DPIGLIT_HAS_LIBCACA)
> +endif(HAVE_LIBCACA)
> +endif(GBM_FOUND)
> +
> if(PIGLIT_USE_WAFFLE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
> pkg_check_modules(EGL egl)
> endif()
> diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
> index 27c8888..c661f44 100644
> --- a/tests/util/CMakeLists.txt
> +++ b/tests/util/CMakeLists.txt
> @@ -4,6 +4,10 @@ if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC AND HAVE_LIBRT)
> link_libraries(rt)
> endif()
>
> +if(HAVE_LIBCACA)
> + link_libraries(caca)
> +endif()
> +
> set(UTIL_INCLUDES
> ${CMAKE_CURRENT_BINARY_DIR}
> ${CMAKE_CURRENT_SOURCE_DIR}
> diff --git a/tests/util/piglit-framework-gl/piglit_gbm_framework.c b/tests/util/piglit-framework-gl/piglit_gbm_framework.c
> index 859a7c9..f30edf1 100644
> --- a/tests/util/piglit-framework-gl/piglit_gbm_framework.c
> +++ b/tests/util/piglit-framework-gl/piglit_gbm_framework.c
> @@ -29,6 +29,9 @@
> #include "piglit_gbm_framework.h"
>
> static void
> +piglit_gbm_console_display(void);
> +
> +static void
> enter_event_loop(struct piglit_winsys_framework *winsys_fw)
> {
> const struct piglit_gl_test_config *test_config = winsys_fw->wfl_fw.gl_fw.test_config;
> @@ -41,6 +44,8 @@ enter_event_loop(struct piglit_winsys_framework *winsys_fw)
> if (piglit_automatic)
> piglit_report_result(result);
>
> + piglit_gbm_console_display();
> +
> /* gbm has no input, so we exit immediately, as if the user
> * had pressed escape.
> */
> @@ -90,3 +95,83 @@ fail:
> destroy(gl_fw);
> return NULL;
> }
> +
> +#ifdef PIGLIT_HAS_LIBCACA
> +#include <caca.h>
> +#endif
> +
> +static void
> +piglit_gbm_console_display(void)
> +{
> +#ifdef PIGLIT_HAS_LIBCACA
> + caca_canvas_t *canvas;
> + caca_dither_t *dither;
> + void *export;
> + uint32_t *pixels;
> + size_t export_size;
> + int width = 40, height = 20;
> + int i;
> +
> + canvas = caca_create_canvas(width, height);
> + if (!canvas) {
> + printf("Failed to get canvas for gbm console display!\n");
> + return;
> + }
> +
> + caca_set_color_ansi(canvas, CACA_DEFAULT, CACA_TRANSPARENT);
> +
> + dither = caca_create_dither(32, piglit_width, piglit_height,
> + 4 * piglit_width,
> + 0x000000ff, 0x0000ff00,
> + 0x00ff0000, 0xff000000);
I'm not sure if gbm will ever create a non-RGBA8888 visual, but this
would need tweaking. Maybe replace 4 with a "components" variable or
such...? Would reduce the number of magic constants a bit.
> + if (!dither) {
> + caca_free_canvas(canvas);
> + printf("Failed to get dither object for gbm console display!\n");
> + return;
> + }
> +
> + /* Note: we allocate memory for 1 extra row */
> + pixels = malloc(4 * piglit_width * (piglit_height + 1));
> +
> + while (!piglit_check_gl_error(GL_NO_ERROR)) {
> + /* Clear any OpenGL errors */
> + }
You could do:
piglit_reset_gl_error();
> + glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
> + glReadPixels(0, 0, piglit_width, piglit_height,
> + GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) pixels);
> + if (!piglit_check_gl_error(GL_NO_ERROR)) {
> + caca_free_dither(dither);
> + caca_free_canvas(canvas);
> + printf("Error reading pixels for gbm console display!\n");
> + return;
> + }
> +
> + /* Swap the image's pixels vertically using the extra
> + * row of pixels that we allocated as swap space.
> + */
> + for (i = 0; i < (piglit_height / 2); i++) {
> + memcpy(&pixels[piglit_width * piglit_height],
> + &pixels[piglit_width * i],
> + 4 * piglit_width);
> + memcpy(&pixels[piglit_width * i],
> + &pixels[piglit_width * (piglit_height - i)],
> + 4 * piglit_width);
> + memcpy(&pixels[piglit_width * (piglit_height - i)],
> + &pixels[piglit_width * piglit_height],
> + 4 * piglit_width);
> + }
I think with caca 1.0 you could just do:
cucul_flop(canvas);
and avoid this code, as well as the extra line.
> +
> + caca_dither_bitmap(canvas, 0, 0, width, height, dither, pixels);
> + caca_free_dither(dither);
> + free(pixels);
> +
> + export = caca_export_canvas_to_memory(canvas, "ansi", &export_size);
> + caca_free_canvas(canvas);
> + if (!export) {
> + printf("Failed to export image for gbm console display!\n");
> + } else {
> + fwrite(export, export_size, 1, stdout);
> + free(export);
> + }
> +#endif
> +}
Jordan, you rock.
--Ken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140207/1347e320/attachment.pgp>
More information about the Piglit
mailing list