summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-07-19 08:29:40 -0700
committerAdam Jackson <ajax@redhat.com>2016-07-19 11:30:11 -0400
commit6473b68762b0dca2dfccfdfc74100398b7459296 (patch)
treeddbb4f13641014a93edd13d15bbb5a188eb026d8
parenta964931e8dc4e06c27749edb4993a656dc261d75 (diff)
Use NotifyFd for drm and udev fds
NotifyFd is available after API 22, and must be used after API 23. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--src/compat-api.h4
-rw-r--r--src/drmmode_display.c36
2 files changed, 40 insertions, 0 deletions
diff --git a/src/compat-api.h b/src/compat-api.h
index 5d63e10..fde2f4b 100644
--- a/src/compat-api.h
+++ b/src/compat-api.h
@@ -74,6 +74,10 @@
#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
+#if ABI_VIDEODRV_VERSION >= SET_ABI_VERSION(22,0)
+#define HAVE_NOTIFY_FD 1
+#endif
+
#if ABI_VIDEODRV_VERSION >= SET_ABI_VERSION(23, 0)
#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout
#define BLOCKHANDLER_ARGS arg, pTimeout
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index f326e46..b6c9bb9 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -1537,6 +1537,15 @@ drmmode_handle_uevents(ScrnInfoPtr scrn)
}
#endif
+#if HAVE_NOTIFY_FD
+static void
+drmmode_udev_notify(int fd, int notify, void *data)
+{
+ ScrnInfoPtr scrn = data;
+ drmmode_handle_uevents(scrn);
+}
+#endif
+
static void
drmmode_uevent_init(ScrnInfoPtr scrn)
{
@@ -1563,7 +1572,11 @@ drmmode_uevent_init(ScrnInfoPtr scrn)
return;
}
+#if HAVE_NOTIFY_FD
+ SetNotifyFd(udev_monitor_get_fd(mon), drmmode_udev_notify, X_NOTIFY_READ, scrn);
+#else
AddGeneralSocket(udev_monitor_get_fd(mon));
+#endif
drmmode->uevent_monitor = mon;
#endif
}
@@ -1577,13 +1590,27 @@ drmmode_uevent_fini(ScrnInfoPtr scrn)
if (drmmode->uevent_monitor) {
struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor);
+#if HAVE_NOTIFY_FD
+ RemoveNotifyFd(udev_monitor_get_fd(drmmode->uevent_monitor));
+#else
RemoveGeneralSocket(udev_monitor_get_fd(drmmode->uevent_monitor));
+#endif
udev_monitor_unref(drmmode->uevent_monitor);
udev_unref(u);
}
#endif
}
+#if HAVE_NOTIFY_FD
+static void
+drmmode_notify_fd(int fd, int notify, void *data)
+{
+ ScrnInfoPtr scrn = data;
+ drmmode_ptr drmmode = drmmode_from_scrn(scrn);
+ drmHandleEvent(drmmode->fd, &drmmode->event_context);
+}
+#else
+
static void
drmmode_wakeup_handler(pointer data, int err, pointer p)
{
@@ -1602,6 +1629,7 @@ drmmode_wakeup_handler(pointer data, int err, pointer p)
drmmode_handle_uevents(scrn);
#endif
}
+#endif
void
drmmode_screen_init(ScreenPtr pScreen)
@@ -1619,9 +1647,13 @@ drmmode_screen_init(ScreenPtr pScreen)
/* Register wakeup handler only once per servergen, so ZaphodHeads work */
if (pNVEnt->fd_wakeup_registered != serverGeneration) {
/* Register a wakeup handler to get informed on DRM events */
+#if HAVE_NOTIFY_FD
+ SetNotifyFd(drmmode->fd, drmmode_notify_fd, X_NOTIFY_READ, scrn);
+#else
AddGeneralSocket(drmmode->fd);
RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
drmmode_wakeup_handler, scrn);
+#endif
pNVEnt->fd_wakeup_registered = serverGeneration;
pNVEnt->fd_wakeup_ref = 1;
}
@@ -1640,10 +1672,14 @@ drmmode_screen_fini(ScreenPtr pScreen)
if (pNVEnt->fd_wakeup_registered == serverGeneration &&
!--pNVEnt->fd_wakeup_ref) {
+#if HAVE_NOTIFY_FD
+ RemoveNotifyFd(drmmode->fd);
+#else
/* Unregister wakeup handler */
RemoveBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
drmmode_wakeup_handler, scrn);
RemoveGeneralSocket(drmmode->fd);
+#endif
}
/* Tear down udev event handler */