summaryrefslogtreecommitdiff
path: root/test/dri3.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2015-04-20 14:54:50 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2015-04-20 15:00:47 +0100
commit75037efcd75f6baa3b48dd818b3efca42087f1b9 (patch)
tree73132ab074131937823c2df16fb2cc3f7e198979 /test/dri3.c
parent7eaf593640d4479f850227252fd793bcb55be8d3 (diff)
downloadxorg-driver-xf86-video-intel-75037efcd75f6baa3b48dd818b3efca42087f1b9.tar.gz
test/dri3: Add an explicit DRI3 extension check first
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'test/dri3.c')
-rw-r--r--test/dri3.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/dri3.c b/test/dri3.c
index 45f3285c..e5644629 100644
--- a/test/dri3.c
+++ b/test/dri3.c
@@ -29,6 +29,7 @@
#include <xcb/dri3.h>
#include <xcb/sync.h>
#include <unistd.h>
+#include <stdlib.h>
#include "dri3.h"
@@ -109,12 +110,45 @@ void dri3_fence_free(Display *dpy, struct dri3_fence *fence)
xcb_sync_destroy_fence(c, fence->xid);
}
+static void dri3_query_version(xcb_connection_t *c, int *major, int *minor)
+{
+ xcb_dri3_query_version_reply_t *reply;
+
+ reply = xcb_dri3_query_version_reply(c,
+ xcb_dri3_query_version(c,
+ XCB_DRI3_MAJOR_VERSION,
+ XCB_DRI3_MINOR_VERSION),
+ NULL);
+ if (reply != NULL) {
+ *major = reply->major_version;
+ *minor = reply->minor_version;
+ free(reply);
+ }
+}
+
+static int dri3_exists(xcb_connection_t *c)
+{
+ const xcb_query_extension_reply_t *ext;
+ int major, minor;
+
+ major = minor = -1;
+
+ ext = xcb_get_extension_data(c, &xcb_dri3_id);
+ if (ext != NULL && ext->present)
+ dri3_query_version(c, &major, &minor);
+
+ return major >= 0;
+}
+
int dri3_open__full(Display *dpy, Window root, unsigned provider)
{
xcb_connection_t *c = XGetXCBConnection(dpy);
xcb_dri3_open_cookie_t cookie;
xcb_dri3_open_reply_t *reply;
+ if (!dri3_exists(c))
+ return -1;
+
cookie = xcb_dri3_open(c, root, provider);
reply = xcb_dri3_open_reply(c, cookie, NULL);