summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-04-06 12:57:26 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-04-06 12:57:26 +0200
commit19ecf7dd386419773c6114114f6e062d9ad4dcb7 (patch)
tree3a775e44f7b63a1095f7831a1b562c6db7db6ad5
parent5145edbc8bda0d82f7699901c225f79aa2a5da1a (diff)
wfdevent: dup the drm fd
-rw-r--r--src/wfdevent.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/wfdevent.c b/src/wfdevent.c
index e0150ed..e0abf27 100644
--- a/src/wfdevent.c
+++ b/src/wfdevent.c
@@ -46,6 +46,7 @@ struct wfd_event {
struct wfd_device *device;
/* source bind complete */
+ int drm_fd;
WFDint pipeline_id;
/* port attach */
@@ -63,6 +64,7 @@ wfd_event_destroy(struct wfd_device *device,
struct wfd_event *event)
{
g_queue_free(event->bind_event_queue);
+ close(event->drm_fd);
udev_monitor_unref(event->udev_monitor);
close(event->epoll_fd);
free(event);
@@ -113,12 +115,20 @@ wfd_create_event(struct wfd_device *device,
memset(&ep, 0, sizeof ep);
ep.events = EPOLLIN;
- ep.data.fd = wfd_device_get_fd(device);
+ event->drm_fd = dup(wfd_device_get_fd(device));
+ if (event->drm_fd < 0) {
+ fprintf(stderr, "failed to dup drm fd: %m\n");
+ close(event->epoll_fd);
+ free(event);
+ return NULL;
+ }
+ ep.data.fd = event->drm_fd;
ret = epoll_ctl(event->epoll_fd, EPOLL_CTL_ADD,
ep.data.fd, &ep);
if (ret == -1) {
fprintf(stderr, "failed to add fd to epoll: %m\n");
close(event->epoll_fd);
+ close(event->drm_fd);
free(event);
return NULL;
}
@@ -234,7 +244,6 @@ wfd_event_wait(struct wfd_device *device,
WFDEventType event_type = WFD_EVENT_NONE;
int num;
int timeout;
- int drm_fd = wfd_device_get_fd(device);
timeout = time / 1e6;
@@ -256,7 +265,7 @@ wfd_event_wait(struct wfd_device *device,
(uintptr_t) g_queue_pop_head(event->bind_event_queue);
event_type = WFD_EVENT_PIPELINE_BIND_SOURCE_COMPLETE;
- } else if (ep.data.fd == drm_fd) {
+ } else if (ep.data.fd == event->drm_fd) {
drmEventContext drm_evctx;
memset(&drm_evctx, 0, sizeof drm_evctx);
@@ -264,7 +273,7 @@ wfd_event_wait(struct wfd_device *device,
drm_evctx.page_flip_handler = page_flip_handler;
flip_pipeline_id = 0;
- drmHandleEvent(drm_fd, &drm_evctx);
+ drmHandleEvent(event->drm_fd, &drm_evctx);
if (flip_pipeline_id != 0) {
event->pipeline_id = flip_pipeline_id;
event_type = WFD_EVENT_PIPELINE_BIND_SOURCE_COMPLETE;