diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2010-07-18 21:02:36 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2010-07-18 21:02:36 +0000 |
commit | 728599f06efd64e220618ec623ed45086c6b892c (patch) | |
tree | 3e8aac86457fc211afa608e7d6e579967588099b /lib/libdrm | |
parent | 4cabc8d5e3f593378a0538c0a8b751d9cc1708e1 (diff) |
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.
Diffstat (limited to 'lib/libdrm')
-rw-r--r-- | lib/libdrm/shlib_version | 2 | ||||
-rw-r--r-- | lib/libdrm/xf86drm.h | 17 | ||||
-rw-r--r-- | lib/libdrm/xf86drmMode.c | 40 |
3 files changed, 58 insertions, 1 deletions
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; +} |