From 65586a3b359cfca99b5b3a041968e50f466f25d0 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 24 Feb 2013 08:46:47 +0100 Subject: v4l2-drm-example: Factor out page flipping Factor the common page flip code out to a function. Signed-off-by: Laurent Pinchart --- v4l2-drm-example/dmabuf-sharing.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'v4l2-drm-example') diff --git a/v4l2-drm-example/dmabuf-sharing.c b/v4l2-drm-example/dmabuf-sharing.c index 7156046..6c7abe5 100644 --- a/v4l2-drm-example/dmabuf-sharing.c +++ b/v4l2-drm-example/dmabuf-sharing.c @@ -334,6 +334,15 @@ static void drm_init(struct drm_device *dev, const struct v4l2_pix_format *fmt, BYE_ON(ret, "failed to find valid mode\n"); } +static void drm_page_flip(struct drm_device *dev, struct buffer *buffer) +{ + int ret; + + ret = drmModePageFlip(dev->fd, dev->crtc_id, buffer->fb_handle, + DRM_MODE_PAGE_FLIP_EVENT, (void*)(unsigned long)buffer->index); + BYE_ON(ret, "drmModePageFlip failed: %s\n", ERRSTR); +} + static void v4l2_init(struct v4l2_device *dev, unsigned int num_buffers) { int ret; @@ -474,9 +483,7 @@ int main(int argc, char *argv[]) BYE_ON(ret, "drmModeSetCrtc failed: %s\n", ERRSTR); /* Enqueue the first buffer to DRM and all other buffers to V4L2 */ - ret = drmModePageFlip(drm.fd, drm.crtc_id, buffers[0].fb_handle, - DRM_MODE_PAGE_FLIP_EVENT, 0); - BYE_ON(ret, "drmModePageFlip failed: %s\n", ERRSTR); + drm_page_flip(&drm, &buffers[0]); for (unsigned int i = 1; i < s.buffer_count; ++i) v4l2_queue_buffer(&v4l2, &buffers[i]); @@ -501,12 +508,9 @@ int main(int argc, char *argv[]) struct buffer *buffer; buffer = v4l2_dequeue_buffer(&v4l2, buffers); - - ret = drmModePageFlip(drm.fd, drm.crtc_id, buffer->fb_handle, - DRM_MODE_PAGE_FLIP_EVENT, (void*)(unsigned long)buffer->index); - BYE_ON(ret, "drmModePageFlip failed: %s\n", ERRSTR); - + drm_page_flip(&drm, buffer); } + if (fds[1].revents & POLLIN) { drmEventContext evctx; memset(&evctx, 0, sizeof evctx); -- cgit v1.2.3