[Mesa-dev] [PATCH] gbm: convert gbm bo format to fourcc format on dma-buf import

Ray Strode halfline at gmail.com
Sat Sep 5 16:27:16 PDT 2015


Hey Kristian, Ander,

Can I convince either/both of you to give this a once over and a r-b ?

--Ray

On Fri, Aug 28, 2015 at 2:15 PM, Ray Strode <halfline at gmail.com> wrote:
> From: Ray Strode <rstrode at redhat.com>
>
> At the moment if a gbm buffer is imported and the gbm buffer
> has an old-style GBM_BO_FORMAT format, the import will crash,
> since it's passed directly to DRI functions that expect
> a fourcc format (as provided by the newer GBM_FORMAT
> definitions)
>
> This commit addresses the problem in two ways:
>
> 1) it prevents invalid formats from leading to a crash by
> returning EINVAL up front.
>
> 2) it translates GBM_BO_FORMAT formats into the comparable
> GBM_FORMAT formats.
> ---
>  src/gbm/backends/dri/gbm_dri.c | 27 ++++++++++++++++++++++++++-
>  1 file changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
> index ccc3cc6..3deb2d9 100644
> --- a/src/gbm/backends/dri/gbm_dri.c
> +++ b/src/gbm/backends/dri/gbm_dri.c
> @@ -679,65 +679,90 @@ gbm_dri_bo_import(struct gbm_device *gbm,
>        default:
>           return NULL;
>        }
>        break;
>     }
>  #endif
>
>     case GBM_BO_IMPORT_EGL_IMAGE:
>     {
>        int dri_format;
>        if (dri->lookup_image == NULL) {
>           errno = EINVAL;
>           return NULL;
>        }
>
>        image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
>        image = dri->image->dupImage(image, NULL);
>        dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
>        gbm_format = gbm_dri_to_gbm_format(dri_format);
>        if (gbm_format == 0) {
>           errno = EINVAL;
>           return NULL;
>        }
>        break;
>     }
>
>     case GBM_BO_IMPORT_FD:
>     {
>        struct gbm_import_fd_data *fd_data = buffer;
>        int stride = fd_data->stride, offset = 0;
> +      int dri_format;
> +
> +      /* This switch statement serves two purposes:
> +       *    1) return EINVAL if an invalid format is passed in
> +       *    2) convert GBM_BO_FORMAT formats to fourcc format
> +       */
> +      switch (fd_data->format) {
> +      case GBM_FORMAT_RGB565:
> +      case GBM_FORMAT_XRGB8888:
> +      case GBM_FORMAT_ARGB8888:
> +      case GBM_FORMAT_ABGR8888:
> +      case GBM_FORMAT_ARGB2101010:
> +      case GBM_FORMAT_XRGB2101010:
> +          dri_format = fd_data->format;
> +          break;
> +      case GBM_BO_FORMAT_XRGB8888:
> +          dri_format = GBM_FORMAT_XRGB8888;
> +          break;
> +      case GBM_BO_FORMAT_ARGB8888:
> +          dri_format = GBM_FORMAT_ARGB8888;
> +          break;
> +      default:
> +          errno = EINVAL;
> +          return NULL;
> +      }
>
>        image = dri->image->createImageFromFds(dri->screen,
>                                               fd_data->width,
>                                               fd_data->height,
> -                                             fd_data->format,
> +                                             dri_format,
>                                               &fd_data->fd, 1,
>                                               &stride, &offset,
>                                               NULL);
>        gbm_format = fd_data->format;
>        break;
>     }
>
>     default:
>        errno = ENOSYS;
>        return NULL;
>     }
>
>
>     bo = calloc(1, sizeof *bo);
>     if (bo == NULL)
>        return NULL;
>
>     bo->image = image;
>
>     if (usage & GBM_BO_USE_SCANOUT)
>        dri_use |= __DRI_IMAGE_USE_SCANOUT;
>     if (usage & GBM_BO_USE_CURSOR)
>        dri_use |= __DRI_IMAGE_USE_CURSOR;
>     if (dri->image->base.version >= 2 &&
>         !dri->image->validateUsage(bo->image, dri_use)) {
>        errno = EINVAL;
>        free(bo);
>        return NULL;
>     }
>
> --
> 2.5.0
>


More information about the mesa-dev mailing list