mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-01 18:20:10 +01:00
gbm: Implement dmabuf import using dumb buffers only
Split from https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38646 The dmabuf import code will never get called for now, since the dri backend will not be initialized if only dumb buffers can be created. Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
This commit is contained in:
parent
dbe71918aa
commit
b3f3a097bc
1 changed files with 45 additions and 0 deletions
|
|
@ -676,6 +676,43 @@ gbm_dri_bo_destroy(struct gbm_bo *_bo)
|
|||
free(bo);
|
||||
}
|
||||
|
||||
static struct gbm_bo *
|
||||
dumb_bo_from_fd(struct gbm_device *gbm,
|
||||
struct gbm_import_fd_data *fd_data)
|
||||
{
|
||||
#ifdef HAVE_LIBDRM
|
||||
struct gbm_dri_bo *bo;
|
||||
int ret;
|
||||
uint32_t handle;
|
||||
|
||||
bo = calloc(1, sizeof *bo);
|
||||
if (bo == NULL) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = drmPrimeFDToHandle(gbm->v0.fd, fd_data->fd, &handle);
|
||||
if (ret) {
|
||||
free(bo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bo->base.gbm = gbm;
|
||||
bo->base.v0.width = fd_data->width;
|
||||
bo->base.v0.height = fd_data->height;
|
||||
bo->base.v0.stride = fd_data->stride;
|
||||
bo->base.v0.format = fd_data->format;
|
||||
bo->base.v0.handle.u32 = handle;
|
||||
bo->handle = handle;
|
||||
bo->size = fd_data->stride * fd_data->height;
|
||||
|
||||
return &bo->base;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct gbm_bo *
|
||||
gbm_dri_bo_import(struct gbm_device *gbm,
|
||||
uint32_t type, void *buffer, uint32_t usage)
|
||||
|
|
@ -750,6 +787,9 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
* the sARGB format. */
|
||||
fourcc = core->v0.format_canonicalize(fd_data->format);
|
||||
|
||||
if (!dri->screen)
|
||||
return dumb_bo_from_fd(gbm, fd_data);
|
||||
|
||||
image = dri2_from_dma_bufs(dri->screen,
|
||||
fd_data->width,
|
||||
fd_data->height,
|
||||
|
|
@ -778,6 +818,11 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
* the sARGB format. */
|
||||
fourcc = core->v0.format_canonicalize(fd_data->format);
|
||||
|
||||
if (!dri->screen) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = dri2_from_dma_bufs(dri->screen, fd_data->width,
|
||||
fd_data->height, fourcc,
|
||||
fd_data->modifier,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue