[Piglit] [PATCH v2] gbm: use libcaca to display results in non-auto mode

Jordan Justen jordan.l.justen at intel.com
Mon Nov 3 09:39:11 PST 2014


On 2014-11-01 00:06:33, Ben Widawsky wrote:
> From: Jordan Justen <jordan.l.justen at intel.com>
> 
> 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.
> 
> v2 (Ben): Rebase
> Per Ken's comment the libcaca API may change at v1.0, but it's still not
> there are 8 months. I propose we push this, and worry about libcaca
> breakage later.

Thanks for rebasing it Ben.

I agree about libcaca. Let's deal with API breaks if/when they happen.

I would say that you can go ahead and push this patch.

-Jordan

> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com> (v1)
> Acked-by: Kenneth Graunke <kenneth at whitecape.org>
> Cc: Kristian Høgsberg <krh at bitplanet.net>
> Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
> ---
>  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 c6c48bc..4c187e3 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -350,6 +350,14 @@ if(PIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
>         add_definitions(-DPIGLIT_HAS_POSIX_TIMER_NOTIFY_THREAD)
>  endif()
>  
> +if(GBM_FOUND)
> +FIND_LIBRARY(HAVE_LIBCACA NAMES caca)
> +if(HAVE_LIBCACA)
> +       set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} caca)
> +       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 d8a72df..98eedd0 100644
> --- a/tests/util/CMakeLists.txt
> +++ b/tests/util/CMakeLists.txt
> @@ -11,6 +11,10 @@ set_source_files_properties(
>         PROPERTIES GENERATED 1
>         )
>  
> +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 3ea2a16..de80b0d 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);
> +       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 */
> +       }
> +       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);
> +       }
> +
> +       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
> +}
> -- 
> 2.1.3
> 


More information about the Piglit mailing list