Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [igt PATCH 1/5] lib: move connector_type_str and co to drmtest
@ 2013-05-31  9:23 Imre Deak
  2013-05-31  9:23 ` [igt PATCH 2/5] lib: add kmstest_cairo_printf_line Imre Deak
                   ` (4 more replies)
  0 siblings, 5 replies; 22+ messages in thread
From: Imre Deak @ 2013-05-31  9:23 UTC (permalink / raw)
  To: intel-gfx

These are used by multiple test cases, so make them shared.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 demos/intel_sprite_on.c | 58 ++++------------------------------------------
 lib/drmtest.c           | 54 +++++++++++++++++++++++++++++++++++++++++++
 lib/drmtest.h           |  3 +++
 tests/testdisplay.c     | 61 ++++---------------------------------------------
 4 files changed, 65 insertions(+), 111 deletions(-)

diff --git a/demos/intel_sprite_on.c b/demos/intel_sprite_on.c
index 62bd98e..783f9af 100644
--- a/demos/intel_sprite_on.c
+++ b/demos/intel_sprite_on.c
@@ -53,56 +53,6 @@
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-struct type_name {
-	int                 type;
-	const char          *name;
-};
-
-#define type_name_fn(res) \
-	static const char * res##_str(int type) {		\
-		unsigned int i;					\
-		for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
-			if (res##_names[i].type == type)	\
-			return res##_names[i].name;		\
-		}						\
-		return "(invalid)";				\
-	}
-
-struct type_name encoder_type_names[] = {
-	{ DRM_MODE_ENCODER_NONE, "none" },
-	{ DRM_MODE_ENCODER_DAC, "DAC" },
-	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
-	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
-	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
-};
-type_name_fn(encoder_type)
-
-struct type_name connector_status_names[] = {
-	{ DRM_MODE_CONNECTED, "connected" },
-	{ DRM_MODE_DISCONNECTED, "disconnected" },
-	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
-};
-type_name_fn(connector_status)
-
-struct type_name connector_type_names[] = {
-	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
-	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
-	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
-	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
-	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
-	{ DRM_MODE_CONNECTOR_Composite, "composite" },
-	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
-	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
-	{ DRM_MODE_CONNECTOR_Component, "component" },
-	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
-	{ DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
-	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
-	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
-	{ DRM_MODE_CONNECTOR_TV, "TV" },
-	{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
-};
-type_name_fn(connector_type)
-
 /*
  * Mode setting with the kernel interfaces is a bit of a chore.
  * First you have to find the connector in question and make sure the
@@ -157,8 +107,8 @@ static void dump_connectors(int gfx_fd, drmModeRes *resources)
 		printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
 			connector->connector_id,
 			connector->encoder_id,
-			connector_status_str(connector->connection),
-			connector_type_str(connector->connector_type),
+			kmstest_connector_status_str(connector->connection),
+			kmstest_connector_type_str(connector->connector_type),
 			connector->mmWidth, connector->mmHeight,
 			connector->count_modes);
 
@@ -744,14 +694,14 @@ static void ricochet(int tiled, int sprite_w, int sprite_h,
 				curr_connector.mode.flags,
 				curr_connector.encoder->encoder_id,
 				curr_connector.encoder->encoder_type,
-				encoder_type_str(curr_connector.encoder->encoder_type),
+				kmstest_encoder_type_str(curr_connector.encoder->encoder_type),
 				curr_connector.encoder->crtc_id,
 				curr_connector.encoder->possible_crtcs,
 				curr_connector.encoder->possible_clones,
 				curr_connector.connector->connector_id,
 				curr_connector.connector->encoder_id,
 				curr_connector.connector->connector_type,
-				connector_type_str(curr_connector.connector->connector_type),
+				kmstest_connector_type_str(curr_connector.connector->connector_type),
 				curr_connector.connector->connector_type_id);
 
 			printf("Sprite surface dimensions = %dx%d\n"
diff --git a/lib/drmtest.c b/lib/drmtest.c
index d17dbb0..3c4812f 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -1023,6 +1023,60 @@ void kmstest_remove_fb(int fd, int fb_id)
 	do_or_die(drmModeRmFB(fd, fb_id));
 }
 
+struct type_name {
+	int type;
+	const char *name;
+};
+
+#define type_name_fn(res) \
+const char * kmstest_##res##_str(int type) {		\
+	unsigned int i;					\
+	for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
+		if (res##_names[i].type == type)	\
+			return res##_names[i].name;	\
+	}						\
+	return "(invalid)";				\
+}
+
+struct type_name encoder_type_names[] = {
+	{ DRM_MODE_ENCODER_NONE, "none" },
+	{ DRM_MODE_ENCODER_DAC, "DAC" },
+	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
+	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
+	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
+};
+
+type_name_fn(encoder_type)
+
+struct type_name connector_status_names[] = {
+	{ DRM_MODE_CONNECTED, "connected" },
+	{ DRM_MODE_DISCONNECTED, "disconnected" },
+	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
+};
+
+type_name_fn(connector_status)
+
+struct type_name connector_type_names[] = {
+	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
+	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
+	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
+	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
+	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
+	{ DRM_MODE_CONNECTOR_Composite, "composite" },
+	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
+	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
+	{ DRM_MODE_CONNECTOR_Component, "component" },
+	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
+	{ DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
+	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
+	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
+	{ DRM_MODE_CONNECTOR_TV, "TV" },
+	{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
+};
+
+type_name_fn(connector_type)
+
+
 void kmstest_dump_mode(drmModeModeInfo *mode)
 {
 	printf("  %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n",
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 7202ad5..38aeb9d 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -119,6 +119,9 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 void kmstest_remove_fb(int fd, int fb_id);
 void kmstest_dump_mode(drmModeModeInfo *mode);
 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
+const char *kmstest_encoder_type_str(int type);
+const char *kmstest_connector_status_str(int type);
+const char *kmstest_connector_type_str(int type);
 
 inline static void _do_or_die(const char *function, int line, int ret)
 {
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 80cd112..e7a2555 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -88,59 +88,6 @@ uint32_t *fb_ptr;
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-struct type_name {
-	int type;
-	const char *name;
-};
-
-#define type_name_fn(res) \
-static const char * res##_str(int type) {			\
-	unsigned int i;					\
-	for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
-		if (res##_names[i].type == type)	\
-			return res##_names[i].name;	\
-	}						\
-	return "(invalid)";				\
-}
-
-struct type_name encoder_type_names[] = {
-	{ DRM_MODE_ENCODER_NONE, "none" },
-	{ DRM_MODE_ENCODER_DAC, "DAC" },
-	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
-	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
-	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
-};
-
-type_name_fn(encoder_type)
-
-struct type_name connector_status_names[] = {
-	{ DRM_MODE_CONNECTED, "connected" },
-	{ DRM_MODE_DISCONNECTED, "disconnected" },
-	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
-};
-
-type_name_fn(connector_status)
-
-struct type_name connector_type_names[] = {
-	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
-	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
-	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
-	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
-	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
-	{ DRM_MODE_CONNECTOR_Composite, "composite" },
-	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
-	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
-	{ DRM_MODE_CONNECTOR_Component, "component" },
-	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
-	{ DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
-	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
-	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
-	{ DRM_MODE_CONNECTOR_TV, "TV" },
-	{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
-};
-
-type_name_fn(connector_type)
-
 /*
  * Mode setting with the kernel interfaces is a bit of a chore.
  * First you have to find the connector in question and make sure the
@@ -185,8 +132,8 @@ static void dump_connectors_fd(int drmfd)
 		printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
 		       connector->connector_id,
 		       connector->encoder_id,
-		       connector_status_str(connector->connection),
-		       connector_type_str(connector->connector_type),
+		       kmstest_connector_status_str(connector->connection),
+		       kmstest_connector_type_str(connector->connector_type),
 		       connector->mmWidth, connector->mmHeight,
 		       connector->count_modes);
 
@@ -390,7 +337,7 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	/* Get text extents for each string */
 	snprintf(name_buf, sizeof name_buf, "%s",
-		 connector_type_str(c->connector->connector_type));
+		 kmstest_connector_type_str(c->connector->connector_type));
 	cairo_set_font_size(cr, 48);
 	cairo_select_font_face(cr, "Helvetica",
 			       CAIRO_FONT_SLANT_NORMAL,
@@ -399,7 +346,7 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz on %s encoder",
 		 c->mode.name, c->mode.vrefresh,
-		 encoder_type_str(c->encoder->encoder_type));
+		 kmstest_encoder_type_str(c->encoder->encoder_type));
 	cairo_set_font_size(cr, 36);
 	cairo_text_extents(cr, mode_buf, &mode_extents);
 
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [igt PATCH 2/5] lib: add kmstest_cairo_printf_line
  2013-05-31  9:23 [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Imre Deak
@ 2013-05-31  9:23 ` Imre Deak
  2013-06-05 17:44   ` Rodrigo Vivi
  2013-05-31  9:23 ` [igt PATCH 3/5] lib: add kmstest_get_connector_config Imre Deak
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 22+ messages in thread
From: Imre Deak @ 2013-05-31  9:23 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 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)
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [igt PATCH 3/5] lib: add kmstest_get_connector_config
  2013-05-31  9:23 [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Imre Deak
  2013-05-31  9:23 ` [igt PATCH 2/5] lib: add kmstest_cairo_printf_line Imre Deak
@ 2013-05-31  9:23 ` Imre Deak
  2013-06-05 18:00   ` Rodrigo Vivi
  2013-05-31  9:23 ` [igt PATCH 4/5] lib: refactor kmstest_create_fb Imre Deak
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 22+ messages in thread
From: Imre Deak @ 2013-05-31  9:23 UTC (permalink / raw)
  To: intel-gfx

This is used by multiple test cases, so make it shared.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/drmtest.c       | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/drmtest.h       |  14 ++++++
 tests/kms_flip.c    | 115 ++++++++------------------------------------
 tests/testdisplay.c | 134 +++++++++++++++-------------------------------------
 4 files changed, 206 insertions(+), 191 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 3ad77a8..7368077 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -1317,3 +1317,137 @@ int drmtest_set_vt_graphics_mode(void)
 	return orig_vt_mode < 0 ? -1 : 0;
 }
 
+static int get_connector_default_mode(int drm_fd, drmModeConnector *connector,
+				      drmModeModeInfo *mode)
+{
+	drmModeRes *resources;
+	int i;
+
+	resources = drmModeGetResources(drm_fd);
+	if (!resources) {
+		perror("drmModeGetResources failed");
+
+		return -1;
+	}
+
+	if (!connector->count_modes) {
+		fprintf(stderr, "no modes for connector %d\n",
+			connector->connector_id);
+		drmModeFreeResources(resources);
+
+		return -1;
+	}
+
+	for (i = 0; i < connector->count_modes; i++) {
+		if (i == 0 ||
+		    connector->modes[i].type & DRM_MODE_TYPE_PREFERRED) {
+			*mode = connector->modes[i];
+			if (mode->type & DRM_MODE_TYPE_PREFERRED)
+				break;
+		}
+	}
+
+	drmModeFreeResources(resources);
+
+	return 0;
+}
+
+int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
+				 unsigned long crtc_idx_mask,
+				 struct kmstest_connector_config *config)
+{
+	drmModeRes *resources;
+	drmModeConnector *connector;
+	drmModeEncoder *encoder;
+	int i, j;
+
+	resources = drmModeGetResources(drm_fd);
+	if (!resources) {
+		perror("drmModeGetResources failed");
+		goto err1;
+	}
+
+	/* First, find the connector & mode */
+	connector = drmModeGetConnector(drm_fd, connector_id);
+	if (!connector)
+		goto err2;
+
+	if (connector->connection != DRM_MODE_CONNECTED)
+		goto err3;
+
+	if (!connector->count_modes) {
+		fprintf(stderr, "connector %d has no modes\n", connector_id);
+		goto err3;
+	}
+
+	if (connector->connector_id != connector_id) {
+		fprintf(stderr, "connector id doesn't match (%d != %d)\n",
+			connector->connector_id, connector_id);
+		goto err3;
+	}
+
+	/*
+	 * Find given CRTC if crtc_id != 0 or else the first CRTC not in use.
+	 * In both cases find the first compatible encoder and skip the CRTC
+	 * if there is non such.
+	 */
+	encoder = NULL;		/* suppress GCC warning */
+	for (i = 0; i < resources->count_crtcs; i++) {
+		if (!resources->crtcs[i] || !(crtc_idx_mask & (1 << i)))
+			continue;
+
+		/* Now get a compatible encoder */
+		for (j = 0; j < connector->count_encoders; j++) {
+			encoder = drmModeGetEncoder(drm_fd,
+						    connector->encoders[j]);
+
+			if (!encoder) {
+				fprintf(stderr, "could not get encoder %d: %s\n",
+					resources->encoders[j], strerror(errno));
+
+				continue;
+			}
+
+			if (encoder->possible_crtcs & (1 << i))
+				goto found;
+
+			drmModeFreeEncoder(encoder);
+		}
+	}
+
+	fprintf(stderr,
+		"no crtc with a compatible encoder (crtc_idx_mask %08lx)\n",
+		crtc_idx_mask);
+	goto err3;
+
+found:
+	if (get_connector_default_mode(drm_fd, connector,
+				       &config->default_mode) < 0)
+		goto err4;
+
+	config->connector = connector;
+	config->encoder = encoder;
+	config->crtc = drmModeGetCrtc(drm_fd, resources->crtcs[i]);
+	config->crtc_idx = i;
+	config->pipe = kmstest_get_pipe_from_crtc_id(drm_fd,
+						     config->crtc->crtc_id);
+
+	drmModeFreeResources(resources);
+
+	return 0;
+err4:
+	drmModeFreeEncoder(encoder);
+err3:
+	drmModeFreeConnector(connector);
+err2:
+	drmModeFreeResources(resources);
+err1:
+	return -1;
+}
+
+void kmstest_free_connector_config(struct kmstest_connector_config *config)
+{
+	drmModeFreeCrtc(config->crtc);
+	drmModeFreeEncoder(config->encoder);
+	drmModeFreeConnector(config->connector);
+}
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 3c1368d..89ded11 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -101,6 +101,20 @@ void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr);
 void drmtest_trash_aperture(void);
 void drmtest_cleanup_aperture_trashers(void);
 
+struct kmstest_connector_config {
+	drmModeCrtc *crtc;
+	drmModeConnector *connector;
+	drmModeEncoder *encoder;
+	drmModeModeInfo default_mode;
+	int crtc_idx;
+	int pipe;
+};
+
+int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
+				 unsigned long crtc_idx_mask,
+				 struct kmstest_connector_config *config);
+void kmstest_free_connector_config(struct kmstest_connector_config *config);
+
 /* helpers to create nice-looking framebuffers */
 struct kmstest_fb {
 	uint32_t fb_id;
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index 735b4dd..c9b3d8a 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -825,97 +825,23 @@ static void update_all_state(struct test_output *o,
 		update_state(&o->vblank_state);
 }
 
-static void connector_find_preferred_mode(struct test_output *o, int crtc_id)
+static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
+					  struct test_output *o)
 {
-	drmModeConnector *connector;
-	drmModeEncoder *encoder = NULL;
-	int i, j;
-
-	/* First, find the connector & mode */
-	o->mode_valid = 0;
-	o->crtc = 0;
-	connector = drmModeGetConnector(drm_fd, o->id);
-	assert(connector);
-
-	if (connector->connection != DRM_MODE_CONNECTED) {
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (!connector->count_modes) {
-		fprintf(stderr, "connector %d has no modes\n", o->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (connector->connector_id != o->id) {
-		fprintf(stderr, "connector id doesn't match (%d != %d)\n",
-			connector->connector_id, o->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	for (j = 0; j < connector->count_modes; j++) {
-		o->mode = connector->modes[j];
-		if (o->mode.type & DRM_MODE_TYPE_PREFERRED) {
-			o->mode_valid = 1;
-			break;
-		}
-	}
-
-	if (!o->mode_valid) {
-		if (connector->count_modes > 0) {
-			/* use the first mode as test mode */
-			o->mode = connector->modes[0];
-			o->mode_valid = 1;
-		}
-		else {
-			fprintf(stderr, "failed to find any modes on connector %d\n",
-				o->id);
-			return;
-		}
-	}
+	struct kmstest_connector_config config;
 
-	/* Now get the encoder */
-	for (i = 0; i < connector->count_encoders; i++) {
-		encoder = drmModeGetEncoder(drm_fd, connector->encoders[i]);
-
-		if (!encoder) {
-			fprintf(stderr, "could not get encoder %i: %s\n",
-				resources->encoders[i], strerror(errno));
-			drmModeFreeEncoder(encoder);
-			continue;
-		}
-
-		break;
-	}
-
-	o->encoder = encoder;
-
-	if (i == resources->count_encoders) {
-		fprintf(stderr, "failed to find encoder\n");
-		o->mode_valid = 0;
-		return;
-	}
-
-	/* Find first CRTC not in use */
-	for (i = 0; i < resources->count_crtcs; i++) {
-		if (resources->crtcs[i] != crtc_id)
-			continue;
-		if (resources->crtcs[i] &&
-		    (o->encoder->possible_crtcs & (1<<i))) {
-			o->crtc = resources->crtcs[i];
-			break;
-		}
-	}
-
-	if (!o->crtc) {
-		fprintf(stderr, "could not find requested crtc %d\n", crtc_id);
+	if (kmstest_get_connector_config(drm_fd, connector_id, 1 << crtc_idx,
+					 &config) < 0) {
 		o->mode_valid = 0;
 		return;
 	}
 
-	o->connector = connector;
+	o->connector = config.connector;
+	o->encoder = config.encoder;
+	o->crtc = config.crtc->crtc_id;
+	o->pipe = config.pipe;
+	o->mode = config.default_mode;
+	o->mode_valid = 1;
 }
 
 static void
@@ -1042,21 +968,21 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)
 	return end - start;
 }
 
-static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
+static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
 {
 	unsigned ellapsed;
 
 	o->bpp = 32;
 	o->depth = 24;
 
-	connector_find_preferred_mode(o, crtc);
+	connector_find_preferred_mode(o->id, crtc_idx, o);
 	if (!o->mode_valid)
 		return;
 
 	last_connector = o->connector;
 
 	fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
-		o->test_name, crtc, o->id);
+		o->test_name, o->crtc, o->id);
 
 	o->fb_width = o->mode.hdisplay;
 	o->fb_height = o->mode.vdisplay;
@@ -1116,7 +1042,7 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
 		check_final_state(o, &o->vblank_state, ellapsed);
 
 	fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
-		o->test_name, crtc, o->id);
+		o->test_name, o->crtc, o->id);
 
 	kmstest_remove_fb(drm_fd, o->fb_ids[2]);
 	kmstest_remove_fb(drm_fd, o->fb_ids[1]);
@@ -1131,7 +1057,8 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
 static int run_test(int duration, int flags, const char *test_name)
 {
 	struct test_output o;
-	int c, i;
+	int c;
+	int crtc_idx;
 
 	resources = drmModeGetResources(drm_fd);
 	if (!resources) {
@@ -1142,19 +1069,15 @@ static int run_test(int duration, int flags, const char *test_name)
 
 	/* Find any connected displays */
 	for (c = 0; c < resources->count_connectors; c++) {
-		for (i = 0; i < resources->count_crtcs; i++) {
-			int crtc;
-
+		for (crtc_idx = 0; crtc_idx < resources->count_crtcs; crtc_idx++) {
 			memset(&o, 0, sizeof(o));
 			o.test_name = test_name;
 			o.id = resources->connectors[c];
 			o.flags = flags;
 			o.flip_state.name = "flip";
 			o.vblank_state.name = "vblank";
-			crtc = resources->crtcs[i];
-			o.pipe = kmstest_get_pipe_from_crtc_id(drm_fd, crtc);
 
-			run_test_on_crtc(&o, crtc, duration);
+			run_test_on_crtc(&o, crtc_idx, duration);
 		}
 	}
 
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index b10c3b9..4470339 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -102,6 +102,7 @@ struct connector {
 	drmModeEncoder *encoder;
 	drmModeConnector *connector;
 	int crtc;
+	int crtc_idx;
 	int pipe;
 };
 
@@ -185,101 +186,31 @@ static void dump_crtcs_fd(int drmfd)
 	drmModeFreeResources(mode_resources);
 }
 
-static void connector_find_preferred_mode(struct connector *c)
+static void connector_find_preferred_mode(uint32_t connector_id,
+					  unsigned long crtc_idx_mask,
+					  int mode_num, struct connector *c)
 {
-	drmModeConnector *connector;
-	drmModeEncoder *encoder = NULL;
-	int i, j;
-
-	/* First, find the connector & mode */
-	c->mode_valid = 0;
-	connector = drmModeGetConnector(drm_fd, c->id);
-	if (!connector) {
-		fprintf(stderr, "could not get connector %d: %s\n",
-			c->id, strerror(errno));
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (connector->connection != DRM_MODE_CONNECTED) {
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (!connector->count_modes) {
-		fprintf(stderr, "connector %d has no modes\n", c->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (connector->connector_id != c->id) {
-		fprintf(stderr, "connector id doesn't match (%d != %d)\n",
-			connector->connector_id, c->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	for (j = 0; j < connector->count_modes; j++) {
-		c->mode = connector->modes[j];
-		if (c->mode.type & DRM_MODE_TYPE_PREFERRED) {
-			c->mode_valid = 1;
-			break;
-		}
-	}
-
-	if ( specified_mode_num != -1 ){
-		c->mode = connector->modes[specified_mode_num];
-		if (c->mode.type & DRM_MODE_TYPE_PREFERRED)
-			c->mode_valid = 1;
-	}
-
-	if (!c->mode_valid) {
-		if (connector->count_modes > 0) {
-			/* use the first mode as test mode */
-			c->mode = connector->modes[0];
-			c->mode_valid = 1;
-		}
-		else {
-			fprintf(stderr, "failed to find any modes on connector %d\n",
-				c->id);
-			return;
-		}
-	}
-
-	/* Now get the encoder */
-	for (i = 0; i < connector->count_encoders; i++) {
-		encoder = drmModeGetEncoder(drm_fd, connector->encoders[i]);
-
-		if (!encoder) {
-			fprintf(stderr, "could not get encoder %i: %s\n",
-				resources->encoders[i], strerror(errno));
-			drmModeFreeEncoder(encoder);
-			continue;
-		}
-
-		break;
-	}
-
-	c->encoder = encoder;
+	struct kmstest_connector_config config;
 
-	if (i == resources->count_encoders) {
-		fprintf(stderr, "failed to find encoder\n");
+	if (kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask,
+					 &config) < 0) {
 		c->mode_valid = 0;
 		return;
 	}
 
-	/* Find first CRTC not in use */
-	for (i = 0; i < resources->count_crtcs; i++) {
-		if (resources->crtcs[i] && (c->encoder->possible_crtcs & (1<<i)))
-			break;
+	c->connector = config.connector;
+	c->encoder = config.encoder;
+	c->crtc = config.crtc->crtc_id;
+	c->crtc_idx = config.crtc_idx;
+	c->pipe = config.pipe;
+
+	if (mode_num != -1) {
+		assert(mode_num < config.connector->count_modes);
+		c->mode = config.connector->modes[mode_num];
+	} else {
+		c->mode = config.default_mode;
 	}
-	c->crtc = resources->crtcs[i];
-	c->pipe = i;
-
-	if(test_preferred_mode || force_mode || specified_mode_num != -1)
-		resources->crtcs[i] = 0;
-
-	c->connector = connector;
+	c->mode_valid = 1;
 }
 
 static void
@@ -409,10 +340,6 @@ set_mode(struct connector *c)
 	else if (depth > 16 && depth <= 32)
 		bpp = 32;
 
-	connector_find_preferred_mode(c);
-	if (!c->mode_valid)
-		return;
-
 	test_mode_num = 1;
 	if (force_mode){
 		memcpy( &c->mode, &force_timing, sizeof(force_timing));
@@ -506,13 +433,30 @@ int update_display(void)
 	}
 
 	if (test_preferred_mode || test_all_modes || force_mode || specified_disp_id != -1) {
+		unsigned long crtc_idx_mask = -1UL;
+
 		/* Find any connected displays */
 		for (c = 0; c < resources->count_connectors; c++) {
-			connectors[c].id = resources->connectors[c];
-			if ( specified_disp_id != -1 && connectors[c].id != specified_disp_id )
+			struct connector *connector = &connectors[c];
+
+			connector->id = resources->connectors[c];
+			if (specified_disp_id != -1 &&
+			    connector->id != specified_disp_id)
+				continue;
+
+			connector_find_preferred_mode(connector->id,
+						      crtc_idx_mask,
+						      specified_mode_num,
+						      connector);
+			if (!connector->mode_valid)
 				continue;
 
-			set_mode(&connectors[c]);
+			set_mode(connector);
+
+			if (test_preferred_mode || force_mode ||
+			    specified_mode_num != -1)
+				crtc_idx_mask &= ~(1 << connector->crtc_idx);
+
 		}
 	}
 	drmModeFreeResources(resources);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [igt PATCH 4/5] lib: refactor kmstest_create_fb
  2013-05-31  9:23 [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Imre Deak
  2013-05-31  9:23 ` [igt PATCH 2/5] lib: add kmstest_cairo_printf_line Imre Deak
  2013-05-31  9:23 ` [igt PATCH 3/5] lib: add kmstest_get_connector_config Imre Deak
@ 2013-05-31  9:23 ` Imre Deak
  2013-06-05 18:21   ` Rodrigo Vivi
  2013-05-31  9:23 ` [igt PATCH 5/5] tests: add kms_render Imre Deak
  2013-06-05 17:40 ` [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Rodrigo Vivi
  4 siblings, 1 reply; 22+ messages in thread
From: Imre Deak @ 2013-05-31  9:23 UTC (permalink / raw)
  To: intel-gfx

Factor out parts that will be used by an upcoming patch adding
kmstest_create_fb2.

Also call the fb paint functions directly, there is not much
point in passing a function pointer for that.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/drmtest.c       | 176 ++++++++++++++++++++++++++++++++--------------------
 lib/drmtest.h       |  15 +++--
 tests/kms_flip.c    |  30 +++++----
 tests/testdisplay.c |  15 +++--
 4 files changed, 147 insertions(+), 89 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 7368077..a551e7c 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -39,6 +39,7 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include <linux/kd.h>
+#include <drm/drm_fourcc.h>
 
 #include "drmtest.h"
 #include "i915_drm.h"
@@ -788,16 +789,14 @@ void drmtest_cleanup_aperture_trashers(void)
 }
 
 /* helpers to create nice-looking framebuffers */
-static cairo_surface_t *
-paint_allocate_surface(int fd, int width, int height, int depth, int bpp,
-		       bool tiled,
-		       struct kmstest_fb *fb_info)
+static int create_bo_for_fb(int fd, int width, int height, int bpp,
+			    bool tiled, uint32_t *gem_handle_ret,
+			    unsigned *size_ret, unsigned *stride_ret)
 {
-	cairo_format_t format;
 	struct drm_i915_gem_set_tiling set_tiling;
+	uint32_t gem_handle;
 	int size;
 	unsigned stride;
-	uint32_t *fb_ptr;
 
 	if (tiled) {
 		int v;
@@ -823,49 +822,24 @@ paint_allocate_surface(int fd, int width, int height, int depth, int bpp,
 		size = stride * height;
 	}
 
-	switch (depth) {
-	case 16:
-		format = CAIRO_FORMAT_RGB16_565;
-		break;
-	case 24:
-		format = CAIRO_FORMAT_RGB24;
-		break;
-#if 0
-	case 30:
-		format = CAIRO_FORMAT_RGB30;
-		break;
-#endif
-	case 32:
-		format = CAIRO_FORMAT_ARGB32;
-		break;
-	default:
-		fprintf(stderr, "bad depth %d\n", depth);
-		return NULL;
-	}
-
-	assert (bpp >= depth);
-
-	fb_info->gem_handle = gem_create(fd, size);
+	gem_handle = gem_create(fd, size);
 
 	if (tiled) {
-		set_tiling.handle = fb_info->gem_handle;
+		set_tiling.handle = gem_handle;
 		set_tiling.tiling_mode = I915_TILING_X;
 		set_tiling.stride = stride;
 		if (ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling)) {
 			fprintf(stderr, "set tiling failed: %s (stride=%d, size=%d)\n",
 				strerror(errno), stride, size);
-			return NULL;
+			return -1;
 		}
 	}
 
-	fb_ptr = gem_mmap(fd, fb_info->gem_handle, size, PROT_READ | PROT_WRITE);
-
-	fb_info->stride = stride;
-	fb_info->size = size;
+	*stride_ret = stride;
+	*size_ret = size;
+	*gem_handle_ret = gem_handle;
 
-	return cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
-						   format, width, height,
-						   stride);
+	return 0;
 }
 
 static void
@@ -981,23 +955,8 @@ paint_marker(cairo_t *cr, int x, int y)
 	kmstest_cairo_printf_line(cr, align, 0, "(%d, %d)", x, y);
 }
 
-unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
-			       int depth, bool tiled,
-			       struct kmstest_fb *fb_info,
-			       kmstest_paint_func paint_func,
-			       void *func_arg)
+void kmstest_paint_test_pattern(cairo_t *cr, int width, int height)
 {
-	cairo_surface_t *surface;
-	cairo_status_t status;
-	cairo_t *cr;
-	unsigned int fb_id;
-
-	surface = paint_allocate_surface(fd, width, height, depth, bpp,
-					 tiled, fb_info);
-	assert(surface);
-
-	cr = cairo_create(surface);
-
 	paint_test_patterns(cr, width, height);
 
 	cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
@@ -1008,27 +967,112 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 	paint_marker(cr, 0, height);
 	paint_marker(cr, width, height);
 
-	if (paint_func)
-		paint_func(cr, width, height, func_arg);
+	assert(!cairo_status(cr));
+}
+
+#define DF(did, cid, _bpp, _depth)	\
+	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
+static struct format_desc_struct {
+	uint32_t drm_id;
+	cairo_format_t cairo_id;
+	const char *name;
+	int bpp;
+	int depth;
+} format_desc[] = {
+	DF(RGB565,	RGB16_565,	16, 16),
+	DF(RGB888,	INVALID,	24, 24),
+	DF(XRGB8888,	RGB24,		32, 24),
+	DF(XRGB2101010,	RGB30,		32, 30),
+	DF(ARGB8888,	ARGB32,		32, 32),
+};
+#undef DF
+
+#define for_each_format(f)	\
+	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
+
+static uint32_t bpp_depth_to_drm_format(int bpp, int depth)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->bpp == bpp && f->depth == depth)
+			return f->drm_id;
+
+	abort();
+}
+
+/* Return fb_id on success, 0 on error */
+unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
+			       int depth, bool tiled, struct kmstest_fb *fb)
+{
+	memset(fb, 0, sizeof(*fb));
 
-	status = cairo_status(cr);
-	assert(!status);
-	cairo_destroy(cr);
+	if (create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
+			       &fb->size, &fb->stride) < 0)
+		return 0;
+
+	if (drmModeAddFB(fd, width, height, depth, bpp, fb->stride,
+			       fb->gem_handle, &fb->fb_id) < 0) {
+		gem_close(fd, fb->gem_handle);
+
+		return 0;
+	}
+
+	fb->width = width;
+	fb->height = height;
+	fb->drm_format = bpp_depth_to_drm_format(bpp, depth);
+
+	return fb->fb_id;
+}
+
+static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
 
-	do_or_die(drmModeAddFB(fd, width, height, depth, bpp,
-			       fb_info->stride,
-			       fb_info->gem_handle, &fb_id));
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->cairo_id;
 
+	abort();
+}
+
+static cairo_t *create_cairo_ctx(int fd, struct kmstest_fb *fb)
+{
+	cairo_t *cr;
+	cairo_surface_t *surface;
+	cairo_format_t cformat;
+	void *fb_ptr;
+
+	cformat = drm_format_to_cairo(fb->drm_format);
+	fb_ptr = gem_mmap(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
+	surface = cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
+						   cformat, fb->width,
+						   fb->height, fb->stride);
+	assert(surface);
+	cr = cairo_create(surface);
 	cairo_surface_destroy(surface);
 
-	fb_info->fb_id = fb_id;
+	return cr;
+}
+
+cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb)
+{
+
+	if (!fb->cairo_ctx)
+		fb->cairo_ctx = create_cairo_ctx(fd, fb);
+
+	gem_set_domain(fd, fb->gem_handle, I915_GEM_DOMAIN_CPU,
+		       I915_GEM_DOMAIN_CPU);
 
-	return fb_id;
+	return fb->cairo_ctx;
 }
 
-void kmstest_remove_fb(int fd, int fb_id)
+void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
 {
-	do_or_die(drmModeRmFB(fd, fb_id));
+	if (fb->cairo_ctx)
+		cairo_destroy(fb->cairo_ctx);
+	do_or_die(drmModeRmFB(fd, fb->fb_id));
+	gem_close(fd, fb->gem_handle);
 }
 
 struct type_name {
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 89ded11..218914f 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -119,8 +119,13 @@ void kmstest_free_connector_config(struct kmstest_connector_config *config);
 struct kmstest_fb {
 	uint32_t fb_id;
 	uint32_t gem_handle;
+	uint32_t drm_format;
+	int width;
+	int height;
+	int depth;
 	unsigned stride;
 	unsigned size;
+	cairo_t *cairo_ctx;
 };
 
 enum kmstest_text_align {
@@ -136,14 +141,12 @@ 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,
 			       int depth, bool tiled,
-			       struct kmstest_fb *fb_info,
-			       kmstest_paint_func paint_func,
-			       void *func_arg);
-void kmstest_remove_fb(int fd, int fb_id);
+			       struct kmstest_fb *fb_info);
+void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
+cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
+void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
 void kmstest_dump_mode(drmModeModeInfo *mode);
 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
 const char *kmstest_encoder_type_str(int type);
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index c9b3d8a..aeeaace 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -844,10 +844,13 @@ static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
 	o->mode_valid = 1;
 }
 
-static void
-paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
+static void paint_flip_mode(struct kmstest_fb *fb, bool odd_frame)
 {
-	bool odd_frame = (bool) priv;
+	cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
+	int width = fb->width;
+	int height = fb->height;
+
+	kmstest_paint_test_pattern(cr, width, height);
 
 	if (odd_frame)
 		cairo_rectangle(cr, width/4, height/2, width/4, height/8);
@@ -856,6 +859,8 @@ paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
 
 	cairo_set_source_rgb(cr, 1, 1, 1);
 	cairo_fill(cr);
+
+	assert(!cairo_status(cr));
 }
 
 static int
@@ -991,20 +996,21 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
 		o->fb_width *= 2;
 
 	o->fb_ids[0] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
-					 o->bpp, o->depth, false, &o->fb_info[0],
-					 paint_flip_mode, (void *)false);
+					 o->bpp, o->depth, false, &o->fb_info[0]);
 	o->fb_ids[1] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
-					 o->bpp, o->depth, false, &o->fb_info[1],
-					 paint_flip_mode, (void *)true);
+					 o->bpp, o->depth, false, &o->fb_info[1]);
 	o->fb_ids[2] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
-					 o->bpp, o->depth, true, &o->fb_info[2],
-					 paint_flip_mode, (void *)true);
+					 o->bpp, o->depth, true, &o->fb_info[2]);
 
 	if (!o->fb_ids[0] || !o->fb_ids[1] || !o->fb_ids[2]) {
 		fprintf(stderr, "failed to create fbs\n");
 		exit(3);
 	}
 
+	paint_flip_mode(&o->fb_info[0], false);
+	paint_flip_mode(&o->fb_info[1], true);
+	paint_flip_mode(&o->fb_info[2], true);
+
 	set_y_tiling(o, 2);
 
 	kmstest_dump_mode(&o->mode);
@@ -1044,9 +1050,9 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
 	fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
 		o->test_name, o->crtc, o->id);
 
-	kmstest_remove_fb(drm_fd, o->fb_ids[2]);
-	kmstest_remove_fb(drm_fd, o->fb_ids[1]);
-	kmstest_remove_fb(drm_fd, o->fb_ids[0]);
+	kmstest_remove_fb(drm_fd, &o->fb_info[2]);
+	kmstest_remove_fb(drm_fd, &o->fb_info[1]);
+	kmstest_remove_fb(drm_fd, &o->fb_info[0]);
 
 	last_connector = NULL;
 
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 4470339..5ece921 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -258,15 +258,18 @@ static void paint_image(cairo_t *cr, const char *file)
 	cairo_surface_destroy(image);
 }
 
-static void
-paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
+static void paint_output_info(struct connector *c, struct kmstest_fb *fb)
 {
-	struct connector *c = priv;
+	cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
+	int l_width = fb->width;
+	int l_height = fb->height;
 	double str_width;
 	double x, y, top_y;
 	double max_width;
 	int i;
 
+	kmstest_paint_test_pattern(cr, l_width, l_height);
+
 	cairo_select_font_face(cr, "Helvetica",
 			       CAIRO_FONT_SLANT_NORMAL,
 			       CAIRO_FONT_WEIGHT_NORMAL);
@@ -308,6 +311,8 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	if (qr_code)
 		paint_image(cr, "./pass.png");
+
+	assert(!cairo_status(cr));
 }
 
 static void sighandler(int signo)
@@ -362,8 +367,8 @@ set_mode(struct connector *c)
 		height = c->mode.vdisplay;
 
 		fb_id = kmstest_create_fb(drm_fd, width, height, bpp, depth,
-					  enable_tiling, &fb_info,
-					  paint_output_info, c);
+					  enable_tiling, &fb_info);
+		paint_output_info(c, &fb_info);
 
 		fb_ptr = gem_mmap(drm_fd, fb_info.gem_handle,
 				  fb_info.size, PROT_READ | PROT_WRITE);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [igt PATCH 5/5] tests: add kms_render
  2013-05-31  9:23 [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Imre Deak
                   ` (2 preceding siblings ...)
  2013-05-31  9:23 ` [igt PATCH 4/5] lib: refactor kmstest_create_fb Imre Deak
@ 2013-05-31  9:23 ` Imre Deak
  2013-06-05 18:28   ` Rodrigo Vivi
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
  2013-06-05 17:40 ` [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Rodrigo Vivi
  4 siblings, 2 replies; 22+ messages in thread
From: Imre Deak @ 2013-05-31  9:23 UTC (permalink / raw)
  To: intel-gfx

Add a test going through all connectors/crtcs/modes/formats painting to
a front FB with CPU or painting to a back FB with CPU and blitting it
to the front FB.

Only formats understood by cairo are supported for now.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/drmtest.c      | 101 ++++++++++++++++++++--
 lib/drmtest.h      |   7 ++
 tests/.gitignore   |   1 +
 tests/Makefile.am  |   1 +
 tests/kms_render.c | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 349 insertions(+), 6 deletions(-)
 create mode 100644 tests/kms_render.c

diff --git a/lib/drmtest.c b/lib/drmtest.c
index a551e7c..d9d58e5 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -842,8 +842,8 @@ static int create_bo_for_fb(int fd, int width, int height, int bpp,
 	return 0;
 }
 
-static void
-paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
+void
+kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
 		     int r, int g, int b)
 {
 	cairo_pattern_t *pat;
@@ -869,16 +869,16 @@ paint_test_patterns(cairo_t *cr, int width, int height)
 	gr_height = height * 0.08;
 	x = (width / 2) - (gr_width / 2);
 
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
+	kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
 
 	y += gr_height;
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
+	kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
 
 	y += gr_height;
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
+	kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
 
 	y += gr_height;
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
+	kmstest_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,
@@ -1025,6 +1025,55 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 	return fb->fb_id;
 }
 
+static uint32_t drm_format_to_bpp(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->bpp;
+
+	abort();
+}
+
+unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
+			        bool tiled, struct kmstest_fb *fb)
+{
+	uint32_t handles[4];
+	uint32_t pitches[4];
+	uint32_t offsets[4];
+	uint32_t fb_id;
+	int bpp;
+	int ret;
+
+	memset(fb, 0, sizeof(*fb));
+
+	bpp = drm_format_to_bpp(format);
+	ret = create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
+			      &fb->size, &fb->stride);
+	if (ret < 0)
+		return ret;
+
+	memset(handles, 0, sizeof(handles));
+	handles[0] = fb->gem_handle;
+	memset(pitches, 0, sizeof(pitches));
+	pitches[0] = fb->stride;
+	memset(offsets, 0, sizeof(offsets));
+	if (drmModeAddFB2(fd, width, height, format, handles, pitches,
+			  offsets, &fb_id, 0) < 0) {
+		gem_close(fd, fb->gem_handle);
+
+		return 0;
+	}
+
+	fb->width = width;
+	fb->height = height;
+	fb->drm_format = format;
+	fb->fb_id = fb_id;
+
+	return fb_id;
+}
+
 static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 {
 	struct format_desc_struct *f;
@@ -1075,6 +1124,46 @@ void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
 	gem_close(fd, fb->gem_handle);
 }
 
+const char *kmstest_format_str(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->name;
+
+	return "invalid";
+}
+
+const char *kmstest_pipe_str(int pipe)
+{
+	const char *str[] = { "A", "B", "C" };
+
+	if (pipe > 2)
+		return "invalid";
+
+	return str[pipe];
+}
+
+void kmstest_get_all_formats(const uint32_t **formats, int *format_count)
+{
+	static uint32_t *drm_formats;
+
+	if (!drm_formats) {
+		struct format_desc_struct *f;
+		uint32_t *format;
+
+		drm_formats = calloc(ARRAY_SIZE(format_desc),
+				     sizeof(*drm_formats));
+		format = &drm_formats[0];
+		for_each_format(f)
+			*format++ = f->drm_id;
+	}
+
+	*formats = drm_formats;
+	*format_count = ARRAY_SIZE(format_desc);
+}
+
 struct type_name {
 	int type;
 	const char *name;
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 218914f..e3a9275 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -144,11 +144,18 @@ int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
 unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 			       int depth, bool tiled,
 			       struct kmstest_fb *fb_info);
+unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
+			        bool tiled, struct kmstest_fb *fb);
 void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
 cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
+void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
+				  int r, int g, int b);
 void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
 void kmstest_dump_mode(drmModeModeInfo *mode);
 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
+const char *kmstest_format_str(uint32_t drm_format);
+const char *kmstest_pipe_str(int pipe);
+void kmstest_get_all_formats(const uint32_t **formats, int *format_count);
 const char *kmstest_encoder_type_str(int type);
 const char *kmstest_connector_status_str(int type);
 const char *kmstest_connector_type_str(int type);
diff --git a/tests/.gitignore b/tests/.gitignore
index 3cac813..1f7c691 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -85,6 +85,7 @@ getclient
 getstats
 getversion
 kms_flip
+kms_render
 prime_nv_api
 prime_nv_pcopy
 prime_nv_test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7250968..3f301c9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,6 +33,7 @@ TESTS_progs_M = \
 	gem_tiled_partial_pwrite_pread \
 	$(NOUVEAU_TESTS_M) \
 	kms_flip \
+	kms_render \
 	prime_self_import \
 	$(NULL)
 
diff --git a/tests/kms_render.c b/tests/kms_render.c
new file mode 100644
index 0000000..707ce27
--- /dev/null
+++ b/tests/kms_render.c
@@ -0,0 +1,245 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Imre Deak <imre.deak@intel.com>
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <cairo.h>
+#include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include "drmtest.h"
+#include "testdisplay.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_gpu_tools.h"
+
+drmModeRes *resources;
+int drm_fd;
+static drm_intel_bufmgr *bufmgr;
+struct intel_batchbuffer *batch;
+uint32_t devid;
+
+enum test_flags {
+	TEST_DIRECT_RENDER	= 0x01,
+	TEST_GPU_BLIT		= 0x02,
+};
+
+static int paint_fb(struct kmstest_fb *fb, const char *test_name,
+		    const char *mode_format_str, const char *cconf_str)
+{
+	cairo_t *cr;
+
+	cr = kmstest_get_cairo_ctx(drm_fd, fb);
+	if (!cr)
+		return -1;
+
+	kmstest_paint_color_gradient(cr, 0, 0, fb->width, fb->height, 1, 1, 1);
+	kmstest_paint_test_pattern(cr, fb->width, fb->height);
+
+	cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
+			       CAIRO_FONT_WEIGHT_NORMAL);
+	cairo_move_to(cr, fb->width / 2, fb->height / 2);
+	cairo_set_font_size(cr, 36);
+	kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
+	kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
+	kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
+
+	return 0;
+}
+
+static void gpu_blit(struct kmstest_fb *dst_fb, struct kmstest_fb *src_fb)
+{
+	drm_intel_bo *dst_bo;
+	drm_intel_bo *src_bo;
+
+	dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
+					 dst_fb->gem_handle);
+	assert(dst_bo);
+	src_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "source",
+					 src_fb->gem_handle);
+	assert(src_bo);
+
+	intel_copy_bo(batch, dst_bo, src_bo, src_fb->width, src_fb->height);
+	intel_batchbuffer_flush(batch);
+	gem_quiescent_gpu(drm_fd);
+
+	drm_intel_bo_unreference(src_bo);
+	drm_intel_bo_unreference(dst_bo);
+}
+
+static int test_format(const char *test_name,
+		       struct kmstest_connector_config *cconf,
+		       drmModeModeInfo *mode, uint32_t format,
+		       enum test_flags flags)
+{
+	int width;
+	int height;
+	struct kmstest_fb fb[2];
+	char *mode_format_str;
+	char *cconf_str;
+	int ret;
+
+	ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
+		 mode->name, mode->vrefresh, kmstest_format_str(format));
+	assert(ret > 0);
+	ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
+		       kmstest_pipe_str(cconf->pipe),
+		       kmstest_encoder_type_str(cconf->encoder->encoder_type),
+		       kmstest_connector_type_str(cconf->connector->connector_type));
+	assert(ret > 0);
+
+	printf("Beginning test %s with %s on %s\n",
+		test_name, mode_format_str, cconf_str);
+
+	width = mode->hdisplay;
+	height = mode->vdisplay;
+
+	if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[0]))
+		goto err1;
+
+	if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[1]))
+		goto err2;
+
+	do_or_die(drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
+				 0, 0, &cconf->connector->connector_id, 1,
+				 mode));
+	do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
+				  0, NULL));
+	sleep(2);
+
+	if (flags & TEST_DIRECT_RENDER) {
+		paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
+	} else if (flags & TEST_GPU_BLIT) {
+		paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
+		gpu_blit(&fb[0], &fb[1]);
+	}
+	sleep(5);
+
+	printf("Test %s with %s on %s: PASSED\n",
+		test_name, mode_format_str, cconf_str);
+	free(mode_format_str);
+	free(cconf_str);
+
+	kmstest_remove_fb(drm_fd, &fb[1]);
+	kmstest_remove_fb(drm_fd, &fb[0]);
+
+	return 0;
+
+err2:
+	kmstest_remove_fb(drm_fd, &fb[0]);
+err1:
+	fprintf(stderr, "skip testing unsupported format %s\n",
+		kmstest_format_str(format));
+
+	return -1;
+}
+
+static void test_connector(const char *test_name,
+			   struct kmstest_connector_config *cconf,
+			   enum test_flags flags)
+{
+	const uint32_t *formats;
+	int format_count;
+	int i;
+
+	kmstest_get_all_formats(&formats, &format_count);
+	for (i = 0; i < cconf->connector->count_modes; i++) {
+		int j;
+
+		for (j = 0; j < format_count; j++)
+			test_format(test_name,
+				    cconf, &cconf->connector->modes[i],
+				    formats[j], flags);
+	}
+}
+
+static int run_test(const char *test_name, enum test_flags flags)
+{
+	int i;
+
+	resources = drmModeGetResources(drm_fd);
+	assert(resources);
+
+	/* Find any connected displays */
+	for (i = 0; i < resources->count_connectors; i++) {
+		uint32_t connector_id;
+		int j;
+
+		connector_id = resources->connectors[i];
+		for (j = 0; j < resources->count_crtcs; j++) {
+			struct kmstest_connector_config cconf;
+			int ret;
+
+			ret = kmstest_get_connector_config(drm_fd, connector_id,
+							   1 << j, &cconf);
+			if (ret < 0)
+				continue;
+
+			test_connector(test_name, &cconf, flags);
+
+			kmstest_free_connector_config(&cconf);
+		}
+	}
+
+	drmModeFreeResources(resources);
+
+	return 1;
+}
+
+int main(int argc, char **argv)
+{
+	struct {
+		enum test_flags flags;
+		const char *name;
+	} tests[] = {
+		{ TEST_DIRECT_RENDER,	"direct-render" },
+		{ TEST_GPU_BLIT,	"gpu-blit" },
+	};
+	int i;
+
+	drmtest_subtest_init(argc, argv);
+
+	if (!drmtest_only_list_subtests()) {
+		drm_fd = drm_open_any();
+
+		bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
+		devid = intel_get_drm_devid(drm_fd);
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+
+		do_or_die(drmtest_set_vt_graphics_mode());
+	}
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (drmtest_run_subtest(tests[i].name))
+			run_test(tests[i].name, tests[i].flags);
+	}
+
+	if (!drmtest_only_list_subtests())
+		close(drm_fd);
+
+	return 0;
+}
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 1/5] lib: move connector_type_str and co to drmtest
  2013-05-31  9:23 [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Imre Deak
                   ` (3 preceding siblings ...)
  2013-05-31  9:23 ` [igt PATCH 5/5] tests: add kms_render Imre Deak
@ 2013-06-05 17:40 ` Rodrigo Vivi
  4 siblings, 0 replies; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 17:40 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

On Fri, May 31, 2013 at 6:23 AM, Imre Deak <imre.deak@intel.com> wrote:
> These are used by multiple test cases, so make them shared.
>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  demos/intel_sprite_on.c | 58 ++++------------------------------------------
>  lib/drmtest.c           | 54 +++++++++++++++++++++++++++++++++++++++++++
>  lib/drmtest.h           |  3 +++
>  tests/testdisplay.c     | 61 ++++---------------------------------------------
>  4 files changed, 65 insertions(+), 111 deletions(-)
>
> diff --git a/demos/intel_sprite_on.c b/demos/intel_sprite_on.c
> index 62bd98e..783f9af 100644
> --- a/demos/intel_sprite_on.c
> +++ b/demos/intel_sprite_on.c
> @@ -53,56 +53,6 @@
>
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
>
> -struct type_name {
> -       int                 type;
> -       const char          *name;
> -};
> -
> -#define type_name_fn(res) \
> -       static const char * res##_str(int type) {               \
> -               unsigned int i;                                 \
> -               for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
> -                       if (res##_names[i].type == type)        \
> -                       return res##_names[i].name;             \
> -               }                                               \
> -               return "(invalid)";                             \
> -       }
> -
> -struct type_name encoder_type_names[] = {
> -       { DRM_MODE_ENCODER_NONE, "none" },
> -       { DRM_MODE_ENCODER_DAC, "DAC" },
> -       { DRM_MODE_ENCODER_TMDS, "TMDS" },
> -       { DRM_MODE_ENCODER_LVDS, "LVDS" },
> -       { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
> -};
> -type_name_fn(encoder_type)
> -
> -struct type_name connector_status_names[] = {
> -       { DRM_MODE_CONNECTED, "connected" },
> -       { DRM_MODE_DISCONNECTED, "disconnected" },
> -       { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
> -};
> -type_name_fn(connector_status)
> -
> -struct type_name connector_type_names[] = {
> -       { DRM_MODE_CONNECTOR_Unknown, "unknown" },
> -       { DRM_MODE_CONNECTOR_VGA, "VGA" },
> -       { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
> -       { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
> -       { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
> -       { DRM_MODE_CONNECTOR_Composite, "composite" },
> -       { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
> -       { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
> -       { DRM_MODE_CONNECTOR_Component, "component" },
> -       { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
> -       { DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
> -       { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
> -       { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
> -       { DRM_MODE_CONNECTOR_TV, "TV" },
> -       { DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
> -};
> -type_name_fn(connector_type)
> -
>  /*
>   * Mode setting with the kernel interfaces is a bit of a chore.
>   * First you have to find the connector in question and make sure the
> @@ -157,8 +107,8 @@ static void dump_connectors(int gfx_fd, drmModeRes *resources)
>                 printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
>                         connector->connector_id,
>                         connector->encoder_id,
> -                       connector_status_str(connector->connection),
> -                       connector_type_str(connector->connector_type),
> +                       kmstest_connector_status_str(connector->connection),
> +                       kmstest_connector_type_str(connector->connector_type),
>                         connector->mmWidth, connector->mmHeight,
>                         connector->count_modes);
>
> @@ -744,14 +694,14 @@ static void ricochet(int tiled, int sprite_w, int sprite_h,
>                                 curr_connector.mode.flags,
>                                 curr_connector.encoder->encoder_id,
>                                 curr_connector.encoder->encoder_type,
> -                               encoder_type_str(curr_connector.encoder->encoder_type),
> +                               kmstest_encoder_type_str(curr_connector.encoder->encoder_type),
>                                 curr_connector.encoder->crtc_id,
>                                 curr_connector.encoder->possible_crtcs,
>                                 curr_connector.encoder->possible_clones,
>                                 curr_connector.connector->connector_id,
>                                 curr_connector.connector->encoder_id,
>                                 curr_connector.connector->connector_type,
> -                               connector_type_str(curr_connector.connector->connector_type),
> +                               kmstest_connector_type_str(curr_connector.connector->connector_type),
>                                 curr_connector.connector->connector_type_id);
>
>                         printf("Sprite surface dimensions = %dx%d\n"
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index d17dbb0..3c4812f 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -1023,6 +1023,60 @@ void kmstest_remove_fb(int fd, int fb_id)
>         do_or_die(drmModeRmFB(fd, fb_id));
>  }
>
> +struct type_name {
> +       int type;
> +       const char *name;
> +};
> +
> +#define type_name_fn(res) \
> +const char * kmstest_##res##_str(int type) {           \
> +       unsigned int i;                                 \
> +       for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
> +               if (res##_names[i].type == type)        \
> +                       return res##_names[i].name;     \
> +       }                                               \
> +       return "(invalid)";                             \
> +}
> +
> +struct type_name encoder_type_names[] = {
> +       { DRM_MODE_ENCODER_NONE, "none" },
> +       { DRM_MODE_ENCODER_DAC, "DAC" },
> +       { DRM_MODE_ENCODER_TMDS, "TMDS" },
> +       { DRM_MODE_ENCODER_LVDS, "LVDS" },
> +       { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
> +};
> +
> +type_name_fn(encoder_type)
> +
> +struct type_name connector_status_names[] = {
> +       { DRM_MODE_CONNECTED, "connected" },
> +       { DRM_MODE_DISCONNECTED, "disconnected" },
> +       { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
> +};
> +
> +type_name_fn(connector_status)
> +
> +struct type_name connector_type_names[] = {
> +       { DRM_MODE_CONNECTOR_Unknown, "unknown" },
> +       { DRM_MODE_CONNECTOR_VGA, "VGA" },
> +       { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
> +       { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
> +       { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
> +       { DRM_MODE_CONNECTOR_Composite, "composite" },
> +       { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
> +       { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
> +       { DRM_MODE_CONNECTOR_Component, "component" },
> +       { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
> +       { DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
> +       { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
> +       { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
> +       { DRM_MODE_CONNECTOR_TV, "TV" },
> +       { DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
> +};
> +
> +type_name_fn(connector_type)
> +
> +
>  void kmstest_dump_mode(drmModeModeInfo *mode)
>  {
>         printf("  %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n",
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 7202ad5..38aeb9d 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -119,6 +119,9 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
>  void kmstest_remove_fb(int fd, int fb_id);
>  void kmstest_dump_mode(drmModeModeInfo *mode);
>  int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
> +const char *kmstest_encoder_type_str(int type);
> +const char *kmstest_connector_status_str(int type);
> +const char *kmstest_connector_type_str(int type);
>
>  inline static void _do_or_die(const char *function, int line, int ret)
>  {
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index 80cd112..e7a2555 100644
> --- a/tests/testdisplay.c
> +++ b/tests/testdisplay.c
> @@ -88,59 +88,6 @@ uint32_t *fb_ptr;
>
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
>
> -struct type_name {
> -       int type;
> -       const char *name;
> -};
> -
> -#define type_name_fn(res) \
> -static const char * res##_str(int type) {                      \
> -       unsigned int i;                                 \
> -       for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
> -               if (res##_names[i].type == type)        \
> -                       return res##_names[i].name;     \
> -       }                                               \
> -       return "(invalid)";                             \
> -}
> -
> -struct type_name encoder_type_names[] = {
> -       { DRM_MODE_ENCODER_NONE, "none" },
> -       { DRM_MODE_ENCODER_DAC, "DAC" },
> -       { DRM_MODE_ENCODER_TMDS, "TMDS" },
> -       { DRM_MODE_ENCODER_LVDS, "LVDS" },
> -       { DRM_MODE_ENCODER_TVDAC, "TVDAC" },
> -};
> -
> -type_name_fn(encoder_type)
> -
> -struct type_name connector_status_names[] = {
> -       { DRM_MODE_CONNECTED, "connected" },
> -       { DRM_MODE_DISCONNECTED, "disconnected" },
> -       { DRM_MODE_UNKNOWNCONNECTION, "unknown" },
> -};
> -
> -type_name_fn(connector_status)
> -
> -struct type_name connector_type_names[] = {
> -       { DRM_MODE_CONNECTOR_Unknown, "unknown" },
> -       { DRM_MODE_CONNECTOR_VGA, "VGA" },
> -       { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
> -       { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
> -       { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
> -       { DRM_MODE_CONNECTOR_Composite, "composite" },
> -       { DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
> -       { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
> -       { DRM_MODE_CONNECTOR_Component, "component" },
> -       { DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
> -       { DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
> -       { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
> -       { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
> -       { DRM_MODE_CONNECTOR_TV, "TV" },
> -       { DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
> -};
> -
> -type_name_fn(connector_type)
> -
>  /*
>   * Mode setting with the kernel interfaces is a bit of a chore.
>   * First you have to find the connector in question and make sure the
> @@ -185,8 +132,8 @@ static void dump_connectors_fd(int drmfd)
>                 printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
>                        connector->connector_id,
>                        connector->encoder_id,
> -                      connector_status_str(connector->connection),
> -                      connector_type_str(connector->connector_type),
> +                      kmstest_connector_status_str(connector->connection),
> +                      kmstest_connector_type_str(connector->connector_type),
>                        connector->mmWidth, connector->mmHeight,
>                        connector->count_modes);
>
> @@ -390,7 +337,7 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
>
>         /* Get text extents for each string */
>         snprintf(name_buf, sizeof name_buf, "%s",
> -                connector_type_str(c->connector->connector_type));
> +                kmstest_connector_type_str(c->connector->connector_type));
>         cairo_set_font_size(cr, 48);
>         cairo_select_font_face(cr, "Helvetica",
>                                CAIRO_FONT_SLANT_NORMAL,
> @@ -399,7 +346,7 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
>
>         snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz on %s encoder",
>                  c->mode.name, c->mode.vrefresh,
> -                encoder_type_str(c->encoder->encoder_type));
> +                kmstest_encoder_type_str(c->encoder->encoder_type));
>         cairo_set_font_size(cr, 36);
>         cairo_text_extents(cr, mode_buf, &mode_extents);
>
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 2/5] lib: add kmstest_cairo_printf_line
  2013-05-31  9:23 ` [igt PATCH 2/5] lib: add kmstest_cairo_printf_line Imre Deak
@ 2013-06-05 17:44   ` Rodrigo Vivi
  2013-06-05 19:01     ` Imre Deak
  0 siblings, 1 reply; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 17:44 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

This patch is big and doing considerable changes in paint_marker
besides add cairo_printf line... doesn' t it deserves a split?

On Fri, May 31, 2013 at 6:23 AM, Imre Deak <imre.deak@intel.com> wrote:
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  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)
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 3/5] lib: add kmstest_get_connector_config
  2013-05-31  9:23 ` [igt PATCH 3/5] lib: add kmstest_get_connector_config Imre Deak
@ 2013-06-05 18:00   ` Rodrigo Vivi
  0 siblings, 0 replies; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 18:00 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

On Fri, May 31, 2013 at 6:23 AM, Imre Deak <imre.deak@intel.com> wrote:
> This is used by multiple test cases, so make it shared.
>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  lib/drmtest.c       | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/drmtest.h       |  14 ++++++
>  tests/kms_flip.c    | 115 ++++++++------------------------------------
>  tests/testdisplay.c | 134 +++++++++++++++-------------------------------------
>  4 files changed, 206 insertions(+), 191 deletions(-)
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index 3ad77a8..7368077 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -1317,3 +1317,137 @@ int drmtest_set_vt_graphics_mode(void)
>         return orig_vt_mode < 0 ? -1 : 0;
>  }
>
> +static int get_connector_default_mode(int drm_fd, drmModeConnector *connector,
> +                                     drmModeModeInfo *mode)
> +{
> +       drmModeRes *resources;
> +       int i;
> +
> +       resources = drmModeGetResources(drm_fd);
> +       if (!resources) {
> +               perror("drmModeGetResources failed");
> +
> +               return -1;
> +       }
> +
> +       if (!connector->count_modes) {
> +               fprintf(stderr, "no modes for connector %d\n",
> +                       connector->connector_id);
> +               drmModeFreeResources(resources);
> +
> +               return -1;
> +       }
> +
> +       for (i = 0; i < connector->count_modes; i++) {
> +               if (i == 0 ||
> +                   connector->modes[i].type & DRM_MODE_TYPE_PREFERRED) {
> +                       *mode = connector->modes[i];
> +                       if (mode->type & DRM_MODE_TYPE_PREFERRED)
> +                               break;
> +               }
> +       }
> +
> +       drmModeFreeResources(resources);
> +
> +       return 0;
> +}
> +
> +int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
> +                                unsigned long crtc_idx_mask,
> +                                struct kmstest_connector_config *config)
> +{
> +       drmModeRes *resources;
> +       drmModeConnector *connector;
> +       drmModeEncoder *encoder;
> +       int i, j;
> +
> +       resources = drmModeGetResources(drm_fd);
> +       if (!resources) {
> +               perror("drmModeGetResources failed");
> +               goto err1;
> +       }
> +
> +       /* First, find the connector & mode */
> +       connector = drmModeGetConnector(drm_fd, connector_id);
> +       if (!connector)
> +               goto err2;
> +
> +       if (connector->connection != DRM_MODE_CONNECTED)
> +               goto err3;
> +
> +       if (!connector->count_modes) {
> +               fprintf(stderr, "connector %d has no modes\n", connector_id);
> +               goto err3;
> +       }
> +
> +       if (connector->connector_id != connector_id) {
> +               fprintf(stderr, "connector id doesn't match (%d != %d)\n",
> +                       connector->connector_id, connector_id);
> +               goto err3;
> +       }
> +
> +       /*
> +        * Find given CRTC if crtc_id != 0 or else the first CRTC not in use.
> +        * In both cases find the first compatible encoder and skip the CRTC
> +        * if there is non such.
> +        */
> +       encoder = NULL;         /* suppress GCC warning */
> +       for (i = 0; i < resources->count_crtcs; i++) {
> +               if (!resources->crtcs[i] || !(crtc_idx_mask & (1 << i)))
> +                       continue;
> +
> +               /* Now get a compatible encoder */
> +               for (j = 0; j < connector->count_encoders; j++) {
> +                       encoder = drmModeGetEncoder(drm_fd,
> +                                                   connector->encoders[j]);
> +
> +                       if (!encoder) {
> +                               fprintf(stderr, "could not get encoder %d: %s\n",
> +                                       resources->encoders[j], strerror(errno));
> +
> +                               continue;
> +                       }
> +
> +                       if (encoder->possible_crtcs & (1 << i))
> +                               goto found;
> +
> +                       drmModeFreeEncoder(encoder);
> +               }
> +       }
> +
> +       fprintf(stderr,
> +               "no crtc with a compatible encoder (crtc_idx_mask %08lx)\n",
> +               crtc_idx_mask);
> +       goto err3;
> +
> +found:
> +       if (get_connector_default_mode(drm_fd, connector,
> +                                      &config->default_mode) < 0)
> +               goto err4;
> +
> +       config->connector = connector;
> +       config->encoder = encoder;
> +       config->crtc = drmModeGetCrtc(drm_fd, resources->crtcs[i]);
> +       config->crtc_idx = i;
> +       config->pipe = kmstest_get_pipe_from_crtc_id(drm_fd,
> +                                                    config->crtc->crtc_id);
> +
> +       drmModeFreeResources(resources);
> +
> +       return 0;
> +err4:
> +       drmModeFreeEncoder(encoder);
> +err3:
> +       drmModeFreeConnector(connector);
> +err2:
> +       drmModeFreeResources(resources);
> +err1:
> +       return -1;
> +}
> +
> +void kmstest_free_connector_config(struct kmstest_connector_config *config)
> +{
> +       drmModeFreeCrtc(config->crtc);
> +       drmModeFreeEncoder(config->encoder);
> +       drmModeFreeConnector(config->connector);
> +}
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 3c1368d..89ded11 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -101,6 +101,20 @@ void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr);
>  void drmtest_trash_aperture(void);
>  void drmtest_cleanup_aperture_trashers(void);
>
> +struct kmstest_connector_config {
> +       drmModeCrtc *crtc;
> +       drmModeConnector *connector;
> +       drmModeEncoder *encoder;
> +       drmModeModeInfo default_mode;
> +       int crtc_idx;
> +       int pipe;
> +};
> +
> +int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
> +                                unsigned long crtc_idx_mask,
> +                                struct kmstest_connector_config *config);
> +void kmstest_free_connector_config(struct kmstest_connector_config *config);
> +
>  /* helpers to create nice-looking framebuffers */
>  struct kmstest_fb {
>         uint32_t fb_id;
> diff --git a/tests/kms_flip.c b/tests/kms_flip.c
> index 735b4dd..c9b3d8a 100644
> --- a/tests/kms_flip.c
> +++ b/tests/kms_flip.c
> @@ -825,97 +825,23 @@ static void update_all_state(struct test_output *o,
>                 update_state(&o->vblank_state);
>  }
>
> -static void connector_find_preferred_mode(struct test_output *o, int crtc_id)
> +static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
> +                                         struct test_output *o)
>  {
> -       drmModeConnector *connector;
> -       drmModeEncoder *encoder = NULL;
> -       int i, j;
> -
> -       /* First, find the connector & mode */
> -       o->mode_valid = 0;
> -       o->crtc = 0;
> -       connector = drmModeGetConnector(drm_fd, o->id);
> -       assert(connector);
> -
> -       if (connector->connection != DRM_MODE_CONNECTED) {
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       if (!connector->count_modes) {
> -               fprintf(stderr, "connector %d has no modes\n", o->id);
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       if (connector->connector_id != o->id) {
> -               fprintf(stderr, "connector id doesn't match (%d != %d)\n",
> -                       connector->connector_id, o->id);
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       for (j = 0; j < connector->count_modes; j++) {
> -               o->mode = connector->modes[j];
> -               if (o->mode.type & DRM_MODE_TYPE_PREFERRED) {
> -                       o->mode_valid = 1;
> -                       break;
> -               }
> -       }
> -
> -       if (!o->mode_valid) {
> -               if (connector->count_modes > 0) {
> -                       /* use the first mode as test mode */
> -                       o->mode = connector->modes[0];
> -                       o->mode_valid = 1;
> -               }
> -               else {
> -                       fprintf(stderr, "failed to find any modes on connector %d\n",
> -                               o->id);
> -                       return;
> -               }
> -       }
> +       struct kmstest_connector_config config;
>
> -       /* Now get the encoder */
> -       for (i = 0; i < connector->count_encoders; i++) {
> -               encoder = drmModeGetEncoder(drm_fd, connector->encoders[i]);
> -
> -               if (!encoder) {
> -                       fprintf(stderr, "could not get encoder %i: %s\n",
> -                               resources->encoders[i], strerror(errno));
> -                       drmModeFreeEncoder(encoder);
> -                       continue;
> -               }
> -
> -               break;
> -       }
> -
> -       o->encoder = encoder;
> -
> -       if (i == resources->count_encoders) {
> -               fprintf(stderr, "failed to find encoder\n");
> -               o->mode_valid = 0;
> -               return;
> -       }
> -
> -       /* Find first CRTC not in use */
> -       for (i = 0; i < resources->count_crtcs; i++) {
> -               if (resources->crtcs[i] != crtc_id)
> -                       continue;
> -               if (resources->crtcs[i] &&
> -                   (o->encoder->possible_crtcs & (1<<i))) {
> -                       o->crtc = resources->crtcs[i];
> -                       break;
> -               }
> -       }
> -
> -       if (!o->crtc) {
> -               fprintf(stderr, "could not find requested crtc %d\n", crtc_id);
> +       if (kmstest_get_connector_config(drm_fd, connector_id, 1 << crtc_idx,
> +                                        &config) < 0) {
>                 o->mode_valid = 0;
>                 return;
>         }
>
> -       o->connector = connector;
> +       o->connector = config.connector;
> +       o->encoder = config.encoder;
> +       o->crtc = config.crtc->crtc_id;
> +       o->pipe = config.pipe;
> +       o->mode = config.default_mode;
> +       o->mode_valid = 1;
>  }
>
>  static void
> @@ -1042,21 +968,21 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)
>         return end - start;
>  }
>
> -static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
> +static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
>  {
>         unsigned ellapsed;
>
>         o->bpp = 32;
>         o->depth = 24;
>
> -       connector_find_preferred_mode(o, crtc);
> +       connector_find_preferred_mode(o->id, crtc_idx, o);
>         if (!o->mode_valid)
>                 return;
>
>         last_connector = o->connector;
>
>         fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
> -               o->test_name, crtc, o->id);
> +               o->test_name, o->crtc, o->id);
>
>         o->fb_width = o->mode.hdisplay;
>         o->fb_height = o->mode.vdisplay;
> @@ -1116,7 +1042,7 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
>                 check_final_state(o, &o->vblank_state, ellapsed);
>
>         fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
> -               o->test_name, crtc, o->id);
> +               o->test_name, o->crtc, o->id);
>
>         kmstest_remove_fb(drm_fd, o->fb_ids[2]);
>         kmstest_remove_fb(drm_fd, o->fb_ids[1]);
> @@ -1131,7 +1057,8 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
>  static int run_test(int duration, int flags, const char *test_name)
>  {
>         struct test_output o;
> -       int c, i;
> +       int c;
> +       int crtc_idx;
>
>         resources = drmModeGetResources(drm_fd);
>         if (!resources) {
> @@ -1142,19 +1069,15 @@ static int run_test(int duration, int flags, const char *test_name)
>
>         /* Find any connected displays */
>         for (c = 0; c < resources->count_connectors; c++) {
> -               for (i = 0; i < resources->count_crtcs; i++) {
> -                       int crtc;
> -
> +               for (crtc_idx = 0; crtc_idx < resources->count_crtcs; crtc_idx++) {
>                         memset(&o, 0, sizeof(o));
>                         o.test_name = test_name;
>                         o.id = resources->connectors[c];
>                         o.flags = flags;
>                         o.flip_state.name = "flip";
>                         o.vblank_state.name = "vblank";
> -                       crtc = resources->crtcs[i];
> -                       o.pipe = kmstest_get_pipe_from_crtc_id(drm_fd, crtc);
>
> -                       run_test_on_crtc(&o, crtc, duration);
> +                       run_test_on_crtc(&o, crtc_idx, duration);
>                 }
>         }
>
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index b10c3b9..4470339 100644
> --- a/tests/testdisplay.c
> +++ b/tests/testdisplay.c
> @@ -102,6 +102,7 @@ struct connector {
>         drmModeEncoder *encoder;
>         drmModeConnector *connector;
>         int crtc;
> +       int crtc_idx;
>         int pipe;
>  };
>
> @@ -185,101 +186,31 @@ static void dump_crtcs_fd(int drmfd)
>         drmModeFreeResources(mode_resources);
>  }
>
> -static void connector_find_preferred_mode(struct connector *c)
> +static void connector_find_preferred_mode(uint32_t connector_id,
> +                                         unsigned long crtc_idx_mask,
> +                                         int mode_num, struct connector *c)
>  {
> -       drmModeConnector *connector;
> -       drmModeEncoder *encoder = NULL;
> -       int i, j;
> -
> -       /* First, find the connector & mode */
> -       c->mode_valid = 0;
> -       connector = drmModeGetConnector(drm_fd, c->id);
> -       if (!connector) {
> -               fprintf(stderr, "could not get connector %d: %s\n",
> -                       c->id, strerror(errno));
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       if (connector->connection != DRM_MODE_CONNECTED) {
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       if (!connector->count_modes) {
> -               fprintf(stderr, "connector %d has no modes\n", c->id);
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       if (connector->connector_id != c->id) {
> -               fprintf(stderr, "connector id doesn't match (%d != %d)\n",
> -                       connector->connector_id, c->id);
> -               drmModeFreeConnector(connector);
> -               return;
> -       }
> -
> -       for (j = 0; j < connector->count_modes; j++) {
> -               c->mode = connector->modes[j];
> -               if (c->mode.type & DRM_MODE_TYPE_PREFERRED) {
> -                       c->mode_valid = 1;
> -                       break;
> -               }
> -       }
> -
> -       if ( specified_mode_num != -1 ){
> -               c->mode = connector->modes[specified_mode_num];
> -               if (c->mode.type & DRM_MODE_TYPE_PREFERRED)
> -                       c->mode_valid = 1;
> -       }
> -
> -       if (!c->mode_valid) {
> -               if (connector->count_modes > 0) {
> -                       /* use the first mode as test mode */
> -                       c->mode = connector->modes[0];
> -                       c->mode_valid = 1;
> -               }
> -               else {
> -                       fprintf(stderr, "failed to find any modes on connector %d\n",
> -                               c->id);
> -                       return;
> -               }
> -       }
> -
> -       /* Now get the encoder */
> -       for (i = 0; i < connector->count_encoders; i++) {
> -               encoder = drmModeGetEncoder(drm_fd, connector->encoders[i]);
> -
> -               if (!encoder) {
> -                       fprintf(stderr, "could not get encoder %i: %s\n",
> -                               resources->encoders[i], strerror(errno));
> -                       drmModeFreeEncoder(encoder);
> -                       continue;
> -               }
> -
> -               break;
> -       }
> -
> -       c->encoder = encoder;
> +       struct kmstest_connector_config config;
>
> -       if (i == resources->count_encoders) {
> -               fprintf(stderr, "failed to find encoder\n");
> +       if (kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask,
> +                                        &config) < 0) {
>                 c->mode_valid = 0;
>                 return;
>         }
>
> -       /* Find first CRTC not in use */
> -       for (i = 0; i < resources->count_crtcs; i++) {
> -               if (resources->crtcs[i] && (c->encoder->possible_crtcs & (1<<i)))
> -                       break;
> +       c->connector = config.connector;
> +       c->encoder = config.encoder;
> +       c->crtc = config.crtc->crtc_id;
> +       c->crtc_idx = config.crtc_idx;
> +       c->pipe = config.pipe;
> +
> +       if (mode_num != -1) {
> +               assert(mode_num < config.connector->count_modes);
> +               c->mode = config.connector->modes[mode_num];
> +       } else {
> +               c->mode = config.default_mode;
>         }
> -       c->crtc = resources->crtcs[i];
> -       c->pipe = i;
> -
> -       if(test_preferred_mode || force_mode || specified_mode_num != -1)
> -               resources->crtcs[i] = 0;
> -
> -       c->connector = connector;
> +       c->mode_valid = 1;
>  }
>
>  static void
> @@ -409,10 +340,6 @@ set_mode(struct connector *c)
>         else if (depth > 16 && depth <= 32)
>                 bpp = 32;
>
> -       connector_find_preferred_mode(c);
> -       if (!c->mode_valid)
> -               return;
> -
>         test_mode_num = 1;
>         if (force_mode){
>                 memcpy( &c->mode, &force_timing, sizeof(force_timing));
> @@ -506,13 +433,30 @@ int update_display(void)
>         }
>
>         if (test_preferred_mode || test_all_modes || force_mode || specified_disp_id != -1) {
> +               unsigned long crtc_idx_mask = -1UL;
> +
>                 /* Find any connected displays */
>                 for (c = 0; c < resources->count_connectors; c++) {
> -                       connectors[c].id = resources->connectors[c];
> -                       if ( specified_disp_id != -1 && connectors[c].id != specified_disp_id )
> +                       struct connector *connector = &connectors[c];
> +
> +                       connector->id = resources->connectors[c];
> +                       if (specified_disp_id != -1 &&
> +                           connector->id != specified_disp_id)
> +                               continue;
> +
> +                       connector_find_preferred_mode(connector->id,
> +                                                     crtc_idx_mask,
> +                                                     specified_mode_num,
> +                                                     connector);
> +                       if (!connector->mode_valid)
>                                 continue;
>
> -                       set_mode(&connectors[c]);
> +                       set_mode(connector);
> +
> +                       if (test_preferred_mode || force_mode ||
> +                           specified_mode_num != -1)
> +                               crtc_idx_mask &= ~(1 << connector->crtc_idx);
> +
>                 }
>         }
>         drmModeFreeResources(resources);
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 4/5] lib: refactor kmstest_create_fb
  2013-05-31  9:23 ` [igt PATCH 4/5] lib: refactor kmstest_create_fb Imre Deak
@ 2013-06-05 18:21   ` Rodrigo Vivi
  0 siblings, 0 replies; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 18:21 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

what a huge patch... but hopefully I haven' t missed anything.
Feel free to use Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

On Fri, May 31, 2013 at 6:23 AM, Imre Deak <imre.deak@intel.com> wrote:
> Factor out parts that will be used by an upcoming patch adding
> kmstest_create_fb2.
>
> Also call the fb paint functions directly, there is not much
> point in passing a function pointer for that.
>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  lib/drmtest.c       | 176 ++++++++++++++++++++++++++++++++--------------------
>  lib/drmtest.h       |  15 +++--
>  tests/kms_flip.c    |  30 +++++----
>  tests/testdisplay.c |  15 +++--
>  4 files changed, 147 insertions(+), 89 deletions(-)
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index 7368077..a551e7c 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -39,6 +39,7 @@
>  #include <getopt.h>
>  #include <stdlib.h>
>  #include <linux/kd.h>
> +#include <drm/drm_fourcc.h>
>
>  #include "drmtest.h"
>  #include "i915_drm.h"
> @@ -788,16 +789,14 @@ void drmtest_cleanup_aperture_trashers(void)
>  }
>
>  /* helpers to create nice-looking framebuffers */
> -static cairo_surface_t *
> -paint_allocate_surface(int fd, int width, int height, int depth, int bpp,
> -                      bool tiled,
> -                      struct kmstest_fb *fb_info)
> +static int create_bo_for_fb(int fd, int width, int height, int bpp,
> +                           bool tiled, uint32_t *gem_handle_ret,
> +                           unsigned *size_ret, unsigned *stride_ret)
>  {
> -       cairo_format_t format;
>         struct drm_i915_gem_set_tiling set_tiling;
> +       uint32_t gem_handle;
>         int size;
>         unsigned stride;
> -       uint32_t *fb_ptr;
>
>         if (tiled) {
>                 int v;
> @@ -823,49 +822,24 @@ paint_allocate_surface(int fd, int width, int height, int depth, int bpp,
>                 size = stride * height;
>         }
>
> -       switch (depth) {
> -       case 16:
> -               format = CAIRO_FORMAT_RGB16_565;
> -               break;
> -       case 24:
> -               format = CAIRO_FORMAT_RGB24;
> -               break;
> -#if 0
> -       case 30:
> -               format = CAIRO_FORMAT_RGB30;
> -               break;
> -#endif
> -       case 32:
> -               format = CAIRO_FORMAT_ARGB32;
> -               break;
> -       default:
> -               fprintf(stderr, "bad depth %d\n", depth);
> -               return NULL;
> -       }
> -
> -       assert (bpp >= depth);
> -
> -       fb_info->gem_handle = gem_create(fd, size);
> +       gem_handle = gem_create(fd, size);
>
>         if (tiled) {
> -               set_tiling.handle = fb_info->gem_handle;
> +               set_tiling.handle = gem_handle;
>                 set_tiling.tiling_mode = I915_TILING_X;
>                 set_tiling.stride = stride;
>                 if (ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling)) {
>                         fprintf(stderr, "set tiling failed: %s (stride=%d, size=%d)\n",
>                                 strerror(errno), stride, size);
> -                       return NULL;
> +                       return -1;
>                 }
>         }
>
> -       fb_ptr = gem_mmap(fd, fb_info->gem_handle, size, PROT_READ | PROT_WRITE);
> -
> -       fb_info->stride = stride;
> -       fb_info->size = size;
> +       *stride_ret = stride;
> +       *size_ret = size;
> +       *gem_handle_ret = gem_handle;
>
> -       return cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
> -                                                  format, width, height,
> -                                                  stride);
> +       return 0;
>  }
>
>  static void
> @@ -981,23 +955,8 @@ paint_marker(cairo_t *cr, int x, int y)
>         kmstest_cairo_printf_line(cr, align, 0, "(%d, %d)", x, y);
>  }
>
> -unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
> -                              int depth, bool tiled,
> -                              struct kmstest_fb *fb_info,
> -                              kmstest_paint_func paint_func,
> -                              void *func_arg)
> +void kmstest_paint_test_pattern(cairo_t *cr, int width, int height)
>  {
> -       cairo_surface_t *surface;
> -       cairo_status_t status;
> -       cairo_t *cr;
> -       unsigned int fb_id;
> -
> -       surface = paint_allocate_surface(fd, width, height, depth, bpp,
> -                                        tiled, fb_info);
> -       assert(surface);
> -
> -       cr = cairo_create(surface);
> -
>         paint_test_patterns(cr, width, height);
>
>         cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
> @@ -1008,27 +967,112 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
>         paint_marker(cr, 0, height);
>         paint_marker(cr, width, height);
>
> -       if (paint_func)
> -               paint_func(cr, width, height, func_arg);
> +       assert(!cairo_status(cr));
> +}
> +
> +#define DF(did, cid, _bpp, _depth)     \
> +       { DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
> +static struct format_desc_struct {
> +       uint32_t drm_id;
> +       cairo_format_t cairo_id;
> +       const char *name;
> +       int bpp;
> +       int depth;
> +} format_desc[] = {
> +       DF(RGB565,      RGB16_565,      16, 16),
> +       DF(RGB888,      INVALID,        24, 24),
> +       DF(XRGB8888,    RGB24,          32, 24),
> +       DF(XRGB2101010, RGB30,          32, 30),
> +       DF(ARGB8888,    ARGB32,         32, 32),
> +};
> +#undef DF
> +
> +#define for_each_format(f)     \
> +       for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
> +
> +static uint32_t bpp_depth_to_drm_format(int bpp, int depth)
> +{
> +       struct format_desc_struct *f;
> +
> +       for_each_format(f)
> +               if (f->bpp == bpp && f->depth == depth)
> +                       return f->drm_id;
> +
> +       abort();
> +}
> +
> +/* Return fb_id on success, 0 on error */
> +unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
> +                              int depth, bool tiled, struct kmstest_fb *fb)
> +{
> +       memset(fb, 0, sizeof(*fb));
>
> -       status = cairo_status(cr);
> -       assert(!status);
> -       cairo_destroy(cr);
> +       if (create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
> +                              &fb->size, &fb->stride) < 0)
> +               return 0;
> +
> +       if (drmModeAddFB(fd, width, height, depth, bpp, fb->stride,
> +                              fb->gem_handle, &fb->fb_id) < 0) {
> +               gem_close(fd, fb->gem_handle);
> +
> +               return 0;
> +       }
> +
> +       fb->width = width;
> +       fb->height = height;
> +       fb->drm_format = bpp_depth_to_drm_format(bpp, depth);
> +
> +       return fb->fb_id;
> +}
> +
> +static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
> +{
> +       struct format_desc_struct *f;
>
> -       do_or_die(drmModeAddFB(fd, width, height, depth, bpp,
> -                              fb_info->stride,
> -                              fb_info->gem_handle, &fb_id));
> +       for_each_format(f)
> +               if (f->drm_id == drm_format)
> +                       return f->cairo_id;
>
> +       abort();
> +}
> +
> +static cairo_t *create_cairo_ctx(int fd, struct kmstest_fb *fb)
> +{
> +       cairo_t *cr;
> +       cairo_surface_t *surface;
> +       cairo_format_t cformat;
> +       void *fb_ptr;
> +
> +       cformat = drm_format_to_cairo(fb->drm_format);
> +       fb_ptr = gem_mmap(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
> +       surface = cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
> +                                                  cformat, fb->width,
> +                                                  fb->height, fb->stride);
> +       assert(surface);
> +       cr = cairo_create(surface);
>         cairo_surface_destroy(surface);
>
> -       fb_info->fb_id = fb_id;
> +       return cr;
> +}
> +
> +cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb)
> +{
> +
> +       if (!fb->cairo_ctx)
> +               fb->cairo_ctx = create_cairo_ctx(fd, fb);
> +
> +       gem_set_domain(fd, fb->gem_handle, I915_GEM_DOMAIN_CPU,
> +                      I915_GEM_DOMAIN_CPU);
>
> -       return fb_id;
> +       return fb->cairo_ctx;
>  }
>
> -void kmstest_remove_fb(int fd, int fb_id)
> +void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
>  {
> -       do_or_die(drmModeRmFB(fd, fb_id));
> +       if (fb->cairo_ctx)
> +               cairo_destroy(fb->cairo_ctx);
> +       do_or_die(drmModeRmFB(fd, fb->fb_id));
> +       gem_close(fd, fb->gem_handle);
>  }
>
>  struct type_name {
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 89ded11..218914f 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -119,8 +119,13 @@ void kmstest_free_connector_config(struct kmstest_connector_config *config);
>  struct kmstest_fb {
>         uint32_t fb_id;
>         uint32_t gem_handle;
> +       uint32_t drm_format;
> +       int width;
> +       int height;
> +       int depth;
>         unsigned stride;
>         unsigned size;
> +       cairo_t *cairo_ctx;
>  };
>
>  enum kmstest_text_align {
> @@ -136,14 +141,12 @@ 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,
>                                int depth, bool tiled,
> -                              struct kmstest_fb *fb_info,
> -                              kmstest_paint_func paint_func,
> -                              void *func_arg);
> -void kmstest_remove_fb(int fd, int fb_id);
> +                              struct kmstest_fb *fb_info);
> +void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
> +cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
> +void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
>  void kmstest_dump_mode(drmModeModeInfo *mode);
>  int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
>  const char *kmstest_encoder_type_str(int type);
> diff --git a/tests/kms_flip.c b/tests/kms_flip.c
> index c9b3d8a..aeeaace 100644
> --- a/tests/kms_flip.c
> +++ b/tests/kms_flip.c
> @@ -844,10 +844,13 @@ static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
>         o->mode_valid = 1;
>  }
>
> -static void
> -paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
> +static void paint_flip_mode(struct kmstest_fb *fb, bool odd_frame)
>  {
> -       bool odd_frame = (bool) priv;
> +       cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
> +       int width = fb->width;
> +       int height = fb->height;
> +
> +       kmstest_paint_test_pattern(cr, width, height);
>
>         if (odd_frame)
>                 cairo_rectangle(cr, width/4, height/2, width/4, height/8);
> @@ -856,6 +859,8 @@ paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
>
>         cairo_set_source_rgb(cr, 1, 1, 1);
>         cairo_fill(cr);
> +
> +       assert(!cairo_status(cr));
>  }
>
>  static int
> @@ -991,20 +996,21 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
>                 o->fb_width *= 2;
>
>         o->fb_ids[0] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
> -                                        o->bpp, o->depth, false, &o->fb_info[0],
> -                                        paint_flip_mode, (void *)false);
> +                                        o->bpp, o->depth, false, &o->fb_info[0]);
>         o->fb_ids[1] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
> -                                        o->bpp, o->depth, false, &o->fb_info[1],
> -                                        paint_flip_mode, (void *)true);
> +                                        o->bpp, o->depth, false, &o->fb_info[1]);
>         o->fb_ids[2] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
> -                                        o->bpp, o->depth, true, &o->fb_info[2],
> -                                        paint_flip_mode, (void *)true);
> +                                        o->bpp, o->depth, true, &o->fb_info[2]);
>
>         if (!o->fb_ids[0] || !o->fb_ids[1] || !o->fb_ids[2]) {
>                 fprintf(stderr, "failed to create fbs\n");
>                 exit(3);
>         }
>
> +       paint_flip_mode(&o->fb_info[0], false);
> +       paint_flip_mode(&o->fb_info[1], true);
> +       paint_flip_mode(&o->fb_info[2], true);
> +
>         set_y_tiling(o, 2);
>
>         kmstest_dump_mode(&o->mode);
> @@ -1044,9 +1050,9 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
>         fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
>                 o->test_name, o->crtc, o->id);
>
> -       kmstest_remove_fb(drm_fd, o->fb_ids[2]);
> -       kmstest_remove_fb(drm_fd, o->fb_ids[1]);
> -       kmstest_remove_fb(drm_fd, o->fb_ids[0]);
> +       kmstest_remove_fb(drm_fd, &o->fb_info[2]);
> +       kmstest_remove_fb(drm_fd, &o->fb_info[1]);
> +       kmstest_remove_fb(drm_fd, &o->fb_info[0]);
>
>         last_connector = NULL;
>
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index 4470339..5ece921 100644
> --- a/tests/testdisplay.c
> +++ b/tests/testdisplay.c
> @@ -258,15 +258,18 @@ static void paint_image(cairo_t *cr, const char *file)
>         cairo_surface_destroy(image);
>  }
>
> -static void
> -paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
> +static void paint_output_info(struct connector *c, struct kmstest_fb *fb)
>  {
> -       struct connector *c = priv;
> +       cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
> +       int l_width = fb->width;
> +       int l_height = fb->height;
>         double str_width;
>         double x, y, top_y;
>         double max_width;
>         int i;
>
> +       kmstest_paint_test_pattern(cr, l_width, l_height);
> +
>         cairo_select_font_face(cr, "Helvetica",
>                                CAIRO_FONT_SLANT_NORMAL,
>                                CAIRO_FONT_WEIGHT_NORMAL);
> @@ -308,6 +311,8 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
>
>         if (qr_code)
>                 paint_image(cr, "./pass.png");
> +
> +       assert(!cairo_status(cr));
>  }
>
>  static void sighandler(int signo)
> @@ -362,8 +367,8 @@ set_mode(struct connector *c)
>                 height = c->mode.vdisplay;
>
>                 fb_id = kmstest_create_fb(drm_fd, width, height, bpp, depth,
> -                                         enable_tiling, &fb_info,
> -                                         paint_output_info, c);
> +                                         enable_tiling, &fb_info);
> +               paint_output_info(c, &fb_info);
>
>                 fb_ptr = gem_mmap(drm_fd, fb_info.gem_handle,
>                                   fb_info.size, PROT_READ | PROT_WRITE);
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 5/5] tests: add kms_render
  2013-05-31  9:23 ` [igt PATCH 5/5] tests: add kms_render Imre Deak
@ 2013-06-05 18:28   ` Rodrigo Vivi
  2013-06-06 10:19     ` Imre Deak
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
  1 sibling, 1 reply; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 18:28 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

nice tests, only now I understood why Daniel "randomly" volunteered me
to review this series ;)
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

On Fri, May 31, 2013 at 6:23 AM, Imre Deak <imre.deak@intel.com> wrote:
> Add a test going through all connectors/crtcs/modes/formats painting to
> a front FB with CPU or painting to a back FB with CPU and blitting it
> to the front FB.
>
> Only formats understood by cairo are supported for now.
>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  lib/drmtest.c      | 101 ++++++++++++++++++++--
>  lib/drmtest.h      |   7 ++
>  tests/.gitignore   |   1 +
>  tests/Makefile.am  |   1 +
>  tests/kms_render.c | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 349 insertions(+), 6 deletions(-)
>  create mode 100644 tests/kms_render.c
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index a551e7c..d9d58e5 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -842,8 +842,8 @@ static int create_bo_for_fb(int fd, int width, int height, int bpp,
>         return 0;
>  }
>
> -static void
> -paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
> +void
> +kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
>                      int r, int g, int b)
>  {
>         cairo_pattern_t *pat;
> @@ -869,16 +869,16 @@ paint_test_patterns(cairo_t *cr, int width, int height)
>         gr_height = height * 0.08;
>         x = (width / 2) - (gr_width / 2);
>
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
>
>         y += gr_height;
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
>
>         y += gr_height;
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
> +       kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
>
>         y += gr_height;
> -       paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
> +       kmstest_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,
> @@ -1025,6 +1025,55 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
>         return fb->fb_id;
>  }
>
> +static uint32_t drm_format_to_bpp(uint32_t drm_format)
> +{
> +       struct format_desc_struct *f;
> +
> +       for_each_format(f)
> +               if (f->drm_id == drm_format)
> +                       return f->bpp;
> +
> +       abort();
> +}
> +
> +unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
> +                               bool tiled, struct kmstest_fb *fb)
> +{
> +       uint32_t handles[4];
> +       uint32_t pitches[4];
> +       uint32_t offsets[4];
> +       uint32_t fb_id;
> +       int bpp;
> +       int ret;
> +
> +       memset(fb, 0, sizeof(*fb));
> +
> +       bpp = drm_format_to_bpp(format);
> +       ret = create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
> +                             &fb->size, &fb->stride);
> +       if (ret < 0)
> +               return ret;
> +
> +       memset(handles, 0, sizeof(handles));
> +       handles[0] = fb->gem_handle;
> +       memset(pitches, 0, sizeof(pitches));
> +       pitches[0] = fb->stride;
> +       memset(offsets, 0, sizeof(offsets));
> +       if (drmModeAddFB2(fd, width, height, format, handles, pitches,
> +                         offsets, &fb_id, 0) < 0) {
> +               gem_close(fd, fb->gem_handle);
> +
> +               return 0;
> +       }
> +
> +       fb->width = width;
> +       fb->height = height;
> +       fb->drm_format = format;
> +       fb->fb_id = fb_id;
> +
> +       return fb_id;
> +}
> +
>  static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
>  {
>         struct format_desc_struct *f;
> @@ -1075,6 +1124,46 @@ void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
>         gem_close(fd, fb->gem_handle);
>  }
>
> +const char *kmstest_format_str(uint32_t drm_format)
> +{
> +       struct format_desc_struct *f;
> +
> +       for_each_format(f)
> +               if (f->drm_id == drm_format)
> +                       return f->name;
> +
> +       return "invalid";
> +}
> +
> +const char *kmstest_pipe_str(int pipe)
> +{
> +       const char *str[] = { "A", "B", "C" };
> +
> +       if (pipe > 2)
> +               return "invalid";
> +
> +       return str[pipe];
> +}
> +
> +void kmstest_get_all_formats(const uint32_t **formats, int *format_count)
> +{
> +       static uint32_t *drm_formats;
> +
> +       if (!drm_formats) {
> +               struct format_desc_struct *f;
> +               uint32_t *format;
> +
> +               drm_formats = calloc(ARRAY_SIZE(format_desc),
> +                                    sizeof(*drm_formats));
> +               format = &drm_formats[0];
> +               for_each_format(f)
> +                       *format++ = f->drm_id;
> +       }
> +
> +       *formats = drm_formats;
> +       *format_count = ARRAY_SIZE(format_desc);
> +}
> +
>  struct type_name {
>         int type;
>         const char *name;
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 218914f..e3a9275 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -144,11 +144,18 @@ int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
>  unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
>                                int depth, bool tiled,
>                                struct kmstest_fb *fb_info);
> +unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
> +                               bool tiled, struct kmstest_fb *fb);
>  void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
>  cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
> +void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
> +                                 int r, int g, int b);
>  void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
>  void kmstest_dump_mode(drmModeModeInfo *mode);
>  int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
> +const char *kmstest_format_str(uint32_t drm_format);
> +const char *kmstest_pipe_str(int pipe);
> +void kmstest_get_all_formats(const uint32_t **formats, int *format_count);
>  const char *kmstest_encoder_type_str(int type);
>  const char *kmstest_connector_status_str(int type);
>  const char *kmstest_connector_type_str(int type);
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 3cac813..1f7c691 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -85,6 +85,7 @@ getclient
>  getstats
>  getversion
>  kms_flip
> +kms_render
>  prime_nv_api
>  prime_nv_pcopy
>  prime_nv_test
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 7250968..3f301c9 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -33,6 +33,7 @@ TESTS_progs_M = \
>         gem_tiled_partial_pwrite_pread \
>         $(NOUVEAU_TESTS_M) \
>         kms_flip \
> +       kms_render \
>         prime_self_import \
>         $(NULL)
>
> diff --git a/tests/kms_render.c b/tests/kms_render.c
> new file mode 100644
> index 0000000..707ce27
> --- /dev/null
> +++ b/tests/kms_render.c
> @@ -0,0 +1,245 @@
> +/*
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors:
> + *    Imre Deak <imre.deak@intel.com>
> + */
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <assert.h>
> +#include <cairo.h>
> +#include <errno.h>
> +#include <stdint.h>
> +#include <unistd.h>
> +#include <sys/time.h>
> +
> +#include "drmtest.h"
> +#include "testdisplay.h"
> +#include "intel_bufmgr.h"
> +#include "intel_batchbuffer.h"
> +#include "intel_gpu_tools.h"
> +
> +drmModeRes *resources;
> +int drm_fd;
> +static drm_intel_bufmgr *bufmgr;
> +struct intel_batchbuffer *batch;
> +uint32_t devid;
> +
> +enum test_flags {
> +       TEST_DIRECT_RENDER      = 0x01,
> +       TEST_GPU_BLIT           = 0x02,
> +};
> +
> +static int paint_fb(struct kmstest_fb *fb, const char *test_name,
> +                   const char *mode_format_str, const char *cconf_str)
> +{
> +       cairo_t *cr;
> +
> +       cr = kmstest_get_cairo_ctx(drm_fd, fb);
> +       if (!cr)
> +               return -1;
> +
> +       kmstest_paint_color_gradient(cr, 0, 0, fb->width, fb->height, 1, 1, 1);
> +       kmstest_paint_test_pattern(cr, fb->width, fb->height);
> +
> +       cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
> +                              CAIRO_FONT_WEIGHT_NORMAL);
> +       cairo_move_to(cr, fb->width / 2, fb->height / 2);
> +       cairo_set_font_size(cr, 36);
> +       kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
> +       kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
> +       kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
> +
> +       return 0;
> +}
> +
> +static void gpu_blit(struct kmstest_fb *dst_fb, struct kmstest_fb *src_fb)
> +{
> +       drm_intel_bo *dst_bo;
> +       drm_intel_bo *src_bo;
> +
> +       dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
> +                                        dst_fb->gem_handle);
> +       assert(dst_bo);
> +       src_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "source",
> +                                        src_fb->gem_handle);
> +       assert(src_bo);
> +
> +       intel_copy_bo(batch, dst_bo, src_bo, src_fb->width, src_fb->height);
> +       intel_batchbuffer_flush(batch);
> +       gem_quiescent_gpu(drm_fd);
> +
> +       drm_intel_bo_unreference(src_bo);
> +       drm_intel_bo_unreference(dst_bo);
> +}
> +
> +static int test_format(const char *test_name,
> +                      struct kmstest_connector_config *cconf,
> +                      drmModeModeInfo *mode, uint32_t format,
> +                      enum test_flags flags)
> +{
> +       int width;
> +       int height;
> +       struct kmstest_fb fb[2];
> +       char *mode_format_str;
> +       char *cconf_str;
> +       int ret;
> +
> +       ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
> +                mode->name, mode->vrefresh, kmstest_format_str(format));
> +       assert(ret > 0);
> +       ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
> +                      kmstest_pipe_str(cconf->pipe),
> +                      kmstest_encoder_type_str(cconf->encoder->encoder_type),
> +                      kmstest_connector_type_str(cconf->connector->connector_type));
> +       assert(ret > 0);
> +
> +       printf("Beginning test %s with %s on %s\n",
> +               test_name, mode_format_str, cconf_str);
> +
> +       width = mode->hdisplay;
> +       height = mode->vdisplay;
> +
> +       if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[0]))
> +               goto err1;
> +
> +       if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[1]))
> +               goto err2;
> +
> +       do_or_die(drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
> +                                0, 0, &cconf->connector->connector_id, 1,
> +                                mode));
> +       do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
> +                                 0, NULL));
> +       sleep(2);
> +
> +       if (flags & TEST_DIRECT_RENDER) {
> +               paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
> +       } else if (flags & TEST_GPU_BLIT) {
> +               paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
> +               gpu_blit(&fb[0], &fb[1]);
> +       }
> +       sleep(5);
> +
> +       printf("Test %s with %s on %s: PASSED\n",
> +               test_name, mode_format_str, cconf_str);
> +       free(mode_format_str);
> +       free(cconf_str);
> +
> +       kmstest_remove_fb(drm_fd, &fb[1]);
> +       kmstest_remove_fb(drm_fd, &fb[0]);
> +
> +       return 0;
> +
> +err2:
> +       kmstest_remove_fb(drm_fd, &fb[0]);
> +err1:
> +       fprintf(stderr, "skip testing unsupported format %s\n",
> +               kmstest_format_str(format));
> +
> +       return -1;
> +}
> +
> +static void test_connector(const char *test_name,
> +                          struct kmstest_connector_config *cconf,
> +                          enum test_flags flags)
> +{
> +       const uint32_t *formats;
> +       int format_count;
> +       int i;
> +
> +       kmstest_get_all_formats(&formats, &format_count);
> +       for (i = 0; i < cconf->connector->count_modes; i++) {
> +               int j;
> +
> +               for (j = 0; j < format_count; j++)
> +                       test_format(test_name,
> +                                   cconf, &cconf->connector->modes[i],
> +                                   formats[j], flags);
> +       }
> +}
> +
> +static int run_test(const char *test_name, enum test_flags flags)
> +{
> +       int i;
> +
> +       resources = drmModeGetResources(drm_fd);
> +       assert(resources);
> +
> +       /* Find any connected displays */
> +       for (i = 0; i < resources->count_connectors; i++) {
> +               uint32_t connector_id;
> +               int j;
> +
> +               connector_id = resources->connectors[i];
> +               for (j = 0; j < resources->count_crtcs; j++) {
> +                       struct kmstest_connector_config cconf;
> +                       int ret;
> +
> +                       ret = kmstest_get_connector_config(drm_fd, connector_id,
> +                                                          1 << j, &cconf);
> +                       if (ret < 0)
> +                               continue;
> +
> +                       test_connector(test_name, &cconf, flags);
> +
> +                       kmstest_free_connector_config(&cconf);
> +               }
> +       }
> +
> +       drmModeFreeResources(resources);
> +
> +       return 1;
> +}
> +
> +int main(int argc, char **argv)
> +{
> +       struct {
> +               enum test_flags flags;
> +               const char *name;
> +       } tests[] = {
> +               { TEST_DIRECT_RENDER,   "direct-render" },
> +               { TEST_GPU_BLIT,        "gpu-blit" },
> +       };
> +       int i;
> +
> +       drmtest_subtest_init(argc, argv);
> +
> +       if (!drmtest_only_list_subtests()) {
> +               drm_fd = drm_open_any();
> +
> +               bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
> +               devid = intel_get_drm_devid(drm_fd);
> +               batch = intel_batchbuffer_alloc(bufmgr, devid);
> +
> +               do_or_die(drmtest_set_vt_graphics_mode());
> +       }
> +
> +       for (i = 0; i < ARRAY_SIZE(tests); i++) {
> +               if (drmtest_run_subtest(tests[i].name))
> +                       run_test(tests[i].name, tests[i].flags);
> +       }
> +
> +       if (!drmtest_only_list_subtests())
> +               close(drm_fd);
> +
> +       return 0;
> +}
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 2/5] lib: add kmstest_cairo_printf_line
  2013-06-05 17:44   ` Rodrigo Vivi
@ 2013-06-05 19:01     ` Imre Deak
  0 siblings, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:01 UTC (permalink / raw)
  To: Rodrigo Vivi; +Cc: intel-gfx

On Wed, 2013-06-05 at 14:44 -0300, Rodrigo Vivi wrote:
> This patch is big and doing considerable changes in paint_marker
> besides add cairo_printf line... doesn' t it deserves a split?

Ok, will resend this with the paint_marker changes in a separate patch.

--Imre

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v2 0/6] tests: add tests for front buffer rendering
  2013-05-31  9:23 ` [igt PATCH 5/5] tests: add kms_render Imre Deak
  2013-06-05 18:28   ` Rodrigo Vivi
@ 2013-06-05 19:25   ` Imre Deak
  2013-06-05 19:25     ` [PATCH v2 1/6] lib: move connector_type_str and co to drmtest Imre Deak
                       ` (5 more replies)
  1 sibling, 6 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

v2:
- split changes to paint_marker() to a separate patch (Rodrigo)

Imre Deak (6):
  lib: move connector_type_str and co to drmtest
  lib: add kmstest_cairo_printf_line
  lib: use kmstest_cairo_printf_line in paint_marker
  lib: add kmstest_get_connector_config
  lib: refactor kmstest_create_fb
  tests: add kms_render

 demos/intel_sprite_on.c |  58 +----
 lib/drmtest.c           | 575 +++++++++++++++++++++++++++++++++++++-----------
 lib/drmtest.h           |  50 ++++-
 tests/.gitignore        |   1 +
 tests/Makefile.am       |   1 +
 tests/kms_flip.c        | 145 ++++--------
 tests/kms_render.c      | 245 +++++++++++++++++++++
 tests/testdisplay.c     | 304 +++++++------------------
 8 files changed, 866 insertions(+), 513 deletions(-)
 create mode 100644 tests/kms_render.c

-- 
1.8.1.2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v2 1/6] lib: move connector_type_str and co to drmtest
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
@ 2013-06-05 19:25     ` Imre Deak
  2013-06-05 19:25     ` [PATCH v2 2/6] lib: add kmstest_cairo_printf_line Imre Deak
                       ` (4 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

These are used by multiple test cases, so make them shared.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
---
 demos/intel_sprite_on.c | 58 ++++------------------------------------------
 lib/drmtest.c           | 54 +++++++++++++++++++++++++++++++++++++++++++
 lib/drmtest.h           |  3 +++
 tests/testdisplay.c     | 61 ++++---------------------------------------------
 4 files changed, 65 insertions(+), 111 deletions(-)

diff --git a/demos/intel_sprite_on.c b/demos/intel_sprite_on.c
index 62bd98e..783f9af 100644
--- a/demos/intel_sprite_on.c
+++ b/demos/intel_sprite_on.c
@@ -53,56 +53,6 @@
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-struct type_name {
-	int                 type;
-	const char          *name;
-};
-
-#define type_name_fn(res) \
-	static const char * res##_str(int type) {		\
-		unsigned int i;					\
-		for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
-			if (res##_names[i].type == type)	\
-			return res##_names[i].name;		\
-		}						\
-		return "(invalid)";				\
-	}
-
-struct type_name encoder_type_names[] = {
-	{ DRM_MODE_ENCODER_NONE, "none" },
-	{ DRM_MODE_ENCODER_DAC, "DAC" },
-	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
-	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
-	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
-};
-type_name_fn(encoder_type)
-
-struct type_name connector_status_names[] = {
-	{ DRM_MODE_CONNECTED, "connected" },
-	{ DRM_MODE_DISCONNECTED, "disconnected" },
-	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
-};
-type_name_fn(connector_status)
-
-struct type_name connector_type_names[] = {
-	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
-	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
-	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
-	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
-	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
-	{ DRM_MODE_CONNECTOR_Composite, "composite" },
-	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
-	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
-	{ DRM_MODE_CONNECTOR_Component, "component" },
-	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
-	{ DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
-	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
-	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
-	{ DRM_MODE_CONNECTOR_TV, "TV" },
-	{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
-};
-type_name_fn(connector_type)
-
 /*
  * Mode setting with the kernel interfaces is a bit of a chore.
  * First you have to find the connector in question and make sure the
@@ -157,8 +107,8 @@ static void dump_connectors(int gfx_fd, drmModeRes *resources)
 		printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
 			connector->connector_id,
 			connector->encoder_id,
-			connector_status_str(connector->connection),
-			connector_type_str(connector->connector_type),
+			kmstest_connector_status_str(connector->connection),
+			kmstest_connector_type_str(connector->connector_type),
 			connector->mmWidth, connector->mmHeight,
 			connector->count_modes);
 
@@ -744,14 +694,14 @@ static void ricochet(int tiled, int sprite_w, int sprite_h,
 				curr_connector.mode.flags,
 				curr_connector.encoder->encoder_id,
 				curr_connector.encoder->encoder_type,
-				encoder_type_str(curr_connector.encoder->encoder_type),
+				kmstest_encoder_type_str(curr_connector.encoder->encoder_type),
 				curr_connector.encoder->crtc_id,
 				curr_connector.encoder->possible_crtcs,
 				curr_connector.encoder->possible_clones,
 				curr_connector.connector->connector_id,
 				curr_connector.connector->encoder_id,
 				curr_connector.connector->connector_type,
-				connector_type_str(curr_connector.connector->connector_type),
+				kmstest_connector_type_str(curr_connector.connector->connector_type),
 				curr_connector.connector->connector_type_id);
 
 			printf("Sprite surface dimensions = %dx%d\n"
diff --git a/lib/drmtest.c b/lib/drmtest.c
index d17dbb0..3c4812f 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -1023,6 +1023,60 @@ void kmstest_remove_fb(int fd, int fb_id)
 	do_or_die(drmModeRmFB(fd, fb_id));
 }
 
+struct type_name {
+	int type;
+	const char *name;
+};
+
+#define type_name_fn(res) \
+const char * kmstest_##res##_str(int type) {		\
+	unsigned int i;					\
+	for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
+		if (res##_names[i].type == type)	\
+			return res##_names[i].name;	\
+	}						\
+	return "(invalid)";				\
+}
+
+struct type_name encoder_type_names[] = {
+	{ DRM_MODE_ENCODER_NONE, "none" },
+	{ DRM_MODE_ENCODER_DAC, "DAC" },
+	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
+	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
+	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
+};
+
+type_name_fn(encoder_type)
+
+struct type_name connector_status_names[] = {
+	{ DRM_MODE_CONNECTED, "connected" },
+	{ DRM_MODE_DISCONNECTED, "disconnected" },
+	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
+};
+
+type_name_fn(connector_status)
+
+struct type_name connector_type_names[] = {
+	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
+	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
+	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
+	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
+	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
+	{ DRM_MODE_CONNECTOR_Composite, "composite" },
+	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
+	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
+	{ DRM_MODE_CONNECTOR_Component, "component" },
+	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
+	{ DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
+	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
+	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
+	{ DRM_MODE_CONNECTOR_TV, "TV" },
+	{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
+};
+
+type_name_fn(connector_type)
+
+
 void kmstest_dump_mode(drmModeModeInfo *mode)
 {
 	printf("  %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n",
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 7202ad5..38aeb9d 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -119,6 +119,9 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 void kmstest_remove_fb(int fd, int fb_id);
 void kmstest_dump_mode(drmModeModeInfo *mode);
 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
+const char *kmstest_encoder_type_str(int type);
+const char *kmstest_connector_status_str(int type);
+const char *kmstest_connector_type_str(int type);
 
 inline static void _do_or_die(const char *function, int line, int ret)
 {
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 80cd112..e7a2555 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -88,59 +88,6 @@ uint32_t *fb_ptr;
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
-struct type_name {
-	int type;
-	const char *name;
-};
-
-#define type_name_fn(res) \
-static const char * res##_str(int type) {			\
-	unsigned int i;					\
-	for (i = 0; i < ARRAY_SIZE(res##_names); i++) { \
-		if (res##_names[i].type == type)	\
-			return res##_names[i].name;	\
-	}						\
-	return "(invalid)";				\
-}
-
-struct type_name encoder_type_names[] = {
-	{ DRM_MODE_ENCODER_NONE, "none" },
-	{ DRM_MODE_ENCODER_DAC, "DAC" },
-	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
-	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
-	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
-};
-
-type_name_fn(encoder_type)
-
-struct type_name connector_status_names[] = {
-	{ DRM_MODE_CONNECTED, "connected" },
-	{ DRM_MODE_DISCONNECTED, "disconnected" },
-	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
-};
-
-type_name_fn(connector_status)
-
-struct type_name connector_type_names[] = {
-	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
-	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
-	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
-	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
-	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
-	{ DRM_MODE_CONNECTOR_Composite, "composite" },
-	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
-	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
-	{ DRM_MODE_CONNECTOR_Component, "component" },
-	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
-	{ DRM_MODE_CONNECTOR_DisplayPort, "DisplayPort" },
-	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
-	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
-	{ DRM_MODE_CONNECTOR_TV, "TV" },
-	{ DRM_MODE_CONNECTOR_eDP, "Embedded DisplayPort" },
-};
-
-type_name_fn(connector_type)
-
 /*
  * Mode setting with the kernel interfaces is a bit of a chore.
  * First you have to find the connector in question and make sure the
@@ -185,8 +132,8 @@ static void dump_connectors_fd(int drmfd)
 		printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n",
 		       connector->connector_id,
 		       connector->encoder_id,
-		       connector_status_str(connector->connection),
-		       connector_type_str(connector->connector_type),
+		       kmstest_connector_status_str(connector->connection),
+		       kmstest_connector_type_str(connector->connector_type),
 		       connector->mmWidth, connector->mmHeight,
 		       connector->count_modes);
 
@@ -390,7 +337,7 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	/* Get text extents for each string */
 	snprintf(name_buf, sizeof name_buf, "%s",
-		 connector_type_str(c->connector->connector_type));
+		 kmstest_connector_type_str(c->connector->connector_type));
 	cairo_set_font_size(cr, 48);
 	cairo_select_font_face(cr, "Helvetica",
 			       CAIRO_FONT_SLANT_NORMAL,
@@ -399,7 +346,7 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	snprintf(mode_buf, sizeof mode_buf, "%s @ %dHz on %s encoder",
 		 c->mode.name, c->mode.vrefresh,
-		 encoder_type_str(c->encoder->encoder_type));
+		 kmstest_encoder_type_str(c->encoder->encoder_type));
 	cairo_set_font_size(cr, 36);
 	cairo_text_extents(cr, mode_buf, &mode_extents);
 
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 2/6] lib: add kmstest_cairo_printf_line
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
  2013-06-05 19:25     ` [PATCH v2 1/6] lib: move connector_type_str and co to drmtest Imre Deak
@ 2013-06-05 19:25     ` Imre Deak
  2013-06-05 19:27       ` Rodrigo Vivi
  2013-06-05 20:04       ` [PATCH v3 " Imre Deak
  2013-06-05 19:25     ` [PATCH v2 3/6] lib: use kmstest_cairo_printf_line in paint_marker Imre Deak
                       ` (3 subsequent siblings)
  5 siblings, 2 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/drmtest.c       | 44 ++++++++++++++++++++++++
 lib/drmtest.h       | 13 ++++++++
 tests/testdisplay.c | 96 ++++++++++++++++-------------------------------------
 3 files changed, 86 insertions(+), 67 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 3c4812f..71dd06b 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -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);
 }
 
+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 {
 	topleft,
 	topright,
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)
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 3/6] lib: use kmstest_cairo_printf_line in paint_marker
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
  2013-06-05 19:25     ` [PATCH v2 1/6] lib: move connector_type_str and co to drmtest Imre Deak
  2013-06-05 19:25     ` [PATCH v2 2/6] lib: add kmstest_cairo_printf_line Imre Deak
@ 2013-06-05 19:25     ` Imre Deak
  2013-06-05 19:29       ` Rodrigo Vivi
  2013-06-05 19:25     ` [PATCH v2 4/6] lib: add kmstest_get_connector_config Imre Deak
                       ` (2 subsequent siblings)
  5 siblings, 1 reply; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 lib/drmtest.c | 64 +++++++++++++----------------------------------------------
 1 file changed, 14 insertions(+), 50 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 71dd06b..3ad77a8 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -951,46 +951,12 @@ int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
 	return extents.width;
 }
 
-enum corner {
-	topleft,
-	topright,
-	bottomleft,
-	bottomright,
-};
-
 static void
-paint_marker(cairo_t *cr, int x, int y, char *str, enum corner text_location)
+paint_marker(cairo_t *cr, int x, int y)
 {
-	cairo_text_extents_t extents;
+	enum kmstest_text_align align;
 	int xoff, yoff;
 
-	cairo_set_font_size(cr, 18);
-	cairo_text_extents(cr, str, &extents);
-
-	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_move_to(cr, x, y - 20);
 	cairo_line_to(cr, x, y + 20);
 	cairo_move_to(cr, x - 20, y);
@@ -1004,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,
@@ -1021,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,
@@ -1035,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);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 4/6] lib: add kmstest_get_connector_config
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
                       ` (2 preceding siblings ...)
  2013-06-05 19:25     ` [PATCH v2 3/6] lib: use kmstest_cairo_printf_line in paint_marker Imre Deak
@ 2013-06-05 19:25     ` Imre Deak
  2013-06-05 19:25     ` [PATCH v2 5/6] lib: refactor kmstest_create_fb Imre Deak
  2013-06-05 19:25     ` [PATCH v2 6/6] tests: add kms_render Imre Deak
  5 siblings, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

This is used by multiple test cases, so make it shared.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
---
 lib/drmtest.c       | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/drmtest.h       |  14 ++++++
 tests/kms_flip.c    | 115 ++++++++------------------------------------
 tests/testdisplay.c | 134 +++++++++++++++-------------------------------------
 4 files changed, 206 insertions(+), 191 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 3ad77a8..7368077 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -1317,3 +1317,137 @@ int drmtest_set_vt_graphics_mode(void)
 	return orig_vt_mode < 0 ? -1 : 0;
 }
 
+static int get_connector_default_mode(int drm_fd, drmModeConnector *connector,
+				      drmModeModeInfo *mode)
+{
+	drmModeRes *resources;
+	int i;
+
+	resources = drmModeGetResources(drm_fd);
+	if (!resources) {
+		perror("drmModeGetResources failed");
+
+		return -1;
+	}
+
+	if (!connector->count_modes) {
+		fprintf(stderr, "no modes for connector %d\n",
+			connector->connector_id);
+		drmModeFreeResources(resources);
+
+		return -1;
+	}
+
+	for (i = 0; i < connector->count_modes; i++) {
+		if (i == 0 ||
+		    connector->modes[i].type & DRM_MODE_TYPE_PREFERRED) {
+			*mode = connector->modes[i];
+			if (mode->type & DRM_MODE_TYPE_PREFERRED)
+				break;
+		}
+	}
+
+	drmModeFreeResources(resources);
+
+	return 0;
+}
+
+int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
+				 unsigned long crtc_idx_mask,
+				 struct kmstest_connector_config *config)
+{
+	drmModeRes *resources;
+	drmModeConnector *connector;
+	drmModeEncoder *encoder;
+	int i, j;
+
+	resources = drmModeGetResources(drm_fd);
+	if (!resources) {
+		perror("drmModeGetResources failed");
+		goto err1;
+	}
+
+	/* First, find the connector & mode */
+	connector = drmModeGetConnector(drm_fd, connector_id);
+	if (!connector)
+		goto err2;
+
+	if (connector->connection != DRM_MODE_CONNECTED)
+		goto err3;
+
+	if (!connector->count_modes) {
+		fprintf(stderr, "connector %d has no modes\n", connector_id);
+		goto err3;
+	}
+
+	if (connector->connector_id != connector_id) {
+		fprintf(stderr, "connector id doesn't match (%d != %d)\n",
+			connector->connector_id, connector_id);
+		goto err3;
+	}
+
+	/*
+	 * Find given CRTC if crtc_id != 0 or else the first CRTC not in use.
+	 * In both cases find the first compatible encoder and skip the CRTC
+	 * if there is non such.
+	 */
+	encoder = NULL;		/* suppress GCC warning */
+	for (i = 0; i < resources->count_crtcs; i++) {
+		if (!resources->crtcs[i] || !(crtc_idx_mask & (1 << i)))
+			continue;
+
+		/* Now get a compatible encoder */
+		for (j = 0; j < connector->count_encoders; j++) {
+			encoder = drmModeGetEncoder(drm_fd,
+						    connector->encoders[j]);
+
+			if (!encoder) {
+				fprintf(stderr, "could not get encoder %d: %s\n",
+					resources->encoders[j], strerror(errno));
+
+				continue;
+			}
+
+			if (encoder->possible_crtcs & (1 << i))
+				goto found;
+
+			drmModeFreeEncoder(encoder);
+		}
+	}
+
+	fprintf(stderr,
+		"no crtc with a compatible encoder (crtc_idx_mask %08lx)\n",
+		crtc_idx_mask);
+	goto err3;
+
+found:
+	if (get_connector_default_mode(drm_fd, connector,
+				       &config->default_mode) < 0)
+		goto err4;
+
+	config->connector = connector;
+	config->encoder = encoder;
+	config->crtc = drmModeGetCrtc(drm_fd, resources->crtcs[i]);
+	config->crtc_idx = i;
+	config->pipe = kmstest_get_pipe_from_crtc_id(drm_fd,
+						     config->crtc->crtc_id);
+
+	drmModeFreeResources(resources);
+
+	return 0;
+err4:
+	drmModeFreeEncoder(encoder);
+err3:
+	drmModeFreeConnector(connector);
+err2:
+	drmModeFreeResources(resources);
+err1:
+	return -1;
+}
+
+void kmstest_free_connector_config(struct kmstest_connector_config *config)
+{
+	drmModeFreeCrtc(config->crtc);
+	drmModeFreeEncoder(config->encoder);
+	drmModeFreeConnector(config->connector);
+}
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 3c1368d..89ded11 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -101,6 +101,20 @@ void drmtest_init_aperture_trashers(drm_intel_bufmgr *bufmgr);
 void drmtest_trash_aperture(void);
 void drmtest_cleanup_aperture_trashers(void);
 
+struct kmstest_connector_config {
+	drmModeCrtc *crtc;
+	drmModeConnector *connector;
+	drmModeEncoder *encoder;
+	drmModeModeInfo default_mode;
+	int crtc_idx;
+	int pipe;
+};
+
+int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
+				 unsigned long crtc_idx_mask,
+				 struct kmstest_connector_config *config);
+void kmstest_free_connector_config(struct kmstest_connector_config *config);
+
 /* helpers to create nice-looking framebuffers */
 struct kmstest_fb {
 	uint32_t fb_id;
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index 735b4dd..c9b3d8a 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -825,97 +825,23 @@ static void update_all_state(struct test_output *o,
 		update_state(&o->vblank_state);
 }
 
-static void connector_find_preferred_mode(struct test_output *o, int crtc_id)
+static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
+					  struct test_output *o)
 {
-	drmModeConnector *connector;
-	drmModeEncoder *encoder = NULL;
-	int i, j;
-
-	/* First, find the connector & mode */
-	o->mode_valid = 0;
-	o->crtc = 0;
-	connector = drmModeGetConnector(drm_fd, o->id);
-	assert(connector);
-
-	if (connector->connection != DRM_MODE_CONNECTED) {
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (!connector->count_modes) {
-		fprintf(stderr, "connector %d has no modes\n", o->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (connector->connector_id != o->id) {
-		fprintf(stderr, "connector id doesn't match (%d != %d)\n",
-			connector->connector_id, o->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	for (j = 0; j < connector->count_modes; j++) {
-		o->mode = connector->modes[j];
-		if (o->mode.type & DRM_MODE_TYPE_PREFERRED) {
-			o->mode_valid = 1;
-			break;
-		}
-	}
-
-	if (!o->mode_valid) {
-		if (connector->count_modes > 0) {
-			/* use the first mode as test mode */
-			o->mode = connector->modes[0];
-			o->mode_valid = 1;
-		}
-		else {
-			fprintf(stderr, "failed to find any modes on connector %d\n",
-				o->id);
-			return;
-		}
-	}
+	struct kmstest_connector_config config;
 
-	/* Now get the encoder */
-	for (i = 0; i < connector->count_encoders; i++) {
-		encoder = drmModeGetEncoder(drm_fd, connector->encoders[i]);
-
-		if (!encoder) {
-			fprintf(stderr, "could not get encoder %i: %s\n",
-				resources->encoders[i], strerror(errno));
-			drmModeFreeEncoder(encoder);
-			continue;
-		}
-
-		break;
-	}
-
-	o->encoder = encoder;
-
-	if (i == resources->count_encoders) {
-		fprintf(stderr, "failed to find encoder\n");
-		o->mode_valid = 0;
-		return;
-	}
-
-	/* Find first CRTC not in use */
-	for (i = 0; i < resources->count_crtcs; i++) {
-		if (resources->crtcs[i] != crtc_id)
-			continue;
-		if (resources->crtcs[i] &&
-		    (o->encoder->possible_crtcs & (1<<i))) {
-			o->crtc = resources->crtcs[i];
-			break;
-		}
-	}
-
-	if (!o->crtc) {
-		fprintf(stderr, "could not find requested crtc %d\n", crtc_id);
+	if (kmstest_get_connector_config(drm_fd, connector_id, 1 << crtc_idx,
+					 &config) < 0) {
 		o->mode_valid = 0;
 		return;
 	}
 
-	o->connector = connector;
+	o->connector = config.connector;
+	o->encoder = config.encoder;
+	o->crtc = config.crtc->crtc_id;
+	o->pipe = config.pipe;
+	o->mode = config.default_mode;
+	o->mode_valid = 1;
 }
 
 static void
@@ -1042,21 +968,21 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)
 	return end - start;
 }
 
-static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
+static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
 {
 	unsigned ellapsed;
 
 	o->bpp = 32;
 	o->depth = 24;
 
-	connector_find_preferred_mode(o, crtc);
+	connector_find_preferred_mode(o->id, crtc_idx, o);
 	if (!o->mode_valid)
 		return;
 
 	last_connector = o->connector;
 
 	fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
-		o->test_name, crtc, o->id);
+		o->test_name, o->crtc, o->id);
 
 	o->fb_width = o->mode.hdisplay;
 	o->fb_height = o->mode.vdisplay;
@@ -1116,7 +1042,7 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
 		check_final_state(o, &o->vblank_state, ellapsed);
 
 	fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
-		o->test_name, crtc, o->id);
+		o->test_name, o->crtc, o->id);
 
 	kmstest_remove_fb(drm_fd, o->fb_ids[2]);
 	kmstest_remove_fb(drm_fd, o->fb_ids[1]);
@@ -1131,7 +1057,8 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)
 static int run_test(int duration, int flags, const char *test_name)
 {
 	struct test_output o;
-	int c, i;
+	int c;
+	int crtc_idx;
 
 	resources = drmModeGetResources(drm_fd);
 	if (!resources) {
@@ -1142,19 +1069,15 @@ static int run_test(int duration, int flags, const char *test_name)
 
 	/* Find any connected displays */
 	for (c = 0; c < resources->count_connectors; c++) {
-		for (i = 0; i < resources->count_crtcs; i++) {
-			int crtc;
-
+		for (crtc_idx = 0; crtc_idx < resources->count_crtcs; crtc_idx++) {
 			memset(&o, 0, sizeof(o));
 			o.test_name = test_name;
 			o.id = resources->connectors[c];
 			o.flags = flags;
 			o.flip_state.name = "flip";
 			o.vblank_state.name = "vblank";
-			crtc = resources->crtcs[i];
-			o.pipe = kmstest_get_pipe_from_crtc_id(drm_fd, crtc);
 
-			run_test_on_crtc(&o, crtc, duration);
+			run_test_on_crtc(&o, crtc_idx, duration);
 		}
 	}
 
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index b10c3b9..4470339 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -102,6 +102,7 @@ struct connector {
 	drmModeEncoder *encoder;
 	drmModeConnector *connector;
 	int crtc;
+	int crtc_idx;
 	int pipe;
 };
 
@@ -185,101 +186,31 @@ static void dump_crtcs_fd(int drmfd)
 	drmModeFreeResources(mode_resources);
 }
 
-static void connector_find_preferred_mode(struct connector *c)
+static void connector_find_preferred_mode(uint32_t connector_id,
+					  unsigned long crtc_idx_mask,
+					  int mode_num, struct connector *c)
 {
-	drmModeConnector *connector;
-	drmModeEncoder *encoder = NULL;
-	int i, j;
-
-	/* First, find the connector & mode */
-	c->mode_valid = 0;
-	connector = drmModeGetConnector(drm_fd, c->id);
-	if (!connector) {
-		fprintf(stderr, "could not get connector %d: %s\n",
-			c->id, strerror(errno));
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (connector->connection != DRM_MODE_CONNECTED) {
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (!connector->count_modes) {
-		fprintf(stderr, "connector %d has no modes\n", c->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	if (connector->connector_id != c->id) {
-		fprintf(stderr, "connector id doesn't match (%d != %d)\n",
-			connector->connector_id, c->id);
-		drmModeFreeConnector(connector);
-		return;
-	}
-
-	for (j = 0; j < connector->count_modes; j++) {
-		c->mode = connector->modes[j];
-		if (c->mode.type & DRM_MODE_TYPE_PREFERRED) {
-			c->mode_valid = 1;
-			break;
-		}
-	}
-
-	if ( specified_mode_num != -1 ){
-		c->mode = connector->modes[specified_mode_num];
-		if (c->mode.type & DRM_MODE_TYPE_PREFERRED)
-			c->mode_valid = 1;
-	}
-
-	if (!c->mode_valid) {
-		if (connector->count_modes > 0) {
-			/* use the first mode as test mode */
-			c->mode = connector->modes[0];
-			c->mode_valid = 1;
-		}
-		else {
-			fprintf(stderr, "failed to find any modes on connector %d\n",
-				c->id);
-			return;
-		}
-	}
-
-	/* Now get the encoder */
-	for (i = 0; i < connector->count_encoders; i++) {
-		encoder = drmModeGetEncoder(drm_fd, connector->encoders[i]);
-
-		if (!encoder) {
-			fprintf(stderr, "could not get encoder %i: %s\n",
-				resources->encoders[i], strerror(errno));
-			drmModeFreeEncoder(encoder);
-			continue;
-		}
-
-		break;
-	}
-
-	c->encoder = encoder;
+	struct kmstest_connector_config config;
 
-	if (i == resources->count_encoders) {
-		fprintf(stderr, "failed to find encoder\n");
+	if (kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask,
+					 &config) < 0) {
 		c->mode_valid = 0;
 		return;
 	}
 
-	/* Find first CRTC not in use */
-	for (i = 0; i < resources->count_crtcs; i++) {
-		if (resources->crtcs[i] && (c->encoder->possible_crtcs & (1<<i)))
-			break;
+	c->connector = config.connector;
+	c->encoder = config.encoder;
+	c->crtc = config.crtc->crtc_id;
+	c->crtc_idx = config.crtc_idx;
+	c->pipe = config.pipe;
+
+	if (mode_num != -1) {
+		assert(mode_num < config.connector->count_modes);
+		c->mode = config.connector->modes[mode_num];
+	} else {
+		c->mode = config.default_mode;
 	}
-	c->crtc = resources->crtcs[i];
-	c->pipe = i;
-
-	if(test_preferred_mode || force_mode || specified_mode_num != -1)
-		resources->crtcs[i] = 0;
-
-	c->connector = connector;
+	c->mode_valid = 1;
 }
 
 static void
@@ -409,10 +340,6 @@ set_mode(struct connector *c)
 	else if (depth > 16 && depth <= 32)
 		bpp = 32;
 
-	connector_find_preferred_mode(c);
-	if (!c->mode_valid)
-		return;
-
 	test_mode_num = 1;
 	if (force_mode){
 		memcpy( &c->mode, &force_timing, sizeof(force_timing));
@@ -506,13 +433,30 @@ int update_display(void)
 	}
 
 	if (test_preferred_mode || test_all_modes || force_mode || specified_disp_id != -1) {
+		unsigned long crtc_idx_mask = -1UL;
+
 		/* Find any connected displays */
 		for (c = 0; c < resources->count_connectors; c++) {
-			connectors[c].id = resources->connectors[c];
-			if ( specified_disp_id != -1 && connectors[c].id != specified_disp_id )
+			struct connector *connector = &connectors[c];
+
+			connector->id = resources->connectors[c];
+			if (specified_disp_id != -1 &&
+			    connector->id != specified_disp_id)
+				continue;
+
+			connector_find_preferred_mode(connector->id,
+						      crtc_idx_mask,
+						      specified_mode_num,
+						      connector);
+			if (!connector->mode_valid)
 				continue;
 
-			set_mode(&connectors[c]);
+			set_mode(connector);
+
+			if (test_preferred_mode || force_mode ||
+			    specified_mode_num != -1)
+				crtc_idx_mask &= ~(1 << connector->crtc_idx);
+
 		}
 	}
 	drmModeFreeResources(resources);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 5/6] lib: refactor kmstest_create_fb
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
                       ` (3 preceding siblings ...)
  2013-06-05 19:25     ` [PATCH v2 4/6] lib: add kmstest_get_connector_config Imre Deak
@ 2013-06-05 19:25     ` Imre Deak
  2013-06-05 19:25     ` [PATCH v2 6/6] tests: add kms_render Imre Deak
  5 siblings, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

Factor out parts that will be used by an upcoming patch adding
kmstest_create_fb2.

Also call the fb paint functions directly, there is not much
point in passing a function pointer for that.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
---
 lib/drmtest.c       | 176 ++++++++++++++++++++++++++++++++--------------------
 lib/drmtest.h       |  15 +++--
 tests/kms_flip.c    |  30 +++++----
 tests/testdisplay.c |  15 +++--
 4 files changed, 147 insertions(+), 89 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 7368077..a551e7c 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -39,6 +39,7 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include <linux/kd.h>
+#include <drm/drm_fourcc.h>
 
 #include "drmtest.h"
 #include "i915_drm.h"
@@ -788,16 +789,14 @@ void drmtest_cleanup_aperture_trashers(void)
 }
 
 /* helpers to create nice-looking framebuffers */
-static cairo_surface_t *
-paint_allocate_surface(int fd, int width, int height, int depth, int bpp,
-		       bool tiled,
-		       struct kmstest_fb *fb_info)
+static int create_bo_for_fb(int fd, int width, int height, int bpp,
+			    bool tiled, uint32_t *gem_handle_ret,
+			    unsigned *size_ret, unsigned *stride_ret)
 {
-	cairo_format_t format;
 	struct drm_i915_gem_set_tiling set_tiling;
+	uint32_t gem_handle;
 	int size;
 	unsigned stride;
-	uint32_t *fb_ptr;
 
 	if (tiled) {
 		int v;
@@ -823,49 +822,24 @@ paint_allocate_surface(int fd, int width, int height, int depth, int bpp,
 		size = stride * height;
 	}
 
-	switch (depth) {
-	case 16:
-		format = CAIRO_FORMAT_RGB16_565;
-		break;
-	case 24:
-		format = CAIRO_FORMAT_RGB24;
-		break;
-#if 0
-	case 30:
-		format = CAIRO_FORMAT_RGB30;
-		break;
-#endif
-	case 32:
-		format = CAIRO_FORMAT_ARGB32;
-		break;
-	default:
-		fprintf(stderr, "bad depth %d\n", depth);
-		return NULL;
-	}
-
-	assert (bpp >= depth);
-
-	fb_info->gem_handle = gem_create(fd, size);
+	gem_handle = gem_create(fd, size);
 
 	if (tiled) {
-		set_tiling.handle = fb_info->gem_handle;
+		set_tiling.handle = gem_handle;
 		set_tiling.tiling_mode = I915_TILING_X;
 		set_tiling.stride = stride;
 		if (ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling)) {
 			fprintf(stderr, "set tiling failed: %s (stride=%d, size=%d)\n",
 				strerror(errno), stride, size);
-			return NULL;
+			return -1;
 		}
 	}
 
-	fb_ptr = gem_mmap(fd, fb_info->gem_handle, size, PROT_READ | PROT_WRITE);
-
-	fb_info->stride = stride;
-	fb_info->size = size;
+	*stride_ret = stride;
+	*size_ret = size;
+	*gem_handle_ret = gem_handle;
 
-	return cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
-						   format, width, height,
-						   stride);
+	return 0;
 }
 
 static void
@@ -981,23 +955,8 @@ paint_marker(cairo_t *cr, int x, int y)
 	kmstest_cairo_printf_line(cr, align, 0, "(%d, %d)", x, y);
 }
 
-unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
-			       int depth, bool tiled,
-			       struct kmstest_fb *fb_info,
-			       kmstest_paint_func paint_func,
-			       void *func_arg)
+void kmstest_paint_test_pattern(cairo_t *cr, int width, int height)
 {
-	cairo_surface_t *surface;
-	cairo_status_t status;
-	cairo_t *cr;
-	unsigned int fb_id;
-
-	surface = paint_allocate_surface(fd, width, height, depth, bpp,
-					 tiled, fb_info);
-	assert(surface);
-
-	cr = cairo_create(surface);
-
 	paint_test_patterns(cr, width, height);
 
 	cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
@@ -1008,27 +967,112 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 	paint_marker(cr, 0, height);
 	paint_marker(cr, width, height);
 
-	if (paint_func)
-		paint_func(cr, width, height, func_arg);
+	assert(!cairo_status(cr));
+}
+
+#define DF(did, cid, _bpp, _depth)	\
+	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
+static struct format_desc_struct {
+	uint32_t drm_id;
+	cairo_format_t cairo_id;
+	const char *name;
+	int bpp;
+	int depth;
+} format_desc[] = {
+	DF(RGB565,	RGB16_565,	16, 16),
+	DF(RGB888,	INVALID,	24, 24),
+	DF(XRGB8888,	RGB24,		32, 24),
+	DF(XRGB2101010,	RGB30,		32, 30),
+	DF(ARGB8888,	ARGB32,		32, 32),
+};
+#undef DF
+
+#define for_each_format(f)	\
+	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
+
+static uint32_t bpp_depth_to_drm_format(int bpp, int depth)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->bpp == bpp && f->depth == depth)
+			return f->drm_id;
+
+	abort();
+}
+
+/* Return fb_id on success, 0 on error */
+unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
+			       int depth, bool tiled, struct kmstest_fb *fb)
+{
+	memset(fb, 0, sizeof(*fb));
 
-	status = cairo_status(cr);
-	assert(!status);
-	cairo_destroy(cr);
+	if (create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
+			       &fb->size, &fb->stride) < 0)
+		return 0;
+
+	if (drmModeAddFB(fd, width, height, depth, bpp, fb->stride,
+			       fb->gem_handle, &fb->fb_id) < 0) {
+		gem_close(fd, fb->gem_handle);
+
+		return 0;
+	}
+
+	fb->width = width;
+	fb->height = height;
+	fb->drm_format = bpp_depth_to_drm_format(bpp, depth);
+
+	return fb->fb_id;
+}
+
+static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
 
-	do_or_die(drmModeAddFB(fd, width, height, depth, bpp,
-			       fb_info->stride,
-			       fb_info->gem_handle, &fb_id));
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->cairo_id;
 
+	abort();
+}
+
+static cairo_t *create_cairo_ctx(int fd, struct kmstest_fb *fb)
+{
+	cairo_t *cr;
+	cairo_surface_t *surface;
+	cairo_format_t cformat;
+	void *fb_ptr;
+
+	cformat = drm_format_to_cairo(fb->drm_format);
+	fb_ptr = gem_mmap(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE);
+	surface = cairo_image_surface_create_for_data((unsigned char *)fb_ptr,
+						   cformat, fb->width,
+						   fb->height, fb->stride);
+	assert(surface);
+	cr = cairo_create(surface);
 	cairo_surface_destroy(surface);
 
-	fb_info->fb_id = fb_id;
+	return cr;
+}
+
+cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb)
+{
+
+	if (!fb->cairo_ctx)
+		fb->cairo_ctx = create_cairo_ctx(fd, fb);
+
+	gem_set_domain(fd, fb->gem_handle, I915_GEM_DOMAIN_CPU,
+		       I915_GEM_DOMAIN_CPU);
 
-	return fb_id;
+	return fb->cairo_ctx;
 }
 
-void kmstest_remove_fb(int fd, int fb_id)
+void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
 {
-	do_or_die(drmModeRmFB(fd, fb_id));
+	if (fb->cairo_ctx)
+		cairo_destroy(fb->cairo_ctx);
+	do_or_die(drmModeRmFB(fd, fb->fb_id));
+	gem_close(fd, fb->gem_handle);
 }
 
 struct type_name {
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 89ded11..218914f 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -119,8 +119,13 @@ void kmstest_free_connector_config(struct kmstest_connector_config *config);
 struct kmstest_fb {
 	uint32_t fb_id;
 	uint32_t gem_handle;
+	uint32_t drm_format;
+	int width;
+	int height;
+	int depth;
 	unsigned stride;
 	unsigned size;
+	cairo_t *cairo_ctx;
 };
 
 enum kmstest_text_align {
@@ -136,14 +141,12 @@ 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,
 			       int depth, bool tiled,
-			       struct kmstest_fb *fb_info,
-			       kmstest_paint_func paint_func,
-			       void *func_arg);
-void kmstest_remove_fb(int fd, int fb_id);
+			       struct kmstest_fb *fb_info);
+void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
+cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
+void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
 void kmstest_dump_mode(drmModeModeInfo *mode);
 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
 const char *kmstest_encoder_type_str(int type);
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index c9b3d8a..aeeaace 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -844,10 +844,13 @@ static void connector_find_preferred_mode(uint32_t connector_id, int crtc_idx,
 	o->mode_valid = 1;
 }
 
-static void
-paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
+static void paint_flip_mode(struct kmstest_fb *fb, bool odd_frame)
 {
-	bool odd_frame = (bool) priv;
+	cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
+	int width = fb->width;
+	int height = fb->height;
+
+	kmstest_paint_test_pattern(cr, width, height);
 
 	if (odd_frame)
 		cairo_rectangle(cr, width/4, height/2, width/4, height/8);
@@ -856,6 +859,8 @@ paint_flip_mode(cairo_t *cr, int width, int height, void *priv)
 
 	cairo_set_source_rgb(cr, 1, 1, 1);
 	cairo_fill(cr);
+
+	assert(!cairo_status(cr));
 }
 
 static int
@@ -991,20 +996,21 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
 		o->fb_width *= 2;
 
 	o->fb_ids[0] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
-					 o->bpp, o->depth, false, &o->fb_info[0],
-					 paint_flip_mode, (void *)false);
+					 o->bpp, o->depth, false, &o->fb_info[0]);
 	o->fb_ids[1] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
-					 o->bpp, o->depth, false, &o->fb_info[1],
-					 paint_flip_mode, (void *)true);
+					 o->bpp, o->depth, false, &o->fb_info[1]);
 	o->fb_ids[2] = kmstest_create_fb(drm_fd, o->fb_width, o->fb_height,
-					 o->bpp, o->depth, true, &o->fb_info[2],
-					 paint_flip_mode, (void *)true);
+					 o->bpp, o->depth, true, &o->fb_info[2]);
 
 	if (!o->fb_ids[0] || !o->fb_ids[1] || !o->fb_ids[2]) {
 		fprintf(stderr, "failed to create fbs\n");
 		exit(3);
 	}
 
+	paint_flip_mode(&o->fb_info[0], false);
+	paint_flip_mode(&o->fb_info[1], true);
+	paint_flip_mode(&o->fb_info[2], true);
+
 	set_y_tiling(o, 2);
 
 	kmstest_dump_mode(&o->mode);
@@ -1044,9 +1050,9 @@ static void run_test_on_crtc(struct test_output *o, int crtc_idx, int duration)
 	fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
 		o->test_name, o->crtc, o->id);
 
-	kmstest_remove_fb(drm_fd, o->fb_ids[2]);
-	kmstest_remove_fb(drm_fd, o->fb_ids[1]);
-	kmstest_remove_fb(drm_fd, o->fb_ids[0]);
+	kmstest_remove_fb(drm_fd, &o->fb_info[2]);
+	kmstest_remove_fb(drm_fd, &o->fb_info[1]);
+	kmstest_remove_fb(drm_fd, &o->fb_info[0]);
 
 	last_connector = NULL;
 
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 4470339..5ece921 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -258,15 +258,18 @@ static void paint_image(cairo_t *cr, const char *file)
 	cairo_surface_destroy(image);
 }
 
-static void
-paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
+static void paint_output_info(struct connector *c, struct kmstest_fb *fb)
 {
-	struct connector *c = priv;
+	cairo_t *cr = kmstest_get_cairo_ctx(drm_fd, fb);
+	int l_width = fb->width;
+	int l_height = fb->height;
 	double str_width;
 	double x, y, top_y;
 	double max_width;
 	int i;
 
+	kmstest_paint_test_pattern(cr, l_width, l_height);
+
 	cairo_select_font_face(cr, "Helvetica",
 			       CAIRO_FONT_SLANT_NORMAL,
 			       CAIRO_FONT_WEIGHT_NORMAL);
@@ -308,6 +311,8 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	if (qr_code)
 		paint_image(cr, "./pass.png");
+
+	assert(!cairo_status(cr));
 }
 
 static void sighandler(int signo)
@@ -362,8 +367,8 @@ set_mode(struct connector *c)
 		height = c->mode.vdisplay;
 
 		fb_id = kmstest_create_fb(drm_fd, width, height, bpp, depth,
-					  enable_tiling, &fb_info,
-					  paint_output_info, c);
+					  enable_tiling, &fb_info);
+		paint_output_info(c, &fb_info);
 
 		fb_ptr = gem_mmap(drm_fd, fb_info.gem_handle,
 				  fb_info.size, PROT_READ | PROT_WRITE);
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v2 6/6] tests: add kms_render
  2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
                       ` (4 preceding siblings ...)
  2013-06-05 19:25     ` [PATCH v2 5/6] lib: refactor kmstest_create_fb Imre Deak
@ 2013-06-05 19:25     ` Imre Deak
  5 siblings, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 19:25 UTC (permalink / raw)
  To: intel-gfx

Add a test going through all connectors/crtcs/modes/formats painting to
a front FB with CPU or painting to a back FB with CPU and blitting it
to the front FB.

Only formats understood by cairo are supported for now.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
---
 lib/drmtest.c      | 101 ++++++++++++++++++++--
 lib/drmtest.h      |   7 ++
 tests/.gitignore   |   1 +
 tests/Makefile.am  |   1 +
 tests/kms_render.c | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 349 insertions(+), 6 deletions(-)
 create mode 100644 tests/kms_render.c

diff --git a/lib/drmtest.c b/lib/drmtest.c
index a551e7c..d9d58e5 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -842,8 +842,8 @@ static int create_bo_for_fb(int fd, int width, int height, int bpp,
 	return 0;
 }
 
-static void
-paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
+void
+kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
 		     int r, int g, int b)
 {
 	cairo_pattern_t *pat;
@@ -869,16 +869,16 @@ paint_test_patterns(cairo_t *cr, int width, int height)
 	gr_height = height * 0.08;
 	x = (width / 2) - (gr_width / 2);
 
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
+	kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 0, 0);
 
 	y += gr_height;
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
+	kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 1, 0);
 
 	y += gr_height;
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
+	kmstest_paint_color_gradient(cr, x, y, gr_width, gr_height, 0, 0, 1);
 
 	y += gr_height;
-	paint_color_gradient(cr, x, y, gr_width, gr_height, 1, 1, 1);
+	kmstest_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,
@@ -1025,6 +1025,55 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 	return fb->fb_id;
 }
 
+static uint32_t drm_format_to_bpp(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->bpp;
+
+	abort();
+}
+
+unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
+			        bool tiled, struct kmstest_fb *fb)
+{
+	uint32_t handles[4];
+	uint32_t pitches[4];
+	uint32_t offsets[4];
+	uint32_t fb_id;
+	int bpp;
+	int ret;
+
+	memset(fb, 0, sizeof(*fb));
+
+	bpp = drm_format_to_bpp(format);
+	ret = create_bo_for_fb(fd, width, height, bpp, tiled, &fb->gem_handle,
+			      &fb->size, &fb->stride);
+	if (ret < 0)
+		return ret;
+
+	memset(handles, 0, sizeof(handles));
+	handles[0] = fb->gem_handle;
+	memset(pitches, 0, sizeof(pitches));
+	pitches[0] = fb->stride;
+	memset(offsets, 0, sizeof(offsets));
+	if (drmModeAddFB2(fd, width, height, format, handles, pitches,
+			  offsets, &fb_id, 0) < 0) {
+		gem_close(fd, fb->gem_handle);
+
+		return 0;
+	}
+
+	fb->width = width;
+	fb->height = height;
+	fb->drm_format = format;
+	fb->fb_id = fb_id;
+
+	return fb_id;
+}
+
 static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 {
 	struct format_desc_struct *f;
@@ -1075,6 +1124,46 @@ void kmstest_remove_fb(int fd, struct kmstest_fb *fb)
 	gem_close(fd, fb->gem_handle);
 }
 
+const char *kmstest_format_str(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->name;
+
+	return "invalid";
+}
+
+const char *kmstest_pipe_str(int pipe)
+{
+	const char *str[] = { "A", "B", "C" };
+
+	if (pipe > 2)
+		return "invalid";
+
+	return str[pipe];
+}
+
+void kmstest_get_all_formats(const uint32_t **formats, int *format_count)
+{
+	static uint32_t *drm_formats;
+
+	if (!drm_formats) {
+		struct format_desc_struct *f;
+		uint32_t *format;
+
+		drm_formats = calloc(ARRAY_SIZE(format_desc),
+				     sizeof(*drm_formats));
+		format = &drm_formats[0];
+		for_each_format(f)
+			*format++ = f->drm_id;
+	}
+
+	*formats = drm_formats;
+	*format_count = ARRAY_SIZE(format_desc);
+}
+
 struct type_name {
 	int type;
 	const char *name;
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 218914f..e3a9275 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -144,11 +144,18 @@ int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
 unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 			       int depth, bool tiled,
 			       struct kmstest_fb *fb_info);
+unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format,
+			        bool tiled, struct kmstest_fb *fb);
 void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info);
 cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb);
+void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h,
+				  int r, int g, int b);
 void kmstest_paint_test_pattern(cairo_t *cr, int width, int height);
 void kmstest_dump_mode(drmModeModeInfo *mode);
 int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id);
+const char *kmstest_format_str(uint32_t drm_format);
+const char *kmstest_pipe_str(int pipe);
+void kmstest_get_all_formats(const uint32_t **formats, int *format_count);
 const char *kmstest_encoder_type_str(int type);
 const char *kmstest_connector_status_str(int type);
 const char *kmstest_connector_type_str(int type);
diff --git a/tests/.gitignore b/tests/.gitignore
index 3cac813..1f7c691 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -85,6 +85,7 @@ getclient
 getstats
 getversion
 kms_flip
+kms_render
 prime_nv_api
 prime_nv_pcopy
 prime_nv_test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7250968..3f301c9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,6 +33,7 @@ TESTS_progs_M = \
 	gem_tiled_partial_pwrite_pread \
 	$(NOUVEAU_TESTS_M) \
 	kms_flip \
+	kms_render \
 	prime_self_import \
 	$(NULL)
 
diff --git a/tests/kms_render.c b/tests/kms_render.c
new file mode 100644
index 0000000..707ce27
--- /dev/null
+++ b/tests/kms_render.c
@@ -0,0 +1,245 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Imre Deak <imre.deak@intel.com>
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <cairo.h>
+#include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include "drmtest.h"
+#include "testdisplay.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_gpu_tools.h"
+
+drmModeRes *resources;
+int drm_fd;
+static drm_intel_bufmgr *bufmgr;
+struct intel_batchbuffer *batch;
+uint32_t devid;
+
+enum test_flags {
+	TEST_DIRECT_RENDER	= 0x01,
+	TEST_GPU_BLIT		= 0x02,
+};
+
+static int paint_fb(struct kmstest_fb *fb, const char *test_name,
+		    const char *mode_format_str, const char *cconf_str)
+{
+	cairo_t *cr;
+
+	cr = kmstest_get_cairo_ctx(drm_fd, fb);
+	if (!cr)
+		return -1;
+
+	kmstest_paint_color_gradient(cr, 0, 0, fb->width, fb->height, 1, 1, 1);
+	kmstest_paint_test_pattern(cr, fb->width, fb->height);
+
+	cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
+			       CAIRO_FONT_WEIGHT_NORMAL);
+	cairo_move_to(cr, fb->width / 2, fb->height / 2);
+	cairo_set_font_size(cr, 36);
+	kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
+	kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
+	kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
+
+	return 0;
+}
+
+static void gpu_blit(struct kmstest_fb *dst_fb, struct kmstest_fb *src_fb)
+{
+	drm_intel_bo *dst_bo;
+	drm_intel_bo *src_bo;
+
+	dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
+					 dst_fb->gem_handle);
+	assert(dst_bo);
+	src_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "source",
+					 src_fb->gem_handle);
+	assert(src_bo);
+
+	intel_copy_bo(batch, dst_bo, src_bo, src_fb->width, src_fb->height);
+	intel_batchbuffer_flush(batch);
+	gem_quiescent_gpu(drm_fd);
+
+	drm_intel_bo_unreference(src_bo);
+	drm_intel_bo_unreference(dst_bo);
+}
+
+static int test_format(const char *test_name,
+		       struct kmstest_connector_config *cconf,
+		       drmModeModeInfo *mode, uint32_t format,
+		       enum test_flags flags)
+{
+	int width;
+	int height;
+	struct kmstest_fb fb[2];
+	char *mode_format_str;
+	char *cconf_str;
+	int ret;
+
+	ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
+		 mode->name, mode->vrefresh, kmstest_format_str(format));
+	assert(ret > 0);
+	ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
+		       kmstest_pipe_str(cconf->pipe),
+		       kmstest_encoder_type_str(cconf->encoder->encoder_type),
+		       kmstest_connector_type_str(cconf->connector->connector_type));
+	assert(ret > 0);
+
+	printf("Beginning test %s with %s on %s\n",
+		test_name, mode_format_str, cconf_str);
+
+	width = mode->hdisplay;
+	height = mode->vdisplay;
+
+	if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[0]))
+		goto err1;
+
+	if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[1]))
+		goto err2;
+
+	do_or_die(drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
+				 0, 0, &cconf->connector->connector_id, 1,
+				 mode));
+	do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
+				  0, NULL));
+	sleep(2);
+
+	if (flags & TEST_DIRECT_RENDER) {
+		paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
+	} else if (flags & TEST_GPU_BLIT) {
+		paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
+		gpu_blit(&fb[0], &fb[1]);
+	}
+	sleep(5);
+
+	printf("Test %s with %s on %s: PASSED\n",
+		test_name, mode_format_str, cconf_str);
+	free(mode_format_str);
+	free(cconf_str);
+
+	kmstest_remove_fb(drm_fd, &fb[1]);
+	kmstest_remove_fb(drm_fd, &fb[0]);
+
+	return 0;
+
+err2:
+	kmstest_remove_fb(drm_fd, &fb[0]);
+err1:
+	fprintf(stderr, "skip testing unsupported format %s\n",
+		kmstest_format_str(format));
+
+	return -1;
+}
+
+static void test_connector(const char *test_name,
+			   struct kmstest_connector_config *cconf,
+			   enum test_flags flags)
+{
+	const uint32_t *formats;
+	int format_count;
+	int i;
+
+	kmstest_get_all_formats(&formats, &format_count);
+	for (i = 0; i < cconf->connector->count_modes; i++) {
+		int j;
+
+		for (j = 0; j < format_count; j++)
+			test_format(test_name,
+				    cconf, &cconf->connector->modes[i],
+				    formats[j], flags);
+	}
+}
+
+static int run_test(const char *test_name, enum test_flags flags)
+{
+	int i;
+
+	resources = drmModeGetResources(drm_fd);
+	assert(resources);
+
+	/* Find any connected displays */
+	for (i = 0; i < resources->count_connectors; i++) {
+		uint32_t connector_id;
+		int j;
+
+		connector_id = resources->connectors[i];
+		for (j = 0; j < resources->count_crtcs; j++) {
+			struct kmstest_connector_config cconf;
+			int ret;
+
+			ret = kmstest_get_connector_config(drm_fd, connector_id,
+							   1 << j, &cconf);
+			if (ret < 0)
+				continue;
+
+			test_connector(test_name, &cconf, flags);
+
+			kmstest_free_connector_config(&cconf);
+		}
+	}
+
+	drmModeFreeResources(resources);
+
+	return 1;
+}
+
+int main(int argc, char **argv)
+{
+	struct {
+		enum test_flags flags;
+		const char *name;
+	} tests[] = {
+		{ TEST_DIRECT_RENDER,	"direct-render" },
+		{ TEST_GPU_BLIT,	"gpu-blit" },
+	};
+	int i;
+
+	drmtest_subtest_init(argc, argv);
+
+	if (!drmtest_only_list_subtests()) {
+		drm_fd = drm_open_any();
+
+		bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
+		devid = intel_get_drm_devid(drm_fd);
+		batch = intel_batchbuffer_alloc(bufmgr, devid);
+
+		do_or_die(drmtest_set_vt_graphics_mode());
+	}
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (drmtest_run_subtest(tests[i].name))
+			run_test(tests[i].name, tests[i].flags);
+	}
+
+	if (!drmtest_only_list_subtests())
+		close(drm_fd);
+
+	return 0;
+}
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 2/6] lib: add kmstest_cairo_printf_line
  2013-06-05 19:25     ` [PATCH v2 2/6] lib: add kmstest_cairo_printf_line Imre Deak
@ 2013-06-05 19:27       ` Rodrigo Vivi
  2013-06-05 20:04       ` [PATCH v3 " Imre Deak
  1 sibling, 0 replies; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 19:27 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

On Wed, Jun 5, 2013 at 4:25 PM, Imre Deak <imre.deak@intel.com> wrote:
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  lib/drmtest.c       | 44 ++++++++++++++++++++++++
>  lib/drmtest.h       | 13 ++++++++
>  tests/testdisplay.c | 96 ++++++++++++++++-------------------------------------
>  3 files changed, 86 insertions(+), 67 deletions(-)
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index 3c4812f..71dd06b 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -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);
>  }
>
> +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 {
>         topleft,
>         topright,
> 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)
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 3/6] lib: use kmstest_cairo_printf_line in paint_marker
  2013-06-05 19:25     ` [PATCH v2 3/6] lib: use kmstest_cairo_printf_line in paint_marker Imre Deak
@ 2013-06-05 19:29       ` Rodrigo Vivi
  0 siblings, 0 replies; 22+ messages in thread
From: Rodrigo Vivi @ 2013-06-05 19:29 UTC (permalink / raw)
  To: Imre Deak; +Cc: intel-gfx

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

On Wed, Jun 5, 2013 at 4:25 PM, Imre Deak <imre.deak@intel.com> wrote:
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  lib/drmtest.c | 64 +++++++++++++----------------------------------------------
>  1 file changed, 14 insertions(+), 50 deletions(-)
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index 71dd06b..3ad77a8 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -951,46 +951,12 @@ int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align,
>         return extents.width;
>  }
>
> -enum corner {
> -       topleft,
> -       topright,
> -       bottomleft,
> -       bottomright,
> -};
> -
>  static void
> -paint_marker(cairo_t *cr, int x, int y, char *str, enum corner text_location)
> +paint_marker(cairo_t *cr, int x, int y)
>  {
> -       cairo_text_extents_t extents;
> +       enum kmstest_text_align align;
>         int xoff, yoff;
>
> -       cairo_set_font_size(cr, 18);
> -       cairo_text_extents(cr, str, &extents);
> -
> -       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_move_to(cr, x, y - 20);
>         cairo_line_to(cr, x, y + 20);
>         cairo_move_to(cr, x - 20, y);
> @@ -1004,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,
> @@ -1021,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,
> @@ -1035,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);
> --
> 1.8.1.2
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx



-- 
Rodrigo Vivi
Blog: http://blog.vivi.eng.br

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v3 2/6] lib: add kmstest_cairo_printf_line
  2013-06-05 19:25     ` [PATCH v2 2/6] lib: add kmstest_cairo_printf_line Imre Deak
  2013-06-05 19:27       ` Rodrigo Vivi
@ 2013-06-05 20:04       ` Imre Deak
  1 sibling, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-05 20:04 UTC (permalink / raw)
  To: intel-gfx

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 :/ ]
---
 lib/drmtest.c       | 44 ++++++++++++++++++++++++
 lib/drmtest.h       | 13 ++++++++
 tests/testdisplay.c | 96 ++++++++++++++++-------------------------------------
 3 files changed, 86 insertions(+), 67 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 3c4812f..71dd06b 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -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);
 }
 
+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 {
 	topleft,
 	topright,
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..67b7031 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].name,
+			 c->connector->modes[i].vrefresh);
+		if (str_width > max_width)
+			max_width = str_width;
 	}
 
 	if (qr_code)
-- 
1.8.1.2

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [igt PATCH 5/5] tests: add kms_render
  2013-06-05 18:28   ` Rodrigo Vivi
@ 2013-06-06 10:19     ` Imre Deak
  0 siblings, 0 replies; 22+ messages in thread
From: Imre Deak @ 2013-06-06 10:19 UTC (permalink / raw)
  To: Rodrigo Vivi; +Cc: intel-gfx

On Wed, 2013-06-05 at 15:28 -0300, Rodrigo Vivi wrote:
> nice tests, only now I understood why Daniel "randomly" volunteered me
> to review this series ;)
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>

Thanks for the review, the patchset is pushed now to igt.

--Imre

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2013-06-06 10:19 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-31  9:23 [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Imre Deak
2013-05-31  9:23 ` [igt PATCH 2/5] lib: add kmstest_cairo_printf_line Imre Deak
2013-06-05 17:44   ` Rodrigo Vivi
2013-06-05 19:01     ` Imre Deak
2013-05-31  9:23 ` [igt PATCH 3/5] lib: add kmstest_get_connector_config Imre Deak
2013-06-05 18:00   ` Rodrigo Vivi
2013-05-31  9:23 ` [igt PATCH 4/5] lib: refactor kmstest_create_fb Imre Deak
2013-06-05 18:21   ` Rodrigo Vivi
2013-05-31  9:23 ` [igt PATCH 5/5] tests: add kms_render Imre Deak
2013-06-05 18:28   ` Rodrigo Vivi
2013-06-06 10:19     ` Imre Deak
2013-06-05 19:25   ` [PATCH v2 0/6] tests: add tests for front buffer rendering Imre Deak
2013-06-05 19:25     ` [PATCH v2 1/6] lib: move connector_type_str and co to drmtest Imre Deak
2013-06-05 19:25     ` [PATCH v2 2/6] lib: add kmstest_cairo_printf_line Imre Deak
2013-06-05 19:27       ` Rodrigo Vivi
2013-06-05 20:04       ` [PATCH v3 " Imre Deak
2013-06-05 19:25     ` [PATCH v2 3/6] lib: use kmstest_cairo_printf_line in paint_marker Imre Deak
2013-06-05 19:29       ` Rodrigo Vivi
2013-06-05 19:25     ` [PATCH v2 4/6] lib: add kmstest_get_connector_config Imre Deak
2013-06-05 19:25     ` [PATCH v2 5/6] lib: refactor kmstest_create_fb Imre Deak
2013-06-05 19:25     ` [PATCH v2 6/6] tests: add kms_render Imre Deak
2013-06-05 17:40 ` [igt PATCH 1/5] lib: move connector_type_str and co to drmtest Rodrigo Vivi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox