From 728599f06efd64e220618ec623ed45086c6b892c Mon Sep 17 00:00:00 2001 From: Owain Ainsworth Date: Sun, 18 Jul 2010 21:02:36 +0000 Subject: Support the apis for getting vblank events from the drm fd. (only vblank events for now, pageflip events require kms and thus have not yet been added). Bumps libdrm minor version. --- lib/libdrm/shlib_version | 2 +- lib/libdrm/xf86drm.h | 17 +++++++++++++++++ lib/libdrm/xf86drmMode.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/lib/libdrm/shlib_version b/lib/libdrm/shlib_version index c29621c83..f7f3cf728 100644 --- a/lib/libdrm/shlib_version +++ b/lib/libdrm/shlib_version @@ -1,2 +1,2 @@ major=2 -minor=5 +minor=6 diff --git a/lib/libdrm/xf86drm.h b/lib/libdrm/xf86drm.h index d3e118b74..92c4aea9b 100644 --- a/lib/libdrm/xf86drm.h +++ b/lib/libdrm/xf86drm.h @@ -669,6 +669,23 @@ extern void drmMsg(const char *format, ...); extern int drmSetMaster(int fd); extern int drmDropMaster(int fd); +#define DRM_EVENT_CONTEXT_VERSION 1 + +typedef struct _drmEventContext { + + /* This struct is versioned so we can add more pointers if we + * add more events. */ + int version; + + void (*vblank_handler)(int fd, + unsigned int sequence, + unsigned int tv_sec, + unsigned int tv_usec, + void *user_data); +} drmEventContext, *drmEventContextPtr; + +extern int drmHandleEvent(int fd, drmEventContextPtr evctx); + extern char *drmGetDeviceNameFromFd(int fd); #endif diff --git a/lib/libdrm/xf86drmMode.c b/lib/libdrm/xf86drmMode.c index 88b4fe3af..221bf67cf 100644 --- a/lib/libdrm/xf86drmMode.c +++ b/lib/libdrm/xf86drmMode.c @@ -667,3 +667,43 @@ 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; +} -- cgit v1.2.3