diff options
author | Kristian Høgsberg <krh@redhat.com> | 2009-09-11 13:27:35 -0400 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-10-29 17:14:09 -0700 |
commit | b0b96636dbf93445dd532b09b21fa4fc5ce6bdc7 (patch) | |
tree | 651a1d6ea2aff02f9fe43c696401eca1d82fe434 /libdrm/xf86drmMode.c | |
parent | 0d7ad7e43ca212b1e9f16cd18f36493cab455e61 (diff) |
Add support for vblank events
The kernel will now write data to the DRM fd for various event types if
requested. Currently, the only supported event is a vblank event: it contains
the vblank count for the event as well as a timestamp from when the event
ocurred. Since the DRM fd is now pollable, it's easy to integrate into
existing event loops.
Diffstat (limited to 'libdrm/xf86drmMode.c')
-rw-r--r-- | libdrm/xf86drmMode.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libdrm/xf86drmMode.c b/libdrm/xf86drmMode.c index 88b4fe3a..6d85113a 100644 --- a/libdrm/xf86drmMode.c +++ b/libdrm/xf86drmMode.c @@ -46,6 +46,7 @@ #include <drm.h> #include <string.h> #include <dirent.h> +#include <unistd.h> #include <errno.h> #define U642VOID(x) ((void *)(unsigned long)(x)) @@ -667,3 +668,45 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size, return 0; } + +int drmHandleEvent(int fd, drmEventContextPtr evctx) +{ + char buffer[1024]; + int len, i; + struct drm_event *e; + struct drm_event_vblank *vblank; + + /* The DRM read semantics guarantees that we always get only + * complete events. */ + + len = read(fd, buffer, sizeof buffer); + if (len == 0) + return 0; + if (len < sizeof *e) + return -1; + + i = 0; + while (i < len) { + e = (struct drm_event *) &buffer[i]; + switch (e->type) { + case DRM_EVENT_VBLANK: + if (evctx->version < 1 || + evctx->vblank_handler == NULL) + break; + vblank = (struct drm_event_vblank *) e; + evctx->vblank_handler(fd, + vblank->sequence, + vblank->tv_sec, + vblank->tv_usec, + U642VOID (vblank->user_data)); + break; + + default: + break; + } + i += e->length; + } + + return 0; +} + |