Skip to contentSkip to conversation

lib: Dump information about the supported 3D stereo formats

PATCH In review Damien Lespiau 2 participants 3 messages Sep 12, 2012 – Sep 14, 2012 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib: Dump information about the supported 3D stereo formats

From: Damien Lespiau <[email protected]>

When dumping the details of a mode, let's add the 3D formats the mode supports.

---
 lib/drmtest.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
lib/drmtest.c +11 -2
index 8df9797..4d5a67c 100644
@@ -812,7 +812,15 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,
 
 void kmstest_dump_mode(drmModeModeInfo *mode)
 {
-	printf("  %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n",
+	bool stereo_3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
+	char flags_str[32];
+
+	snprintf(flags_str, sizeof(flags_str), " (3D:%s%s%s)",
+		 mode->flags & DRM_MODE_FLAG_3D_TOP_BOTTOM ? " TB": "",
+		 mode->flags & DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF ? " SBSH": "",
+		 mode->flags & DRM_MODE_FLAG_3D_FRAME_PACKING ? " FP": "");
+
+	printf("  %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d%s\n",
 	       mode->name,
 	       mode->vrefresh,
 	       mode->hdisplay,
@@ -825,7 +833,8 @@ void kmstest_dump_mode(drmModeModeInfo *mode)
 	       mode->vtotal,
 	       mode->flags,
 	       mode->type,
-	       mode->clock);
+	       mode->clock,
+	       stereo_3d ? flags_str : "");
 	fflush(stdout);
 }
 
Signature · 1 line
1.7.11.4
#1 lore raw

PATCH 2/2 tests/testdisplay: Test the stereo 3D modes

From: Damien Lespiau <[email protected]>

Now that modes have flags to describe which 3d formats the sink supports, it's time to test them.

The new test cycles through the supported 3D formats and paint 3D stereoscopic images taken from publicly available samples:
http://www.quantumdata.com/apps/3D/sample_BMP.asp

---
 tests/1080FP.png    | Bin 0 -> 2291944 bytes
 tests/1080TB.png    | Bin 0 -> 1137594 bytes
 tests/720FP.png     | Bin 0 -> 1088754 bytes
 tests/720TB.png     | Bin 0 -> 555755 bytes
 tests/testdisplay.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 213 insertions(+), 3 deletions(-)
 create mode 100644 tests/1080FP.png
 create mode 100644 tests/1080TB.png
 create mode 100644 tests/720FP.png
 create mode 100644 tests/720TB.png
tests/1080FP.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..92f668a74d505d99eed923fc5f6d9e078c1da696
GIT binary patch
tests/1080TB.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8e53e8752fe3a4ec15a3e05dfb0a92579205a0e6
GIT binary patch
tests/720FP.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8baf5075b01de401494f68927d1b794baa0e76ae
GIT binary patch
tests/720TB.png new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ed09bf25381362e68f74985d1e35d52d5e88b90f
GIT binary patch
tests/testdisplay.c +213 -3

268 lines not on this page · raw message

Signature · 1 line
1.7.11.4
#2 lore raw

Re: [PATCH 2/2] tests/testdisplay: Test the stereo 3D modes

tests/1080FP.png

Quoted 23 lines · Damien Lespiau

From: Damien Lespiau <[email protected]>

Now that modes have flags to describe which 3d formats the sink supports, it's time to test them.

The new test cycles through the supported 3D formats and paint 3D stereoscopic images taken from publicly available samples:
http://www.quantumdata.com/apps/3D/sample_BMP.asp

---
 tests/1080FP.png    | Bin 0 -> 2291944 bytes
 tests/1080TB.png    | Bin 0 -> 1137594 bytes
 tests/720FP.png     | Bin 0 -> 1088754 bytes
 tests/720TB.png     | Bin 0 -> 555755 bytes
 tests/testdisplay.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 213 insertions(+), 3 deletions(-)
 create mode 100644 tests/1080FP.png
 create mode 100644 tests/1080TB.png
 create mode 100644 tests/720FP.png
 create mode 100644 tests/720TB.png
tests/1080FP.png +0 -0

<snip stereoscopic base64>

Quoted 116 lines

literal 0
HcmV?d00001

tests/testdisplay.c +83 -1
index c52bb2f..77d1503 100644
@@ -52,6 +52,7 @@
 #include <errno.h>
 #include <math.h>
 #include <stdint.h>
+#include <strings.h>
 #include <unistd.h>
 #include <sys/poll.h>
 #include <sys/time.h>
@@ -68,7 +69,7 @@
 drmModeRes *resources;
 int drm_fd, modes;
 int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
-	test_plane, enable_tiling;
+	test_plane, test_3d_modes, enable_tiling;
 int sleep_between_modes = 5;
 uint32_t depth = 24, stride, bpp;
 int qr_code = 0;
@@ -153,6 +154,11 @@ struct connector {
 	drmModeConnector *connector;
 	int crtc;
 	int pipe;
+
+	/* stereo 3d */
+	int s3d_format;
+	uint32_t s3d_property_id;
+	char s3d_image[32];
 };
 
 static void dump_connectors_fd(int drmfd)
@@ -554,6 +560,193 @@ set_mode(struct connector *c)
 	drmModeFreeConnector(c->connector);
 }
 
+static void
+paint_3d_image(cairo_t *cr, int l_width, int l_height, void *priv)
+{
+	struct connector *c = priv;
+	cairo_surface_t *image;
+
+	image = cairo_image_surface_create_from_png(c->s3d_image);
+
+	cairo_set_source_surface(cr, image, 0, 0);
+	cairo_paint(cr);
+
+	cairo_surface_destroy(image);
+}
+
+static void adjust_3d_timings(drmModeModeInfo *mode, unsigned int format)
+{
+	uint16_t vdisplay, vactive_space;
+
+	/* just set the 3D format we are setting (this is not used by the
+	 * kernel, it's just for kmstest_dump_mode()) */
+	mode->flags &= ~DRM_MODE_FLAG_3D_MASK;
+	mode->flags |= format;
+
+	switch (format) {
+	case DRM_MODE_FLAG_3D_TOP_BOTTOM:
+	case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
+		return;
+	case DRM_MODE_FLAG_3D_FRAME_PACKING:
+		vactive_space = mode->vtotal - mode->vdisplay;
+		vdisplay = mode->vdisplay;
+
+		mode->vdisplay += vdisplay + vactive_space;
+		mode->vsync_start += vdisplay + vactive_space;
+		mode->vsync_end += vdisplay + vactive_space;
+		mode->vtotal += vdisplay + vactive_space;
+		mode->clock = (mode->vtotal * mode->htotal * mode->vrefresh) /
+			      1000;
+		return;
+	default:
+		assert(0);
+	}
+}
+
+static const char *s3d_format_str(unsigned int format)
+{
+	switch(format) {
+	case DRM_MODE_FLAG_3D_TOP_BOTTOM:
+		return "TB";
+	case DRM_MODE_FLAG_3D_FRAME_PACKING:
+		return "FP";
+	}
+
+	return "Unknown format";
+}
+
+static void do_set_3d_format(struct connector *c, unsigned int format)
+{
+	uint32_t fb_id;
+	struct kmstest_fb fb_info;
+
+	snprintf(c->s3d_image, sizeof(c->s3d_image), "%d%s.png",
+		 c->mode.vdisplay, s3d_format_str(format));
+
+	adjust_3d_timings(&c->mode, format);
+	width = c->mode.hdisplay;
+	height = c->mode.vdisplay;
+
+	fb_id = kmstest_create_fb(drm_fd, width, height, bpp, depth,
+				  enable_tiling, &fb_info,
+				  paint_3d_image, c);
+
+	fb_ptr = gem_mmap(drm_fd, fb_info.gem_handle,
+			  fb_info.size, PROT_READ | PROT_WRITE);
+	assert(fb_ptr);
+
+	gem_close(drm_fd, fb_info.gem_handle);

tests/testdisplay.c set_mode(struct connector *c) · line 648

Quoted 10 lines
tests/testdisplay.c +10 -0
+
+	kmstest_dump_mode(&c->mode);
+
+	if (drmModeConnectorSetProperty(drm_fd,
+					c->id,
+					c->s3d_property_id,
+					format)) {
+		fprintf(stderr, "failed to set \"select 3D mode\" "
+			"property to %d: %s\n", 1, strerror(errno));
+	}

I agree with Chris that this would be better done as part of the mode. We can do it in a way that doesn't break backwards compatibility by having an "please actually use the 3d mode bits" in the mode flags. That way, the kernel can advertise 3d caps in the mode flags as it does now, and you can select it by picking the 3d mode you want (oh, I see, my previous enum vs bitfield comment was wrong) and setting the "enable 3d" flags as well. Existing KMS apps will just pass the mode back to the kernel without the enable flag and work as usual.

Kristian

Quoted 163 lines
tests/testdisplay.c +119 -2
+	if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0,
+			   &c->id, 1, &c->mode)) {
+		fprintf(stderr, "failed to set mode (%dx%d@%dHz): %s\n",
+			width, height, c->mode.vrefresh,
+			strerror(errno));
+	}
+}
+
+static void
+set_3d_mode(struct connector *c)
+{
+	int i;
+
+	if (depth <= 8)
+		bpp = 8;
+	else if (depth > 8 && depth <= 16)
+		bpp = 16;
+	else if (depth > 16 && depth <= 32)
+		bpp = 32;
+
+	connector_find_preferred_mode(c);
+	if (!c->mode_valid)
+		return;
+
+	for (i = 0; i < c->connector->count_modes; i++) {
+		unsigned int s3d_formats, format;
+
+		c->mode = c->connector->modes[i];
+
+		if (!c->mode_valid)
+			continue;
+
+		if (c->mode.flags & DRM_MODE_FLAG_INTERLACE)
+			continue;
+
+		s3d_formats = c->mode.flags & DRM_MODE_FLAG_3D_MASK;
+		if (!s3d_formats)
+			continue;
+
+		do {
+			format = 1 << (ffs(s3d_formats) - 1);
+
+			do_set_3d_format(c, format);
+
+			if (qr_code){
+				set_single();
+				pause();
+			} else if (sleep_between_modes) {
+				sleep(sleep_between_modes);
+			}
+
+			s3d_formats &= ~(format);
+		} while (s3d_formats);
+
+	}
+
+	/* disable the HDMI info frames with the next mode set */
+	if (drmModeConnectorSetProperty(drm_fd,
+					c->id,
+					c->s3d_property_id,
+					0)) {
+		fprintf(stderr, "failed to reset the \"select 3D mode\""
+			" property\n");
+	}
+
+	drmModeFreeEncoder(c->encoder);
+	drmModeFreeConnector(c->connector);
+}
+
+static bool connector_supports_3d(struct connector *c)
+{
+	drmModeConnector *connector;
+	drmModePropertyRes *property;
+	bool found = false;
+	int i;
+
+	connector = drmModeGetConnector(drm_fd, c->id);
+	if (connector->count_props == 0)
+		return false;
+
+	for (i = 0; i < connector->count_props; i++) {
+		property = drmModeGetProperty(drm_fd, connector->props[i]);
+		if (!property)
+			continue;
+
+		if (strcmp(property->name, "select 3D mode") == 0) {
+			found = true;
+			c->s3d_property_id = property->prop_id;
+			drmModeFreeProperty(property);
+			goto out;
+		}
+
+		drmModeFreeProperty(property);
+	}
+
+out:
+	drmModeFreeConnector(connector);
+	return found;
+}
+
 /*
  * Re-probe outputs and light up as many as possible.
  *
@@ -592,11 +785,24 @@ int update_display(void)
 			set_mode(&connectors[c]);
 		}
 	}
+
+	if (test_all_modes || test_3d_modes) {
+		/* Find connectors with the "select 3D mode" property */
+		for (c = 0; c < resources->count_connectors; c++) {
+			connectors[c].id = resources->connectors[c];
+
+			if (!connector_supports_3d(&connectors[c]))
+				continue;
+
+			set_3d_mode(&connectors[c]);
+		}
+	}
+
 	drmModeFreeResources(resources);
 	return 1;
 }
 
-static char optstr[] = "hiaf:s:d:p:mrt";
+static char optstr[] = "3hiaf:s:d:p:mrt";
 
 static void __attribute__((noreturn)) usage(char *name)
 {
@@ -607,6 +813,7 @@ static void __attribute__((noreturn)) usage(char *name)
 	fprintf(stderr, "\t-d\t<depth>\tbit depth of scanout buffer\n");
 	fprintf(stderr, "\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n");
 	fprintf(stderr, "\t-m\ttest the preferred mode\n");
+	fprintf(stderr, "\t-3\ttest all 3D modes\n");
 	fprintf(stderr, "\t-t\tuse a tiled framebuffer\n");
 	fprintf(stderr, "\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n");
 	fprintf(stderr, "\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n");
@@ -663,6 +870,9 @@ int main(int argc, char **argv)
 	opterr = 0;
 	while ((c = getopt(argc, argv, optstr)) != -1) {
 		switch (c) {
+		case '3':
+			test_3d_modes = 1;
+			break;
 		case 'i':
 			dump_info = 1;
 			break;
@@ -710,7 +920,7 @@ int main(int argc, char **argv)
 		}
 	}
 	if (!test_all_modes && !force_mode && !dump_info &&
-	    !test_preferred_mode)
+	    !test_preferred_mode && !test_3d_modes)
 		test_all_modes = 1;
 
 	drm_fd = drm_open_any();
Signature · 6 lines
1.7.11.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel