Skip to contentSkip to conversation

drm: Implement drmHandleEvent2()

PATCH New Hyungwon Hwang 1 participant 1 message Nov 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Implement drmHandleEvent2()

From: Tobias Jakobi <[email protected]>

Basically this is an extended version of drmHandleEvent().

drmHandleEvent() only handles core events (like e.g. page flips), but since kernel DRM drivers might use vendor-specific events to signal userspace the completion of pending jobs, etc., its desirable to provide a way to handle these without putting vendor-specific code in the core libdrm.

To use this you provide drmHandleEvent2() with a function that handles your non-core events.

The signature of that function looks like this:
void vendor(int fd, struct drm_event *e, void *ctx);

'fd' is the DRM file descriptor, 'e' the non-core event and 'ctx' the event context (casted to void).

This way we don't have to maintain a copy of drmHandleEvent() in the vendor code.

---
Changes for v2:
- Remove the opaque pointer, since this can be better handled with a container approach.

This patch is separated from Tobias's patchset. Please refer to
http://lists.freedesktop.org/archives/dri-devel/2015-November/095456.html

 xf86drm.h     | 21 +++++++++++++++++++++
 xf86drmMode.c | 10 +++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
xf86drm.h +21 -0
index 481d882..1e474a3 100644
@@ -750,8 +750,29 @@ typedef struct _drmEventContext {
 
 } drmEventContext, *drmEventContextPtr;
 
+typedef void (*drmEventVendorHandler)(int fd, struct drm_event *e, void *ctx);
+
 extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
 
+/*
+ * drmHandleEvent2() is an extended variant of drmHandleEvent() which
+ * allows handling of vendor-specific/non-core events.
+ * The function pointer 'vendorhandler' is used (if non-zero) to
+ * process non-core events. Users of have to prepare a container struct
+ * in the following way:
+ *
+ * struct vendor_event_context {
+ *		drmEventContext base;
+ *		int vendor_specific_data[num];
+ * };
+ *
+ * And then call:
+ * struct vendor_event_context ctx = {0};
+ * drmHandleEvent2(fd, &ctx.base, handler);
+ */
+extern int drmHandleEvent2(int fd, drmEventContextPtr evctx,
+	drmEventVendorHandler vendorhandler);
+
 extern char *drmGetDeviceNameFromFd(int fd);
 extern int drmGetNodeTypeFromFd(int fd);
 
xf86drmMode.c +9 -1
index ab6b519..89698da 100644
@@ -867,7 +867,8 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETGAMMA, &l);
 }
 
-int drmHandleEvent(int fd, drmEventContextPtr evctx)
+int drmHandleEvent2(int fd, drmEventContextPtr evctx,
+			drmEventVendorHandler vendorhandler)
 {
 	char buffer[1024];
 	int len, i;
@@ -910,6 +911,8 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 						 U642VOID (vblank->user_data));
 			break;
 		default:
+			if (vendorhandler)
+				vendorhandler(fd, e, evctx);
 			break;
 		}
 		i += e->length;
@@ -918,6 +921,11 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	return 0;
 }
 
+int drmHandleEvent(int fd, drmEventContextPtr evctx)
+{
+	return drmHandleEvent2(fd, evctx, NULL);
+}
+
 int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
 		    uint32_t flags, void *user_data)
 {

--
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel