From patchwork Mon Jul 6 12:35:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 6723331 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 255A9C05AC for ; Mon, 6 Jul 2015 12:35:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C08C20601 for ; Mon, 6 Jul 2015 12:35:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2ED4120613 for ; Mon, 6 Jul 2015 12:35:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C88486E877; Mon, 6 Jul 2015 05:35:56 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 520DB6E870 for ; Mon, 6 Jul 2015 05:35:54 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 06 Jul 2015 05:35:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,414,1432623600"; d="scan'208";a="741421028" Received: from magarwal-mobl.amr.corp.intel.com (HELO strange.amr.corp.intel.com) ([10.254.77.111]) by fmsmga001.fm.intel.com with ESMTP; 06 Jul 2015 05:35:53 -0700 From: Damien Lespiau To: intel-gfx@lists.freedesktop.org Date: Mon, 6 Jul 2015 13:35:36 +0100 Message-Id: <1436186144-19665-9-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1436186144-19665-1-git-send-email-damien.lespiau@intel.com> References: <1436186144-19665-1-git-send-email-damien.lespiau@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 08/16] plot: Add top and right axes X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This frames a bit more the plot will look nice with a background grid. Signed-off-by: Damien Lespiau --- lib/igt_plot.c | 46 +++++++++++++++++++++++++++++++++++++--------- lib/igt_plot.h | 2 ++ lib/igt_types.h | 14 ++++++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/lib/igt_plot.c b/lib/igt_plot.c index 9a1bea2..126f160 100644 --- a/lib/igt_plot.c +++ b/lib/igt_plot.c @@ -221,12 +221,16 @@ igt_vector_t *igt_vector_linear(double min, double max, unsigned int n) } static void igt_plot_axis_init(igt_plot_axis_t *axis, - igt_orientation_t orientation) + igt_side_t side) { memset(axis, 0, sizeof(*axis)); axis->n_ticks = 5; - axis->orientation = orientation; + axis->side = side; + if (side == IGT_SIDE_TOP || side == IGT_SIDE_BOTTOM) + axis->orientation = IGT_ORIENTATION_HORIZONTAL; + else + axis->orientation = IGT_ORIENTATION_VERTICAL; axis->min = DBL_MAX; axis->max = -DBL_MAX; } @@ -280,8 +284,10 @@ void igt_plot_init(igt_plot_t *plot, unsigned int width, unsigned int height) plot->height = height; plot->cr = cairo_create(plot->surface); - igt_plot_axis_init(&plot->x_axis, IGT_ORIENTATION_HORIZONTAL); - igt_plot_axis_init(&plot->y_axis, IGT_ORIENTATION_VERTICAL); + igt_plot_axis_init(&plot->x_axis, IGT_SIDE_BOTTOM); + igt_plot_axis_init(&plot->y_axis, IGT_SIDE_LEFT); + igt_plot_axis_init(&plot->x_axis_top, IGT_SIDE_TOP); + igt_plot_axis_init(&plot->y_axis_right, IGT_SIDE_RIGHT); plot->ctx = &plot->contexts[0]; igt_plot_ctx_init(plot->ctx); @@ -501,6 +507,7 @@ static void igt_plot_draw_ticks(igt_plot_t *plot, igt_plot_axis_t *axis, area_width = area->x2 - area->x1; area_height = area->y2 - area->y1; + cairo_set_font_size(plot->cr, flush->tick_label_font_size); cairo_set_line_cap(plot->cr, CAIRO_LINE_CAP_SQUARE); cairo_set_line_width(plot->cr, 1.0); @@ -508,7 +515,7 @@ static void igt_plot_draw_ticks(igt_plot_t *plot, igt_plot_axis_t *axis, double x, y; igt_label_t *label; - if (axis->orientation == IGT_ORIENTATION_HORIZONTAL) { + if (axis->side == IGT_SIDE_BOTTOM) { x = area->x1 + i * area_width / (axis->n_ticks - 1); y = area->y2; @@ -518,7 +525,8 @@ static void igt_plot_draw_ticks(igt_plot_t *plot, igt_plot_axis_t *axis, label = &flush->x_tick_labels[i]; y += flush->tick_label_padding; - } else { + igt_plot_draw_text(plot, x, y, label); + } else if (axis->side == IGT_SIDE_LEFT) { x = area->x1; y = area->y2 - i * area_height / (axis->n_ticks - 1); @@ -528,10 +536,22 @@ static void igt_plot_draw_ticks(igt_plot_t *plot, igt_plot_axis_t *axis, label = &flush->y_tick_labels[i]; x -= flush->tick_label_padding; - } + igt_plot_draw_text(plot, x, y, label); + } else if (axis->side == IGT_SIDE_TOP) { + x = area->x1 + i * area_width / (axis->n_ticks - 1); + y = area->y1; - cairo_set_font_size(plot->cr, flush->tick_label_font_size); - igt_plot_draw_text(plot, x, y, label); + cairo_move_to(plot->cr, SNAP(x), y); + cairo_line_to(plot->cr, SNAP(x), SNAP(y + tick_length)); + cairo_stroke(plot->cr); + } else { + x = area->x2; + y = area->y1 + i * area_height / (axis->n_ticks - 1); + + cairo_move_to(plot->cr, x, SNAP(y)); + cairo_line_to(plot->cr, SNAP(x - tick_length), SNAP(y)); + cairo_stroke(plot->cr); + } } } @@ -545,11 +565,19 @@ static void igt_plot_draw_axis(igt_plot_t *plot, flush_t *flush) cairo_line_to(plot->cr, area->x2, area->y2); igt_plot_draw_ticks(plot, &plot->x_axis, tick_length, flush); + cairo_move_to(plot->cr, area->x1, area->y1); + cairo_line_to(plot->cr, area->x2, area->y1); + igt_plot_draw_ticks(plot, &plot->x_axis_top, tick_length, flush); + /* Y-axis */ cairo_move_to(plot->cr, area->x1, area->y2); cairo_line_to(plot->cr, area->x1, area->y1); igt_plot_draw_ticks(plot, &plot->y_axis, tick_length, flush); + cairo_move_to(plot->cr, area->x2, area->y1); + cairo_line_to(plot->cr, area->x2, area->y2); + igt_plot_draw_ticks(plot, &plot->y_axis_right, tick_length, flush); + } static void igt_plot_layout_tick_labels(igt_plot_t *plot, diff --git a/lib/igt_plot.h b/lib/igt_plot.h index 2af035e..c8b031f 100644 --- a/lib/igt_plot.h +++ b/lib/igt_plot.h @@ -74,6 +74,7 @@ void igt_vector_get_min_max(const igt_vector_t *v, double *min, double *max); typedef struct { /*< private >*/ igt_orientation_t orientation; + igt_side_t side; unsigned int n_ticks; double min, max; /* range of the values on this axis */ } igt_plot_axis_t; @@ -104,6 +105,7 @@ typedef struct { unsigned int width, height; igt_trbl_t margin; igt_plot_axis_t x_axis, y_axis; + igt_plot_axis_t x_axis_top, y_axis_right; /* per draw command contexts */ igt_plot_ctx_t contexts[IGT_PLOT_MAX_PLOTS + 1]; diff --git a/lib/igt_types.h b/lib/igt_types.h index 3d7f1d6..959aa4b 100644 --- a/lib/igt_types.h +++ b/lib/igt_types.h @@ -66,6 +66,20 @@ typedef struct { } igt_box_t; /** + * igt_side_t: + * @IGT_SIDE_TOP: Top + * @IGT_SIDE_RIGHT: Right + * @IGT_SIDE_BOTTOM: Bottom + * @IGT_SIDE_LEFT: Left + */ +typedef enum { + IGT_SIDE_TOP, + IGT_SIDE_RIGHT, + IGT_SIDE_BOTTOM, + IGT_SIDE_LEFT, +} igt_side_t; + +/** * igt_trbl_t: * @top: Top value * @right: Right value