struct fd_bo * fd_screen_bo_from_handle(struct pipe_screen *pscreen, struct winsys_handle *whandle, unsigned *out_stride) { struct fd_screen *screen = fd_screen(pscreen); struct fd_bo *bo; if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { bo = fd_bo_from_name(screen->dev, whandle->handle); } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { bo = fd_bo_from_handle(screen->dev, whandle->handle, 0); } else if (whandle->type == DRM_API_HANDLE_TYPE_FD) { bo = fd_bo_from_dmabuf(screen->dev, whandle->handle); } else { DBG("Attempt to import unsupported handle type %d", whandle->type); return NULL; } if (!bo) { DBG("ref name 0x%08x failed", whandle->handle); return NULL; } *out_stride = whandle->stride; return bo; }
drm_public struct fd_bo * fd_bo_from_dmabuf(struct fd_device *dev, int fd) { struct drm_prime_handle req = { .fd = fd, }; int ret, size; ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req); if (ret) { return NULL; } /* hmm, would be nice if we had a way to figure out the size.. */ size = 0; return fd_bo_from_handle(dev, req.handle, size); }