From patchwork Fri May 31 09:23:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Imre Deak X-Patchwork-Id: 2641211 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 348943FD2B for ; Fri, 31 May 2013 09:25:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15B1EE5D41 for ; Fri, 31 May 2013 02:25:38 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by gabe.freedesktop.org (Postfix) with ESMTP id 455CCE5D27 for ; Fri, 31 May 2013 02:23:25 -0700 (PDT) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 31 May 2013 02:23:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,777,1363158000"; d="scan'208";a="310475166" Received: from intelbox.fi.intel.com (HELO localhost) ([10.237.72.70]) by azsmga001.ch.intel.com with ESMTP; 31 May 2013 02:23:17 -0700 From: Imre Deak To: intel-gfx@lists.freedesktop.org Date: Fri, 31 May 2013 12:23:09 +0300 Message-Id: <1369992192-957-2-git-send-email-imre.deak@intel.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1369992192-957-1-git-send-email-imre.deak@intel.com> References: <1369992192-957-1-git-send-email-imre.deak@intel.com> Subject: [Intel-gfx] [igt PATCH 2/5] lib: add kmstest_cairo_printf_line X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Signed-off-by: Imre Deak --- lib/drmtest.c | 106 ++++++++++++++++++++++++++++------------------------ lib/drmtest.h | 13 +++++++ tests/testdisplay.c | 96 ++++++++++++++--------------------------------- 3 files changed, 99 insertions(+), 116 deletions(-) diff --git a/lib/drmtest.c b/lib/drmtest.c index 3c4812f..3ad77a8 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -907,45 +907,55 @@ paint_test_patterns(cairo_t *cr, int width, int height) paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1); } -enum corner { - topleft, - topright, - bottomleft, - bottomright, -}; - -static void -paint_marker(cairo_t *cr, int x, int y, char *str, enum corner text_location) +int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align, + double yspacing, const char *fmt, ...) { + double x, y, xofs, yofs; cairo_text_extents_t extents; - int xoff, yoff; + char *text; + va_list ap; + int ret; - cairo_set_font_size(cr, 18); - cairo_text_extents(cr, str, &extents); + va_start(ap, fmt); + ret = vasprintf(&text, fmt, ap); + assert(ret >= 0); + va_end(ap); - switch (text_location) { - case topleft: - xoff = -20; - xoff -= extents.width; - yoff = -20; - break; - case topright: - xoff = 20; - yoff = -20; - break; - case bottomleft: - xoff = -20; - xoff -= extents.width; - yoff = 20; - break; - case bottomright: - xoff = 20; - yoff = 20; - break; - default: - xoff = 0; - yoff = 0; - } + cairo_text_extents(cr, text, &extents); + + xofs = yofs = 0; + if (align & align_right) + xofs = -extents.width; + else if (align & align_hcenter) + xofs = -extents.width / 2; + + if (align & align_top) + yofs = extents.height; + else if (align & align_vcenter) + yofs = extents.height / 2; + + cairo_get_current_point(cr, &x, &y); + if (xofs || yofs) + cairo_rel_move_to(cr, xofs, yofs); + + cairo_text_path(cr, text); + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_stroke_preserve(cr); + cairo_set_source_rgb(cr, 1, 1, 1); + cairo_fill(cr); + + cairo_move_to(cr, x, y + extents.height + yspacing); + + free(text); + + return extents.width; +} + +static void +paint_marker(cairo_t *cr, int x, int y) +{ + enum kmstest_text_align align; + int xoff, yoff; cairo_move_to(cr, x, y - 20); cairo_line_to(cr, x, y + 20); @@ -960,12 +970,15 @@ paint_marker(cairo_t *cr, int x, int y, char *str, enum corner text_location) cairo_set_line_width(cr, 2); cairo_stroke(cr); + xoff = x ? -20 : 20; + align = x ? align_right : align_left; + + yoff = y ? -20 : 20; + align |= y ? align_bottom : align_top; + cairo_move_to(cr, x + xoff, y + yoff); - cairo_text_path(cr, str); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill(cr); + cairo_set_font_size(cr, 18); + kmstest_cairo_printf_line(cr, align, 0, "(%d, %d)", x, y); } unsigned int kmstest_create_fb(int fd, int width, int height, int bpp, @@ -977,7 +990,6 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp, cairo_surface_t *surface; cairo_status_t status; cairo_t *cr; - char buf[128]; unsigned int fb_id; surface = paint_allocate_surface(fd, width, height, depth, bpp, @@ -991,14 +1003,10 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp, cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); /* Paint corner markers */ - snprintf(buf, sizeof buf, "(%d, %d)", 0, 0); - paint_marker(cr, 0, 0, buf, bottomright); - snprintf(buf, sizeof buf, "(%d, %d)", width, 0); - paint_marker(cr, width, 0, buf, bottomleft); - snprintf(buf, sizeof buf, "(%d, %d)", 0, height); - paint_marker(cr, 0, height, buf, topright); - snprintf(buf, sizeof buf, "(%d, %d)", width, height); - paint_marker(cr, width, height, buf, topleft); + paint_marker(cr, 0, 0); + paint_marker(cr, width, 0); + paint_marker(cr, 0, height); + paint_marker(cr, width, height); if (paint_func) paint_func(cr, width, height, func_arg); diff --git a/lib/drmtest.h b/lib/drmtest.h index 38aeb9d..3c1368d 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -109,6 +109,19 @@ struct kmstest_fb { unsigned size; }; +enum kmstest_text_align { + align_left, + align_bottom = align_left, + align_right = 0x01, + align_top = 0x02, + align_vcenter = 0x04, + align_hcenter = 0x08, +}; + +int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align, + double yspacing, const char *fmt, ...) + __attribute__((format (printf, 4, 5))); + typedef void (*kmstest_paint_func)(cairo_t *cr, int width, int height, void *priv); unsigned int kmstest_create_fb(int fd, int width, int height, int bpp, diff --git a/tests/testdisplay.c b/tests/testdisplay.c index e7a2555..b10c3b9 100644 --- a/tests/testdisplay.c +++ b/tests/testdisplay.c @@ -331,86 +331,48 @@ static void paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv) { struct connector *c = priv; - cairo_text_extents_t name_extents, mode_extents; - char name_buf[128], mode_buf[128]; - int i, x, y, modes_x, modes_y; + double str_width; + double x, y, top_y; + double max_width; + int i; - /* Get text extents for each string */ - snprintf(name_buf, sizeof name_buf, "%s", - kmstest_connector_type_str(c->connector->connector_type)); - cairo_set_font_size(cr, 48); cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_text_extents(cr, name_buf, &name_extents); - - snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz on %s encoder", - c->mode.name, c->mode.vrefresh, - kmstest_encoder_type_str(c->encoder->encoder_type)); - cairo_set_font_size(cr, 36); - cairo_text_extents(cr, mode_buf, &mode_extents); + cairo_move_to(cr, l_width / 2, l_height / 2); - /* Paint output name */ - x = l_width / 2; - x -= name_extents.width / 2; - y = l_height / 2; - y -= (name_extents.height / 2) - (mode_extents.height / 2) - 10; + /* Print connector and mode name */ cairo_set_font_size(cr, 48); - cairo_move_to(cr, x, y); - cairo_text_path(cr, name_buf); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill(cr); - - /* Paint mode name */ - x = l_width / 2; - x -= mode_extents.width / 2; - modes_x = x; - y = l_height / 2; - y += (mode_extents.height / 2) + (name_extents.height / 2) + 10; + kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", + kmstest_connector_type_str(c->connector->connector_type)); + cairo_set_font_size(cr, 36); - cairo_move_to(cr, x, y); - cairo_text_path(cr, mode_buf); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill(cr); + str_width = kmstest_cairo_printf_line(cr, align_hcenter, 10, + "%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh, + kmstest_encoder_type_str(c->encoder->encoder_type)); + + cairo_rel_move_to(cr, -str_width / 2, 0); /* List available modes */ - snprintf(mode_buf, sizeof mode_buf, "Available modes:"); cairo_set_font_size(cr, 18); - cairo_text_extents(cr, mode_buf, &mode_extents); - x = modes_x; - modes_x = x + mode_extents.width; - y += mode_extents.height + 10; - modes_y = y; - cairo_move_to(cr, x, y); - cairo_text_path(cr, mode_buf); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill(cr); + str_width = kmstest_cairo_printf_line(cr, align_left, 10, + "Available modes:"); + cairo_rel_move_to(cr, str_width, 0); + cairo_get_current_point(cr, &x, &top_y); + max_width = 0; for (i = 0; i < c->connector->count_modes; i++) { - snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz", - c->connector->modes[i].name, - c->connector->modes[i].vrefresh); - cairo_set_font_size(cr, 18); - cairo_text_extents(cr, mode_buf, &mode_extents); - x = modes_x - mode_extents.width; /* right justify modes */ - y += mode_extents.height + 10; - if (y + mode_extents.height >= height) { - y = modes_y + mode_extents.height + 10; - modes_x += mode_extents.width + 10; - x = modes_x - mode_extents.width; + cairo_get_current_point(cr, &x, &y); + if (y >= l_height) { + x += max_width + 10; + max_width = 0; + cairo_move_to(cr, x, top_y); } - cairo_move_to(cr, x, y); - cairo_text_path(cr, mode_buf); - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_stroke_preserve(cr); - cairo_set_source_rgb(cr, 1, 1, 1); - cairo_fill(cr); + str_width = kmstest_cairo_printf_line(cr, align_right, 10, + "%s @ %dHz", c->connector->modes[i % 2].name, + c->connector->modes[i % 2].vrefresh); + if (str_width > max_width) + max_width = str_width; } if (qr_code)