[PATCH 6/6] modetest: add atomic page flip support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds support for atomic page flip. User can specify -W option
with the plane id for testing atomic page flipping.

Signed-off-by: Hyungwon Hwang <human.hwang@xxxxxxxxxxx>
---
 tests/modetest/modetest.c | 150 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 3 deletions(-)

diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index bf9222d..d1b7dc4 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -719,6 +719,10 @@ struct pipe_arg {
 	struct timeval start;
 
 	int swap_count;
+
+	/* for atomic modeset */
+	uint32_t plane_id;
+	uint32_t fb_obj_id;
 };
 
 struct plane_arg {
@@ -1446,6 +1450,7 @@ static void usage(char *name)
 	fprintf(stderr, "\n Atomic Test options: [A]\n\n");
 	fprintf(stderr, "\t-a\tuse atomic modeset\n");
 	fprintf(stderr, "\t-W <obj_id>:<prop_name>:<value>\tset property\n");
+	fprintf(stderr, "\t-V <flipping_plane_id>\ttest vsynced page flipping\n");
 
 	fprintf(stderr, "\n Legacy test options: [L]\n\n");
 	fprintf(stderr, "\t-P <crtc_id>:<w>x<h>[+<x>+<y>][*<scale>][@<format>]\tset a plane\n");
@@ -1637,7 +1642,137 @@ static void atomic_modeset(struct device *dev, drmModeAtomicReqPtr req,
 	drmModeAtomicCommit(dev->fd, req, flags, NULL);
 }
 
-static char optstr[] = "acdD:efM:P:ps:Cvw:W:";
+static void
+atomic_page_flip_handler(int fd, unsigned int frame,
+		unsigned int sec, unsigned int usec, void *data)
+{
+	static drmModeAtomicReqPtr req = NULL;
+	unsigned int new_fb_id;
+	struct timeval end;
+	struct pipe_arg *pipe;
+	double t;
+	uint32_t flags = 0;
+
+	pipe = (struct pipe_arg *)(unsigned long)data;
+
+	if (pipe->current_fb_id == pipe->fb_id[0])
+		new_fb_id = pipe->fb_id[1];
+	else
+		new_fb_id = pipe->fb_id[0];
+
+	pipe->current_fb_id = new_fb_id;
+	pipe->swap_count++;
+
+	req = drmModeAtomicAlloc();
+
+	drmModeAtomicAddProperty(req, pipe->plane_id, pipe->fb_obj_id, new_fb_id);
+
+	flags = DRM_MODE_PAGE_FLIP_EVENT;
+	drmModeAtomicCommit(fd, req, flags, pipe);
+
+	if (pipe->swap_count == 60) {
+		gettimeofday(&end, NULL);
+		t = end.tv_sec + end.tv_usec * 1e-6 -
+			(pipe->start.tv_sec + pipe->start.tv_usec * 1e-6);
+		fprintf(stderr, "freq: %.02fHz\n", pipe->swap_count / t);
+		pipe->swap_count = 0;
+		pipe->start = end;
+	}
+
+	drmModeAtomicFree(req);
+}
+
+static int atomic_test_page_flip(struct device *dev, drmModeAtomicReqPtr req,
+		struct resources *res, unsigned int plane_id)
+{
+	struct bo *other_bo;
+	unsigned int other_fb_id;
+	struct pipe_arg *pipe = NULL;
+	drmEventContext evctx;
+	uint32_t flags = 0, fb_obj_id = 0, pixel_format;
+	uint64_t width, height;
+	int ret;
+
+	if (!is_atomic_obj_in_request(req, plane_id))
+		return -1;
+
+	fb_obj_id = get_atomic_plane_prop_id(res, plane_id, "FB_ID");
+	if (!fb_obj_id)
+		return -1;
+
+	width = get_atomic_plane_prop_value_in_request(req, res,
+			plane_id, "SRC_W");
+	height = get_atomic_plane_prop_value_in_request(req, res,
+			plane_id, "SRC_H");
+	pixel_format = DRM_FORMAT_XRGB8888;
+
+	ret = allocate_fb(dev, req, res, width, height, pixel_format,
+			PATTERN_TILES, &other_bo, &other_fb_id);
+	if (ret < 0)
+		return ret;
+
+	ret = drmModeAtomicAddProperty(req, plane_id, fb_obj_id,
+			other_fb_id);
+	if (ret < 0)
+		goto err;
+
+	if (!fb_obj_id) {
+		fprintf(stderr, "page flipping requires at least one plane setting.\n");
+		return -1;
+	}
+
+	pipe = drmMalloc(sizeof *pipe);
+
+	gettimeofday(&pipe->start, NULL);
+	pipe->swap_count = 0;
+	pipe->plane_id = plane_id;
+	pipe->fb_obj_id = fb_obj_id;
+	pipe->fb_id[0] = dev->mode.fb_id;
+	pipe->fb_id[1] = other_fb_id;
+	pipe->current_fb_id = other_fb_id;
+
+	flags = DRM_MODE_PAGE_FLIP_EVENT;
+
+	ret = drmModeAtomicCommit(dev->fd, req, flags, pipe);
+	if (ret < 0)
+		goto err_rmfb;
+
+	memset(&evctx, 0, sizeof evctx);
+	evctx.version = DRM_EVENT_CONTEXT_VERSION;
+	evctx.vblank_handler = NULL;
+	evctx.page_flip_handler = atomic_page_flip_handler;
+
+	while (1) {
+		struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
+		fd_set fds;
+		int ret;
+
+		FD_ZERO(&fds);
+		FD_SET(0, &fds);
+		FD_SET(dev->fd, &fds);
+		ret = select(dev->fd + 1, &fds, NULL, NULL, &timeout);
+
+		if (ret <= 0) {
+			fprintf(stderr, "select timed out or error (ret %d)\n",
+					ret);
+			continue;
+		} else if (FD_ISSET(0, &fds)) {
+			break;
+		}
+
+		drmHandleEvent(dev->fd, &evctx);
+	}
+
+err_rmfb:
+	drmFree(pipe);
+	drmModeRmFB(dev->fd, other_fb_id);
+err:
+	bo_destroy(other_bo);
+
+	return 0;
+}
+
+static char optstr[] = "acdD:efM:P:ps:CvV:w:W:";
 
 int main(int argc, char **argv)
 {
@@ -1651,7 +1786,7 @@ int main(int argc, char **argv)
 	const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "exynos", "tilcdc", "msm", "sti", "tegra", "imx-drm", "rockchip", "atmel-hlcdc" };
 	char *device = NULL;
 	char *module = NULL;
-	unsigned int i;
+	unsigned int i, flip_plane_id = 0;
 	int count = 0, plane_count = 0;
 	unsigned int prop_count = 0;
 	struct pipe_arg *pipe_args = NULL;
@@ -1732,6 +1867,11 @@ int main(int argc, char **argv)
 		case 'v':
 			test_vsync = 1;
 			break;
+		case 'V':
+			if (sscanf(optarg, "%u", &flip_plane_id) != 1)
+				usage(argv[0]);
+			test_vsync = 1;
+			break;
 		case 'w':
 			prop_args = realloc(prop_args,
 					   (prop_count + 1) * sizeof *prop_args);
@@ -1788,7 +1928,7 @@ int main(int argc, char **argv)
 		return -1;
 	}
 
-	if (test_vsync && !count) {
+	if (test_vsync && (!count && !req)) {
 		fprintf(stderr, "page flipping requires at least one -s option.\n");
 		return -1;
 	}
@@ -1818,6 +1958,10 @@ int main(int argc, char **argv)
 	if (req) {
 		atomic_modeset(&dev, req, dev.resources);
 
+		if (test_vsync)
+			atomic_test_page_flip(&dev, req, dev.resources,
+								flip_plane_id);
+
 		getchar();
 	} else {
 		for (i = 0; i < prop_count; ++i)
-- 
2.4.3

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




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux