[Mesa-dev] [PATCH v2 4/4] egl: android: add dma-buf fd support

Emil Velikov emil.l.velikov at gmail.com
Fri Apr 29 11:29:41 UTC 2016


On 28 April 2016 at 21:37, Rob Herring <robh at kernel.org> wrote:
> Add support for creating images from Android native buffers with dma-buf
> fd. As dma-buf support also requires DRI image loader extension, add
> that as well.
>
> This is based on several originally patches written by Varad Gautam.
> I've collapsed them into logical changes and done a bit of reformatting.
> Using dma-bufs vs. GEM handles is now a runtime decision similar to the
> wayland EGL instead of being compile time selection. The dma-buf support
> is also re-written to use common dri2_create_image_dma_buf function in
> egl_dri2.c.
>
> Cc: Varad Gautam <varadgautam at gmail.com>
> Cc: Rob Clark <robdclark at gmail.com>
> Cc: Emil Velikov <emil.velikov at collabora.com>
> Signed-off-by: Rob Herring <robh at kernel.org>
> ---
>  src/egl/drivers/dri2/platform_android.c | 124 ++++++++++++++++++++++++++++++--
>  1 file changed, 117 insertions(+), 7 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
> index a922f01..9747338 100644
> --- a/src/egl/drivers/dri2/platform_android.c
> +++ b/src/egl/drivers/dri2/platform_android.c
> @@ -65,6 +65,19 @@ get_format_bpp(int native)
>     return bpp;
>  }
>
> +/* createImageFromFds requires fourcc format */
> +static int get_fourcc(int format)
> +{
> +   switch(format) {
> +   case __DRI_IMAGE_FORMAT_RGB565:   return __DRI_IMAGE_FOURCC_RGB565;
> +   case __DRI_IMAGE_FORMAT_ARGB8888: return __DRI_IMAGE_FOURCC_ARGB8888;
> +   case __DRI_IMAGE_FORMAT_XRGB8888: return __DRI_IMAGE_FOURCC_XRGB8888;
> +   case __DRI_IMAGE_FORMAT_ABGR8888: return __DRI_IMAGE_FOURCC_ABGR8888;
> +   case __DRI_IMAGE_FORMAT_XBGR8888: return __DRI_IMAGE_FOURCC_XBGR8888;
> +   }
> +   return -1;
> +}
> +
>  static int get_format(int format)
>  {
>     switch (format) {
> @@ -80,6 +93,18 @@ static int get_format(int format)
>     return -1;
>  }
>  static int
> +get_native_buffer_fd(struct ANativeWindowBuffer *buf)
> +{
> +   native_handle_t *handle = (native_handle_t *)buf->handle;
> +   /*
> +    * Various gralloc implementations exist, but the dma-buf fd tends
> +    * to be first. Access it directly to avoid a dependency on specific
> +    * gralloc versions.
> +    */
> +   return (handle && handle->numFds) ? handle->data[0] : -1;
> +}
> +
> +static int
>  get_native_buffer_name(struct ANativeWindowBuffer *buf)
>  {
>     return gralloc_drm_get_gem_handle(buf->handle);
> @@ -333,6 +358,66 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
>     return 0;
>  }
>
> +static int
> +get_back_bo(struct dri2_egl_surface *dri2_surf)
> +{
> +   struct dri2_egl_display *dri2_dpy =
> +      dri2_egl_display(dri2_surf->base.Resource.Display);
> +   int format, stride;
> +   int offset = 0, fd;
> +
> +   if (!dri2_surf->buffer)
> +      return -1;
> +
> +   fd = get_native_buffer_fd(dri2_surf->buffer);
> +   if (fd < 0)
> +      return -1;
> +
> +   format = get_format(dri2_surf->buffer->format);
> +
> +   stride = dri2_surf->buffer->stride *
> +      get_format_bpp(dri2_surf->buffer->format);
> +
> +   dri2_surf->dri_image =
> +      dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
> +                                          dri2_surf->base.Width,
> +                                          dri2_surf->base.Height,
> +                                          get_fourcc(format),
And similar goes here for get_fourcc(), get_format_bpp() and get_format()

Thanks
Emil


More information about the mesa-dev mailing list