[Mesa-dev] [PATCH 4/4] gbm: Add map/unmap functions
Eric Anholt
eric at anholt.net
Fri Apr 22 18:21:34 UTC 2016
Rob Herring <robh at kernel.org> writes:
> This adds map and unmap functions to GBM utilizing the DRIimage extension
> mapImage/unmapImage functions or existing internal mapping for dumb
> buffers. Unlike prior attempts, this version provides a region to map and
> usage flags for the mapping. The operation follows the same semantics as
> the gallium transfer_map() function.
>
> This was tested with GBM based gralloc on Android.
>
> This still creates a context, but I've moved it into gbm_create_device
> rather than in the map function. This should remove any need for reference
> counting and problems with memory leaks.
>
> Signed-off-by: Rob Herring <robh at kernel.org>
> @@ -981,6 +1033,8 @@ dri_device_create(int fd)
> dri->base.base.fd = fd;
> dri->base.base.bo_create = gbm_dri_bo_create;
> dri->base.base.bo_import = gbm_dri_bo_import;
> + dri->base.base.bo_map = gbm_dri_bo_map;
> + dri->base.base.bo_unmap = gbm_dri_bo_unmap;
> dri->base.base.is_format_supported = gbm_dri_is_format_supported;
> dri->base.base.bo_write = gbm_dri_bo_write;
> dri->base.base.bo_get_fd = gbm_dri_bo_get_fd;
> @@ -1004,6 +1058,10 @@ dri_device_create(int fd)
> if (ret)
> goto err_dri;
>
> + if (dri->image->base.version >= 12)
> + dri->context = dri->dri2->createNewContext(dri->screen, NULL,
> + NULL, NULL);
> +
> return &dri->base.base;
I don't think we want to always make a spare context just in case
someone uses the map API. Contexts can be pretty expensive to set up,
in time (for piglit tests on gbm) and memory (for X.Org).
It's too bad I don't think we have a way to get the existing
__DRIcontext from EGL to pass as an arg to map/unmap here, which could
be nice for glamor.
> diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
> index c046b1a..0f70bbd 100644
> --- a/src/gbm/main/gbm.c
> +++ b/src/gbm/main/gbm.c
> @@ -386,6 +386,57 @@ gbm_bo_import(struct gbm_device *gbm,
> }
>
> /**
> + * Map a region of a gbm buffer object for cpu access
> + *
> + * This function maps a region of a gbm bo for cpu read and/or write
> + * access.
> + *
> + * \param bo The buffer object
> + * \param x The X starting position of the mapped region for the buffer
> + * \param y The Y starting position of the mapped region for the buffer
> + * \param width The width of the mapped region for the buffer
> + * \param height The height of the mapped region for the buffer
> + * \param flags The union of the usage flags for this buffer
This should probably say at least "transfer flags", or even better "the
union of the GBM_BO_TRANSFER_* flags" to help people grep.
> + * \param stride Returned stride in bytes of the mapped region.
> + * \param map_data Returned opaque ptr for the mapped region
> + *
> + * \return Address of the mapped buffer
> + * gbm_bo_unmap() when no longer needed. On error, %NULL is returned
> + * and errno is set.
> + *
> + * \sa enum gbm_bo_transfer_flags for the list of flags
> + */
> +GBM_EXPORT void *
> +gbm_bo_map(struct gbm_bo *bo,
> + uint32_t x, uint32_t y,
> + uint32_t width, uint32_t height,
> + uint32_t flags, uint32_t *stride, void **map_data)
> +{
> + if (!bo || width == 0 || height == 0 || !stride || !map_data) {
> + errno = EINVAL;
> + return NULL;
> + }
> +
> + return bo->gbm->bo_map(bo, x, y, width, height,
> + flags, stride, map_data);
> +}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160422/9f420698/attachment.sig>
More information about the mesa-dev
mailing list