+static _EGLImage *
+dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx,
+ EGLClientBuffer buffer,
+ const EGLint *attr_list)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_image *dri2_img;
+ xcb_dri3_buffers_from_pixmap_cookie_t bp_cookie;
+ xcb_dri3_buffers_from_pixmap_reply_t *bp_reply;
+ xcb_drawable_t drawable;
+ unsigned int format;
+
+ drawable = (xcb_drawable_t) (uintptr_t) buffer;
+ bp_cookie = xcb_dri3_buffers_from_pixmap(dri2_dpy->conn, drawable);
+ bp_reply = xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn,
+ bp_cookie, NULL);
+
+ if (!bp_reply) {
+ _eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr");
+ return EGL_NO_IMAGE_KHR;
+ }
+
+ format = dri3_format_for_depth(bp_reply->depth);
+ if (format == __DRI_IMAGE_FORMAT_NONE) {
+ _eglError(EGL_BAD_PARAMETER,
+ "dri3_create_image_khr: unsupported pixmap depth");
+ free(bp_reply);
+ return EGL_NO_IMAGE_KHR;
+ }
+
+ dri2_img = malloc(sizeof *dri2_img);
+ if (!dri2_img) {
+ _eglError(EGL_BAD_ALLOC, "dri3_create_image_khr");
+ free(bp_reply);
+ return EGL_NO_IMAGE_KHR;
+ }
+
+ _eglInitImage(&dri2_img->base, disp);
+
+ dri2_img->dri_image = loader_dri3_create_image_from_buffers(dri2_dpy->conn,
+ bp_reply,
+ format,
+ dri2_dpy->dri_screen,
+ dri2_dpy->image,
+ dri2_img);
+ free(bp_reply);
+
+ if (!dri2_img->dri_image) {
+ _eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr");
+ free(dri2_img);
+ return EGL_NO_IMAGE_KHR;
+ }
+
+ return &dri2_img->base;
+}
+