mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-12 02:16:17 +00:00
lib: add kmstest_cairo_printf_line
Signed-off-by: Imre Deak <imre.deak@intel.com> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com> [v3: fix mode printing in paint_output_info() botched by debugging leftover :/ ]
This commit is contained in:
parent
3a2aed1f30
commit
542a40c485
@ -907,6 +907,50 @@ paint_test_patterns(cairo_t *cr, int width, int height)
|
|||||||
paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
|
paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
char *text;
|
||||||
|
va_list ap;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
ret = vasprintf(&text, fmt, ap);
|
||||||
|
assert(ret >= 0);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
enum corner {
|
enum corner {
|
||||||
topleft,
|
topleft,
|
||||||
topright,
|
topright,
|
||||||
|
@ -109,6 +109,19 @@ struct kmstest_fb {
|
|||||||
unsigned size;
|
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);
|
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,
|
unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
|
||||||
|
@ -331,86 +331,48 @@ static void
|
|||||||
paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
|
paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
|
||||||
{
|
{
|
||||||
struct connector *c = priv;
|
struct connector *c = priv;
|
||||||
cairo_text_extents_t name_extents, mode_extents;
|
double str_width;
|
||||||
char name_buf[128], mode_buf[128];
|
double x, y, top_y;
|
||||||
int i, x, y, modes_x, modes_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_select_font_face(cr, "Helvetica",
|
||||||
CAIRO_FONT_SLANT_NORMAL,
|
CAIRO_FONT_SLANT_NORMAL,
|
||||||
CAIRO_FONT_WEIGHT_NORMAL);
|
CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
cairo_text_extents(cr, name_buf, &name_extents);
|
cairo_move_to(cr, l_width / 2, l_height / 2);
|
||||||
|
|
||||||
snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz on %s encoder",
|
/* Print connector and mode name */
|
||||||
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);
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
cairo_set_font_size(cr, 48);
|
cairo_set_font_size(cr, 48);
|
||||||
cairo_move_to(cr, x, y);
|
kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s",
|
||||||
cairo_text_path(cr, name_buf);
|
kmstest_connector_type_str(c->connector->connector_type));
|
||||||
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;
|
|
||||||
cairo_set_font_size(cr, 36);
|
cairo_set_font_size(cr, 36);
|
||||||
cairo_move_to(cr, x, y);
|
str_width = kmstest_cairo_printf_line(cr, align_hcenter, 10,
|
||||||
cairo_text_path(cr, mode_buf);
|
"%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh,
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
kmstest_encoder_type_str(c->encoder->encoder_type));
|
||||||
cairo_stroke_preserve(cr);
|
|
||||||
cairo_set_source_rgb(cr, 1, 1, 1);
|
cairo_rel_move_to(cr, -str_width / 2, 0);
|
||||||
cairo_fill(cr);
|
|
||||||
|
|
||||||
/* List available modes */
|
/* List available modes */
|
||||||
snprintf(mode_buf, sizeof mode_buf, "Available modes:");
|
|
||||||
cairo_set_font_size(cr, 18);
|
cairo_set_font_size(cr, 18);
|
||||||
cairo_text_extents(cr, mode_buf, &mode_extents);
|
str_width = kmstest_cairo_printf_line(cr, align_left, 10,
|
||||||
x = modes_x;
|
"Available modes:");
|
||||||
modes_x = x + mode_extents.width;
|
cairo_rel_move_to(cr, str_width, 0);
|
||||||
y += mode_extents.height + 10;
|
cairo_get_current_point(cr, &x, &top_y);
|
||||||
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);
|
|
||||||
|
|
||||||
|
max_width = 0;
|
||||||
for (i = 0; i < c->connector->count_modes; i++) {
|
for (i = 0; i < c->connector->count_modes; i++) {
|
||||||
snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz",
|
cairo_get_current_point(cr, &x, &y);
|
||||||
c->connector->modes[i].name,
|
if (y >= l_height) {
|
||||||
c->connector->modes[i].vrefresh);
|
x += max_width + 10;
|
||||||
cairo_set_font_size(cr, 18);
|
max_width = 0;
|
||||||
cairo_text_extents(cr, mode_buf, &mode_extents);
|
cairo_move_to(cr, x, top_y);
|
||||||
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_move_to(cr, x, y);
|
str_width = kmstest_cairo_printf_line(cr, align_right, 10,
|
||||||
cairo_text_path(cr, mode_buf);
|
"%s @ %dHz", c->connector->modes[i].name,
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
c->connector->modes[i].vrefresh);
|
||||||
cairo_stroke_preserve(cr);
|
if (str_width > max_width)
|
||||||
cairo_set_source_rgb(cr, 1, 1, 1);
|
max_width = str_width;
|
||||||
cairo_fill(cr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qr_code)
|
if (qr_code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user