+
+/** wsi_dri3_open
+ *
+ * Wrapper around xcb_dri3_open
+ */
+static int
+wsi_dri3_open(xcb_connection_t *conn,
+ xcb_window_t root,
+ uint32_t provider)
+{
+ xcb_dri3_open_cookie_t cookie;
+ xcb_dri3_open_reply_t *reply;
+ int fd;
+
+ cookie = xcb_dri3_open(conn,
+ root,
+ provider);
+
+ reply = xcb_dri3_open_reply(conn, cookie, NULL);
+ if (!reply)
+ return -1;
+
+ if (reply->nfd != 1) {
+ free(reply);
+ return -1;
+ }
+
+ fd = xcb_dri3_open_reply_fds(conn, reply)[0];
+ free(reply);
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+
+ return fd;
+}
+
+static bool
+wsi_x11_check_dri3_compatible(xcb_connection_t *conn, int local_fd)
+{
+ xcb_screen_iterator_t screen_iter =
+ xcb_setup_roots_iterator(xcb_get_setup(conn));
+ xcb_screen_t *screen = screen_iter.data;
+
+ int dri3_fd = wsi_dri3_open(conn, screen->root, None);
+ if (dri3_fd != -1) {
+ char *local_dev = drmGetRenderDeviceNameFromFd(local_fd);
+ char *dri3_dev = drmGetRenderDeviceNameFromFd(dri3_fd);
+ int ret;
+
+ close(dri3_fd);
+
+ ret = strcmp(local_dev, dri3_dev);
+
+ free(local_dev);
+ free(dri3_dev);
+
+ if (ret != 0)
+ return false;
+ }
+ return true;
+}
+