All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: [PATCH libdrm 11/11] tests: kms: Implement universal planes test
Date: Fri, 23 Jan 2015 17:08:24 +0100	[thread overview]
Message-ID: <1422029304-1926-12-git-send-email-thierry.reding@gmail.com> (raw)
In-Reply-To: <1422029304-1926-1-git-send-email-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

This small program allows universal planes to be tested. Currently this
isn't very flexible because it allows only the first plane of a given
type to be tested on the first CRTC. However it should be simple to
extend this with some additional command-line arguments.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/kms/Makefile.am            |   9 +-
 tests/kms/kms-universal-planes.c | 358 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 365 insertions(+), 2 deletions(-)
 create mode 100644 tests/kms/kms-universal-planes.c

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index 10584c8930a4..e9589221e489 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -20,11 +20,16 @@ libkms_test_la_LIBADD = \
 
 if HAVE_INSTALL_TESTS
 bin_PROGRAMS = \
-	kms-steal-crtc
+	kms-steal-crtc \
+	kms-universal-planes
 else
 noinst_PROGRAMS = \
-	kms-steal-crtc
+	kms-steal-crtc \
+	kms-universal-planes
 endif
 
 kms_steal_crtc_SOURCES = kms-steal-crtc.c
 kms_steal_crtc_LDADD = libkms-test.la ../util/libutil.la
+
+kms_universal_planes_SOURCES = kms-universal-planes.c
+kms_universal_planes_LDADD = libkms-test.la
diff --git a/tests/kms/kms-universal-planes.c b/tests/kms/kms-universal-planes.c
new file mode 100644
index 000000000000..9151231ff860
--- /dev/null
+++ b/tests/kms/kms-universal-planes.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * 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 (including the next
+ * paragraph) 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <drm_fourcc.h>
+#include "xf86drm.h"
+
+#include "util/common.h"
+#include "libkms-test.h"
+
+static const uint32_t formats[] = {
+	DRM_FORMAT_XRGB8888,
+	DRM_FORMAT_XBGR8888,
+	DRM_FORMAT_RGBA8888,
+};
+
+static uint32_t choose_format(struct kms_plane *plane)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(formats); i++)
+		if (kms_plane_supports_format(plane, formats[i]))
+			return formats[i];
+
+	return 0;
+}
+
+static void prepare_framebuffer(struct kms_framebuffer *fb, bool invert)
+{
+	const unsigned int block_size = 16;
+	uint32_t colors[2];
+	unsigned int i, j;
+	uint32_t *buf;
+	void *ptr;
+	int err;
+
+	switch (fb->format) {
+	case DRM_FORMAT_XRGB8888:
+		printf("using XRGB8888 format\n");
+		           /* XXRRGGBB */
+		colors[0] = 0xffff0000;
+		colors[1] = 0xff0000ff;
+		break;
+
+	case DRM_FORMAT_XBGR8888:
+		printf("using XBGR8888 format\n");
+		           /* XXBBGGRR */
+		colors[0] = 0xff0000ff;
+		colors[1] = 0xffff0000;
+		break;
+
+	case DRM_FORMAT_RGBA8888:
+		printf("using RGBA8888 format\n");
+		           /* RRGGBBAA */
+		colors[0] = 0xff0000ff;
+		colors[1] = 0x0000ffff;
+		break;
+
+	default:
+		colors[0] = 0xffffffff;
+		colors[1] = 0xffffffff;
+		break;
+	}
+
+	err = kms_framebuffer_map(fb, &ptr);
+	if (err < 0) {
+		fprintf(stderr, "kms_framebuffer_map() failed: %s\n",
+			strerror(-err));
+		return;
+	}
+
+	buf = ptr;
+
+	for (j = 0; j < fb->height; j++) {
+		for (i = 0; i < fb->width; i++) {
+			unsigned int color = (j / block_size) ^
+					     (i / block_size);
+
+			if (invert)
+				color ^= color;
+
+			*buf++ = colors[color & 1];
+		}
+	}
+
+	kms_framebuffer_unmap(fb);
+}
+
+int main(int argc, char *argv[])
+{
+	static const char opts[] = "chopv";
+	static struct option options[] = {
+		{ "cursor", 0, 0, 'c' },
+		{ "help", 0, 0, 'h' },
+		{ "overlay", 0, 0, 'o' },
+		{ "primary", 0, 0, 'p' },
+		{ "verbose", 0, 0, 'v' },
+		{ 0, 0, 0, 0 },
+	};
+	struct kms_framebuffer *cursor = NULL;
+	struct kms_framebuffer *root = NULL;
+	struct kms_framebuffer *fb = NULL;
+	struct kms_device *device;
+	bool use_overlay = false;
+	bool use_primary = false;
+	struct kms_plane *plane;
+	bool use_cursor = false;
+	bool verbose = false;
+	unsigned int i;
+	int opt, idx;
+	int fd, err;
+
+	while ((opt = getopt_long(argc, argv, opts, options, &idx)) != -1) {
+		switch (opt) {
+		case 'c':
+			use_cursor = true;
+			break;
+
+		case 'h':
+			break;
+
+		case 'o':
+			use_overlay = true;
+			break;
+
+		case 'p':
+			use_primary = true;
+			break;
+
+		case 'v':
+			verbose = true;
+			break;
+
+		default:
+			printf("unknown option \"%c\"\n", opt);
+			return 1;
+		}
+	}
+
+	if (optind >= argc) {
+		fprintf(stderr, "usage: %s [options] DEVICE\n", argv[0]);
+		return 1;
+	}
+
+	fd = open(argv[optind], O_RDWR);
+	if (fd < 0) {
+		fprintf(stderr, "open() failed: %m\n");
+		return 1;
+	}
+
+	err = drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+	if (err < 0) {
+		fprintf(stderr, "drmSetClientCap() failed: %d\n", err);
+		return 1;
+	}
+
+	device = kms_device_open(fd);
+	if (!device)
+		return 1;
+
+	if (verbose) {
+		printf("Screens: %u\n", device->num_screens);
+
+		for (i = 0; i < device->num_screens; i++) {
+			struct kms_screen *screen = device->screens[i];
+			const char *status = "disconnected";
+
+			if (screen->connected)
+				status = "connected";
+
+			printf("  %u: %x\n", i, screen->id);
+			printf("    Status: %s\n", status);
+			printf("    Name: %s\n", screen->name);
+			printf("    Resolution: %ux%u\n", screen->width,
+			       screen->height);
+		}
+
+		printf("Planes: %u\n", device->num_planes);
+
+		for (i = 0; i < device->num_planes; i++) {
+			struct kms_plane *plane = device->planes[i];
+			const char *type = NULL;
+
+			switch (plane->type) {
+			case DRM_PLANE_TYPE_OVERLAY:
+				type = "overlay";
+				break;
+
+			case DRM_PLANE_TYPE_PRIMARY:
+				type = "primary";
+				break;
+
+			case DRM_PLANE_TYPE_CURSOR:
+				type = "cursor";
+				break;
+			}
+
+			printf("  %u: %p\n", i, plane);
+			printf("    ID: %x\n", plane->id);
+			printf("    CRTC: %x\n", plane->crtc->id);
+			printf("    Type: %x (%s)\n", plane->type, type);
+		}
+	}
+
+	if (use_cursor) {
+		unsigned int x, y;
+		uint32_t format;
+
+		plane = kms_device_find_plane_by_type(device,
+						      DRM_PLANE_TYPE_CURSOR,
+						      0);
+		if (!plane) {
+			fprintf(stderr, "no cursor plane found\n");
+			return 1;
+		}
+
+		format = choose_format(plane);
+		if (!format) {
+			fprintf(stderr, "no matching format found\n");
+			return 1;
+		}
+
+		cursor = kms_framebuffer_create(device, 32, 32, format);
+		if (!cursor) {
+			fprintf(stderr, "failed to create cursor buffer\n");
+			return 1;
+		}
+
+		prepare_framebuffer(cursor, false);
+
+		x = (device->screens[0]->width - cursor->width) / 2;
+		y = (device->screens[0]->height - cursor->height) / 2;
+
+		kms_plane_set(plane, cursor, x, y);
+	}
+
+	if (use_overlay) {
+		uint32_t format;
+
+		plane = kms_device_find_plane_by_type(device,
+						      DRM_PLANE_TYPE_OVERLAY,
+						      0);
+		if (!plane) {
+			fprintf(stderr, "no overlay plane found\n");
+			return 1;
+		}
+
+		format = choose_format(plane);
+		if (!format) {
+			fprintf(stderr, "no matching format found\n");
+			return 1;
+		}
+
+		fb = kms_framebuffer_create(device, 320, 240, format);
+		if (!fb)
+			return 1;
+
+		prepare_framebuffer(fb, false);
+
+		kms_plane_set(plane, fb, 0, 0);
+	}
+
+	if (use_primary) {
+		unsigned int x, y;
+		uint32_t format;
+
+		plane = kms_device_find_plane_by_type(device,
+						      DRM_PLANE_TYPE_PRIMARY,
+						      0);
+		if (!plane) {
+			fprintf(stderr, "no primary plane found\n");
+			return 1;
+		}
+
+		format = choose_format(plane);
+		if (!format) {
+			fprintf(stderr, "no matching format found\n");
+			return 1;
+		}
+
+		root = kms_framebuffer_create(device, 640, 480, format);
+		if (!root)
+			return 1;
+
+		prepare_framebuffer(root, true);
+
+		x = (device->screens[0]->width - root->width) / 2;
+		y = (device->screens[0]->height - root->height) / 2;
+
+		kms_plane_set(plane, root, x, y);
+	}
+
+	while (1) {
+		struct timeval timeout = { 1, 0 };
+		fd_set fds;
+
+		FD_ZERO(&fds);
+		FD_SET(STDIN_FILENO, &fds);
+
+		err = select(STDIN_FILENO + 1, &fds, NULL, NULL, &timeout);
+		if (err < 0) {
+			fprintf(stderr, "select() failed: %m\n");
+			break;
+		}
+
+		/* timeout */
+		if (err == 0)
+			continue;
+
+		if (FD_ISSET(STDIN_FILENO, &fds))
+			break;
+	}
+
+	if (cursor)
+		kms_framebuffer_free(cursor);
+
+	if (root)
+		kms_framebuffer_free(root);
+
+	if (fb)
+		kms_framebuffer_free(fb);
+
+	kms_device_close(device);
+	close(fd);
+
+	return 0;
+}
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2015-01-23 16:09 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
2015-01-24 23:19   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
2015-01-24 23:19   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
2015-01-24 23:20   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
2015-01-24 23:24   ` Laurent Pinchart
2015-01-29 15:27   ` [PATCH 04.1/11] SQUASH: tests: misc cleanups Emil Velikov
2015-01-29 15:27   ` [PATCH 04.2/11] SQUASH: util: add android build Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
2015-01-24 23:24   ` Laurent Pinchart
2015-01-29 15:28   ` [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
2015-01-24 23:26   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
2015-01-24 23:40   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
2015-01-24 23:56   ` Laurent Pinchart
2015-01-26 10:14     ` Thierry Reding
2015-01-26 10:24       ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
2015-01-29 15:30   ` [PATCH 09.1/11] SQUASH: libkms-test: add missing header to the distribution Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test Thierry Reding
2015-01-29 15:30   ` [PATCH 10.1/11] SQUASH: kms-steal-crtc: link against cairo Emil Velikov
2015-01-23 16:08 ` Thierry Reding [this message]
2015-01-29 15:31   ` [PATCH 11.1/11] SQUASH: kms-universal-planes: " Emil Velikov
2015-01-29 15:36 ` [PATCH libdrm 00/11] Random assortment of fixes and enhancements Emil Velikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422029304-1926-12-git-send-email-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.