diff options
author | Jordan Justen <jordan.l.justen@intel.com> | 2015-01-31 23:11:14 -0800 |
---|---|---|
committer | Jordan Justen <jordan.l.justen@intel.com> | 2015-02-09 10:43:20 -0800 |
commit | 931b21ed6b7821dbdcb13bd203f20760044fa13d (patch) | |
tree | af1482fa5cd8c05febfdfb7b39b8f652684b71d5 | |
parent | 12dacb6704f4d49e3f7d2ece7a7db6f40b2cb44f (diff) |
gbm: Attempt to size libcaca output to fit the console window
Take into account the aspect ratio of piglit_width to piglit_height.
The assumption is made that the console window is 80 x 24.
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
-rw-r--r-- | tests/util/piglit-framework-gl/piglit_gbm_framework.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/tests/util/piglit-framework-gl/piglit_gbm_framework.c b/tests/util/piglit-framework-gl/piglit_gbm_framework.c index 3c42fba6b..581ca9999 100644 --- a/tests/util/piglit-framework-gl/piglit_gbm_framework.c +++ b/tests/util/piglit-framework-gl/piglit_gbm_framework.c @@ -98,18 +98,43 @@ fail: #ifdef PIGLIT_HAS_LIBCACA #include <caca.h> -#endif + +static void +determine_canvas_size(int *width, int *height) +{ + int columns = 80, rows = 24; + float test_aspect, console_aspect; + const float font_aspect = 0.5; + + /* Don't fill the entire window. */ + columns--; + rows--; + + test_aspect = (float)piglit_width / (float)piglit_height; + console_aspect = (float)(columns) / (float)(2 * (rows)); + if (console_aspect < test_aspect) { + rows = (int) (font_aspect * piglit_height * + ((float)columns / piglit_width)); + } else { + columns = (int) ((float)piglit_width * + ((float)rows / piglit_height / font_aspect)); + } + + *width = MAX2(1, columns); + *height = MAX2(1, rows); +} 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 width, height; + + determine_canvas_size(&width, &height); canvas = caca_create_canvas(width, height); if (!canvas) { @@ -157,5 +182,13 @@ piglit_gbm_console_display(void) fwrite(export, export_size, 1, stdout); free(export); } -#endif } + +#else // PIGLIT_HAS_LIBCACA + +static void +piglit_gbm_console_display(void) +{ +} + +#endif |